Search in sources :

Example 1 with SessionID

use of net.java.otr4j.session.SessionID in project xabber-android by redsolution.

the class OTRManager method getOrCreateSession.

private Session getOrCreateSession(String account, String user) {
    Session session = sessions.get(account, user);
    if (session != null) {
        LogManager.i(this, "Found session with id " + session.getSessionID() + " with status " + session.getSessionStatus() + " for user " + user);
        return session;
    }
    LogManager.i(this, "Creating new session for " + user);
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    session = new Session(new SessionID(account, user, accountItem == null ? "" : accountItem.getConnectionSettings().getProtocol().toString()), this);
    session.addOtrEngineListener(this);
    sessions.put(account, user, session);
    return session;
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) SessionID(net.java.otr4j.session.SessionID) Session(net.java.otr4j.session.Session)

Example 2 with SessionID

use of net.java.otr4j.session.SessionID in project Conversations by siacs.

the class XmppConnectionService method onOtrSessionEstablished.

public void onOtrSessionEstablished(Conversation conversation) {
    final Account account = conversation.getAccount();
    final Session otrSession = conversation.getOtrSession();
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + " otr session established with " + conversation.getJid() + "/" + otrSession.getSessionID().getUserID());
    conversation.findUnsentMessagesWithEncryption(Message.ENCRYPTION_OTR, new Conversation.OnMessageFound() {

        @Override
        public void onMessageFound(Message message) {
            SessionID id = otrSession.getSessionID();
            try {
                message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
            } catch (InvalidJidException e) {
                return;
            }
            if (message.needsUploading()) {
                mJingleConnectionManager.createNewConnection(message);
            } else {
                MessagePacket outPacket = mMessageGenerator.generateOtrChat(message);
                if (outPacket != null) {
                    mMessageGenerator.addDelay(outPacket, message.getTimeSent());
                    message.setStatus(Message.STATUS_SEND);
                    databaseBackend.updateMessage(message);
                    sendMessagePacket(account, outPacket);
                }
            }
            updateConversationUi();
        }
    });
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Account(eu.siacs.conversations.entities.Account) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Conversation(eu.siacs.conversations.entities.Conversation) SessionID(net.java.otr4j.session.SessionID) Session(net.java.otr4j.session.Session)

Example 3 with SessionID

use of net.java.otr4j.session.SessionID in project Conversations by siacs.

the class Conversation method startOtrSession.

public SessionImpl startOtrSession(String presence, boolean sendStart) {
    if (this.otrSession != null) {
        return this.otrSession;
    } else {
        final SessionID sessionId = new SessionID(this.getJid().toBareJid().toString(), presence, "xmpp");
        this.otrSession = new SessionImpl(sessionId, getAccount().getOtrService());
        try {
            if (sendStart) {
                this.otrSession.startSession();
                return this.otrSession;
            }
            return this.otrSession;
        } catch (OtrException e) {
            return null;
        }
    }
}
Also used : SessionImpl(net.java.otr4j.session.SessionImpl) OtrException(net.java.otr4j.OtrException) SessionID(net.java.otr4j.session.SessionID)

Example 4 with SessionID

use of net.java.otr4j.session.SessionID in project Conversations by siacs.

the class XmppActivity method selectPresence.

public void selectPresence(final Conversation conversation, final OnPresenceSelected listener) {
    final Contact contact = conversation.getContact();
    if (conversation.hasValidOtrSession()) {
        SessionID id = conversation.getOtrSession().getSessionID();
        Jid jid;
        try {
            jid = Jid.fromString(id.getAccountID() + "/" + id.getUserID());
        } catch (InvalidJidException e) {
            jid = null;
        }
        conversation.setNextCounterpart(jid);
        listener.onPresenceSelected();
    } else if (!contact.showInRoster()) {
        showAddToRosterDialog(conversation);
    } else {
        final Presences presences = contact.getPresences();
        if (presences.size() == 0) {
            if (!contact.getOption(Contact.Options.TO) && !contact.getOption(Contact.Options.ASKING) && contact.getAccount().getStatus() == Account.State.ONLINE) {
                showAskForPresenceDialog(contact);
            } else if (!contact.getOption(Contact.Options.TO) || !contact.getOption(Contact.Options.FROM)) {
                warnMutalPresenceSubscription(conversation, listener);
            } else {
                conversation.setNextCounterpart(null);
                listener.onPresenceSelected();
            }
        } else if (presences.size() == 1) {
            String presence = presences.toResourceArray()[0];
            try {
                conversation.setNextCounterpart(Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), presence));
            } catch (InvalidJidException e) {
                conversation.setNextCounterpart(null);
            }
            listener.onPresenceSelected();
        } else {
            showPresenceSelectionDialog(presences, conversation, listener);
        }
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) Presences(eu.siacs.conversations.entities.Presences) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) SessionID(net.java.otr4j.session.SessionID) Contact(eu.siacs.conversations.entities.Contact)

Aggregations

SessionID (net.java.otr4j.session.SessionID)4 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)2 Session (net.java.otr4j.session.Session)2 AccountItem (com.xabber.android.data.account.AccountItem)1 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)1 Account (eu.siacs.conversations.entities.Account)1 Contact (eu.siacs.conversations.entities.Contact)1 Conversation (eu.siacs.conversations.entities.Conversation)1 Message (eu.siacs.conversations.entities.Message)1 Presences (eu.siacs.conversations.entities.Presences)1 Jid (eu.siacs.conversations.xmpp.jid.Jid)1 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)1 OtrException (net.java.otr4j.OtrException)1 SessionImpl (net.java.otr4j.session.SessionImpl)1