Skip to content

Commit f544daa

Browse files
committed
emoji_reaction: Put "You" first in ReactionChip label; pull out helper
We'll use this for a semantics label, coming up.
1 parent 277397d commit f544daa

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

lib/widgets/emoji_reaction.dart

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:collection/collection.dart';
12
import 'package:flutter/material.dart';
23

34
import '../api/exception.dart';
@@ -6,6 +7,7 @@ import '../api/route/messages.dart';
67
import '../generated/l10n/zulip_localizations.dart';
78
import '../model/autocomplete.dart';
89
import '../model/emoji.dart';
10+
import '../model/store.dart';
911
import 'color.dart';
1012
import 'dialog.dart';
1113
import 'emoji.dart';
@@ -144,6 +146,22 @@ class ReactionChip extends StatelessWidget {
144146
required this.reactionWithVotes,
145147
});
146148

149+
// Linear in the number of voters (of course);
150+
// best to avoid calling this unless we know there are few voters.
151+
String _voterNames(PerAccountStore store, ZulipLocalizations zulipLocalizations) {
152+
final selfUserId = store.selfUserId;
153+
final userIds = reactionWithVotes.userIds;
154+
final result = <String>[];
155+
if (userIds.contains(selfUserId)) {
156+
result.add(zulipLocalizations.reactedEmojiSelfUser);
157+
}
158+
result.addAll(userIds.whereNot((userId) => userId == selfUserId).map(store.userDisplayName));
159+
// TODO(i18n): List formatting, like you can do in JavaScript:
160+
// new Intl.ListFormat('ja').format(['Chris', 'Greg', 'Alya', 'Shu'])
161+
// // 'Chris、Greg、Alya、Shu'
162+
return result.join(', ');
163+
}
164+
147165
@override
148166
Widget build(BuildContext context) {
149167
final store = PerAccountStoreWidget.of(context);
@@ -156,14 +174,7 @@ class ReactionChip extends StatelessWidget {
156174

157175
final selfVoted = userIds.contains(store.selfUserId);
158176
final label = showName
159-
// TODO(i18n): List formatting, like you can do in JavaScript:
160-
// new Intl.ListFormat('ja').format(['Chris', 'Greg', 'Alya', 'Shu'])
161-
// // 'Chris、Greg、Alya、Shu'
162-
? userIds.map((id) {
163-
return id == store.selfUserId
164-
? zulipLocalizations.reactedEmojiSelfUser
165-
: store.userDisplayName(id);
166-
}).join(', ')
177+
? _voterNames(store, zulipLocalizations)
167178
: userIds.length.toString();
168179

169180
final reactionTheme = EmojiReactionTheme.of(context);

0 commit comments

Comments
 (0)