Search in sources :

Example 1 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 2 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 3 with IqPacket

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

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

the class HttpUploadConnection method init.

public void init(Message message, boolean delay) {
    this.message = message;
    this.account = message.getConversation().getAccount();
    this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
    this.mime = this.file.getMimeType();
    this.delayed = delay;
    if (Config.ENCRYPT_ON_HTTP_UPLOADED || message.getEncryption() == Message.ENCRYPTION_AXOLOTL || message.getEncryption() == Message.ENCRYPTION_OTR) {
        this.key = new byte[48];
        mXmppConnectionService.getRNG().nextBytes(this.key);
        this.file.setKeyAndIv(this.key);
    }
    Pair<InputStream, Integer> pair;
    try {
        pair = AbstractConnectionManager.createInputStream(file, true);
    } catch (FileNotFoundException e) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not find file to upload - " + e.getMessage());
        fail(e.getMessage());
        return;
    }
    this.file.setExpectedSize(pair.second);
    this.mFileInputStream = pair.first;
    Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD);
    IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host, file, mime);
    mXmppConnectionService.sendIqPacket(account, request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                Element slot = packet.findChild("slot", Namespace.HTTP_UPLOAD);
                if (slot != null) {
                    try {
                        mGetUrl = new URL(slot.findChildContent("get"));
                        mPutUrl = new URL(slot.findChildContent("put"));
                        if (!canceled) {
                            new Thread(new FileUploader()).start();
                        }
                        return;
                    } catch (MalformedURLException e) {
                    //fall through
                    }
                }
            }
            Log.d(Config.LOGTAG, account.getJid().toString() + ": invalid response to slot request " + packet);
            fail(IqParser.extractErrorMessage(packet));
        }
    });
    message.setTransferable(this);
    mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
}
Also used : Account(eu.siacs.conversations.entities.Account) MalformedURLException(java.net.MalformedURLException) Jid(eu.siacs.conversations.xmpp.jid.Jid) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) InputStream(java.io.InputStream) Element(eu.siacs.conversations.xml.Element) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 5 with IqPacket

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

the class IqGenerator method publish.

protected IqPacket publish(final String node, final Element item) {
    final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
    final Element pubsub = packet.addChild("pubsub", "http://jabber.org/protocol/pubsub");
    final Element publish = pubsub.addChild("publish");
    publish.setAttribute("node", node);
    publish.addChild(item);
    return packet;
}
Also used : Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Aggregations

IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)119 Element (eu.siacs.conversations.xml.Element)71 Account (eu.siacs.conversations.entities.Account)35 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)30 Jid (eu.siacs.conversations.xmpp.Jid)15 Data (eu.siacs.conversations.xmpp.forms.Data)10 ArrayList (java.util.ArrayList)8 Contact (eu.siacs.conversations.entities.Contact)6 HashSet (java.util.HashSet)6 JabberIdContact (eu.siacs.conversations.android.JabberIdContact)5 PreKeyBundle (org.whispersystems.libsignal.state.PreKeyBundle)5 Bundle (android.os.Bundle)4 Bookmark (eu.siacs.conversations.entities.Bookmark)4 Conversation (eu.siacs.conversations.entities.Conversation)4 MucOptions (eu.siacs.conversations.entities.MucOptions)4 ServiceDiscoveryResult (eu.siacs.conversations.entities.ServiceDiscoveryResult)4 XmppConnection (eu.siacs.conversations.xmpp.XmppConnection)4 Pair (android.util.Pair)3 ImmutableList (com.google.common.collect.ImmutableList)3 JinglePacket (eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket)3