Skip to content

Commit 3089187

Browse files
Add '(you)' label for self in new DM user list
Wrap in WidgetSpan with ExcludeSemantics so screen readers ignore it.
1 parent 2fc0e8c commit 3089187

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lib/widgets/new_dm_sheet.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ class _NewDmUserListItem extends StatelessWidget {
395395
Widget build(BuildContext context) {
396396
final store = PerAccountStoreWidget.of(context);
397397
final designVariables = DesignVariables.of(context);
398+
final selfUserId = store.selfUserId ;
399+
final labelColor = designVariables.labelMenuButton ;
398400
return Material(
399401
clipBehavior: Clip.antiAlias,
400402
borderRadius: BorderRadius.circular(10),
@@ -421,9 +423,14 @@ class _NewDmUserListItem extends StatelessWidget {
421423
SizedBox(width: 8),
422424
Expanded(
423425
child: Text.rich(
424-
TextSpan(text: store.userDisplayName(userId), children: [
426+
TextSpan(text: store.userDisplayName(userId),children: [
427+
if (userId == selfUserId)WidgetSpan (
428+
alignment: PlaceholderAlignment.middle,
429+
child:ExcludeSemantics(child: Text(' (you)',
430+
style: TextStyle(
431+
color: labelColor.withValues(alpha: 0.6))))),
425432
UserStatusEmoji.asWidgetSpan(userId: userId, fontSize: 17,
426-
textScaler: MediaQuery.textScalerOf(context)),
433+
textScaler: MediaQuery.textScalerOf(context),),
427434
]),
428435
style: TextStyle(
429436
fontSize: 17,

test/widgets/new_dm_sheet_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,35 @@ void main() {
136136
check(find.byIcon(ZulipIcons.check_circle_checked)).findsNothing();
137137
});
138138

139+
testWidgets('shows (you) label for self user in new DM list', (tester) async {
140+
final self = eg.user(fullName: 'Self User',email: '[email protected]');
141+
final other = eg.user(fullName: 'Other User',email: '[email protected]');
142+
await setupSheet(tester, selfUser: self, users: [self, other]);
143+
// Self user's name is shown
144+
check(findText(includePlaceholders: false, 'Self User')).findsOne();
145+
// "(you)" label is shown for self
146+
final youTextFinder = find.byWidgetPredicate(
147+
(w) => w is Text && (w.data?.contains('(you)') ?? false));
148+
check(youTextFinder).findsOne();
149+
// Other user does NOT get "(you)"
150+
check(findText(includePlaceholders: false, 'Other User')).findsOne();
151+
});
152+
153+
testWidgets('does not show (you) label for non-self users', (tester) async {
154+
final self = eg.user(fullName: 'Self User',email: '[email protected]');
155+
final other = eg.user(fullName: 'Other User',email: '[email protected]');
156+
await setupSheet(tester, selfUser: self, users: [other]);
157+
await tester.pump();
158+
// Other user's name is shown
159+
check(findText(includePlaceholders: false, 'Other User')).findsOne();
160+
// "(you)" must not appear at all
161+
final otherRow = find.ancestor(
162+
of: findText(includePlaceholders: false, 'Other User'),matching: find.byType(Row));
163+
final youInOtherRow = find.descendant(of: otherRow, matching: find.byWidgetPredicate(
164+
(w) => w is Text && (w.data?.contains('(you)') ?? false)));
165+
check(youInOtherRow).findsNothing();
166+
});
167+
139168
testWidgets('shows filtered users based on search', (tester) async {
140169
await setupSheet(tester, users: testUsers);
141170
await tester.enterText(find.byType(TextField), 'Alice');

0 commit comments

Comments
 (0)