refactor: remove muteList as a field

This commit is contained in:
P. Reis 2024-04-26 16:05:53 -03:00
parent ddc84bf47a
commit c87db6d1f8
1 changed files with 2 additions and 7 deletions

View File

@ -5,12 +5,10 @@ import { getTagSet } from '@/tags.ts';
export class UserStore implements NStore { export class UserStore implements NStore {
private store: NStore; private store: NStore;
private pubkey: string; private pubkey: string;
private muteList: Promise<DittoEvent | undefined>;
constructor(pubkey: string, store: NStore) { constructor(pubkey: string, store: NStore) {
this.pubkey = pubkey; this.pubkey = pubkey;
this.store = store; this.store = store;
this.muteList = this.getMuteList();
} }
async event(event: NostrEvent, opts?: { signal?: AbortSignal }): Promise<void> { async event(event: NostrEvent, opts?: { signal?: AbortSignal }): Promise<void> {
@ -24,7 +22,7 @@ export class UserStore implements NStore {
async query(filters: NostrFilter[], opts: { signal?: AbortSignal; limit?: number } = {}): Promise<DittoEvent[]> { async query(filters: NostrFilter[], opts: { signal?: AbortSignal; limit?: number } = {}): Promise<DittoEvent[]> {
const allEvents = await this.store.query(filters, opts); const allEvents = await this.store.query(filters, opts);
const mutedPubkeysEvent = await this.muteList; const mutedPubkeysEvent = await this.getMuteList();
if (!mutedPubkeysEvent) { if (!mutedPubkeysEvent) {
return allEvents; return allEvents;
} }
@ -36,10 +34,7 @@ export class UserStore implements NStore {
} }
private async getMuteList(): Promise<DittoEvent | undefined> { private async getMuteList(): Promise<DittoEvent | undefined> {
const [muteList] = await this.query([{ authors: [this.pubkey], kinds: [10000], limit: 1 }], { const [muteList] = await this.store.query([{ authors: [this.pubkey], kinds: [10000], limit: 1 }]);
signal: AbortSignal.timeout(5000),
limit: 1,
});
return muteList; return muteList;
} }
} }