]> granicus.if.org Git - ejabberd/commitdiff
mod_mam: Strip existing JID tags from MUC messages
authorHolger Weiss <holger@zedat.fu-berlin.de>
Mon, 18 Jan 2016 23:39:10 +0000 (00:39 +0100)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Mon, 18 Jan 2016 23:39:10 +0000 (00:39 +0100)
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.

src/mod_mam.erl

index ff362539387dd5080cf9469f5b57f17a9189cc7c..88206716c32c31ce9949a523d4ed27a1067e7a7b 100644 (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,