Diff

util/pubsub.lua @ 10521:cbb2c3f8bb1d

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Mon, 23 Dec 2019 20:57:10 +0100
parent 10356:0a2d7efca039
parent 10519:641e3b7a6a39
child 10537:c5558138ce33
line wrap: on
line diff
--- a/util/pubsub.lua	Sun Dec 22 20:10:20 2019 +0100
+++ b/util/pubsub.lua	Mon Dec 23 20:57:10 2019 +0100
@@ -7,6 +7,7 @@
 local default_config = {
 	itemstore = function (config, _) return cache.new(config["max_items"]) end;
 	broadcaster = function () end;
+	subscriber_filter = function (subs) return subs end;
 	itemcheck = function () return true; end;
 	get_affiliation = function () end;
 	normalize_jid = function (jid) return jid; end;
@@ -500,7 +501,7 @@
 	end
 
 	self.events.fire_event("node-deleted", { service = self, node = node, actor = actor });
-	self.config.broadcaster("delete", node, node_obj.subscribers, nil, actor, node_obj, self);
+	self:broadcast("delete", node, node_obj.subscribers, nil, actor, node_obj);
 	return true;
 end
 
@@ -568,10 +569,15 @@
 	local event_data = { service = self, node = node, actor = actor, id = id, item = item };
 	self.events.fire_event("item-published/"..node, event_data);
 	self.events.fire_event("item-published", event_data);
-	self.config.broadcaster("items", node, node_obj.subscribers, item, actor, node_obj, self);
+	self:broadcast("items", node, node_obj.subscribers, item, actor, node_obj);
 	return true;
 end
 
+function service:broadcast(event, node, subscribers, item, actor, node_obj)
+	subscribers = self.config.subscriber_filter(subscribers, node, event);
+	return self.config.broadcaster(event, node, subscribers, item, actor, node_obj, self);
+end
+
 function service:retract(node, actor, id, retract) --> ok, err
 	-- Access checking
 	if not self:may(node, actor, "retract") then
@@ -588,7 +594,7 @@
 	end
 	self.events.fire_event("item-retracted", { service = self, node = node, actor = actor, id = id });
 	if retract then
-		self.config.broadcaster("retract", node, node_obj.subscribers, retract, actor, node_obj, self);
+		self:broadcast("retract", node, node_obj.subscribers, retract, actor, node_obj);
 	end
 	return true
 end
@@ -610,7 +616,7 @@
 	end
 	self.events.fire_event("node-purged", { service = self, node = node, actor = actor });
 	if notify then
-		self.config.broadcaster("purge", node, node_obj.subscribers, nil, actor, node_obj, self);
+		self:broadcast("purge", node, node_obj.subscribers, nil, actor, node_obj);
 	end
 	return true
 end