Search in sources :

Example 6 with IContactListManager

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

the class AddContactAsyncTask method getContactList.

private IContactList getContactList(IImConnection conn) {
    if (conn == null) {
        return null;
    }
    try {
        IContactListManager contactListMgr = conn.getContactListManager();
        // Use the default list
        List<IBinder> lists = contactListMgr.getContactLists();
        for (IBinder binder : lists) {
            IContactList list = IContactList.Stub.asInterface(binder);
            if (list.isDefault()) {
                return list;
            }
        }
        // No default list, use the first one as default list
        if (!lists.isEmpty()) {
            return IContactList.Stub.asInterface(lists.get(0));
        }
        return null;
    } catch (RemoteException e) {
        // If the service has died, there is no list for now.
        return null;
    }
}
Also used : IBinder(android.os.IBinder) IContactList(org.awesomeapp.messenger.service.IContactList) IContactListManager(org.awesomeapp.messenger.service.IContactListManager) RemoteException(android.os.RemoteException)

Example 7 with IContactListManager

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

the class MigrateAccountTask method getContactList.

private IContactList getContactList(IImConnection conn) {
    if (conn == null) {
        return null;
    }
    try {
        IContactListManager contactListMgr = conn.getContactListManager();
        // Use the default list
        List<IBinder> lists = contactListMgr.getContactLists();
        for (IBinder binder : lists) {
            IContactList list = IContactList.Stub.asInterface(binder);
            if (list.isDefault()) {
                return list;
            }
        }
        // No default list, use the first one as default list
        if (!lists.isEmpty()) {
            return IContactList.Stub.asInterface(lists.get(0));
        }
        return null;
    } catch (RemoteException e) {
        // If the service has died, there is no list for now.
        return null;
    }
}
Also used : IBinder(android.os.IBinder) IContactList(org.awesomeapp.messenger.service.IContactList) IContactListManager(org.awesomeapp.messenger.service.IContactListManager) RemoteException(android.os.RemoteException)

Example 8 with IContactListManager

use of org.awesomeapp.messenger.service.IContactListManager 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 IContactListManager

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

the class ContactListItem method declineSubscription.

void declineSubscription() {
    ImApp app = ((ImApp) ((Activity) getContext()).getApplication());
    IImConnection mConn = app.getConnection(mHolder.mProviderId, mHolder.mAccountId);
    if (mConn != null) {
        try {
            IContactListManager manager = mConn.getContactListManager();
            manager.declineSubscription(new Contact(new XmppAddress(address), nickname, Imps.Contacts.TYPE_NORMAL));
            app.dismissChatNotification(mHolder.mProviderId, address);
            manager.removeContact(address);
        } catch (RemoteException e) {
            // mHandler.showServiceErrorAlert(e.getLocalizedMessage());
            LogCleaner.error(ImApp.LOG_TAG, "decline sub error", e);
        }
    }
}
Also used : IImConnection(org.awesomeapp.messenger.service.IImConnection) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) Activity(android.app.Activity) ImApp(org.awesomeapp.messenger.ImApp) IContactListManager(org.awesomeapp.messenger.service.IContactListManager) RemoteException(android.os.RemoteException) Contact(org.awesomeapp.messenger.model.Contact)

Example 10 with IContactListManager

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

the class ContactListItem method approveSubscription.

/*
    private String queryGroupMembers(ContentResolver resolver, long groupId) {
        String[] projection = { Imps.GroupMembers.NICKNAME };
        Uri uri = ContentUris.withAppendedId(Imps.GroupMembers.CONTENT_URI, groupId);
        Cursor c = resolver.query(uri, projection, null, null, null);
        StringBuilder buf = new StringBuilder();
        if (c != null) {
            while (c.moveToNext()) {
                buf.append(c.getString(0));
                                                Imps.Avatars.DATA
                if (!c.isLast()) {
                    buf.append(',');
                }
            }
        }
        c.close();

        return buf.toString();
    }*/
void approveSubscription() {
    ImApp app = ((ImApp) ((Activity) getContext()).getApplication());
    IImConnection mConn = app.getConnection(mHolder.mProviderId, mHolder.mAccountId);
    if (mConn != null) {
        try {
            IContactListManager manager = mConn.getContactListManager();
            manager.approveSubscription(new Contact(new XmppAddress(address), nickname, Imps.Contacts.TYPE_NORMAL));
        } catch (RemoteException e) {
            // mHandler.showServiceErrorAlert(e.getLocalizedMessage());
            LogCleaner.error(ImApp.LOG_TAG, "approve sub error", e);
        }
    }
}
Also used : IImConnection(org.awesomeapp.messenger.service.IImConnection) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) Activity(android.app.Activity) ImApp(org.awesomeapp.messenger.ImApp) IContactListManager(org.awesomeapp.messenger.service.IContactListManager) RemoteException(android.os.RemoteException) Contact(org.awesomeapp.messenger.model.Contact)

Aggregations

RemoteException (android.os.RemoteException)21 IContactListManager (org.awesomeapp.messenger.service.IContactListManager)21 IImConnection (org.awesomeapp.messenger.service.IImConnection)9 ImApp (org.awesomeapp.messenger.ImApp)6 IOException (java.io.IOException)5 Contact (org.awesomeapp.messenger.model.Contact)5 XmppAddress (org.awesomeapp.messenger.plugin.xmpp.XmppAddress)5 CursorIndexOutOfBoundsException (android.database.CursorIndexOutOfBoundsException)4 IContactList (org.awesomeapp.messenger.service.IContactList)4 Activity (android.app.Activity)3 DialogInterface (android.content.DialogInterface)3 Resources (android.content.res.Resources)3 Paint (android.graphics.Paint)3 IBinder (android.os.IBinder)3 IChatSession (org.awesomeapp.messenger.service.IChatSession)2 IChatSessionManager (org.awesomeapp.messenger.service.IChatSessionManager)2 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1