gitscope
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/modules/users/domain/is-online.ts · v0.6.5
Source
1 e6e6467 Dawsh 2y ago import { UserType } from "@marzneshin/modules/users";
2 02f4c98 Mrdn 2y ago
3 02f4c98 Mrdn 2y ago /**
4 02f4c98 Mrdn 2y ago * Checks whether the user has been online recently.
5 02f4c98 Mrdn 2y ago *
6 02f4c98 Mrdn 2y ago * This function compares the provided user's last online time with the current time
7 02f4c98 Mrdn 2y ago * to determine if the user has been online within a certain threshold.
8 02f4c98 Mrdn 2y ago *
9 02f4c98 Mrdn 2y ago * @param user - The user entity containing information about the user.
10 02f4c98 Mrdn 2y ago * @returns A boolean value indicating whether the user has been online recently.
11 02f4c98 Mrdn 2y ago */
12 02f4c98 Mrdn 2y ago export const isUserOnline = (user: UserType): boolean => {
13 02f4c98 Mrdn 2y ago const utcUserOnlineTime = new Date(user.online_at + 'Z');
14 02f4c98 Mrdn 2y ago const currentTime = new Date();
15 02f4c98 Mrdn 2y ago const timeDifference = Math.abs(currentTime.getTime() - utcUserOnlineTime.getTime());
16 02f4c98 Mrdn 2y ago return timeDifference < 30000;
17 02f4c98 Mrdn 2y ago };