Search in sources :

Example 6 with Jid

use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.

the class XmppConnectionService method persistSelfNick.

public void persistSelfNick(MucOptions.User self) {
    final Conversation conversation = self.getConversation();
    final boolean tookProposedNickFromBookmark = conversation.getMucOptions().isTookProposedNickFromBookmark();
    Jid full = self.getFullJid();
    if (!full.equals(conversation.getJid())) {
        Log.d(Config.LOGTAG, "nick changed. updating");
        conversation.setContactJid(full);
        databaseBackend.updateConversation(conversation);
    }
    final Bookmark bookmark = conversation.getBookmark();
    final String bookmarkedNick = bookmark == null ? null : bookmark.getNick();
    if (bookmark != null && (tookProposedNickFromBookmark || TextUtils.isEmpty(bookmarkedNick)) && !full.getResource().equals(bookmarkedNick)) {
        final Account account = conversation.getAccount();
        final String defaultNick = MucOptions.defaultNick(account);
        if (TextUtils.isEmpty(bookmarkedNick) && full.getResource().equals(defaultNick)) {
            Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": do not overwrite empty bookmark nick with default nick for " + conversation.getJid().asBareJid());
            return;
        }
        Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": persist nick '" + full.getResource() + "' into bookmark for " + conversation.getJid().asBareJid());
        bookmark.setNick(full.getResource());
        createBookmark(bookmark.getAccount(), bookmark);
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.Jid) Bookmark(eu.siacs.conversations.entities.Bookmark) Conversation(eu.siacs.conversations.entities.Conversation)

Example 7 with Jid

use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.

the class XmppConnectionService method provisionAccount.

private void provisionAccount(final String address, final String password) {
    final Jid jid = Jid.ofEscaped(address);
    final Account account = new Account(jid, password);
    account.setOption(Account.OPTION_DISABLED, true);
    Log.d(Config.LOGTAG, jid.asBareJid().toEscapedString() + ": provisioning account");
    createAccount(account);
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.Jid)

Example 8 with Jid

use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.

the class XmppConnectionService method changeAffiliationInConference.

public void changeAffiliationInConference(final Conversation conference, Jid user, final MucOptions.Affiliation affiliation, final OnAffiliationChanged callback) {
    final Jid jid = user.asBareJid();
    final IqPacket request = this.mIqGenerator.changeAffiliation(conference, jid, affiliation.toString());
    sendIqPacket(conference.getAccount(), request, (account, response) -> {
        if (response.getType() == IqPacket.TYPE.RESULT) {
            conference.getMucOptions().changeAffiliation(jid, affiliation);
            getAvatarService().clear(conference);
            if (callback != null) {
                callback.onAffiliationChangedSuccessful(jid);
            } else {
                Log.d(Config.LOGTAG, "changed affiliation of " + user + " to " + affiliation);
            }
        } else if (callback != null) {
            callback.onAffiliationChangeFailed(jid, R.string.could_not_change_affiliation);
        } else {
            Log.d(Config.LOGTAG, "unable to change affiliation");
        }
    });
}
Also used : Jid(eu.siacs.conversations.xmpp.Jid) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 9 with Jid

use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.

the class XmppConnectionService method joinMuc.

private void joinMuc(Conversation conversation, final OnConferenceJoined onConferenceJoined, final boolean followedInvite) {
    final Account account = conversation.getAccount();
    synchronized (account.pendingConferenceJoins) {
        account.pendingConferenceJoins.remove(conversation);
    }
    synchronized (account.pendingConferenceLeaves) {
        account.pendingConferenceLeaves.remove(conversation);
    }
    if (account.getStatus() == Account.State.ONLINE) {
        synchronized (account.inProgressConferenceJoins) {
            account.inProgressConferenceJoins.add(conversation);
        }
        if (Config.MUC_LEAVE_BEFORE_JOIN) {
            sendPresencePacket(account, mPresenceGenerator.leave(conversation.getMucOptions()));
        }
        conversation.resetMucOptions();
        if (onConferenceJoined != null) {
            conversation.getMucOptions().flagNoAutoPushConfiguration();
        }
        conversation.setHasMessagesLeftOnServer(false);
        fetchConferenceConfiguration(conversation, new OnConferenceConfigurationFetched() {

            private void join(Conversation conversation) {
                Account account = conversation.getAccount();
                final MucOptions mucOptions = conversation.getMucOptions();
                if (mucOptions.nonanonymous() && !mucOptions.membersOnly() && !conversation.getBooleanAttribute("accept_non_anonymous", false)) {
                    synchronized (account.inProgressConferenceJoins) {
                        account.inProgressConferenceJoins.remove(conversation);
                    }
                    mucOptions.setError(MucOptions.Error.NON_ANONYMOUS);
                    updateConversationUi();
                    if (onConferenceJoined != null) {
                        onConferenceJoined.onConferenceJoined(conversation);
                    }
                    return;
                }
                final Jid joinJid = mucOptions.getSelf().getFullJid();
                Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": joining conversation " + joinJid.toString());
                PresencePacket packet = mPresenceGenerator.selfPresence(account, Presence.Status.ONLINE, mucOptions.nonanonymous() || onConferenceJoined != null);
                packet.setTo(joinJid);
                Element x = packet.addChild("x", "http://jabber.org/protocol/muc");
                if (conversation.getMucOptions().getPassword() != null) {
                    x.addChild("password").setContent(mucOptions.getPassword());
                }
                if (mucOptions.mamSupport()) {
                    // Use MAM instead of the limited muc history to get history
                    x.addChild("history").setAttribute("maxchars", "0");
                } else {
                    // Fallback to muc history
                    x.addChild("history").setAttribute("since", PresenceGenerator.getTimestamp(conversation.getLastMessageTransmitted().getTimestamp()));
                }
                sendPresencePacket(account, packet);
                if (onConferenceJoined != null) {
                    onConferenceJoined.onConferenceJoined(conversation);
                }
                if (!joinJid.equals(conversation.getJid())) {
                    conversation.setContactJid(joinJid);
                    databaseBackend.updateConversation(conversation);
                }
                if (mucOptions.mamSupport()) {
                    getMessageArchiveService().catchupMUC(conversation);
                }
                if (mucOptions.isPrivateAndNonAnonymous()) {
                    fetchConferenceMembers(conversation);
                    if (followedInvite) {
                        final Bookmark bookmark = conversation.getBookmark();
                        if (bookmark != null) {
                            if (!bookmark.autojoin()) {
                                bookmark.setAutojoin(true);
                                createBookmark(account, bookmark);
                            }
                        } else {
                            saveConversationAsBookmark(conversation, null);
                        }
                    }
                }
                synchronized (account.inProgressConferenceJoins) {
                    account.inProgressConferenceJoins.remove(conversation);
                    sendUnsentMessages(conversation);
                }
            }

            @Override
            public void onConferenceConfigurationFetched(Conversation conversation) {
                if (conversation.getStatus() == Conversation.STATUS_ARCHIVED) {
                    Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": conversation (" + conversation.getJid() + ") got archived before IQ result");
                    return;
                }
                join(conversation);
            }

            @Override
            public void onFetchFailed(final Conversation conversation, final String errorCondition) {
                if (conversation.getStatus() == Conversation.STATUS_ARCHIVED) {
                    Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": conversation (" + conversation.getJid() + ") got archived before IQ result");
                    return;
                }
                if ("remote-server-not-found".equals(errorCondition)) {
                    synchronized (account.inProgressConferenceJoins) {
                        account.inProgressConferenceJoins.remove(conversation);
                    }
                    conversation.getMucOptions().setError(MucOptions.Error.SERVER_NOT_FOUND);
                    updateConversationUi();
                } else {
                    join(conversation);
                    fetchConferenceConfiguration(conversation);
                }
            }
        });
        updateConversationUi();
    } else {
        synchronized (account.pendingConferenceJoins) {
            account.pendingConferenceJoins.add(conversation);
        }
        conversation.resetMucOptions();
        conversation.setHasMessagesLeftOnServer(false);
        updateConversationUi();
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) MucOptions(eu.siacs.conversations.entities.MucOptions) Jid(eu.siacs.conversations.xmpp.Jid) Bookmark(eu.siacs.conversations.entities.Bookmark) Element(eu.siacs.conversations.xml.Element) Conversation(eu.siacs.conversations.entities.Conversation) PresencePacket(eu.siacs.conversations.xmpp.stanzas.PresencePacket)

Example 10 with Jid

use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.

the class XmppConnectionService method loadPhoneContacts.

public void loadPhoneContacts() {
    mContactMergerExecutor.execute(() -> {
        Map<Jid, JabberIdContact> contacts = JabberIdContact.load(this);
        Log.d(Config.LOGTAG, "start merging phone contacts with roster");
        for (Account account : accounts) {
            List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts(JabberIdContact.class);
            for (JabberIdContact jidContact : contacts.values()) {
                final Contact contact = account.getRoster().getContact(jidContact.getJid());
                boolean needsCacheClean = contact.setPhoneContact(jidContact);
                if (needsCacheClean) {
                    getAvatarService().clear(contact);
                }
                withSystemAccounts.remove(contact);
            }
            for (Contact contact : withSystemAccounts) {
                boolean needsCacheClean = contact.unsetPhoneContact(JabberIdContact.class);
                if (needsCacheClean) {
                    getAvatarService().clear(contact);
                }
            }
        }
        Log.d(Config.LOGTAG, "finished merging phone contacts");
        mShortcutService.refresh(mInitialAddressbookSyncCompleted.compareAndSet(false, true));
        updateRosterUi();
        mQuickConversationsService.considerSync();
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.Jid) JabberIdContact(eu.siacs.conversations.android.JabberIdContact) Contact(eu.siacs.conversations.entities.Contact) JabberIdContact(eu.siacs.conversations.android.JabberIdContact)

Aggregations

Jid (eu.siacs.conversations.xmpp.Jid)106 Account (eu.siacs.conversations.entities.Account)35 Element (eu.siacs.conversations.xml.Element)24 Conversation (eu.siacs.conversations.entities.Conversation)22 Contact (eu.siacs.conversations.entities.Contact)17 InvalidJid (eu.siacs.conversations.xmpp.InvalidJid)16 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)16 Intent (android.content.Intent)15 ArrayList (java.util.ArrayList)13 MucOptions (eu.siacs.conversations.entities.MucOptions)12 Bookmark (eu.siacs.conversations.entities.Bookmark)10 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)7 Message (eu.siacs.conversations.entities.Message)7 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)6 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)6 Map (java.util.Map)6 XmppUri (eu.siacs.conversations.utils.XmppUri)5 XmppConnectionService (eu.siacs.conversations.services.XmppConnectionService)4 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)4 HashMap (java.util.HashMap)4