From beafd7a26bd72ae795cee6bcc19cf4e2e91e9600 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 21 Mar 2020 16:43:53 +0100 Subject: [PATCH] Can get last activity of groups --- src/helpers/GroupsHelper.ts | 9 ++++++--- src/helpers/WebappHelper.ts | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/helpers/GroupsHelper.ts b/src/helpers/GroupsHelper.ts index be22c09..f22fa07 100644 --- a/src/helpers/GroupsHelper.ts +++ b/src/helpers/GroupsHelper.ts @@ -5,6 +5,7 @@ import { NewGroup } from "../entities/NewGroup"; import { time } from "../utils/DateUtils"; import { GroupSettings } from "../entities/GroupSettings"; import { existsSync, unlinkSync } from "fs"; +import { PostsHelper } from "./PostsHelper"; /** * Groups helper @@ -536,9 +537,11 @@ export class GroupsHelper { * * @param groupID Target group ID */ - public static async GetLastActivity(groupID: number) : Promise { - // TODO URGENT : implement - return groupID; + public static async GetLastActivity(userID: number, groupID: number) : Promise { + + const lastPost = await PostsHelper.GetGroupPosts(userID, groupID, 0, 1); + + return lastPost.length == 0 ? 0 : lastPost[0].timeCreate; } /** diff --git a/src/helpers/WebappHelper.ts b/src/helpers/WebappHelper.ts index 3c358e2..f5a0bf6 100644 --- a/src/helpers/WebappHelper.ts +++ b/src/helpers/WebappHelper.ts @@ -29,7 +29,7 @@ export class WebappHelper { // Add groups to the list for(const g of groupsList) list.push(new UserMembershipEntry( - await GroupsHelper.GetLastActivity(g), g, UserMembershipType.GROUP)); + await GroupsHelper.GetLastActivity(userID, g), g, UserMembershipType.GROUP)); // Sort entries by latest activities list.sort((a, b) => b.lastActivity - a.lastActivity);