]> granicus.if.org Git - ejabberd/commitdiff
Add <stanza-id/> (XEP-0359) to archived messages
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Tue, 22 Sep 2015 18:15:34 +0000 (21:15 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Tue, 22 Sep 2015 18:15:34 +0000 (21:15 +0300)
include/ns.hrl
src/mod_mam.erl

index 0685ae65c68a622a427edf69869abf2c7c5a37ff..85cf762effbf6634f336f5e04b16780285abf96e 100644 (file)
 -define(NS_MAM_TMP, <<"urn:xmpp:mam:tmp">>).
 -define(NS_MAM_0, <<"urn:xmpp:mam:0">>).
 -define(NS_MAM_1, <<"urn:xmpp:mam:1">>).
+-define(NS_SID_0, <<"urn:xmpp:sid:0">>).
 -define(NS_PING, <<"urn:xmpp:ping">>).
 -define(NS_CARBONS_2, <<"urn:xmpp:carbons:2">>).
 -define(NS_CARBONS_1, <<"urn:xmpp:carbons:1">>).
index cd9dd7e400d785c922a4b37f0d5ec986f14414e1..3e3e0873de33afe5ee79af7889f68b13c0a30335 100644 (file)
@@ -169,7 +169,11 @@ user_receive_packet(Pkt, C2SState, JID, Peer, _To) ->
                                       attrs = [{<<"by">>, LServer},
                                                {<<"xmlns">>, ?NS_MAM_TMP},
                                                {<<"id">>, ID}]},
-                    NewEls = [Archived|NewPkt#xmlel.children],
+                   StanzaID = #xmlel{name = <<"stanza-id">>,
+                                     attrs = [{<<"by">>, LServer},
+                                               {<<"xmlns">>, ?NS_SID_0},
+                                               {<<"id">>, ID}]},
+                    NewEls = [Archived, StanzaID|NewPkt#xmlel.children],
                     NewPkt#xmlel{children = NewEls};
                 _ ->
                     NewPkt
@@ -194,9 +198,19 @@ user_send_packet(Pkt, C2SState, JID, Peer) ->
 muc_filter_message(Pkt, #state{config = Config} = MUCState,
                   RoomJID, From, FromNick) ->
     if Config#config.mam ->
-           NewPkt = strip_my_archived_tag(Pkt, MUCState#state.server_host),
-           store_muc(MUCState, NewPkt, RoomJID, From, FromNick),
-           NewPkt;
+           By = jlib:jid_to_string(RoomJID),
+           NewPkt = strip_my_archived_tag(Pkt, By),
+           case store_muc(MUCState, NewPkt, RoomJID, From, FromNick) of
+               {ok, ID} ->
+                   StanzaID = #xmlel{name = <<"stanza-id">>,
+                                     attrs = [{<<"by">>, By},
+                                               {<<"xmlns">>, ?NS_SID_0},
+                                               {<<"id">>, ID}]},
+                    NewEls = [StanzaID|NewPkt#xmlel.children],
+                    NewPkt#xmlel{children = NewEls};
+               _ ->
+                   NewPkt
+           end;
        true ->
            Pkt
     end.
@@ -345,8 +359,8 @@ should_archive(#xmlel{}) ->
 
 strip_my_archived_tag(Pkt, LServer) ->
     NewEls = lists:filter(
-               fun(#xmlel{name = <<"archived">>,
-                          attrs = Attrs}) ->
+               fun(#xmlel{name = Tag, attrs = Attrs})
+                 when Tag == <<"archived">>; Tag == <<"stanza-id">> ->
                        case catch jlib:nameprep(
                                     xml:get_attr_s(
                                       <<"by">>, Attrs)) of