fix: use eventStore.timeline() to query local events

- Subscribe to timeline to get initial cached events
- Unsubscribe immediately after reading initial value
- This works with IEventStore interface correctly
This commit is contained in:
Gigi
2025-10-19 12:04:49 +02:00
parent 1ba375e93e
commit 0e98ddeef4

View File

@@ -129,17 +129,22 @@ class ReadingProgressController {
this.lastLoadedPubkey = pubkey
try {
// 1. First, load from local event store (instant, non-blocking)
const localEvents = eventStore.getEvents({
// 1. First, get events from local event store timeline (instant, non-blocking)
const timeline = eventStore.timeline({
kinds: [KINDS.ReadingProgress],
authors: [pubkey]
})
console.log('📊 [ReadingProgress] Found', localEvents.length, 'events in local store')
// Subscribe to get initial events synchronously
const subscription = timeline.subscribe((localEvents) => {
console.log('📊 [ReadingProgress] Found', localEvents.length, 'events in local store')
if (localEvents.length > 0) {
this.processEvents(localEvents)
}
})
if (localEvents.length > 0) {
this.processEvents(localEvents)
}
// Unsubscribe immediately after getting initial value
subscription.unsubscribe()
// 2. Then fetch from relays (incremental or full) to augment local data
const lastSynced = force ? null : this.getLastSyncedAt(pubkey)