refactor: optimize note interaction data processing

This commit is contained in:
codytseng
2025-07-03 21:46:12 +08:00
parent 2d2153448d
commit 18ce08ce07
13 changed files with 289 additions and 293 deletions

View File

@@ -11,6 +11,7 @@ import { formatPubkey, isValidPubkey, pubkeyToNpub } from '@/lib/pubkey'
import client from '@/services/client.service'
import indexedDb from '@/services/indexed-db.service'
import storage from '@/services/local-storage.service'
import noteStatsService from '@/services/note-stats.service'
import { ISigner, TAccount, TAccountPointer, TDraftEvent, TProfile, TRelayList } from '@/types'
import { hexToBytes } from '@noble/hashes/utils'
import dayjs from 'dayjs'
@@ -276,6 +277,29 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
}
}, [account])
useEffect(() => {
if (!account) return
const initInteractions = async () => {
const pubkey = account.pubkey
const relayList = await client.fetchRelayList(pubkey)
const events = await client.fetchEvents(relayList.write.slice(0, 4), [
{
authors: [pubkey],
kinds: [kinds.Reaction, kinds.Repost],
limit: 100
},
{
'#P': [pubkey],
kinds: [kinds.Zap],
limit: 100
}
])
noteStatsService.updateNoteStatsByEvents(events)
}
initInteractions()
}, [account])
useEffect(() => {
if (signer) {
client.signer = signer