feat: 💨

This commit is contained in:
codytseng
2025-09-10 22:15:31 +08:00
parent 5f165308c1
commit 63869ef3b7
5 changed files with 72 additions and 28 deletions

35
src/lib/notification.ts Normal file
View File

@@ -0,0 +1,35 @@
import { kinds, NostrEvent } from 'nostr-tools'
import { isMentioningMutedUsers } from './event'
import { tagNameEquals } from './tag'
export function notificationFilter(
event: NostrEvent,
{
pubkey,
mutePubkeySet,
hideContentMentioningMutedUsers,
hideUntrustedNotifications,
isUserTrusted
}: {
pubkey?: string | null
mutePubkeySet: Set<string>
hideContentMentioningMutedUsers?: boolean
hideUntrustedNotifications?: boolean
isUserTrusted: (pubkey: string) => boolean
}
): boolean {
if (
mutePubkeySet.has(event.pubkey) ||
(hideContentMentioningMutedUsers && isMentioningMutedUsers(event, mutePubkeySet)) ||
(hideUntrustedNotifications && !isUserTrusted(event.pubkey))
) {
return false
}
if (pubkey && event.kind === kinds.Reaction) {
const targetPubkey = event.tags.findLast(tagNameEquals('p'))?.[1]
if (targetPubkey !== pubkey) return false
}
return true
}