Software /
code /
prosody
Changeset
9041:b3bc742ee188
mod_pubsub: Add support for changing subscription options
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 14 Jul 2018 20:18:49 +0200 |
parents | 9040:e993fad0cc62 |
children | 9042:734ba7080b35 |
files | plugins/mod_pubsub/pubsub.lib.lua |
diffstat | 1 files changed, 30 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_pubsub/pubsub.lib.lua Sat Jul 14 19:35:26 2018 +0200 +++ b/plugins/mod_pubsub/pubsub.lib.lua Sat Jul 14 20:18:49 2018 +0200 @@ -24,6 +24,7 @@ ["nodeid-required"] = { "modify", "bad-request", nil, "nodeid-required" }; ["item-not-found"] = { "cancel", "item-not-found" }; ["not-subscribed"] = { "modify", "unexpected-request", nil, "not-subscribed" }; + ["invalid-options"] = { "modify", "bad-request", nil, "invalid-options" }; ["forbidden"] = { "auth", "forbidden" }; ["not-allowed"] = { "cancel", "not-allowed" }; ["internal-server-error"] = { "wait", "internal-server-error" }; @@ -453,6 +454,35 @@ return true; end +function handlers.set_options(origin, stanza, options, service) + local node, jid = options.attr.node, options.attr.jid; + jid = jid_prep(jid); + if not (node and jid) then + origin.send(pubsub_error_reply(stanza, jid and "nodeid-required" or "invalid-jid")); + return true; + end + local ok, ret = service:get_subscription(node, stanza.attr.from, jid); + if not ok then + origin.send(pubsub_error_reply(stanza, ret)); + return true; + elseif not ret then + origin.send(pubsub_error_reply(stanza, "not-subscribed")); + return true; + end + local new_subopts, err = options_form:data(options.tags[1]); + if not new_subopts then + origin.send(pubsub_error_reply(stanza, ret)); + return true; + end + local ok, err = service:add_subscription(node, stanza.attr.from, jid, new_subopts); + if not ok then + origin.send(pubsub_error_reply(stanza, err)); + return true; + end + origin.send(st.reply(stanza)); + return true; +end + function handlers.set_publish(origin, stanza, publish, service) local node = publish.attr.node; if not node then