Search in sources :

Example 1 with OnIqPacketReceived

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

the class XmppConnectionService method publishDisplayName.

public void publishDisplayName(Account account) {
    String displayName = account.getDisplayName();
    if (displayName != null && !displayName.isEmpty()) {
        IqPacket publish = mIqGenerator.publishNick(displayName);
        sendIqPacket(account, publish, new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(Account account, IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.ERROR) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not publish nick");
                }
            }
        });
    }
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 2 with OnIqPacketReceived

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

the class XmppConnectionService method fetchAvatarPep.

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

        @Override
        public void onIqPacketReceived(Account account, IqPacket result) {
            synchronized (mInProgressAvatarFetches) {
                mInProgressAvatarFetches.remove(generateFetchKey(account, avatar));
            }
            final String ERROR = account.getJid().toBareJid() + ": fetching avatar for " + avatar.owner + " failed ";
            if (result.getType() == IqPacket.TYPE.RESULT) {
                avatar.image = mIqParser.avatarData(result);
                if (avatar.image != null) {
                    if (getFileBackend().save(avatar)) {
                        if (account.getJid().toBareJid().equals(avatar.owner)) {
                            if (account.setAvatar(avatar.getFilename())) {
                                databaseBackend.updateAccount(account);
                            }
                            getAvatarService().clear(account);
                            updateConversationUi();
                            updateAccountUi();
                        } else {
                            Contact contact = account.getRoster().getContact(avatar.owner);
                            contact.setAvatar(avatar);
                            getAvatarService().clear(contact);
                            updateConversationUi();
                            updateRosterUi();
                        }
                        if (callback != null) {
                            callback.success(avatar);
                        }
                        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": successfully fetched pep avatar for " + avatar.owner);
                        return;
                    }
                } else {
                    Log.d(Config.LOGTAG, ERROR + "(parsing error)");
                }
            } else {
                Element error = result.findChild("error");
                if (error == null) {
                    Log.d(Config.LOGTAG, ERROR + "(server error)");
                } else {
                    Log.d(Config.LOGTAG, ERROR + error.toString());
                }
            }
            if (callback != null) {
                callback.error(0, null);
            }
        }
    });
}
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) Contact(de.pixart.messenger.entities.Contact)

Example 3 with OnIqPacketReceived

use of de.pixart.messenger.xmpp.OnIqPacketReceived 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 4 with OnIqPacketReceived

use of de.pixart.messenger.xmpp.OnIqPacketReceived 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 5 with OnIqPacketReceived

use of de.pixart.messenger.xmpp.OnIqPacketReceived 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)

Aggregations

Account (de.pixart.messenger.entities.Account)31 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)31 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)31 Element (de.pixart.messenger.xml.Element)17 Jid (de.pixart.messenger.xmpp.jid.Jid)8 PreKeyBundle (org.whispersystems.libsignal.state.PreKeyBundle)5 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)4 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)4 Bundle (android.os.Bundle)3 Contact (de.pixart.messenger.entities.Contact)3 Conversation (de.pixart.messenger.entities.Conversation)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 InvalidKeyIdException (org.whispersystems.libsignal.InvalidKeyIdException)3 UntrustedIdentityException (org.whispersystems.libsignal.UntrustedIdentityException)3 Pair (android.util.Pair)2 Data (de.pixart.messenger.xmpp.forms.Data)2 Content (de.pixart.messenger.xmpp.jingle.stanzas.Content)2 JinglePacket (de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket)2