Comparison

mod_mam/mod_mam.lua @ 2760:7c2416a1eb94

mod_mam: Clone stanzas before mutating (thanks waqas) (fixes #961)
author Kim Alvefur <zash@zash.se>
date Sun, 03 Sep 2017 00:35:31 +0200
parent 2725:210c3a7644cb
child 2761:b13d07613b80
comparison
equal deleted inserted replaced
2759:4bf60727459b 2760:7c2416a1eb94
274 local store_user = c2s and origin.username or jid_split(orig_to); 274 local store_user = c2s and origin.username or jid_split(orig_to);
275 -- And who are they chatting with? 275 -- And who are they chatting with?
276 local with = jid_bare(c2s and orig_to or orig_from); 276 local with = jid_bare(c2s and orig_to or orig_from);
277 277
278 -- Filter out <stanza-id> that claim to be from us 278 -- Filter out <stanza-id> that claim to be from us
279 stanza:maptags(function (tag) 279 if stanza:get_child("stanza-id", xmlns_st_id) then
280 if tag.name == "stanza-id" and tag.attr.xmlns == xmlns_st_id then 280 stanza = st.clone(stanza);
281 local by_user, by_host, res = jid_prepped_split(tag.attr.by); 281 stanza:maptags(function (tag)
282 if not res and by_host == module.host and by_user == store_user then 282 if tag.name == "stanza-id" and tag.attr.xmlns == xmlns_st_id then
283 return nil; 283 local by_user, by_host, res = jid_prepped_split(tag.attr.by);
284 if not res and by_host == module.host and by_user == store_user then
285 return nil;
286 end
284 end 287 end
285 end 288 return tag;
286 return tag; 289 end);
287 end); 290 event.stanza = stanza;
291 end
288 292
289 -- We store chat messages or normal messages that have a body 293 -- We store chat messages or normal messages that have a body
290 if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then 294 if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body")) ) then
291 log("debug", "Not archiving stanza: %s (type)", stanza:top_tag()); 295 log("debug", "Not archiving stanza: %s (type)", stanza:top_tag());
292 return; 296 return;
306 log("debug", "Archiving stanza: %s", stanza:top_tag()); 310 log("debug", "Archiving stanza: %s", stanza:top_tag());
307 311
308 -- And stash it 312 -- And stash it
309 local ok = archive:append(store_user, nil, stanza, time_now(), with); 313 local ok = archive:append(store_user, nil, stanza, time_now(), with);
310 if ok then 314 if ok then
315 local clone_for_other_handlers = st.clone(stanza);
311 local id = ok; 316 local id = ok;
312 stanza:tag("stanza-id", { xmlns = xmlns_st_id, by = store_user.."@"..host, id = id }):up(); 317 clone_for_other_handlers:tag("stanza-id", { xmlns = xmlns_st_id, by = store_user.."@"..host, id = id }):up();
318 event.stanza = clone_for_other_handlers;
313 if cleanup then cleanup[store_user] = true; end 319 if cleanup then cleanup[store_user] = true; end
314 module:fire_event("archive-message-added", { origin = origin, stanza = stanza, for_user = store_user, id = id }); 320 module:fire_event("archive-message-added", { origin = origin, stanza = clone_for_storage, for_user = store_user, id = id });
315 end 321 end
316 else 322 else
317 log("debug", "Not archiving stanza: %s (prefs)", stanza:top_tag()); 323 log("debug", "Not archiving stanza: %s (prefs)", stanza:top_tag());
318 end 324 end
319 end 325 end