aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep/0264_jingle_content_thumbnails.vala
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp-vala/src/module/xep/0264_jingle_content_thumbnails.vala')
-rw-r--r--xmpp-vala/src/module/xep/0264_jingle_content_thumbnails.vala41
1 files changed, 20 insertions, 21 deletions
diff --git a/xmpp-vala/src/module/xep/0264_jingle_content_thumbnails.vala b/xmpp-vala/src/module/xep/0264_jingle_content_thumbnails.vala
index cb281f80..053fb7d5 100644
--- a/xmpp-vala/src/module/xep/0264_jingle_content_thumbnails.vala
+++ b/xmpp-vala/src/module/xep/0264_jingle_content_thumbnails.vala
@@ -1,6 +1,16 @@
namespace Xmpp.Xep.JingleContentThumbnails {
public const string NS_URI = "urn:xmpp:thumbs:1";
- public const string STANZA_NAME = "thumbnail";
+
+ public Gee.List<Thumbnail> get_thumbnails(StanzaNode node) {
+ var thumbnails = new Gee.ArrayList<Thumbnail>();
+ foreach (StanzaNode thumbnail_node in node.get_subnodes("thumbnail", Xep.JingleContentThumbnails.NS_URI)) {
+ var thumbnail = Thumbnail.from_stanza_node(thumbnail_node);
+ if (thumbnail != null) {
+ thumbnails.add(thumbnail);
+ }
+ }
+ return thumbnails;
+ }
public class Thumbnail {
public string uri;
@@ -8,41 +18,30 @@ namespace Xmpp.Xep.JingleContentThumbnails {
public int width;
public int height;
- const string URI_ATTRIBUTE = "uri";
- const string MIME_ATTRIBUTE = "media-type";
- const string WIDTH_ATTRIBUTE = "width";
- const string HEIGHT_ATTRIBUTE = "height";
-
public StanzaNode to_stanza_node() {
- StanzaNode node = new StanzaNode.build(STANZA_NAME, NS_URI).add_self_xmlns()
- .put_attribute(URI_ATTRIBUTE, this.uri);
+ StanzaNode node = new StanzaNode.build("thumbnail", NS_URI).add_self_xmlns()
+ .put_attribute("uri", this.uri);
if (this.media_type != null) {
- node.put_attribute(MIME_ATTRIBUTE, this.media_type);
+ node.put_attribute("media-type", this.media_type);
}
if (this.width != -1) {
- node.put_attribute(WIDTH_ATTRIBUTE, this.width.to_string());
+ node.put_attribute("width", this.width.to_string());
}
if (this.height != -1) {
- node.put_attribute(HEIGHT_ATTRIBUTE, this.height.to_string());
+ node.put_attribute("height", this.height.to_string());
}
return node;
}
public static Thumbnail? from_stanza_node(StanzaNode node) {
Thumbnail thumbnail = new Thumbnail();
- thumbnail.uri = node.get_attribute(URI_ATTRIBUTE);
+ thumbnail.uri = node.get_attribute("uri");
if (thumbnail.uri == null) {
return null;
}
- thumbnail.media_type = node.get_attribute(MIME_ATTRIBUTE);
- string? width = node.get_attribute(WIDTH_ATTRIBUTE);
- if (width != null) {
- thumbnail.width = int.parse(width);
- }
- string? height = node.get_attribute(HEIGHT_ATTRIBUTE);
- if (height != null) {
- thumbnail.height = int.parse(height);
- }
+ thumbnail.media_type = node.get_attribute("media-type");
+ thumbnail.width = node.get_attribute_int("width");
+ thumbnail.height = node.get_attribute_int("height");
return thumbnail;
}
}