25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Make a message is not bounced if it's archived

This commit is contained in:
Evgeniy Khramtsov 2017-01-21 13:47:47 +03:00
parent 68cf45a8b9
commit e564f9ae31
5 changed files with 33 additions and 25 deletions

View File

@ -41,7 +41,7 @@
open_session/6,
close_session/4,
check_in_subscription/6,
bounce_offline_message/3,
bounce_offline_message/4,
disconnect_removed_user/2,
get_user_resources/2,
get_user_present_resources/2,
@ -172,14 +172,16 @@ check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
false -> {stop, false}
end.
-spec bounce_offline_message(jid(), jid(), message()) -> stop.
-spec bounce_offline_message(bounce | any(), jid(), jid(), message()) -> stop.
bounce_offline_message(From, To, Packet) ->
bounce_offline_message(bounce = Acc, From, To, Packet) ->
Lang = xmpp:get_lang(Packet),
Txt = <<"User session not found">>,
Err = xmpp:err_service_unavailable(Txt, Lang),
ejabberd_router:route_error(To, From, Packet, Err),
stop.
{stop, Acc};
bounce_offline_message(Acc, _From, _To, _Packet) ->
Acc.
-spec disconnect_removed_user(binary(), binary()) -> ok.
@ -625,7 +627,8 @@ route_message(From, To, Packet, Type) ->
case ejabberd_auth:is_user_exists(LUser, LServer) andalso
is_privacy_allow(From, To, Packet) of
true ->
ejabberd_hooks:run(offline_message_hook, LServer,
ejabberd_hooks:run_fold(offline_message_hook,
LServer, bounce,
[From, To, Packet]);
false ->
Err = xmpp:err_service_unavailable(),

View File

@ -161,8 +161,8 @@ process_offline(Server, To, #xmlel{children = Els}) ->
undefined -> jid:make(Server);
_ -> JID
end,
ejabberd_hooks:run(offline_message_hook,
LServer, [From, To, El]);
ejabberd_hooks:run_fold(offline_message_hook,
LServer, pass, [From, To, El]);
_ ->
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/3]).
offline_message/4]).
-include("xmpp.hrl").
-include("logger.hrl").
@ -241,17 +241,21 @@ user_send_packet({Pkt, #{jid := JID} = C2SState}) ->
end,
{Pkt2, C2SState}.
-spec offline_message(jid(), jid(), message()) -> ok.
offline_message(Peer, To, Pkt) ->
-spec offline_message(any(), jid(), jid(), message()) -> any().
offline_message(Acc, Peer, To, Pkt) ->
LUser = To#jid.luser,
LServer = To#jid.lserver,
case should_archive(Pkt, LServer) of
true ->
Pkt1 = strip_my_archived_tag(Pkt, LServer),
store_msg(undefined, Pkt1, LUser, LServer, Peer, recv),
ok;
case store_msg(undefined, Pkt1, LUser, LServer, Peer, recv) of
{ok, _ID} ->
archived;
_ ->
Acc
end;
false ->
ok
Acc
end.
-spec user_send_packet_strip_tag({stanza(), ejabberd_c2s:state()}) ->

View File

@ -36,7 +36,7 @@
-export([start/2, stop/1, send_metrics/4, opt_type/1, mod_opt_type/1,
depends/2]).
-export([offline_message_hook/3,
-export([offline_message_hook/4,
sm_register_connection_hook/3, sm_remove_connection_hook/3,
user_send_packet/1, user_receive_packet/1,
s2s_send_packet/3, s2s_receive_packet/1,
@ -74,9 +74,10 @@ depends(_Host, _Opts) ->
%%====================================================================
%% Hooks handlers
%%====================================================================
-spec offline_message_hook(jid(), jid(), message()) -> any().
offline_message_hook(_From, #jid{lserver=LServer}, _Packet) ->
push(LServer, offline_message).
-spec offline_message_hook(any(), jid(), jid(), message()) -> any().
offline_message_hook(Acc, _From, #jid{lserver=LServer}, _Packet) ->
push(LServer, offline_message),
Acc.
-spec sm_register_connection_hook(ejabberd_sm:sid(), jid(), ejabberd_sm:info()) -> any().
sm_register_connection_hook(_SID, #jid{lserver=LServer}, _Info) ->

View File

@ -41,7 +41,7 @@
-export([start/2,
start_link/2,
stop/1,
store_packet/3,
store_packet/4,
store_offline_msg/5,
resend_offline_messages/2,
c2s_self_presence/1,
@ -464,8 +464,8 @@ need_to_store(LServer, #message{type = Type} = Packet) ->
false
end.
-spec store_packet(jid(), jid(), message()) -> ok | stop.
store_packet(From, To, Packet) ->
-spec store_packet(any(), jid(), jid(), message()) -> any().
store_packet(Acc, From, To, Packet) ->
case need_to_store(To#jid.lserver, Packet) of
true ->
case check_event(From, To, Packet) of
@ -474,7 +474,7 @@ store_packet(From, To, Packet) ->
case ejabberd_hooks:run_fold(store_offline_message, LServer,
Packet, [From, To]) of
drop ->
ok;
Acc;
NewPacket ->
TimeStamp = p1_time_compat:timestamp(),
Expire = find_x_expire(TimeStamp, NewPacket),
@ -485,11 +485,11 @@ store_packet(From, To, Packet) ->
from = From,
to = To,
packet = NewPacket},
stop
offlined
end;
_ -> ok
_ -> Acc
end;
false -> ok
false -> Acc
end.
-spec check_store_hint(message()) -> store | no_store | none.