Search in sources :

Example 26 with Conversation

use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.

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) {
            final boolean previouslyOmittedPepFetch;
            synchronized (mInProgressAvatarFetches) {
                final String KEY = generateFetchKey(account, avatar);
                mInProgressAvatarFetches.remove(KEY);
                previouslyOmittedPepFetch = mOmittedPepAvatarFetches.remove(KEY);
            }
            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().asBareJid() + ": successfully fetched vCard avatar for " + avatar.owner + " omittedPep=" + previouslyOmittedPepFetch);
                        if (avatar.owner.isBareJid()) {
                            if (account.getJid().asBareJid().equals(avatar.owner) && account.getAvatar() == null) {
                                Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": had no avatar. replacing with vcard");
                                account.setAvatar(avatar.getFilename());
                                databaseBackend.updateAccount(account);
                                getAvatarService().clear(account);
                                updateAccountUi();
                            } else {
                                final Contact contact = account.getRoster().getContact(avatar.owner);
                                contact.setAvatar(avatar, previouslyOmittedPepFetch);
                                syncRoster(account);
                                getAvatarService().clear(contact);
                                updateRosterUi();
                            }
                            updateConversationUi();
                        } else {
                            Conversation conversation = find(account, avatar.owner.asBareJid());
                            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();
                                    }
                                    if (user.getRealJid() != null) {
                                        Contact contact = account.getRoster().getContact(user.getRealJid());
                                        contact.setAvatar(avatar);
                                        syncRoster(account);
                                        getAvatarService().clear(contact);
                                        updateRosterUi();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) Conversation(eu.siacs.conversations.entities.Conversation) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket) Contact(eu.siacs.conversations.entities.Contact) JabberIdContact(eu.siacs.conversations.android.JabberIdContact)

Example 27 with Conversation

use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.

the class ContactChooserTargetService method onGetChooserTargets.

@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    final ArrayList<ChooserTarget> chooserTargets = new ArrayList<>();
    if (!EventReceiver.hasEnabledAccounts(this)) {
        return chooserTargets;
    }
    final Intent intent = new Intent(this, XmppConnectionService.class);
    intent.setAction("contact_chooser");
    Compatibility.startService(this, intent);
    bindService(intent, this, Context.BIND_AUTO_CREATE);
    try {
        waitForService();
        final ArrayList<Conversation> conversations = new ArrayList<>();
        if (!mXmppConnectionService.areMessagesInitialized()) {
            return chooserTargets;
        }
        mXmppConnectionService.populateWithOrderedConversations(conversations, textOnly(matchedFilter));
        final ComponentName componentName = new ComponentName(this, ConversationsActivity.class);
        final int pixel = AvatarService.getSystemUiAvatarSize(this);
        for (Conversation conversation : conversations) {
            if (conversation.sentMessagesCount() == 0) {
                continue;
            }
            final String name = conversation.getName().toString();
            final Icon icon = Icon.createWithBitmap(mXmppConnectionService.getAvatarService().get(conversation, pixel));
            final float score = 1 - (1.0f / MAX_TARGETS) * chooserTargets.size();
            final Bundle extras = new Bundle();
            extras.putString(ConversationsActivity.EXTRA_CONVERSATION, conversation.getUuid());
            chooserTargets.add(new ChooserTarget(name, icon, score, componentName, extras));
            if (chooserTargets.size() >= MAX_TARGETS) {
                break;
            }
        }
    } catch (InterruptedException e) {
    }
    unbindService(this);
    return chooserTargets;
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Intent(android.content.Intent) Conversation(eu.siacs.conversations.entities.Conversation) ChooserTarget(android.service.chooser.ChooserTarget) ComponentName(android.content.ComponentName) Icon(android.graphics.drawable.Icon)

Example 28 with Conversation

use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.

the class MessageArchiveService method finalizeQuery.

private void finalizeQuery(final Query query, boolean done) {
    synchronized (this.queries) {
        if (!this.queries.remove(query)) {
            throw new IllegalStateException("Unable to remove query from queries");
        }
    }
    final Conversation conversation = query.getConversation();
    if (conversation != null) {
        conversation.sort();
        conversation.setHasMessagesLeftOnServer(!done);
    } else {
        for (Conversation tmp : this.mXmppConnectionService.getConversations()) {
            if (tmp.getAccount() == query.getAccount()) {
                tmp.sort();
            }
        }
    }
    if (query.hasCallback()) {
        query.callback(done);
    } else {
        this.mXmppConnectionService.updateConversationUi();
    }
}
Also used : Conversation(eu.siacs.conversations.entities.Conversation)

Example 29 with Conversation

use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.

the class StartConversationActivity method onJoinDialogPositiveClick.

@Override
public void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, TextInputLayout layout, AutoCompleteTextView jid, boolean isBookmarkChecked) {
    if (!xmppConnectionServiceBound) {
        return;
    }
    final Account account = getSelectedAccount(this, spinner);
    if (account == null) {
        return;
    }
    final String input = jid.getText().toString();
    Jid conferenceJid;
    try {
        conferenceJid = Jid.ofEscaped(input);
    } catch (final IllegalArgumentException e) {
        final XmppUri xmppUri = new XmppUri(input);
        if (xmppUri.isValidJid() && xmppUri.isAction(XmppUri.ACTION_JOIN)) {
            final Editable editable = jid.getEditableText();
            editable.clear();
            editable.append(xmppUri.getJid().toEscapedString());
            conferenceJid = xmppUri.getJid();
        } else {
            layout.setError(getString(R.string.invalid_jid));
            return;
        }
    }
    if (isBookmarkChecked) {
        Bookmark bookmark = account.getBookmark(conferenceJid);
        if (bookmark != null) {
            dialog.dismiss();
            openConversationsForBookmark(bookmark);
        } else {
            bookmark = new Bookmark(account, conferenceJid.asBareJid());
            bookmark.setAutojoin(getBooleanPreference("autojoin", R.bool.autojoin));
            final String nick = conferenceJid.getResource();
            if (nick != null && !nick.isEmpty() && !nick.equals(MucOptions.defaultNick(account))) {
                bookmark.setNick(nick);
            }
            xmppConnectionService.createBookmark(account, bookmark);
            final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true, true);
            bookmark.setConversation(conversation);
            dialog.dismiss();
            switchToConversation(conversation);
        }
    } else {
        final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true, true);
        dialog.dismiss();
        switchToConversation(conversation);
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.Jid) XmppUri(eu.siacs.conversations.utils.XmppUri) Bookmark(eu.siacs.conversations.entities.Bookmark) Editable(android.text.Editable) Conversation(eu.siacs.conversations.entities.Conversation)

Example 30 with Conversation

use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.

the class StartConversationActivity method openConversationForContact.

protected void openConversationForContact(Contact contact) {
    Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false, true);
    SoftKeyboardUtils.hideSoftKeyboard(this);
    switchToConversation(conversation);
}
Also used : Conversation(eu.siacs.conversations.entities.Conversation)

Aggregations

Conversation (eu.siacs.conversations.entities.Conversation)110 Account (eu.siacs.conversations.entities.Account)27 Message (eu.siacs.conversations.entities.Message)24 Jid (eu.siacs.conversations.xmpp.Jid)22 Contact (eu.siacs.conversations.entities.Contact)17 MucOptions (eu.siacs.conversations.entities.MucOptions)10 Intent (android.content.Intent)9 Element (eu.siacs.conversations.xml.Element)9 PendingIntent (android.app.PendingIntent)8 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)8 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)8 Uri (android.net.Uri)7 Conversational (eu.siacs.conversations.entities.Conversational)7 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)7 SuppressLint (android.annotation.SuppressLint)6 SpannableString (android.text.SpannableString)6 XmppConnection (eu.siacs.conversations.xmpp.XmppConnection)6 Jid (eu.siacs.conversations.xmpp.jid.Jid)6 ArrayList (java.util.ArrayList)6 Fragment (android.app.Fragment)4