Mercurial > prosody-modules
comparison mod_mam_muc/mod_mam_muc.lua @ 2627:3f166242b460
mod_mam_muc: Add stanza-id tags (updates to XEP-0313 v0.6)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 21 Mar 2017 04:26:00 +0100 |
parents | 17883c405df3 |
children | fbb26a56a667 |
comparison
equal
deleted
inserted
replaced
2626:17883c405df3 | 2627:3f166242b460 |
---|---|
6 if module:get_host_type() ~= "component" then | 6 if module:get_host_type() ~= "component" then |
7 module:log("error", "mod_%s should be loaded only on a MUC component, not normal hosts", module.name); | 7 module:log("error", "mod_%s should be loaded only on a MUC component, not normal hosts", module.name); |
8 return; | 8 return; |
9 end | 9 end |
10 | 10 |
11 local xmlns_mam = "urn:xmpp:mam:1"; | 11 local xmlns_mam = "urn:xmpp:mam:2"; |
12 local xmlns_delay = "urn:xmpp:delay"; | 12 local xmlns_delay = "urn:xmpp:delay"; |
13 local xmlns_forward = "urn:xmpp:forward:0"; | 13 local xmlns_forward = "urn:xmpp:forward:0"; |
14 local xmlns_st_id = "urn:xmpp:sid:0"; | |
14 local muc_form_enable_logging = "muc#roomconfig_enablelogging" | 15 local muc_form_enable_logging = "muc#roomconfig_enablelogging" |
15 | 16 |
16 local st = require "util.stanza"; | 17 local st = require "util.stanza"; |
17 local rsm = require "util.rsm"; | 18 local rsm = require "util.rsm"; |
18 local jid_bare = require "util.jid".bare; | 19 local jid_bare = require "util.jid".bare; |
19 local jid_split = require "util.jid".split; | 20 local jid_split = require "util.jid".split; |
21 local jid_prep = require "util.jid".prep; | |
20 local dataform = require "util.dataforms".new; | 22 local dataform = require "util.dataforms".new; |
21 local it = require"util.iterators"; | 23 local it = require"util.iterators"; |
22 | 24 |
23 -- Support both old and new MUC code | 25 -- Support both old and new MUC code |
24 local mod_muc = module:depends"muc"; | 26 local mod_muc = module:depends"muc"; |
349 end | 351 end |
350 end | 352 end |
351 | 353 |
352 -- Handle messages | 354 -- Handle messages |
353 function save_to_history(self, stanza) | 355 function save_to_history(self, stanza) |
354 local room_node = jid_split(self.jid); | 356 local room_node, room_host = jid_split(self.jid); |
357 | |
358 -- Filter out <stanza-id> that claim to be from us | |
359 stanza:maptags(function (tag) | |
360 if tag.name == "stanza-id" and tag.attr.xmlns == xmlns_st_id | |
361 and jid_prep(tag.attr.by) == self.jid then | |
362 return nil; | |
363 end | |
364 return tag; | |
365 end); | |
355 | 366 |
356 -- Policy check | 367 -- Policy check |
357 if not logging_enabled(self) then return end -- Don't log | 368 if not logging_enabled(self) then return end -- Don't log |
358 | 369 |
359 -- And stash it | 370 -- And stash it |
360 local with = stanza.name | 371 local with = stanza.name |
361 if stanza.attr.type then | 372 if stanza.attr.type then |
362 with = with .. "<" .. stanza.attr.type | 373 with = with .. "<" .. stanza.attr.type |
363 end | 374 end |
364 archive:append(room_node, nil, stanza, time_now(), with); | 375 |
376 local id = archive:append(room_node, nil, stanza, time_now(), with); | |
377 | |
378 if id then | |
379 stanza:add_direct_child(st.stanza("stanza-id", { xmlns = xmlns_st_id, by = self.jid, id = id })); | |
380 end | |
365 end | 381 end |
366 | 382 |
367 module:hook("muc-broadcast-message", function (event) | 383 module:hook("muc-broadcast-message", function (event) |
368 local room, stanza = event.room, event.stanza; | 384 local room, stanza = event.room, event.stanza; |
369 if stanza:get_child("body") then | 385 if stanza:get_child("body") then |