Search in sources :

Example 61 with IqPacket

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

the class AxolotlService method publishDeviceBundle.

private void publishDeviceBundle(SignedPreKeyRecord signedPreKeyRecord, Set<PreKeyRecord> preKeyRecords, final boolean announceAfter, final boolean wipe) {
    IqPacket publish = mXmppConnectionService.getIqGenerator().publishBundles(signedPreKeyRecord, axolotlStore.getIdentityKeyPair().getPublicKey(), preKeyRecords, getOwnDeviceId());
    Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + ": Bundle " + getOwnDeviceId() + " in PEP not current. Publishing...");
    mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Successfully published bundle. ");
                if (wipe) {
                    wipeOtherPepDevices();
                } else if (announceAfter) {
                    Log.d(Config.LOGTAG, getLogprefix(account) + "Announcing device " + getOwnDeviceId());
                    publishOwnDeviceIdIfNeeded();
                }
            } else if (packet.getType() == IqPacket.TYPE.ERROR) {
                pepBroken = true;
                Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while publishing bundle: " + packet.findChild("error"));
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 62 with IqPacket

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

the class AxolotlService method publishOwnDeviceId.

public void publishOwnDeviceId(Set<Integer> deviceIds) {
    Set<Integer> deviceIdsCopy = new HashSet<>(deviceIds);
    Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "publishing own device ids");
    if (deviceIdsCopy.isEmpty()) {
        if (numPublishTriesOnEmptyPep >= publishTriesThreshold) {
            Log.w(Config.LOGTAG, getLogprefix(account) + "Own device publish attempt threshold exceeded, aborting...");
            pepBroken = true;
            return;
        } else {
            numPublishTriesOnEmptyPep++;
            Log.w(Config.LOGTAG, getLogprefix(account) + "Own device list empty, attempting to publish (try " + numPublishTriesOnEmptyPep + ")");
        }
    } else {
        numPublishTriesOnEmptyPep = 0;
    }
    deviceIdsCopy.add(getOwnDeviceId());
    IqPacket publish = mXmppConnectionService.getIqGenerator().publishDeviceIds(deviceIdsCopy);
    ownPushPending.set(true);
    mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            ownPushPending.set(false);
            if (packet.getType() == IqPacket.TYPE.ERROR) {
                pepBroken = true;
                Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while publishing own device id" + packet.findChild("error"));
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) HashSet(java.util.HashSet) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 63 with IqPacket

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

the class IqGenerator method generateSetBlockRequest.

public IqPacket generateSetBlockRequest(final Jid jid, boolean reportSpam) {
    final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
    final Element block = iq.addChild("block", Namespace.BLOCKING);
    final Element item = block.addChild("item").setAttribute("jid", jid.toBareJid().toString());
    if (reportSpam) {
        item.addChild("report", "urn:xmpp:reporting:0").addChild("spam");
    }
    Log.d(Config.LOGTAG, iq.toString());
    return iq;
}
Also used : Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 64 with IqPacket

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

the class IqGenerator method discoResponse.

public IqPacket discoResponse(final IqPacket request) {
    final IqPacket packet = new IqPacket(IqPacket.TYPE.RESULT);
    packet.setId(request.getId());
    packet.setTo(request.getFrom());
    final Element query = packet.addChild("query", "http://jabber.org/protocol/disco#info");
    query.setAttribute("node", request.query().getAttribute("node"));
    final Element identity = query.addChild("identity");
    identity.setAttribute("category", "client");
    identity.setAttribute("type", getIdentityType());
    identity.setAttribute("name", getIdentityName());
    for (final String feature : getFeatures()) {
        query.addChild("feature").setAttribute("var", feature);
    }
    return packet;
}
Also used : Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 65 with IqPacket

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

the class IqGenerator method retrievePepAvatar.

public IqPacket retrievePepAvatar(final Avatar avatar) {
    final Element item = new Element("item");
    item.setAttribute("id", avatar.sha1sum);
    final IqPacket packet = retrieve("urn:xmpp:avatar:data", item);
    packet.setTo(avatar.owner);
    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)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