1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-21 21:09:22 +00:00

Start to add support for incognito mode

This commit is contained in:
Pierre HUBERT 2020-04-01 10:35:37 +02:00
parent 23733b229e
commit 99af649cfe
2 changed files with 21 additions and 5 deletions

View File

@ -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) {

View File

@ -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
*