Software /
code /
prosody-modules
Comparison
mod_muc_log/mod_muc_log.lua @ 1104:34c86e4d6c9d
mod_muc_log: Add a room config option for logging
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 10 Jul 2013 12:41:32 +0200 |
parent | 1050:a0aff903659b |
child | 1105:7837a5f7c10d |
comparison
equal
deleted
inserted
replaced
1103:59657e03c25c | 1104:34c86e4d6c9d |
---|---|
6 local datamanager = require "util.datamanager"; | 6 local datamanager = require "util.datamanager"; |
7 local data_load, data_store, data_getpath = datamanager.load, datamanager.store, datamanager.getpath; | 7 local data_load, data_store, data_getpath = datamanager.load, datamanager.store, datamanager.getpath; |
8 local datastore = "muc_log"; | 8 local datastore = "muc_log"; |
9 local error_reply = require "util.stanza".error_reply; | 9 local error_reply = require "util.stanza".error_reply; |
10 local storagemanager = storagemanager; | 10 local storagemanager = storagemanager; |
11 local muc_form_config_option = "muc#roomconfig_enablelogging" | |
11 | 12 |
12 local mod_host = module:get_host(); | 13 local mod_host = module:get_host(); |
13 local log_presences = module:get_option_boolean("muc_log_presences", false); | 14 local log_presences = module:get_option_boolean("muc_log_presences", false); |
14 | 15 |
15 -- Helper Functions | 16 -- Helper Functions |
115 end | 116 end |
116 end | 117 end |
117 end | 118 end |
118 end | 119 end |
119 | 120 |
121 module:hook("muc-config-form", function(event) | |
122 local room, form = event.room, event.form; | |
123 table.insert(form, | |
124 { | |
125 name = muc_form_config_option, | |
126 type = "boolean", | |
127 label = "Enable Logging?", | |
128 value = room._data.logging or false, | |
129 } | |
130 ); | |
131 end); | |
132 | |
133 module:hook("muc-config-submitted", function(event) | |
134 local room, fields, changed = event.room, event.fields, event.changed; | |
135 local new = fields[muc_form_config_option]; | |
136 if new ~= room._data.logging then | |
137 room._data.logging = new; | |
138 if type(changed) == "table" then | |
139 changed[muc_form_config_option] = true; | |
140 else | |
141 event.changed = true; | |
142 end | |
143 end | |
144 end); | |
145 | |
120 module:hook("message/bare", log_if_needed, 1); | 146 module:hook("message/bare", log_if_needed, 1); |
121 if log_presences then | 147 if log_presences then |
122 module:hook("iq/bare", log_if_needed, 1); | 148 module:hook("iq/bare", log_if_needed, 1); |
123 module:hook("presence/full", log_if_needed, 1); | 149 module:hook("presence/full", log_if_needed, 1); |
124 end | 150 end |