From be4953b1e477c693df58e58e7e03ad467239ced4 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 13 Sep 2019 16:38:15 +0200 Subject: [PATCH] parse LMC 1.1 --- .../java/eu/siacs/conversations/Config.java | 2 ++ .../conversations/entities/Conversation.java | 10 +++------- .../siacs/conversations/entities/Message.java | 17 +++++++++++++++++ .../generator/MessageGenerator.java | 2 +- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index 0b43675ad..ac637d76f 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -116,6 +116,8 @@ public final class Config { public static final boolean IGNORE_ID_REWRITE_IN_MUC = true; public static final boolean MUC_LEAVE_BEFORE_JOIN = true; + public static final boolean USE_LMC_VERSION_1_1 = false; + public static final long MAM_MAX_CATCHUP = MILLISECONDS_IN_DAY * 5; public static final int MAM_MAX_MESSAGES = 750; diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 2004953ee..bd0d4bcd2 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -2,7 +2,6 @@ package eu.siacs.conversations.entities; import android.content.ContentValues; import android.database.Cursor; -import android.graphics.Color; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; @@ -13,23 +12,19 @@ import org.json.JSONObject; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.ListIterator; -import java.util.Locale; import java.util.concurrent.atomic.AtomicBoolean; import eu.siacs.conversations.Config; import eu.siacs.conversations.crypto.OmemoSetting; import eu.siacs.conversations.crypto.PgpDecryptionService; -import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.persistance.DatabaseBackend; import eu.siacs.conversations.services.AvatarService; import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.utils.JidHelper; import eu.siacs.conversations.utils.UIHelper; -import eu.siacs.conversations.xmpp.InvalidJid; import eu.siacs.conversations.xmpp.chatstate.ChatState; import eu.siacs.conversations.xmpp.mam.MamReference; import rocks.xmpp.addr.Jid; @@ -311,11 +306,12 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public Message findMessageWithRemoteIdAndCounterpart(String id, Jid counterpart, boolean received, boolean carbon) { synchronized (this.messages) { for (int i = this.messages.size() - 1; i >= 0; --i) { - Message message = messages.get(i); + final Message message = messages.get(i); if (counterpart.equals(message.getCounterpart()) && ((message.getStatus() == Message.STATUS_RECEIVED) == received) && (carbon == message.isCarbon() || received)) { - if (id.equals(message.getRemoteMsgId()) && !message.isFileOrImage() && !message.treatAsDownloadable()) { + final boolean idMatch = id.equals(message.getRemoteMsgId()) || message.remoteMsgIdMatchInEdit(id); + if (idMatch && !message.isFileOrImage() && !message.treatAsDownloadable()) { return message; } else { return null; diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index c18693976..2035d8ac8 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -437,6 +437,15 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable this.edits.add(new Edited(edited, serverMsgId)); } + public boolean remoteMsgIdMatchInEdit(String id) { + for(Edited edit : this.edits) { + if (id.equals(edit.getEditedId())) { + return true; + } + } + return false; + } + public String getBodyLanguage() { return this.bodyLanguage; } @@ -732,6 +741,14 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable } } + public String getEditedIdWireFormat() { + if (edits.size() > 0) { + return edits.get(Config.USE_LMC_VERSION_1_1 ? 0 : edits.size() - 1).getEditedId(); + } else { + throw new IllegalStateException("Attempting to store unedited message"); + } + } + public void setOob(boolean isOob) { this.oob = isOob; } diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java index 771ebccdc..8f56d39bb 100644 --- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java @@ -58,7 +58,7 @@ public class MessageGenerator extends AbstractGenerator { packet.setId(message.getUuid()); packet.addChild("origin-id", Namespace.STANZA_IDS).setAttribute("id", message.getUuid()); if (message.edited()) { - packet.addChild("replace", "urn:xmpp:message-correct:0").setAttribute("id", message.getEditedId()); + packet.addChild("replace", "urn:xmpp:message-correct:0").setAttribute("id", message.getEditedIdWireFormat()); } return packet; }