From 13ad754eccbcc0305aae903b188c87dbbc77d31e Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Fri, 18 Aug 2017 16:44:32 +0200 Subject: [PATCH] Suppress push notifications for online clients When a client enabled push notifications during the current session, notifications should be suppressed as long as the client is online. Suppressing the notification didn't work for the case where the notification was triggered by MAM, but this is now fixed. --- src/ejabberd_sm.erl | 3 ++- src/mod_push.erl | 3 ++- test/push_tests.erl | 2 -- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ejabberd_sm.erl b/src/ejabberd_sm.erl index 5771a5bbf..d93e66473 100644 --- a/src/ejabberd_sm.erl +++ b/src/ejabberd_sm.erl @@ -317,7 +317,8 @@ get_session_sids(User, Server) -> LUser = jid:nodeprep(User), LServer = jid:nameprep(Server), Mod = get_sm_backend(LServer), - online(get_sessions(Mod, LUser, LServer)). + OnlineSs = online(get_sessions(Mod, LUser, LServer)), + [SID || #session{sid = SID} <- OnlineSs]. -spec set_offline_info(sid(), binary(), binary(), binary(), info()) -> ok. diff --git a/src/mod_push.erl b/src/mod_push.erl index 55db7c0e9..90f4ba55e 100644 --- a/src/mod_push.erl +++ b/src/mod_push.erl @@ -546,8 +546,9 @@ delete_sessions(LUser, LServer, LookupFun, Mod) -> -> [push_session()]. drop_online_sessions(LUser, LServer, Clients) -> SessIDs = ejabberd_sm:get_session_sids(LUser, LServer), + ?WARNING_MSG("SessIDs: ~p", [SessIDs]), [Client || {TS, _, _, _} = Client <- Clients, - not lists:keyfind(TS, 1, SessIDs)]. + lists:keyfind(TS, 1, SessIDs) == false]. %%-------------------------------------------------------------------- %% Caching. diff --git a/test/push_tests.erl b/test/push_tests.erl index 4b49cc8fe..04840bad5 100644 --- a/test/push_tests.erl +++ b/test/push_tests.erl @@ -134,8 +134,6 @@ mam_slave(Config) -> self_presence(Config, available), ct:comment("Receiving message from offline storage"), recv_test_message(Config), - ct:comment("Re-enabling push notifications"), - ok = enable_push(Config), ct:comment("Enabling MAM"), ok = enable_mam(Config), ct:comment("Letting the master know that we're ready"),