Files
discord-decomp/modules/auth_sessions/AuthSessionsUtils.tsx
T
2026-11-01 12:12:55 +02:00

29 lines
1.3 KiB
TypeScript

// Metro module 13766 (f13767).
import { useMemo } from "react";
import AuthenticationStore from "../../stores/AuthenticationStore";
import AuthSessionsStore from "./AuthSessionsStore";
import { useStateFromStoresObject } from "../../_bundle/Module589";
import { intl, t } from "../../intl/index.native";
import Module3771 from "../../_bundle/Module3771";
export function useAuthSessions() {
const stateFromStoresObject = useStateFromStoresObject([AuthSessionsStore], () => AuthSessionsStore.getSessions());
return useMemo(() => {
const otherSessions = [...stateFromStoresObject];
const authSessionIdHash = AuthenticationStore.getAuthSessionIdHash();
const r3 = authSessionIdHash != null;
let currentSession = null;
if (r3) {
const r17 = otherSessions.findIndex((otherSession) => otherSession.id_hash === authSessionIdHash);
currentSession = r17 >= 0 ? otherSessions.splice(r17, 1)[0] : null;
}
otherSessions.sort((a, b) => b.approx_last_used_time.valueOf() - a.approx_last_used_time.valueOf());
return {
currentSession,
otherSessions
};
}, [stateFromStoresObject]);
}
export function formatDate(a0) {
return (Date.now() - a0.valueOf()) / 1000 / 60 / 60 < 1 ? intl.string(t.TXCmfL) : Module3771(a0).fromNow();
}