Software /
code /
prosody
Diff
plugins/mod_pubsub.lua @ 3698:77171fd1dc3c
mod_pubsub, util.pubsub: Support for unsubscribing
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Sun, 05 Dec 2010 02:46:08 +0100 |
parent | 3697:67c01f75af97 |
child | 3699:150e58d69e60 |
line wrap: on
line diff
--- a/plugins/mod_pubsub.lua Fri Dec 03 16:36:13 2010 +0100 +++ b/plugins/mod_pubsub.lua Sun Dec 05 02:46:08 2010 +0100 @@ -28,6 +28,7 @@ ["conflict"] = { "cancel", "conflict" }; ["invalid-jid"] = { "modify", "bad-request", nil, "invalid-jid" }; ["item-not-found"] = { "cancel", "item-not-found" }; + ["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" }; }; function pubsub_error_reply(stanza, error) local e = pubsub_errors[error]; @@ -99,6 +100,21 @@ return origin.send(reply); end +function handlers.set_unsubscribe(origin, stanza, unsubscribe) + local node, jid = unsubscribe.attr.node, unsubscribe.attr.jid; + if jid_bare(jid) ~= jid_bare(stanza.attr.from) then + return origin.send(pubsub_error_reply(stanza, "invalid-jid")); + end + local ok, ret = service:remove_subscription(node, stanza.attr.from, jid); + local reply; + if ok then + reply = st.reply(stanza); + else + reply = pubsub_error_reply(stanza, ret); + end + return origin.send(reply); +end + function handlers.set_publish(origin, stanza, publish) local node = publish.attr.node; local item = publish:get_child("item");