Search in sources :

Example 6 with IqPacket

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

the class XmppConnectionService method sendUnblockRequest.

public void sendUnblockRequest(final Blockable blockable) {
    if (blockable != null && blockable.getJid() != null) {
        final Jid jid = blockable.getBlockedJid();
        this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetUnblockRequest(jid), new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(final Account account, final IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.RESULT) {
                    account.getBlocklist().remove(jid);
                    updateBlocklistUi(OnUpdateBlocklist.Status.UNBLOCKED);
                }
            }
        });
    }
}
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 7 with IqPacket

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

the class XmppConnectionService method republishAvatarIfNeeded.

public void republishAvatarIfNeeded(Account account) {
    if (account.getAxolotlService().isPepBroken()) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": skipping republication of avatar because pep is broken");
        return;
    }
    IqPacket packet = this.mIqGenerator.retrieveAvatarMetaData(null);
    this.sendIqPacket(account, packet, new OnIqPacketReceived() {

        private Avatar parseAvatar(IqPacket packet) {
            Element pubsub = packet.findChild("pubsub", "http://jabber.org/protocol/pubsub");
            if (pubsub != null) {
                Element items = pubsub.findChild("items");
                if (items != null) {
                    return Avatar.parseMetadata(items);
                }
            }
            return null;
        }

        private boolean errorIsItemNotFound(IqPacket packet) {
            Element error = packet.findChild("error");
            return packet.getType() == IqPacket.TYPE.ERROR && error != null && error.hasChild("item-not-found");
        }

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT || errorIsItemNotFound(packet)) {
                Avatar serverAvatar = parseAvatar(packet);
                if (serverAvatar == null && account.getAvatar() != null) {
                    Avatar avatar = fileBackend.getStoredPepAvatar(account.getAvatar());
                    if (avatar != null) {
                        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": avatar on server was null. republishing");
                        publishAvatar(account, fileBackend.getStoredPepAvatar(account.getAvatar()), null);
                    } else {
                        Log.e(Config.LOGTAG, account.getJid().toBareJid() + ": error rereading avatar");
                    }
                }
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) Avatar(de.pixart.messenger.xmpp.pep.Avatar) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 8 with IqPacket

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

the class XmppConnectionService method publishAvatar.

public void publishAvatar(Account account, final Avatar avatar, final UiCallback<Avatar> callback) {
    IqPacket packet = this.mIqGenerator.publishAvatar(avatar);
    this.sendIqPacket(account, packet, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket result) {
            if (result.getType() == IqPacket.TYPE.RESULT) {
                final IqPacket packet = XmppConnectionService.this.mIqGenerator.publishAvatarMetadata(avatar);
                sendIqPacket(account, packet, new OnIqPacketReceived() {

                    @Override
                    public void onIqPacketReceived(Account account, IqPacket result) {
                        if (result.getType() == IqPacket.TYPE.RESULT) {
                            if (account.setAvatar(avatar.getFilename())) {
                                getAvatarService().clear(account);
                                databaseBackend.updateAccount(account);
                            }
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": published avatar " + (avatar.size / 1024) + "KiB");
                            if (callback != null) {
                                callback.success(avatar);
                            }
                        } else {
                            if (callback != null) {
                                callback.error(R.string.error_publish_avatar_server_reject, avatar);
                            }
                        }
                    }
                });
            } else {
                Element error = result.findChild("error");
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server rejected avatar " + (avatar.size / 1024) + "KiB " + (error != null ? error.toString() : ""));
                if (callback != null) {
                    callback.error(R.string.error_publish_avatar_server_reject, avatar);
                }
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 9 with IqPacket

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

the class XmppConnectionService method fetchConferenceConfiguration.

public void fetchConferenceConfiguration(final Conversation conversation, final OnConferenceConfigurationFetched callback) {
    IqPacket request = new IqPacket(IqPacket.TYPE.GET);
    request.setTo(conversation.getJid().toBareJid());
    request.query("http://jabber.org/protocol/disco#info");
    sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            Element query = packet.findChild("query", "http://jabber.org/protocol/disco#info");
            if (packet.getType() == IqPacket.TYPE.RESULT && query != null) {
                ArrayList<String> features = new ArrayList<>();
                for (Element child : query.getChildren()) {
                    if (child != null && child.getName().equals("feature")) {
                        String var = child.getAttribute("var");
                        if (var != null) {
                            features.add(var);
                        }
                    }
                }
                Element form = query.findChild("x", Namespace.DATA);
                if (form != null) {
                    conversation.getMucOptions().updateFormData(Data.parse(form));
                }
                conversation.getMucOptions().updateFeatures(features);
                if (callback != null) {
                    callback.onConferenceConfigurationFetched(conversation);
                }
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetched muc configuration for " + conversation.getJid().toBareJid() + " - " + features.toString());
                updateConversationUi();
            } else if (packet.getType() == IqPacket.TYPE.ERROR) {
                if (callback != null) {
                    callback.onFetchFailed(conversation, packet.getError());
                }
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 10 with IqPacket

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

the class XmppConnectionService method changeAffiliationInConference.

public void changeAffiliationInConference(final Conversation conference, Jid user, final MucOptions.Affiliation affiliation, final OnAffiliationChanged callback) {
    final Jid jid = user.toBareJid();
    IqPacket request = this.mIqGenerator.changeAffiliation(conference, jid, affiliation.toString());
    sendIqPacket(conference.getAccount(), request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                conference.getMucOptions().changeAffiliation(jid, affiliation);
                getAvatarService().clear(conference);
                callback.onAffiliationChangedSuccessful(jid);
            } else {
                callback.onAffiliationChangeFailed(jid, R.string.could_not_change_affiliation);
            }
        }
    });
}
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)

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