Search in sources :

Example 71 with IqPacket

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

the class XmppConnectionService method fetchCaps.

public void fetchCaps(Account account, final Jid jid, final Presence presence) {
    final Pair<String, String> key = new Pair<>(presence.getHash(), presence.getVer());
    ServiceDiscoveryResult disco = getCachedServiceDiscoveryResult(key);
    if (disco != null) {
        presence.setServiceDiscoveryResult(disco);
    } else {
        if (!account.inProgressDiscoFetches.contains(key)) {
            account.inProgressDiscoFetches.add(key);
            IqPacket request = new IqPacket(IqPacket.TYPE.GET);
            request.setTo(jid);
            request.query("http://jabber.org/protocol/disco#info");
            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": making disco request for " + key.second + " to " + jid);
            sendIqPacket(account, request, new OnIqPacketReceived() {

                @Override
                public void onIqPacketReceived(Account account, IqPacket discoPacket) {
                    if (discoPacket.getType() == IqPacket.TYPE.RESULT) {
                        ServiceDiscoveryResult disco = new ServiceDiscoveryResult(discoPacket);
                        if (presence.getVer().equals(disco.getVer())) {
                            databaseBackend.insertDiscoveryResult(disco);
                            injectServiceDiscorveryResult(account.getRoster(), presence.getHash(), presence.getVer(), disco);
                        } else {
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": mismatch in caps for contact " + jid + " " + presence.getVer() + " vs " + disco.getVer());
                        }
                    }
                    account.inProgressDiscoFetches.remove(key);
                }
            });
        }
    }
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) ServiceDiscoveryResult(de.pixart.messenger.entities.ServiceDiscoveryResult) Pair(android.util.Pair) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 72 with IqPacket

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

the class XmppConnectionService method fetchConferenceMembers.

private void fetchConferenceMembers(final Conversation conversation) {
    final Account account = conversation.getAccount();
    final AxolotlService axolotlService = account.getAxolotlService();
    final String[] affiliations = { "member", "admin", "owner" };
    OnIqPacketReceived callback = new OnIqPacketReceived() {

        private int i = 0;

        private boolean success = true;

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            Element query = packet.query("http://jabber.org/protocol/muc#admin");
            if (packet.getType() == IqPacket.TYPE.RESULT && query != null) {
                for (Element child : query.getChildren()) {
                    if ("item".equals(child.getName())) {
                        MucOptions.User user = AbstractParser.parseItem(conversation, child);
                        if (!user.realJidMatchesAccount()) {
                            boolean isNew = conversation.getMucOptions().updateUser(user);
                            Contact contact = user.getContact();
                            if (isNew && user.getRealJid() != null && (contact == null || !contact.mutualPresenceSubscription()) && axolotlService.hasEmptyDeviceList(user.getRealJid())) {
                                axolotlService.fetchDeviceIds(user.getRealJid());
                            }
                        }
                    }
                }
            } else {
                success = false;
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not request affiliation " + affiliations[i] + " in " + conversation.getJid().toBareJid());
            }
            ++i;
            if (i >= affiliations.length) {
                List<Jid> members = conversation.getMucOptions().getMembers();
                if (success) {
                    List<Jid> cryptoTargets = conversation.getAcceptedCryptoTargets();
                    boolean changed = false;
                    for (ListIterator<Jid> iterator = cryptoTargets.listIterator(); iterator.hasNext(); ) {
                        Jid jid = iterator.next();
                        if (!members.contains(jid)) {
                            iterator.remove();
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": removed " + jid + " from crypto targets of " + conversation.getName());
                            changed = true;
                        }
                    }
                    if (changed) {
                        conversation.setAcceptedCryptoTargets(cryptoTargets);
                        updateConversation(conversation);
                    }
                }
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": retrieved members for " + conversation.getJid().toBareJid() + ": " + conversation.getMucOptions().getMembers());
                getAvatarService().clear(conversation);
                updateMucRosterUi();
                updateConversationUi();
            }
        }
    };
    for (String affiliation : affiliations) {
        sendIqPacket(account, mIqGenerator.queryAffiliation(conversation, affiliation), callback);
    }
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching members for " + conversation.getName());
}
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) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket) Contact(de.pixart.messenger.entities.Contact) AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService) MucOptions(de.pixart.messenger.entities.MucOptions)

Example 73 with IqPacket

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

the class XmppConnectionService method fetchRosterFromServer.

public void fetchRosterFromServer(final Account account) {
    final IqPacket iqPacket = new IqPacket(IqPacket.TYPE.GET);
    if (!"".equals(account.getRosterVersion())) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching roster version " + account.getRosterVersion());
    } else {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching roster");
    }
    iqPacket.query(Namespace.ROSTER).setAttribute("ver", account.getRosterVersion());
    sendIqPacket(account, iqPacket, mIqParser);
}
Also used : IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 74 with IqPacket

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

the class XmppConnectionService method destroyConference.

public void destroyConference(final Conversation conference, final OnDestroyMuc callback) {
    IqPacket request = this.mIqGenerator.destroyConference(conference);
    sendIqPacket(conference.getAccount(), request, (account, packet) -> {
        if (packet.getType() == IqPacket.TYPE.RESULT) {
            callback.OnDestroyMucSuccessful(R.string.destroy_muc_succeed);
        } else {
            callback.OnDestroyMucFailed(R.string.destroy_muc_failed);
        }
    });
}
Also used : IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 75 with IqPacket

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

the class XmppConnectionService method pushConferenceConfiguration.

public void pushConferenceConfiguration(final Conversation conversation, final Bundle options, final OnConfigurationPushed callback) {
    IqPacket request = new IqPacket(IqPacket.TYPE.GET);
    request.setTo(conversation.getJid().toBareJid());
    request.query("http://jabber.org/protocol/muc#owner");
    sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                Data data = Data.parse(packet.query().findChild("x", Namespace.DATA));
                data.submit(options);
                IqPacket set = new IqPacket(IqPacket.TYPE.SET);
                set.setTo(conversation.getJid().toBareJid());
                set.query("http://jabber.org/protocol/muc#owner").addChild(data);
                sendIqPacket(account, set, new OnIqPacketReceived() {

                    @Override
                    public void onIqPacketReceived(Account account, IqPacket packet) {
                        if (callback != null) {
                            if (packet.getType() == IqPacket.TYPE.RESULT) {
                                callback.onPushSucceeded();
                            } else {
                                callback.onPushFailed();
                            }
                        }
                    }
                });
            } else {
                if (callback != null) {
                    callback.onPushFailed();
                }
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Data(de.pixart.messenger.xmpp.forms.Data) 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