aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2017-12-02 20:52:30 +0100
committerDaniel Gultsch <daniel@gultsch.de>2017-12-02 20:52:30 +0100
commitffb3eeb9139f77a3d4465e207dac0fee51773cdd (patch)
tree33b5f9eb89703bda8cd380bb079f5b4bbefc6464
parentfc8a5641db962ae7df14e7aad4a6319d765c939d (diff)
MAM: update previously sent messages with server msg id during mam query
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Conversation.java10
-rw-r--r--src/main/java/eu/siacs/conversations/parser/MessageParser.java28
2 files changed, 32 insertions, 6 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java
index c0af689..301d2b8 100644
--- a/src/main/java/eu/siacs/conversations/entities/Conversation.java
+++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java
@@ -804,15 +804,19 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
return this.bookmark;
}
- public boolean hasDuplicateMessage(Message message) {
+ public Message findDuplicateMessage(Message message) {
synchronized (this.messages) {
for (int i = this.messages.size() - 1; i >= 0; --i) {
if (this.messages.get(i).similar(message)) {
- return true;
+ return this.messages.get(i);
}
}
}
- return false;
+ return null;
+ }
+
+ public boolean hasDuplicateMessage(Message message) {
+ return findDuplicateMessage(message) != null;
}
public Message findSentMessageWithBody(String body) {
diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
index 7fcf6b9..5458ecb 100644
--- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
@@ -474,6 +474,14 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (query == null && extractChatState(mXmppConnectionService.find(account, counterpart.toBareJid()), isTypeGroupChat, packet)) {
mXmppConnectionService.updateConversationUi();
}
+ if (query != null && status == Message.STATUS_SEND && remoteMsgId != null) {
+ Message previouslySent = conversation.findSentMessageWithUuid(remoteMsgId);
+ if (previouslySent != null && previouslySent.getServerMsgId() == null && serverMsgId != null) {
+ previouslySent.setServerMsgId(serverMsgId);
+ mXmppConnectionService.databaseBackend.updateMessage(previouslySent);
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": encountered previously sent OMEMO message without serverId. updating...");
+ }
+ }
return;
}
if (conversationMultiMode) {
@@ -577,9 +585,23 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
boolean checkForDuplicates = (isTypeGroupChat && packet.hasChild("delay", "urn:xmpp:delay"))
|| message.getType() == Message.TYPE_PRIVATE
|| message.getServerMsgId() != null;
- if (checkForDuplicates && conversation.hasDuplicateMessage(message)) {
- Log.d(Config.LOGTAG, "skipping duplicate message from " + message.getCounterpart().toString() + " " + message.getBody());
- return;
+ if (checkForDuplicates ) {
+ final Message duplicate = conversation.findDuplicateMessage(message);
+ if (duplicate != null) {
+ final boolean serverMsgIdUpdated;
+ if (duplicate.getStatus() != Message.STATUS_RECEIVED
+ && duplicate.getUuid().equals(message.getRemoteMsgId())
+ && duplicate.getServerMsgId() == null
+ && message.getServerMsgId() != null) {
+ duplicate.setServerMsgId(message.getServerMsgId());
+ mXmppConnectionService.databaseBackend.updateMessage(message);
+ serverMsgIdUpdated = true;
+ } else {
+ serverMsgIdUpdated = false;
+ }
+ Log.d(Config.LOGTAG, "skipping duplicate message with " + message.getCounterpart()+". serverMsgIdUpdated="+Boolean.toString(serverMsgIdUpdated));
+ return;
+ }
}
if (query != null && query.getPagingOrder() == MessageArchiveService.PagingOrder.REVERSE) {