Search in sources :

Example 6 with IqPacket

use of eu.siacs.conversations.xmpp.stanzas.IqPacket in project Conversations by siacs.

the class XmppConnectionService method pushContactToServer.

public void pushContactToServer(final Contact contact) {
    contact.resetOption(Contact.Options.DIRTY_DELETE);
    contact.setOption(Contact.Options.DIRTY_PUSH);
    final Account account = contact.getAccount();
    if (account.getStatus() == Account.State.ONLINE) {
        final boolean ask = contact.getOption(Contact.Options.ASKING);
        final boolean sendUpdates = contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST) && contact.getOption(Contact.Options.PREEMPTIVE_GRANT);
        final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
        iq.query(Namespace.ROSTER).addChild(contact.asElement());
        account.getXmppConnection().sendIqPacket(iq, mDefaultIqHandler);
        if (sendUpdates) {
            sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact));
        }
        if (ask) {
            sendPresencePacket(account, mPresenceGenerator.requestPresenceUpdatesFrom(contact));
        }
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 7 with IqPacket

use of eu.siacs.conversations.xmpp.stanzas.IqPacket in project Conversations by siacs.

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(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 8 with IqPacket

use of eu.siacs.conversations.xmpp.stanzas.IqPacket in project Conversations by siacs.

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

Example 9 with IqPacket

use of eu.siacs.conversations.xmpp.stanzas.IqPacket in project Conversations by siacs.

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

Example 10 with IqPacket

use of eu.siacs.conversations.xmpp.stanzas.IqPacket 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)

Aggregations

IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)78 Element (eu.siacs.conversations.xml.Element)43 Account (eu.siacs.conversations.entities.Account)41 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)33 Jid (eu.siacs.conversations.xmpp.jid.Jid)14 Data (eu.siacs.conversations.xmpp.forms.Data)6 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)6 ArrayList (java.util.ArrayList)6 JinglePacket (eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket)4 HashSet (java.util.HashSet)4 InvalidKeyException (org.whispersystems.libaxolotl.InvalidKeyException)4 PreKeyBundle (org.whispersystems.libaxolotl.state.PreKeyBundle)4 Pair (android.util.Pair)3 Conversation (eu.siacs.conversations.entities.Conversation)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 InvalidKeyIdException (org.whispersystems.libaxolotl.InvalidKeyIdException)3 Bundle (android.os.Bundle)2 Bookmark (eu.siacs.conversations.entities.Bookmark)2 Contact (eu.siacs.conversations.entities.Contact)2