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/otr/OtrUtil.java | |
parent | 853f50e43f68599774469dd12240f35800144991 (diff) |
introduces new message state model
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/crypto/otr/OtrUtil.java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/crypto/otr/OtrUtil.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/crypto/otr/OtrUtil.java b/src/main/java/de/thedevstack/conversationsplus/crypto/otr/OtrUtil.java new file mode 100644 index 00000000..97075455 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/crypto/otr/OtrUtil.java @@ -0,0 +1,39 @@ +package de.thedevstack.conversationsplus.crypto.otr; + +import net.java.otr4j.session.SessionID; +import net.java.otr4j.session.SessionImpl; + +import de.thedevstack.conversationsplus.entities.Account; +import de.thedevstack.conversationsplus.entities.Conversation; +import de.thedevstack.conversationsplus.xmpp.Forwarded; +import de.thedevstack.conversationsplus.xmpp.jid.Jid; +import de.thedevstack.conversationsplus.xmpp.stanzas.MessagePacket; + +/** + */ +public class OtrUtil { + public static boolean isOtrSessionActive(Conversation conversation) { + return null != conversation && null != conversation.getOtrSession(); + } + + public static boolean isCounterpartOfActiveOtrSession(Conversation conversation, Jid counterpart) { + SessionImpl otrSession = (null != conversation) ? conversation.getOtrSession() : null; + SessionID sessionID = (null != otrSession) ? otrSession.getSessionID() : null; + String userID = (null != sessionID) ? sessionID.getUserID() : null; + + return null != userID && null != counterpart && userID.equals(counterpart.getResourcepart()); + } + + public static boolean isValidOtrMessagePacket(MessagePacket messagePacket, Account account) { + Jid to = messagePacket.getTo(); + boolean isProperlyAddressed = (to != null) && (!to.isBareJid() || account.countPresences() <= 1); + boolean isNotTypeGroupChat = messagePacket.getType() != MessagePacket.TYPE_GROUPCHAT; + boolean isNotForwarded = !messagePacket.hasChildRecursive(Forwarded.FORWARDED); + + return isProperlyAddressed && isNotTypeGroupChat && isNotForwarded; + } + + public static boolean isOtrBody(String body) { + return body != null && body.startsWith("?OTR"); + } +} |