|
1 | 1 | import '@bacons/text-decoder/install'; |
2 | 2 | import { createStore } from 'zustand/vanilla'; |
3 | 3 | import { useStore } from 'zustand'; |
4 | | -import { NDKEvent, NDKFilter, NDKRelaySet, NDKSubscription, NDKSubscriptionOptions, wrapEvent } from '@nostr-dev-kit/ndk'; |
| 4 | +import { NDKEvent, NDKFilter, NDKRelaySet, NDKSubscription, NDKSubscriptionOptions } from '@nostr-dev-kit/ndk'; |
5 | 5 | import { useCallback, useEffect, useMemo, useRef } from 'react'; |
6 | 6 | import { useNDK } from './ndk.js'; |
7 | 7 | import { useNDKSession } from '../stores/session/index.js'; |
8 | | - |
9 | 8 | /** |
10 | 9 | * Extends NDKEvent with a 'from' method to wrap events with a kind-specific handler |
11 | 10 | */ |
@@ -229,16 +228,10 @@ export const useSubscribe = <T extends NDKEvent>( |
229 | 228 | return; |
230 | 229 | } |
231 | 230 |
|
232 | | - // If we need to convert the event, we do so |
233 | | - if (opts?.wrap) event = wrapEvent<T>(event); |
234 | | - |
235 | 231 | event.once("deleted", () => { |
236 | 232 | storeInstance.removeEventId(id); |
237 | 233 | }); |
238 | 234 |
|
239 | | - // If conversion failed, we bail |
240 | | - if (!event) return; |
241 | | - |
242 | 235 | storeInstance.addEvent(event as T); |
243 | 236 | eventIds.current.set(id, event.created_at!); |
244 | 237 | }, |
@@ -268,7 +261,10 @@ export const useSubscribe = <T extends NDKEvent>( |
268 | 261 | subscription.on('closed', handleClosed); |
269 | 262 |
|
270 | 263 | storeInstance.setSubscription(subscription); |
271 | | - subscription.start(); |
| 264 | + const cachedEvents = subscription.start(false); |
| 265 | + if (cachedEvents) { |
| 266 | + for (const event of cachedEvents) handleEvent(event); |
| 267 | + } |
272 | 268 |
|
273 | 269 | return () => { |
274 | 270 | if (storeInstance.subscriptionRef) { |
|
0 commit comments