aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/generator/IqGenerator.java
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-08-05 01:36:17 +0200
committeriNPUTmice <daniel@gultsch.de>2014-08-05 01:36:17 +0200
commitf8b4d5f338aede361c2562379d816b45f7bed3b8 (patch)
tree82ea92f7e35b94400e618387d8d522daeb62dc70 /src/eu/siacs/conversations/generator/IqGenerator.java
parent629ff3afcdba5e6721a1b63cd0d497d97e3bdbed (diff)
publish avatars
Diffstat (limited to 'src/eu/siacs/conversations/generator/IqGenerator.java')
-rw-r--r--src/eu/siacs/conversations/generator/IqGenerator.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/eu/siacs/conversations/generator/IqGenerator.java b/src/eu/siacs/conversations/generator/IqGenerator.java
index 7b3350d4..1a38347b 100644
--- a/src/eu/siacs/conversations/generator/IqGenerator.java
+++ b/src/eu/siacs/conversations/generator/IqGenerator.java
@@ -5,6 +5,7 @@ import java.util.Collections;
import java.util.List;
import eu.siacs.conversations.xml.Element;
+import eu.siacs.conversations.xmpp.pep.Avatar;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class IqGenerator extends AbstractGenerator {
@@ -28,4 +29,34 @@ public class IqGenerator extends AbstractGenerator {
}
return packet;
}
+
+ protected IqPacket publish(String node, Element item) {
+ IqPacket packet = new IqPacket(IqPacket.TYPE_SET);
+ Element pubsub = packet.addChild("pubsub", "http://jabber.org/protocol/pubsub");
+ Element publish = pubsub.addChild("publish");
+ publish.setAttribute("node", node);
+ publish.addChild(item);
+ return packet;
+ }
+
+ public IqPacket publishAvatar(Avatar avatar) {
+ Element item = new Element("item");
+ item.setAttribute("id", avatar.sha1sum);
+ 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");
+ item.setAttribute("id", avatar.sha1sum);
+ Element metadata = item.addChild("metadata","urn:xmpp:avatar:metadata");
+ Element info = metadata.addChild("info");
+ info.setAttribute("bytes",avatar.size);
+ info.setAttribute("id",avatar.sha1sum);
+ info.setAttribute("height",avatar.height);
+ info.setAttribute("width",avatar.height);
+ info.setAttribute("type", avatar.type);
+ return publish("urn:xmpp:avatar:metadata",item);
+ }
}