mod_server_contact_info: Include both global and local admins in fallback mode

Sat, 01 Oct 2016 17:13:57 +0200

author
Kim Alvefur <zash@zash.se>
date
Sat, 01 Oct 2016 17:13:57 +0200
changeset 2317
465b34fdeb60
parent 2316
2a2de19413e7
child 2318
3e5828e3f17f

mod_server_contact_info: Include both global and local admins in fallback mode

mod_server_contact_info/mod_server_contact_info.lua file | annotate | diff | comparison | revisions
--- a/mod_server_contact_info/mod_server_contact_info.lua	Sat Oct 01 01:09:31 2016 +0200
+++ b/mod_server_contact_info/mod_server_contact_info.lua	Sat Oct 01 17:13:57 2016 +0200
@@ -1,5 +1,6 @@
 -- This plugin implements http://xmpp.org/extensions/xep-0157.html
 local t_insert = table.insert;
+local array = require "util.array";
 local df_new = require "util.dataforms".new;
 
 -- Source: http://xmpp.org/registrar/formtypes.html#http:--jabber.org-network-serverinfo
@@ -14,18 +15,15 @@
 
 local contact_config = module:get_option("contact_info");
 if not contact_config then -- we'll use admins from the config as default
-	contact_config = { admin = {}; };
-	local admins = module:get_option("admins");
-	if not admins or #admins == 0 then
+	local admins = module:get_option_inherited_set("admins", {});
+	if admins:empty() then
 		module:log("debug", "No contact_info or admins in config");
 		return -- Nothing to attach, so we'll just skip it.
 	end
 	module:log("debug", "No contact_info in config, using admins as fallback");
-	--TODO fetch global admins too?
-	for i = 1,#admins do
-		t_insert(contact_config.admin, "xmpp:" .. admins[i])
-		module:log("debug", "Added %s to admin-addresses", admins[i]);
-	end
+	contact_config = {
+		admin = array.collect( admins / function(admin) return "xmpp:" .. admin; end);
+	};
 end
 if not next(contact_config) then
 	module:log("debug", "No contacts, skipping");

mercurial