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,4 +1,7 @@
import { isMentioningMutedUsers } from '@/lib/event'
import { cn } from '@/lib/utils'
import { useContentPolicy } from '@/providers/ContentPolicyProvider'
import { useMuteList } from '@/providers/MuteListProvider'
import { useNostr } from '@/providers/NostrProvider'
import { useReply } from '@/providers/ReplyProvider'
import { useUserTrust } from '@/providers/UserTrustProvider'
@ -14,18 +17,29 @@ export default function ReplyButton({ event }: { event: Event }) {
const { pubkey, checkLogin } = useNostr()
const { repliesMap } = useReply()
const { hideUntrustedInteractions, isUserTrusted } = useUserTrust()
const { mutePubkeySet } = useMuteList()
const { hideContentMentioningMutedUsers } = useContentPolicy()
const { replyCount, hasReplied } = useMemo(() => {
const hasReplied = pubkey
? repliesMap.get(event.id)?.events.some((evt) => evt.pubkey === pubkey)
: false
if (hideUntrustedInteractions) {
return {
replyCount:
repliesMap.get(event.id)?.events.filter((evt) => isUserTrusted(evt.pubkey)).length ?? 0,
hasReplied
}
return {
replyCount:
repliesMap.get(event.id)?.events.filter((evt) => {
if (hideUntrustedInteractions && !isUserTrusted(evt.pubkey)) {
return false
}
if (mutePubkeySet.has(evt.pubkey)) {
return false
}
if (hideContentMentioningMutedUsers && isMentioningMutedUsers(evt, mutePubkeySet)) {
return false
}
return true
}).length ?? 0,
hasReplied
}
return { replyCount: repliesMap.get(event.id)?.events.length ?? 0, hasReplied }
}, [repliesMap, event.id, hideUntrustedInteractions])
const [open, setOpen] = useState(false)