X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fpubsub.lua;h=02e845e192d0536da60094aa64989d7d20be7714;hb=eecf63b9e5aff94dc3d3e88e3b5dfa853d92fc1a;hp=dc3f3432f4ace195db2a500925c35c5249c81237;hpb=7d72563c747f6f15f42e516cd0cbedddf3329c9f;p=prosody.git diff --git a/util/pubsub.lua b/util/pubsub.lua index dc3f3432..02e845e1 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -17,7 +17,14 @@ function service:add_subscription(node, actor, jid) end function service:remove_subscription(node, actor, jid) - self.nodes[node].subscribers[jid] = nil; + local node_obj = self.nodes[node]; + if not node_obj then + return false, "item-not-found"; + end + if not node_obj.subscribers[jid] then + return false, "not-subscribed"; + end + node_obj.subscribers[jid] = nil; return true; end @@ -47,6 +54,18 @@ function service:publish(node, actor, id, item) return true; end +function service:retract(node, actor, id, retract) + local node_obj = self.nodes[node]; + if (not node_obj) or (not node_obj.data[id]) then + return false, "item-not-found"; + end + node_obj.data[id] = nil; + if retract then + self.cb.broadcaster(node, node_obj.subscribers, retract); + end + return true +end + function service:get(node, actor, id) local node_obj = self.nodes[node]; if node_obj then