Search in sources :

Example 1 with Contact

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

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

the class XmppConnection method loadVCard.

private boolean loadVCard(ContentResolver resolver, String jid) {
    try {
        debug(TAG, "loading vcard for: " + jid);
        EntityBareJid bareJid = JidCreate.entityBareFrom(jid);
        VCardManager vCardManager = VCardManager.getInstanceFor(mConnection);
        VCard vCard = vCardManager.loadVCard(bareJid);
        Contact contact = mContactListManager.getContact(bareJid.toString());
        if (!TextUtils.isEmpty(vCard.getNickName())) {
            if (!vCard.getNickName().equals(contact.getName())) {
                contact.setName(vCard.getNickName());
                mContactListManager.doSetContactName(contact.getAddress().getBareAddress(), contact.getName());
            }
        }
        // check for a forwarding address
        if (vCard.getJabberId() != null && (!vCard.getJabberId().equals(bareJid.toString()))) {
            contact.setForwardingAddress(vCard.getJabberId());
        } else {
            contact.setForwardingAddress(null);
        }
        // If VCard is loaded, then save the avatar to the personal folder.
        String avatarHash = vCard.getAvatarHash();
        if (avatarHash != null) {
            byte[] avatarBytes = vCard.getAvatar();
            if (avatarBytes != null) {
                debug(TAG, "found avatar image in vcard for: " + bareJid.toString());
                debug(TAG, "start avatar length: " + avatarBytes.length);
                int rowsUpdated = DatabaseUtils.updateAvatarBlob(resolver, Imps.Avatars.CONTENT_URI, avatarBytes, bareJid.toString());
                if (rowsUpdated <= 0)
                    DatabaseUtils.insertAvatarBlob(resolver, Imps.Avatars.CONTENT_URI, mProviderId, mAccountId, avatarBytes, avatarHash, bareJid.toString());
                return true;
            }
        }
    } catch (Exception e) {
        debug(TAG, "err loading vcard: " + e.toString());
        if (e.getMessage() != null) {
            String streamErr = e.getMessage();
            if (streamErr != null && (streamErr.contains("404") || streamErr.contains("503"))) {
                return false;
            }
        }
    }
    return false;
}
Also used : VCardManager(org.jivesoftware.smackx.vcardtemp.VCardManager) EntityBareJid(org.jxmpp.jid.EntityBareJid) VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard) OmemoFingerprint(org.jivesoftware.smackx.omemo.OmemoFingerprint) 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)

Example 3 with Contact

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

the class XmppConnection method makeUser.

private synchronized Contact makeUser(Imps.ProviderSettings.QueryMap providerSettings, ContentResolver contentResolver) {
    Contact contactUser = null;
    String nickname = Imps.Account.getNickname(contentResolver, mAccountId);
    String userName = Imps.Account.getUserName(contentResolver, mAccountId);
    String domain = providerSettings.getDomain();
    String xmppName = userName + '@' + domain + '/' + providerSettings.getXmppResource();
    contactUser = new Contact(new XmppAddress(xmppName), nickname, Imps.Contacts.TYPE_NORMAL);
    return contactUser;
}
Also used : Contact(org.awesomeapp.messenger.model.Contact)

Example 4 with Contact

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

the class ImUrlActivity method startChat.

public void startChat(long providerId, long accountId, String username, final boolean openChat) {
    if (username != null)
        new ChatSessionInitTask(((ImApp) getApplication()), providerId, accountId, Imps.Contacts.TYPE_NORMAL, true) {

            @Override
            protected void onPostExecute(Long chatId) {
                if (chatId != -1 && openChat) {
                    Intent intent = new Intent(ImUrlActivity.this, ConversationDetailActivity.class);
                    intent.putExtra("id", chatId);
                    startActivity(intent);
                }
                finish();
                super.onPostExecute(chatId);
            }
        }.executeOnExecutor(ImApp.sThreadPoolExecutor, new Contact(new XmppAddress(username)));
}
Also used : ChatSessionInitTask(org.awesomeapp.messenger.tasks.ChatSessionInitTask) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) Intent(android.content.Intent) Contact(org.awesomeapp.messenger.model.Contact)

Example 5 with Contact

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

Aggregations

Contact (org.awesomeapp.messenger.model.Contact)33 RemoteException (android.os.RemoteException)11 XmppAddress (org.awesomeapp.messenger.plugin.xmpp.XmppAddress)10 Presence (org.awesomeapp.messenger.model.Presence)6 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)6 Intent (android.content.Intent)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ImException (org.awesomeapp.messenger.model.ImException)5 IContactListManager (org.awesomeapp.messenger.service.IContactListManager)5 ContentValues (android.content.ContentValues)4 Uri (android.net.Uri)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 KeyManagementException (java.security.KeyManagementException)4 KeyStoreException (java.security.KeyStoreException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 CertificateException (java.security.cert.CertificateException)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)4 ContactList (org.awesomeapp.messenger.model.ContactList)4 IChatSession (org.awesomeapp.messenger.service.IChatSession)4