Annotate

mod_server_info/mod_server_info.lua @ 5925:9ed02a4f6ff4

mod_invites_tracking: Don't bother storing anything for non-invite IBR
author Matthew Wild <mwild1@gmail.com>
date Wed, 08 May 2024 12:48:41 +0100
parent 5866:ed82916e5796
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5866
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
1 -- mod_server_info imported from Prosody commit 1ce18cb3e6cc for the benefit
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
2 -- of 0.12 deployments. This community version of the module will not load in
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
3 -- newer Prosody versions, which include their own copy of the module.
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
4 --% conflicts: mod_server_info
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
5
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
6 local dataforms = require "prosody.util.dataforms";
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
7
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
8 local server_info_config = module:get_option("server_info", {});
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
9 local server_info_custom_fields = module:get_option_array("server_info_extensions");
5817
174c77da03f5 mod_server_info: New module to add custom service extension forms to disco
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
5866
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
11 -- Source: http://xmpp.org/registrar/formtypes.html#http:--jabber.org-network-serverinfo
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
12 local form_layout = dataforms.new({
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
13 { var = "FORM_TYPE"; type = "hidden"; value = "http://jabber.org/network/serverinfo" };
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
14 });
5817
174c77da03f5 mod_server_info: New module to add custom service extension forms to disco
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
5866
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
16 if server_info_custom_fields then
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
17 for _, field in ipairs(server_info_custom_fields) do
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
18 table.insert(form_layout, field);
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
19 end
5817
174c77da03f5 mod_server_info: New module to add custom service extension forms to disco
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end
174c77da03f5 mod_server_info: New module to add custom service extension forms to disco
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
5866
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
22 local generated_form;
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
23
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
24 function update_form()
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
25 local new_form = form_layout:form(server_info_config, "result");
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
26 if generated_form then
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
27 module:remove_item("extension", generated_form);
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
28 end
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
29 generated_form = new_form;
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
30 module:add_item("extension", generated_form);
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
31 end
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
32
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
33 function add_fields(event)
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
34 local fields = event.item;
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
35 for _, field in ipairs(fields) do
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
36 table.insert(form_layout, field);
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
37 end
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
38 update_form();
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
39 end
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
40
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
41 function remove_fields(event)
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
42 local removed_fields = event.item;
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
43 for _, removed_field in ipairs(removed_fields) do
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
44 local removed_var = removed_field.var or removed_field.name;
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
45 for i, field in ipairs(form_layout) do
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
46 local var = field.var or field.name
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
47 if var == removed_var then
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
48 table.remove(form_layout, i);
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
49 break;
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
50 end
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
51 end
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
52 end
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
53 update_form();
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
54 end
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
55
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
56 module:handle_items("server-info-fields", add_fields, remove_fields);
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
57
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
58 function module.load()
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
59 update_form();
ed82916e5796 mod_server_info: Rewrite/backport from Prosody 1ce18cb3e6cc
Matthew Wild <mwild1@gmail.com>
parents: 5817
diff changeset
60 end