refactor(MuteListPolicy): simplify condition

This commit is contained in:
P. Reis 2024-05-10 18:03:35 -03:00
parent 4069ddc02c
commit 3970bb81f7
1 changed files with 5 additions and 7 deletions

View File

@ -6,15 +6,13 @@ export class MuteListPolicy implements NPolicy {
constructor(private pubkey: string, private store: NStore) {}
async call(event: NostrEvent): Promise<NostrRelayOK> {
const allowEvent: NostrRelayOK = ['OK', event.id, true, ''];
const blockEvent: NostrRelayOK = ['OK', event.id, false, 'You are banned in this server.'];
const [muteList] = await this.store.query([{ authors: [this.pubkey], kinds: [10000], limit: 1 }]);
if (!muteList) return allowEvent;
const pubkeys = getTagSet(muteList?.tags ?? [], 'p');
const mutedPubkeys = getTagSet(muteList.tags, 'p');
if (mutedPubkeys.has(event.pubkey)) return blockEvent;
if (pubkeys.has(event.pubkey)) {
return ['OK', event.id, false, 'You are banned in this server.'];
}
return allowEvent;
return ['OK', event.id, true, ''];
}
}