Daniel Brötzmann pushed to branch reactions at gajim / gajim
Commits: e93db547 by wurstsalat at 2024-05-18T23:50:05+02:00 imprv: Reactions: Don't toggle reactions when sent from emoji chooser - - - - - 4 changed files: - gajim/common/util/text.py - gajim/gtk/conversation/reactions_bar.py - gajim/gtk/conversation/rows/message.py - gajim/gtk/conversation/rows/widgets.py Changes: ===================================== gajim/common/util/text.py ===================================== @@ -86,10 +86,9 @@ def normalize_reactions(reactions: list[str]) -> tuple[set[str], set[str]]: # performance problems when loading and displaying them. reactions = reactions[:10] for reaction in reactions: - # Remote emoji variant selectors they are not needed because - # reactions need to be always shown in emoji representation - # Further it allows us to make them equal with the version - # without selector + # Remove emoji variant selectors. They are not needed because + # reactions are required to be shown as emoji representation. + # Furthermore it allows us to unify both versions. reaction = reaction.strip('\uFE0E\uFE0F') if not emoji.is_emoji(reaction): invalid.add(reaction) ===================================== gajim/gtk/conversation/reactions_bar.py ===================================== @@ -96,7 +96,7 @@ def _on_reaction_clicked(self, reaction_button: ReactionButton) -> None: self._message_row.send_reaction(reaction_button.emoji) def _on_emoji_added(self, _widget: AddReactionButton, emoji: str) -> None: - self._message_row.send_reaction(emoji) + self._message_row.send_reaction(emoji, toggle=False) def update_from_reactions(self, reactions: list[mod.Reaction]) -> None: for widget in self.get_children(): ===================================== gajim/gtk/conversation/rows/message.py ===================================== @@ -458,7 +458,13 @@ def update_reactions(self) -> None: self.refresh(complete=False) self._reactions_bar.update_from_reactions(self._original_message.reactions) - def send_reaction(self, emoji: str) -> None: + def send_reaction(self, emoji: str, toggle: bool = True) -> None: + '''Adds or removes 'emoji' from this message's reactions and sends the result. + + Args: + emoji: Reaction emoji to add or remove + toggle: Whether an existing emoji should be removed from the set + ''' reaction_id = self.message_id if self._original_message.type == MessageType.GROUPCHAT: reaction_id = self.stanza_id @@ -467,7 +473,14 @@ def send_reaction(self, emoji: str) -> None: log.warning('No reaction id') return + # Remove emoji variant selectors + emoji = emoji.strip('\uFE0E\uFE0F') + our_reactions = self.get_our_reactions() + if emoji in our_reactions and not toggle: + log.info('Not toggling reaction <%s>', emoji) + return + if emoji in our_reactions: our_reactions.discard(emoji) else: ===================================== gajim/gtk/conversation/rows/widgets.py ===================================== @@ -152,10 +152,9 @@ def _get_reactions_visible(self) -> bool: return True def _hide(self) -> None: - if self._has_cursor: + if self._has_cursor or self._message_row is None: return - assert self._message_row is not None self._message_row.get_style_context().remove_class('conversation-row-hover') self._timeout_id = None @@ -202,11 +201,11 @@ def _on_choose_reaction_button_clicked(self, _button: AddReactionButton) -> None def _on_reaction_added(self, _widget: AddReactionButton, emoji: str) -> None: self._menu_button_clicked = False - self._send_reaction(emoji) + self._send_reaction(emoji, toggle=False) - def _send_reaction(self, emoji: str) -> None: + def _send_reaction(self, emoji: str, toggle: bool = True) -> None: assert self._message_row is not None - self._message_row.send_reaction(emoji) + self._message_row.send_reaction(emoji, toggle) def _on_more_clicked(self, button: Gtk.Button) -> None: assert self._message_row is not None View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/e93db547057ada058c57e9abcb541fc0dd2b56e9 -- View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/e93db547057ada058c57e9abcb541fc0dd2b56e9 You're receiving this email because of your account on dev.gajim.org.
_______________________________________________ Commits mailing list -- commits@gajim.org To unsubscribe send an email to commits-le...@gajim.org