diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-06-22 12:22:57 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-06-22 12:22:57 +0200 |
commit | 982a20fef557142eac4e1cc41b9c3cbe5a7b091f (patch) | |
tree | 4e7763bf516a3a09e8ca1963f064628f8047417e | |
parent | 4ba5472d0c56f8cf136a7af780d6bb9d5786229e (diff) |
refactor code that reads real jid from muc
-rw-r--r-- | src/main/java/eu/siacs/conversations/parser/MessageParser.java | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index af71bdb0..3f5a8366 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<String> receiptsNamespaces = new ArrayList<>(); if (packet.hasChild("markable", "urn:xmpp:chat-markers:0")) { |