Mercurial > prosody-modules
diff 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 |
line wrap: on
line diff
--- a/mod_mam_muc/mod_mam_muc.lua Tue Mar 21 04:18:23 2017 +0100 +++ b/mod_mam_muc/mod_mam_muc.lua Tue Mar 21 04:26:00 2017 +0100 @@ -8,15 +8,17 @@ return; end -local xmlns_mam = "urn:xmpp:mam:1"; +local xmlns_mam = "urn:xmpp:mam:2"; local xmlns_delay = "urn:xmpp:delay"; local xmlns_forward = "urn:xmpp:forward:0"; +local xmlns_st_id = "urn:xmpp:sid:0"; local muc_form_enable_logging = "muc#roomconfig_enablelogging" local st = require "util.stanza"; local rsm = require "util.rsm"; local jid_bare = require "util.jid".bare; local jid_split = require "util.jid".split; +local jid_prep = require "util.jid".prep; local dataform = require "util.dataforms".new; local it = require"util.iterators"; @@ -351,7 +353,16 @@ -- Handle messages function save_to_history(self, stanza) - local room_node = jid_split(self.jid); + local room_node, room_host = jid_split(self.jid); + + -- Filter out <stanza-id> that claim to be from us + stanza:maptags(function (tag) + if tag.name == "stanza-id" and tag.attr.xmlns == xmlns_st_id + and jid_prep(tag.attr.by) == self.jid then + return nil; + end + return tag; + end); -- Policy check if not logging_enabled(self) then return end -- Don't log @@ -361,7 +372,12 @@ if stanza.attr.type then with = with .. "<" .. stanza.attr.type end - archive:append(room_node, nil, stanza, time_now(), with); + + local id = archive:append(room_node, nil, stanza, time_now(), with); + + if id then + stanza:add_direct_child(st.stanza("stanza-id", { xmlns = xmlns_st_id, by = self.jid, id = id })); + end end module:hook("muc-broadcast-message", function (event)