Search in sources :

Example 51 with IqPacket

use of de.pixart.messenger.xmpp.stanzas.IqPacket in project Pix-Art-Messenger by kriztan.

the class PushManagementService method enablePushOnServer.

private void enablePushOnServer(final Account account, final Jid jid, final String node, final String secret) {
    IqPacket enable = mXmppConnectionService.getIqGenerator().enablePush(jid, node, secret);
    mXmppConnectionService.sendIqPacket(account, enable, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": successfully enabled push on server");
            } else if (packet.getType() == IqPacket.TYPE.ERROR) {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": enabling push on server failed");
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 52 with IqPacket

use of de.pixart.messenger.xmpp.stanzas.IqPacket in project Pix-Art-Messenger by kriztan.

the class PushManagementService method registerPushTokenOnServer.

public void registerPushTokenOnServer(final Account account) {
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": has push support");
    retrieveGcmInstanceToken(new OnGcmInstanceTokenRetrieved() {

        @Override
        public void onGcmInstanceTokenRetrieved(String token) {
            try {
                final String deviceId = Settings.Secure.getString(mXmppConnectionService.getContentResolver(), Settings.Secure.ANDROID_ID);
                IqPacket packet = mXmppConnectionService.getIqGenerator().pushTokenToAppServer(Jid.fromString(APP_SERVER), token, deviceId);
                mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {

                    @Override
                    public void onIqPacketReceived(Account account, IqPacket packet) {
                        Element command = packet.findChild("command", "http://jabber.org/protocol/commands");
                        if (packet.getType() == IqPacket.TYPE.RESULT && command != null) {
                            Element x = command.findChild("x", Namespace.DATA);
                            if (x != null) {
                                Data data = Data.parse(x);
                                try {
                                    String node = data.getValue("node");
                                    String secret = data.getValue("secret");
                                    Jid jid = Jid.fromString(data.getValue("jid"));
                                    if (node != null && secret != null) {
                                        enablePushOnServer(account, jid, node, secret);
                                    }
                                } catch (InvalidJidException e) {
                                    e.printStackTrace();
                                }
                            }
                        } else {
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": invalid response from app server");
                        }
                    }
                });
            } catch (InvalidJidException ignored) {
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Data(de.pixart.messenger.xmpp.forms.Data) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 53 with IqPacket

use of de.pixart.messenger.xmpp.stanzas.IqPacket in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method changeRoleInConference.

public void changeRoleInConference(final Conversation conference, final String nick, MucOptions.Role role, final OnRoleChanged callback) {
    IqPacket request = this.mIqGenerator.changeRole(conference, nick, role.toString());
    Log.d(Config.LOGTAG, request.toString());
    sendIqPacket(conference.getAccount(), request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            Log.d(Config.LOGTAG, packet.toString());
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                callback.onRoleChangedSuccessful(nick);
            } else {
                callback.onRoleChangeFailed(nick, R.string.could_not_change_role);
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 54 with IqPacket

use of de.pixart.messenger.xmpp.stanzas.IqPacket in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method sendBlockRequest.

public boolean sendBlockRequest(final Blockable blockable, boolean reportSpam) {
    if (blockable != null && blockable.getBlockedJid() != null) {
        final Jid jid = blockable.getBlockedJid();
        this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid, reportSpam), new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(final Account account, final IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.RESULT) {
                    account.getBlocklist().add(jid);
                    updateBlocklistUi(OnUpdateBlocklist.Status.BLOCKED);
                }
            }
        });
        if (removeBlockedConversations(blockable.getAccount(), jid)) {
            updateConversationUi();
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 55 with IqPacket

use of de.pixart.messenger.xmpp.stanzas.IqPacket in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method updateAccountPasswordOnServer.

public void updateAccountPasswordOnServer(final Account account, final String newPassword, final OnAccountPasswordChanged callback) {
    final IqPacket iq = getIqGenerator().generateSetPassword(account, newPassword);
    sendIqPacket(account, iq, (a, packet) -> {
        if (packet.getType() == IqPacket.TYPE.RESULT) {
            a.setPassword(newPassword);
            a.setOption(Account.OPTION_MAGIC_CREATE, false);
            databaseBackend.updateAccount(a);
            callback.onPasswordChangeSucceeded();
        } else {
            callback.onPasswordChangeFailed();
        }
    });
}
Also used : IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Aggregations

IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)81 Element (de.pixart.messenger.xml.Element)48 Account (de.pixart.messenger.entities.Account)39 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)31 Jid (de.pixart.messenger.xmpp.jid.Jid)15 ArrayList (java.util.ArrayList)7 Data (de.pixart.messenger.xmpp.forms.Data)6 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)6 PreKeyBundle (org.whispersystems.libsignal.state.PreKeyBundle)5 JinglePacket (de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket)4 IOException (java.io.IOException)4 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)4 Bundle (android.os.Bundle)3 Pair (android.util.Pair)3 Contact (de.pixart.messenger.entities.Contact)3 Conversation (de.pixart.messenger.entities.Conversation)3 FileNotFoundException (java.io.FileNotFoundException)3 InputStream (java.io.InputStream)3 HashSet (java.util.HashSet)3 List (java.util.List)3