Skip to content

Commit 5ecbf46

Browse files
committed
filter away emoji that was already selected
1 parent f727c54 commit 5ecbf46

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

lib/emoji.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ final emojiSet = defaultEmojiSet.map((emojiCategory) =>
88
.map((emoji) =>
99
Emoji(emoji.emoji, getEmojiCanonicalName(emoji), hasSkinTone: emoji.hasSkinTone)).toList())).toList();
1010

11+
List<CategoryEmoji> filterUnicodeEmojiSet(List<CategoryEmoji> emojiSet, Iterable<String> emojiNamesToRemove) {
12+
return emojiSet.map((categoryEmoji) =>
13+
CategoryEmoji(
14+
categoryEmoji.category,
15+
categoryEmoji.emoji
16+
.where((emoji) => !emojiNamesToRemove.contains(emoji.name))
17+
.toList())).toList();
18+
}
19+
1120
String getEmojiCanonicalName(Emoji emoji) {
1221
final emojiCode = getEmojiCode(emoji);
1322
final emojiName = emojiNameMaps[emojiCode];

lib/widgets/action_sheet.dart

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,12 @@ import 'store.dart';
2020
///
2121
/// Must have a [MessageListPage] ancestor.
2222
void showMessageActionSheet({required BuildContext context, required Message message}) {
23-
final store = PerAccountStoreWidget.of(context);
24-
2523
// The UI that's conditioned on this won't live-update during this appearance
2624
// of the action sheet (we avoid calling composeBoxControllerOf in a build
2725
// method; see its doc). But currently it will be constant through the life of
2826
// any message list, so that's fine.
2927
final isComposeBoxOffered = MessageListPage.composeBoxControllerOf(context) != null;
3028

31-
// TODO filter away reactions by current user
32-
// final hasThumbsUpReactionVote = message.reactions
33-
// ?.aggregated.any((reactionWithVotes) =>
34-
// reactionWithVotes.reactionType == ReactionType.unicodeEmoji
35-
// && reactionWithVotes.emojiCode == '1f44d'
36-
// && reactionWithVotes.userIds.contains(store.selfUserId))
37-
// ?? false;
38-
3929
showDraggableScrollableModalBottomSheet(
4030
context: context,
4131
builder: (BuildContext _) {
@@ -103,7 +93,9 @@ class AddReactionButton extends MessageActionSheetMenuItemButton {
10393
padding: EdgeInsets.only(bottom: MediaQuery.of(emojiPickerContext).viewInsets.bottom),
10494
child: EmojiPicker(
10595
config: Config(
106-
emojiSet: emojiSet,
96+
checkPlatformCompatibility: false,
97+
emojiSet: getEmojiToDisplay(),
98+
// TODO figure out why tests fail without RecentTabBehavior.NONE
10799
categoryViewConfig: const CategoryViewConfig(recentTabBehavior: RecentTabBehavior.NONE)),
108100
onEmojiSelected: (_, Emoji? emoji) async {
109101
if (emoji == null) {
@@ -142,6 +134,18 @@ class AddReactionButton extends MessageActionSheetMenuItemButton {
142134
}));
143135
});
144136
};
137+
138+
/// Returns the emoji set to display in the emoji picker.
139+
List<CategoryEmoji> getEmojiToDisplay() {
140+
final selfUserId = PerAccountStoreWidget.of(messageListContext).selfUserId;
141+
final selfUserUnicodeReactions = message.reactions
142+
?.aggregated.where((reactionWithVotes) =>
143+
reactionWithVotes.reactionType == ReactionType.unicodeEmoji
144+
&& reactionWithVotes.userIds.contains(selfUserId))
145+
.map((reactionWithVotes) => reactionWithVotes.emojiName);
146+
return selfUserUnicodeReactions != null
147+
? filterUnicodeEmojiSet(emojiSet, selfUserUnicodeReactions) : emojiSet;
148+
}
145149
}
146150

147151
class StarButton extends MessageActionSheetMenuItemButton {

0 commit comments

Comments
 (0)