@@ -39,6 +39,10 @@ class MessageContent extends HookConsumerWidget {
3939 /// Called when a #channel link is tapped.
4040 final void Function (String channelId)? onChannelTap;
4141
42+ /// Called when an @mention of a known user is tapped, with the
43+ /// mentioned user's pubkey.
44+ final void Function (String pubkey)? onMentionTap;
45+
4246 final TextStyle ? baseStyle;
4347
4448 final int ? maxLines;
@@ -50,6 +54,7 @@ class MessageContent extends HookConsumerWidget {
5054 this .channelNames = const {},
5155 this .tags = const [],
5256 this .onChannelTap,
57+ this .onMentionTap,
5358 this .baseStyle,
5459 this .maxLines,
5560 });
@@ -145,7 +150,7 @@ class MessageContent extends HookConsumerWidget {
145150 _buildMedia (context, imageUrl, imetaByUrl[imageUrl]),
146151 maxLines: maxLines,
147152 inlineComponents: [
148- _MentionMd (mentionNames: mentionNames),
153+ _MentionMd (mentionNames: mentionNames, onMentionTap : onMentionTap ),
149154 CustomEmojiMd (customEmoji),
150155 _ChannelLinkMd (channelNames: channelNames, onChannelTap: onChannelTap),
151156 ...MarkdownComponent .inlineComponents,
@@ -572,13 +577,14 @@ class _MessageCodeBlock extends HookWidget {
572577
573578class _MentionMd extends InlineMd {
574579 final Map <String , String > mentionNames;
580+ final void Function (String pubkey)? onMentionTap;
575581 late final RegExp _exp = _buildPrefixPattern (
576582 prefix: '@' ,
577583 knownNames: _mentionAliases (mentionNames.values),
578584 genericTokenPattern: r'[A-Za-z0-9_][A-Za-z0-9_\u00A0-]*' ,
579585 );
580586
581- _MentionMd ({required this .mentionNames});
587+ _MentionMd ({required this .mentionNames, this .onMentionTap });
582588
583589 @override
584590 RegExp get exp => _exp;
@@ -596,22 +602,28 @@ class _MentionMd extends InlineMd {
596602
597603 final name = raw.substring (1 ).replaceAll ('\u 00A0' , ' ' ).toLowerCase ();
598604 String ? displayName;
605+ String ? pubkey;
599606 for (final entry in mentionNames.entries) {
600607 final entryName = entry.value.toLowerCase ();
601608 final firstName = entryName.split (RegExp (r'\s+' )).first;
602609 if (entryName == name || firstName == name) {
603610 displayName = entry.value;
611+ pubkey = entry.key;
604612 break ;
605613 }
606614 }
607615
616+ final pill = _TokenPill (
617+ text: '@${displayName ?? raw .substring (1 )}' ,
618+ textStyle: config.style,
619+ );
620+
608621 return WidgetSpan (
609622 alignment: PlaceholderAlignment .baseline,
610623 baseline: TextBaseline .alphabetic,
611- child: _TokenPill (
612- text: '@${displayName ?? raw .substring (1 )}' ,
613- textStyle: config.style,
614- ),
624+ child: pubkey != null && onMentionTap != null
625+ ? GestureDetector (onTap: () => onMentionTap !(pubkey! ), child: pill)
626+ : pill,
615627 );
616628 }
617629}
0 commit comments