Search in sources :

Example 6 with OnIqPacketReceived

use of eu.siacs.conversations.xmpp.OnIqPacketReceived in project Conversations by siacs.

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(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) ServiceDiscoveryResult(eu.siacs.conversations.entities.ServiceDiscoveryResult) Pair(android.util.Pair) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 7 with OnIqPacketReceived

use of eu.siacs.conversations.xmpp.OnIqPacketReceived in project Conversations by siacs.

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(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 8 with OnIqPacketReceived

use of eu.siacs.conversations.xmpp.OnIqPacketReceived in project Conversations by siacs.

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(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 9 with OnIqPacketReceived

use of eu.siacs.conversations.xmpp.OnIqPacketReceived in project Conversations by siacs.

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(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 10 with OnIqPacketReceived

use of eu.siacs.conversations.xmpp.OnIqPacketReceived in project Conversations by siacs.

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(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Aggregations

Account (eu.siacs.conversations.entities.Account)33 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)33 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)33 Element (eu.siacs.conversations.xml.Element)16 Jid (eu.siacs.conversations.xmpp.jid.Jid)9 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)4 InvalidKeyException (org.whispersystems.libaxolotl.InvalidKeyException)4 PreKeyBundle (org.whispersystems.libaxolotl.state.PreKeyBundle)4 Conversation (eu.siacs.conversations.entities.Conversation)3 HashSet (java.util.HashSet)3 InvalidKeyIdException (org.whispersystems.libaxolotl.InvalidKeyIdException)3 UntrustedIdentityException (org.whispersystems.libaxolotl.UntrustedIdentityException)3 Bundle (android.os.Bundle)2 Pair (android.util.Pair)2 Contact (eu.siacs.conversations.entities.Contact)2 Data (eu.siacs.conversations.xmpp.forms.Data)2 Content (eu.siacs.conversations.xmpp.jingle.stanzas.Content)2 JinglePacket (eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket)2 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)2 FileNotFoundException (java.io.FileNotFoundException)2