comparison mod_mam_muc/mod_mam_muc.lua @ 1142:fabdaa0d99e3

mod_mam_muc: Stap archived messages
author Kim Alvefur <zash@zash.se>
date Sat, 10 Aug 2013 21:17:12 +0200
parents 1091be1c3aba
children 8098683b6d6f
comparison
equal deleted inserted replaced
1141:1091be1c3aba 1142:fabdaa0d99e3
20 local tostring = tostring; 20 local tostring = tostring;
21 local time_now = os.time; 21 local time_now = os.time;
22 local m_min = math.min; 22 local m_min = math.min;
23 local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse; 23 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); 24 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50);
25
26 local advertise_archive = module:get_option_boolean("muc_log_advertise", true);
25 27
26 local archive = module:open_store("archive2", "archive"); 28 local archive = module:open_store("archive2", "archive");
27 local rooms = hosts[module.host].modules.muc.rooms; 29 local rooms = hosts[module.host].modules.muc.rooms;
28 30
29 -- Handle archive queries 31 -- Handle archive queries
131 local nick = room_obj._jid_nick[orig_from]; 133 local nick = room_obj._jid_nick[orig_from];
132 if not nick then return end -- Message from someone not in the room? 134 if not nick then return end -- Message from someone not in the room?
133 135
134 stanza.attr.from = nick; 136 stanza.attr.from = nick;
135 -- And stash it 137 -- And stash it
136 archive:append(room, time_now(), "", stanza); 138 local ok, id = archive:append(room, time_now(), "", stanza);
137 stanza.attr.from = orig_from; 139 stanza.attr.from = orig_from;
140 if ok and advertise_archive then
141 stanza:tag("archived", { xmlns = xmlns_mam, by = jid_bare(orig_to), id = id }):up();
142 end
138 end 143 end
139 144
140 module:hook("message/bare", message_handler, 2); 145 module:hook("message/bare", message_handler, 2);
141 146
142 -- TODO should we perhaps log presence as well? 147 -- TODO should we perhaps log presence as well?