@unicitylabs/sphere-sdk 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -201,6 +201,14 @@ interface TransportProvider extends BaseProvider {
201
201
  * and resolves after EOSE (End Of Stored Events).
202
202
  */
203
203
  fetchPendingEvents?(): Promise<void>;
204
+ /**
205
+ * Register a handler to be called when the chat subscription receives EOSE
206
+ * (End Of Stored Events), indicating that historical DMs have been delivered.
207
+ * The handler fires at most once per subscription lifecycle.
208
+ *
209
+ * @returns Unsubscribe function
210
+ */
211
+ onChatReady?(handler: () => void): () => void;
204
212
  }
205
213
  /**
206
214
  * Payload for sending instant split bundles
@@ -535,6 +543,7 @@ declare class NostrTransportProvider implements TransportProvider {
535
543
  onReadReceipt(handler: ReadReceiptHandler): () => void;
536
544
  sendTypingIndicator(recipientTransportPubkey: string): Promise<void>;
537
545
  onTypingIndicator(handler: TypingIndicatorHandler): () => void;
546
+ onChatReady(handler: () => void): () => void;
538
547
  onComposing(handler: ComposingHandler): () => void;
539
548
  sendComposingIndicator(recipientPubkey: string, content: string): Promise<void>;
540
549
  /**
@@ -604,6 +613,8 @@ declare class NostrTransportProvider implements TransportProvider {
604
613
  private queryEvents;
605
614
  private walletSubscriptionId;
606
615
  private chatSubscriptionId;
616
+ private chatEoseHandlers;
617
+ private chatEoseFired;
607
618
  private subscribeToEvents;
608
619
  private subscribeToTags;
609
620
  private decryptContent;
@@ -201,6 +201,14 @@ interface TransportProvider extends BaseProvider {
201
201
  * and resolves after EOSE (End Of Stored Events).
202
202
  */
203
203
  fetchPendingEvents?(): Promise<void>;
204
+ /**
205
+ * Register a handler to be called when the chat subscription receives EOSE
206
+ * (End Of Stored Events), indicating that historical DMs have been delivered.
207
+ * The handler fires at most once per subscription lifecycle.
208
+ *
209
+ * @returns Unsubscribe function
210
+ */
211
+ onChatReady?(handler: () => void): () => void;
204
212
  }
205
213
  /**
206
214
  * Payload for sending instant split bundles
@@ -535,6 +543,7 @@ declare class NostrTransportProvider implements TransportProvider {
535
543
  onReadReceipt(handler: ReadReceiptHandler): () => void;
536
544
  sendTypingIndicator(recipientTransportPubkey: string): Promise<void>;
537
545
  onTypingIndicator(handler: TypingIndicatorHandler): () => void;
546
+ onChatReady(handler: () => void): () => void;
538
547
  onComposing(handler: ComposingHandler): () => void;
539
548
  sendComposingIndicator(recipientPubkey: string, content: string): Promise<void>;
540
549
  /**
@@ -604,6 +613,8 @@ declare class NostrTransportProvider implements TransportProvider {
604
613
  private queryEvents;
605
614
  private walletSubscriptionId;
606
615
  private chatSubscriptionId;
616
+ private chatEoseHandlers;
617
+ private chatEoseFired;
607
618
  private subscribeToEvents;
608
619
  private subscribeToTags;
609
620
  private decryptContent;
@@ -1180,6 +1180,7 @@ var NostrTransportProvider = class {
1180
1180
  this.mainSubscriptionId = null;
1181
1181
  this.walletSubscriptionId = null;
1182
1182
  this.chatSubscriptionId = null;
1183
+ this.chatEoseFired = false;
1183
1184
  this.status = "disconnected";
1184
1185
  this.emitEvent({ type: "transport:disconnected", timestamp: Date.now() });
1185
1186
  logger.debug("Nostr", "Disconnected from all relays");
@@ -1503,6 +1504,20 @@ var NostrTransportProvider = class {
1503
1504
  this.typingIndicatorHandlers.add(handler);
1504
1505
  return () => this.typingIndicatorHandlers.delete(handler);
1505
1506
  }
1507
+ onChatReady(handler) {
1508
+ if (this.chatEoseFired) {
1509
+ try {
1510
+ handler();
1511
+ } catch {
1512
+ }
1513
+ return () => {
1514
+ };
1515
+ }
1516
+ this.chatEoseHandlers.push(handler);
1517
+ return () => {
1518
+ this.chatEoseHandlers = this.chatEoseHandlers.filter((h) => h !== handler);
1519
+ };
1520
+ }
1506
1521
  // ===========================================================================
1507
1522
  // Composing Indicators (NIP-59 kind 25050)
1508
1523
  // ===========================================================================
@@ -2220,6 +2235,9 @@ var NostrTransportProvider = class {
2220
2235
  // Track subscription IDs for cleanup
2221
2236
  walletSubscriptionId = null;
2222
2237
  chatSubscriptionId = null;
2238
+ // Chat EOSE handlers — fired once when relay finishes delivering stored DMs
2239
+ chatEoseHandlers = [];
2240
+ chatEoseFired = false;
2223
2241
  async subscribeToEvents() {
2224
2242
  logger.debug("Nostr", "subscribeToEvents called, identity:", !!this.identity, "keyManager:", !!this.keyManager, "nostrClient:", !!this.nostrClient);
2225
2243
  if (!this.identity || !this.keyManager || !this.nostrClient) {
@@ -2309,6 +2327,16 @@ var NostrTransportProvider = class {
2309
2327
  },
2310
2328
  onEndOfStoredEvents: () => {
2311
2329
  logger.debug("Nostr", "Chat subscription ready (EOSE)");
2330
+ if (!this.chatEoseFired) {
2331
+ this.chatEoseFired = true;
2332
+ for (const handler of this.chatEoseHandlers) {
2333
+ try {
2334
+ handler();
2335
+ } catch {
2336
+ }
2337
+ }
2338
+ this.chatEoseHandlers = [];
2339
+ }
2312
2340
  },
2313
2341
  onError: (_subId, error) => {
2314
2342
  logger.debug("Nostr", "Chat subscription error:", error);