Search in sources :

Example 6 with Contact

use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method loadPhoneContacts.

public void loadPhoneContacts() {
    mContactMergerExecutor.execute(new Runnable() {

        @Override
        public void run() {
            PhoneHelper.loadPhoneContacts(XmppConnectionService.this, new OnPhoneContactsLoadedListener() {

                @Override
                public void onPhoneContactsLoaded(List<Bundle> phoneContacts) {
                    Log.d(Config.LOGTAG, "start merging phone contacts with roster");
                    for (Account account : accounts) {
                        List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts();
                        for (Bundle phoneContact : phoneContacts) {
                            Jid jid;
                            try {
                                jid = Jid.fromString(phoneContact.getString("jid"));
                            } catch (final InvalidJidException e) {
                                continue;
                            }
                            final Contact contact = account.getRoster().getContact(jid);
                            String systemAccount = phoneContact.getInt("phoneid") + "#" + phoneContact.getString("lookup");
                            contact.setSystemAccount(systemAccount);
                            boolean needsCacheClean = contact.setPhotoUri(phoneContact.getString("photouri"));
                            needsCacheClean |= contact.setSystemName(phoneContact.getString("displayname"));
                            if (needsCacheClean) {
                                getAvatarService().clear(contact);
                            }
                            withSystemAccounts.remove(contact);
                        }
                        for (Contact contact : withSystemAccounts) {
                            contact.setSystemAccount(null);
                            boolean needsCacheClean = contact.setPhotoUri(null);
                            needsCacheClean |= contact.setSystemName(null);
                            if (needsCacheClean) {
                                getAvatarService().clear(contact);
                            }
                        }
                    }
                    Log.d(Config.LOGTAG, "finished merging phone contacts");
                    mShortcutService.refresh(mInitialAddressbookSyncCompleted.compareAndSet(false, true));
                    updateAccountUi();
                }
            });
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) Bundle(android.os.Bundle) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) OnPhoneContactsLoadedListener(de.pixart.messenger.utils.OnPhoneContactsLoadedListener) Contact(de.pixart.messenger.entities.Contact)

Example 7 with Contact

use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method findOrCreateConversation.

public Conversation findOrCreateConversation(final Account account, final Jid jid, final boolean muc, final boolean joinAfterCreate, final MessageArchiveService.Query query, final boolean async) {
    synchronized (this.conversations) {
        Conversation conversation = find(account, jid);
        if (conversation != null) {
            return conversation;
        }
        conversation = databaseBackend.findConversation(account, jid);
        final boolean loadMessagesFromDb;
        if (conversation != null) {
            conversation.setStatus(Conversation.STATUS_AVAILABLE);
            conversation.setAccount(account);
            if (muc) {
                conversation.setMode(Conversation.MODE_MULTI);
                conversation.setContactJid(jid);
            } else {
                conversation.setMode(Conversation.MODE_SINGLE);
                conversation.setContactJid(jid.toBareJid());
            }
            databaseBackend.updateConversation(conversation);
            loadMessagesFromDb = conversation.messagesLoaded.compareAndSet(true, false);
        } else {
            String conversationName;
            Contact contact = account.getRoster().getContact(jid);
            if (contact != null) {
                conversationName = contact.getDisplayName();
            } else {
                conversationName = jid.getLocalpart();
            }
            if (muc) {
                conversation = new Conversation(conversationName, account, jid, Conversation.MODE_MULTI);
            } else {
                conversation = new Conversation(conversationName, account, jid.toBareJid(), Conversation.MODE_SINGLE);
            }
            this.databaseBackend.createConversation(conversation);
            loadMessagesFromDb = false;
        }
        final Conversation c = conversation;
        final Runnable runnable = () -> {
            if (loadMessagesFromDb) {
                c.addAll(0, databaseBackend.getMessages(c, Config.PAGE_SIZE));
                updateConversationUi();
                c.messagesLoaded.set(true);
            }
            if (account.getXmppConnection() != null && !c.getContact().isBlocked() && account.getXmppConnection().getFeatures().mam() && !muc) {
                if (query == null) {
                    mMessageArchiveService.query(c);
                } else {
                    if (query.getConversation() == null) {
                        mMessageArchiveService.query(c, query.getStart(), query.isCatchup());
                    }
                }
            }
            checkDeletedFiles(c);
            if (joinAfterCreate) {
                joinMuc(c);
            }
        };
        if (async) {
            mDatabaseReaderExecutor.execute(runnable);
        } else {
            runnable.run();
        }
        this.conversations.add(conversation);
        updateConversationUi();
        return conversation;
    }
}
Also used : Conversation(de.pixart.messenger.entities.Conversation) Contact(de.pixart.messenger.entities.Contact)

Example 8 with Contact

use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method fetchAvatarVcard.

private void fetchAvatarVcard(final Account account, final Avatar avatar, final UiCallback<Avatar> callback) {
    IqPacket packet = this.mIqGenerator.retrieveVcardAvatar(avatar);
    this.sendIqPacket(account, packet, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            synchronized (mInProgressAvatarFetches) {
                mInProgressAvatarFetches.remove(generateFetchKey(account, avatar));
            }
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                Element vCard = packet.findChild("vCard", "vcard-temp");
                Element photo = vCard != null ? vCard.findChild("PHOTO") : null;
                String image = photo != null ? photo.findChildContent("BINVAL") : null;
                if (image != null) {
                    avatar.image = image;
                    if (getFileBackend().save(avatar)) {
                        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": successfully fetched vCard avatar for " + avatar.owner);
                        if (avatar.owner.isBareJid()) {
                            if (account.getJid().toBareJid().equals(avatar.owner) && account.getAvatar() == null) {
                                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": had no avatar. replacing with vcard");
                                account.setAvatar(avatar.getFilename());
                                databaseBackend.updateAccount(account);
                                getAvatarService().clear(account);
                                updateAccountUi();
                            } else {
                                Contact contact = account.getRoster().getContact(avatar.owner);
                                contact.setAvatar(avatar);
                                getAvatarService().clear(contact);
                                updateRosterUi();
                            }
                            updateConversationUi();
                        } else {
                            Conversation conversation = find(account, avatar.owner.toBareJid());
                            if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {
                                MucOptions.User user = conversation.getMucOptions().findUserByFullJid(avatar.owner);
                                if (user != null) {
                                    if (user.setAvatar(avatar)) {
                                        getAvatarService().clear(user);
                                        updateConversationUi();
                                        updateMucRosterUi();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) Conversation(de.pixart.messenger.entities.Conversation) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket) Contact(de.pixart.messenger.entities.Contact)

Example 9 with Contact

use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.

the class BlocklistActivity method filterContacts.

@Override
protected void filterContacts(final String needle) {
    getListItems().clear();
    if (account != null) {
        for (final Jid jid : account.getBlocklist()) {
            final Contact contact = account.getRoster().getContact(jid);
            if (contact.match(this, needle) && contact.isBlocked()) {
                getListItems().add(contact);
            }
        }
        Collections.sort(getListItems());
    }
    getListItemAdapter().notifyDataSetChanged();
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) Contact(de.pixart.messenger.entities.Contact)

Example 10 with Contact

use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.

the class ChooseContactActivity method filterContacts.

protected void filterContacts(final String needle) {
    getListItems().clear();
    if (xmppConnectionService == null) {
        getListItemAdapter().notifyDataSetChanged();
        return;
    }
    for (final Account account : xmppConnectionService.getAccounts()) {
        if (account.getStatus() != Account.State.DISABLED) {
            for (final Contact contact : account.getRoster().getContacts()) {
                if (contact.showInRoster() && !filterContacts.contains(contact.getJid().toBareJid().toString()) && contact.match(this, needle)) {
                    getListItems().add(contact);
                }
            }
        }
    }
    Collections.sort(getListItems());
    getListItemAdapter().notifyDataSetChanged();
}
Also used : Account(de.pixart.messenger.entities.Account) Contact(de.pixart.messenger.entities.Contact)

Aggregations

Contact (de.pixart.messenger.entities.Contact)39 Jid (de.pixart.messenger.xmpp.jid.Jid)16 Account (de.pixart.messenger.entities.Account)12 Conversation (de.pixart.messenger.entities.Conversation)11 Element (de.pixart.messenger.xml.Element)9 SuppressLint (android.annotation.SuppressLint)7 MucOptions (de.pixart.messenger.entities.MucOptions)6 AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)5 ArrayList (java.util.ArrayList)5 PendingIntent (android.app.PendingIntent)4 Intent (android.content.Intent)4 AlertDialog (android.support.v7.app.AlertDialog)4 MenuItem (android.view.MenuItem)4 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)4 DialogInterface (android.content.DialogInterface)3 Bitmap (android.graphics.Bitmap)3 Uri (android.net.Uri)3 Bundle (android.os.Bundle)3 Message (de.pixart.messenger.entities.Message)3 Presence (de.pixart.messenger.entities.Presence)3