mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
mod_push: Avoid notification duplicates (again)
Now that mod_mam no longer uses the 'offline_message_hook', avoid duplicating notifications for messages written to both MAM and offline storage in another way.
This commit is contained in:
parent
28661d20bd
commit
d1df522fd9
@ -270,7 +270,8 @@ sm_receive_packet(#message{from = Peer, to = JID} = Pkt) ->
|
||||
true ->
|
||||
case store_msg(Pkt1, LUser, LServer, Peer, recv) of
|
||||
{ok, ID} ->
|
||||
set_stanza_id(Pkt1, JID, ID);
|
||||
xmpp:put_meta(set_stanza_id(Pkt1, JID, ID),
|
||||
mam_archived, true);
|
||||
_ ->
|
||||
Pkt1
|
||||
end;
|
||||
@ -291,7 +292,8 @@ user_send_packet({#message{to = Peer} = Pkt, #{jid := JID} = C2SState}) ->
|
||||
case store_msg(xmpp:set_from_to(Pkt1, JID, Peer),
|
||||
LUser, LServer, Peer, send) of
|
||||
{ok, ID} ->
|
||||
set_stanza_id(Pkt1, JID, ID);
|
||||
xmpp:put_meta(set_stanza_id(Pkt1, JID, ID),
|
||||
mam_archived, true);
|
||||
_ ->
|
||||
Pkt1
|
||||
end;
|
||||
@ -321,7 +323,8 @@ muc_filter_message(#message{from = From} = Pkt,
|
||||
StorePkt = strip_x_jid_tags(NewPkt),
|
||||
case store_muc(MUCState, StorePkt, RoomJID, From, FromNick) of
|
||||
{ok, ID} ->
|
||||
set_stanza_id(NewPkt, RoomJID, ID);
|
||||
xmpp:put_meta(set_stanza_id(NewPkt, RoomJID, ID),
|
||||
mam_archived, true);
|
||||
_ ->
|
||||
NewPkt
|
||||
end;
|
||||
|
@ -199,8 +199,8 @@ register_hooks(Host) ->
|
||||
c2s_stanza, 50),
|
||||
ejabberd_hooks:add(store_mam_message, Host, ?MODULE,
|
||||
mam_message, 50),
|
||||
ejabberd_hooks:add(offline_message_hook, Host, ?MODULE,
|
||||
offline_message, 30),
|
||||
ejabberd_hooks:add(store_offline_message, Host, ?MODULE,
|
||||
offline_message, 50),
|
||||
ejabberd_hooks:add(remove_user, Host, ?MODULE,
|
||||
remove_user, 50).
|
||||
|
||||
@ -218,8 +218,8 @@ unregister_hooks(Host) ->
|
||||
c2s_stanza, 50),
|
||||
ejabberd_hooks:delete(store_mam_message, Host, ?MODULE,
|
||||
mam_message, 50),
|
||||
ejabberd_hooks:delete(offline_message_hook, Host, ?MODULE,
|
||||
offline_message, 30),
|
||||
ejabberd_hooks:delete(store_offline_message, Host, ?MODULE,
|
||||
offline_message, 50),
|
||||
ejabberd_hooks:delete(remove_user, Host, ?MODULE,
|
||||
remove_user, 50).
|
||||
|
||||
@ -343,9 +343,6 @@ c2s_stanza(State, _Pkt, _SendResult) ->
|
||||
|
||||
-spec mam_message(message() | drop, binary(), binary(), jid(),
|
||||
chat | groupchat, recv | send) -> message().
|
||||
mam_message(#message{meta = #{push_notified := true}} = Pkt,
|
||||
_LUser, _LServer, _Peer, _Type, _Dir) ->
|
||||
Pkt;
|
||||
mam_message(#message{} = Pkt, LUser, LServer, _Peer, chat, _Dir) ->
|
||||
case lookup_sessions(LUser, LServer) of
|
||||
{ok, [_|_] = Clients} ->
|
||||
@ -363,9 +360,10 @@ mam_message(#message{} = Pkt, LUser, LServer, _Peer, chat, _Dir) ->
|
||||
mam_message(Pkt, _LUser, _LServer, _Peer, _Type, _Dir) ->
|
||||
Pkt.
|
||||
|
||||
-spec offline_message({any(), message()}) -> {any(), message()}.
|
||||
offline_message({Action, #message{to = #jid{luser = LUser,
|
||||
lserver = LServer}} = Pkt}) ->
|
||||
-spec offline_message(message()) -> message().
|
||||
offline_message(#message{meta = #{mam_archived := true}} = Pkt) ->
|
||||
Pkt; % Push notification was triggered via MAM.
|
||||
offline_message(#message{to = #jid{luser = LUser, lserver = LServer}} = Pkt) ->
|
||||
case lookup_sessions(LUser, LServer) of
|
||||
{ok, [_|_] = Clients} ->
|
||||
?DEBUG("Notifying ~s@~s of offline message", [LUser, LServer]),
|
||||
@ -373,7 +371,7 @@ offline_message({Action, #message{to = #jid{luser = LUser,
|
||||
_ ->
|
||||
ok
|
||||
end,
|
||||
{Action, xmpp:put_meta(Pkt, push_notified, true)}.
|
||||
Pkt.
|
||||
|
||||
-spec c2s_session_pending(c2s_state()) -> c2s_state().
|
||||
c2s_session_pending(#{push_enabled := true, mgmt_queue := Queue} = State) ->
|
||||
|
Loading…
Reference in New Issue
Block a user