Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msglist: Add double-tap to toggle thumbs up reaction. #1307

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

E-m-i-n-e-n-c-e
Copy link

@E-m-i-n-e-n-c-e E-m-i-n-e-n-c-e commented Jan 25, 2025

This PR adds the ability to double-tap messages to quickly add/remove 👍 reactions

Closes #969.

Video:

20250125-0900-02.5007496.mp4

I placed the double tap gesture in the same gesture detector that detects the long press to open message action sheet. Reused the same logic that is being used to add or remove reactions in message action sheet. So it should handle all cases correctly

      onDoubleTap: () {
        // Access the PerAccountStore to get user-specific data.
        final store = PerAccountStoreWidget.of(context);
        // First emoji in popular Candidates is thumbs up
        final thumbsUpEmoji = EmojiStore.popularEmojiCandidates.toList()[0];
        // Check if the user has already reacted with thumbs up
        // Uses the same logic as hasSelfVote() in action_sheet.dart
        final isSelfVoted = message.reactions?.aggregated.any((reactionWithVotes) =>
          reactionWithVotes.reactionType == ReactionType.unicodeEmoji
          && reactionWithVotes.emojiCode == thumbsUpEmoji.emojiCode
          && reactionWithVotes.userIds.contains(store.selfUserId)) ?? false;

        // Get the localizations for the current context to display appropriate messages.
        final zulipLocalizations = ZulipLocalizations.of(context);

        // Call the function to add or remove the reaction based on the user's current state.
        doAddOrRemoveReaction(
          context: context,
          doRemoveReaction: isSelfVoted,
          messageId: message.id,
          emoji: thumbsUpEmoji,
          errorDialogTitle: isSelfVoted
            ? zulipLocalizations.errorReactionRemovingFailedTitle
            : zulipLocalizations.errorReactionAddingFailedTitle);
      },

Edit:

Added 4 tests under the group 'double-tap gesture' to the message_list_test.dart file

  • add thumbs up reaction on double-tap
  • remove thumbs up reaction on double-tap when already reacted
  • shows error dialog when adding reaction fails
  • shows error dialog when removing reaction fails

Again reused the same logic that was being used to test reaction adding and removing in message action sheet ;)

@E-m-i-n-e-n-c-e E-m-i-n-e-n-c-e force-pushed the DoubleTap branch 2 times, most recently from 078c29f to 9ca66c9 Compare January 27, 2025 14:45
Add ability to double-tap messages to quickly add/remove 👍 reactions

Fixes zulip#969.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Double-tap message to add 👍 reaction
1 participant