Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions mobile/lib/features/channels/compose_bar/composer_mentions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,16 @@ _resolveComposerMentions(
return (recipients: winners.values.toList(), nameEnds: nameEnds);
}

/// The content sent for [text]. A picked multi-word person uses an identity
/// link. Other bound mentions are written `@Name (<key>)`
/// The content sent for [text]. A bound mention is written `@Name (<key>)`
/// when its plain text would read as someone else in the bubble: when bound
/// mentions of different keys share its name, ignoring case, as buzz-app's
/// `composer-markdown.ts` qualifies them, or when the text typed against it
/// spells a longer known name (`-bot` after a picked `@Bob`, beside a
/// `Bob-bot`), which the bubble's longest-name match would otherwise draw
/// as that other person. [nameEnds] says where the longest name at each `@`
/// ends, among the chips, the recipients and the channel's members; it is
/// the send's one scan, from [_resolveComposerMentions]. No live mention sits inside code, where the controller
/// the send's one scan, from [_resolveComposerMentions]. One key under a
/// name stays bare. No live mention sits inside code, where the controller
/// keeps a binding dormant, so code is sent as typed. The composer itself
/// never showed the key.
String _qualifiedMentionContent(
Expand All @@ -307,19 +307,6 @@ String _qualifiedMentionContent(
}
var content = text;
for (final mention in mentions.reversed) {
// Preserve a picked full name as one inline identity even when the
// reader has only a first name or has yet to load this person's profile.
final label = text.substring(mention.start, mention.end);
if (!mention.candidate.isAgent &&
label.trim().contains(' ') &&
!_keyQualifier.hasMatch(label)) {
content = content.replaceRange(
mention.start,
mention.end,
mentionIdentityLink(label, mention.pubkey),
);
continue;
}
if (keysByName[foldMentionLabel(mention.label(text))]!.length < 2 &&

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 P2 — Preserve the selected key for a picked full name. Pick Alex Smith and Alex in one message. Both recipient tags are correct, but the body sends @Alex Smith @Alex. A reader who only has Alex's name can tap the first @Alex prefix and open Alex. If edit-open also lacks Alex Smith's original name, it seeds that same wrong key and saving an unrelated change turns it into an explicit identity link. Keep the full-name occurrence bound to the picked key in a reader-compatible format. Cover send → tap and edit-open with a competing name and a missing or renamed profile. Tap binding · Edit hydration

(nameEnds[mention.start] ?? 0) <= mention.end) {
continue;
Expand Down
4 changes: 0 additions & 4 deletions mobile/lib/features/channels/compose_bar/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,6 @@ class _ComposeBarLayout extends HookWidget {
allowedMimeTypes: _pastedImageMimeTypes,
onContentInserted: onContentInserted,
),
// Give wrapped mention chips room above and below their baseline.
strutStyle: controller.bindings.isEmpty
? null
: const StrutStyle(forceStrutHeight: false),
minLines: 1,
maxLines: 5,
style: messageBodyTextStyle,
Expand Down
3 changes: 1 addition & 2 deletions mobile/lib/features/channels/message_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ class MessageContent extends HookConsumerWidget {
content,
mentionNames,
signedMentionPubkeys,
mentionLabels,
);
final resolvedAgentMentionPubkeys = {
...agentMentionPubkeys.map((pubkey) => pubkey.toLowerCase()),
Expand Down Expand Up @@ -401,7 +400,7 @@ class MessageContent extends HookConsumerWidget {
}
return segment;
});
}, [markdownContent, mentionPresentationKey, mentionLabels]);
}, [markdownContent, mentionPresentationKey]);

final inlinePatterns = _useMessageInlinePatterns(
ownBubble: bubble && ownMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class MessagePreview extends HookConsumerWidget {
source,
mentionNames,
mentionedPubkeysFromTags(tags),
mentionLabels,
),
mentionNames: mentionNames,
mentionLabels: mentionLabels,
Expand Down
29 changes: 19 additions & 10 deletions mobile/lib/features/channels/message_mention_pill.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,34 @@ class MessageMentionPill extends ConsumerWidget {
final fontSize = style.fontSize ?? 16;

final key = pubkey?.toLowerCase();
final picture = key == null || !showPortrait
final cached = key == null || !showPortrait
? null
: ref.watch(
userCacheProvider.select((cache) => cache[key]?.avatarUrl),
) ??
userCacheProvider.select(
(cache) =>
(known: cache.containsKey(key), url: cache[key]?.avatarUrl),
),
);
final picture = cached == null
? null
: cached.url ??
(isAgent
? ref.watch(
agentDirectoryPicturesProvider.select(
(pictures) => pictures[key],
),
)
: null) ??
candidateAvatar ??
(isAgent
// The picker's and search's portraits stand in only until the
// profile loads, so a profile without a picture stays without one.
(cached.known
? null
: ref.watch(mentionSearchCacheProvider).portraitFor(key));
: candidateAvatar ??
(isAgent
? null
: ref
.watch(mentionSearchCacheProvider)
.portraitFor(key!)));
final hasPicture = picture != null && picture.isNotEmpty;
// The enclosing span already scales the chip.
final size = fontSize;
Expand All @@ -116,10 +128,7 @@ class MessageMentionPill extends ConsumerWidget {
: BuzzAgentIcon(size: size, color: ink);

return Container(
margin: EdgeInsets.symmetric(
horizontal: fontSize / 17,
vertical: 2 * fontSize / 17,
),
margin: EdgeInsets.symmetric(horizontal: fontSize / 17),
padding: EdgeInsetsDirectional.fromSTEB(
hasPicture ? Grid.quarter : Grid.quarter * 1.5,
Grid.quarter,
Expand Down
5 changes: 0 additions & 5 deletions mobile/lib/shared/mentions/mention_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ Map<String, Set<String>> renderedMentionBindings(
String content,
Map<String, String> names, [
Iterable<String> signedPubkeys = const [],
Map<String, String> contextualLabels = const {},
]) {
final bindings = <String, Set<String>>{};
void add(String label, String key) =>
Expand All @@ -134,10 +133,6 @@ Map<String, Set<String>> renderedMentionBindings(
add(entry.value.split(RegExp(r'\s+')).first, entry.key);
}
final keys = signedPubkeys.map((key) => key.toLowerCase()).toSet();
for (final key in keys) {
final label = contextualLabels[key];
if (label != null && label.trim().isNotEmpty) add(label, key);
}
for (final match in RegExp(
r'@([^@\r\n]+) \(([0-9a-f]{64})\)(?: ((?:[1-9][0-9]+|[2-9])))?',
caseSensitive: false,
Expand Down
47 changes: 1 addition & 46 deletions mobile/test/features/channels/compose_bar_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'package:buzz/features/channels/message_content.dart';
import 'package:buzz/features/channels/message_mention_pill.dart';
import 'package:buzz/features/channels/voice_note_composer_recorder.dart';
import 'package:clock/clock.dart';
import 'package:buzz/features/channels/composer_transcription.dart';
Expand Down Expand Up @@ -7122,7 +7120,6 @@ void main() {
tester,
) async {
final signer = nostr.Keys.generate();
String? sentContent;
List<String>? sentRecipients;
List<List<String>>? sentTags;
await tester.pumpWidget(
Expand All @@ -7139,12 +7136,7 @@ void main() {
],
searchPeople: (query) async => [maryJane],
onSend:
(
content,
recipients, {
mediaTags = const <List<String>>[],
}) async {
sentContent = content;
(_, recipients, {mediaTags = const <List<String>>[]}) async {
sentRecipients = recipients;
sentTags = mediaTags;
},
Expand All @@ -7155,43 +7147,6 @@ void main() {
expect(find.byType(AlertDialog), findsNothing);
expect(sentRecipients, isNot(contains(maryJane.pubkey)));
expect(sentTags, contains(orderedEquals(['mention', maryJane.pubkey])));
final container = ProviderScope.containerOf(
tester.element(find.byType(ComposeBar)),
);
// The picker has a portrait before the timeline has a hydrated profile.
container.read(mentionSearchCacheProvider).put('Mary J', [
UserProfile(
pubkey: maryJane.pubkey,
avatarUrl: 'https://example.org/mary.png',
),
]);
await tester.pumpWidget(
UncontrolledProviderScope(
container: container,
child: MaterialApp(
home: Scaffold(
body: AppMarkdownTheme(
child: MessageContent(
content: sentContent!,
tags: sentTags!,
bubble: true,
),
),
),
),
),
);
await tester.pump();
final chip = tester.widget<MessageMentionPill>(
find.byType(MessageMentionPill),
);
expect(chip.label, 'Mary Jane');
expect(chip.pubkey, maryJane.pubkey);
expect(chip.isAgent, isFalse);
expect(
tester.widget<AvatarImage>(find.byType(AvatarImage)).imageUrl,
'https://example.org/mary.png',
);
});

testWidgets('a DM without membership uses its participants and sends', (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,42 @@ void exactMentionTests() {
expect(sentText, '@Sam ($first) @ſam ($second)');
});

testWidgets('picked multi-word namesakes each carry their key on send', (
tester,
) async {
ChannelMember named(String key) => ChannelMember(
pubkey: key,
displayName: 'Alex Smith',
role: 'member',
joinedAt: DateTime(2025),
);
String? sentText;
await mountComposer(tester, [named(first), named(second)], (
text,
_, {
mediaTags = const [],
}) async {
sentText = text;
});
Finder rows() => find.descendant(
of: find.byKey(const ValueKey('mention-suggestions-popover')),
matching: find.textContaining('Alex Smith'),
);
final field = find.byType(TextField);
await tester.enterText(field, '@Alex');
await tester.pumpAndSettle();
await tester.tap(rows().first);
await tester.pumpAndSettle();
final controller = tester.widget<TextField>(field).controller!;
await tester.enterText(field, '${controller.text}@Alex');
await tester.pumpAndSettle();
await tester.tap(rows().last);
await tester.pumpAndSettle();
await tester.tap(find.byIcon(BuzzIcons.arrowUp));
await tester.pumpAndSettle();
expect(sentText, '@Alex Smith ($first) @Alex Smith ($second)');
});

testWidgets('closing punctuation never selects a shared name', (
tester,
) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,33 @@ void mentionChipTests() {
},
);

testWidgets('chips keep the field at the plain line height', (tester) async {
final controller = await mount(
tester,
onSend: (_, _, {mediaTags = const []}) async {},
);
final field = find.byType(TextField);
await tester.enterText(field, 'a\nb\nc\nd\ne');
await tester.pumpAndSettle();
final plain = tester.getSize(field).height;
await tester.enterText(field, '');
await tester.pumpAndSettle();
for (var line = 0; line < 5; line++) {
final prefix = line == 0 ? '' : '${controller.text}\n';
await tester.enterText(field, '$prefix@bo');
await tester.pumpAndSettle();
await tester.tap(row('Bob'));
await tester.pumpAndSettle();
}
expect(personChip, findsNWidgets(5));
expect(tester.getSize(field).height, plain);
// All five lines show: none scrolls out of the capped field.
final scroll = tester.state<ScrollableState>(
find.descendant(of: field, matching: find.byType(Scrollable)),
);
expect(scroll.position.maxScrollExtent, 0);
});

testWidgets(
'picked people and agents are atomic chips that carry the recipient',
(tester) async {
Expand Down
Loading
Loading