From c61be892628ed4f131f8bbe6c5b660e912a7a95a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 12 Apr 2018 09:50:33 +0200 Subject: [PATCH] keep track of user object in messages --- .../eu/siacs/conversations/entities/Message.java | 12 ++++++++++++ .../eu/siacs/conversations/parser/MessageParser.java | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index 129895ecb..cfc61ee69 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -4,6 +4,7 @@ import android.content.ContentValues; import android.database.Cursor; import android.text.SpannableStringBuilder; +import java.lang.ref.WeakReference; import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; @@ -102,6 +103,7 @@ public class Message extends AbstractEntity { private Boolean treatAsDownloadable = null; private FileParams fileParams = null; private List counterparts; + private WeakReference user; private Message(Conversation conversation) { this.conversation = conversation; @@ -313,6 +315,16 @@ public class Message extends AbstractEntity { this.fileParams = null; } + public void setMucUser(MucOptions.User user) { + this.user = new WeakReference<>(user); + } + + public boolean sameMucUser(Message otherMessage) { + final MucOptions.User thisUser = this.user == null ? null : this.user.get(); + final MucOptions.User otherUser = otherMessage.user == null ? null : otherMessage.user.get(); + return thisUser != null && thisUser == otherUser; + } + public String getErrorMessage() { return errorMessage; } diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 44ef7bf83..b4f61796d 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -430,6 +430,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0"); if (conversationMultiMode) { + message.setMucUser(conversation.getMucOptions().findUserByFullJid(message.getCounterpart())); final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart); Jid trueCounterpart; if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) { @@ -461,8 +462,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece || replacedMessage.getFingerprint().equals(message.getFingerprint()); final boolean trueCountersMatch = replacedMessage.getTrueCounterpart() != null && replacedMessage.getTrueCounterpart().equals(message.getTrueCounterpart()); + final boolean mucUserMatches = query == null && replacedMessage.sameMucUser(message); //can not be checked when using mam final boolean duplicate = conversation.hasDuplicateMessage(message); - if (fingerprintsMatch && (trueCountersMatch || !conversationMultiMode) && !duplicate) { + if (fingerprintsMatch && (trueCountersMatch || !conversationMultiMode || !mucUserMatches) && !duplicate) { Log.d(Config.LOGTAG, "replaced message '" + replacedMessage.getBody() + "' with '" + message.getBody() + "'"); synchronized (replacedMessage) { final String uuid = replacedMessage.getUuid();