@pmate/chat-sdk 0.13.0-profile.0 → 0.13.0-profile.1
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/lib/profile.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { profileDiscussionId } from "./runtime/profileProjection.js";
|
|
|
7
7
|
export { ProfileCoordinator } from "./runtime/profileCoordinator.js";
|
|
8
8
|
export { ProfileInboxFeed } from "./runtime/profileInboxFeed.js";
|
|
9
9
|
export { ProfileOutboxDispatcher } from "./runtime/profileOutboxDispatcher.js";
|
|
10
|
-
export { createProfileChat, getProfileChatRuntime } from "./runtime/profileChat.js";
|
|
10
|
+
export { createProfileChat, getProfileChatRuntime, handleProfileChatReach, revokeProfileChatAccess } from "./runtime/profileChat.js";
|
|
11
11
|
export type { ProfileChatHost } from "./runtime/profileChat.js";
|
|
12
12
|
export type { ProfileWorkerConfiguration } from "./runtime/profileWorkerHost.js";
|
|
13
13
|
export type { ProfileSnapshot, ProfileDelta } from "./runtime/profileMemoryStore.js";
|
package/lib/profile.js
CHANGED
|
@@ -7,4 +7,4 @@ export { profileDiscussionId } from "./runtime/profileProjection.js";
|
|
|
7
7
|
export { ProfileCoordinator } from "./runtime/profileCoordinator.js";
|
|
8
8
|
export { ProfileInboxFeed } from "./runtime/profileInboxFeed.js";
|
|
9
9
|
export { ProfileOutboxDispatcher } from "./runtime/profileOutboxDispatcher.js";
|
|
10
|
-
export { createProfileChat, getProfileChatRuntime } from "./runtime/profileChat.js";
|
|
10
|
+
export { createProfileChat, getProfileChatRuntime, handleProfileChatReach, revokeProfileChatAccess } from "./runtime/profileChat.js";
|
|
@@ -4,6 +4,7 @@ import type { ProfileMemoryStore } from "./profileMemoryStore.js";
|
|
|
4
4
|
import { type ProfileOperation } from "./profileProjection.js";
|
|
5
5
|
import type { ProfileIdentity } from "./profileStoreTypes.js";
|
|
6
6
|
import { type ChatRuntimeMessage } from "./protocol.js";
|
|
7
|
+
import type { OnlineReachEvent } from "./reach.js";
|
|
7
8
|
export type ProfileChatHost = {
|
|
8
9
|
identity: ProfileIdentity;
|
|
9
10
|
memory: ProfileMemoryStore;
|
|
@@ -15,6 +16,8 @@ export type ProfileChatHost = {
|
|
|
15
16
|
};
|
|
16
17
|
export declare function getProfileChatRuntime(chat: Chat): ProfileChat;
|
|
17
18
|
export declare function createProfileChat(host: ProfileChatHost, teamId: string): Chat;
|
|
19
|
+
export declare function handleProfileChatReach(chat: Chat, event: OnlineReachEvent): "handled" | undefined;
|
|
20
|
+
export declare function revokeProfileChatAccess(chat: Chat): Promise<void>;
|
|
18
21
|
/** Product-facing Chat adapter over prepared Profile views. No legacy Session,
|
|
19
22
|
* second outbox, reading persistence or per-team message database is created. */
|
|
20
23
|
export declare class ProfileChat implements Chat {
|
|
@@ -5,6 +5,7 @@ import { createRuntimeMsg } from "./protocol.js";
|
|
|
5
5
|
import { outgoingContent } from "./outgoingContent.js";
|
|
6
6
|
import { dmThreadId, groupThreadId } from "./thread.js";
|
|
7
7
|
import { createUniqueGroup } from "./groupIdentity.js";
|
|
8
|
+
import { messageThreadRoot } from "./messageThread.js";
|
|
8
9
|
const sessions = new WeakMap();
|
|
9
10
|
export function getProfileChatRuntime(chat) {
|
|
10
11
|
const session = sessions.get(chat);
|
|
@@ -13,6 +14,19 @@ export function getProfileChatRuntime(chat) {
|
|
|
13
14
|
return session;
|
|
14
15
|
}
|
|
15
16
|
export function createProfileChat(host, teamId) { return new ProfileChat(host, teamId); }
|
|
17
|
+
export function handleProfileChatReach(chat, event) {
|
|
18
|
+
if (!["social.readCountsChanged", "social.readStateChanged"].includes(event.eventType))
|
|
19
|
+
return;
|
|
20
|
+
const { identity } = getProfileChatRuntime(chat).host;
|
|
21
|
+
if (event.appId !== identity.appId)
|
|
22
|
+
throw Error("UNEXPECTED_READING_APPLICATION");
|
|
23
|
+
if (event.eventType === "social.readStateChanged" && event.payload.profileId !== identity.profileId)
|
|
24
|
+
throw Error("Reading reach identity mismatch");
|
|
25
|
+
// Inbox owns the ordered receipt stream. Reach is only a hint and must not
|
|
26
|
+
// create another reading store or apply facts outside that stream.
|
|
27
|
+
return "handled";
|
|
28
|
+
}
|
|
29
|
+
export function revokeProfileChatAccess(chat) { return getProfileChatRuntime(chat).revokeAccess(); }
|
|
16
30
|
/** Product-facing Chat adapter over prepared Profile views. No legacy Session,
|
|
17
31
|
* second outbox, reading persistence or per-team message database is created. */
|
|
18
32
|
export class ProfileChat {
|
|
@@ -134,7 +148,16 @@ export class ProfileChat {
|
|
|
134
148
|
return id;
|
|
135
149
|
}
|
|
136
150
|
async getThread(id, options = {}) { this.assertOpen(); options.signal?.throwIfAborted(); return this.prepare(id); }
|
|
137
|
-
async loadEarlier(id, options = {}) {
|
|
151
|
+
async loadEarlier(id, options = {}) {
|
|
152
|
+
this.assertOpen();
|
|
153
|
+
options.signal?.throwIfAborted();
|
|
154
|
+
this.limits.set(id, (this.limits.get(id) ?? 128) + 128);
|
|
155
|
+
const previous = this.views.get(id), value = this.prepare(id);
|
|
156
|
+
if (previous !== value)
|
|
157
|
+
for (const listener of this.listening.get(id) ?? [])
|
|
158
|
+
listener(value);
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
138
161
|
async refreshThread(id, options = {}) { options.signal?.throwIfAborted(); await this.host.synchronize(); return this.getThread(id, options); }
|
|
139
162
|
subscribeThread(id, listener, _options = {}) {
|
|
140
163
|
this.assertOpen();
|
|
@@ -173,8 +196,10 @@ export class ProfileChat {
|
|
|
173
196
|
}
|
|
174
197
|
async sendPrepared(threadId, wire, options = {}, voiceBlob) {
|
|
175
198
|
this.assertOpen();
|
|
176
|
-
|
|
177
|
-
|
|
199
|
+
const root = messageThreadRoot(wire.body);
|
|
200
|
+
const destination = this.discussion ? this.key(threadId) : root ? profileDiscussionId(threadId, root) : threadId;
|
|
201
|
+
await this.host.submit({ type: "send", threadId: destination, parentThreadId: this.discussion?.parentId ?? (root ? threadId : undefined), message: wire, command: {
|
|
202
|
+
commandId: wire.hash, messageId: wire.hash, kind: "message", threadId: destination, createdAt: wire.t,
|
|
178
203
|
payload: voiceBlob ? { message: wire, voiceBlob } : wire, state: "pending", attempts: 0,
|
|
179
204
|
} }, true);
|
|
180
205
|
if (options.waitFor === "delivered")
|
|
@@ -30,6 +30,7 @@ export declare class ProfileMemoryStore {
|
|
|
30
30
|
private directories;
|
|
31
31
|
private listeners;
|
|
32
32
|
private listListeners;
|
|
33
|
+
private messageListeners;
|
|
33
34
|
private list;
|
|
34
35
|
private pageCache;
|
|
35
36
|
private epochs;
|
|
@@ -102,6 +103,7 @@ export declare class ProfileMemoryStore {
|
|
|
102
103
|
}> | undefined;
|
|
103
104
|
getThreadList: () => readonly ProfileThread[];
|
|
104
105
|
subscribeThreadList: (listener: () => void) => () => void;
|
|
106
|
+
subscribeMessages(listener: (messages: readonly ProfileMessage[]) => void): () => void;
|
|
105
107
|
subscribeThread(threadId: string, listener: () => void): () => void;
|
|
106
108
|
restore(snapshot: ProfileSnapshot): void;
|
|
107
109
|
apply(delta: ProfileDelta): void;
|
|
@@ -14,6 +14,7 @@ export class ProfileMemoryStore {
|
|
|
14
14
|
directories = new Map();
|
|
15
15
|
listeners = new Map();
|
|
16
16
|
listListeners = new Set();
|
|
17
|
+
messageListeners = new Set();
|
|
17
18
|
list = [];
|
|
18
19
|
pageCache = new Map();
|
|
19
20
|
epochs = new Map();
|
|
@@ -40,6 +41,7 @@ export class ProfileMemoryStore {
|
|
|
40
41
|
getPresentedMessage(messageId) { return this.presented.get(messageId); }
|
|
41
42
|
getThreadList = () => this.list;
|
|
42
43
|
subscribeThreadList = (listener) => { this.listListeners.add(listener); return () => { this.listListeners.delete(listener); }; };
|
|
44
|
+
subscribeMessages(listener) { this.messageListeners.add(listener); return () => { this.messageListeners.delete(listener); }; }
|
|
43
45
|
subscribeThread(threadId, listener) {
|
|
44
46
|
let listeners = this.listeners.get(threadId);
|
|
45
47
|
if (!listeners) {
|
|
@@ -119,6 +121,7 @@ export class ProfileMemoryStore {
|
|
|
119
121
|
}
|
|
120
122
|
}
|
|
121
123
|
const affected = new Set(delta.threads.map(row => row.threadId));
|
|
124
|
+
const added = delta.messages.filter(row => !this.entities.has(row.messageId));
|
|
122
125
|
const previousThreads = new Map(delta.threads.map(row => [row.threadId, this.threads.get(row.threadId)]));
|
|
123
126
|
for (const message of delta.messages) {
|
|
124
127
|
const previous = this.entities.get(message.messageId);
|
|
@@ -183,6 +186,9 @@ export class ProfileMemoryStore {
|
|
|
183
186
|
}
|
|
184
187
|
}
|
|
185
188
|
this.publish(affected, delta.threads.length > 0);
|
|
189
|
+
if (added.length)
|
|
190
|
+
for (const listener of this.messageListeners)
|
|
191
|
+
this.notify(() => listener(added));
|
|
186
192
|
}
|
|
187
193
|
indexMessage(message) {
|
|
188
194
|
const index = this.readingIndices.get(message.threadId) ?? new ProfileReadingIndex();
|
package/package.json
CHANGED