full update
This commit is contained in:
20
src/lib/chat/deleteWindow.ts
Normal file
20
src/lib/chat/deleteWindow.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export const DELETE_WINDOW_MS = 24 * 60 * 60 * 1000;
|
||||
|
||||
export function parseMessageCreatedAt(
|
||||
createdAt?: string | null,
|
||||
createdAtIso?: string | null
|
||||
): Date | null {
|
||||
const raw = createdAtIso || createdAt;
|
||||
if (!raw) return null;
|
||||
const d = new Date(String(raw));
|
||||
return Number.isNaN(d.getTime()) ? null : d;
|
||||
}
|
||||
|
||||
export function isMessageDeletable(
|
||||
createdAt?: string | null,
|
||||
createdAtIso?: string | null
|
||||
): boolean {
|
||||
const created = parseMessageCreatedAt(createdAt, createdAtIso);
|
||||
if (!created) return false;
|
||||
return Date.now() - created.getTime() <= DELETE_WINDOW_MS;
|
||||
}
|
||||
@@ -28,10 +28,13 @@ export function getChatSocket(): Socket | null {
|
||||
|
||||
export function releaseChatSocket(): void {
|
||||
refCount = Math.max(0, refCount - 1);
|
||||
if (refCount === 0 && sharedSocket) {
|
||||
sharedSocket.removeAllListeners();
|
||||
}
|
||||
|
||||
export function disconnectChatSocket(): void {
|
||||
if (sharedSocket) {
|
||||
sharedSocket.disconnect();
|
||||
sharedSocket = null;
|
||||
refCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user