Search in sources :

Example 1 with ImEntity

use of org.awesomeapp.messenger.model.ImEntity in project Zom-Android by zom.

the class ChatSessionAdapter method getNickName.

String getNickName(String username) {
    ImEntity participant = mChatSession.getParticipant();
    if (mIsGroupChat) {
        ChatGroup group = (ChatGroup) participant;
        /**
         *            List<Contact> members = group.getMembers();
         *            for (Contact c : members) {
         *                if (username.equals(c.getAddress().getAddress())) {
         *
         *                    return c.getAddress().getResource();
         *
         *                }
         *            }*
         */
        Contact groupMember = group.getMember(username);
        if (groupMember != null) {
            return groupMember.getAddress().getAddress();
        } else {
            // not found, impossible
            String[] parts = username.split("/");
            return parts[parts.length - 1];
        }
    } else {
        return ((Contact) participant).getName();
    }
}
Also used : ImEntity(org.awesomeapp.messenger.model.ImEntity) ChatGroup(org.awesomeapp.messenger.model.ChatGroup) Contact(org.awesomeapp.messenger.model.Contact)

Example 2 with ImEntity

use of org.awesomeapp.messenger.model.ImEntity in project Zom-Android by zom.

the class XmppConnection method findOrCreateParticipant.

synchronized ImEntity findOrCreateParticipant(String address, boolean isGroupChat) {
    ImEntity participant = null;
    if (isGroupChat) {
        Address xmppAddress = new XmppAddress(address);
        participant = mChatGroupManager.getChatGroup(xmppAddress);
        if (participant == null) {
            try {
                mChatGroupManager.createChatGroupAsync(address, xmppAddress.getUser(), mUser.getName());
                participant = mChatGroupManager.getChatGroup(xmppAddress);
            } catch (Exception e) {
                debug(TAG, "unable to join group chat: " + e);
                return null;
            }
        }
    } else {
        return mContactListManager.getContact(address);
    }
    return participant;
}
Also used : Address(org.awesomeapp.messenger.model.Address) HostAddress(org.jivesoftware.smack.util.dns.HostAddress) InetAddress(java.net.InetAddress) InetSocketAddress(java.net.InetSocketAddress) ImEntity(org.awesomeapp.messenger.model.ImEntity) KeyStoreException(java.security.KeyStoreException) UndecidedOmemoIdentityException(org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException) XMPPException(org.jivesoftware.smack.XMPPException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ImException(org.awesomeapp.messenger.model.ImException) KeyManagementException(java.security.KeyManagementException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SmackException(org.jivesoftware.smack.SmackException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MultiUserChatException(org.jivesoftware.smackx.muc.MultiUserChatException) CryptoFailedException(org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException) CertificateException(java.security.cert.CertificateException)

Example 3 with ImEntity

use of org.awesomeapp.messenger.model.ImEntity in project Zom-Android by zom.

the class XmppConnection method initConnectionAndLogin.

private void initConnectionAndLogin(Imps.ProviderSettings.QueryMap providerSettings, String userName) throws InterruptedException, IOException, SmackException, XMPPException, KeyManagementException, NoSuchAlgorithmException, IllegalStateException, RuntimeException {
    // Roster.SubscriptionMode.accept_all;//load this from a preference
    Roster.SubscriptionMode subMode = Roster.SubscriptionMode.manual;
    // only activates if Debug TRUE is set, so you can leave this in!
    Debug.onConnectionStart();
    initConnection(providerSettings, userName);
    if (mConnection.isConnected() && mConnection.isSecureConnection() && (!mConnection.isAuthenticated())) {
        mResource = providerSettings.getXmppResource();
        mRoster = Roster.getInstanceFor(mConnection);
        mRoster.setRosterLoadedAtLogin(true);
        mRoster.setSubscriptionMode(subMode);
        getContactListManager().listenToRoster(mRoster);
        ReconnectionManager manager = ReconnectionManager.getInstanceFor(mConnection);
        manager.disableAutomaticReconnection();
        mChatManager = ChatManager.getInstanceFor(mConnection);
        mPingManager = PingManager.getInstanceFor(mConnection);
        mPingManager.setPingInterval(PING_INTERVAL);
        if (mUser == null)
            mUser = makeUser(providerSettings, mContext.getContentResolver());
        try {
            getOmemo();
        } catch (Exception e) {
            debug(TAG, "error init'ing omemo during connectoin", e);
        }
        MultiUserChatManager.getInstanceFor(mConnection).addInvitationListener(new InvitationListener() {

            @Override
            public void invitationReceived(XMPPConnection xmppConnection, MultiUserChat muc, EntityJid entityJid, String reason, String password, org.jivesoftware.smack.packet.Message message, MUCUser.Invite invite) {
                try {
                    getChatGroupManager().acceptInvitationAsync(invite.getFrom().toString());
                    XmppAddress xa = new XmppAddress(muc.getRoom().toString());
                    mChatGroupManager.joinChatGroupAsync(xa, reason);
                    ChatSession session = mSessionManager.findSession(muc.getRoom());
                    // create a session
                    if (session == null) {
                        ImEntity participant = findOrCreateParticipant(xa.getAddress(), true);
                        if (participant != null)
                            session = mSessionManager.createChatSession(participant, false);
                        if (session != null)
                            ((ChatGroup) session.getParticipant()).setName(muc.getSubject());
                    }
                } catch (Exception se) {
                    Log.e(TAG, "error accepting invite", se);
                }
            }
        });
        mConnection.login(mUsername, mPassword, Resourcepart.from(mResource));
        mStreamHandler.notifyInitialLogin();
        initServiceDiscovery();
        getContactListManager().loadContactListsAsync();
        execute(new Runnable() {

            public void run() {
                sendPresencePacket();
                sendVCard();
            }
        });
    } else {
        // throw some meaningful error message here
        throw new SmackException("Unable to securely conenct to server");
    }
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) ReconnectionManager(org.jivesoftware.smack.ReconnectionManager) SmackException(org.jivesoftware.smack.SmackException) ChatGroup(org.awesomeapp.messenger.model.ChatGroup) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection) XMPPConnection(org.jivesoftware.smack.XMPPConnection) KeyStoreException(java.security.KeyStoreException) UndecidedOmemoIdentityException(org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException) XMPPException(org.jivesoftware.smack.XMPPException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ImException(org.awesomeapp.messenger.model.ImException) KeyManagementException(java.security.KeyManagementException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SmackException(org.jivesoftware.smack.SmackException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MultiUserChatException(org.jivesoftware.smackx.muc.MultiUserChatException) CryptoFailedException(org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException) CertificateException(java.security.cert.CertificateException) ChatSession(org.awesomeapp.messenger.model.ChatSession) IChatSession(org.awesomeapp.messenger.service.IChatSession) EntityJid(org.jxmpp.jid.EntityJid) Roster(org.jivesoftware.smack.roster.Roster) InvitationListener(org.jivesoftware.smackx.muc.InvitationListener) ImEntity(org.awesomeapp.messenger.model.ImEntity)

Example 4 with ImEntity

use of org.awesomeapp.messenger.model.ImEntity in project Zom-Android by zom.

the class XmppConnection method findOrCreateSession.

private ChatSession findOrCreateSession(String address, boolean groupChat) {
    try {
        if (mConnection == null || (!mConnection.isConnected()))
            return null;
        ChatSession session = mSessionManager.findSession(JidCreate.bareFrom(address));
        BareJid bareJid = JidCreate.bareFrom(address);
        if (session == null) {
            if (!groupChat) {
                ImEntity participant = findOrCreateParticipant(address, groupChat);
                if (participant != null) {
                    session = mSessionManager.createChatSession(participant, false);
                    mContactListManager.refreshPresence(address);
                    qAvatar.put(bareJid.toString(), "");
                    if (getOmemo().getManager().contactSupportsOmemo(bareJid)) {
                        getOmemo().getManager().requestDeviceListUpdateFor(bareJid);
                        getOmemo().getManager().buildSessionsWith(bareJid);
                    }
                }
            } else {
                XmppAddress xAddr = new XmppAddress(address);
                mChatGroupManager.joinChatGroupAsync(xAddr, null);
                MultiUserChat muc = mChatGroupManager.getMultiUserChat(xAddr.getBareAddress());
                session = mSessionManager.findSession(muc.getRoom());
                // create a session
                if (session == null) {
                    ImEntity participant = findOrCreateParticipant(xAddr.getAddress(), true);
                    if (participant != null)
                        session = mSessionManager.createChatSession(participant, false);
                    if (session != null)
                        ((ChatGroup) session.getParticipant()).setName(muc.getSubject());
                }
            }
        }
        return session;
    } catch (Exception e) {
        debug(ImApp.LOG_TAG, "error findOrCreateSession", e);
        return null;
    }
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) EntityBareJid(org.jxmpp.jid.EntityBareJid) BareJid(org.jxmpp.jid.BareJid) DomainBareJid(org.jxmpp.jid.DomainBareJid) ImEntity(org.awesomeapp.messenger.model.ImEntity) ChatSession(org.awesomeapp.messenger.model.ChatSession) IChatSession(org.awesomeapp.messenger.service.IChatSession) KeyStoreException(java.security.KeyStoreException) UndecidedOmemoIdentityException(org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException) XMPPException(org.jivesoftware.smack.XMPPException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ImException(org.awesomeapp.messenger.model.ImException) KeyManagementException(java.security.KeyManagementException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SmackException(org.jivesoftware.smack.SmackException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MultiUserChatException(org.jivesoftware.smackx.muc.MultiUserChatException) CryptoFailedException(org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException) CertificateException(java.security.cert.CertificateException)

Aggregations

ImEntity (org.awesomeapp.messenger.model.ImEntity)4 RemoteException (android.os.RemoteException)3 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 KeyManagementException (java.security.KeyManagementException)3 KeyStoreException (java.security.KeyStoreException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CertificateException (java.security.cert.CertificateException)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 ImException (org.awesomeapp.messenger.model.ImException)3 SmackException (org.jivesoftware.smack.SmackException)3 XMPPException (org.jivesoftware.smack.XMPPException)3 MultiUserChatException (org.jivesoftware.smackx.muc.MultiUserChatException)3 CryptoFailedException (org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException)3 UndecidedOmemoIdentityException (org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException)3 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)3 ChatGroup (org.awesomeapp.messenger.model.ChatGroup)2 ChatSession (org.awesomeapp.messenger.model.ChatSession)2 IChatSession (org.awesomeapp.messenger.service.IChatSession)2 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)2