From c78cef6164eb261f9cdddad0a20549ca79707359 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Fri, 4 Oct 2024 21:37:52 -0500 Subject: [PATCH] Less nosiy fallback for reactions Show only the added emoji and nothing on removal (cherry picked from commit c574ac73ccb47dfa8210bd8ca7c9e6c063d36eb2) --- .../generator/MessageGenerator.java | 18 ++++++++++-------- .../services/XmppConnectionService.java | 4 +++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java index a6b5dd43b..a3b8552e5 100644 --- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java @@ -236,7 +236,7 @@ public class MessageGenerator extends AbstractGenerator { return packet; } - public im.conversations.android.xmpp.model.stanza.Message reaction(final Conversational conversation, final Message inReplyTo, final String reactingTo, final Collection ourReactions) { + public im.conversations.android.xmpp.model.stanza.Message reaction(final Conversational conversation, final Message inReplyTo, final String reactingTo, final Collection ourReactions, final Collection newReactions) { final boolean groupChat = conversation.getMode() == Conversational.MODE_MULTI; final Jid to = conversation.getJid().asBareJid(); final im.conversations.android.xmpp.model.stanza.Message packet = new im.conversations.android.xmpp.model.stanza.Message(); @@ -248,20 +248,22 @@ public class MessageGenerator extends AbstractGenerator { reactions.addExtension(new Reaction(ourReaction)); } - final var quote = QuoteHelper.quote(MessageUtils.prepareQuote(inReplyTo)) + "\n"; - packet.setBody(quote + String.join(" ", ourReactions)); + if (newReactions.size() > 0) { + final var quote = QuoteHelper.quote(MessageUtils.prepareQuote(inReplyTo)) + "\n"; + packet.setBody(quote + String.join(" ", newReactions)); - packet.addChild("reply", "urn:xmpp:reply:0") + packet.addChild("reply", "urn:xmpp:reply:0") .setAttribute("to", inReplyTo.getCounterpart()) .setAttribute("id", reactingTo); - final var replyFallback = packet.addChild("fallback", "urn:xmpp:fallback:0").setAttribute("for", "urn:xmpp:reply:0"); - replyFallback.addChild("body", "urn:xmpp:fallback:0") + final var replyFallback = packet.addChild("fallback", "urn:xmpp:fallback:0").setAttribute("for", "urn:xmpp:reply:0"); + replyFallback.addChild("body", "urn:xmpp:fallback:0") .setAttribute("start", "0") .setAttribute("end", "" + quote.codePointCount(0, quote.length())); - final var fallback = packet.addChild("fallback", "urn:xmpp:fallback:0").setAttribute("for", "urn:xmpp:reactions:0"); - fallback.addChild("body", "urn:xmpp:fallback:0"); + final var fallback = packet.addChild("fallback", "urn:xmpp:fallback:0").setAttribute("for", "urn:xmpp:reactions:0"); + fallback.addChild("body", "urn:xmpp:fallback:0"); + } final var thread = inReplyTo.getThread(); if (thread != null) packet.addChild(thread); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index b34973e45..0ccad241d 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -5378,6 +5378,8 @@ public class XmppConnectionService extends Service { if (message.getConversation() instanceof Conversation conversation) { final String reactToId; final Collection combinedReactions; + final var newReactions = new HashSet<>(reactions); + newReactions.removeAll(message.getAggregatedReactions().ourReactions); if (conversation.getMode() == Conversational.MODE_MULTI) { final var self = conversation.getMucOptions().getSelf(); final String occupantId = self.getOccupantId(); @@ -5409,7 +5411,7 @@ public class XmppConnectionService extends Service { return false; } final var reactionMessage = - mMessageGenerator.reaction(conversation, message, reactToId, reactions); + mMessageGenerator.reaction(conversation, message, reactToId, reactions, newReactions); sendMessagePacket(conversation.getAccount(), reactionMessage); message.setReactions(combinedReactions); updateMessage(message, false);