@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.cjs CHANGED
@@ -8767,6 +8767,12 @@ var CommunicationsModule = class {
8767
8767
  this.unsubscribeComposing = deps.transport.onComposing?.((indicator) => {
8768
8768
  this.handleComposingIndicator(indicator);
8769
8769
  }) ?? null;
8770
+ if (deps.transport.onChatReady) {
8771
+ deps.transport.onChatReady(() => {
8772
+ const conversations = this.getConversations();
8773
+ deps.emitEvent("communications:ready", { conversationCount: conversations.size });
8774
+ });
8775
+ }
8770
8776
  }
8771
8777
  /**
8772
8778
  * Load messages from storage.
@@ -9409,6 +9415,7 @@ var GroupChatModule = class {
9409
9415
  await this.subscribeToJoinedGroups();
9410
9416
  }
9411
9417
  this.deps.emitEvent("groupchat:connection", { connected: true });
9418
+ this.deps.emitEvent("groupchat:ready", { groupCount: this.groups.size });
9412
9419
  } catch (error) {
9413
9420
  logger.error("GroupChat", "Failed to connect to relays", error);
9414
9421
  this.deps.emitEvent("groupchat:connection", { connected: false });
@@ -10043,6 +10050,19 @@ var GroupChatModule = class {
10043
10050
  getMessages(groupId) {
10044
10051
  return (this.messages.get(groupId) || []).sort((a, b) => a.timestamp - b.timestamp);
10045
10052
  }
10053
+ getMessagesPage(groupId, options) {
10054
+ const limit = options?.limit ?? 20;
10055
+ const before = options?.before ?? Infinity;
10056
+ const groupMessages = this.messages.get(groupId) ?? [];
10057
+ const filtered = groupMessages.filter((m) => m.timestamp < before).sort((a, b) => b.timestamp - a.timestamp);
10058
+ const page = filtered.slice(0, limit);
10059
+ return {
10060
+ messages: page.reverse(),
10061
+ // chronological order
10062
+ hasMore: filtered.length > limit,
10063
+ oldestTimestamp: page.length > 0 ? page[0].timestamp : null
10064
+ };
10065
+ }
10046
10066
  getMembers(groupId) {
10047
10067
  return (this.members.get(groupId) || []).sort((a, b) => a.joinedAt - b.joinedAt);
10048
10068
  }