From f94df67ad8307460d344f95811705bebee015f2f Mon Sep 17 00:00:00 2001 From: codytseng Date: Sat, 9 Aug 2025 13:05:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/NoteStats/LikeButton.tsx | 11 ++++++++--- src/components/NoteStats/ReplyButton.tsx | 2 +- src/components/NoteStats/RepostButton.tsx | 8 ++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/components/NoteStats/LikeButton.tsx b/src/components/NoteStats/LikeButton.tsx index 291a046d..58da9307 100644 --- a/src/components/NoteStats/LikeButton.tsx +++ b/src/components/NoteStats/LikeButton.tsx @@ -8,6 +8,7 @@ import { useNoteStatsById } from '@/hooks/useNoteStatsById' import { createReactionDraftEvent } from '@/lib/draft-event' import { useNostr } from '@/providers/NostrProvider' import { useScreenSize } from '@/providers/ScreenSizeProvider' +import { useUserTrust } from '@/providers/UserTrustProvider' import noteStatsService from '@/services/note-stats.service' import { Loader, SmilePlus } from 'lucide-react' import { Event } from 'nostr-tools' @@ -22,15 +23,19 @@ export default function LikeButton({ event }: { event: Event }) { const { t } = useTranslation() const { isSmallScreen } = useScreenSize() const { pubkey, publish, checkLogin } = useNostr() + const { hideUntrustedInteractions, isUserTrusted } = useUserTrust() const [liking, setLiking] = useState(false) const [isEmojiReactionsOpen, setIsEmojiReactionsOpen] = useState(false) const [isPickerOpen, setIsPickerOpen] = useState(false) const noteStats = useNoteStatsById(event.id) const { myLastEmoji, likeCount } = useMemo(() => { const stats = noteStats || {} - const like = stats.likes?.find((like) => like.pubkey === pubkey) - return { myLastEmoji: like?.emoji, likeCount: stats.likes?.length } - }, [noteStats, pubkey]) + const myLike = stats.likes?.find((like) => like.pubkey === pubkey) + const likes = hideUntrustedInteractions + ? stats.likes?.filter((like) => isUserTrusted(like.pubkey)) + : stats.likes + return { myLastEmoji: myLike?.emoji, likeCount: likes?.length } + }, [noteStats, pubkey, hideUntrustedInteractions]) const like = async (emoji: string) => { checkLogin(async () => { diff --git a/src/components/NoteStats/ReplyButton.tsx b/src/components/NoteStats/ReplyButton.tsx index 9771ffbc..90add1b6 100644 --- a/src/components/NoteStats/ReplyButton.tsx +++ b/src/components/NoteStats/ReplyButton.tsx @@ -18,7 +18,7 @@ export default function ReplyButton({ event }: { event: Event }) { return repliesMap.get(event.id)?.events.filter((evt) => isUserTrusted(evt.pubkey)).length ?? 0 } return repliesMap.get(event.id)?.events.length ?? 0 - }, [repliesMap, event.id, isUserTrusted]) + }, [repliesMap, event.id, hideUntrustedInteractions]) const [open, setOpen] = useState(false) return ( diff --git a/src/components/NoteStats/RepostButton.tsx b/src/components/NoteStats/RepostButton.tsx index 2b747a4a..82555ec8 100644 --- a/src/components/NoteStats/RepostButton.tsx +++ b/src/components/NoteStats/RepostButton.tsx @@ -12,6 +12,7 @@ import { getNoteBech32Id } from '@/lib/event' import { cn } from '@/lib/utils' import { useNostr } from '@/providers/NostrProvider' import { useScreenSize } from '@/providers/ScreenSizeProvider' +import { useUserTrust } from '@/providers/UserTrustProvider' import noteStatsService from '@/services/note-stats.service' import { Loader, PencilLine, Repeat } from 'lucide-react' import { Event, kinds } from 'nostr-tools' @@ -23,6 +24,7 @@ import { formatCount } from './utils' export default function RepostButton({ event }: { event: Event }) { const { t } = useTranslation() const { isSmallScreen } = useScreenSize() + const { hideUntrustedInteractions, isUserTrusted } = useUserTrust() const { publish, checkLogin, pubkey } = useNostr() const noteStats = useNoteStatsById(event.id) const [reposting, setReposting] = useState(false) @@ -30,10 +32,12 @@ export default function RepostButton({ event }: { event: Event }) { const [isDrawerOpen, setIsDrawerOpen] = useState(false) const { repostCount, hasReposted } = useMemo(() => { return { - repostCount: noteStats?.repostPubkeySet?.size, + repostCount: hideUntrustedInteractions + ? noteStats?.reposts?.filter((repost) => isUserTrusted(repost.pubkey)).length + : noteStats?.reposts?.length, hasReposted: pubkey ? noteStats?.repostPubkeySet?.has(pubkey) : false } - }, [noteStats, event.id]) + }, [noteStats, event.id, hideUntrustedInteractions]) const canRepost = !hasReposted && !reposting const repost = async () => {