From 99af649cfeab64d5a6d03375214cb3abc6b19e28 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 1 Apr 2020 10:35:37 +0200 Subject: [PATCH] Start to add support for incognito mode --- src/controllers/FriendsController.ts | 4 +++- src/controllers/UserWebSocketController.ts | 22 ++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/controllers/FriendsController.ts b/src/controllers/FriendsController.ts index 3d06335..fcd062a 100644 --- a/src/controllers/FriendsController.ts +++ b/src/controllers/FriendsController.ts @@ -220,7 +220,9 @@ export class FriendsController { ID_friend: friend.friendID, accepted: friend.accepted ? 1 : 0, time_last_activity: - UserWebSocketController.IsConnected(friend.friendID) ? time() : friend.lastActivityTime + UserWebSocketController.IsConnected(friend.friendID) && + !UserWebSocketController.IsIcognito(friend.friendID) + ? time() : friend.lastActivityTime } if(full) { diff --git a/src/controllers/UserWebSocketController.ts b/src/controllers/UserWebSocketController.ts index a2cf631..e424685 100644 --- a/src/controllers/UserWebSocketController.ts +++ b/src/controllers/UserWebSocketController.ts @@ -19,14 +19,16 @@ interface PendingRequests { time: number, clientID: number, userID: number, - token: string + token: string, + incognito: boolean } export interface ActiveClient { socketID: string, clientID: number, userID: number, - ws: ws + ws: ws, + incognito: boolean } // Tokens are valid only 10 seconds after they are generated @@ -70,7 +72,8 @@ export class UserWebSocketController { time: time(), clientID: h.getClientInfo().id, userID: h.getUserId(), - token: token + token: token, + incognito: h.postBool("incognito", false) }); h.send({ @@ -114,7 +117,8 @@ export class UserWebSocketController { socketID: randomStr(30), clientID: entry.clientID, userID: entry.userID, - ws: ws + ws: ws, + incognito: entry.incognito } this.active_clients.push(client); @@ -228,6 +232,16 @@ export class UserWebSocketController { return this.active_clients.find((e) => e.userID == userID) != undefined; } + /** + * Check out whether a has all its connections marked as incognito + * + * @param userID Target user ID + */ + public static IsIcognito(userID: number) : boolean { + return this.IsConnected(userID) + && this.active_clients.find(e => e.userID == userID && !e.incognito) == undefined; + } + /** * Send updated notifications number to some users *