From 85f06f1cd6a3e019a2ec8c8b664b823bf1989a80 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 2 May 2022 08:29:51 +0200 Subject: [PATCH] do not merge failed decryptions fixes #4314 --- .../java/eu/siacs/conversations/entities/Message.java | 10 ++++++++-- .../conversations/services/XmppConnectionService.java | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index fa1819124..e50ffc73c 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -14,6 +14,7 @@ import org.json.JSONException; import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Set; @@ -633,9 +634,8 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED && this.getType() == message.getType() && - //this.getStatus() == message.getStatus() && isStatusMergeable(this.getStatus(), message.getStatus()) && - this.getEncryption() == message.getEncryption() && + isEncryptionMergeable(this.getEncryption(),message.getEncryption()) && this.getCounterpart() != null && this.getCounterpart().equals(message.getCounterpart()) && this.edited() == message.edited() && @@ -668,6 +668,12 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable ); } + private static boolean isEncryptionMergeable(final int a, final int b) { + return a == b + && Arrays.asList(ENCRYPTION_NONE, ENCRYPTION_DECRYPTED, ENCRYPTION_AXOLOTL) + .contains(a); + } + public void setCounterparts(List counterparts) { this.counterparts = counterparts; } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 0f121b0b3..7965a4e31 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -4128,7 +4128,7 @@ public class XmppConnectionService extends Service { } public void updateAccountUi() { - for (OnAccountUpdate listener : threadSafeList(this.mOnAccountUpdates)) { + for (final OnAccountUpdate listener : threadSafeList(this.mOnAccountUpdates)) { listener.onAccountUpdate(); } }