Skip to content

Commit b2408e8

Browse files
committed
content: Update Mention widget to render user group mentions dynamically
Fixes #1259. Look up current user group name from PerAccountStore when rendering mentions, while respecting "isSilent" flag. This ensures mentions display correctly even if the user group name has been changed since the message was sent. Falls back to original HTML text when user group not found. Added 'user group mention dynamic name resolution' tests group.
1 parent 717b088 commit b2408e8

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

lib/widgets/content.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,12 @@ class Mention extends StatelessWidget {
12061206
if (user case User(:final fullName)) {
12071207
nodes = [TextNode(node.isSilent ? fullName : '@$fullName')];
12081208
}
1209+
} else if (node case UserGroupMentionNode(:final userGroupId)) {
1210+
final userGroup = store.getGroup(userGroupId);
1211+
if (userGroup case UserGroup(:final name)) {
1212+
// TODO(#1260) Get display name for system groups using localization
1213+
nodes = [TextNode(node.isSilent ? name : '@$name')];
1214+
}
12091215
}
12101216
return Container(
12111217
decoration: BoxDecoration(

test/widgets/content_test.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,45 @@ void main() {
11111111
check(find.text('@New Name')).findsNothing();
11121112
});
11131113
});
1114+
1115+
group('user group mention dynamic name resolution', () {
1116+
Future<void> prepare({
1117+
required WidgetTester tester,
1118+
required String html,
1119+
List<UserGroup>? userGroups,
1120+
}) async {
1121+
final initialSnapshot = eg.initialSnapshot(realmUserGroups: userGroups);
1122+
await prepareContent(tester,
1123+
wrapWithPerAccountStoreWidget: true,
1124+
initialSnapshot: initialSnapshot,
1125+
plainContent(html));
1126+
}
1127+
1128+
testWidgets('resolves current user group name from store', (tester) async {
1129+
await prepare(
1130+
tester: tester,
1131+
html: '<p><span class="user-group-mention" data-user-group-id="186">@old-name</span></p>',
1132+
userGroups: [eg.userGroup(id: 186, name: 'new-name')]);
1133+
check(find.text('@new-name')).findsOne();
1134+
check(find.text('@old-name')).findsNothing();
1135+
});
1136+
1137+
testWidgets('falls back to original text when user group not found', (tester) async {
1138+
await prepare(
1139+
tester: tester,
1140+
html: '<p><span class="user-group-mention" data-user-group-id="999">@Unknown Group</span></p>');
1141+
check(find.text('@Unknown Group')).findsOne();
1142+
});
1143+
1144+
testWidgets('handles silent mentions correctly', (tester) async {
1145+
await prepare(
1146+
tester: tester,
1147+
html: '<p><span class="user-group-mention silent" data-user-group-id="186">old-name</span></p>',
1148+
userGroups: [eg.userGroup(id: 186, name: 'new-name')]);
1149+
check(find.text('new-name')).findsOne();
1150+
check(find.text('@new-name')).findsNothing();
1151+
});
1152+
});
11141153
});
11151154

11161155
Future<void> tapText(WidgetTester tester, Finder textFinder) async {

0 commit comments

Comments
 (0)