Mercurial > prosody-modules
comparison mod_mam_muc/mod_mam_muc.lua @ 1143:8098683b6d6f
mod_mam_muc: Allow archiving to be enabled trough in the room configuration
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 10 Aug 2013 21:18:25 +0200 |
| parents | fabdaa0d99e3 |
| children | ccb0c5afe658 |
comparison
equal
deleted
inserted
replaced
| 1142:fabdaa0d99e3 | 1143:8098683b6d6f |
|---|---|
| 4 -- This file is MIT/X11 licensed. | 4 -- This file is MIT/X11 licensed. |
| 5 | 5 |
| 6 local xmlns_mam = "urn:xmpp:mam:tmp"; | 6 local xmlns_mam = "urn:xmpp:mam:tmp"; |
| 7 local xmlns_delay = "urn:xmpp:delay"; | 7 local xmlns_delay = "urn:xmpp:delay"; |
| 8 local xmlns_forward = "urn:xmpp:forward:0"; | 8 local xmlns_forward = "urn:xmpp:forward:0"; |
| 9 local muc_form_config_option = "muc#roomconfig_enablelogging" | |
| 9 | 10 |
| 10 local st = require "util.stanza"; | 11 local st = require "util.stanza"; |
| 11 local rsm = module:require "mod_mam/rsm"; | 12 local rsm = module:require "mod_mam/rsm"; |
| 12 local jid_bare = require "util.jid".bare; | 13 local jid_bare = require "util.jid".bare; |
| 13 local jid_split = require "util.jid".split; | 14 local jid_split = require "util.jid".split; |
| 21 local time_now = os.time; | 22 local time_now = os.time; |
| 22 local m_min = math.min; | 23 local m_min = math.min; |
| 23 local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse; | 24 local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse; |
| 24 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); | 25 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); |
| 25 | 26 |
| 27 local log_all_rooms = module:get_option_boolean("muc_log_all_rooms", false); | |
| 28 local log_by_default = module:get_option_boolean("muc_log_by_default", true); | |
| 26 local advertise_archive = module:get_option_boolean("muc_log_advertise", true); | 29 local advertise_archive = module:get_option_boolean("muc_log_advertise", true); |
| 27 | 30 |
| 28 local archive = module:open_store("archive2", "archive"); | 31 local archive = module:open_store("archive2", "archive"); |
| 29 local rooms = hosts[module.host].modules.muc.rooms; | 32 local rooms = hosts[module.host].modules.muc.rooms; |
| 33 | |
| 34 module:hook("muc-config-form", function(event) | |
| 35 local room, form = event.room, event.form; | |
| 36 table.insert(form, | |
| 37 { | |
| 38 name = muc_form_config_option, | |
| 39 type = "boolean", | |
| 40 label = "Enable Logging?", | |
| 41 value = room._data.logging or false, | |
| 42 } | |
| 43 ); | |
| 44 end); | |
| 45 | |
| 46 module:hook("muc-config-submitted", function(event) | |
| 47 local room, fields, changed = event.room, event.fields, event.changed; | |
| 48 local new = fields[muc_form_config_option]; | |
| 49 if new ~= room._data.logging then | |
| 50 room._data.logging = new; | |
| 51 if type(changed) == "table" then | |
| 52 changed[muc_form_config_option] = true; | |
| 53 else | |
| 54 event.changed = true; | |
| 55 end | |
| 56 end | |
| 57 end); | |
| 58 | |
| 30 | 59 |
| 31 -- Handle archive queries | 60 -- Handle archive queries |
| 32 module:hook("iq-get/bare/"..xmlns_mam..":query", function(event) | 61 module:hook("iq-get/bare/"..xmlns_mam..":query", function(event) |
| 33 local origin, stanza = event.origin, event.stanza; | 62 local origin, stanza = event.origin, event.stanza; |
| 34 local room = jid_split(stanza.attr.to); | 63 local room = jid_split(stanza.attr.to); |
| 128 | 157 |
| 129 local room = jid_split(orig_to); | 158 local room = jid_split(orig_to); |
| 130 local room_obj = rooms[orig_to] | 159 local room_obj = rooms[orig_to] |
| 131 if not room_obj then return end -- No such room | 160 if not room_obj then return end -- No such room |
| 132 | 161 |
| 162 if not ( log_all_rooms == true -- Logging forced on all rooms | |
| 163 or (room_obj._data.logging == nil and log_by_default == true) | |
| 164 or room_obj._data.logging ) then return end -- Don't log | |
| 165 | |
| 133 local nick = room_obj._jid_nick[orig_from]; | 166 local nick = room_obj._jid_nick[orig_from]; |
| 134 if not nick then return end -- Message from someone not in the room? | 167 if not nick then return end -- Message from someone not in the room? |
| 135 | 168 |
| 136 stanza.attr.from = nick; | 169 stanza.attr.from = nick; |
| 137 -- And stash it | 170 -- And stash it |
