Search in sources :

Example 1 with Presences

use of eu.siacs.conversations.entities.Presences 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

Contact (eu.siacs.conversations.entities.Contact)1 Presences (eu.siacs.conversations.entities.Presences)1 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)1 Jid (eu.siacs.conversations.xmpp.jid.Jid)1 SessionID (net.java.otr4j.session.SessionID)1