@unicitylabs/sphere-sdk 0.6.1 → 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.
package/dist/index.d.cts CHANGED
@@ -64,6 +64,17 @@ interface GroupChatModuleConfig {
64
64
  /** Max reconnect attempts (default: 5) */
65
65
  maxReconnectAttempts?: number;
66
66
  }
67
+ interface GroupMessagesPage {
68
+ messages: GroupMessageData[];
69
+ hasMore: boolean;
70
+ oldestTimestamp: number | null;
71
+ }
72
+ interface GetGroupMessagesPageOptions {
73
+ /** Max messages to return (default: 20) */
74
+ limit?: number;
75
+ /** Return messages older than this timestamp */
76
+ before?: number;
77
+ }
67
78
  interface CreateGroupOptions {
68
79
  name: string;
69
80
  description?: string;
@@ -1303,7 +1314,7 @@ interface TrackedAddress extends TrackedAddressEntry {
1303
1314
  /** Primary nametag (from nametag cache, without @ prefix) */
1304
1315
  readonly nametag?: string;
1305
1316
  }
1306
- type SphereEventType = 'transfer:incoming' | 'transfer:confirmed' | 'transfer:failed' | 'payment_request:incoming' | 'payment_request:accepted' | 'payment_request:rejected' | 'payment_request:paid' | 'payment_request:response' | 'message:dm' | 'message:read' | 'message:typing' | 'composing:started' | 'message:broadcast' | 'sync:started' | 'sync:completed' | 'sync:provider' | 'sync:error' | 'connection:changed' | 'nametag:registered' | 'nametag:recovered' | 'identity:changed' | 'address:activated' | 'address:hidden' | 'address:unhidden' | 'sync:remote-update' | 'groupchat:message' | 'groupchat:joined' | 'groupchat:left' | 'groupchat:kicked' | 'groupchat:group_deleted' | 'groupchat:updated' | 'groupchat:connection' | 'history:updated';
1317
+ type SphereEventType = 'transfer:incoming' | 'transfer:confirmed' | 'transfer:failed' | 'payment_request:incoming' | 'payment_request:accepted' | 'payment_request:rejected' | 'payment_request:paid' | 'payment_request:response' | 'message:dm' | 'message:read' | 'message:typing' | 'composing:started' | 'message:broadcast' | 'sync:started' | 'sync:completed' | 'sync:provider' | 'sync:error' | 'connection:changed' | 'nametag:registered' | 'nametag:recovered' | 'identity:changed' | 'address:activated' | 'address:hidden' | 'address:unhidden' | 'sync:remote-update' | 'groupchat:message' | 'groupchat:joined' | 'groupchat:left' | 'groupchat:kicked' | 'groupchat:group_deleted' | 'groupchat:updated' | 'groupchat:connection' | 'groupchat:ready' | 'communications:ready' | 'history:updated';
1307
1318
  interface SphereEventMap {
1308
1319
  'transfer:incoming': IncomingTransfer;
1309
1320
  'transfer:confirmed': TransferResult;
@@ -1403,6 +1414,12 @@ interface SphereEventMap {
1403
1414
  'groupchat:connection': {
1404
1415
  connected: boolean;
1405
1416
  };
1417
+ 'groupchat:ready': {
1418
+ groupCount: number;
1419
+ };
1420
+ 'communications:ready': {
1421
+ conversationCount: number;
1422
+ };
1406
1423
  'history:updated': TransactionHistoryEntry;
1407
1424
  }
1408
1425
  type SphereEventHandler<T extends SphereEventType> = (data: SphereEventMap[T]) => void;
@@ -1967,6 +1984,14 @@ interface TransportProvider extends BaseProvider {
1967
1984
  * and resolves after EOSE (End Of Stored Events).
1968
1985
  */
1969
1986
  fetchPendingEvents?(): Promise<void>;
1987
+ /**
1988
+ * Register a handler to be called when the chat subscription receives EOSE
1989
+ * (End Of Stored Events), indicating that historical DMs have been delivered.
1990
+ * The handler fires at most once per subscription lifecycle.
1991
+ *
1992
+ * @returns Unsubscribe function
1993
+ */
1994
+ onChatReady?(handler: () => void): () => void;
1970
1995
  }
1971
1996
  /**
1972
1997
  * Payload for sending instant split bundles
@@ -3656,6 +3681,7 @@ declare class GroupChatModule {
3656
3681
  getGroups(): GroupData[];
3657
3682
  getGroup(groupId: string): GroupData | null;
3658
3683
  getMessages(groupId: string): GroupMessageData[];
3684
+ getMessagesPage(groupId: string, options?: GetGroupMessagesPageOptions): GroupMessagesPage;
3659
3685
  getMembers(groupId: string): GroupMemberData[];
3660
3686
  getMember(groupId: string, pubkey: string): GroupMemberData | null;
3661
3687
  getTotalUnreadCount(): number;
package/dist/index.d.ts CHANGED
@@ -64,6 +64,17 @@ interface GroupChatModuleConfig {
64
64
  /** Max reconnect attempts (default: 5) */
65
65
  maxReconnectAttempts?: number;
66
66
  }
67
+ interface GroupMessagesPage {
68
+ messages: GroupMessageData[];
69
+ hasMore: boolean;
70
+ oldestTimestamp: number | null;
71
+ }
72
+ interface GetGroupMessagesPageOptions {
73
+ /** Max messages to return (default: 20) */
74
+ limit?: number;
75
+ /** Return messages older than this timestamp */
76
+ before?: number;
77
+ }
67
78
  interface CreateGroupOptions {
68
79
  name: string;
69
80
  description?: string;
@@ -1303,7 +1314,7 @@ interface TrackedAddress extends TrackedAddressEntry {
1303
1314
  /** Primary nametag (from nametag cache, without @ prefix) */
1304
1315
  readonly nametag?: string;
1305
1316
  }
1306
- type SphereEventType = 'transfer:incoming' | 'transfer:confirmed' | 'transfer:failed' | 'payment_request:incoming' | 'payment_request:accepted' | 'payment_request:rejected' | 'payment_request:paid' | 'payment_request:response' | 'message:dm' | 'message:read' | 'message:typing' | 'composing:started' | 'message:broadcast' | 'sync:started' | 'sync:completed' | 'sync:provider' | 'sync:error' | 'connection:changed' | 'nametag:registered' | 'nametag:recovered' | 'identity:changed' | 'address:activated' | 'address:hidden' | 'address:unhidden' | 'sync:remote-update' | 'groupchat:message' | 'groupchat:joined' | 'groupchat:left' | 'groupchat:kicked' | 'groupchat:group_deleted' | 'groupchat:updated' | 'groupchat:connection' | 'history:updated';
1317
+ type SphereEventType = 'transfer:incoming' | 'transfer:confirmed' | 'transfer:failed' | 'payment_request:incoming' | 'payment_request:accepted' | 'payment_request:rejected' | 'payment_request:paid' | 'payment_request:response' | 'message:dm' | 'message:read' | 'message:typing' | 'composing:started' | 'message:broadcast' | 'sync:started' | 'sync:completed' | 'sync:provider' | 'sync:error' | 'connection:changed' | 'nametag:registered' | 'nametag:recovered' | 'identity:changed' | 'address:activated' | 'address:hidden' | 'address:unhidden' | 'sync:remote-update' | 'groupchat:message' | 'groupchat:joined' | 'groupchat:left' | 'groupchat:kicked' | 'groupchat:group_deleted' | 'groupchat:updated' | 'groupchat:connection' | 'groupchat:ready' | 'communications:ready' | 'history:updated';
1307
1318
  interface SphereEventMap {
1308
1319
  'transfer:incoming': IncomingTransfer;
1309
1320
  'transfer:confirmed': TransferResult;
@@ -1403,6 +1414,12 @@ interface SphereEventMap {
1403
1414
  'groupchat:connection': {
1404
1415
  connected: boolean;
1405
1416
  };
1417
+ 'groupchat:ready': {
1418
+ groupCount: number;
1419
+ };
1420
+ 'communications:ready': {
1421
+ conversationCount: number;
1422
+ };
1406
1423
  'history:updated': TransactionHistoryEntry;
1407
1424
  }
1408
1425
  type SphereEventHandler<T extends SphereEventType> = (data: SphereEventMap[T]) => void;
@@ -1967,6 +1984,14 @@ interface TransportProvider extends BaseProvider {
1967
1984
  * and resolves after EOSE (End Of Stored Events).
1968
1985
  */
1969
1986
  fetchPendingEvents?(): Promise<void>;
1987
+ /**
1988
+ * Register a handler to be called when the chat subscription receives EOSE
1989
+ * (End Of Stored Events), indicating that historical DMs have been delivered.
1990
+ * The handler fires at most once per subscription lifecycle.
1991
+ *
1992
+ * @returns Unsubscribe function
1993
+ */
1994
+ onChatReady?(handler: () => void): () => void;
1970
1995
  }
1971
1996
  /**
1972
1997
  * Payload for sending instant split bundles
@@ -3656,6 +3681,7 @@ declare class GroupChatModule {
3656
3681
  getGroups(): GroupData[];
3657
3682
  getGroup(groupId: string): GroupData | null;
3658
3683
  getMessages(groupId: string): GroupMessageData[];
3684
+ getMessagesPage(groupId: string, options?: GetGroupMessagesPageOptions): GroupMessagesPage;
3659
3685
  getMembers(groupId: string): GroupMemberData[];
3660
3686
  getMember(groupId: string, pubkey: string): GroupMemberData | null;
3661
3687
  getTotalUnreadCount(): number;
package/dist/index.js CHANGED
@@ -8594,6 +8594,12 @@ var CommunicationsModule = class {
8594
8594
  this.unsubscribeComposing = deps.transport.onComposing?.((indicator) => {
8595
8595
  this.handleComposingIndicator(indicator);
8596
8596
  }) ?? null;
8597
+ if (deps.transport.onChatReady) {
8598
+ deps.transport.onChatReady(() => {
8599
+ const conversations = this.getConversations();
8600
+ deps.emitEvent("communications:ready", { conversationCount: conversations.size });
8601
+ });
8602
+ }
8597
8603
  }
8598
8604
  /**
8599
8605
  * Load messages from storage.
@@ -9240,6 +9246,7 @@ var GroupChatModule = class {
9240
9246
  await this.subscribeToJoinedGroups();
9241
9247
  }
9242
9248
  this.deps.emitEvent("groupchat:connection", { connected: true });
9249
+ this.deps.emitEvent("groupchat:ready", { groupCount: this.groups.size });
9243
9250
  } catch (error) {
9244
9251
  logger.error("GroupChat", "Failed to connect to relays", error);
9245
9252
  this.deps.emitEvent("groupchat:connection", { connected: false });
@@ -9874,6 +9881,19 @@ var GroupChatModule = class {
9874
9881
  getMessages(groupId) {
9875
9882
  return (this.messages.get(groupId) || []).sort((a, b) => a.timestamp - b.timestamp);
9876
9883
  }
9884
+ getMessagesPage(groupId, options) {
9885
+ const limit = options?.limit ?? 20;
9886
+ const before = options?.before ?? Infinity;
9887
+ const groupMessages = this.messages.get(groupId) ?? [];
9888
+ const filtered = groupMessages.filter((m) => m.timestamp < before).sort((a, b) => b.timestamp - a.timestamp);
9889
+ const page = filtered.slice(0, limit);
9890
+ return {
9891
+ messages: page.reverse(),
9892
+ // chronological order
9893
+ hasMore: filtered.length > limit,
9894
+ oldestTimestamp: page.length > 0 ? page[0].timestamp : null
9895
+ };
9896
+ }
9877
9897
  getMembers(groupId) {
9878
9898
  return (this.members.get(groupId) || []).sort((a, b) => a.joinedAt - b.joinedAt);
9879
9899
  }