diff --git a/lib/models/video/reply/content.dart b/lib/models/video/reply/content.dart index ad1759ac..9180ec97 100644 --- a/lib/models/video/reply/content.dart +++ b/lib/models/video/reply/content.dart @@ -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, // {} @@ -13,7 +13,7 @@ class ReplyContent { String? message; Map? atNameToMid; - List? memebers; + List? members; Map? emote; Map? jumpUrl; List? pictures; @@ -27,7 +27,11 @@ class ReplyContent { .replaceAll('"', '"') .replaceAll(''', "'"); atNameToMid = json['at_name_to_mid'] ?? {}; - memebers = json['memebers'] ?? []; + members = json['members'] != null + ? json['members'] + .map((e) => MemberItemModel.fromJson(e)) + .toList() + : []; emote = json['emote'] ?? {}; jumpUrl = json['jump_url'] ?? {}; pictures = json['pictures'] ?? []; @@ -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 json) { + mid = json['mid']; + uname = json['uname']; + } +} diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 58acd8ab..73784a61 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -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; @@ -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; }, );