changeset 1544:814398c7139b

mod_muc_log: Add option to log rooms by default unless changed in room config
author Kim Alvefur <zash@zash.se>
date Mon, 03 Nov 2014 20:37:33 +0100
parents 57fb9ce21f9c
children a104a159697d
files mod_muc_log/mod_muc_log.lua
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_log/mod_muc_log.lua	Thu Oct 30 12:43:00 2014 +0100
+++ b/mod_muc_log/mod_muc_log.lua	Mon Nov 03 20:37:33 2014 +0100
@@ -12,6 +12,7 @@
 local datastore = "muc_log";
 local muc_form_config_option = "muc#roomconfig_enablelogging"
 
+local log_by_default = module:get_option_boolean("muc_log_by_default", false);
 local log_presences = module:get_option_boolean("muc_log_presences", true);
 
 -- Module Definitions
@@ -33,6 +34,14 @@
 	end
 end
 
+local function logging_enabled(room)
+	local enabled = room._data.logging;
+	if enabled == nil then
+		return log_by_default;
+	end
+	return enabled;
+end
+
 function log_if_needed(event)
 	local stanza = event.stanza;
 
@@ -56,7 +65,7 @@
 				if room._data.hidden then -- do not log any data of private rooms
 					return;
 				end
-				if not room._data.logging then -- do not log where logging is not enabled
+				if not logging_enabled(room) then -- do not log where logging is not enabled
 					return;
 				end
 
@@ -129,7 +138,7 @@
 		name = muc_form_config_option,
 		type = "boolean",
 		label = "Enable Logging?",
-		value = room._data.logging or false,
+		value = logging_enabled(room),
 	}
 	);
 end);