From 1c22c6073312f7c404363c4f6122301944e9e215 Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Fri, 20 Mar 2020 10:29:18 +0100 Subject: [PATCH] Delete Auth-records on logout if not mobile or push --- apps/roster/src/protocol/roster_presence.erl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/roster/src/protocol/roster_presence.erl b/apps/roster/src/protocol/roster_presence.erl index 57e26ec43..9ecf2434c 100644 --- a/apps/roster/src/protocol/roster_presence.erl +++ b/apps/roster/src/protocol/roster_presence.erl @@ -45,7 +45,10 @@ on_disconnect(#'Auth'{type = disconnect, phone = Phone, client_id = ClientId, us send_presence(offline, Phone, C, ClientId), roster:unsubscribe_p2p(ClientId, roster:roster_id(PhoneId)), roster:unsubscribe_room(ClientId), - %% Warning: Do not delete Auth record, it holds push notification tokens + case should_preserve_auth_record(ClientId) of + true -> ok; + false -> kvs:delete('Auth', ClientId) + end, roster:final_disconnect(ClientId); on_disconnect(#'Auth'{phone = Phone, client_id = ClientId, type=Type}, C) -> @@ -54,6 +57,15 @@ on_disconnect(#'Auth'{phone = Phone, client_id = ClientId, type=Type}, C) -> on_verify(ClientId, PhoneId) -> roster:sub_client(subscribe, ClientId, PhoneId). +%% Warning: Do not always delete Auth record, it holds push notification tokens +should_preserve_auth_record(ClientId) -> + case kvs:get('Auth', ClientId) of + {ok, #'Auth'{ os = OS, push = Push }} -> + is_binary(Push) orelse OS == ios orelse OS == android; + _Err -> + false + end. + send_presence(Status, Phone, C, ClientId) when Status == online; Status == offline -> case kvs:get('Profile', Phone) of {ok, #'Profile'{rosters = Rosters} = P} -> -- GitLab