Comparison

mod_muc_webchat_url/mod_muc_webchat_url.lua @ 3673:11ebf1da416b

mod_muc_webchat_url: Don't save templated value This prevents changing of other settings without touching the webchat URL from saving the template value. Otherwise the URL will still be advertised when configuring members-only or hidden.
author Kim Alvefur <zash@zash.se>
date Tue, 17 Sep 2019 17:22:35 +0200
parent 3672:b8bcea17ccd6
child 3675:776ff0875e35
comparison
equal deleted inserted replaced
3672:b8bcea17ccd6 3673:11ebf1da416b
1 local jid_split = require "util.jid".split; 1 local jid_split = require "util.jid".split;
2 module:depends"muc"; 2 module:depends"muc";
3 3
4 local webchat_baseurl = module:get_option_string("muc_webchat_baseurl", nil); 4 local webchat_baseurl = module:get_option_string("muc_webchat_baseurl", nil);
5 5
6 local function get_webchat_url(room) 6 local function get_default_url(room)
7 local webchat_url = room._data.webchat_url;
8 if webchat_url then -- explicitly configured
9 return webchat_url;
10 end
11 if not webchat_baseurl then 7 if not webchat_baseurl then
12 -- no template 8 -- no template
13 return nil; 9 return nil;
14 end 10 end
15 if room:get_hidden() or room:get_members_only() or room:get_password() then 11 if room:get_hidden() or room:get_members_only() or room:get_password() then
21 node = select(1, jid_split(room.jid)), 17 node = select(1, jid_split(room.jid)),
22 host = select(2, jid_split(room.jid)), 18 host = select(2, jid_split(room.jid)),
23 })); 19 }));
24 end 20 end
25 21
22 local function get_webchat_url(room)
23 local webchat_url = room._data.webchat_url;
24 if webchat_url then -- explicitly configured
25 return webchat_url;
26 end
27 end
28
26 module:hook("muc-config-form", function(event) 29 module:hook("muc-config-form", function(event)
27 local room, form = event.room, event.form; 30 local room, form = event.room, event.form;
28 table.insert(form, { 31 table.insert(form, {
29 name = "muc#roomconfig_webchat_url", 32 name = "muc#roomconfig_webchat_url",
30 type = "text-single", 33 type = "text-single",
34 end); 37 end);
35 38
36 module:hook("muc-config-submitted", function(event) 39 module:hook("muc-config-submitted", function(event)
37 local room, fields, changed = event.room, event.fields, event.changed; 40 local room, fields, changed = event.room, event.fields, event.changed;
38 local new = fields["muc#roomconfig_webchat_url"]; 41 local new = fields["muc#roomconfig_webchat_url"];
39 if new ~= room._data.webchat_url then 42 if new ~= get_webchat_url(room) then
40 room._data.webchat_url = new; 43 if new == get_default_url(room) then
44 room._data.webchat_url = nil;
45 else
46 room._data.webchat_url = new;
47 end
41 if type(changed) == "table" then 48 if type(changed) == "table" then
42 changed["muc#roomconfig_webchat_url"] = true; 49 changed["muc#roomconfig_webchat_url"] = true;
43 else 50 else
44 event.changed = true; 51 event.changed = true;
45 end 52 end