diff options
author | Florian Zeitz <florob@babelmonkeys.de> | 2010-12-05 04:19:23 +0100 |
---|---|---|
committer | Florian Zeitz <florob@babelmonkeys.de> | 2010-12-05 04:19:23 +0100 |
commit | 649c7432b75f0faea2e5e7ba7336138f98a8e001 (patch) | |
tree | 78b13c20b1654d2b0733176198eb6ec86e82ad78 | |
parent | 0e2b3ce46897f044dba8a262bb3a7cf848d624be (diff) | |
download | prosody-649c7432b75f0faea2e5e7ba7336138f98a8e001.tar.gz prosody-649c7432b75f0faea2e5e7ba7336138f98a8e001.zip |
mod_pubsub: Support item retraction
-rw-r--r-- | plugins/mod_pubsub.lua | 20 | ||||
-rw-r--r-- | util/pubsub.lua | 12 |
2 files changed, 31 insertions, 1 deletions
diff --git a/plugins/mod_pubsub.lua b/plugins/mod_pubsub.lua index 0475ea1d..0644001f 100644 --- a/plugins/mod_pubsub.lua +++ b/plugins/mod_pubsub.lua @@ -76,7 +76,7 @@ function handlers.set_create(origin, stanza, create) :tag("pubsub", { xmlns = xmlns_pubsub }) :tag("create", { node = node }); end - origin.send(reply); + return origin.send(reply); end function handlers.set_subscribe(origin, stanza, subscribe) @@ -132,6 +132,24 @@ function handlers.set_publish(origin, stanza, publish) return origin.send(reply); end +function handlers.set_retract(origin, stanza, retract) + local node, notify = retract.attr.node, retract.attr.notify; + notify = (notify == "1") or (notify == "true"); + local item = retract:get_child("item"); + local id = item and item.attr.id + local reply, notifier; + if notify then + notifier = st.stanza("retract", { id = id }); + end + local ok, ret = service:retract(node, stanza.attr.from, id, notifier); + if ok then + reply = st.reply(stanza); + else + reply = pubsub_error_reply(stanza, ret); + end + return origin.send(reply); +end + function simple_broadcast(node, jids, item) local message = st.message({ from = module.host, type = "headline" }) :tag("event", { xmlns = xmlns_pubsub_event }) diff --git a/util/pubsub.lua b/util/pubsub.lua index 4789dff9..02e845e1 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -54,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 |