25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-20 17:27:00 +01:00

Omit push notifications if offline storage failed

This commit removes the 'store_offline_message' hook which didn't allow
mod_push to suppress notifications when storing an offline message
failed (due to the offline spool size limit being exceeded or due to
database issues).

Fixes #3120.
This commit is contained in:
Holger Weiss 2020-01-05 20:08:54 +01:00
parent 19e47375df
commit 0e96d64e60
2 changed files with 27 additions and 29 deletions

View File

@ -493,26 +493,20 @@ store_packet({_Action, #message{from = From, to = To} = Packet} = Acc) ->
case check_event(Packet) of case check_event(Packet) of
true -> true ->
#jid{luser = LUser, lserver = LServer} = To, #jid{luser = LUser, lserver = LServer} = To,
case ejabberd_hooks:run_fold(store_offline_message, LServer, TimeStamp = erlang:timestamp(),
Packet, []) of Expire = find_x_expire(TimeStamp, Packet),
drop -> OffMsg = #offline_msg{us = {LUser, LServer},
Acc; timestamp = TimeStamp,
NewPacket -> expire = Expire,
TimeStamp = erlang:timestamp(), from = From,
Expire = find_x_expire(TimeStamp, NewPacket), to = To,
OffMsg = #offline_msg{us = {LUser, LServer}, packet = Packet},
timestamp = TimeStamp, case store_offline_msg(OffMsg) of
expire = Expire, ok ->
from = From, {offlined, Packet};
to = To, {error, Reason} ->
packet = NewPacket}, discard_warn_sender(Packet, Reason),
case store_offline_msg(OffMsg) of stop
ok ->
{offlined, NewPacket};
{error, Reason} ->
discard_warn_sender(Packet, Reason),
stop
end
end; end;
_ -> _ ->
maybe_update_cache(To, Packet), maybe_update_cache(To, Packet),

View File

@ -209,8 +209,8 @@ register_hooks(Host) ->
c2s_stanza, 50), c2s_stanza, 50),
ejabberd_hooks:add(store_mam_message, Host, ?MODULE, ejabberd_hooks:add(store_mam_message, Host, ?MODULE,
mam_message, 50), mam_message, 50),
ejabberd_hooks:add(store_offline_message, Host, ?MODULE, ejabberd_hooks:add(offline_message_hook, Host, ?MODULE,
offline_message, 50), offline_message, 55),
ejabberd_hooks:add(remove_user, Host, ?MODULE, ejabberd_hooks:add(remove_user, Host, ?MODULE,
remove_user, 50). remove_user, 50).
@ -228,8 +228,8 @@ unregister_hooks(Host) ->
c2s_stanza, 50), c2s_stanza, 50),
ejabberd_hooks:delete(store_mam_message, Host, ?MODULE, ejabberd_hooks:delete(store_mam_message, Host, ?MODULE,
mam_message, 50), mam_message, 50),
ejabberd_hooks:delete(store_offline_message, Host, ?MODULE, ejabberd_hooks:delete(offline_message_hook, Host, ?MODULE,
offline_message, 50), offline_message, 55),
ejabberd_hooks:delete(remove_user, Host, ?MODULE, ejabberd_hooks:delete(remove_user, Host, ?MODULE,
remove_user, 50). remove_user, 50).
@ -373,10 +373,12 @@ mam_message(#message{} = Pkt, LUser, LServer, _Peer, _Nick, chat, Dir) ->
mam_message(Pkt, _LUser, _LServer, _Peer, _Nick, _Type, _Dir) -> mam_message(Pkt, _LUser, _LServer, _Peer, _Nick, _Type, _Dir) ->
Pkt. Pkt.
-spec offline_message(message()) -> message(). -spec offline_message({any(), message()}) -> {any(), message()}.
offline_message(#message{meta = #{mam_archived := true}} = Pkt) -> offline_message({offlined, #message{meta = #{mam_archived := true}}} = Acc) ->
Pkt; % Push notification was triggered via MAM. Acc; % Push notification was triggered via MAM.
offline_message(#message{to = #jid{luser = LUser, lserver = LServer}} = Pkt) -> offline_message({offlined,
#message{to = #jid{luser = LUser,
lserver = LServer}} = Pkt} = Acc) ->
case lookup_sessions(LUser, LServer) of case lookup_sessions(LUser, LServer) of
{ok, [_|_] = Clients} -> {ok, [_|_] = Clients} ->
?DEBUG("Notifying ~ts@~ts of offline message", [LUser, LServer]), ?DEBUG("Notifying ~ts@~ts of offline message", [LUser, LServer]),
@ -384,7 +386,9 @@ offline_message(#message{to = #jid{luser = LUser, lserver = LServer}} = Pkt) ->
_ -> _ ->
ok ok
end, end,
Pkt. Acc;
offline_message(Acc) ->
Acc.
-spec c2s_session_pending(c2s_state()) -> c2s_state(). -spec c2s_session_pending(c2s_state()) -> c2s_state().
c2s_session_pending(#{push_enabled := true, mgmt_queue := Queue} = State) -> c2s_session_pending(#{push_enabled := true, mgmt_queue := Queue} = State) ->