1
+ import 'package:collection/collection.dart' ;
1
2
import 'package:flutter/material.dart' ;
2
3
3
4
import '../api/exception.dart' ;
@@ -6,6 +7,7 @@ import '../api/route/messages.dart';
6
7
import '../generated/l10n/zulip_localizations.dart' ;
7
8
import '../model/autocomplete.dart' ;
8
9
import '../model/emoji.dart' ;
10
+ import '../model/store.dart' ;
9
11
import 'color.dart' ;
10
12
import 'dialog.dart' ;
11
13
import 'emoji.dart' ;
@@ -144,6 +146,22 @@ class ReactionChip extends StatelessWidget {
144
146
required this .reactionWithVotes,
145
147
});
146
148
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
+
147
165
@override
148
166
Widget build (BuildContext context) {
149
167
final store = PerAccountStoreWidget .of (context);
@@ -156,14 +174,7 @@ class ReactionChip extends StatelessWidget {
156
174
157
175
final selfVoted = userIds.contains (store.selfUserId);
158
176
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)
167
178
: userIds.length.toString ();
168
179
169
180
final reactionTheme = EmojiReactionTheme .of (context);
0 commit comments