25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

Merge pull request #1499 from weiss/offline-stanza-id

Include stanza ID with archived offline messages
This commit is contained in:
Evgeny Khramtsov 2017-02-23 20:36:05 +04:00 committed by GitHub
commit 33e82de475
6 changed files with 21 additions and 23 deletions

View 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, _}.

View 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)

View 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} ->

View 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;

View 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.

View 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;