@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.
@@ -8401,6 +8401,12 @@ var CommunicationsModule = class {
8401
8401
  this.unsubscribeComposing = deps.transport.onComposing?.((indicator) => {
8402
8402
  this.handleComposingIndicator(indicator);
8403
8403
  }) ?? null;
8404
+ if (deps.transport.onChatReady) {
8405
+ deps.transport.onChatReady(() => {
8406
+ const conversations = this.getConversations();
8407
+ deps.emitEvent("communications:ready", { conversationCount: conversations.size });
8408
+ });
8409
+ }
8404
8410
  }
8405
8411
  /**
8406
8412
  * Load messages from storage.
@@ -9043,6 +9049,7 @@ var GroupChatModule = class {
9043
9049
  await this.subscribeToJoinedGroups();
9044
9050
  }
9045
9051
  this.deps.emitEvent("groupchat:connection", { connected: true });
9052
+ this.deps.emitEvent("groupchat:ready", { groupCount: this.groups.size });
9046
9053
  } catch (error) {
9047
9054
  logger.error("GroupChat", "Failed to connect to relays", error);
9048
9055
  this.deps.emitEvent("groupchat:connection", { connected: false });
@@ -9677,6 +9684,19 @@ var GroupChatModule = class {
9677
9684
  getMessages(groupId) {
9678
9685
  return (this.messages.get(groupId) || []).sort((a, b) => a.timestamp - b.timestamp);
9679
9686
  }
9687
+ getMessagesPage(groupId, options) {
9688
+ const limit = options?.limit ?? 20;
9689
+ const before = options?.before ?? Infinity;
9690
+ const groupMessages = this.messages.get(groupId) ?? [];
9691
+ const filtered = groupMessages.filter((m) => m.timestamp < before).sort((a, b) => b.timestamp - a.timestamp);
9692
+ const page = filtered.slice(0, limit);
9693
+ return {
9694
+ messages: page.reverse(),
9695
+ // chronological order
9696
+ hasMore: filtered.length > limit,
9697
+ oldestTimestamp: page.length > 0 ? page[0].timestamp : null
9698
+ };
9699
+ }
9680
9700
  getMembers(groupId) {
9681
9701
  return (this.members.get(groupId) || []).sort((a, b) => a.joinedAt - b.joinedAt);
9682
9702
  }