diff plugins/mod_pubsub/pubsub.lib.lua @ 13951:eea166afad9b

mod_pubsub: Implement retrieval of own affiliation(s) #1966
author Kim Alvefur <zash@zash.se>
date Tue, 16 Sep 2025 20:35:52 +0200
parents e17ff906d71b
children 3eb39ff813ac
line wrap: on
line diff
--- a/plugins/mod_pubsub/pubsub.lib.lua	Sat Sep 20 23:48:04 2025 +0200
+++ b/plugins/mod_pubsub/pubsub.lib.lua	Tue Sep 16 20:35:52 2025 +0200
@@ -232,7 +232,7 @@
 	add_subscription = { "subscribe", "subscription-options" };
 	create = { "create-nodes", "instant-nodes", "item-ids", "create-and-configure" };
 	delete = { "delete-nodes" };
-	get_items = { "retrieve-items" };
+	get_items = { "retrieve-items", "retrieve-affiliations" };
 	get_subscriptions = { "retrieve-subscriptions" };
 	node_defaults = { "retrieve-default" };
 	publish = { "publish", "multi-items", "publish-options" };
@@ -793,6 +793,33 @@
 	return true;
 end
 
+function handlers.get_affiliations(origin, stanza, affiliations, service)
+	local ok, nodes = service:get_nodes(stanza.attr.from);
+	if not ok then
+		origin.send(pubsub_error_reply(stanza, err));
+		return true;
+	end
+	local node = affiliations.attr.node;
+	if node then
+		nodes = { [node] = nodes[node] };
+	end
+
+	local reply = st.reply(stanza)
+		:tag("pubsub", { xmlns = xmlns_pubsub })
+			:tag("affiliations");
+
+	local jid = service.config.normalize_jid(stanza.attr.from);
+	for node, node_obj in pairs(nodes) do
+		local affiliation = node_obj.affiliations[jid];
+		if affiliation then
+			reply:tag("affiliation", { node = node; affiliation = affiliation }):up();
+		end
+	end
+
+	origin.send(reply);
+	return true;
+end
+
 function handlers.owner_get_affiliations(origin, stanza, affiliations, service)
 	local node = affiliations.attr.node;
 	if not node then