From 0aea68741122a0518dce2455e2011854c37722cf Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 30 Sep 2024 15:21:10 -0500 Subject: [PATCH] Reply with a single emoji is a reaction (cherry picked from commit ba47a5f1639fdb0b8d2a1b3a8cd89bb2c9eef931) --- .../conversations/entities/Reaction.java | 29 ++++++++++++- .../conversations/parser/MessageParser.java | 41 ++++++++++++++++++- 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Reaction.java b/src/main/java/eu/siacs/conversations/entities/Reaction.java index eff7be74b..67d169374 100644 --- a/src/main/java/eu/siacs/conversations/entities/Reaction.java +++ b/src/main/java/eu/siacs/conversations/entities/Reaction.java @@ -82,6 +82,21 @@ public class Reaction { } } + public static Collection append( + final Collection existing, + final Collection reactions, + final boolean received, + final Jid from, + final Jid trueJid, + final String occupantId) { + final ImmutableSet.Builder builder = new ImmutableSet.Builder<>(); + builder.addAll(existing); + builder.addAll( + Collections2.transform( + reactions, r -> new Reaction(r, received, from, trueJid, occupantId))); + return builder.build(); + } + public static Collection withOccupantId( final Collection existing, final Collection reactions, @@ -89,7 +104,7 @@ public class Reaction { final Jid from, final Jid trueJid, final String occupantId) { - final ImmutableList.Builder builder = new ImmutableList.Builder<>(); + final ImmutableSet.Builder builder = new ImmutableSet.Builder<>(); builder.addAll(Collections2.filter(existing, e -> !occupantId.equals(e.occupantId))); builder.addAll( Collections2.transform( @@ -109,12 +124,22 @@ public class Reaction { .toString(); } + public int hashCode() { + return toString().hashCode(); + } + + public boolean equals(Object o) { + if (o == null) return false; + if (!(o instanceof Reaction)) return false; + return toString().equals(o.toString()); + } + public static Collection withFrom( final Collection existing, final Collection reactions, final boolean received, final Jid from) { - final ImmutableList.Builder builder = new ImmutableList.Builder<>(); + final ImmutableSet.Builder builder = new ImmutableSet.Builder<>(); builder.addAll( Collections2.filter(existing, e -> !from.asBareJid().equals(e.from.asBareJid()))); builder.addAll( diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index a27c139b9..d511360b6 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -59,6 +59,7 @@ import eu.siacs.conversations.services.MessageArchiveService; import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.CryptoHelper; +import eu.siacs.conversations.utils.Emoticons; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.LocalizedContent; import eu.siacs.conversations.xml.Namespace; @@ -574,7 +575,6 @@ public class MessageParser extends AbstractParser implements Consumer