diff plugins/mod_pubsub/mod_pubsub.lua @ 14118:221f3378e7f4

mod_pubsub, util.pubsub: Support for 'authorize' access model
author Matthew Wild <mwild1@gmail.com>
date Tue, 31 Mar 2026 14:18:06 +0100
parents 354427afb638
children
line wrap: on
line diff
--- a/plugins/mod_pubsub/mod_pubsub.lua	Tue Mar 31 14:15:00 2026 +0100
+++ b/plugins/mod_pubsub/mod_pubsub.lua	Tue Mar 31 14:18:06 2026 +0100
@@ -30,6 +30,10 @@
 	return lib_pubsub.handle_pubsub_iq(event, service);
 end
 
+function handle_pubsub_message(event)
+	return lib_pubsub.handle_pubsub_message(event, service);
+end
+
 -- An itemstore supports the following methods:
 --   items(): iterator over (id, item)
 --   get(id): return item with id
@@ -43,6 +47,10 @@
 --   get(node_name)
 --   users(): iterator over (node_name)
 
+local supported_access_models = require "prosody.util.set".new({
+	"open", "whitelist", "authorize"
+});
+
 local max_max_items = module:get_option_integer("pubsub_max_items", 256, 1);
 
 local function tonumber_max_items(n)
@@ -130,8 +138,7 @@
 	if (tonumber_max_items(new_config["max_items"]) or 1) > max_max_items then
 		return false;
 	end
-	if new_config["access_model"] ~= "whitelist"
-	and new_config["access_model"] ~= "open" then
+	if not supported_access_models:contains(new_config["access_model"]) then
 		return false;
 	end
 	return true;
@@ -173,6 +180,8 @@
 module:hook("iq/host/"..xmlns_pubsub..":pubsub", handle_pubsub_iq);
 module:hook("iq/host/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq);
 
+module:hook("message/host", handle_pubsub_message);
+
 local function add_disco_features_from_service(service) --luacheck: ignore 431/service
 	for feature in lib_pubsub.get_feature_set(service) do
 		module:add_feature(xmlns_pubsub.."#"..feature);
@@ -243,6 +252,7 @@
 
 	module.environment.service = service;
 	add_disco_features_from_service(service);
+	lib_pubsub.add_service_hooks(service);
 end
 
 function module.save()