diff --git a/src/storages/UserStore.ts b/src/storages/UserStore.ts index 02a3b03e..f9cc068d 100644 --- a/src/storages/UserStore.ts +++ b/src/storages/UserStore.ts @@ -3,32 +3,39 @@ import { DittoEvent } from '@/interfaces/DittoEvent.ts'; import { getTagSet } from '@/tags.ts'; export class UserStore implements NStore { - store: NStore; - pubkey: string; - #muteList: Promise; + private store: NStore; + private pubkey: string; + private muteList: Promise; constructor(pubkey: string, store: NStore) { this.pubkey = pubkey; this.store = store; - this.#muteList = this.#getMuteList(); + this.muteList = this.getMuteList(); } async event(event: NostrEvent, opts?: { signal?: AbortSignal }): Promise { return await this.store.event(event, opts); } - /** Query events that `pubkey` did not block */ + /** + * Query events that `pubkey` did not block + * https://github.com/nostr-protocol/nips/blob/master/51.md#standard-lists + */ async query(filters: NostrFilter[], opts: { signal?: AbortSignal; limit?: number } = {}): Promise { const allEvents = await this.store.query(filters, opts); - const blockedUsers = getTagSet((await this.#muteList).tags, 'p'); + const mutedPubkeysEvent = await this.muteList; + if (!mutedPubkeysEvent) { + return allEvents; + } + const mutedPubkeys = getTagSet(mutedPubkeysEvent.tags, 'p'); return allEvents.filter((event) => { - blockedUsers.has(event.pubkey) === false; + mutedPubkeys.has(event.pubkey) === false; }); } - async #getMuteList(): Promise { + private async getMuteList(): Promise { const [muteList] = await this.query([{ authors: [this.pubkey], kinds: [10000], limit: 1 }], { signal: AbortSignal.timeout(5000), limit: 1,