Diff

plugins/mod_pubsub/pubsub.lib.lua @ 12960:31b22cc221b5

mod_pubsub, mod_pep: Support per-node configurable inclusion of publisher This matches ejabberd's behaviour, using the 'pubsub#itemreply' config option. Although the current definition of this option in the specification is not as clear as it could be, I think matching what existing deployments do is the best option to resolve the ambiguity and reduce fragmentation. We should update the spec to be clearer about how to use and interpret this option. The 'expose_publisher' option for mod_pubsub is now an override (always expose or never expose). If unset, it will use the per-node config (which defaults to not exposing). Thanks to Link Mauve, edhelas and goffi for sparking this feature.
author Matthew Wild <mwild1@gmail.com>
date Wed, 22 Mar 2023 11:39:19 +0000
parent 12636:e8934ce6ea0f
child 12961:1cbfa843f8c3
line wrap: on
line diff
--- a/plugins/mod_pubsub/pubsub.lib.lua	Tue Mar 21 20:43:42 2023 +0100
+++ b/plugins/mod_pubsub/pubsub.lib.lua	Wed Mar 22 11:39:19 2023 +0000
@@ -164,6 +164,17 @@
 		var = "pubsub#notify_retract";
 		value = true;
 	};
+	{
+		type = "list-single";
+		label = "Specify whose JID to include as the publisher of items";
+		name = "pubsub#itemreply";
+		var = "itemreply";
+		options = {
+			{ label = "Include the node owner's JID", value = "owner" };
+			{ label = "Include the item publisher's JID", value = "publisher" };
+			{ label = "Don't include any JID with items", value = "none", default = true };
+		};
+	};
 };
 _M.node_config_form = node_config_form;
 
@@ -347,6 +358,13 @@
 		origin.send(pubsub_error_reply(stanza, "nodeid-required"));
 		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
+
 	local resultspec; -- TODO rsm.get()
 	if items.attr.max_items then
 		resultspec = { max = tonumber(items.attr.max_items) };
@@ -358,6 +376,9 @@
 	end
 
 	local expose_publisher = service.config.expose_publisher;
+	if expose_publisher == nil and node_obj.config.itemreply == "publisher" then
+		expose_publisher = true;
+	end
 
 	local data = st.stanza("items", { node = node });
 	local iter, v, i = ipairs(results);