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:
parent
68cf45a8b9
commit
e564f9ae31
@ -41,7 +41,7 @@
|
|||||||
open_session/6,
|
open_session/6,
|
||||||
close_session/4,
|
close_session/4,
|
||||||
check_in_subscription/6,
|
check_in_subscription/6,
|
||||||
bounce_offline_message/3,
|
bounce_offline_message/4,
|
||||||
disconnect_removed_user/2,
|
disconnect_removed_user/2,
|
||||||
get_user_resources/2,
|
get_user_resources/2,
|
||||||
get_user_present_resources/2,
|
get_user_present_resources/2,
|
||||||
@ -172,14 +172,16 @@ check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
|
|||||||
false -> {stop, false}
|
false -> {stop, false}
|
||||||
end.
|
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),
|
Lang = xmpp:get_lang(Packet),
|
||||||
Txt = <<"User session not found">>,
|
Txt = <<"User session not found">>,
|
||||||
Err = xmpp:err_service_unavailable(Txt, Lang),
|
Err = xmpp:err_service_unavailable(Txt, Lang),
|
||||||
ejabberd_router:route_error(To, From, Packet, Err),
|
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.
|
-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
|
case ejabberd_auth:is_user_exists(LUser, LServer) andalso
|
||||||
is_privacy_allow(From, To, Packet) of
|
is_privacy_allow(From, To, Packet) of
|
||||||
true ->
|
true ->
|
||||||
ejabberd_hooks:run(offline_message_hook, LServer,
|
ejabberd_hooks:run_fold(offline_message_hook,
|
||||||
|
LServer, bounce,
|
||||||
[From, To, Packet]);
|
[From, To, Packet]);
|
||||||
false ->
|
false ->
|
||||||
Err = xmpp:err_service_unavailable(),
|
Err = xmpp:err_service_unavailable(),
|
||||||
|
@ -161,8 +161,8 @@ process_offline(Server, To, #xmlel{children = Els}) ->
|
|||||||
undefined -> jid:make(Server);
|
undefined -> jid:make(Server);
|
||||||
_ -> JID
|
_ -> JID
|
||||||
end,
|
end,
|
||||||
ejabberd_hooks:run(offline_message_hook,
|
ejabberd_hooks:run_fold(offline_message_hook,
|
||||||
LServer, [From, To, El]);
|
LServer, pass, [From, To, El]);
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
catch _:{xmpp_codec, Why} ->
|
catch _:{xmpp_codec, Why} ->
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
remove_user/2, remove_room/3, mod_opt_type/1, muc_process_iq/2,
|
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,
|
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,
|
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("xmpp.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
@ -241,17 +241,21 @@ user_send_packet({Pkt, #{jid := JID} = C2SState}) ->
|
|||||||
end,
|
end,
|
||||||
{Pkt2, C2SState}.
|
{Pkt2, C2SState}.
|
||||||
|
|
||||||
-spec offline_message(jid(), jid(), message()) -> ok.
|
-spec offline_message(any(), jid(), jid(), message()) -> any().
|
||||||
offline_message(Peer, To, Pkt) ->
|
offline_message(Acc, Peer, To, Pkt) ->
|
||||||
LUser = To#jid.luser,
|
LUser = To#jid.luser,
|
||||||
LServer = To#jid.lserver,
|
LServer = To#jid.lserver,
|
||||||
case should_archive(Pkt, LServer) of
|
case should_archive(Pkt, LServer) of
|
||||||
true ->
|
true ->
|
||||||
Pkt1 = strip_my_archived_tag(Pkt, LServer),
|
Pkt1 = strip_my_archived_tag(Pkt, LServer),
|
||||||
store_msg(undefined, Pkt1, LUser, LServer, Peer, recv),
|
case store_msg(undefined, Pkt1, LUser, LServer, Peer, recv) of
|
||||||
ok;
|
{ok, _ID} ->
|
||||||
|
archived;
|
||||||
|
_ ->
|
||||||
|
Acc
|
||||||
|
end;
|
||||||
false ->
|
false ->
|
||||||
ok
|
Acc
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec user_send_packet_strip_tag({stanza(), ejabberd_c2s:state()}) ->
|
-spec user_send_packet_strip_tag({stanza(), ejabberd_c2s:state()}) ->
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
-export([start/2, stop/1, send_metrics/4, opt_type/1, mod_opt_type/1,
|
-export([start/2, stop/1, send_metrics/4, opt_type/1, mod_opt_type/1,
|
||||||
depends/2]).
|
depends/2]).
|
||||||
|
|
||||||
-export([offline_message_hook/3,
|
-export([offline_message_hook/4,
|
||||||
sm_register_connection_hook/3, sm_remove_connection_hook/3,
|
sm_register_connection_hook/3, sm_remove_connection_hook/3,
|
||||||
user_send_packet/1, user_receive_packet/1,
|
user_send_packet/1, user_receive_packet/1,
|
||||||
s2s_send_packet/3, s2s_receive_packet/1,
|
s2s_send_packet/3, s2s_receive_packet/1,
|
||||||
@ -74,9 +74,10 @@ depends(_Host, _Opts) ->
|
|||||||
%%====================================================================
|
%%====================================================================
|
||||||
%% Hooks handlers
|
%% Hooks handlers
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
-spec offline_message_hook(jid(), jid(), message()) -> any().
|
-spec offline_message_hook(any(), jid(), jid(), message()) -> any().
|
||||||
offline_message_hook(_From, #jid{lserver=LServer}, _Packet) ->
|
offline_message_hook(Acc, _From, #jid{lserver=LServer}, _Packet) ->
|
||||||
push(LServer, offline_message).
|
push(LServer, offline_message),
|
||||||
|
Acc.
|
||||||
|
|
||||||
-spec sm_register_connection_hook(ejabberd_sm:sid(), jid(), ejabberd_sm:info()) -> any().
|
-spec sm_register_connection_hook(ejabberd_sm:sid(), jid(), ejabberd_sm:info()) -> any().
|
||||||
sm_register_connection_hook(_SID, #jid{lserver=LServer}, _Info) ->
|
sm_register_connection_hook(_SID, #jid{lserver=LServer}, _Info) ->
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
-export([start/2,
|
-export([start/2,
|
||||||
start_link/2,
|
start_link/2,
|
||||||
stop/1,
|
stop/1,
|
||||||
store_packet/3,
|
store_packet/4,
|
||||||
store_offline_msg/5,
|
store_offline_msg/5,
|
||||||
resend_offline_messages/2,
|
resend_offline_messages/2,
|
||||||
c2s_self_presence/1,
|
c2s_self_presence/1,
|
||||||
@ -464,8 +464,8 @@ need_to_store(LServer, #message{type = Type} = Packet) ->
|
|||||||
false
|
false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec store_packet(jid(), jid(), message()) -> ok | stop.
|
-spec store_packet(any(), jid(), jid(), message()) -> any().
|
||||||
store_packet(From, To, Packet) ->
|
store_packet(Acc, From, To, Packet) ->
|
||||||
case need_to_store(To#jid.lserver, Packet) of
|
case need_to_store(To#jid.lserver, Packet) of
|
||||||
true ->
|
true ->
|
||||||
case check_event(From, To, Packet) of
|
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,
|
case ejabberd_hooks:run_fold(store_offline_message, LServer,
|
||||||
Packet, [From, To]) of
|
Packet, [From, To]) of
|
||||||
drop ->
|
drop ->
|
||||||
ok;
|
Acc;
|
||||||
NewPacket ->
|
NewPacket ->
|
||||||
TimeStamp = p1_time_compat:timestamp(),
|
TimeStamp = p1_time_compat:timestamp(),
|
||||||
Expire = find_x_expire(TimeStamp, NewPacket),
|
Expire = find_x_expire(TimeStamp, NewPacket),
|
||||||
@ -485,11 +485,11 @@ store_packet(From, To, Packet) ->
|
|||||||
from = From,
|
from = From,
|
||||||
to = To,
|
to = To,
|
||||||
packet = NewPacket},
|
packet = NewPacket},
|
||||||
stop
|
offlined
|
||||||
end;
|
end;
|
||||||
_ -> ok
|
_ -> Acc
|
||||||
end;
|
end;
|
||||||
false -> ok
|
false -> Acc
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec check_store_hint(message()) -> store | no_store | none.
|
-spec check_store_hint(message()) -> store | no_store | none.
|
||||||
|
Loading…
Reference in New Issue
Block a user