Search in sources :

Example 1 with ContactList

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

the class XmppConnection method initNewContactProcessor.

private void initNewContactProcessor() {
    mTimerNewContacts = new Timer();
    mTimerNewContacts.scheduleAtFixedRate(new TimerTask() {

        public void run() {
            try {
                Contact contact = null;
                if (qNewContact.size() > 0)
                    while (qNewContact.peek() != null) {
                        contact = qNewContact.poll();
                        if (mConnection == null || (!mConnection.isConnected())) {
                            debug(TAG, "postponed adding new contact" + " because we are not connected");
                            // return the packet to the stack
                            qNewContact.add(contact);
                            return;
                        } else {
                            try {
                                RosterEntry rEntry;
                                ContactList list = mContactListManager.getDefaultContactList();
                                String[] groups = new String[] { list.getName() };
                                BareJid jid = JidCreate.bareFrom(contact.getAddress().getBareAddress());
                                rEntry = mRoster.getEntry(jid);
                                RosterGroup rGroup = mRoster.getGroup(list.getName());
                                if (rGroup == null) {
                                    if (rEntry == null) {
                                        mRoster.createEntry(jid, contact.getName(), groups);
                                        while ((rEntry = mRoster.getEntry(jid)) == null) {
                                            try {
                                                Thread.sleep(500);
                                            } catch (Exception e) {
                                            }
                                        }
                                    }
                                } else if (rEntry == null) {
                                    mRoster.createEntry(jid, contact.getName(), groups);
                                    while ((rEntry = mRoster.getEntry(jid)) == null) {
                                        try {
                                            Thread.sleep(500);
                                        } catch (Exception e) {
                                        }
                                    }
                                }
                                int subStatus = Imps.Contacts.SUBSCRIPTION_STATUS_NONE;
                                if (rEntry.isSubscriptionPending())
                                    subStatus = Imps.Contacts.SUBSCRIPTION_STATUS_SUBSCRIBE_PENDING;
                                int subType = Imps.Contacts.SUBSCRIPTION_TYPE_NONE;
                                if (rEntry.canSeeHisPresence() && rEntry.canSeeMyPresence()) {
                                    subType = Imps.Contacts.SUBSCRIPTION_TYPE_BOTH;
                                } else if (rEntry.canSeeHisPresence()) {
                                    subType = Imps.Contacts.SUBSCRIPTION_TYPE_FROM;
                                    if (rEntry.isSubscriptionPending()) {
                                        try {
                                            handleSubscribeRequest(rEntry.getJid());
                                        } catch (Exception e) {
                                            debug(TAG, "Error requesting subscribe notification", e);
                                        }
                                    }
                                } else if (rEntry.canSeeMyPresence()) {
                                    // it is still pending
                                    subType = Imps.Contacts.SUBSCRIPTION_TYPE_TO;
                                }
                                contact.setSubscriptionType(subType);
                                contact.setSubscriptionStatus(subStatus);
                                try {
                                    mContactListManager.getSubscriptionRequestListener().onSubScriptionChanged(contact, mProviderId, mAccountId, subType, subStatus);
                                } catch (Exception e) {
                                }
                            } catch (XMPPException e) {
                                debug(TAG, "error updating remote roster", e);
                                // try again later
                                qNewContact.add(contact);
                            } catch (Exception e) {
                                String msg = "Not logged in to server while updating remote roster";
                                debug(TAG, msg, e);
                                // try again later
                                qNewContact.add(contact);
                            }
                        }
                    }
            } catch (Exception e) {
                Log.e(TAG, "error sending packet", e);
            }
        }
    }, 500, 500);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) EntityBareJid(org.jxmpp.jid.EntityBareJid) BareJid(org.jxmpp.jid.BareJid) DomainBareJid(org.jxmpp.jid.DomainBareJid) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) ContactList(org.awesomeapp.messenger.model.ContactList) XMPPException(org.jivesoftware.smack.XMPPException) 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) OmemoFingerprint(org.jivesoftware.smackx.omemo.OmemoFingerprint) Contact(org.awesomeapp.messenger.model.Contact) RosterGroup(org.jivesoftware.smack.roster.RosterGroup)

Example 2 with ContactList

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

the class LoopbackConnection method doUpdateUserPresenceAsync.

@Override
protected void doUpdateUserPresenceAsync(Presence presence) {
    // mimic presence
    ContactList cl;
    try {
        cl = mContactListManager.getDefaultContactList();
    } catch (ImException e) {
        throw new RuntimeException(e);
    }
    if (cl == null)
        return;
    Collection<Contact> contacts = cl.getContacts();
    for (Iterator<Contact> iter = contacts.iterator(); iter.hasNext(); ) {
        Contact contact = iter.next();
        contact.setPresence(presence);
    }
    Contact[] contacts_array = new Contact[contacts.size()];
    contacts.toArray(contacts_array);
    mContactListManager.doPresence(contacts_array);
}
Also used : ImException(org.awesomeapp.messenger.model.ImException) ContactList(org.awesomeapp.messenger.model.ContactList) Contact(org.awesomeapp.messenger.model.Contact)

Example 3 with ContactList

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

the class XmppConnection method handleSubscribeRequest.

private void handleSubscribeRequest(Jid jid) throws ImException, RemoteException {
    Contact contact = mContactListManager.getContact(jid.asBareJid().toString());
    if (contact == null) {
        XmppAddress xAddr = new XmppAddress(jid.toString());
        contact = new Contact(xAddr, xAddr.getUser(), Imps.Contacts.TYPE_NORMAL);
    }
    if (contact.getSubscriptionType() == Imps.Contacts.SUBSCRIPTION_TYPE_BOTH || contact.getSubscriptionType() == Imps.Contacts.SUBSCRIPTION_TYPE_TO) {
        mContactListManager.approveSubscriptionRequest(contact);
    } else {
        ContactList cList = getContactListManager().getDefaultContactList();
        contact.setSubscriptionStatus(Imps.Contacts.SUBSCRIPTION_STATUS_SUBSCRIBE_PENDING);
        contact.setSubscriptionType(Imps.Contacts.SUBSCRIPTION_TYPE_FROM);
        mContactListManager.doAddContactToListAsync(contact, cList, false);
        mContactListManager.getSubscriptionRequestListener().onSubScriptionRequest(contact, mProviderId, mAccountId);
    }
    ChatSession session = findOrCreateSession(jid.toString(), false);
}
Also used : ContactList(org.awesomeapp.messenger.model.ContactList) ChatSession(org.awesomeapp.messenger.model.ChatSession) IChatSession(org.awesomeapp.messenger.service.IChatSession) Contact(org.awesomeapp.messenger.model.Contact)

Example 4 with ContactList

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

the class XmppConnection method initPresenceProcessor.

private void initPresenceProcessor() {
    mTimerPresence = new Timer();
    mTimerPresence.schedule(new TimerTask() {

        public void run() {
            if (qPresence.size() > 0) {
                try {
                    ContactList cList = getContactListManager().getDefaultContactList();
                    if (cList == null)
                        // not ready yet
                        return;
                } catch (Exception e) {
                    // not ready yet
                    return;
                }
                Map<String, Contact> alUpdate = new HashMap<String, Contact>();
                org.jivesoftware.smack.packet.Presence p = null;
                Contact contact = null;
                final int maxBatch = 20;
                while (qPresence.peek() != null && alUpdate.size() < maxBatch) {
                    p = qPresence.poll();
                    contact = handlePresenceChanged(p);
                    if (contact != null) {
                        alUpdate.put(contact.getAddress().getBareAddress(), contact);
                    }
                }
                if (alUpdate.size() > 0) {
                    loadVCardsAsync();
                    // Log.d(TAG,"XMPP processed presence q=" + alUpdate.size());
                    Collection<Contact> contactsUpdate = alUpdate.values();
                    if (mContactListManager != null)
                        mContactListManager.notifyContactsPresenceUpdated(contactsUpdate.toArray(new Contact[contactsUpdate.size()]));
                }
            }
        }
    }, 500, 500);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) Presence(org.awesomeapp.messenger.model.Presence) Collection(java.util.Collection) ContactList(org.awesomeapp.messenger.model.ContactList) Map(java.util.Map) HashMap(java.util.HashMap) 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) Contact(org.awesomeapp.messenger.model.Contact)

Aggregations

Contact (org.awesomeapp.messenger.model.Contact)4 ContactList (org.awesomeapp.messenger.model.ContactList)4 ImException (org.awesomeapp.messenger.model.ImException)3 RemoteException (android.os.RemoteException)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 CertificateException (java.security.cert.CertificateException)2 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 SmackException (org.jivesoftware.smack.SmackException)2 XMPPException (org.jivesoftware.smack.XMPPException)2 MultiUserChatException (org.jivesoftware.smackx.muc.MultiUserChatException)2 CryptoFailedException (org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException)2 UndecidedOmemoIdentityException (org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException)2 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)2 Collection (java.util.Collection)1