Search in sources :

Example 1 with OnRenameListener

use of eu.siacs.conversations.entities.MucOptions.OnRenameListener in project Conversations by siacs.

the class XmppConnectionService method renameInMuc.

public boolean renameInMuc(final Conversation conversation, final String nick, final UiCallback<Conversation> callback) {
    final MucOptions options = conversation.getMucOptions();
    final Jid joinJid = options.createJoinJid(nick);
    if (joinJid == null) {
        return false;
    }
    if (options.online()) {
        Account account = conversation.getAccount();
        options.setOnRenameListener(new OnRenameListener() {

            @Override
            public void onSuccess() {
                callback.success(conversation);
            }

            @Override
            public void onFailure() {
                callback.error(R.string.nick_in_use, conversation);
            }
        });
        final PresencePacket packet = mPresenceGenerator.selfPresence(account, Presence.Status.ONLINE, options.nonanonymous());
        packet.setTo(joinJid);
        sendPresencePacket(account, packet);
    } else {
        conversation.setContactJid(joinJid);
        databaseBackend.updateConversation(conversation);
        if (conversation.getAccount().getStatus() == Account.State.ONLINE) {
            Bookmark bookmark = conversation.getBookmark();
            if (bookmark != null) {
                bookmark.setNick(nick);
                createBookmark(bookmark.getAccount(), bookmark);
            }
            joinMuc(conversation);
        }
    }
    return true;
}
Also used : Account(eu.siacs.conversations.entities.Account) OnRenameListener(eu.siacs.conversations.entities.MucOptions.OnRenameListener) MucOptions(eu.siacs.conversations.entities.MucOptions) Jid(eu.siacs.conversations.xmpp.Jid) Bookmark(eu.siacs.conversations.entities.Bookmark) PresencePacket(eu.siacs.conversations.xmpp.stanzas.PresencePacket)

Aggregations

Account (eu.siacs.conversations.entities.Account)1 Bookmark (eu.siacs.conversations.entities.Bookmark)1 MucOptions (eu.siacs.conversations.entities.MucOptions)1 OnRenameListener (eu.siacs.conversations.entities.MucOptions.OnRenameListener)1 Jid (eu.siacs.conversations.xmpp.Jid)1 PresencePacket (eu.siacs.conversations.xmpp.stanzas.PresencePacket)1