From 0d6239ea42ad130b18c48c8791bbc1529b3d6f60 Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 13 Apr 2024 23:04:17 +0100 Subject: [PATCH] Added `getActiveProfileIdsWithinMinutes()` to `ProfileActivityService` --- .../src/services/ProfileActivityService.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/project/src/services/ProfileActivityService.ts b/project/src/services/ProfileActivityService.ts index 025a3885..b9f7619e 100644 --- a/project/src/services/ProfileActivityService.ts +++ b/project/src/services/ProfileActivityService.ts @@ -25,6 +25,34 @@ export class ProfileActivityService return (currentTimestamp - storedActivityTimestamp) < (minutes * 60); // convert minutes to seconds to compare } + /** + * Get an array of profile ids that were active in the last x minutes + * @param minutes How many minutes from now to search for profiles + * @returns String array of profile ids + */ + public getActiveProfileIdsWithinMinutes(minutes: number): string[] + { + const currentTimestamp = new Date().getTime() / 1000; + const result: string[] = []; + + for (const id of Object.keys(this.profileActivityTimestamps ?? {})) + { + const lastActiveTimestamp = this.profileActivityTimestamps[id]; + if (!lastActiveTimestamp) + { + continue; + } + + // Profile was active in last x minutes, add to return list + if ((currentTimestamp - lastActiveTimestamp) < (minutes * 60)) + { + result.push(id); + } + } + + return result; + } + /** * Update the timestamp a profile was last observed active * @param sessionId Profile to update