notification.ts raw
1 import { kinds, NostrEvent } from 'nostr-tools'
2 import { isMentioningMutedUsers } from './event'
3 import { tagNameEquals } from './tag'
4
5 export function notificationFilter(
6 event: NostrEvent,
7 {
8 pubkey,
9 mutePubkeySet,
10 hideContentMentioningMutedUsers,
11 hideUntrustedNotifications,
12 isUserTrusted
13 }: {
14 pubkey?: string | null
15 mutePubkeySet: Set<string>
16 hideContentMentioningMutedUsers?: boolean
17 hideUntrustedNotifications?: boolean
18 isUserTrusted: (pubkey: string) => boolean
19 }
20 ): boolean {
21 if (
22 mutePubkeySet.has(event.pubkey) ||
23 (hideContentMentioningMutedUsers && isMentioningMutedUsers(event, mutePubkeySet)) ||
24 (hideUntrustedNotifications && !isUserTrusted(event.pubkey))
25 ) {
26 return false
27 }
28
29 if (pubkey && event.kind === kinds.Reaction) {
30 const targetPubkey = event.tags.findLast(tagNameEquals('p'))?.[1]
31 if (targetPubkey !== pubkey) return false
32 }
33
34 return true
35 }
36