diff options
Diffstat (limited to '')
-rw-r--r-- | src/main/java/eu/siacs/conversations/generator/IqGenerator.java | 81 |
1 files changed, 50 insertions, 31 deletions
diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java index 4819f96eb..4b28e484a 100644 --- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java @@ -1,14 +1,12 @@ package eu.siacs.conversations.generator; -import android.util.Log; - import java.util.Arrays; import java.util.Collections; import java.util.List; -import eu.siacs.conversations.Config; import eu.siacs.conversations.services.MessageArchiveService; import eu.siacs.conversations.services.XmppConnectionService; +import eu.siacs.conversations.utils.Xmlns; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.forms.Data; import eu.siacs.conversations.xmpp.jid.Jid; @@ -17,44 +15,44 @@ import eu.siacs.conversations.xmpp.stanzas.IqPacket; public class IqGenerator extends AbstractGenerator { - public IqGenerator(XmppConnectionService service) { + public IqGenerator(final XmppConnectionService service) { super(service); } - public IqPacket discoResponse(IqPacket request) { - IqPacket packet = new IqPacket(IqPacket.TYPE_RESULT); + public IqPacket discoResponse(final IqPacket request) { + final IqPacket packet = new IqPacket(IqPacket.TYPE_RESULT); packet.setId(request.getId()); - packet.setTo(request.getFrom()); - Element query = packet.addChild("query", + packet.setTo(request.getFrom()); + final Element query = packet.addChild("query", "http://jabber.org/protocol/disco#info"); query.setAttribute("node", request.query().getAttribute("node")); - Element identity = query.addChild("identity"); + final Element identity = query.addChild("identity"); identity.setAttribute("category", "client"); identity.setAttribute("type", this.IDENTITY_TYPE); identity.setAttribute("name", IDENTITY_NAME); - List<String> features = Arrays.asList(FEATURES); + final List<String> features = Arrays.asList(FEATURES); Collections.sort(features); - for (String feature : features) { + for (final String feature : features) { query.addChild("feature").setAttribute("var", feature); } return packet; } - protected IqPacket publish(String node, Element item) { - IqPacket packet = new IqPacket(IqPacket.TYPE_SET); - Element pubsub = packet.addChild("pubsub", + 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"); - Element publish = pubsub.addChild("publish"); + final Element publish = pubsub.addChild("publish"); publish.setAttribute("node", node); publish.addChild(item); return packet; } protected IqPacket retrieve(String node, Element item) { - IqPacket packet = new IqPacket(IqPacket.TYPE_GET); - Element pubsub = packet.addChild("pubsub", + final IqPacket packet = new IqPacket(IqPacket.TYPE_GET); + final Element pubsub = packet.addChild("pubsub", "http://jabber.org/protocol/pubsub"); - Element items = pubsub.addChild("items"); + final Element items = pubsub.addChild("items"); items.setAttribute("node", node); if (item != null) { items.addChild(item); @@ -63,19 +61,19 @@ public class IqGenerator extends AbstractGenerator { } public IqPacket publishAvatar(Avatar avatar) { - Element item = new Element("item"); + final Element item = new Element("item"); item.setAttribute("id", avatar.sha1sum); - Element data = item.addChild("data", "urn:xmpp:avatar:data"); + final Element data = item.addChild("data", "urn:xmpp:avatar:data"); data.setContent(avatar.image); return publish("urn:xmpp:avatar:data", item); } - public IqPacket publishAvatarMetadata(Avatar avatar) { - Element item = new Element("item"); + public IqPacket publishAvatarMetadata(final Avatar avatar) { + final Element item = new Element("item"); item.setAttribute("id", avatar.sha1sum); - Element metadata = item - .addChild("metadata", "urn:xmpp:avatar:metadata"); - Element info = metadata.addChild("info"); + final Element metadata = item + .addChild("metadata", "urn:xmpp:avatar:metadata"); + final Element info = metadata.addChild("info"); info.setAttribute("bytes", avatar.size); info.setAttribute("id", avatar.sha1sum); info.setAttribute("height", avatar.height); @@ -84,10 +82,10 @@ public class IqGenerator extends AbstractGenerator { return publish("urn:xmpp:avatar:metadata", item); } - public IqPacket retrieveAvatar(Avatar avatar) { - Element item = new Element("item"); + public IqPacket retrieveAvatar(final Avatar avatar) { + final Element item = new Element("item"); item.setAttribute("id", avatar.sha1sum); - IqPacket packet = retrieve("urn:xmpp:avatar:data", item); + final IqPacket packet = retrieve("urn:xmpp:avatar:data", item); packet.setTo(avatar.owner); return packet; } @@ -100,11 +98,11 @@ public class IqGenerator extends AbstractGenerator { return packet; } - public IqPacket queryMessageArchiveManagement(MessageArchiveService.Query mam) { + public IqPacket queryMessageArchiveManagement(final MessageArchiveService.Query mam) { final IqPacket packet = new IqPacket(IqPacket.TYPE_SET); - Element query = packet.query("urn:xmpp:mam:0"); + final Element query = packet.query("urn:xmpp:mam:0"); query.setAttribute("queryid",mam.getQueryId()); - Data data = new Data(); + final Data data = new Data(); data.setFormType("urn:xmpp:mam:0"); if (mam.getWith()!=null) { data.put("with", mam.getWith().toString()); @@ -119,4 +117,25 @@ public class IqGenerator extends AbstractGenerator { } return packet; } + + public IqPacket generateGetBlockList() { + final IqPacket iq = new IqPacket(IqPacket.TYPE_GET); + iq.addChild("blocklist", Xmlns.BLOCKING); + + return iq; + } + + public IqPacket generateSetBlockRequest(final Jid jid) { + final IqPacket iq = new IqPacket(IqPacket.TYPE_SET); + final Element block = iq.addChild("block", Xmlns.BLOCKING); + block.addChild("item").setAttribute("jid", jid.toBareJid().toString()); + return iq; + } + + public IqPacket generateSetUnblockRequest(final Jid jid) { + final IqPacket iq = new IqPacket(IqPacket.TYPE_SET); + final Element block = iq.addChild("unblock", Xmlns.BLOCKING); + block.addChild("item").setAttribute("jid", jid.toBareJid().toString()); + return iq; + } } |