feat: create MuteListPolicy class

This commit is contained in:
P. Reis 2024-05-10 10:19:15 -03:00
parent afcf28b506
commit c85f31f63f
1 changed files with 23 additions and 0 deletions

View File

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