From 5e4ed4266d82f58c99614c0e6d914c09c07113b9 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Tue, 19 Jan 2016 00:39:10 +0100 Subject: [PATCH] mod_mam: Strip existing JID tags from MUC messages Strip any pre-existing tags which have an child with a 'jid' attribute from MUC MAM messages. This way, if such a tag exists, clients can be sure it was added by mod_mam. --- src/mod_mam.erl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/mod_mam.erl b/src/mod_mam.erl index ff3625393..88206716c 100644 --- a/src/mod_mam.erl +++ b/src/mod_mam.erl @@ -241,7 +241,8 @@ muc_filter_message(Pkt, #state{config = Config} = MUCState, if Config#config.mam -> LServer = RoomJID#jid.lserver, NewPkt = strip_my_archived_tag(Pkt, LServer), - case store_muc(MUCState, NewPkt, RoomJID, From, FromNick) of + StorePkt = strip_x_jid_tags(NewPkt), + case store_muc(MUCState, StorePkt, RoomJID, From, FromNick) of {ok, ID} -> Archived = #xmlel{name = <<"archived">>, attrs = [{<<"by">>, LServer}, @@ -606,6 +607,18 @@ strip_my_archived_tag(Pkt, LServer) -> end, Pkt#xmlel.children), Pkt#xmlel{children = NewEls}. +strip_x_jid_tags(Pkt) -> + NewEls = lists:filter( + fun(#xmlel{name = <<"x">>} = XEl) -> + not lists:any(fun(ItemEl) -> + xml:get_tag_attr(<<"jid">>, ItemEl) + /= false + end, xml:get_subtags(XEl, <<"item">>)); + (_) -> + true + end, Pkt#xmlel.children), + Pkt#xmlel{children = NewEls}. + should_archive_peer(C2SState, #archive_prefs{default = Default, always = Always,