@pmate/chat-sdk 0.12.0-next.11 → 0.12.0-next.12

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.
@@ -20,7 +20,7 @@ export type ChatThreadSnapshot<T> = {
20
20
  hasEarlier: boolean;
21
21
  resetVersion: number;
22
22
  complete: boolean;
23
- unread: ReturnType<typeof unreadInConversation>;
23
+ unread: ReturnType<typeof unreadInConversation> | undefined;
24
24
  };
25
25
  export type ChatSummarySnapshot<T> = {
26
26
  threads: readonly {
@@ -29,8 +29,8 @@ export type ChatSummarySnapshot<T> = {
29
29
  unread: ChatThreadSnapshot<T>["unread"];
30
30
  outgoingCount: number;
31
31
  }[];
32
- unreadMessageCount: number;
33
- badgeCount: number;
32
+ unreadMessageCount: number | undefined;
33
+ badgeCount: number | undefined;
34
34
  connection: ChatConnectionState;
35
35
  };
36
36
  /** Owns all browser message clients. Hosts subscribe to stable thread snapshots. */
@@ -207,7 +207,7 @@ export class ChatSession {
207
207
  if (!snapshot) {
208
208
  const messages = this.messages.getSnapshot(threadId);
209
209
  const state = this.reading.getSnapshot();
210
- snapshot = { messages: messages?.messages ?? [], hasEarlier: messages?.hasEarlier ?? false, resetVersion: messages?.resetVersion ?? 0, complete: messages?.complete ?? false, outgoing: this.sender.snapshot(threadId), unread: state?.threads.some(thread => (thread.conversationId ?? thread.id) === threadId) ? unreadInConversation(state, threadId) : { unreadMessageCount: 0, unreadMentionCount: 0, badgeCount: 0 } };
210
+ snapshot = { messages: messages?.messages ?? [], hasEarlier: messages?.hasEarlier ?? false, resetVersion: messages?.resetVersion ?? 0, complete: messages?.complete ?? false, outgoing: this.sender.snapshot(threadId), unread: state?.threads.some(thread => (thread.conversationId ?? thread.id) === threadId) ? unreadInConversation(state, threadId) : undefined };
211
211
  this.snapshots.set(threadId, snapshot);
212
212
  }
213
213
  return snapshot;
@@ -250,7 +250,9 @@ export class ChatSession {
250
250
  const snapshot = this.getSnapshot(threadId);
251
251
  return { threadId, lastMessage: snapshot.messages.at(-1), unread: snapshot.unread, outgoingCount: snapshot.outgoing.length };
252
252
  });
253
- return { threads, unreadMessageCount: threads.reduce((sum, t) => sum + t.unread.unreadMessageCount, 0), badgeCount: threads.reduce((sum, t) => sum + t.unread.badgeCount, 0), connection: this.connectionState };
253
+ const state = this.reading.getSnapshot();
254
+ const known = Boolean(state && state.syncCursor !== "0" && threads.every(thread => thread.unread !== undefined));
255
+ return { threads, unreadMessageCount: known ? threads.reduce((sum, t) => sum + (t.unread?.unreadMessageCount ?? 0), 0) : undefined, badgeCount: known ? threads.reduce((sum, t) => sum + (t.unread?.badgeCount ?? 0), 0) : undefined, connection: this.connectionState };
254
256
  }
255
257
  publishGlobal() {
256
258
  const next = this.buildGlobal();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/chat-sdk",
3
- "version": "0.12.0-next.11",
3
+ "version": "0.12.0-next.12",
4
4
  "description": "Cross-platform PMate chat input components, voice input primitives, and ASR helpers",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",