From 5a00b115943d38a5d9fed81ed612cbd479aa763d Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 6 Mar 2017 13:30:13 +0100 Subject: [PATCH] extract stanza-id from muc reflections --- .../conversations/parser/MessageParser.java | 36 ++++++++++--------- .../services/XmppConnectionService.java | 5 ++- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index b52091cdf..f9a13d4d3 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -212,6 +212,20 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece return null; } + private static String extractStanzaid(Element packet, boolean isTypeGroupChat, Conversation conversation) { + final Jid by; + final boolean safeToExtract; + if (isTypeGroupChat) { + by = conversation.getJid().toBareJid(); + safeToExtract = conversation.getMucOptions().hasFeature(Namespace.STANZA_IDS); + } else { + Account account = conversation.getAccount(); + by = account.getJid().toBareJid(); + safeToExtract = account.getXmppConnection().getFeatures().stanzaIds(); + } + return safeToExtract ? extractStanzaId(packet, by) : null; + } + private static String extractStanzaId(Element packet, Jid by) { for(Element child : packet.getChildren()) { if (child.getName().equals("stanza-id") @@ -385,11 +399,16 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if ((body != null || pgpEncrypted != null || axolotlEncrypted != null) && !isMucStatusMessage) { Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, false, query); final boolean conversationMultiMode = conversation.getMode() == Conversation.MODE_MULTI; + + if (serverMsgId == null) { + extractStanzaid(packet, isTypeGroupChat, conversation); + } + if (isTypeGroupChat) { if (counterpart.getResourcepart().equals(conversation.getMucOptions().getActualNick())) { status = Message.STATUS_SEND_RECEIVED; isCarbon = true; //not really carbon but received from another resource - if (mXmppConnectionService.markMessage(conversation, remoteMsgId, status)) { + if (mXmppConnectionService.markMessage(conversation, remoteMsgId, status, serverMsgId)) { return; } else if (remoteMsgId == null || Config.IGNORE_ID_REWRITE_IN_MUC) { Message message = conversation.findSentMessageWithBody(packet.getBody()); @@ -438,21 +457,6 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece message = new Message(conversation, body, Message.ENCRYPTION_NONE, status); } - if (serverMsgId == null) { - final Jid by; - final boolean safeToExtract; - if (isTypeGroupChat) { - by = conversation.getJid().toBareJid(); - safeToExtract = conversation.getMucOptions().hasFeature(Namespace.STANZA_IDS); - } else { - by = account.getJid().toBareJid(); - safeToExtract = account.getXmppConnection().getFeatures().stanzaIds(); - } - if (safeToExtract) { - serverMsgId = extractStanzaId(packet, by); - } - } - message.setCounterpart(counterpart); message.setRemoteMsgId(remoteMsgId); message.setServerMsgId(serverMsgId); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 9242f4197..b9c460d15 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -3180,12 +3180,15 @@ public class XmppConnectionService extends Service { return null; } - public boolean markMessage(Conversation conversation, String uuid, int status) { + public boolean markMessage(Conversation conversation, String uuid, int status, String serverMessageId) { if (uuid == null) { return false; } else { Message message = conversation.findSentMessageWithUuid(uuid); if (message != null) { + if (message.getServerMsgId() == null) { + message.setServerMsgId(serverMessageId); + } markMessage(message, status); return true; } else {