Search in sources :

Example 1 with OmemoMessageInformation

use of org.jivesoftware.smackx.omemo.internal.OmemoMessageInformation in project Zom-Android by zom.

the class XmppConnection method initOmemo.

private synchronized Omemo initOmemo(XMPPTCPConnection conn) throws Exception {
    if (conn != null && conn.isConnected()) {
        mOmemoInstance = new Omemo(conn, mUserJid);
        mOmemoInstance.getManager().addOmemoMessageListener(new OmemoMessageListener() {

            @Override
            public void onOmemoKeyTransportReceived(CipherAndAuthTag cipherAndAuthTag, org.jivesoftware.smack.packet.Message message, org.jivesoftware.smack.packet.Message message1, OmemoMessageInformation omemoMessageInformation) {
                debug(TAG, "omemo key transport received");
            }

            @Override
            public void onOmemoMessageReceived(String body, org.jivesoftware.smack.packet.Message message, org.jivesoftware.smack.packet.Message message1, OmemoMessageInformation omemoMessageInformation) {
                if (body != null) {
                    debug(TAG, "got inbound message omemo: from:" + message.getFrom() + "=" + message.getBody());
                    message.setBody(body);
                    handleMessage(message, true, true);
                } else {
                    debug(TAG, "got empty ibound message omemo: from:" + message.getFrom().toString());
                }
            }
        });
        mOmemoInstance.getManager().addOmemoMucMessageListener(new OmemoMucMessageListener() {

            @Override
            public void onOmemoMucMessageReceived(MultiUserChat muc, BareJid from, String decryptedBody, org.jivesoftware.smack.packet.Message message, org.jivesoftware.smack.packet.Message wrappingMessage, OmemoMessageInformation omemoInformation) {
                if (decryptedBody != null) {
                    debug(TAG, "got inbound MUC message omemo: from:" + message.getFrom() + "=" + message.getBody());
                    org.jivesoftware.smack.packet.Message messagePlain = new org.jivesoftware.smack.packet.Message();
                    messagePlain.setType(message.getType());
                    messagePlain.setFrom(message.getFrom());
                    messagePlain.setTo(message.getTo());
                    messagePlain.setBody(decryptedBody);
                    messagePlain.setStanzaId(message.getStanzaId());
                    messagePlain.addExtensions(message.getExtensions());
                    messagePlain.setThread(message.getThread());
                    messagePlain.setSubject(message.getSubject());
                    handleMessage(messagePlain, true, true);
                } else {
                    debug(TAG, "got empty ibound MUC message omemo: from:" + message.getFrom().toString());
                }
            }

            @Override
            public void onOmemoKeyTransportReceived(MultiUserChat muc, BareJid from, CipherAndAuthTag cipherAndAuthTag, org.jivesoftware.smack.packet.Message message, org.jivesoftware.smack.packet.Message wrappingMessage, OmemoMessageInformation omemoInformation) {
                debug(TAG, "got OmemoKey Transport from: " + from.toString());
            }
        });
        addOmemoListener(mOmemoInstance.getManager());
    }
    return mOmemoInstance;
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) OmemoMessageListener(org.jivesoftware.smackx.omemo.listener.OmemoMessageListener) Message(org.awesomeapp.messenger.model.Message) Omemo(org.awesomeapp.messenger.crypto.omemo.Omemo) EntityBareJid(org.jxmpp.jid.EntityBareJid) BareJid(org.jxmpp.jid.BareJid) DomainBareJid(org.jxmpp.jid.DomainBareJid) CipherAndAuthTag(org.jivesoftware.smackx.omemo.internal.CipherAndAuthTag) OmemoMucMessageListener(org.jivesoftware.smackx.omemo.listener.OmemoMucMessageListener) OmemoMessageInformation(org.jivesoftware.smackx.omemo.internal.OmemoMessageInformation)

Aggregations

Omemo (org.awesomeapp.messenger.crypto.omemo.Omemo)1 Message (org.awesomeapp.messenger.model.Message)1 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)1 CipherAndAuthTag (org.jivesoftware.smackx.omemo.internal.CipherAndAuthTag)1 OmemoMessageInformation (org.jivesoftware.smackx.omemo.internal.OmemoMessageInformation)1 OmemoMessageListener (org.jivesoftware.smackx.omemo.listener.OmemoMessageListener)1 OmemoMucMessageListener (org.jivesoftware.smackx.omemo.listener.OmemoMucMessageListener)1 BareJid (org.jxmpp.jid.BareJid)1 DomainBareJid (org.jxmpp.jid.DomainBareJid)1 EntityBareJid (org.jxmpp.jid.EntityBareJid)1