/** * Remember a join request across reloads so the panel can resume the * coordinator poll instead of losing the “waiting for approval” state. * * Scoped by account + room and expires after 30 days; an old request should not * make the panel poll forever if the user abandoned it. */ const KEY_PREFIX = 'skatespots:cordn-pending:'; const MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000; function key(pubkey: string, gid: string): string { return `${KEY_PREFIX}${pubkey}:${gid}`; } export function readPendingJoin(pubkey: string, gid: string): boolean { if (!pubkey || !gid) return false; try { const raw = localStorage.getItem(key(pubkey, gid)); if (raw === null) return false; const at = Number(raw); return Number.isFinite(at) && Date.now() - at < MAX_AGE_MS; } catch { return false; } } export function writePendingJoin(pubkey: string, gid: string): void { if (!pubkey || !gid) return; try { localStorage.setItem(key(pubkey, gid), String(Date.now())); } catch { // private mode / quota — polling still works for this session } } export function clearPendingJoin(pubkey: string, gid: string): void { if (!pubkey || !gid) return; try { localStorage.removeItem(key(pubkey, gid)); } catch { // ignore } }