fix: 🐛

This commit is contained in:
codytseng
2025-07-04 09:11:50 +08:00
parent af07240df0
commit b470ef4857
2 changed files with 17 additions and 13 deletions

View File

@@ -30,8 +30,8 @@ export default function RepostButton({ event }: { event: Event }) {
const [isDrawerOpen, setIsDrawerOpen] = useState(false)
const { repostCount, hasReposted } = useMemo(() => {
return {
repostCount: noteStats?.reposts?.size,
hasReposted: pubkey ? noteStats?.reposts?.has(pubkey) : false
repostCount: noteStats?.repostPubkeySet?.size,
hasReposted: pubkey ? noteStats?.repostPubkeySet?.has(pubkey) : false
}
}, [noteStats, event.id])
const canRepost = !hasReposted && !reposting
@@ -44,7 +44,7 @@ export default function RepostButton({ event }: { event: Event }) {
const timer = setTimeout(() => setReposting(false), 5000)
try {
const hasReposted = noteStats?.reposts?.has(pubkey)
const hasReposted = noteStats?.repostPubkeySet?.has(pubkey)
if (hasReposted) return
if (!noteStats?.updatedAt) {
const events = await noteStatsService.fetchNoteStats(event, pubkey)

View File

@@ -6,8 +6,10 @@ import dayjs from 'dayjs'
import { Event, Filter, kinds } from 'nostr-tools'
export type TNoteStats = {
likeIdSet: Set<string>
likes: { id: string; pubkey: string; created_at: number; emoji: TEmoji | string }[]
reposts: Set<string>
repostPubkeySet: Set<string>
zapPrSet: Set<string>
zaps: { pr: string; pubkey: string; amount: number; comment?: string }[]
updatedAt?: number
}
@@ -149,9 +151,9 @@ class NoteStatsService {
if (!targetEventId) return
const old = this.noteStatsMap.get(targetEventId) || {}
const likeIdSet = old.likeIdSet || new Set()
const likes = old.likes || []
const exists = likes.find((l) => l.id === evt.id)
if (exists) return
if (likeIdSet.has(evt.id)) return
let emoji: TEmoji | string = evt.content.trim()
if (!emoji) return
@@ -167,8 +169,9 @@ class NoteStatsService {
}
}
likeIdSet.add(evt.id)
likes.push({ id: evt.id, pubkey: evt.pubkey, created_at: evt.created_at, emoji })
this.noteStatsMap.set(targetEventId, { ...old, likes })
this.noteStatsMap.set(targetEventId, { ...old, likeIdSet, likes })
return targetEventId
}
@@ -177,9 +180,9 @@ class NoteStatsService {
if (!eventId) return
const old = this.noteStatsMap.get(eventId) || {}
const reposts = old.reposts || new Set()
reposts.add(evt.id)
this.noteStatsMap.set(eventId, { ...old, reposts })
const repostPubkeySet = old.repostPubkeySet || new Set()
repostPubkeySet.add(evt.pubkey)
this.noteStatsMap.set(eventId, { ...old, repostPubkeySet })
return eventId
}
@@ -190,12 +193,13 @@ class NoteStatsService {
if (!originalEventId || !senderPubkey) return
const old = this.noteStatsMap.get(originalEventId) || {}
const zapPrSet = old.zapPrSet || new Set()
const zaps = old.zaps || []
const exists = zaps.find((zap) => zap.pr === invoice)
if (exists) return
if (zapPrSet.has(invoice)) return
zapPrSet.add(invoice)
zaps.push({ pr: invoice, pubkey: senderPubkey, amount, comment })
this.noteStatsMap.set(originalEventId, { ...old, zaps })
this.noteStatsMap.set(originalEventId, { ...old, zapPrSet, zaps })
return originalEventId
}
}