Skip to content

Commit

Permalink
filter away emoji that was already selected
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisirhc committed Mar 15, 2024
1 parent 51dc759 commit cd4d8e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
9 changes: 9 additions & 0 deletions lib/emoji.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ final emojiSet = defaultEmojiSet.map((emojiCategory) =>
.map((emoji) =>
Emoji(emoji.emoji, getEmojiCanonicalName(emoji), hasSkinTone: emoji.hasSkinTone)).toList())).toList();

List<CategoryEmoji> filterUnicodeEmojiSet(List<CategoryEmoji> emojiSet, Iterable<String> emojiNamesToRemove) {
return emojiSet.map((categoryEmoji) =>
CategoryEmoji(
categoryEmoji.category,
categoryEmoji.emoji
.where((emoji) => !emojiNamesToRemove.contains(emoji.name))
.toList())).toList();
}

String getEmojiCanonicalName(Emoji emoji) {
final emojiCode = getEmojiCode(emoji);
final emojiName = emojiNameMaps[emojiCode];
Expand Down
26 changes: 15 additions & 11 deletions lib/widgets/action_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,12 @@ import 'store.dart';
///
/// Must have a [MessageListPage] ancestor.
void showMessageActionSheet({required BuildContext context, required Message message}) {
final store = PerAccountStoreWidget.of(context);

// The UI that's conditioned on this won't live-update during this appearance
// of the action sheet (we avoid calling composeBoxControllerOf in a build
// method; see its doc). But currently it will be constant through the life of
// any message list, so that's fine.
final isComposeBoxOffered = MessageListPage.composeBoxControllerOf(context) != null;

// TODO filter away reactions by current user
// final hasThumbsUpReactionVote = message.reactions
// ?.aggregated.any((reactionWithVotes) =>
// reactionWithVotes.reactionType == ReactionType.unicodeEmoji
// && reactionWithVotes.emojiCode == '1f44d'
// && reactionWithVotes.userIds.contains(store.selfUserId))
// ?? false;

showDraggableScrollableModalBottomSheet(
context: context,
builder: (BuildContext _) {
Expand Down Expand Up @@ -103,7 +93,9 @@ class AddReactionButton extends MessageActionSheetMenuItemButton {
padding: EdgeInsets.only(bottom: MediaQuery.of(emojiPickerContext).viewInsets.bottom),
child: EmojiPicker(
config: Config(
emojiSet: emojiSet,
checkPlatformCompatibility: false,
emojiSet: getEmojiToDisplay(),
// TODO figure out why tests fail without RecentTabBehavior.NONE
categoryViewConfig: const CategoryViewConfig(recentTabBehavior: RecentTabBehavior.NONE)),
onEmojiSelected: (_, Emoji? emoji) async {
if (emoji == null) {
Expand Down Expand Up @@ -142,6 +134,18 @@ class AddReactionButton extends MessageActionSheetMenuItemButton {
}));
});
};

/// Returns the emoji set to display in the emoji picker.
List<CategoryEmoji> getEmojiToDisplay() {
final selfUserId = PerAccountStoreWidget.of(messageListContext).selfUserId;
final selfUserUnicodeReactions = message.reactions
?.aggregated.where((reactionWithVotes) =>
reactionWithVotes.reactionType == ReactionType.unicodeEmoji
&& reactionWithVotes.userIds.contains(selfUserId))
.map((reactionWithVotes) => reactionWithVotes.emojiName);
return selfUserUnicodeReactions != null
? filterUnicodeEmojiSet(emojiSet, selfUserUnicodeReactions) : emojiSet;
}
}

class StarButton extends MessageActionSheetMenuItemButton {
Expand Down

0 comments on commit cd4d8e6

Please sign in to comment.