Mercurial > prosody-hg
comparison plugins/mod_server_contact_info.lua @ 9333:fd704adc62e1
mod_server_contact_info: Simplify
This relies on the new name mapping in util.dataforms
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 16 Sep 2018 22:40:35 +0200 |
| parents | c24837f57259 |
| children | a86736e0163c |
comparison
equal
deleted
inserted
replaced
| 9332:048389a9bbd4 | 9333:fd704adc62e1 |
|---|---|
| 3 -- Copyright (C) 2011-2016 Kim Alvefur | 3 -- Copyright (C) 2011-2016 Kim Alvefur |
| 4 -- | 4 -- |
| 5 -- This file is MIT/X11 licensed. | 5 -- This file is MIT/X11 licensed. |
| 6 -- | 6 -- |
| 7 | 7 |
| 8 local t_insert = table.insert; | |
| 9 local array = require "util.array"; | 8 local array = require "util.array"; |
| 10 local df_new = require "util.dataforms".new; | |
| 11 | 9 |
| 12 -- Source: http://xmpp.org/registrar/formtypes.html#http:--jabber.org-network-serverinfo | 10 -- Source: http://xmpp.org/registrar/formtypes.html#http:--jabber.org-network-serverinfo |
| 13 local valid_types = { | 11 local form_layout = require "util.dataforms".new({ |
| 14 abuse = true; | 12 { var = "FORM_TYPE"; type = "hidden"; value = "http://jabber.org/network/serverinfo"; }; |
| 15 admin = true; | 13 { name = "abuse", var = "abuse-addresses", type = "list-multi" }, |
| 16 feedback = true; | 14 { name = "admin", var = "admin-addresses", type = "list-multi" }, |
| 17 sales = true; | 15 { name = "feedback", var = "feedback-addresses", type = "list-multi" }, |
| 18 security = true; | 16 { name = "sales", var = "sales-addresses", type = "list-multi" }, |
| 19 support = true; | 17 { name = "security", var = "security-addresses", type = "list-multi" }, |
| 20 } | 18 { name = "support", var = "support-addresses", type = "list-multi" }, |
| 19 }); | |
| 21 | 20 |
| 22 local contact_config = module:get_option("contact_info"); | 21 local admins = module:get_option_inherited_set("admins", {}); |
| 23 if not contact_config or not next(contact_config) then -- we'll use admins from the config as default | |
| 24 local admins = module:get_option_inherited_set("admins", {}); | |
| 25 if admins:empty() then | |
| 26 module:log("error", "No contact_info or admins set in config"); | |
| 27 return -- Nothing to attach, so we'll just skip it. | |
| 28 end | |
| 29 module:log("info", "No contact_info in config, using admins as fallback"); | |
| 30 contact_config = { | |
| 31 admin = array.collect( admins / function(admin) return "xmpp:" .. admin; end); | |
| 32 }; | |
| 33 end | |
| 34 | 22 |
| 35 local form_layout = { | 23 local contact_config = module:get_option("contact_info", { |
| 36 { value = "http://jabber.org/network/serverinfo"; type = "hidden"; name = "FORM_TYPE"; }; | 24 admin = array.collect( admins / function(admin) return "xmpp:" .. admin; end); |
| 37 }; | 25 }); |
| 38 | 26 |
| 39 local form_values = {}; | 27 module:add_extension(form_layout:form(contact_config, "result")); |
| 40 | |
| 41 for t in pairs(valid_types) do | |
| 42 local addresses = contact_config[t]; | |
| 43 if addresses then | |
| 44 t_insert(form_layout, { name = t .. "-addresses", type = "list-multi" }); | |
| 45 form_values[t .. "-addresses"] = addresses; | |
| 46 end | |
| 47 end | |
| 48 | |
| 49 module:add_extension(df_new(form_layout):form(form_values, "result")); |
