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 ->
|
true ->
|
||||||
case store_msg(Pkt1, LUser, LServer, Peer, recv) of
|
case store_msg(Pkt1, LUser, LServer, Peer, recv) of
|
||||||
{ok, ID} ->
|
{ok, ID} ->
|
||||||
set_stanza_id(Pkt1, JID, ID);
|
xmpp:put_meta(set_stanza_id(Pkt1, JID, ID),
|
||||||
|
mam_archived, true);
|
||||||
_ ->
|
_ ->
|
||||||
Pkt1
|
Pkt1
|
||||||
end;
|
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),
|
case store_msg(xmpp:set_from_to(Pkt1, JID, Peer),
|
||||||
LUser, LServer, Peer, send) of
|
LUser, LServer, Peer, send) of
|
||||||
{ok, ID} ->
|
{ok, ID} ->
|
||||||
set_stanza_id(Pkt1, JID, ID);
|
xmpp:put_meta(set_stanza_id(Pkt1, JID, ID),
|
||||||
|
mam_archived, true);
|
||||||
_ ->
|
_ ->
|
||||||
Pkt1
|
Pkt1
|
||||||
end;
|
end;
|
||||||
@ -321,7 +323,8 @@ muc_filter_message(#message{from = From} = Pkt,
|
|||||||
StorePkt = strip_x_jid_tags(NewPkt),
|
StorePkt = strip_x_jid_tags(NewPkt),
|
||||||
case store_muc(MUCState, StorePkt, RoomJID, From, FromNick) of
|
case store_muc(MUCState, StorePkt, RoomJID, From, FromNick) of
|
||||||
{ok, ID} ->
|
{ok, ID} ->
|
||||||
set_stanza_id(NewPkt, RoomJID, ID);
|
xmpp:put_meta(set_stanza_id(NewPkt, RoomJID, ID),
|
||||||
|
mam_archived, true);
|
||||||
_ ->
|
_ ->
|
||||||
NewPkt
|
NewPkt
|
||||||
end;
|
end;
|
||||||
|
@ -199,8 +199,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(offline_message_hook, Host, ?MODULE,
|
ejabberd_hooks:add(store_offline_message, Host, ?MODULE,
|
||||||
offline_message, 30),
|
offline_message, 50),
|
||||||
ejabberd_hooks:add(remove_user, Host, ?MODULE,
|
ejabberd_hooks:add(remove_user, Host, ?MODULE,
|
||||||
remove_user, 50).
|
remove_user, 50).
|
||||||
|
|
||||||
@ -218,8 +218,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(offline_message_hook, Host, ?MODULE,
|
ejabberd_hooks:delete(store_offline_message, Host, ?MODULE,
|
||||||
offline_message, 30),
|
offline_message, 50),
|
||||||
ejabberd_hooks:delete(remove_user, Host, ?MODULE,
|
ejabberd_hooks:delete(remove_user, Host, ?MODULE,
|
||||||
remove_user, 50).
|
remove_user, 50).
|
||||||
|
|
||||||
@ -343,9 +343,6 @@ c2s_stanza(State, _Pkt, _SendResult) ->
|
|||||||
|
|
||||||
-spec mam_message(message() | drop, binary(), binary(), jid(),
|
-spec mam_message(message() | drop, binary(), binary(), jid(),
|
||||||
chat | groupchat, recv | send) -> message().
|
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) ->
|
mam_message(#message{} = Pkt, LUser, LServer, _Peer, chat, _Dir) ->
|
||||||
case lookup_sessions(LUser, LServer) of
|
case lookup_sessions(LUser, LServer) of
|
||||||
{ok, [_|_] = Clients} ->
|
{ok, [_|_] = Clients} ->
|
||||||
@ -363,9 +360,10 @@ mam_message(#message{} = Pkt, LUser, LServer, _Peer, chat, _Dir) ->
|
|||||||
mam_message(Pkt, _LUser, _LServer, _Peer, _Type, _Dir) ->
|
mam_message(Pkt, _LUser, _LServer, _Peer, _Type, _Dir) ->
|
||||||
Pkt.
|
Pkt.
|
||||||
|
|
||||||
-spec offline_message({any(), message()}) -> {any(), message()}.
|
-spec offline_message(message()) -> message().
|
||||||
offline_message({Action, #message{to = #jid{luser = LUser,
|
offline_message(#message{meta = #{mam_archived := true}} = Pkt) ->
|
||||||
lserver = LServer}} = Pkt}) ->
|
Pkt; % Push notification was triggered via MAM.
|
||||||
|
offline_message(#message{to = #jid{luser = LUser, lserver = LServer}} = Pkt) ->
|
||||||
case lookup_sessions(LUser, LServer) of
|
case lookup_sessions(LUser, LServer) of
|
||||||
{ok, [_|_] = Clients} ->
|
{ok, [_|_] = Clients} ->
|
||||||
?DEBUG("Notifying ~s@~s of offline message", [LUser, LServer]),
|
?DEBUG("Notifying ~s@~s of offline message", [LUser, LServer]),
|
||||||
@ -373,7 +371,7 @@ offline_message({Action, #message{to = #jid{luser = LUser,
|
|||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
{Action, xmpp:put_meta(Pkt, push_notified, true)}.
|
Pkt.
|
||||||
|
|
||||||
-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) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user