]> granicus.if.org Git - ejabberd/commitdiff
Include stanza ID with archived offline messages
authorHolger Weiss <holger@zedat.fu-berlin.de>
Thu, 23 Feb 2017 15:55:35 +0000 (16:55 +0100)
committerHolger Weiß <holger@zedat.fu-berlin.de>
Thu, 23 Feb 2017 15:55:35 +0000 (16:55 +0100)
Fixes #1480.

src/ejabberd_piefxis.erl
src/ejabberd_sm.erl
src/jd2ejd.erl
src/mod_mam.erl
src/mod_metrics.erl
src/mod_offline.erl

index 6a2c84a71266a4995245f6a43fef3721409aee39..59d75ff0d825b5d4a51989ffefbef91c498da53e 100644 (file)
@@ -526,8 +526,7 @@ process_offline_msg(#message{from = undefined}, _State) ->
 process_offline_msg(Msg, State = #state{user = U, server = S}) ->
     To = jid:make(U, S),
     ejabberd_hooks:run_fold(
-      offline_message_hook, To#jid.lserver, pass,
-      [xmpp:set_to(Msg, To)]),
+      offline_message_hook, To#jid.lserver, {pass, xmpp:set_to(Msg, To)}, []),
     {ok, State}.
 
 -spec process_presence(presence(), state()) -> {ok, state()} | {error, _}.
index ab6f59639d90bc00a9420a83f5123882c95688ab..aa7c1d080057d0066d0add00635883d27083e0d2 100644 (file)
@@ -45,7 +45,7 @@
         open_session/6,
         close_session/4,
         check_in_subscription/6,
-        bounce_offline_message/2,
+        bounce_offline_message/1,
         disconnect_removed_user/2,
         get_user_resources/2,
         get_user_present_resources/2,
@@ -181,15 +181,15 @@ check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
       false -> {stop, false}
     end.
 
--spec bounce_offline_message(bounce | any(), message()) -> stop.
+-spec bounce_offline_message({bounce, message()} | any()) -> any().
 
-bounce_offline_message(bounce = Acc, Packet) ->
+bounce_offline_message({bounce, Packet} = Acc) ->
     Lang = xmpp:get_lang(Packet),
     Txt = <<"User session not found">>,
     Err = xmpp:err_service_unavailable(Txt, Lang),
     ejabberd_router:route_error(Packet, Err),
     {stop, Acc};
-bounce_offline_message(Acc, _Packet) ->
+bounce_offline_message(Acc) ->
     Acc.
 
 -spec disconnect_removed_user(binary(), binary()) -> ok.
@@ -645,8 +645,7 @@ route_message(#message{to = To, type = Type} = Packet) ->
                is_privacy_allow(Packet) of
                true ->
                    ejabberd_hooks:run_fold(offline_message_hook,
-                                           LServer, bounce,
-                                           [Packet]);
+                                           LServer, {bounce, Packet}, []);
                false ->
                    Err = xmpp:err_service_unavailable(),
                    ejabberd_router:route_error(Packet, Err)
index f67e7ae170bcda92c17fc7eac86e3a1c2a6c6938..ae29369893433877f6a4c376f8584938a6db6cf3 100644 (file)
@@ -163,7 +163,7 @@ process_offline(Server, To, #xmlel{children = Els}) ->
                             end,
                      ejabberd_hooks:run_fold(
                        offline_message_hook,
-                       LServer, pass, [xmpp:set_from_to(Msg, From, To)]);
+                       LServer, {pass, xmpp:set_from_to(Msg, From, To)}, []);
                  _ ->
                      ok
              catch _:{xmpp_codec, Why} ->
index a10c3a3821fd43fc53d17fa9335232b08fcc788f..6ce3805e5bb8ba8904112ae06af54dc12b9b91b6 100644 (file)
@@ -37,7 +37,7 @@
         remove_user/2, remove_room/3, mod_opt_type/1, muc_process_iq/2,
         muc_filter_message/5, message_is_archived/3, delete_old_messages/2,
         get_commands_spec/0, msg_to_el/4, get_room_config/4, set_room_option/3,
-        offline_message/2]).
+        offline_message/1]).
 
 -include("xmpp.hrl").
 -include("logger.hrl").
@@ -82,7 +82,7 @@ start(Host, Opts) ->
     ejabberd_hooks:add(user_send_packet, Host, ?MODULE,
                user_send_packet_strip_tag, 500),
     ejabberd_hooks:add(offline_message_hook, Host, ?MODULE,
-                      offline_message, 50),
+                      offline_message, 40),
     ejabberd_hooks:add(muc_filter_message, Host, ?MODULE,
                       muc_filter_message, 50),
     ejabberd_hooks:add(muc_process_iq, Host, ?MODULE,
@@ -127,7 +127,7 @@ stop(Host) ->
     ejabberd_hooks:delete(user_send_packet, Host, ?MODULE,
                          user_send_packet_strip_tag, 500),
     ejabberd_hooks:delete(offline_message_hook, Host, ?MODULE,
-                         offline_message, 50),
+                         offline_message, 40),
     ejabberd_hooks:delete(muc_filter_message, Host, ?MODULE,
                          muc_filter_message, 50),
     ejabberd_hooks:delete(muc_process_iq, Host, ?MODULE,
@@ -293,16 +293,16 @@ user_send_packet({Pkt, #{jid := JID} = C2SState}) ->
           end,
     {Pkt2, C2SState}.
 
--spec offline_message(any(), message()) -> any().
-offline_message(Acc, #message{from = Peer, to = To} = Pkt) ->
+-spec offline_message({any(), message()}) -> {any(), message()}.
+offline_message({Action, #message{from = Peer, to = To} = Pkt} = Acc) ->
     LUser = To#jid.luser,
     LServer = To#jid.lserver,
     case should_archive(Pkt, LServer) of
        true ->
            Pkt1 = strip_my_archived_tag(Pkt, LServer),
            case store_msg(undefined, Pkt1, LUser, LServer, Peer, recv) of
-               {ok, _ID} ->
-                   archived;
+               {ok, ID} ->
+                   {archived, set_stanza_id(Pkt1, To, ID)};
                _ ->
                    Acc
            end;
index d9fc586f98672eb14503643909fb15a1e05f48ea..6a23935e77db69d0f145ea57b4069d301228a389 100644 (file)
@@ -36,7 +36,7 @@
 -export([start/2, stop/1, send_metrics/4, opt_type/1, mod_opt_type/1,
         depends/2, reload/3]).
 
--export([offline_message_hook/2,
+-export([offline_message_hook/1,
          sm_register_connection_hook/3, sm_remove_connection_hook/3,
          user_send_packet/1, user_receive_packet/1,
          s2s_send_packet/1, s2s_receive_packet/1,
@@ -77,8 +77,8 @@ depends(_Host, _Opts) ->
 %%====================================================================
 %% Hooks handlers
 %%====================================================================
--spec offline_message_hook(any(), message()) -> any().
-offline_message_hook(Acc, #message{to = #jid{lserver = LServer}}) ->
+-spec offline_message_hook({any(), message()}) -> {any(), message()}.
+offline_message_hook({_Action, #message{to = #jid{lserver = LServer}}} = Acc) ->
     push(LServer, offline_message),
     Acc.
 
index 552b49cd92beadf431797c01faf677e4e00c68d7..4c855d52b33712778d3bd20990d38d4328df9e6e 100644 (file)
@@ -39,7 +39,7 @@
 -export([start/2,
         stop/1,
         reload/3,
-        store_packet/2,
+        store_packet/1,
         store_offline_msg/5,
         c2s_self_presence/1,
         get_sm_features/5,
@@ -478,8 +478,8 @@ need_to_store(LServer, #message{type = Type} = Packet) ->
            false
     end.
 
--spec store_packet(any(), message()) -> any().
-store_packet(Acc, #message{from = From, to = To} = Packet) ->
+-spec store_packet({any(), message()}) -> {any(), message()}.
+store_packet({_Action, #message{from = From, to = To} = Packet} = Acc) ->
     case need_to_store(To#jid.lserver, Packet) of
        true ->
            case check_event(Packet) of
@@ -499,7 +499,7 @@ store_packet(Acc, #message{from = From, to = To} = Packet) ->
                                             from = From,
                                             to = To,
                                             packet = NewPacket},
-                           offlined
+                           {offlined, NewPacket}
                    end;
                _ -> Acc
            end;