25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

mod_mam: Strip existing JID tags from MUC messages

Strip any pre-existing <x/> tags which have an <item/> 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.
This commit is contained in:
Holger Weiss 2016-01-19 00:39:10 +01:00
parent 3feceb8279
commit 5e4ed4266d

View File

@ -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,