Software /
code /
prosody-modules
Comparison
mod_muc_log/mod_muc_log.lua @ 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 |
parent | 1450:5107278268ae |
child | 1567:585bb8ac11bb |
comparison
equal
deleted
inserted
replaced
1543:57fb9ce21f9c | 1544:814398c7139b |
---|---|
10 local datamanager = require"core.storagemanager".olddm; | 10 local datamanager = require"core.storagemanager".olddm; |
11 local data_load, data_store = datamanager.load, datamanager.store; | 11 local data_load, data_store = datamanager.load, datamanager.store; |
12 local datastore = "muc_log"; | 12 local datastore = "muc_log"; |
13 local muc_form_config_option = "muc#roomconfig_enablelogging" | 13 local muc_form_config_option = "muc#roomconfig_enablelogging" |
14 | 14 |
15 local log_by_default = module:get_option_boolean("muc_log_by_default", false); | |
15 local log_presences = module:get_option_boolean("muc_log_presences", true); | 16 local log_presences = module:get_option_boolean("muc_log_presences", true); |
16 | 17 |
17 -- Module Definitions | 18 -- Module Definitions |
18 | 19 |
19 local function get_room_from_jid(jid) | 20 local function get_room_from_jid(jid) |
29 return muc.get_room_from_jid(jid); | 30 return muc.get_room_from_jid(jid); |
30 else | 31 else |
31 return | 32 return |
32 end | 33 end |
33 end | 34 end |
35 end | |
36 | |
37 local function logging_enabled(room) | |
38 local enabled = room._data.logging; | |
39 if enabled == nil then | |
40 return log_by_default; | |
41 end | |
42 return enabled; | |
34 end | 43 end |
35 | 44 |
36 function log_if_needed(event) | 45 function log_if_needed(event) |
37 local stanza = event.stanza; | 46 local stanza = event.stanza; |
38 | 47 |
54 local already_joined = false; | 63 local already_joined = false; |
55 | 64 |
56 if room._data.hidden then -- do not log any data of private rooms | 65 if room._data.hidden then -- do not log any data of private rooms |
57 return; | 66 return; |
58 end | 67 end |
59 if not room._data.logging then -- do not log where logging is not enabled | 68 if not logging_enabled(room) then -- do not log where logging is not enabled |
60 return; | 69 return; |
61 end | 70 end |
62 | 71 |
63 if stanza.name == "presence" and stanza.attr.type == nil then | 72 if stanza.name == "presence" and stanza.attr.type == nil then |
64 muc_from = stanza.attr.to; | 73 muc_from = stanza.attr.to; |
127 table.insert(form, | 136 table.insert(form, |
128 { | 137 { |
129 name = muc_form_config_option, | 138 name = muc_form_config_option, |
130 type = "boolean", | 139 type = "boolean", |
131 label = "Enable Logging?", | 140 label = "Enable Logging?", |
132 value = room._data.logging or false, | 141 value = logging_enabled(room), |
133 } | 142 } |
134 ); | 143 ); |
135 end); | 144 end); |
136 | 145 |
137 module:hook("muc-config-submitted", function(event) | 146 module:hook("muc-config-submitted", function(event) |