From 7adb0e82fba1afc62689797be6c9491ad15d03bf Mon Sep 17 00:00:00 2001 From: fiaxh Date: Wed, 2 Oct 2019 19:09:29 +0200 Subject: Fix pubsub item listener notifying --- plugins/omemo/src/protocol/stream_module.vala | 2 +- xmpp-vala/src/module/xep/0060_pubsub.vala | 36 ++++++++++++++++------ xmpp-vala/src/module/xep/0084_user_avatars.vala | 4 +-- xmpp-vala/src/module/xep/0402_bookmarks2.vala | 40 ++++++++++++------------- 4 files changed, 49 insertions(+), 33 deletions(-) diff --git a/plugins/omemo/src/protocol/stream_module.vala b/plugins/omemo/src/protocol/stream_module.vala index 95ba4c85..a456440a 100644 --- a/plugins/omemo/src/protocol/stream_module.vala +++ b/plugins/omemo/src/protocol/stream_module.vala @@ -29,7 +29,7 @@ public class StreamModule : XmppStreamModule { this.store = Plugin.get_context().create_store(); store_created(store); - stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NODE_DEVICELIST, (stream, jid, id, node) => parse_device_list(stream, jid, id, node)); + stream.get_module(Pubsub.Module.IDENTITY).add_filtered_notification(stream, NODE_DEVICELIST, (stream, jid, id, node) => parse_device_list(stream, jid, id, node), null); } 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 IDENTITY = new ModuleIdentity(NS_URI, "0060_pubsub_module"); - private HashMap event_listeners = new HashMap(); + private HashMap item_listeners = new HashMap(); + private HashMap retract_listeners = new HashMap(); - 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? 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.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) { } -- cgit v1.2.3-70-g09d2