changeset 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
parents b8bcea17ccd6
children 8ee5816363b0
files mod_muc_webchat_url/mod_muc_webchat_url.lua
diffstat 1 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_webchat_url/mod_muc_webchat_url.lua	Tue Sep 17 17:12:59 2019 +0200
+++ b/mod_muc_webchat_url/mod_muc_webchat_url.lua	Tue Sep 17 17:22:35 2019 +0200
@@ -3,11 +3,7 @@
 
 local webchat_baseurl = module:get_option_string("muc_webchat_baseurl", nil);
 
-local function get_webchat_url(room)
-	local webchat_url = room._data.webchat_url;
-	if webchat_url then -- explicitly configured
-		return webchat_url;
-	end
+local function get_default_url(room)
 	if not webchat_baseurl then
 		-- no template
 		return nil;
@@ -23,6 +19,13 @@
 		}));
 end
 
+local function get_webchat_url(room)
+	local webchat_url = room._data.webchat_url;
+	if webchat_url then -- explicitly configured
+		return webchat_url;
+	end
+end
+
 module:hook("muc-config-form", function(event)
 	local room, form = event.room, event.form;
 	table.insert(form, {
@@ -36,8 +39,12 @@
 module:hook("muc-config-submitted", function(event)
 	local room, fields, changed = event.room, event.fields, event.changed;
 	local new = fields["muc#roomconfig_webchat_url"];
-	if new ~= room._data.webchat_url then
-		room._data.webchat_url = new;
+	if new ~= get_webchat_url(room) then
+		if new == get_default_url(room) then
+			room._data.webchat_url = nil;
+		else
+			room._data.webchat_url = new;
+		end
 		if type(changed) == "table" then
 			changed["muc#roomconfig_webchat_url"] = true;
 		else