aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2019-10-02 19:09:29 +0200
committerfiaxh <git@lightrise.org>2019-10-02 19:09:29 +0200
commit7adb0e82fba1afc62689797be6c9491ad15d03bf (patch)
treea9d87ab66379f5f012f291f016bee09060510aa5 /xmpp-vala/src/module
parentdf3716622a37cded9e3754da77497ca6d2f2baeb (diff)
downloaddino-7adb0e82fba1afc62689797be6c9491ad15d03bf.tar.gz
dino-7adb0e82fba1afc62689797be6c9491ad15d03bf.zip
Fix pubsub item listener notifying
Diffstat (limited to 'xmpp-vala/src/module')
-rw-r--r--xmpp-vala/src/module/xep/0060_pubsub.vala36
-rw-r--r--xmpp-vala/src/module/xep/0084_user_avatars.vala4
-rw-r--r--xmpp-vala/src/module/xep/0402_bookmarks2.vala40
3 files changed, 48 insertions, 32 deletions
diff --git a/xmpp-vala/src/module/xep/0060_pubsub.vala b/xmpp-vala/src/module/xep/0060_pubsub.vala
index 434e9a7e..9493c5f9 100644
--- a/xmpp-vala/src/module/xep/0060_pubsub.vala
+++ b/xmpp-vala/src/module/xep/0060_pubsub.vala
@@ -14,11 +14,19 @@ namespace Xmpp.Xep.Pubsub {
public class Module : XmppStreamModule {
public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "0060_pubsub_module");
- private HashMap<string, EventListenerDelegate> event_listeners = new HashMap<string, EventListenerDelegate>();
+ private HashMap<string, ItemListenerDelegate> item_listeners = new HashMap<string, ItemListenerDelegate>();
+ private HashMap<string, RetractListenerDelegate> retract_listeners = new HashMap<string, RetractListenerDelegate>();
- public void add_filtered_notification(XmppStream stream, string node, owned EventListenerDelegate.ResultFunc listener) {
+ public void add_filtered_notification(XmppStream stream, string node,
+ owned ItemListenerDelegate.ResultFunc? item_listener,
+ owned RetractListenerDelegate.ResultFunc? retract_listener) {
stream.get_module(ServiceDiscovery.Module.IDENTITY).add_feature_notify(stream, node);
- event_listeners[node] = new EventListenerDelegate((owned)listener);
+ if (item_listener != null) {
+ item_listeners[node] = new ItemListenerDelegate((owned)item_listener);
+ }
+ if (retract_listener != null) {
+ retract_listeners[node] = new RetractListenerDelegate((owned)retract_listener);
+ }
}
public async Gee.List<StanzaNode>? request_all(XmppStream stream, Jid jid, string node) { // TODO multiple nodes gehen auch
@@ -140,8 +148,8 @@ namespace Xmpp.Xep.Pubsub {
if (item_node != null) {
string id = item_node.get_attribute("id", NS_URI_EVENT);
- if (event_listeners.has_key(node)) {
- event_listeners[node].on_result(stream, message.from, id, item_node);
+ if (item_listeners.has_key(node)) {
+ item_listeners[node].on_result(stream, message.from, id, item_node.sub_nodes[0]);
}
}
@@ -149,20 +157,30 @@ namespace Xmpp.Xep.Pubsub {
if (retract_node != null) {
string id = retract_node.get_attribute("id", NS_URI_EVENT);
- if (event_listeners.has_key(node)) {
- event_listeners[node].on_result(stream, message.from, id, retract_node);
+ if (retract_listeners.has_key(node)) {
+ retract_listeners[node].on_result(stream, message.from, id);
}
}
}
}
- public class EventListenerDelegate {
+ public class ItemListenerDelegate {
public delegate void ResultFunc(XmppStream stream, Jid jid, string id, StanzaNode? node);
public ResultFunc on_result { get; private owned set; }
- public EventListenerDelegate(owned ResultFunc on_result) {
+ public ItemListenerDelegate(owned ResultFunc on_result) {
this.on_result = (owned) on_result;
}
}
+
+ public class RetractListenerDelegate {
+ public delegate void ResultFunc(XmppStream stream, Jid jid, string id);
+ public ResultFunc on_result { get; private owned set; }
+
+ public RetractListenerDelegate(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 229b2e12..9722eed5 100644
--- a/xmpp-vala/src/module/xep/0084_user_avatars.vala
+++ b/xmpp-vala/src/module/xep/0084_user_avatars.vala
@@ -32,7 +32,7 @@ namespace Xmpp.Xep.UserAvatars {
}
public override void attach(XmppStream stream) {
- stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NS_URI_METADATA, on_pupsub_event);
+ stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NS_URI_METADATA, on_pupsub_event, null);
}
public override void detach(XmppStream stream) { }
@@ -59,7 +59,7 @@ namespace Xmpp.Xep.UserAvatars {
Bytes image = new Bytes.take(Base64.decode(node.get_string_content()));
string sha1 = Checksum.compute_for_bytes(ChecksumType.SHA1, image);
if (sha1 != id) {
- warning("sha sum did not match for avatar from "+jid.to_string()+" expected="+id+", actual="+sha1);
+ warning("sha sum did not match for avatar from %s expected=%s actual=%s", jid.to_string(), id, sha1);
return;
}
storage.store(id, image);
diff --git a/xmpp-vala/src/module/xep/0402_bookmarks2.vala b/xmpp-vala/src/module/xep/0402_bookmarks2.vala
index cbe6ea45..8394580f 100644
--- a/xmpp-vala/src/module/xep/0402_bookmarks2.vala
+++ b/xmpp-vala/src/module/xep/0402_bookmarks2.vala
@@ -18,7 +18,7 @@ public class Module : BookmarksProvider, XmppStreamModule {
hm = new HashMap<Jid, Conference>(Jid.hash_func, Jid.equals_func);
foreach (StanzaNode item_node in items) {
- Conference? conference = parse_item_node(item_node, item_node.get_attribute("id"));
+ Conference? conference = parse_item_node(item_node.sub_nodes[0], item_node.get_attribute("id"));
if (conference == null) continue;
hm[conference.jid] = conference;
}
@@ -56,33 +56,31 @@ public class Module : BookmarksProvider, XmppStreamModule {
conference.jid.to_string());
}
- private void on_pupsub_event(XmppStream stream, Jid jid, string id, StanzaNode? node) {
- if (node.name == "item") {
- Conference conference = parse_item_node(node, id);
- Flag? flag = stream.get_flag(Flag.IDENTITY);
- if (flag != null) {
- flag.conferences[conference.jid] = conference;
- }
- conference_added(stream, conference);
- } else if (node.name == "retract") {
- string jid_str = node.get_attribute("id");
- Jid jid_parsed = Jid.parse(jid_str);
- Flag? flag = stream.get_flag(Flag.IDENTITY);
- if (flag != null) {
- flag.conferences.unset(jid_parsed);
- }
- conference_removed(stream, jid_parsed);
+ private void on_pupsub_item(XmppStream stream, Jid jid, string id, StanzaNode? node) {
+ Conference conference = parse_item_node(node, id);
+ Flag? flag = stream.get_flag(Flag.IDENTITY);
+ if (flag != null) {
+ flag.conferences[conference.jid] = conference;
+ }
+ conference_added(stream, conference);
+ }
+
+ private void on_pupsub_retract(XmppStream stream, Jid jid, string id) {
+ Jid jid_parsed = Jid.parse(id);
+ Flag? flag = stream.get_flag(Flag.IDENTITY);
+ if (flag != null) {
+ flag.conferences.unset(jid_parsed);
}
+ conference_removed(stream, jid_parsed);
}
- private Conference? parse_item_node(StanzaNode item_node, string id) {
+ private Conference? parse_item_node(StanzaNode conference_node, string id) {
Conference conference = new Conference();
Jid? jid_parsed = Jid.parse(id);
if (jid_parsed == null || jid_parsed.resourcepart != null) return null;
conference.jid = jid_parsed;
- StanzaNode? conference_node = item_node.get_subnode("conference", NS_URI);
- if (conference_node == null) return null;
+ if (conference_node.name != "conference" || conference_node.ns_uri != NS_URI) return null;
conference.name = conference_node.get_attribute("name", NS_URI);
conference.autojoin = conference_node.get_attribute("autojoin", NS_URI) == "true";
@@ -91,7 +89,7 @@ public class Module : BookmarksProvider, XmppStreamModule {
}
public override void attach(XmppStream stream) {
- stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NS_URI, on_pupsub_event);
+ stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NS_URI, on_pupsub_item, on_pupsub_retract);
}
public override void detach(XmppStream stream) { }