Less nosiy fallback for reactions

Show only the added emoji and nothing on removal

(cherry picked from commit c574ac73ccb47dfa8210bd8ca7c9e6c063d36eb2)
This commit is contained in:
Stephen Paul Weber 2024-10-04 21:37:52 -05:00 committed by Arne
parent 841a0ed909
commit c78cef6164
2 changed files with 13 additions and 9 deletions

View file

@ -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<String> ourReactions) {
public im.conversations.android.xmpp.model.stanza.Message reaction(final Conversational conversation, final Message inReplyTo, final String reactingTo, final Collection<String> ourReactions, final Collection<String> 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);

View file

@ -5378,6 +5378,8 @@ public class XmppConnectionService extends Service {
if (message.getConversation() instanceof Conversation conversation) {
final String reactToId;
final Collection<Reaction> 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);