mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-15 01:46:53 +02:00
fix: also subscribe to eventStore.timeline() to process existing zaps
The insert$ stream only fires for NEW events being added. If events were already in the eventStore (from cache or previous session), we wouldn't see them. Now subscribing to both: - insert$ - catches new events in real-time as they're added - timeline() - emits ALL matching events (existing + new) This ensures we process: 1. Zaps already in the eventStore from previous sessions 2. Zaps that loaded from relays before our subscription was active 3. New zaps arriving in real-time Added logging to distinguish between new (insert$) and all (timeline) events.
This commit is contained in:
@@ -109,8 +109,7 @@ class SupportersService {
|
||||
},
|
||||
]);
|
||||
|
||||
// Subscribe to insert stream from eventStore
|
||||
// This catches events as they're added in real-time
|
||||
// Subscribe to insert stream from eventStore for real-time new events
|
||||
const eventSubscription = eventStore.insert$.subscribe(
|
||||
(event: NostrEvent) => {
|
||||
// Filter for zaps to Grimoire
|
||||
@@ -121,13 +120,29 @@ class SupportersService {
|
||||
)
|
||||
) {
|
||||
console.log(
|
||||
`[Supporters] Received zap event ${event.id.slice(0, 8)} from eventStore.insert$`,
|
||||
`[Supporters] Received NEW zap event ${event.id.slice(0, 8)} from eventStore.insert$`,
|
||||
);
|
||||
this.processZapReceipt(event);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Also subscribe to timeline to process ALL existing events
|
||||
const timeline = eventStore.timeline([
|
||||
{
|
||||
kinds: [9735],
|
||||
"#p": [GRIMOIRE_DONATE_PUBKEY],
|
||||
},
|
||||
]);
|
||||
|
||||
const timelineSubscription = timeline.subscribe(async (events) => {
|
||||
console.log(
|
||||
`[Supporters] Timeline has ${events.length} total zap events`,
|
||||
);
|
||||
// Process all existing events (includes both old and new)
|
||||
await Promise.all(events.map((event) => this.processZapReceipt(event)));
|
||||
});
|
||||
|
||||
// Start the loader (pushes events to store)
|
||||
const loaderSubscription = loader().subscribe({
|
||||
error: (error) => {
|
||||
@@ -138,9 +153,10 @@ class SupportersService {
|
||||
},
|
||||
});
|
||||
|
||||
// Combine subscriptions for cleanup
|
||||
// Combine all subscriptions for cleanup
|
||||
this.subscription = eventSubscription;
|
||||
if (this.subscription && loaderSubscription) {
|
||||
if (this.subscription) {
|
||||
this.subscription.add(timelineSubscription);
|
||||
this.subscription.add(loaderSubscription);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user