fix: 🐛

This commit is contained in:
codytseng
2025-07-04 23:35:55 +08:00
parent e53d74edd1
commit 9da5e6663e

View File

@@ -116,14 +116,26 @@ class NoteStatsService {
return this.noteStatsMap.get(id) return this.noteStatsMap.get(id)
} }
addZap(pubkey: string, eventId: string, pr: string, amount: number, comment?: string) { addZap(
const old = this.noteStatsMap.get(eventId) pubkey: string,
const zaps = old?.zaps || [] eventId: string,
this.noteStatsMap.set(eventId, { pr: string,
...old, amount: number,
zaps: [...zaps, { pr, pubkey, amount, comment }].sort((a, b) => b.amount - a.amount) comment?: string,
}) notify: boolean = true
return this.noteStatsMap ) {
const old = this.noteStatsMap.get(eventId) || {}
const zapPrSet = old.zapPrSet || new Set()
const zaps = old.zaps || []
if (zapPrSet.has(pr)) return
zapPrSet.add(pr)
zaps.push({ pr, pubkey, amount, comment })
this.noteStatsMap.set(eventId, { ...old, zapPrSet, zaps })
if (notify) {
this.notifyNoteStats(eventId)
}
return eventId
} }
updateNoteStatsByEvents(events: Event[]) { updateNoteStatsByEvents(events: Event[]) {
@@ -192,15 +204,7 @@ class NoteStatsService {
const { originalEventId, senderPubkey, invoice, amount, comment } = info const { originalEventId, senderPubkey, invoice, amount, comment } = info
if (!originalEventId || !senderPubkey) return if (!originalEventId || !senderPubkey) return
const old = this.noteStatsMap.get(originalEventId) || {} return this.addZap(senderPubkey, originalEventId, invoice, amount, comment, false)
const zapPrSet = old.zapPrSet || new Set()
const zaps = old.zaps || []
if (zapPrSet.has(invoice)) return
zapPrSet.add(invoice)
zaps.push({ pr: invoice, pubkey: senderPubkey, amount, comment })
this.noteStatsMap.set(originalEventId, { ...old, zapPrSet, zaps })
return originalEventId
} }
} }