diff options
author | Kim Alvefur <zash@zash.se> | 2013-02-03 15:52:27 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2013-02-03 15:52:27 +0100 |
commit | 1929113b7830954ae60ad49934b3c16bf746a9ba (patch) | |
tree | a1d3fc24abd3048cb23d45b860640a83baa8c261 /util/pubsub.lua | |
parent | 0f2d3d7139c741b6bd8714048694ee16a9b11c91 (diff) | |
parent | 5cfdac70c61ae6562f72868ef7b55129b166aa80 (diff) | |
download | prosody-1929113b7830954ae60ad49934b3c16bf746a9ba.tar.gz prosody-1929113b7830954ae60ad49934b3c16bf746a9ba.zip |
Merge 0.9->trunk
Diffstat (limited to 'util/pubsub.lua')
-rw-r--r-- | util/pubsub.lua | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/util/pubsub.lua b/util/pubsub.lua index 8ff458e7..e7fc86b1 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -226,6 +226,18 @@ function service:create(node, actor) 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 @@ -245,7 +257,7 @@ function service:publish(node, actor, id, item) end node_obj.data[id] = item; self.events.fire_event("item-published", { node = node, actor = actor, id = id, item = item }); - self.config.broadcaster(node, node_obj.subscribers, item); + self.config.broadcaster("items", node, node_obj.subscribers, item); return true; end @@ -261,7 +273,24 @@ function service:retract(node, actor, id, retract) end node_obj.data[id] = nil; if retract then - self.config.broadcaster(node, node_obj.subscribers, retract); + self.config.broadcaster("items", node, node_obj.subscribers, retract); + end + return true +end + +function service:purge(node, actor, notify) + -- Access checking + if not self:may(node, actor, "retract") then + return false, "forbidden"; + end + -- + local node_obj = self.nodes[node]; + if not node_obj then + return false, "item-not-found"; + end + node_obj.data = {}; -- Purge + if notify then + self.config.broadcaster("purge", node, node_obj.subscribers); end return true end @@ -321,7 +350,7 @@ function service:get_subscriptions(node, actor, jid) if node then -- Return only subscriptions to this node if subscribed_nodes[node] then ret[#ret+1] = { - node = subscribed_node; + node = subscribed_nodes[node]; jid = jid; subscription = node_obj.subscribers[jid]; }; |