From 2ebf84bf8c5d9ba09a2b31f653a2689ddbc6d050 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 22 Jun 2016 12:22:57 +0200 Subject: refactor code that reads real jid from muc --- .../siacs/conversations/parser/MessageParser.java | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/main/java/eu') diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index af71bdb09..3f5a8366c 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -391,7 +391,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece status = Message.STATUS_RECEIVED; } } - Message message; + final Message message; if (body != null && body.startsWith("?OTR") && Config.supportOtr()) { if (!isForwarded && !isTypeGroupChat && isProperlyAddressed && !conversationMultiMode) { message = parseOtrChat(body, from, remoteMsgId, conversation); @@ -407,7 +407,8 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } else if (axolotlEncrypted != null && Config.supportOmemo()) { Jid origin; if (conversationMultiMode) { - origin = conversation.getMucOptions().getTrueCounterpart(counterpart); + 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"); return; @@ -435,21 +436,14 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece message.setOob(isOob); message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0"); if (conversationMultiMode) { - final Element item = mucUserElement == null ? null : mucUserElement.findChild("item"); - Jid trueCounterpart; - if (Config.PARSE_REAL_JID_FROM_MUC_MAM && query != null && item != null) { - trueCounterpart = item.getAttributeAsJid("jid"); - if (trueCounterpart != null) { - if (trueCounterpart.toBareJid().equals(account.getJid().toBareJid())) { - status = isTypeGroupChat ? Message.STATUS_SEND_RECEIVED : Message.STATUS_SEND; - } else { - status = Message.STATUS_RECEIVED; - } - message.setStatus(status); - } + final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart); + Jid trueCounterpart = getTrueCounterpart(query != null ? mucUserElement : null, fallback); + if (trueCounterpart != null && trueCounterpart.toBareJid().equals(account.getJid().toBareJid())) { + status = isTypeGroupChat ? Message.STATUS_SEND_RECEIVED : Message.STATUS_SEND; } else { - trueCounterpart = conversation.getMucOptions().getTrueCounterpart(counterpart); + status = Message.STATUS_RECEIVED; } + message.setStatus(status); message.setTrueCounterpart(trueCounterpart); if (!isTypeGroupChat) { message.setType(Message.TYPE_PRIVATE); @@ -641,6 +635,12 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece } } + private static Jid getTrueCounterpart(Element mucUserElement, Jid fallback) { + final Element item = mucUserElement == null ? null : mucUserElement.findChild("item"); + Jid result = item == null ? null : item.getAttributeAsJid("jid"); + return result != null && Config.PARSE_REAL_JID_FROM_MUC_MAM ? result : fallback; + } + private void sendMessageReceipts(Account account, MessagePacket packet) { ArrayList receiptsNamespaces = new ArrayList<>(); if (packet.hasChild("markable", "urn:xmpp:chat-markers:0")) { -- cgit v1.2.3