mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-26 09:44:25 +01:00
refactor(MuteListPolicy): simplify condition
This commit is contained in:
@@ -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, ''];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user