From c777a1564e64cd63a6b83caa60291c7460335026 Mon Sep 17 00:00:00 2001 From: codytseng Date: Mon, 2 Jun 2025 12:29:48 +0800 Subject: [PATCH] fix: reply count --- src/components/NoteStats/ReplyButton.tsx | 6 ++++-- src/components/NotificationList/index.tsx | 4 ++-- src/providers/UserTrustProvider.tsx | 15 +++++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/components/NoteStats/ReplyButton.tsx b/src/components/NoteStats/ReplyButton.tsx index 9db92af7..50380355 100644 --- a/src/components/NoteStats/ReplyButton.tsx +++ b/src/components/NoteStats/ReplyButton.tsx @@ -1,5 +1,6 @@ import { useNostr } from '@/providers/NostrProvider' import { useReply } from '@/providers/ReplyProvider' +import { useUserTrust } from '@/providers/UserTrustProvider' import { MessageCircle } from 'lucide-react' import { Event } from 'nostr-tools' import { useMemo, useState } from 'react' @@ -11,9 +12,10 @@ export default function ReplyButton({ event }: { event: Event }) { const { t } = useTranslation() const { checkLogin } = useNostr() const { repliesMap } = useReply() + const { isUserTrusted } = useUserTrust() const replyCount = useMemo( - () => repliesMap.get(event.id)?.events.length || 0, - [repliesMap, event.id] + () => repliesMap.get(event.id)?.events.filter((evt) => isUserTrusted(evt.pubkey)).length || 0, + [repliesMap, event.id, isUserTrusted] ) const [open, setOpen] = useState(false) diff --git a/src/components/NotificationList/index.tsx b/src/components/NotificationList/index.tsx index e7b5fd3c..dcfffc51 100644 --- a/src/components/NotificationList/index.tsx +++ b/src/components/NotificationList/index.tsx @@ -23,7 +23,7 @@ const NotificationList = forwardRef((_, ref) => { const { t } = useTranslation() const { current } = usePrimaryPage() const { pubkey } = useNostr() - const { enabled: hideUntrustedEvents, isUserTrusted } = useUserTrust() + const { isUserTrusted } = useUserTrust() const { clearNewNotifications, getNotificationsSeenAt } = useNotification() const { updateNoteStatsByEvents } = useNoteStats() const [notificationType, setNotificationType] = useState('all') @@ -135,7 +135,7 @@ const NotificationList = forwardRef((_, ref) => { setNewNotifications(visibleNotifications.slice(0, index)) setOldNotifications(visibleNotifications.slice(index)) } - }, [notifications, lastReadTime, showCount, hideUntrustedEvents]) + }, [notifications, lastReadTime, showCount, isUserTrusted]) useEffect(() => { const options = { diff --git a/src/providers/UserTrustProvider.tsx b/src/providers/UserTrustProvider.tsx index ed4b9677..0bca8166 100644 --- a/src/providers/UserTrustProvider.tsx +++ b/src/providers/UserTrustProvider.tsx @@ -1,5 +1,5 @@ import client from '@/services/client.service' -import { createContext, useContext, useEffect, useState } from 'react' +import { createContext, useCallback, useContext, useEffect, useState } from 'react' import { useNostr } from './NostrProvider' import storage from '@/services/local-storage.service' @@ -41,16 +41,19 @@ export function UserTrustProvider({ children }: { children: React.ReactNode }) { initWoT() }, [currentPubkey]) + const isUserTrusted = useCallback( + (pubkey: string) => { + if (!currentPubkey || !enabled) return true + return wotSet.has(pubkey) + }, + [enabled] + ) + const updateEnabled = (enabled: boolean) => { setEnabled(enabled) storage.setHideUntrustedEvents(enabled) } - const isUserTrusted = (pubkey: string) => { - if (!currentPubkey || !enabled) return true - return wotSet.has(pubkey) - } - return ( {children}