Diff

plugins/mod_pubsub/pubsub.lib.lua @ 9033:f1b6efd5b379

mod_pubsub: Add support for modifying subscriptions https://xmpp.org/extensions/xep-0060.html#owner-subscriptions-modify
author Kim Alvefur <zash@zash.se>
date Fri, 13 Jul 2018 04:52:43 +0200
parent 9032:029e1e18d65c
child 9037:e3c8274427d3
line wrap: on
line diff
--- a/plugins/mod_pubsub/pubsub.lib.lua	Fri Jul 13 04:42:19 2018 +0200
+++ b/plugins/mod_pubsub/pubsub.lib.lua	Fri Jul 13 04:52:43 2018 +0200
@@ -267,6 +267,44 @@
 	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;