From 9175c76d7f03c0c62323202fdab3e4ab35854855 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Fri, 9 Jan 2026 09:00:32 -0500 Subject: Hide muted chats --- src/lib/nip51.ts | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/lib/nip51.ts (limited to 'src/lib') diff --git a/src/lib/nip51.ts b/src/lib/nip51.ts new file mode 100644 index 00000000..142f0bbf --- /dev/null +++ b/src/lib/nip51.ts @@ -0,0 +1,47 @@ +import { SimplePool } from 'nostr-tools/pool'; +const pool = new SimplePool(); + +import { PUBLIC_DM_RELAYS } from '$env/static/public'; +const DM_RELAYS_LIST = PUBLIC_DM_RELAYS.split(','); + +// export const mute = async (pubkey: string, hidden: bool) => { + +// } + +// export const unmute = async (pubkey: string) => { + +// } + +export const mutedAccounts = async (user: object): Set => { + const { shown, hidden } = await getMuteLists(user); + let muted = new Set(); + for (const pubkey of shown) { + muted.add(pubkey); + } + for (const pubkey of hidden) { + muted.add(pubkey); + } + return muted; +} + +const getMuteLists = async (user: object): object => { + const listEvents = await pool.querySync( + DM_RELAYS_LIST, { kinds: [10000], "authors": [user.pubkey], limit: 1 } + ); + if (listEvents.length == 0) { + return { shown: [], hidden: [] }; + } + + let shown = []; + for (const tag of listEvents[0].tags) { + if (tag.length >= 2 && tag[0] == "p") { + shown.push(tag[1]); + } + } + + return { shown, hidden: [] }; +} + +// const publishMuteList = async (shown: Array, hidden: Array) => { + +// } -- cgit v1.2.3