Mercurial > prosody-modules
comparison mod_muc_log/mod_muc_log.lua @ 1133:11e2598baafb
mod_muc_log: Use old datamanager directly, instead of hacking storagemanager
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 10 Aug 2013 17:25:21 +0200 |
| parents | 7837a5f7c10d |
| children | 0664f8b783fd |
comparison
equal
deleted
inserted
replaced
| 1132:832235cc1910 | 1133:11e2598baafb |
|---|---|
| 1 local prosody = prosody; | 1 local prosody = prosody; |
| 2 local hosts = prosody.hosts; | 2 local hosts = prosody.hosts; |
| 3 local tostring = tostring; | 3 local tostring = tostring; |
| 4 local split_jid = require "util.jid".split; | 4 local split_jid = require "util.jid".split; |
| 5 local cm = require "core.configmanager"; | 5 local cm = require "core.configmanager"; |
| 6 local datamanager = require "util.datamanager"; | 6 local storagemanager = storagemanager; |
| 7 local datamanager = storagemanager.olddm; | |
| 7 local data_load, data_store, data_getpath = datamanager.load, datamanager.store, datamanager.getpath; | 8 local data_load, data_store, data_getpath = datamanager.load, datamanager.store, datamanager.getpath; |
| 8 local datastore = "muc_log"; | 9 local datastore = "muc_log"; |
| 9 local error_reply = require "util.stanza".error_reply; | 10 local error_reply = require "util.stanza".error_reply; |
| 10 local storagemanager = storagemanager; | |
| 11 local muc_form_config_option = "muc#roomconfig_enablelogging" | 11 local muc_form_config_option = "muc#roomconfig_enablelogging" |
| 12 | 12 |
| 13 local mod_host = module:get_host(); | 13 local mod_host = module:get_host(); |
| 14 local log_presences = module:get_option_boolean("muc_log_presences", true); | 14 local log_presences = module:get_option_boolean("muc_log_presences", true); |
| 15 | |
| 16 -- Helper Functions | |
| 17 | |
| 18 local function inject_storage_config() | |
| 19 local _storage = cm.getconfig()[mod_host].storage; | |
| 20 | |
| 21 module:log("debug", "injecting storage config..."); | |
| 22 if type(_storage) == "string" then cm.getconfig()[mod_host].default_storage = _storage; end | |
| 23 if type(_storage) == "table" then -- append | |
| 24 _storage.muc_log = "internal"; | |
| 25 else | |
| 26 cm.getconfig()[mod_host].storage = { muc_log = "internal" }; | |
| 27 end | |
| 28 | |
| 29 storagemanager.get_driver(mod_host, "muc_log"); -- init | |
| 30 end | |
| 31 | 15 |
| 32 -- Module Definitions | 16 -- Module Definitions |
| 33 | 17 |
| 34 function log_if_needed(e) | 18 function log_if_needed(e) |
| 35 local stanza, origin = e.stanza, e.origin; | 19 local stanza, origin = e.stanza, e.origin; |
| 147 if log_presences then | 131 if log_presences then |
| 148 module:hook("iq/bare", log_if_needed, 1); | 132 module:hook("iq/bare", log_if_needed, 1); |
| 149 module:hook("presence/full", log_if_needed, 1); | 133 module:hook("presence/full", log_if_needed, 1); |
| 150 end | 134 end |
| 151 | 135 |
| 152 local function reload() | |
| 153 inject_storage_config(); | |
| 154 end | |
| 155 | |
| 156 function module.load() | |
| 157 inject_storage_config(); | |
| 158 end | |
| 159 | |
| 160 module:log("debug", "module mod_muc_log loaded!"); | 136 module:log("debug", "module mod_muc_log loaded!"); |
