Search in sources :

Example 6 with IChatSession

use of org.awesomeapp.messenger.service.IChatSession in project Zom-Android by zom.

the class GroupDisplayActivity method leaveGroup.

private void leaveGroup() {
    try {
        IChatSessionManager manager = mConn.getChatSessionManager();
        IChatSession session = manager.getChatSession(mAddress);
        if (session == null)
            session = manager.createChatSession(mAddress, true);
        if (session != null) {
            session.leave();
            // clear the stack and go back to the main activity
            Intent intent = new Intent(this, MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    } catch (Exception e) {
        Log.e(ImApp.LOG_TAG, "error leaving group", e);
    }
}
Also used : IChatSessionManager(org.awesomeapp.messenger.service.IChatSessionManager) Intent(android.content.Intent) IChatSession(org.awesomeapp.messenger.service.IChatSession) DecoderException(org.apache.commons.codec.DecoderException) RemoteException(android.os.RemoteException)

Example 7 with IChatSession

use of org.awesomeapp.messenger.service.IChatSession 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 8 with IChatSession

use of org.awesomeapp.messenger.service.IChatSession in project Zom-Android by zom.

the class MigrateAccountTask method doInBackground.

@Override
protected OnboardingAccount doInBackground(String... newDomains) {
    // get existing account username
    String nickname = Imps.Account.getNickname(mContext.getContentResolver(), mAccountId);
    String username = Imps.Account.getUserName(mContext.getContentResolver(), mAccountId);
    String password = Imps.Account.getPassword(mContext.getContentResolver(), mAccountId);
    OtrAndroidKeyManagerImpl keyMan = OtrAndroidKeyManagerImpl.getInstance(mContext);
    KeyPair keyPair = keyMan.generateLocalKeyPair();
    String fingerprint = keyMan.getFingerprint(keyPair.getPublic());
    // find or use provided new server/domain
    String domain = newDomains[0];
    // register account on new domain with same password
    mNewAccount = registerNewAccount(nickname, username, password, domain, null);
    if (mNewAccount == null) {
        username = username + '.' + fingerprint.substring(fingerprint.length() - 8, fingerprint.length()).toLowerCase();
        mNewAccount = registerNewAccount(nickname, username, password, domain, null);
        if (mNewAccount == null)
            return null;
    }
    String newJabberId = mNewAccount.username + '@' + mNewAccount.domain;
    keyMan.storeKeyPair(newJabberId, keyPair);
    // send migration message to existing contacts and/or sessions
    try {
        boolean loggedInToOldAccount = mConn.getState() == ImConnection.LOGGED_IN;
        // login and set new default account
        SignInHelper signInHelper = new SignInHelper(mContext, mHandler);
        signInHelper.activateAccount(mNewAccount.providerId, mNewAccount.accountId);
        signInHelper.signIn(mNewAccount.password, mNewAccount.providerId, mNewAccount.accountId, true);
        mNewConn = mApp.getConnection(mNewAccount.providerId, mNewAccount.accountId);
        while (mNewConn.getState() != ImConnection.LOGGED_IN) {
            try {
                Thread.sleep(500);
            } catch (Exception e) {
            }
        }
        String inviteLink = OnboardingManager.generateInviteLink(mContext, newJabberId, fingerprint, nickname, true);
        String migrateMessage = mContext.getString(R.string.migrate_message) + ' ' + inviteLink;
        IChatSessionManager sessionMgr = mConn.getChatSessionManager();
        IContactListManager clManager = mConn.getContactListManager();
        List<IContactList> listOfLists = clManager.getContactLists();
        if (loggedInToOldAccount) {
            for (IContactList contactList : listOfLists) {
                String[] contacts = contactList.getContacts();
                for (String contact : contacts) {
                    mContacts.add(contact);
                    IChatSession session = sessionMgr.getChatSession(contact);
                    if (session == null) {
                        session = sessionMgr.createChatSession(contact, true);
                    }
                    if (!session.isEncrypted()) {
                        // try to kick off some encryption here
                        session.getDefaultOtrChatSession().startChatEncryption();
                        try {
                            Thread.sleep(500);
                        }// just wait a half second here?
                         catch (Exception e) {
                        }
                    }
                    session.sendMessage(migrateMessage, false);
                    // archive existing contact
                    clManager.archiveContact(contact, session.isGroupChatSession() ? Imps.Contacts.TYPE_NORMAL : Imps.Contacts.TYPE_GROUP, true);
                }
            }
        } else {
            String[] offlineAddresses = clManager.getOfflineAddresses();
            for (String address : offlineAddresses) {
                mContacts.add(address);
                clManager.archiveContact(address, Imps.Contacts.TYPE_NORMAL, true);
            }
        }
        for (String contact : mContacts) {
            addToContactList(mNewConn, contact, keyMan.getRemoteFingerprint(contact), null);
        }
        if (loggedInToOldAccount) {
            // archive existing conversations and contacts
            List<IChatSession> listSession = mConn.getChatSessionManager().getActiveChatSessions();
            for (IChatSession session : listSession) {
                session.leave();
            }
            mConn.broadcastMigrationIdentity(newJabberId);
        }
        migrateAvatars(username, newJabberId);
        mApp.setDefaultAccount(mNewAccount.providerId, mNewAccount.accountId);
        // logout of existing account
        setKeepSignedIn(mAccountId, false);
        if (loggedInToOldAccount)
            mConn.logout();
        return mNewAccount;
    } catch (Exception e) {
        Log.e(ImApp.LOG_TAG, "error with migration", e);
    }
    // failed
    return null;
}
Also used : KeyPair(java.security.KeyPair) OtrAndroidKeyManagerImpl(org.awesomeapp.messenger.crypto.otr.OtrAndroidKeyManagerImpl) IContactList(org.awesomeapp.messenger.service.IContactList) SignInHelper(org.awesomeapp.messenger.ui.legacy.SignInHelper) IChatSession(org.awesomeapp.messenger.service.IChatSession) RemoteException(android.os.RemoteException) JSONException(org.json.JSONException) IOException(java.io.IOException) IChatSessionManager(org.awesomeapp.messenger.service.IChatSessionManager) IContactListManager(org.awesomeapp.messenger.service.IContactListManager)

Example 9 with IChatSession

use of org.awesomeapp.messenger.service.IChatSession in project Zom-Android by zom.

the class ContactsListFragment method deleteContact.

private static void deleteContact(Activity activity, long itemId, String address, long providerId, long accountId) {
    try {
        IImConnection mConn;
        ImApp app = ((ImApp) activity.getApplication());
        mConn = app.getConnection(providerId, accountId);
        // first leave, delete an existing chat session
        IChatSessionManager sessionMgr = mConn.getChatSessionManager();
        if (sessionMgr != null) {
            IChatSession session = sessionMgr.getChatSession(Address.stripResource(address));
        }
        // then delete the contact from our list
        IContactListManager manager = mConn.getContactListManager();
        int res = manager.removeContact(address);
        if (res != ImErrorInfo.NO_ERROR) {
        // mHandler.showAlert(R.string.error,
        // ErrorResUtils.getErrorRes(getResources(), res, address));
        }
    } catch (RemoteException re) {
    }
}
Also used : IImConnection(org.awesomeapp.messenger.service.IImConnection) IChatSessionManager(org.awesomeapp.messenger.service.IChatSessionManager) ImApp(org.awesomeapp.messenger.ImApp) IContactListManager(org.awesomeapp.messenger.service.IContactListManager) RemoteException(android.os.RemoteException) IChatSession(org.awesomeapp.messenger.service.IChatSession) Paint(android.graphics.Paint)

Example 10 with IChatSession

use of org.awesomeapp.messenger.service.IChatSession in project Zom-Android by zom.

the class ConversationListItem method getEncryptionState.

private void getEncryptionState(long providerId, long accountId, String address, ConversationViewHolder holder) {
    try {
        ImApp app = ((ImApp) ((Activity) getContext()).getApplication());
        IImConnection conn = app.getConnection(providerId, accountId);
        if (conn == null || conn.getChatSessionManager() == null)
            return;
        IChatSession chatSession = conn.getChatSessionManager().getChatSession(address);
        if (chatSession != null) {
            if (chatSession.isEncrypted()) {
                holder.mStatusIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_encrypted_grey));
                holder.mStatusIcon.setVisibility(View.VISIBLE);
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
// mCurrentChatSession.getOtrChatSession();
}
Also used : IImConnection(org.awesomeapp.messenger.service.IImConnection) Activity(android.app.Activity) ImApp(org.awesomeapp.messenger.ImApp) IChatSession(org.awesomeapp.messenger.service.IChatSession)

Aggregations

IChatSession (org.awesomeapp.messenger.service.IChatSession)17 RemoteException (android.os.RemoteException)14 IChatSessionManager (org.awesomeapp.messenger.service.IChatSessionManager)10 IOException (java.io.IOException)4 XmppAddress (org.awesomeapp.messenger.plugin.xmpp.XmppAddress)4 Intent (android.content.Intent)3 DecoderException (org.apache.commons.codec.DecoderException)3 ImApp (org.awesomeapp.messenger.ImApp)3 Contact (org.awesomeapp.messenger.model.Contact)3 IImConnection (org.awesomeapp.messenger.service.IImConnection)3 CursorIndexOutOfBoundsException (android.database.CursorIndexOutOfBoundsException)2 Uri (android.net.Uri)2 IOtrChatSession (org.awesomeapp.messenger.crypto.IOtrChatSession)2 ChatSession (org.awesomeapp.messenger.model.ChatSession)2 IContactListManager (org.awesomeapp.messenger.service.IContactListManager)2 Activity (android.app.Activity)1 ProgressDialog (android.app.ProgressDialog)1 Paint (android.graphics.Paint)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1