Comparison

plugins/mod_mam/mod_mam.lua @ 7890:9e4de27e8e08

mod_mam: Move stanza ID namespace to a common variable
author Kim Alvefur <zash@zash.se>
date Tue, 14 Feb 2017 18:51:20 +0100
parent 7882:1017a4f8929d
child 7891:01d2a2af3146
comparison
equal deleted inserted replaced
7889:b8d694646597 7890:9e4de27e8e08
10 -- 10 --
11 11
12 local xmlns_mam = "urn:xmpp:mam:1"; 12 local xmlns_mam = "urn:xmpp:mam:1";
13 local xmlns_delay = "urn:xmpp:delay"; 13 local xmlns_delay = "urn:xmpp:delay";
14 local xmlns_forward = "urn:xmpp:forward:0"; 14 local xmlns_forward = "urn:xmpp:forward:0";
15 local xmlns_st_id = "urn:xmpp:sid:0";
15 16
16 local um = require "core.usermanager"; 17 local um = require "core.usermanager";
17 local st = require "util.stanza"; 18 local st = require "util.stanza";
18 local rsm = require "util.rsm"; 19 local rsm = require "util.rsm";
19 local get_prefs = module:require"mamprefs".get; 20 local get_prefs = module:require"mamprefs".get;
246 -- And who are they chatting with? 247 -- And who are they chatting with?
247 local with = jid_bare(c2s and orig_to or orig_from); 248 local with = jid_bare(c2s and orig_to or orig_from);
248 249
249 -- Filter out <stanza-id> that claim to be from us 250 -- Filter out <stanza-id> that claim to be from us
250 stanza:maptags(function (tag) 251 stanza:maptags(function (tag)
251 if tag.name == "stanza-id" and tag.attr.xmlns == "urn:xmpp:sid:0" then 252 if tag.name == "stanza-id" and tag.attr.xmlns == xmlns_st_id then
252 local by_user, by_host, res = jid_prepped_split(tag.attr.by); 253 local by_user, by_host, res = jid_prepped_split(tag.attr.by);
253 if not res and by_host == module.host and by_user == store_user then 254 if not res and by_host == module.host and by_user == store_user then
254 return nil; 255 return nil;
255 end 256 end
256 end 257 end
291 log("debug", "Archiving stanza: %s", stanza:top_tag()); 292 log("debug", "Archiving stanza: %s", stanza:top_tag());
292 293
293 -- And stash it 294 -- And stash it
294 local ok, id = archive:append(store_user, nil, stanza, time_now(), with); 295 local ok, id = archive:append(store_user, nil, stanza, time_now(), with);
295 if ok then 296 if ok then
296 stanza:tag("stanza-id", { xmlns = "urn:xmpp:sid:0", by = store_user.."@"..host, id = id }):up(); 297 stanza:tag("stanza-id", { xmlns = xmlns_st_id, by = store_user.."@"..host, id = id }):up();
297 if cleanup then cleanup[store_user] = true; end 298 if cleanup then cleanup[store_user] = true; end
298 module:fire_event("archive-message-added", { origin = origin, stanza = stanza, for_user = store_user, id = id }); 299 module:fire_event("archive-message-added", { origin = origin, stanza = stanza, for_user = store_user, id = id });
299 end 300 end
300 else 301 else
301 log("debug", "Not archiving stanza: %s (prefs)", stanza:top_tag()); 302 log("debug", "Not archiving stanza: %s (prefs)", stanza:top_tag());