Software /
code /
prosody-modules
Comparison
mod_mam_muc/mod_mam_muc.lua @ 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 |
parent | 1541:ef032840bc92 |
child | 1543:57fb9ce21f9c |
comparison
equal
deleted
inserted
replaced
1541:ef032840bc92 | 1542:ccb9dc624ebd |
---|---|
41 elseif not archive.find then | 41 elseif not archive.find then |
42 module:log("error", "mod_%s does not support archiving, switch to mod_storage_sql2", archive._provided_by); | 42 module:log("error", "mod_%s does not support archiving, switch to mod_storage_sql2", archive._provided_by); |
43 return | 43 return |
44 end | 44 end |
45 | 45 |
46 local function logging_enabled(room) | |
47 if log_all_rooms then | |
48 return true; | |
49 end | |
50 local enabled = room._data.logging; | |
51 if enabled == nil then | |
52 return log_by_default; | |
53 end | |
54 return enabled; | |
55 end | |
56 | |
46 local send_history, save_to_history; | 57 local send_history, save_to_history; |
47 | 58 |
48 -- Override history methods for all rooms. | 59 -- Override history methods for all rooms. |
49 module:hook("muc-room-created", function (event) | 60 module:hook("muc-room-created", function (event) |
50 local room = event.room; | 61 local room = event.room; |
51 if log_all_rooms or room._data.logging then | 62 if logging_enabled(room) then |
52 room.send_history = send_history; | 63 room.send_history = send_history; |
53 room.save_to_history = save_to_history; | 64 room.save_to_history = save_to_history; |
54 end | 65 end |
55 end); | 66 end); |
56 | 67 |
57 function module.load() | 68 function module.load() |
58 for _, room in pairs(rooms) do | 69 for _, room in pairs(rooms) do |
59 if log_all_rooms or room._data.logging then | 70 if logging_enabled(room) then |
60 room.send_history = send_history; | 71 room.send_history = send_history; |
61 room.save_to_history = save_to_history; | 72 room.save_to_history = save_to_history; |
62 end | 73 end |
63 end | 74 end |
64 end | 75 end |
72 end | 83 end |
73 | 84 |
74 if not log_all_rooms then | 85 if not log_all_rooms then |
75 module:hook("muc-config-form", function(event) | 86 module:hook("muc-config-form", function(event) |
76 local room, form = event.room, event.form; | 87 local room, form = event.room, event.form; |
77 local logging_enabled = room._data.logging; | |
78 if logging_enabled == nil then | |
79 logging_enabled = log_by_default; | |
80 end | |
81 table.insert(form, | 88 table.insert(form, |
82 { | 89 { |
83 name = muc_form_enable_logging, | 90 name = muc_form_enable_logging, |
84 type = "boolean", | 91 type = "boolean", |
85 label = "Enable Logging?", | 92 label = "Enable Logging?", |
86 value = logging_enabled, | 93 value = logging_enabled(room), |
87 } | 94 } |
88 ); | 95 ); |
89 end); | 96 end); |
90 | 97 |
91 module:hook("muc-config-submitted", function(event) | 98 module:hook("muc-config-submitted", function(event) |
274 function save_to_history(self, stanza) | 281 function save_to_history(self, stanza) |
275 local orig_to = stanza.attr.to; | 282 local orig_to = stanza.attr.to; |
276 local room = jid_split(self.jid); | 283 local room = jid_split(self.jid); |
277 | 284 |
278 -- Policy check | 285 -- Policy check |
279 if not ( log_all_rooms == true -- Logging forced on all rooms | 286 if not logging_enabled(self) then return end -- Don't log |
280 or (self._data.logging == nil and log_by_default == true) | |
281 or self._data.logging ) then return end -- Don't log | |
282 | 287 |
283 module:log("debug", "We're logging this") | 288 module:log("debug", "We're logging this") |
284 -- And stash it | 289 -- And stash it |
285 local with = stanza.name | 290 local with = stanza.name |
286 if stanza.attr.type then | 291 if stanza.attr.type then |