diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2016-01-19 02:39:10 +0300 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2016-01-19 02:39:10 +0300 |
commit | 5e4ed4266d82f58c99614c0e6d914c09c07113b9 (patch) | |
tree | da0b88cff1a62288483c27f786d1ea219b2b3a65 /src/mod_mam.erl | |
parent | 3feceb82797543f363fc8aa8f5b460667df380ad (diff) |
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.
Diffstat (limited to 'src/mod_mam.erl')
-rw-r--r-- | src/mod_mam.erl | 15 |
1 files changed, 14 insertions, 1 deletions
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, |