aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_pubsub/pubsub.lib.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-07-13 04:52:43 +0200
committerKim Alvefur <zash@zash.se>2018-07-13 04:52:43 +0200
commitc80aae6deea828a5178a9af5dc5981705ab46175 (patch)
tree4bfba808e2e59cba744f1987ace330815f71ee2f /plugins/mod_pubsub/pubsub.lib.lua
parente18193a4ffec3a0f8351827823a04425e7956a39 (diff)
downloadprosody-c80aae6deea828a5178a9af5dc5981705ab46175.tar.gz
prosody-c80aae6deea828a5178a9af5dc5981705ab46175.zip
mod_pubsub: Add support for modifying subscriptions
https://xmpp.org/extensions/xep-0060.html#owner-subscriptions-modify
Diffstat (limited to 'plugins/mod_pubsub/pubsub.lib.lua')
-rw-r--r--plugins/mod_pubsub/pubsub.lib.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua
index f10c593f..540185a7 100644
--- a/plugins/mod_pubsub/pubsub.lib.lua
+++ b/plugins/mod_pubsub/pubsub.lib.lua
@@ -267,6 +267,44 @@ function handlers.owner_get_subscriptions(origin, stanza, subscriptions, service
return true;
end
+function handlers.owner_set_subscriptions(origin, stanza, subscriptions, service)
+ local node = subscriptions.attr.node;
+ if not node then
+ origin.send(pubsub_error_reply(stanza, "nodeid-required"));
+ return true;
+ end
+ if not service:may(node, stanza.attr.from, "subscribe_other") then
+ origin.send(pubsub_error_reply(stanza, "forbidden"));
+ return true;
+ end
+
+ local node_obj = service.nodes[node];
+ if not node_obj then
+ origin.send(pubsub_error_reply(stanza, "item-not-found"));
+ return true;
+ end
+
+ for subscription_tag in subscriptions:childtags("subscription") do
+ if subscription_tag.attr.subscription == 'subscribed' then
+ local ok, err = service:add_subscription(node, stanza.attr.from, subscription_tag.attr.jid);
+ if not ok then
+ origin.send(pubsub_error_reply(stanza, err));
+ return true;
+ end
+ elseif subscription_tag.attr.subscription == 'none' then
+ local ok, err = service:remove_subscription(node, stanza.attr.from, subscription_tag.attr.jid);
+ if not ok then
+ origin.send(pubsub_error_reply(stanza, err));
+ return true;
+ end
+ end
+ end
+
+ local reply = st.reply(stanza);
+ origin.send(reply);
+ return true;
+end
+
function handlers.set_create(origin, stanza, create, service)
local node = create.attr.node;
local ok, ret, reply;