annotate mod_server_contact_info/mod_server_contact_info.lua @ 1790:4c2146f5bf39

mod_mam: Store chat messages and normal messages with a body
author Kim Alvefur <zash@zash.se>
date Wed, 26 Aug 2015 17:40:22 +0200
parents 4fdcb5c35021
children 465b34fdeb60
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
414
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- This plugin implements http://xmpp.org/extensions/xep-0157.html
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local t_insert = table.insert;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local df_new = require "util.dataforms".new;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 -- Source: http://xmpp.org/registrar/formtypes.html#http:--jabber.org-network-serverinfo
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local valid_types = {
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 abuse = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 admin = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 feedback = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 sales = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 security = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 support = true;
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 }
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
15 local contact_config = module:get_option("contact_info");
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
16 if not contact_config then -- we'll use admins from the config as default
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
17 contact_config = { admin = {}; };
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
18 local admins = module:get_option("admins");
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
19 if not admins or #admins == 0 then
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
20 module:log("debug", "No contact_info or admins in config");
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
21 return -- Nothing to attach, so we'll just skip it.
414
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 end
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
23 module:log("debug", "No contact_info in config, using admins as fallback");
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
24 --TODO fetch global admins too?
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
25 for i = 1,#admins do
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
26 t_insert(contact_config.admin, "xmpp:" .. admins[i])
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
27 module:log("debug", "Added %s to admin-addresses", admins[i]);
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
28 end
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
29 end
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
30 if not next(contact_config) then
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
31 module:log("debug", "No contacts, skipping");
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
32 return -- No use in serving an empty form.
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
33 end
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
34 local form_layout = {
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
35 { value = "http://jabber.org/network/serverinfo"; type = "hidden"; name = "FORM_TYPE"; };
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
36 };
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
37 local form_values = {};
414
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
39 for t,a in pairs(contact_config) do
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
40 if valid_types[t] and a then
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
41 t_insert(form_layout, { name = t .. "-addresses", type = "list-multi" });
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
42 form_values[t .. "-addresses"] = type(a) == "table" and a or {a};
414
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 end
074237d7820b mod_server_contact_info: Add module that publishes contact information.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45
942
4fdcb5c35021 mod_server_contact_info: Remove config-reloaded hook
Kim Alvefur <zash@zash.se>
parents: 414
diff changeset
46 module:add_extension(df_new(form_layout):form(form_values, "result"));