Search in sources :

Example 1 with OtrChatManager

use of org.awesomeapp.messenger.crypto.otr.OtrChatManager in project Zom-Android by zom.

the class ChatSession method sendMessageAsync.

/**
 * Sends a text message to other participant(s) in this session
 * asynchronously and adds the message to the history. TODO: more docs on
 * async callbacks.
 */
// TODO these sendMessageAsync() should probably be renamed to sendMessageAsyncAndLog()/
/*
    public void sendMessageAsync(String text) {
        Message message = new Message(text);
        sendMessageAsync(message);
    }*/
/**
 * Sends a message to other participant(s) in this session asynchronously
 * and adds the message to the history. TODO: more docs on async callbacks.
 *
 * @param message the message to send.
 */
public int sendMessageAsync(Message message) {
    if (mParticipant instanceof Contact) {
        if (mJid.hasNoResource())
            initJid();
        OtrChatManager cm = OtrChatManager.getInstance();
        SessionID sId = cm.getSessionId(message.getFrom().getAddress(), mJid.toString());
        SessionStatus otrStatus = cm.getSessionStatus(sId);
        boolean verified = cm.getKeyManager().isVerified(sId);
        boolean isOffline = !((Contact) mParticipant).getPresence().isOnline();
        message.setTo(mXa);
        message.setType(Imps.MessageType.QUEUED);
        // if we can't omemo, check it again to be sure
        if (!mCanOmemo) {
            mCanOmemo = mManager.resourceSupportsOmemo(mJid);
        }
        if (mCanOmemo) {
            mManager.sendMessageAsync(this, message);
        } else {
            // try to send ChatSecure Push message as a client
            if (isOffline) {
            } else {
                if (otrStatus == SessionStatus.ENCRYPTED) {
                    if (verified) {
                        message.setType(Imps.MessageType.OUTGOING_ENCRYPTED_VERIFIED);
                    } else {
                        message.setType(Imps.MessageType.OUTGOING_ENCRYPTED);
                    }
                } else {
                    OtrChatManager.getInstance().startSession(sId);
                    message.setType(Imps.MessageType.QUEUED);
                    return message.getType();
                }
                boolean canSend = cm.transformSending(message);
                if (canSend) {
                    mManager.sendMessageAsync(this, message);
                } else {
                    // can't be sent due to OTR state
                    message.setType(Imps.MessageType.QUEUED);
                    return message.getType();
                }
            }
        }
    } else if (mParticipant instanceof ChatGroup) {
        // if we can't omemo, check it again to be sure
        if (!mCanOmemo) {
            mCanOmemo = mManager.resourceSupportsOmemo(mJid);
        }
        message.setTo(mParticipant.getAddress());
        message.setType(Imps.MessageType.OUTGOING);
        mManager.sendMessageAsync(this, message);
    } else {
        // what do we do ehre?
        message.setType(Imps.MessageType.QUEUED);
    }
    return message.getType();
}
Also used : SessionStatus(net.java.otr4j.session.SessionStatus) OtrChatManager(org.awesomeapp.messenger.crypto.otr.OtrChatManager) SessionID(net.java.otr4j.session.SessionID)

Example 2 with OtrChatManager

use of org.awesomeapp.messenger.crypto.otr.OtrChatManager in project Zom-Android by zom.

the class ChatSession method sendDataAsync.

/**
 * Sends message + data to other participant(s) in this session asynchronously.
 *
 * @param message the message to send.
 * @param data the data to send.
 */
public void sendDataAsync(Message message, boolean isResponse, byte[] data) {
    OtrChatManager cm = OtrChatManager.getInstance();
    sendDataAsync(cm, message, isResponse, data);
}
Also used : OtrChatManager(org.awesomeapp.messenger.crypto.otr.OtrChatManager)

Example 3 with OtrChatManager

use of org.awesomeapp.messenger.crypto.otr.OtrChatManager in project Zom-Android by zom.

the class ChatSessionAdapter method initOtrChatSession.

private void initOtrChatSession(ImEntity participant) {
    try {
        if (mConnection != null) {
            mDataHandler = new OtrDataHandler(mChatSession);
            mDataHandler.setDataListener(mDataHandlerListener);
            OtrChatManager cm = service.getOtrChatManager();
            cm.addOtrEngineListener(mListenerAdapter);
            mChatSession.setMessageListener(new OtrChatListener(cm, mListenerAdapter));
            if (participant instanceof Contact) {
                String key = participant.getAddress().getAddress();
                if (!mOtrChatSessions.containsKey(key)) {
                    OtrChatSessionAdapter adapter = new OtrChatSessionAdapter(mConnection.getLoginUser().getAddress().getAddress(), participant, cm);
                    mOtrChatSessions.put(key, adapter);
                }
            } else if (participant instanceof ChatGroup) {
            }
            mDataHandler.setChatId(getId());
        }
    } catch (NullPointerException npe) {
        Log.e(ImApp.LOG_TAG, "error init OTR session", npe);
    }
}
Also used : OtrChatSessionAdapter(org.awesomeapp.messenger.crypto.otr.OtrChatSessionAdapter) OtrDataHandler(org.awesomeapp.messenger.crypto.otr.OtrDataHandler) ChatGroup(org.awesomeapp.messenger.model.ChatGroup) OtrChatListener(org.awesomeapp.messenger.crypto.otr.OtrChatListener) OtrChatManager(org.awesomeapp.messenger.crypto.otr.OtrChatManager) Contact(org.awesomeapp.messenger.model.Contact)

Example 4 with OtrChatManager

use of org.awesomeapp.messenger.crypto.otr.OtrChatManager in project Zom-Android by zom.

the class ChatSession method sendPushWhitelistTokenAsync.

/**
 * Returns a unmodifiable list of the history messages in this session.
 *
 * @return a unmodifiable list of the history messages in this session.
 */
/**
 *    public List<Message> getHistoryMessages() {
 *        return Collections.unmodifiableList(mHistoryMessages);
 *    }
 */
public void sendPushWhitelistTokenAsync(@NonNull Message message, @NonNull String[] whitelistTokens) {
    OtrChatManager cm = OtrChatManager.getInstance();
    SessionID sId = cm.getSessionId(message.getFrom().getAddress(), mParticipant.getAddress().getAddress());
    SessionStatus otrStatus = cm.getSessionStatus(sId);
    message.setTo(new XmppAddress(sId.getRemoteUserId()));
    if (otrStatus == SessionStatus.ENCRYPTED) {
        boolean verified = cm.getKeyManager().isVerified(sId);
        if (verified) {
            message.setType(Imps.MessageType.OUTGOING_ENCRYPTED_VERIFIED);
        } else {
            message.setType(Imps.MessageType.OUTGOING_ENCRYPTED);
        }
        boolean canSend = cm.transformPushWhitelistTokenSending(message, whitelistTokens);
        if (canSend)
            mManager.sendMessageAsync(this, message);
    }
}
Also used : SessionStatus(net.java.otr4j.session.SessionStatus) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) OtrChatManager(org.awesomeapp.messenger.crypto.otr.OtrChatManager) SessionID(net.java.otr4j.session.SessionID)

Aggregations

OtrChatManager (org.awesomeapp.messenger.crypto.otr.OtrChatManager)4 SessionID (net.java.otr4j.session.SessionID)2 SessionStatus (net.java.otr4j.session.SessionStatus)2 OtrChatListener (org.awesomeapp.messenger.crypto.otr.OtrChatListener)1 OtrChatSessionAdapter (org.awesomeapp.messenger.crypto.otr.OtrChatSessionAdapter)1 OtrDataHandler (org.awesomeapp.messenger.crypto.otr.OtrDataHandler)1 ChatGroup (org.awesomeapp.messenger.model.ChatGroup)1 Contact (org.awesomeapp.messenger.model.Contact)1 XmppAddress (org.awesomeapp.messenger.plugin.xmpp.XmppAddress)1