From b34a1f7f5e7be8cab29c205afc0c458be32600c7 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 4 Apr 2017 22:15:38 +0200 Subject: [PATCH] parse message that only contain oob tag. fixes #2359 --- .../conversations/generator/AbstractGenerator.java | 1 + .../conversations/generator/MessageGenerator.java | 2 +- .../siacs/conversations/parser/MessageParser.java | 13 ++++++++----- .../java/eu/siacs/conversations/xml/Namespace.java | 1 + 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java index 2866ccf52..aff2ce48b 100644 --- a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java @@ -29,6 +29,7 @@ public abstract class AbstractGenerator { "urn:xmpp:jingle:transports:ibb:1", "http://jabber.org/protocol/muc", "jabber:x:conference", + Namespace.OOB, "http://jabber.org/protocol/caps", "http://jabber.org/protocol/disco#info", "urn:xmpp:avatar:metadata+notify", diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java index bbe645504..659183d2a 100644 --- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java @@ -129,7 +129,7 @@ public class MessageGenerator extends AbstractGenerator { if (message.hasFileOnRemoteHost()) { Message.FileParams fileParams = message.getFileParams(); content = fileParams.url.toString(); - packet.addChild("x","jabber:x:oob").addChild("url").setContent(content); + packet.addChild("x",Namespace.OOB).addChild("url").setContent(content); } else { content = message.getBody(); } diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 7d6e79018..1724a8581 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -372,8 +372,8 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece final Element mucUserElement = packet.findChild("x", "http://jabber.org/protocol/muc#user"); final String pgpEncrypted = packet.findChildContent("x", "jabber:x:encrypted"); final Element replaceElement = packet.findChild("replace", "urn:xmpp:message-correct:0"); - final Element oob = packet.findChild("x", "jabber:x:oob"); - final boolean isOob = oob!= null && body != null && body.equals(oob.findChildContent("url")); + final Element oob = packet.findChild("x", Namespace.OOB); + final String oobUrl = oob != null ? oob.findChildContent("url") : null; final String replacementId = replaceElement == null ? null : replaceElement.getAttribute("id"); final Element axolotlEncrypted = packet.findChild(XmppAxolotlMessage.CONTAINERTAG, AxolotlService.PEP_PREFIX); int status; @@ -414,7 +414,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece mXmppConnectionService.updateConversationUi(); } - if ((body != null || pgpEncrypted != null || axolotlEncrypted != null) && !isMucStatusMessage) { + if ((body != null || pgpEncrypted != null || axolotlEncrypted != null || oobUrl != null) && !isMucStatusMessage) { Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, false, query); final boolean conversationMultiMode = conversation.getMode() == Conversation.MODE_MULTI; @@ -458,7 +458,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart); origin = getTrueCounterpart(query != null ? mucUserElement : null, fallback); if (origin == null) { - Log.d(Config.LOGTAG,"axolotl message in non anonymous conference received"); + Log.d(Config.LOGTAG, "axolotl message in non anonymous conference received"); return; } } else { @@ -471,6 +471,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (conversationMultiMode) { message.setTrueCounterpart(origin); } + } else if (body == null && oobUrl != null) { + message = new Message(conversation, oobUrl, Message.ENCRYPTION_NONE, status); + message.setOob(true); } else { message = new Message(conversation, body, Message.ENCRYPTION_NONE, status); } @@ -480,7 +483,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece message.setServerMsgId(serverMsgId); message.setCarbon(isCarbon); message.setTime(timestamp); - message.setOob(isOob); + message.setOob(body != null && body.equals(oobUrl)); message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0"); if (conversationMultiMode) { final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart); diff --git a/src/main/java/eu/siacs/conversations/xml/Namespace.java b/src/main/java/eu/siacs/conversations/xml/Namespace.java index 913ed0357..def58c4d7 100644 --- a/src/main/java/eu/siacs/conversations/xml/Namespace.java +++ b/src/main/java/eu/siacs/conversations/xml/Namespace.java @@ -10,4 +10,5 @@ public final class Namespace { public static final String MAM = "urn:xmpp:mam:2"; public static final String MAM_LEGACY = "urn:xmpp:mam:0"; public static final String IDLE = "urn:xmpp:idle:1"; + public static final String OOB = "jabber:x:oob"; }