From 17407f964b7beedfea3eb57443d9e57a49c9184f Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 28 Mar 2020 15:21:06 +0100 Subject: [PATCH] Update last user activity --- src/controllers/AccountController.ts | 13 +++++++++---- src/controllers/FriendsController.ts | 5 ++++- src/helpers/AccountHelper.ts | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/controllers/AccountController.ts b/src/controllers/AccountController.ts index bb6fd69..d6c206f 100644 --- a/src/controllers/AccountController.ts +++ b/src/controllers/AccountController.ts @@ -105,11 +105,16 @@ export class AccountController { /** * Get current user ID * - * @param handler + * @param h Request handler */ - public static CurrentUserID(handler: RequestHandler) { - handler.send({ - userID: handler.getUserId() + public static async CurrentUserID(h: RequestHandler) { + + // Update user activity (if allowed) + if(!h.postBool("incognito", false)) + await AccountHelper.UpdateLastActivity(h.getUserId()) + + h.send({ + userID: h.getUserId() }); } diff --git a/src/controllers/FriendsController.ts b/src/controllers/FriendsController.ts index 3c385e0..e8c6b3f 100644 --- a/src/controllers/FriendsController.ts +++ b/src/controllers/FriendsController.ts @@ -4,6 +4,7 @@ import { FriendsHelper } from "../helpers/FriendsHelper"; import { UserHelper } from "../helpers/UserHelper"; import { NotifEventType } from "../entities/Notification"; import { NotificationsHelper } from "../helpers/NotificationsHelper"; +import { AccountHelper } from "../helpers/AccountHelper"; /** * Friends controller @@ -22,7 +23,9 @@ export class FriendsController { const returnAllInfo = h.postBool("complete", false); const list = await FriendsHelper.GetList(h.getUserId()); - // TODO : update user activity (if allowed) + // Update user activity (if allowed) + if(!h.postBool("incognito", false)) + await AccountHelper.UpdateLastActivity(h.getUserId()) h.send(list.map((f) => this.FriendToAPI(f, returnAllInfo))); } diff --git a/src/helpers/AccountHelper.ts b/src/helpers/AccountHelper.ts index e95e5b0..3c07ce0 100644 --- a/src/helpers/AccountHelper.ts +++ b/src/helpers/AccountHelper.ts @@ -225,6 +225,23 @@ export class AccountHelper { return result == null ? -1 : result.ID; } + /** + * Update the last activity time of the user + * + * @param userID Target user ID + */ + public static async UpdateLastActivity(userID: number) { + await DatabaseHelper.UpdateRows({ + table: USER_TABLE, + where: { + ID: userID + }, + set: { + last_activity: time() + } + }) + } + /** * Check out whether a virtual directory is available or not