]> granicus.if.org Git - ejabberd/commitdiff
mod_mam: Don't store resent messages
authorHolger Weiss <holger@zedat.fu-berlin.de>
Wed, 9 Dec 2015 21:44:45 +0000 (22:44 +0100)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Wed, 9 Dec 2015 21:44:45 +0000 (22:44 +0100)
Make sure messages that were resent by the stream management code aren't
stored in MAM.

src/mod_mam.erl

index b1801fd3244a533fba13838abee2d918b31d2327..7e2051057b6b4873c723274cb6cb897e69f49a7d 100644 (file)
@@ -363,18 +363,23 @@ should_archive(#xmlel{name = <<"message">>} = Pkt) ->
        <<"groupchat">> ->
            false;
        _ ->
-           case check_store_hint(Pkt) of
-               store ->
-                   true;
-               no_store ->
+           case is_resent(Pkt) of
+               true ->
                    false;
-               none ->
-                   case xml:get_subtag_cdata(Pkt, <<"body">>) of
-                       <<>> ->
-                           %% Empty body
+               false ->
+                   case check_store_hint(Pkt) of
+                       store ->
+                           true;
+                       no_store ->
                            false;
-                       _ ->
-                           true
+                       none ->
+                           case xml:get_subtag_cdata(Pkt, <<"body">>) of
+                               <<>> ->
+                                   %% Empty body
+                                   false;
+                               _ ->
+                                   true
+                           end
                    end
            end
     end;
@@ -458,6 +463,14 @@ has_no_store_hint(Message) ->
     xml:get_subtag_with_xmlns(Message, <<"no-permanent-storage">>, ?NS_HINTS)
       /= false.
 
+is_resent(Pkt) ->
+    case xml:get_subtag_cdata(Pkt, <<"delay">>) of
+       <<>> ->
+           false;
+       Desc ->
+           binary:match(Desc, <<"Resent">>) =/= nomatch
+    end.
+
 store_msg(C2SState, Pkt, LUser, LServer, Peer, Dir) ->
     Prefs = get_prefs(LUser, LServer),
     case should_archive_peer(C2SState, Prefs, Peer) of