Search in sources :

Example 6 with OnIqPacketReceived

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

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

Example 8 with OnIqPacketReceived

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

the class XmppConnectionService method fetchBookmarks.

public void fetchBookmarks(final Account account) {
    final IqPacket iqPacket = new IqPacket(IqPacket.TYPE.GET);
    final Element query = iqPacket.query("jabber:iq:private");
    query.addChild("storage", "storage:bookmarks");
    final OnIqPacketReceived callback = new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(final Account account, final IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                final Element query = packet.query();
                final HashMap<Jid, Bookmark> bookmarks = new HashMap<>();
                final Element storage = query.findChild("storage", "storage:bookmarks");
                final boolean autojoin = respectAutojoin();
                if (storage != null) {
                    for (final Element item : storage.getChildren()) {
                        if (item.getName().equals("conference")) {
                            final Bookmark bookmark = Bookmark.parse(item, account);
                            Bookmark old = bookmarks.put(bookmark.getJid(), bookmark);
                            if (old != null && old.getBookmarkName() != null && bookmark.getBookmarkName() == null) {
                                bookmark.setBookmarkName(old.getBookmarkName());
                            }
                            Conversation conversation = find(bookmark);
                            if (conversation != null) {
                                bookmark.setConversation(conversation);
                            } else if (bookmark.autojoin() && bookmark.getJid() != null && autojoin) {
                                conversation = findOrCreateConversation(account, bookmark.getJid(), true, true, false);
                                bookmark.setConversation(conversation);
                            }
                        }
                    }
                }
                account.setBookmarks(new CopyOnWriteArrayList<>(bookmarks.values()));
            } else {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not fetch bookmarks");
            }
        }
    };
    sendIqPacket(account, iqPacket, callback);
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Jid(de.pixart.messenger.xmpp.jid.Jid) Bookmark(de.pixart.messenger.entities.Bookmark) HashMap(java.util.HashMap) Element(de.pixart.messenger.xml.Element) Conversation(de.pixart.messenger.entities.Conversation) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 9 with OnIqPacketReceived

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

the class XmppConnectionService method fetchMamPreferences.

public void fetchMamPreferences(Account account, final OnMamPreferencesFetched callback) {
    final boolean legacy = account.getXmppConnection().getFeatures().mamLegacy();
    IqPacket request = new IqPacket(IqPacket.TYPE.GET);
    request.addChild("prefs", legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
    sendIqPacket(account, request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            Element prefs = packet.findChild("prefs", legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
            if (packet.getType() == IqPacket.TYPE.RESULT && prefs != null) {
                callback.onPreferencesFetched(prefs);
            } else {
                callback.onPreferencesFetchFailed();
            }
        }
    });
}
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 10 with OnIqPacketReceived

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

the class XmppConnectionService method checkForAvatar.

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

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                Element pubsub = packet.findChild("pubsub", "http://jabber.org/protocol/pubsub");
                if (pubsub != null) {
                    Element items = pubsub.findChild("items");
                    if (items != null) {
                        Avatar avatar = Avatar.parseMetadata(items);
                        if (avatar != null) {
                            avatar.owner = account.getJid().toBareJid();
                            if (fileBackend.isAvatarCached(avatar)) {
                                if (account.setAvatar(avatar.getFilename())) {
                                    databaseBackend.updateAccount(account);
                                }
                                getAvatarService().clear(account);
                                callback.success(avatar);
                            } else {
                                fetchAvatarPep(account, avatar, callback);
                            }
                            return;
                        }
                    }
                }
            }
            callback.error(0, null);
        }
    });
}
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)

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