fix: reply count

This commit is contained in:
codytseng
2025-06-02 12:29:48 +08:00
parent d2ceb16a58
commit c777a1564e
3 changed files with 15 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
import { useNostr } from '@/providers/NostrProvider' import { useNostr } from '@/providers/NostrProvider'
import { useReply } from '@/providers/ReplyProvider' import { useReply } from '@/providers/ReplyProvider'
import { useUserTrust } from '@/providers/UserTrustProvider'
import { MessageCircle } from 'lucide-react' import { MessageCircle } from 'lucide-react'
import { Event } from 'nostr-tools' import { Event } from 'nostr-tools'
import { useMemo, useState } from 'react' import { useMemo, useState } from 'react'
@@ -11,9 +12,10 @@ export default function ReplyButton({ event }: { event: Event }) {
const { t } = useTranslation() const { t } = useTranslation()
const { checkLogin } = useNostr() const { checkLogin } = useNostr()
const { repliesMap } = useReply() const { repliesMap } = useReply()
const { isUserTrusted } = useUserTrust()
const replyCount = useMemo( const replyCount = useMemo(
() => repliesMap.get(event.id)?.events.length || 0, () => repliesMap.get(event.id)?.events.filter((evt) => isUserTrusted(evt.pubkey)).length || 0,
[repliesMap, event.id] [repliesMap, event.id, isUserTrusted]
) )
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)

View File

@@ -23,7 +23,7 @@ const NotificationList = forwardRef((_, ref) => {
const { t } = useTranslation() const { t } = useTranslation()
const { current } = usePrimaryPage() const { current } = usePrimaryPage()
const { pubkey } = useNostr() const { pubkey } = useNostr()
const { enabled: hideUntrustedEvents, isUserTrusted } = useUserTrust() const { isUserTrusted } = useUserTrust()
const { clearNewNotifications, getNotificationsSeenAt } = useNotification() const { clearNewNotifications, getNotificationsSeenAt } = useNotification()
const { updateNoteStatsByEvents } = useNoteStats() const { updateNoteStatsByEvents } = useNoteStats()
const [notificationType, setNotificationType] = useState<TNotificationType>('all') const [notificationType, setNotificationType] = useState<TNotificationType>('all')
@@ -135,7 +135,7 @@ const NotificationList = forwardRef((_, ref) => {
setNewNotifications(visibleNotifications.slice(0, index)) setNewNotifications(visibleNotifications.slice(0, index))
setOldNotifications(visibleNotifications.slice(index)) setOldNotifications(visibleNotifications.slice(index))
} }
}, [notifications, lastReadTime, showCount, hideUntrustedEvents]) }, [notifications, lastReadTime, showCount, isUserTrusted])
useEffect(() => { useEffect(() => {
const options = { const options = {

View File

@@ -1,5 +1,5 @@
import client from '@/services/client.service' 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 { useNostr } from './NostrProvider'
import storage from '@/services/local-storage.service' import storage from '@/services/local-storage.service'
@@ -41,16 +41,19 @@ export function UserTrustProvider({ children }: { children: React.ReactNode }) {
initWoT() initWoT()
}, [currentPubkey]) }, [currentPubkey])
const isUserTrusted = useCallback(
(pubkey: string) => {
if (!currentPubkey || !enabled) return true
return wotSet.has(pubkey)
},
[enabled]
)
const updateEnabled = (enabled: boolean) => { const updateEnabled = (enabled: boolean) => {
setEnabled(enabled) setEnabled(enabled)
storage.setHideUntrustedEvents(enabled) storage.setHideUntrustedEvents(enabled)
} }
const isUserTrusted = (pubkey: string) => {
if (!currentPubkey || !enabled) return true
return wotSet.has(pubkey)
}
return ( return (
<UserTrustContext.Provider value={{ enabled, updateEnabled, isUserTrusted }}> <UserTrustContext.Provider value={{ enabled, updateEnabled, isUserTrusted }}>
{children} {children}