SkateSpots/src/lib/dmOwnWraps.ts
2026-10-28 22:43:52 +07:00

31 lines
897 B
TypeScript

/**
* Gift-wrap ids created by this device. NIP-17 sends a copy to the sender, and
* envelope-only unread counts can't distinguish that copy from an incoming
* message without decrypting. Tracking outbound wrap ids keeps the decrypt-free
* bell badge honest.
*/
const KEY = 'skatespots:dm-own-wraps';
const MAX = 500;
function read(): string[] {
try {
const raw = localStorage.getItem(KEY);
const parsed = raw ? JSON.parse(raw) as unknown : [];
return Array.isArray(parsed) ? parsed.filter((id): id is string => typeof id === 'string') : [];
} catch {
return [];
}
}
export function markOwnDmWraps(ids: string[]): void {
try {
const next = [...new Set([...ids, ...read()])].slice(0, MAX);
localStorage.setItem(KEY, JSON.stringify(next));
} catch {
// best-effort only
}
}
export function getOwnDmWrapIds(): Set<string> {
return new Set(read());
}