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

Update last user activity

This commit is contained in:
Pierre HUBERT 2020-03-28 15:21:06 +01:00
parent d443551405
commit 17407f964b
3 changed files with 30 additions and 5 deletions

View File

@ -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()
});
}

View File

@ -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)));
}

View File

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