From 07a71d312a8eaaa9b43686905c804dec99c34cef Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 31 Oct 2016 12:07:08 +0100 Subject: extracting stanza-id where by=account --- .../eu/siacs/conversations/parser/MessageParser.java | 16 ++++++++++++++-- src/main/java/eu/siacs/conversations/utils/Xmlns.java | 1 + .../java/eu/siacs/conversations/xmpp/XmppConnection.java | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 0fea84be..eaed0fbc 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -31,6 +31,7 @@ import eu.siacs.conversations.http.HttpConnectionManager; import eu.siacs.conversations.services.MessageArchiveService; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.CryptoHelper; +import eu.siacs.conversations.utils.Xmlns; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.OnMessagePacketReceived; import eu.siacs.conversations.xmpp.chatstate.ChatState; @@ -208,7 +209,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece private static String extractStanzaId(Element packet, Jid by) { for(Element child : packet.getChildren()) { if (child.getName().equals("stanza-id") - && "urn:xmpp:sid:0".equals(child.getNamespace()) + && Xmlns.STANZA_IDS.equals(child.getNamespace()) && by.equals(child.getAttributeAsJid("by"))) { return child.getAttribute("id"); } @@ -430,7 +431,18 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } if (serverMsgId == null) { - serverMsgId = extractStanzaId(packet, isTypeGroupChat ? conversation.getJid().toBareJid() : account.getServer()); + final Jid by; + final boolean safeToExtract; + if (isTypeGroupChat) { + by = conversation.getJid().toBareJid(); + safeToExtract = true; //conversation.getMucOptions().hasFeature(Xmlns.STANZA_IDS); + } else { + by = account.getJid().toBareJid(); + safeToExtract = true; //account.getXmppConnection().getFeatures().stanzaIds(); + } + if (safeToExtract) { + serverMsgId = extractStanzaId(packet, by); + } } message.setCounterpart(counterpart); diff --git a/src/main/java/eu/siacs/conversations/utils/Xmlns.java b/src/main/java/eu/siacs/conversations/utils/Xmlns.java index de0a29ce..3e725059 100644 --- a/src/main/java/eu/siacs/conversations/utils/Xmlns.java +++ b/src/main/java/eu/siacs/conversations/utils/Xmlns.java @@ -6,4 +6,5 @@ public final class Xmlns { public static final String REGISTER = "jabber:iq:register"; public static final String BYTE_STREAMS = "http://jabber.org/protocol/bytestreams"; public static final String HTTP_UPLOAD = "urn:xmpp:http:upload"; + public static final String STANZA_IDS = "urn:xmpp:sid:0"; } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 383e990d..d6a3b2cb 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -1685,6 +1685,10 @@ public class XmppConnection implements Runnable { return -1; } } + + public boolean stanzaIds() { + return hasDiscoFeature(account.getJid().toBareJid(),Xmlns.STANZA_IDS); + } } private IqGenerator getIqGenerator() { -- cgit v1.2.3