diff options
author | steckbrief <steckbrief@chefmail.de> | 2018-05-05 20:28:04 +0200 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2018-05-06 13:46:22 +0200 |
commit | 132b27adeef3ab4d305facda7dd035015b00766f (patch) | |
tree | ce90c05d96d747ea1f6cf80129462119a1291dc1 /src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlMessageParser.java | |
parent | 853f50e43f68599774469dd12240f35800144991 (diff) |
introduces new message state model
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlMessageParser.java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlMessageParser.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlMessageParser.java b/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlMessageParser.java new file mode 100644 index 00000000..d77db0d4 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/crypto/axolotl/AxolotlMessageParser.java @@ -0,0 +1,37 @@ +package de.thedevstack.conversationsplus.crypto.axolotl; + +import de.thedevstack.android.logcat.Logging; +import de.thedevstack.conversationsplus.Config; +import de.thedevstack.conversationsplus.entities.Conversation; +import de.thedevstack.conversationsplus.entities.Message; +import de.thedevstack.conversationsplus.xml.Element; +import de.thedevstack.conversationsplus.xmpp.jid.Jid; + +/** + */ +public class AxolotlMessageParser { + public static Message parseAxolotlChat(Element axolotlMessage, Jid counterpart, Jid from, Conversation conversation) { + Jid origin; + if (conversation.getMode() == Conversation.MODE_MULTI) { + origin = conversation.getMucOptions().getTrueCounterpart(counterpart.getResourcepart()); + if (origin == null) { + Logging.d(Config.LOGTAG,"axolotl message in non anonymous conference received"); + return null; + } + } else { + origin = from; + } + + Message finishedMessage = null; + AxolotlService service = conversation.getAccount().getAxolotlService(); + XmppAxolotlMessage xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlMessage, from.toBareJid()); + XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = service.processReceivingPayloadMessage(xmppAxolotlMessage); + if(plaintextMessage != null) { + finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL); + finishedMessage.setFingerprint(plaintextMessage.getFingerprint()); + Logging.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(finishedMessage.getConversation().getAccount())+" Received Message with session fingerprint: "+plaintextMessage.getFingerprint()); + } + + return finishedMessage; + } +} |