feat: hide content mentioning muted users (#524)

Co-authored-by: mleku <me@mleku.dev>
This commit is contained in:
Cody Tseng 2025-09-02 22:18:34 +08:00 committed by GitHub
parent d3578184fb
commit 3c657dfa8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 289 additions and 83 deletions

View file

@ -1,8 +1,10 @@
import { isMentioningMutedUsers } from '@/lib/event'
import { tagNameEquals } from '@/lib/tag'
import { useContentPolicy } from '@/providers/ContentPolicyProvider'
import { useMuteList } from '@/providers/MuteListProvider'
import client from '@/services/client.service'
import { Event, kinds, nip19, verifyEvent } from 'nostr-tools'
import { useEffect, useState } from 'react'
import { useEffect, useMemo, useState } from 'react'
import MainNoteCard from './MainNoteCard'
export default function RepostNoteCard({
@ -14,8 +16,19 @@ export default function RepostNoteCard({
className?: string
filterMutedNotes?: boolean
}) {
const { mutePubkeys } = useMuteList()
const { mutePubkeySet } = useMuteList()
const { hideContentMentioningMutedUsers } = useContentPolicy()
const [targetEvent, setTargetEvent] = useState<Event | null>(null)
const shouldHide = useMemo(() => {
if (!targetEvent) return true
if (filterMutedNotes && mutePubkeySet.has(targetEvent.pubkey)) {
return true
}
if (hideContentMentioningMutedUsers && isMentioningMutedUsers(targetEvent, mutePubkeySet)) {
return true
}
return false
}, [targetEvent, filterMutedNotes, hideContentMentioningMutedUsers, mutePubkeySet])
useEffect(() => {
const fetch = async () => {
try {
@ -56,10 +69,7 @@ export default function RepostNoteCard({
fetch()
}, [event])
if (!targetEvent) return null
if (filterMutedNotes && mutePubkeys.includes(targetEvent.pubkey)) {
return null
}
if (!targetEvent || shouldHide) return null
return <MainNoteCard className={className} reposter={event.pubkey} event={targetEvent} />
}

View file

@ -1,6 +1,9 @@
import { Skeleton } from '@/components/ui/skeleton'
import { isMentioningMutedUsers } from '@/lib/event'
import { useContentPolicy } from '@/providers/ContentPolicyProvider'
import { useMuteList } from '@/providers/MuteListProvider'
import { Event, kinds } from 'nostr-tools'
import { useMemo } from 'react'
import MainNoteCard from './MainNoteCard'
import RepostNoteCard from './RepostNoteCard'
@ -13,10 +16,18 @@ export default function NoteCard({
className?: string
filterMutedNotes?: boolean
}) {
const { mutePubkeys } = useMuteList()
if (filterMutedNotes && mutePubkeys.includes(event.pubkey)) {
return null
}
const { mutePubkeySet } = useMuteList()
const { hideContentMentioningMutedUsers } = useContentPolicy()
const shouldHide = useMemo(() => {
if (filterMutedNotes && mutePubkeySet.has(event.pubkey)) {
return true
}
if (hideContentMentioningMutedUsers && isMentioningMutedUsers(event, mutePubkeySet)) {
return true
}
return false
}, [event, filterMutedNotes, mutePubkeySet])
if (shouldHide) return null
if (event.kind === kinds.Repost) {
return (