Software /
code /
prosody-modules
Changeset
1542:ccb9dc624ebd
mod_mam_muc: Split logic for determining if logging is enabled into a function
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 30 Oct 2014 12:39:57 +0100 |
parents | 1541:ef032840bc92 |
children | 1543:57fb9ce21f9c |
files | mod_mam_muc/mod_mam_muc.lua |
diffstat | 1 files changed, 15 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_mam_muc/mod_mam_muc.lua Wed Oct 29 12:37:26 2014 +0100 +++ b/mod_mam_muc/mod_mam_muc.lua Thu Oct 30 12:39:57 2014 +0100 @@ -43,12 +43,23 @@ return end +local function logging_enabled(room) + if log_all_rooms then + return true; + end + local enabled = room._data.logging; + if enabled == nil then + return log_by_default; + end + return enabled; +end + local send_history, save_to_history; -- Override history methods for all rooms. module:hook("muc-room-created", function (event) local room = event.room; - if log_all_rooms or room._data.logging then + if logging_enabled(room) then room.send_history = send_history; room.save_to_history = save_to_history; end @@ -56,7 +67,7 @@ function module.load() for _, room in pairs(rooms) do - if log_all_rooms or room._data.logging then + if logging_enabled(room) then room.send_history = send_history; room.save_to_history = save_to_history; end @@ -74,16 +85,12 @@ if not log_all_rooms then module:hook("muc-config-form", function(event) local room, form = event.room, event.form; - local logging_enabled = room._data.logging; - if logging_enabled == nil then - logging_enabled = log_by_default; - end table.insert(form, { name = muc_form_enable_logging, type = "boolean", label = "Enable Logging?", - value = logging_enabled, + value = logging_enabled(room), } ); end); @@ -276,9 +283,7 @@ local room = jid_split(self.jid); -- Policy check - if not ( log_all_rooms == true -- Logging forced on all rooms - or (self._data.logging == nil and log_by_default == true) - or self._data.logging ) then return end -- Don't log + if not logging_enabled(self) then return end -- Don't log module:log("debug", "We're logging this") -- And stash it