aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/generator
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/generator')
-rw-r--r--src/main/java/eu/siacs/conversations/generator/IqGenerator.java81
-rw-r--r--src/main/java/eu/siacs/conversations/generator/MessageGenerator.java10
2 files changed, 55 insertions, 36 deletions
diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
index 4819f96e..4b28e484 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;
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
index ca5417e0..8e99888b 100644
--- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
+++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
@@ -114,7 +114,7 @@ public class MessageGenerator extends AbstractGenerator {
private MessagePacket generateError(MessagePacket origin) {
MessagePacket packet = new MessagePacket();
packet.setId(origin.getId());
- packet.setTo(origin.getFrom());
+ packet.setTo(origin.getFrom());
packet.setBody(origin.getBody());
packet.setType(MessagePacket.TYPE_ERROR);
return packet;
@@ -135,7 +135,7 @@ public class MessageGenerator extends AbstractGenerator {
String subject) {
MessagePacket packet = new MessagePacket();
packet.setType(MessagePacket.TYPE_GROUPCHAT);
- packet.setTo(conversation.getContactJid().toBareJid());
+ packet.setTo(conversation.getJid().toBareJid());
Element subjectChild = new Element("subject");
subjectChild.setContent(subject);
packet.addChild(subjectChild);
@@ -149,13 +149,13 @@ public class MessageGenerator extends AbstractGenerator {
packet.setTo(contact);
packet.setFrom(conversation.getAccount().getJid());
Element x = packet.addChild("x", "jabber:x:conference");
- x.setAttribute("jid", conversation.getContactJid().toBareJid().toString());
+ x.setAttribute("jid", conversation.getJid().toBareJid().toString());
return packet;
}
public MessagePacket invite(Conversation conversation, Jid contact) {
MessagePacket packet = new MessagePacket();
- packet.setTo(conversation.getContactJid().toBareJid());
+ packet.setTo(conversation.getJid().toBareJid());
packet.setFrom(conversation.getAccount().getJid());
Element x = new Element("x");
x.setAttribute("xmlns", "http://jabber.org/protocol/muc#user");
@@ -170,7 +170,7 @@ public class MessageGenerator extends AbstractGenerator {
MessagePacket originalMessage, String namespace) {
MessagePacket receivedPacket = new MessagePacket();
receivedPacket.setType(MessagePacket.TYPE_NORMAL);
- receivedPacket.setTo(originalMessage.getFrom());
+ receivedPacket.setTo(originalMessage.getFrom());
receivedPacket.setFrom(account.getJid());
Element received = receivedPacket.addChild("received", namespace);
received.setAttribute("id", originalMessage.getId());