Search in sources :

Example 1 with ChatGroup

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

the class XmppConnection method setState.

@Override
protected void setState(int state, ImErrorInfo error) {
    debug(TAG, "setState to " + state);
    super.setState(state, error);
    if (state == LOGGED_IN) {
        // update and send new presence packet out
        mUserPresence = new Presence(Presence.AVAILABLE, "", Presence.CLIENT_TYPE_MOBILE);
    } else if (state == DISCONNECTED || state == SUSPENDED) {
        for (ChatGroup group : getChatGroupManager().getAllChatGroups()) {
            group.clearMembers(false);
        }
    }
}
Also used : ChatGroup(org.awesomeapp.messenger.model.ChatGroup) Presence(org.awesomeapp.messenger.model.Presence)

Example 2 with ChatGroup

use of org.awesomeapp.messenger.model.ChatGroup 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 3 with ChatGroup

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

the class ChatSessionAdapter method getParticipants.

public String[] getParticipants() {
    if (mIsGroupChat) {
        Contact self = mConnection.getLoginUser();
        ChatGroup group = (ChatGroup) mChatSession.getParticipant();
        List<Contact> members = group.getMembers();
        String[] result = new String[members.size() - 1];
        int index = 0;
        for (Contact c : members) {
            if (!c.equals(self)) {
                result[index++] = c.getAddress().getAddress();
            }
        }
        return result;
    } else {
        return new String[] { mChatSession.getParticipant().getAddress().getAddress() };
    }
}
Also used : ChatGroup(org.awesomeapp.messenger.model.ChatGroup) Contact(org.awesomeapp.messenger.model.Contact)

Example 4 with ChatGroup

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

the class ChatSessionManagerAdapter method createMultiUserChatSession.

public IChatSession createMultiUserChatSession(String roomAddress, String subject, String nickname, boolean isNewChat) {
    ChatGroupManager groupMan = mConnection.getAdaptee().getChatGroupManager();
    try {
        if (roomAddress.endsWith("@")) {
            String confServer = groupMan.getDefaultGroupChatService();
            if (confServer != null)
                roomAddress += confServer;
        }
        // TODO hard coding XMPP for now
        Address address = new XmppAddress(roomAddress);
        groupMan.createChatGroupAsync(roomAddress, subject, nickname);
        ChatGroup chatGroup = groupMan.getChatGroup(address);
        if (chatGroup != null && mConnection.getState() == ImConnection.LOGGED_IN) {
            ChatSession session = getChatSessionManager().createChatSession(chatGroup, isNewChat);
            ChatSessionAdapter adapter = getChatSessionAdapter(session, isNewChat);
            groupMan.loadMembers(chatGroup);
            return adapter;
        } else {
            return null;
        }
    } catch (Exception e) {
        Log.e(ImApp.LOG_TAG, "unable to join group chat" + e.getMessage());
        return null;
    }
}
Also used : Address(org.awesomeapp.messenger.model.Address) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) ChatGroup(org.awesomeapp.messenger.model.ChatGroup) IChatSession(org.awesomeapp.messenger.service.IChatSession) ChatSession(org.awesomeapp.messenger.model.ChatSession) RemoteException(android.os.RemoteException) ChatGroupManager(org.awesomeapp.messenger.model.ChatGroupManager)

Example 5 with ChatGroup

use of org.awesomeapp.messenger.model.ChatGroup 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)

Aggregations

ChatGroup (org.awesomeapp.messenger.model.ChatGroup)7 RemoteException (android.os.RemoteException)3 Contact (org.awesomeapp.messenger.model.Contact)3 ChatSession (org.awesomeapp.messenger.model.ChatSession)2 ImEntity (org.awesomeapp.messenger.model.ImEntity)2 IChatSession (org.awesomeapp.messenger.service.IChatSession)2 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)2 ContentValues (android.content.ContentValues)1 Uri (android.net.Uri)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 OtrChatListener (org.awesomeapp.messenger.crypto.otr.OtrChatListener)1 OtrChatManager (org.awesomeapp.messenger.crypto.otr.OtrChatManager)1 OtrChatSessionAdapter (org.awesomeapp.messenger.crypto.otr.OtrChatSessionAdapter)1