@pmate/chat-sdk 0.12.0-next.12 → 0.12.0-next.13
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.
|
@@ -10,6 +10,7 @@ export type ChatSessionOptions<T extends StoredMessage> = {
|
|
|
10
10
|
messages: MessageClientOptions<T>;
|
|
11
11
|
connection: ChatClientOptions;
|
|
12
12
|
sharedConnection?: ChatClient;
|
|
13
|
+
activeThreadId?: string;
|
|
13
14
|
reading: ReadingClientOptions;
|
|
14
15
|
decode: (message: ChatRuntimeMessage) => T | undefined;
|
|
15
16
|
onError: (error: unknown) => void;
|
|
@@ -64,7 +64,7 @@ export class ChatSession {
|
|
|
64
64
|
this.publishGlobal();
|
|
65
65
|
if (state === "connected") {
|
|
66
66
|
const since = Date.now();
|
|
67
|
-
this.catchUp.schedule("scope", () => this.messages.restore(since));
|
|
67
|
+
this.catchUp.schedule("scope", () => this.messages.restore(since, options.activeThreadId));
|
|
68
68
|
if (this.readingStarted)
|
|
69
69
|
this.reading.refresh();
|
|
70
70
|
}
|
|
@@ -11,6 +11,8 @@ export type CreateChatOptions = {
|
|
|
11
11
|
profileId: string;
|
|
12
12
|
teamId: string;
|
|
13
13
|
token: string;
|
|
14
|
+
/** Limit reconnect reconciliation for a dedicated conversation document. */
|
|
15
|
+
threadId?: string;
|
|
14
16
|
endpoint?: string;
|
|
15
17
|
clientInstanceId?: string;
|
|
16
18
|
fetch?: typeof fetch;
|
|
@@ -16,6 +16,7 @@ export function createChat(options) {
|
|
|
16
16
|
};
|
|
17
17
|
return new ChatSession({
|
|
18
18
|
sharedConnection: options.connection,
|
|
19
|
+
activeThreadId: options.threadId,
|
|
19
20
|
messages: { scope: { appId, accountId, profileId, teamId }, transport: { load: (thread, signal) => page(thread, signal), changes: (thread, after, signal) => page(thread, signal, { after }), older: (thread, before, signal) => page(thread, signal, { before }) }, onError },
|
|
20
21
|
reading: { appId, profileId, sessionToken: token, hubHttpUrl: http, fetch: options.fetch, onError },
|
|
21
22
|
connection: { appId, profileId, teamId, hubUrl: ws, clientInstanceId: options.clientInstanceId, fetchImpl: options.fetch,
|
|
@@ -59,7 +59,7 @@ export declare class MessageClient<T extends StoredMessage> {
|
|
|
59
59
|
subscribe(thread: string, listener: () => void): () => void;
|
|
60
60
|
subscribeAll(listener: (threadId: string) => void): () => void;
|
|
61
61
|
/** Close the connection gap for saved windows with four bounded background lanes. */
|
|
62
|
-
restore(since: number): Promise<void>;
|
|
62
|
+
restore(since: number, threadId?: string): Promise<void>;
|
|
63
63
|
read(thread: string, limit?: number, refresh?: boolean): Promise<MessageSnapshot<T>>;
|
|
64
64
|
/** Application connection/wake events invalidate, rather than fetching directly. */
|
|
65
65
|
invalidate(thread: string): void;
|
|
@@ -71,8 +71,8 @@ export class MessageClient {
|
|
|
71
71
|
}
|
|
72
72
|
subscribeAll(listener) { this.allListeners.add(listener); return () => { this.allListeners.delete(listener); }; }
|
|
73
73
|
/** Close the connection gap for saved windows with four bounded background lanes. */
|
|
74
|
-
async restore(since) {
|
|
75
|
-
const queue = (await this.storage.windows()).filter(window => (window.syncedAt ?? 0) < since && !window.revoked);
|
|
74
|
+
async restore(since, threadId) {
|
|
75
|
+
const queue = (await this.storage.windows()).filter(window => (window.syncedAt ?? 0) < since && !window.revoked && (threadId === undefined || window.thread === threadId));
|
|
76
76
|
await Promise.all(Array.from({ length: Math.min(4, queue.length) }, async () => {
|
|
77
77
|
while (queue.length && !this.closed && !this.closing) {
|
|
78
78
|
const window = queue.shift();
|
package/package.json
CHANGED