1
0
Fork 1

Add fallbacks for reactions

(cherry picked from commit 65408bb56067c10e69821cb99e0d69340584fc42)
This commit is contained in:
Stephen Paul Weber 2024-09-30 14:20:49 -05:00 committed by Arne
parent ff98748d5c
commit 756d8aa9e1
2 changed files with 20 additions and 2 deletions

View file

@ -17,6 +17,8 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Conversational;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.util.QuoteHelper;
import eu.siacs.conversations.utils.MessageUtils;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xml.Namespace;
@ -234,7 +236,7 @@ public class MessageGenerator extends AbstractGenerator {
return packet;
}
public im.conversations.android.xmpp.model.stanza.Message reaction(final Conversational conversation, 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 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();
@ -245,6 +247,22 @@ public class MessageGenerator extends AbstractGenerator {
for(final String ourReaction : ourReactions) {
reactions.addExtension(new Reaction(ourReaction));
}
final var quote = QuoteHelper.quote(MessageUtils.prepareQuote(inReplyTo)) + "\n";
packet.setBody(quote + String.join(" ", ourReactions));
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")
.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");
packet.addChild("store", "urn:xmpp:hints");
return packet;
}

View file

@ -5411,7 +5411,7 @@ public class XmppConnectionService extends Service {
return false;
}
final var reactionMessage =
mMessageGenerator.reaction(conversation, reactToId, reactions);
mMessageGenerator.reaction(conversation, message, reactToId, reactions);
sendMessagePacket(conversation.getAccount(), reactionMessage);
message.setReactions(combinedReactions);
updateMessage(message, false);