diff options
Diffstat (limited to 'src/lib/nip51.ts')
| -rw-r--r-- | src/lib/nip51.ts | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/lib/nip51.ts b/src/lib/nip51.ts index 81a1a9d3..8d6f76db 100644 --- a/src/lib/nip51.ts +++ b/src/lib/nip51.ts @@ -1,6 +1,6 @@ import { SimplePool } from 'nostr-tools/pool'; import { verifyEvent } from 'nostr-tools/pure'; -import { signEvent } from '$lib/nip07'; +import { signEvent, encrypt, decrypt } from '$lib/nip07'; const pool = new SimplePool(); import { PUBLIC_DM_RELAYS } from '$env/static/public'; @@ -8,7 +8,11 @@ const DM_RELAYS_LIST = PUBLIC_DM_RELAYS.split(','); export const mute = async (user: object, pubkey: string, hide: bool) => { let { shown, hidden } = await getMuteLists(user); - shown.push(["p", pubkey]); + if (hide) { + hidden.push(["p", pubkey]); + } else { + shown.push(["p", pubkey]); + } await publishMuteList(user, shown, hidden); } @@ -18,17 +22,23 @@ const tagMatches = (tag: string[], pubkey: string): bool => export const unmute = async (user: object, pubkey: string) => { let { shown, hidden } = await getMuteLists(user); shown = shown.filter(tag => !tagMatches(tag, pubkey)); + hidden = hidden.filter(tag => !tagMatches(tag, pubkey)); await publishMuteList(user, shown, hidden); } export const mutedAccounts = async (user: object): Set<string> => { - const { shown } = await getMuteLists(user); + const { shown, hidden } = await getMuteLists(user); let muted = new Set<string>(); for (const tag of shown) { if (tag.length >= 2 && tag[0] === "p") { muted.add(tag[1]); } } + for (const tag of hidden) { + if (tag.length >= 2 && tag[0] === "p") { + muted.add(tag[1]); + } + } return muted; } @@ -37,18 +47,22 @@ const getMuteLists = async (user: object): object => { DM_RELAYS_LIST, { kinds: [10000], "authors": [user.pubkey], limit: 1 } ); if (listEvents.length == 0) { - return { shown: [], hidden: "" }; + return { shown: [], hidden: [] }; } - return { shown: listEvents[0].tags, hidden: listEvents[0].content }; + return { + shown: listEvents[0].tags, + hidden: listEvents[0].content == "" ? [] : + await decrypt(listEvents[0].content, user, user.pubkey) + }; } -const publishMuteList = async (user: object, shown: Array<string>, hidden: string) => { +const publishMuteList = async (user: object, shown: string[], hidden: string[]) => { const event = await signEvent({ kind: 10000, created_at: Math.floor(Date.now() / 1000), tags: shown, - content: hidden + content: await encrypt(hidden, user, user.pubkey) }, user); return Promise.any(pool.publish(DM_RELAYS_LIST, event)); } |
