Search in sources :

Example 1 with OnRenameListener

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

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);
            }
        });
        PresencePacket packet = new PresencePacket();
        packet.setTo(joinJid);
        packet.setFrom(conversation.getAccount().getJid());
        String sig = account.getPgpSignature();
        if (sig != null) {
            packet.addChild("status").setContent("online");
            packet.addChild("x", "jabber:x:signed").setContent(sig);
        }
        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);
                pushBookmarks(bookmark.getAccount());
            }
            joinMuc(conversation);
        }
    }
    return true;
}
Also used : Account(de.pixart.messenger.entities.Account) OnRenameListener(de.pixart.messenger.entities.MucOptions.OnRenameListener) MucOptions(de.pixart.messenger.entities.MucOptions) Jid(de.pixart.messenger.xmpp.jid.Jid) Bookmark(de.pixart.messenger.entities.Bookmark) PresencePacket(de.pixart.messenger.xmpp.stanzas.PresencePacket)

Aggregations

Account (de.pixart.messenger.entities.Account)1 Bookmark (de.pixart.messenger.entities.Bookmark)1 MucOptions (de.pixart.messenger.entities.MucOptions)1 OnRenameListener (de.pixart.messenger.entities.MucOptions.OnRenameListener)1 Jid (de.pixart.messenger.xmpp.jid.Jid)1 PresencePacket (de.pixart.messenger.xmpp.stanzas.PresencePacket)1