aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp-vala/src/module')
-rw-r--r--xmpp-vala/src/module/xep/0060_pubsub.vala59
-rw-r--r--xmpp-vala/src/module/xep/0084_user_avatars.vala15
-rw-r--r--xmpp-vala/src/module/xep/0394_message_markup.vala81
-rw-r--r--xmpp-vala/src/module/xep/0402_bookmarks2.vala2
4 files changed, 134 insertions, 23 deletions
diff --git a/xmpp-vala/src/module/xep/0060_pubsub.vala b/xmpp-vala/src/module/xep/0060_pubsub.vala
index 77f9aee6..c6395eb9 100644
--- a/xmpp-vala/src/module/xep/0060_pubsub.vala
+++ b/xmpp-vala/src/module/xep/0060_pubsub.vala
@@ -17,11 +17,12 @@ namespace Xmpp.Xep.Pubsub {
private HashMap<string, ItemListenerDelegate> item_listeners = new HashMap<string, ItemListenerDelegate>();
private HashMap<string, RetractListenerDelegate> retract_listeners = new HashMap<string, RetractListenerDelegate>();
- private ArrayList<string> pep_subset_listeners = new ArrayList<string>();
+ private HashMap<string, DeleteListenerDelegate> delete_listeners = new HashMap<string, DeleteListenerDelegate>();
- public void add_filtered_notification(XmppStream stream, string node, bool pep_subset,
+ public void add_filtered_notification(XmppStream stream, string node,
owned ItemListenerDelegate.ResultFunc? item_listener,
- owned RetractListenerDelegate.ResultFunc? retract_listener) {
+ owned RetractListenerDelegate.ResultFunc? retract_listener,
+ owned DeleteListenerDelegate.ResultFunc? delete_listener) {
stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature_notify(stream, node);
if (item_listener != null) {
item_listeners[node] = new ItemListenerDelegate((owned)item_listener);
@@ -29,8 +30,8 @@ namespace Xmpp.Xep.Pubsub {
if (retract_listener != null) {
retract_listeners[node] = new RetractListenerDelegate((owned)retract_listener);
}
- if (pep_subset) {
- pep_subset_listeners.add(node);
+ if (delete_listener != null) {
+ delete_listeners[node] = new DeleteListenerDelegate((owned)delete_listener);
}
}
@@ -181,30 +182,41 @@ namespace Xmpp.Xep.Pubsub {
private void on_received_message(XmppStream stream, MessageStanza message) {
StanzaNode event_node = message.stanza.get_subnode("event", NS_URI_EVENT);
if (event_node == null) return;
- StanzaNode items_node = event_node.get_subnode("items", NS_URI_EVENT);
- if (items_node == null) return;
- string node = items_node.get_attribute("node", NS_URI_EVENT);
- if (!message.from.is_bare() && pep_subset_listeners.contains(node)) {
+ if (!message.from.is_bare()) {
warning("Got a PEP message from a full JID (%s), ignoring.", message.from.to_string());
return;
}
- StanzaNode? item_node = items_node.get_subnode("item", NS_URI_EVENT);
- if (item_node != null) {
- string id = item_node.get_attribute("id", NS_URI_EVENT);
+ StanzaNode items_node = event_node.get_subnode("items", NS_URI_EVENT);
+ if (items_node != null) {
+ string node = items_node.get_attribute("node", NS_URI_EVENT);
+
+ StanzaNode? item_node = items_node.get_subnode("item", NS_URI_EVENT);
+ if (item_node != null) {
+ string id = item_node.get_attribute("id", NS_URI_EVENT);
+
+ if (item_listeners.has_key(node)) {
+ item_listeners[node].on_result(stream, message.from, id, item_node.sub_nodes[0]);
+ }
+ }
+
+ StanzaNode? retract_node = items_node.get_subnode("retract", NS_URI_EVENT);
+ if (retract_node != null) {
+ string id = retract_node.get_attribute("id", NS_URI_EVENT);
- if (item_listeners.has_key(node)) {
- item_listeners[node].on_result(stream, message.from, id, item_node.sub_nodes[0]);
+ if (retract_listeners.has_key(node)) {
+ retract_listeners[node].on_result(stream, message.from, id);
+ }
}
}
- StanzaNode? retract_node = items_node.get_subnode("retract", NS_URI_EVENT);
- if (retract_node != null) {
- string id = retract_node.get_attribute("id", NS_URI_EVENT);
+ StanzaNode? delete_node = event_node.get_subnode("delete", NS_URI_EVENT);
+ if (delete_node != null) {
+ string node = delete_node.get_attribute("node", NS_URI_EVENT);
- if (retract_listeners.has_key(node)) {
- retract_listeners[node].on_result(stream, message.from, id);
+ if (delete_listeners.has_key(node)) {
+ delete_listeners[node].on_result(stream, message.from);
}
}
}
@@ -264,4 +276,13 @@ namespace Xmpp.Xep.Pubsub {
}
}
+ public class DeleteListenerDelegate {
+ public delegate void ResultFunc(XmppStream stream, Jid jid);
+ public ResultFunc on_result { get; private owned set; }
+
+ public DeleteListenerDelegate(owned ResultFunc on_result) {
+ this.on_result = (owned) on_result;
+ }
+ }
+
}
diff --git a/xmpp-vala/src/module/xep/0084_user_avatars.vala b/xmpp-vala/src/module/xep/0084_user_avatars.vala
index f3cd4060..4d84b34b 100644
--- a/xmpp-vala/src/module/xep/0084_user_avatars.vala
+++ b/xmpp-vala/src/module/xep/0084_user_avatars.vala
@@ -20,6 +20,11 @@ namespace Xmpp.Xep.UserAvatars {
stream.get_module(Pubsub.Module.IDENTITY).publish.begin(stream, null, NS_URI_METADATA, sha1, metadata_node);
}
+ public void unset_avatar(XmppStream stream) {
+ StanzaNode metadata_node = new StanzaNode.build("metadata", NS_URI_METADATA).add_self_xmlns();
+ stream.get_module(Pubsub.Module.IDENTITY).delete_node(stream, null, NS_URI_METADATA);
+ }
+
public async Bytes? fetch_image(XmppStream stream, Jid jid, string hash) {
Gee.List<StanzaNode>? items = yield stream.get_module(Pubsub.Module.IDENTITY).request_all(stream, jid, NS_URI_DATA);
if (items == null || items.size == 0 || items[0].sub_nodes.size == 0) return null;
@@ -41,23 +46,27 @@ namespace Xmpp.Xep.UserAvatars {
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0084_user_avatars");
public signal void received_avatar_hash(XmppStream stream, Jid jid, string id);
+ public signal void avatar_removed(XmppStream stream, Jid jid);
public override void attach(XmppStream stream) {
- stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NS_URI_METADATA, true, on_pupsub_event, null);
+ stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NS_URI_METADATA, on_pupsub_item, null, on_pubsub_delete);
}
public override void detach(XmppStream stream) {
stream.get_module(Pubsub.Module.IDENTITY).remove_filtered_notification(stream, NS_URI_METADATA);
}
-
- public void on_pupsub_event(XmppStream stream, Jid jid, string hash, StanzaNode? node) {
+ public void on_pupsub_item(XmppStream stream, Jid jid, string hash, StanzaNode? node) {
StanzaNode? info_node = node.get_subnode("info", NS_URI_METADATA);
string? type = info_node == null ? null : info_node.get_attribute("type");
if (type != "image/png" && type != "image/jpeg") return;
received_avatar_hash(stream, jid, hash);
}
+ public void on_pubsub_delete(XmppStream stream, Jid jid) {
+ avatar_removed(stream, jid);
+ }
+
public override string get_ns() { return NS_URI; }
public override string get_id() { return IDENTITY.id; }
}
diff --git a/xmpp-vala/src/module/xep/0394_message_markup.vala b/xmpp-vala/src/module/xep/0394_message_markup.vala
new file mode 100644
index 00000000..32b441af
--- /dev/null
+++ b/xmpp-vala/src/module/xep/0394_message_markup.vala
@@ -0,0 +1,81 @@
+using Gee;
+
+namespace Xmpp.Xep.MessageMarkup {
+
+ public const string NS_URI = "urn:xmpp:markup:0";
+
+ public enum SpanType {
+ EMPHASIS,
+ STRONG_EMPHASIS,
+ DELETED,
+ }
+
+ public class Span : Object {
+ public Gee.List<SpanType> types { get; set; }
+ public int start_char { get; set; }
+ public int end_char { get; set; }
+ }
+
+ public Gee.List<Span> get_spans(MessageStanza stanza) {
+ var ret = new ArrayList<Span>();
+
+ foreach (StanzaNode span_node in stanza.stanza.get_deep_subnodes(NS_URI + ":markup", NS_URI + ":span")) {
+ int start_char = span_node.get_attribute_int("start", -1, NS_URI);
+ int end_char = span_node.get_attribute_int("end", -1, NS_URI);
+ if (start_char == -1 || end_char == -1) continue;
+
+ var types = new ArrayList<SpanType>();
+ foreach (StanzaNode span_subnode in span_node.get_all_subnodes()) {
+ types.add(str_to_span_type(span_subnode.name));
+ }
+ ret.add(new Span() { types=types, start_char=start_char, end_char=end_char });
+ }
+ return ret;
+ }
+
+ public void add_spans(MessageStanza stanza, Gee.List<Span> spans) {
+ if (spans.is_empty) return;
+
+ StanzaNode markup_node = new StanzaNode.build("markup", NS_URI).add_self_xmlns();
+
+ foreach (var span in spans) {
+ StanzaNode span_node = new StanzaNode.build("span", NS_URI)
+ .put_attribute("start", span.start_char.to_string(), NS_URI)
+ .put_attribute("end", span.end_char.to_string(), NS_URI);
+
+ foreach (var type in span.types) {
+ span_node.put_node(new StanzaNode.build(span_type_to_str(type), NS_URI));
+ }
+ markup_node.put_node(span_node);
+ }
+
+ stanza.stanza.put_node(markup_node);
+ }
+
+ public static string span_type_to_str(Xep.MessageMarkup.SpanType span_type) {
+ switch (span_type) {
+ case Xep.MessageMarkup.SpanType.EMPHASIS:
+ return "emphasis";
+ case Xep.MessageMarkup.SpanType.STRONG_EMPHASIS:
+ return "strong";
+ case Xep.MessageMarkup.SpanType.DELETED:
+ return "deleted";
+ default:
+ return "";
+ }
+ }
+
+ public static Xep.MessageMarkup.SpanType str_to_span_type(string span_str) {
+ switch (span_str) {
+ case "emphasis":
+ return Xep.MessageMarkup.SpanType.EMPHASIS;
+ case "strong":
+ return Xep.MessageMarkup.SpanType.STRONG_EMPHASIS;
+ case "deleted":
+ return Xep.MessageMarkup.SpanType.DELETED;
+ default:
+ return Xep.MessageMarkup.SpanType.EMPHASIS;
+ }
+ }
+
+} \ No newline at end of file
diff --git a/xmpp-vala/src/module/xep/0402_bookmarks2.vala b/xmpp-vala/src/module/xep/0402_bookmarks2.vala
index d1e53e6e..429f26f5 100644
--- a/xmpp-vala/src/module/xep/0402_bookmarks2.vala
+++ b/xmpp-vala/src/module/xep/0402_bookmarks2.vala
@@ -120,7 +120,7 @@ public class Module : BookmarksProvider, XmppStreamModule {
}
public override void attach(XmppStream stream) {
- stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NS_URI, true, on_pupsub_item, on_pupsub_retract);
+ stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NS_URI, on_pupsub_item, on_pupsub_retract, null);
}
public override void detach(XmppStream stream) {