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