fix(mobile): keep unbound qualified mentions non-notifying

Signed-off-by: Logan Johnson <loganj@squareup.com>
This commit is contained in:
Logan Johnson
2026-09-07 11:07:23 -04:00
parent 2ac8764b26
commit 87d78072a1
4 changed files with 55 additions and 6 deletions

View File

@@ -29,8 +29,14 @@ List<({int start, int end, String label})> mentionOccurrences(
final matches = <int, ({int start, int end, String label})>{};
for (final label in labels) {
if (label.isEmpty) continue;
// A qualifier and reservation suffix belong to the literal even when no
// candidate binds it. Never fall back to a shorter, different recipient.
final suffix =
RegExp(r' \([0-9a-f]{64}\)$', caseSensitive: false).hasMatch(label)
? r'(?! (?:[2-9]|[1-9][0-9]+)(?=[\s,;.!?:)\]}*_]|$))'
: '';
final pattern = RegExp(
'(?:^|\\s|[*_]{1,3}|\\|\\|)(@${RegExp.escape(label)})(?=\\|\\||[\\s,;.!?:)\\]}*_]|\$)',
'(?:^|\\s|[*_]{1,3}|\\|\\|)(@${RegExp.escape(label)})(?! \\([0-9a-f]{64}\\))$suffix(?=\\|\\||[\\s,;.!?:)\\]}*_]|\$)',
caseSensitive: false,
);
for (final match in pattern.allMatches(text)) {
@@ -70,12 +76,14 @@ Map<String, Set<String>> renderedMentionBindings(
).allMatches(content)) {
final key = match.group(2)!.toLowerCase();
final label = match.group(0)!.substring(1).toLowerCase();
if (!keys.contains(key) ||
!mentionOccurrences(content, [
label,
]).any((range) => range.start == match.start)) {
if (!mentionOccurrences(content, [
label,
]).any((range) => range.start == match.start)) {
continue;
}
// Untagged qualified literals are recognition blockers, not bindings.
bindings.putIfAbsent(label, () => <String>{});
if (!keys.contains(key)) continue;
qualified.add((
label: label,
base: match.group(1)!.toLowerCase(),

View File

@@ -59,6 +59,25 @@ void exactMentionTests() {
},
);
testWidgets('unbound qualified text cannot notify a shorter member alias', (
tester,
) async {
List<String>? sent;
await tester.pumpWidget(
_buildComposeBar(
uploadService: _testUploadService(nostr.Keys.generate().nsec),
members: [members().first],
onSend: (_, keys, {mediaTags = const []}) async => sent = keys,
),
);
await _expandComposer(tester);
await tester.enterText(find.byType(TextField), '@Scout ($second)');
await tester.pumpAndSettle();
await tester.tap(find.byIcon(LucideIcons.arrowUp));
await tester.pumpAndSettle();
expect(sent, isEmpty);
});
testWidgets('ambiguous typed names fail visibly without clearing the draft', (
tester,
) async {

View File

@@ -3,6 +3,23 @@ import 'package:buzz/features/channels/message_content.dart';
import '../../helpers/widget_helpers.dart';
void main() {
testWidgets('untagged qualifiers cannot become shorter clickable aliases', (
tester,
) async {
await tester.pumpWidget(
WidgetHelpers.testable(
child: MessageContent(
content: '@Scout (${'b' * 64})',
mentionNames: {'a' * 64: 'Scout'},
onMentionTap: (_) => fail('unbound text is not a profile target'),
),
),
);
await tester.pumpAndSettle();
expect(find.text('Scout'), findsNothing);
expect(tester.takeException(), isNull);
});
testWidgets('namesake chips resolve exact tagged keys, not tag order', (
tester,
) async {

View File

@@ -23,6 +23,11 @@ void main() {
);
expect(mentionOccurrences('@A @B', ['A @B', 'B']).single.label, 'A @B');
expect(mentionOccurrences('mail@Scout', ['Scout']), isEmpty);
expect(mentionOccurrences('@Scout ($second)', ['Scout']), isEmpty);
expect(
mentionOccurrences('@Scout ($second) 2', ['Scout ($second)']),
isEmpty,
);
});
test(
'tagged qualified identity narrows a namesake independently of tag order',
@@ -49,7 +54,7 @@ void main() {
renderedMentionBindings('@Scout ($second)', {
first: 'Scout',
})['scout ($second)'],
isNull,
isEmpty,
);
expect(
renderedMentionBindings('@Old ($second)', {