34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
const KICK_RETENTION_MS = 24 * 60 * 60_000;
|
|
type KickList = { ids: Set<string>; expiresAt: number };
|
|
const kickedParticipantIds = new Map<string, KickList>();
|
|
const kickedClientIds = new Map<string, KickList>();
|
|
|
|
function activeList(map: Map<string, KickList>, eventSlug: string): Set<string> | undefined {
|
|
const entry = map.get(eventSlug);
|
|
if (!entry) return undefined;
|
|
if (entry.expiresAt <= Date.now()) {
|
|
map.delete(eventSlug);
|
|
return undefined;
|
|
}
|
|
return entry.ids;
|
|
}
|
|
|
|
export function isMeetingParticipantKicked(eventSlug: string, participantId: string, clientId?: string): boolean {
|
|
return Boolean(
|
|
activeList(kickedParticipantIds, eventSlug)?.has(participantId) ||
|
|
(clientId && activeList(kickedClientIds, eventSlug)?.has(clientId)),
|
|
);
|
|
}
|
|
|
|
export function markMeetingParticipantKicked(eventSlug: string, participantId: string, clientId?: string): void {
|
|
const expiresAt = Date.now() + KICK_RETENTION_MS;
|
|
const participantIds = activeList(kickedParticipantIds, eventSlug) ?? new Set<string>();
|
|
participantIds.add(participantId);
|
|
kickedParticipantIds.set(eventSlug, { ids: participantIds, expiresAt });
|
|
if (clientId) {
|
|
const clientIds = activeList(kickedClientIds, eventSlug) ?? new Set<string>();
|
|
clientIds.add(clientId);
|
|
kickedClientIds.set(eventSlug, { ids: clientIds, expiresAt });
|
|
}
|
|
}
|