comparison mod_mam/mod_mam.lua @ 1187:d677d1807bb0

mod_mam: Stamp outgoing messages with <archived> as well, but remove it after they should have passed through mod_carbons
author Kim Alvefur <zash@zash.se>
date Thu, 05 Sep 2013 15:48:37 +0200
parents a172e7389cf6
children 853a382c9bd6
comparison
equal deleted inserted replaced
1186:a172e7389cf6 1187:d677d1807bb0
200 if shall_store(store_user, with) then 200 if shall_store(store_user, with) then
201 module:log("debug", "Archiving stanza: %s", stanza:top_tag()); 201 module:log("debug", "Archiving stanza: %s", stanza:top_tag());
202 202
203 -- And stash it 203 -- And stash it
204 local ok, id = archive:append(store_user, time_now(), with, stanza); 204 local ok, id = archive:append(store_user, time_now(), with, stanza);
205 if ok and not c2s then 205 if ok then
206 stanza:tag("archived", { xmlns = xmlns_mam, by = store_user.."@"..host, id = id }):up(); 206 stanza:tag("archived", { xmlns = xmlns_mam, by = store_user.."@"..host, id = id }):up();
207 end 207 end
208 else 208 else
209 module:log("debug", "Not archiving stanza: %s (prefs)", stanza:top_tag()); 209 module:log("debug", "Not archiving stanza: %s (prefs)", stanza:top_tag());
210 end 210 end
219 module:hook("pre-message/full", c2s_message_handler, 2); 219 module:hook("pre-message/full", c2s_message_handler, 2);
220 -- Stanszas to local clients 220 -- Stanszas to local clients
221 module:hook("message/bare", message_handler, 2); 221 module:hook("message/bare", message_handler, 2);
222 module:hook("message/full", message_handler, 2); 222 module:hook("message/full", message_handler, 2);
223 223
224 local function post_carbons_handler(event)
225 event.stanza:maptags(function(tag)
226 if not ( tag.attr.xmlns == xmlns_mam and tag.name == "archived" ) then
227 return tag;
228 end
229 end);
230 end
231
232 module:hook("pre-message/bare", post_carbons_handler, 0.9);
233 module:hook("pre-message/full", post_carbons_handler, 0.9);
234
224 module:add_feature(xmlns_mam); 235 module:add_feature(xmlns_mam);
225 236