diff options
author | Kim Alvefur <zash@zash.se> | 2018-09-16 22:40:35 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2018-09-16 22:40:35 +0200 |
commit | b8e5c6c7a04ae961d41b168b9871aa2504106b6b (patch) | |
tree | a405618f2844eb12fd6056bca1689fa9ac3c089a /plugins/mod_server_contact_info.lua | |
parent | 818a977d3853fcc2ceec217ffb9b6ea4f3057852 (diff) | |
download | prosody-b8e5c6c7a04ae961d41b168b9871aa2504106b6b.tar.gz prosody-b8e5c6c7a04ae961d41b168b9871aa2504106b6b.zip |
mod_server_contact_info: Simplify
This relies on the new name mapping in util.dataforms
Diffstat (limited to 'plugins/mod_server_contact_info.lua')
-rw-r--r-- | plugins/mod_server_contact_info.lua | 50 |
1 files changed, 14 insertions, 36 deletions
diff --git a/plugins/mod_server_contact_info.lua b/plugins/mod_server_contact_info.lua index 7ee8a08f..5f44cdc4 100644 --- a/plugins/mod_server_contact_info.lua +++ b/plugins/mod_server_contact_info.lua @@ -5,45 +5,23 @@ -- This file is MIT/X11 licensed. -- -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 -local valid_types = { - abuse = true; - admin = true; - feedback = true; - sales = true; - security = true; - support = true; -} +local form_layout = require "util.dataforms".new({ + { var = "FORM_TYPE"; type = "hidden"; value = "http://jabber.org/network/serverinfo"; }; + { name = "abuse", var = "abuse-addresses", type = "list-multi" }, + { name = "admin", var = "admin-addresses", type = "list-multi" }, + { name = "feedback", var = "feedback-addresses", type = "list-multi" }, + { name = "sales", var = "sales-addresses", type = "list-multi" }, + { name = "security", var = "security-addresses", type = "list-multi" }, + { name = "support", var = "support-addresses", type = "list-multi" }, +}); -local contact_config = module:get_option("contact_info"); -if not contact_config or not next(contact_config) then -- we'll use admins from the config as default - local admins = module:get_option_inherited_set("admins", {}); - if admins:empty() then - module:log("error", "No contact_info or admins set in config"); - return -- Nothing to attach, so we'll just skip it. - end - module:log("info", "No contact_info in config, using admins as fallback"); - contact_config = { - admin = array.collect( admins / function(admin) return "xmpp:" .. admin; end); - }; -end +local admins = module:get_option_inherited_set("admins", {}); -local form_layout = { - { value = "http://jabber.org/network/serverinfo"; type = "hidden"; name = "FORM_TYPE"; }; -}; +local contact_config = module:get_option("contact_info", { + admin = array.collect( admins / function(admin) return "xmpp:" .. admin; end); +}); -local form_values = {}; - -for t in pairs(valid_types) do - local addresses = contact_config[t]; - if addresses then - t_insert(form_layout, { name = t .. "-addresses", type = "list-multi" }); - form_values[t .. "-addresses"] = addresses; - end -end - -module:add_extension(df_new(form_layout):form(form_values, "result")); +module:add_extension(form_layout:form(contact_config, "result")); |