Skip to content

Commit 175fdba

Browse files
author
npub1qq582hwclq7jnux44a2xul8nhe2ue2zk9z49ehzngznnmmk5ka5sprvchv
committed
fix(mobile): open profile sheet when tapping @mentions
Mention pills rendered in mobile messages were static text. Wire an onMentionTap callback through MessageContent into the existing _MentionMd inline component, resolving the tapped mention back to the mentioned pubkey from the event p-tag map, and hook it up to the established showUserProfileSheet flow (same sheet used by avatar and author-name taps) in channel messages, thread replies, forum posts, and forum replies. Unknown mentions (no matching p-tag) stay inert. Co-authored-by: npub1qq582hwclq7jnux44a2xul8nhe2ue2zk9z49ehzngznnmmk5ka5sprvchv <0028755dd8f83d29f0d5af546e7cf3be55cca85628aa5cdc5340a73deed4b769@sprout-oss.stage.blox.sqprod.co> Signed-off-by: npub1qq582hwclq7jnux44a2xul8nhe2ue2zk9z49ehzngznnmmk5ka5sprvchv <0028755dd8f83d29f0d5af546e7cf3be55cca85628aa5cdc5340a73deed4b769@sprout-oss.stage.blox.sqprod.co>
1 parent 1950eb1 commit 175fdba

5 files changed

Lines changed: 74 additions & 6 deletions

File tree

‎mobile/lib/features/channels/channel_detail_page/message_bubble.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ class _MessageBubble extends ConsumerWidget {
122122
currentChannelId: currentChannelId,
123123
);
124124
},
125+
onMentionTap: (pubkey) =>
126+
showUserProfileSheet(context, pubkey),
125127
),
126128
if (message.reactions.isNotEmpty)
127129
ReactionRow(

‎mobile/lib/features/channels/message_content.dart‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

573578
class _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('\u00A0', ' ').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
}

‎mobile/lib/features/channels/thread_detail_page.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ class _ThreadMessage extends ConsumerWidget {
478478
currentChannelId: channelId,
479479
);
480480
},
481+
onMentionTap: (pubkey) =>
482+
showUserProfileSheet(context, pubkey),
481483
),
482484
if (message.reactions.isNotEmpty)
483485
ReactionRow(

‎mobile/lib/features/forum/forum_thread_page.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ class _OriginalPost extends ConsumerWidget {
363363
content: post.content,
364364
mentionNames: mentionNames,
365365
tags: post.tags,
366+
onMentionTap: (pubkey) => showUserProfileSheet(context, pubkey),
366367
),
367368
],
368369
),
@@ -457,6 +458,7 @@ class _ReplyRow extends ConsumerWidget {
457458
content: reply.content,
458459
mentionNames: mentionNames,
459460
tags: reply.tags,
461+
onMentionTap: (pubkey) => showUserProfileSheet(context, pubkey),
460462
),
461463
),
462464
],

‎mobile/test/features/channels/message_content_test.dart‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,56 @@ void main() {
775775
expect(_allRichText(tester), contains('[email protected]'));
776776
expect(find.text('@example.com'), findsNothing);
777777
});
778+
779+
testWidgets('mention tap callback fires with pubkey', (tester) async {
780+
String? tappedPubkey;
781+
await tester.pumpWidget(
782+
_testable(
783+
MessageContent(
784+
content: 'Hey @Alice check this out',
785+
mentionNames: const {'pk1': 'Alice'},
786+
onMentionTap: (pubkey) => tappedPubkey = pubkey,
787+
),
788+
),
789+
);
790+
791+
await tester.tap(find.text('@Alice'));
792+
expect(tappedPubkey, 'pk1');
793+
});
794+
795+
testWidgets('multi-word mention tap callback fires with pubkey', (
796+
tester,
797+
) async {
798+
String? tappedPubkey;
799+
await tester.pumpWidget(
800+
_testable(
801+
MessageContent(
802+
content: 'Hey @Kenny Lopez can you review this?',
803+
mentionNames: const {'pk1': 'Kenny Lopez'},
804+
onMentionTap: (pubkey) => tappedPubkey = pubkey,
805+
),
806+
),
807+
);
808+
809+
await tester.tap(find.text('@Kenny Lopez'));
810+
expect(tappedPubkey, 'pk1');
811+
});
812+
813+
testWidgets('unknown mention renders without tap', (tester) async {
814+
var tapped = false;
815+
await tester.pumpWidget(
816+
_testable(
817+
MessageContent(
818+
content: 'Hey @unknown check this',
819+
mentionNames: const {},
820+
onMentionTap: (_) => tapped = true,
821+
),
822+
),
823+
);
824+
825+
await tester.tap(find.text('@unknown'), warnIfMissed: false);
826+
expect(tapped, isFalse);
827+
});
778828
});
779829

780830
group('#channel links', () {

0 commit comments

Comments
 (0)