Diff

util/pubsub.lua @ 5320:518d864b2ab8

mod_pubsub, util.pubsub: Add delete action
author Kim Alvefur <zash@zash.se>
date Thu, 31 Jan 2013 18:41:01 +0100
parent 5315:abf1a926d0da
child 5628:ba5c2f6b799e
line wrap: on
line diff
--- a/util/pubsub.lua	Thu Jan 31 15:48:55 2013 +0100
+++ b/util/pubsub.lua	Thu Jan 31 18:41:01 2013 +0100
@@ -226,6 +226,18 @@
 	return ok, err;
 end
 
+function service:delete(node, actor)
+	-- Access checking
+	if not self:may(node, actor, "delete") then
+		return false, "forbidden";
+	end
+	--
+	local node_obj = self.nodes[node];
+	self.nodes[node] = nil;
+	self.config.broadcaster("delete", node, node_obj.subscribers);
+	return true;
+end
+
 function service:publish(node, actor, id, item)
 	-- Access checking
 	if not self:may(node, actor, "publish") then