fix: 🐛

This commit is contained in:
codytseng
2025-08-09 13:05:59 +08:00
parent f2c87b8d5f
commit f94df67ad8
3 changed files with 15 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ import { useNoteStatsById } from '@/hooks/useNoteStatsById'
import { createReactionDraftEvent } from '@/lib/draft-event' import { createReactionDraftEvent } from '@/lib/draft-event'
import { useNostr } from '@/providers/NostrProvider' import { useNostr } from '@/providers/NostrProvider'
import { useScreenSize } from '@/providers/ScreenSizeProvider' import { useScreenSize } from '@/providers/ScreenSizeProvider'
import { useUserTrust } from '@/providers/UserTrustProvider'
import noteStatsService from '@/services/note-stats.service' import noteStatsService from '@/services/note-stats.service'
import { Loader, SmilePlus } from 'lucide-react' import { Loader, SmilePlus } from 'lucide-react'
import { Event } from 'nostr-tools' import { Event } from 'nostr-tools'
@@ -22,15 +23,19 @@ export default function LikeButton({ event }: { event: Event }) {
const { t } = useTranslation() const { t } = useTranslation()
const { isSmallScreen } = useScreenSize() const { isSmallScreen } = useScreenSize()
const { pubkey, publish, checkLogin } = useNostr() const { pubkey, publish, checkLogin } = useNostr()
const { hideUntrustedInteractions, isUserTrusted } = useUserTrust()
const [liking, setLiking] = useState(false) const [liking, setLiking] = useState(false)
const [isEmojiReactionsOpen, setIsEmojiReactionsOpen] = useState(false) const [isEmojiReactionsOpen, setIsEmojiReactionsOpen] = useState(false)
const [isPickerOpen, setIsPickerOpen] = useState(false) const [isPickerOpen, setIsPickerOpen] = useState(false)
const noteStats = useNoteStatsById(event.id) const noteStats = useNoteStatsById(event.id)
const { myLastEmoji, likeCount } = useMemo(() => { const { myLastEmoji, likeCount } = useMemo(() => {
const stats = noteStats || {} const stats = noteStats || {}
const like = stats.likes?.find((like) => like.pubkey === pubkey) const myLike = stats.likes?.find((like) => like.pubkey === pubkey)
return { myLastEmoji: like?.emoji, likeCount: stats.likes?.length } const likes = hideUntrustedInteractions
}, [noteStats, pubkey]) ? stats.likes?.filter((like) => isUserTrusted(like.pubkey))
: stats.likes
return { myLastEmoji: myLike?.emoji, likeCount: likes?.length }
}, [noteStats, pubkey, hideUntrustedInteractions])
const like = async (emoji: string) => { const like = async (emoji: string) => {
checkLogin(async () => { checkLogin(async () => {

View File

@@ -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.filter((evt) => isUserTrusted(evt.pubkey)).length ?? 0
} }
return repliesMap.get(event.id)?.events.length ?? 0 return repliesMap.get(event.id)?.events.length ?? 0
}, [repliesMap, event.id, isUserTrusted]) }, [repliesMap, event.id, hideUntrustedInteractions])
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
return ( return (

View File

@@ -12,6 +12,7 @@ import { getNoteBech32Id } from '@/lib/event'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
import { useNostr } from '@/providers/NostrProvider' import { useNostr } from '@/providers/NostrProvider'
import { useScreenSize } from '@/providers/ScreenSizeProvider' import { useScreenSize } from '@/providers/ScreenSizeProvider'
import { useUserTrust } from '@/providers/UserTrustProvider'
import noteStatsService from '@/services/note-stats.service' import noteStatsService from '@/services/note-stats.service'
import { Loader, PencilLine, Repeat } from 'lucide-react' import { Loader, PencilLine, Repeat } from 'lucide-react'
import { Event, kinds } from 'nostr-tools' import { Event, kinds } from 'nostr-tools'
@@ -23,6 +24,7 @@ import { formatCount } from './utils'
export default function RepostButton({ event }: { event: Event }) { export default function RepostButton({ event }: { event: Event }) {
const { t } = useTranslation() const { t } = useTranslation()
const { isSmallScreen } = useScreenSize() const { isSmallScreen } = useScreenSize()
const { hideUntrustedInteractions, isUserTrusted } = useUserTrust()
const { publish, checkLogin, pubkey } = useNostr() const { publish, checkLogin, pubkey } = useNostr()
const noteStats = useNoteStatsById(event.id) const noteStats = useNoteStatsById(event.id)
const [reposting, setReposting] = useState(false) const [reposting, setReposting] = useState(false)
@@ -30,10 +32,12 @@ export default function RepostButton({ event }: { event: Event }) {
const [isDrawerOpen, setIsDrawerOpen] = useState(false) const [isDrawerOpen, setIsDrawerOpen] = useState(false)
const { repostCount, hasReposted } = useMemo(() => { const { repostCount, hasReposted } = useMemo(() => {
return { 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 hasReposted: pubkey ? noteStats?.repostPubkeySet?.has(pubkey) : false
} }
}, [noteStats, event.id]) }, [noteStats, event.id, hideUntrustedInteractions])
const canRepost = !hasReposted && !reposting const canRepost = !hasReposted && !reposting
const repost = async () => { const repost = async () => {