Skip to content

Commit acd8413

Browse files
committed
fix(mobile): recover historical namesake chip identity
Signed-off-by: Logan Johnson <[email protected]>
1 parent 39afd73 commit acd8413

2 files changed

Lines changed: 56 additions & 12 deletions

File tree

‎mobile/lib/shared/mentions/mention_bindings.dart‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,25 @@ Map<String, Set<String>> renderedMentionBindings(
9090
key: key,
9191
));
9292
add(label, key);
93+
bindings.putIfAbsent(match.group(1)!.toLowerCase(), () => <String>{});
9394
}
9495
final winning = mentionOccurrences(
9596
content,
9697
bindings.keys,
9798
).map((range) => range.label).toSet();
98-
for (final entry in bindings.entries) {
99-
if (entry.value.length < 2) continue;
100-
entry.value.removeAll(
101-
qualified
102-
.where(
103-
(q) =>
104-
q.base == entry.key &&
105-
winning.contains(q.label) &&
106-
bindings[q.label]?.length == 1,
107-
)
108-
.map((q) => q.key),
109-
);
99+
final claimed = qualified.where((q) => winning.contains(q.label)).toList();
100+
final bases = claimed.map((q) => q.base).where(winning.contains).toSet();
101+
final remaining = keys.difference(claimed.map((q) => q.key).toSet());
102+
// Ordinary sibling mentions claim their own identities before recovering a
103+
// historical namesake. Current aliases must not retarget that namesake.
104+
for (final label in winning.difference(bases)) {
105+
final candidates = bindings[label]!;
106+
if (candidates.length == 1) remaining.removeAll(candidates);
107+
}
108+
for (final base in bases) {
109+
// Multiple historical labels or leftover tagged keys cannot be paired
110+
// deterministically. Leave them as non-clickable references, not guesses.
111+
bindings[base] = bases.length == 1 ? remaining.toSet() : <String>{};
110112
}
111113
return bindings;
112114
}

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,46 @@ void main() {
6767
expect(tester.takeException(), isNull);
6868
semantics.dispose();
6969
});
70+
testWidgets('historical namesakes preserve targets with ordinary siblings', (
71+
tester,
72+
) async {
73+
final first = 'a' * 64, second = 'b' * 64, sibling = 'c' * 64;
74+
for (final firstName in ['Scout', 'Renamed Scout', first]) {
75+
for (final secondName in ['Scout', 'Renamed Scout', second]) {
76+
for (final reverse in [false, true]) {
77+
for (final ambiguous in [false, true]) {
78+
final entries = {
79+
first: firstName,
80+
second: secondName,
81+
sibling: 'Alice',
82+
if (ambiguous) 'd' * 64: 'Unknown',
83+
}.entries.toList();
84+
String? tapped;
85+
await tester.pumpWidget(
86+
WidgetHelpers.testable(
87+
child: MessageContent(
88+
content: '@Scout @Scout ($second) @Alice',
89+
mentionNames: Map.fromEntries(
90+
reverse ? entries.reversed : entries,
91+
),
92+
onMentionTap: (key) => tapped = key,
93+
),
94+
),
95+
);
96+
await tester.pumpAndSettle();
97+
if (ambiguous) {
98+
expect(find.text(firstName), findsNothing);
99+
} else {
100+
await tester.tap(find.text(firstName));
101+
expect(tapped, first);
102+
}
103+
await tester.tap(find.text('Scout (bbbbbbbb…bbbb)'));
104+
expect(tapped, second);
105+
await tester.tap(find.text('Alice'));
106+
expect(tapped, sibling);
107+
}
108+
}
109+
}
110+
}
111+
});
70112
}

0 commit comments

Comments
 (0)