Skip to content

Commit

Permalink
fix: 评论区展示@用户 issues #344
Browse files Browse the repository at this point in the history
  • Loading branch information
guozhigq committed Jan 1, 2024
1 parent 7af990d commit 11920e4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
25 changes: 22 additions & 3 deletions lib/models/video/reply/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class ReplyContent {
ReplyContent({
this.message,
this.atNameToMid, // @的用户的mid null
this.memebers, // 被@的用户List 如果有的话 []
this.members, // 被@的用户List 如果有的话 []
this.emote, // 表情包 如果有的话 null
this.jumpUrl, // {}
this.pictures, // {}
Expand All @@ -13,7 +13,7 @@ class ReplyContent {

String? message;
Map? atNameToMid;
List? memebers;
List<MemberItemModel>? members;
Map? emote;
Map? jumpUrl;
List? pictures;
Expand All @@ -27,7 +27,11 @@ class ReplyContent {
.replaceAll('&#34;', '"')
.replaceAll('&#39;', "'");
atNameToMid = json['at_name_to_mid'] ?? {};
memebers = json['memebers'] ?? [];
members = json['members'] != null
? json['members']
.map<MemberItemModel>((e) => MemberItemModel.fromJson(e))
.toList()
: [];
emote = json['emote'] ?? {};
jumpUrl = json['jump_url'] ?? {};
pictures = json['pictures'] ?? [];
Expand All @@ -37,3 +41,18 @@ class ReplyContent {
isText = atNameToMid!.isEmpty && vote!.isEmpty && pictures!.isEmpty;
}
}

class MemberItemModel {
MemberItemModel({
required this.mid,
required this.uname,
});

late String mid;
late String uname;

MemberItemModel.fromJson(Map<String, dynamic> json) {
mid = json['mid'];
uname = json['uname'];
}
}
11 changes: 9 additions & 2 deletions lib/pages/video/detail/reply/widgets/reply_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,13 @@ InlineSpan buildContent(
// 匹配@用户
String matchMember = str;
if (content.atNameToMid.isNotEmpty) {
RegExp reg = RegExp(r"@.*( |:)");
if (content.atNameToMid.length == 1 &&
content.message == '@${content.members.first.uname}') {
reg = RegExp(r"@.*( |:|$)");
}
matchMember = str.splitMapJoin(
RegExp(r"@.*( |:)"),
reg,
onMatch: (Match match) {
if (match[0] != null) {
hasMatchMember = false;
Expand Down Expand Up @@ -657,7 +662,9 @@ InlineSpan buildContent(
return '';
},
onNonMatch: (String str) {
spanChilds.add(TextSpan(text: str));
if (!str.contains('@')) {
spanChilds.add(TextSpan(text: str));
}
return str;
},
);
Expand Down

0 comments on commit 11920e4

Please sign in to comment.