@xmtp/browser-sdk 5.3.0 → 6.0.0
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.d.ts +541 -671
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/workers/client.js +1 -1
- package/dist/workers/client.js.map +1 -1
- package/dist/workers/opfs.js +2 -0
- package/dist/workers/opfs.js.map +1 -0
- package/package.json +12 -16
- package/src/Client.ts +92 -219
- package/src/CodecRegistry.ts +27 -0
- package/src/Conversation.ts +275 -104
- package/src/Conversations.ts +188 -99
- package/src/DebugInformation.ts +10 -27
- package/src/DecodedMessage.ts +155 -58
- package/src/Dm.ts +25 -9
- package/src/Group.ts +30 -29
- package/src/Opfs.ts +63 -0
- package/src/Preferences.ts +68 -52
- package/src/WorkerClient.ts +5 -5
- package/src/WorkerConversation.ts +98 -45
- package/src/WorkerConversations.ts +35 -74
- package/src/WorkerDebugInformation.ts +1 -12
- package/src/WorkerPreferences.ts +6 -14
- package/src/index.ts +53 -24
- package/src/types/actions/client.ts +6 -17
- package/src/types/actions/conversation.ts +160 -31
- package/src/types/actions/conversations.ts +21 -24
- package/src/types/actions/debugInformation.ts +3 -11
- package/src/types/actions/dm.ts +1 -1
- package/src/types/actions/opfs.ts +66 -0
- package/src/types/actions/preferences.ts +6 -13
- package/src/types/actions/streams.ts +8 -8
- package/src/types/actions.ts +11 -9
- package/src/types/options.ts +47 -6
- package/src/{ClientWorkerClass.ts → utils/WorkerBridge.ts} +35 -45
- package/src/utils/contentTypes.ts +77 -0
- package/src/utils/conversions.ts +17 -590
- package/src/utils/createClient.ts +16 -11
- package/src/utils/errors.ts +13 -19
- package/src/utils/inboxId.ts +46 -0
- package/src/utils/inboxState.ts +23 -0
- package/src/utils/installations.ts +95 -0
- package/src/utils/metadata.ts +15 -0
- package/src/utils/signer.ts +4 -4
- package/src/utils/uuid.ts +8 -0
- package/src/workers/client.ts +176 -135
- package/src/workers/opfs.ts +127 -0
- package/dist/workers/utils.js +0 -2
- package/dist/workers/utils.js.map +0 -1
- package/src/Utils.ts +0 -143
- package/src/UtilsWorkerClass.ts +0 -121
- package/src/types/actions/utils.ts +0 -69
- package/src/workers/utils.ts +0 -155
package/src/Conversations.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ConversationType,
|
|
3
3
|
type ConsentState,
|
|
4
|
+
type CreateDmOptions,
|
|
5
|
+
type CreateGroupOptions,
|
|
4
6
|
type Identifier,
|
|
7
|
+
type ListConversationsOptions,
|
|
8
|
+
type DecodedMessage as XmtpDecodedMessage,
|
|
5
9
|
} from "@xmtp/wasm-bindings";
|
|
6
|
-
import {
|
|
7
|
-
import type { Client } from "@/Client";
|
|
10
|
+
import type { CodecRegistry } from "@/CodecRegistry";
|
|
8
11
|
import { DecodedMessage } from "@/DecodedMessage";
|
|
9
12
|
import { Dm } from "@/Dm";
|
|
10
13
|
import { Group } from "@/Group";
|
|
11
|
-
import type {
|
|
12
|
-
|
|
13
|
-
SafeCreateDmOptions,
|
|
14
|
-
SafeCreateGroupOptions,
|
|
15
|
-
SafeListConversationsOptions,
|
|
16
|
-
SafeMessage,
|
|
17
|
-
} from "@/utils/conversions";
|
|
14
|
+
import type { ClientWorkerAction } from "@/types/actions";
|
|
15
|
+
import type { SafeConversation } from "@/utils/conversions";
|
|
18
16
|
import {
|
|
19
17
|
createStream,
|
|
20
18
|
type StreamCallback,
|
|
21
19
|
type StreamOptions,
|
|
22
20
|
} from "@/utils/streams";
|
|
21
|
+
import { uuid } from "@/utils/uuid";
|
|
22
|
+
import type { WorkerBridge } from "@/utils/WorkerBridge";
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Manages conversations
|
|
@@ -27,15 +27,21 @@ import {
|
|
|
27
27
|
* This class is not intended to be initialized directly.
|
|
28
28
|
*/
|
|
29
29
|
export class Conversations<ContentTypes = unknown> {
|
|
30
|
-
#
|
|
30
|
+
#codecRegistry: CodecRegistry;
|
|
31
|
+
#worker: WorkerBridge<ClientWorkerAction>;
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* Creates a new conversations instance
|
|
34
35
|
*
|
|
35
|
-
* @param
|
|
36
|
+
* @param worker - The worker bridge instance for client communication
|
|
37
|
+
* @param codecRegistry - The codec registry instance
|
|
36
38
|
*/
|
|
37
|
-
constructor(
|
|
38
|
-
|
|
39
|
+
constructor(
|
|
40
|
+
worker: WorkerBridge<ClientWorkerAction>,
|
|
41
|
+
codecRegistry: CodecRegistry,
|
|
42
|
+
) {
|
|
43
|
+
this.#worker = worker;
|
|
44
|
+
this.#codecRegistry = codecRegistry;
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
/**
|
|
@@ -44,7 +50,7 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
44
50
|
* @returns Promise that resolves when sync is complete
|
|
45
51
|
*/
|
|
46
52
|
async sync() {
|
|
47
|
-
return this.#
|
|
53
|
+
return this.#worker.action("conversations.sync");
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
/**
|
|
@@ -56,7 +62,7 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
56
62
|
* @returns Promise that resolves when sync is complete
|
|
57
63
|
*/
|
|
58
64
|
async syncAll(consentStates?: ConsentState[]) {
|
|
59
|
-
return this.#
|
|
65
|
+
return this.#worker.action("conversations.syncAll", {
|
|
60
66
|
consentStates,
|
|
61
67
|
});
|
|
62
68
|
}
|
|
@@ -68,16 +74,31 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
68
74
|
* @returns Promise that resolves with the conversation, if found
|
|
69
75
|
*/
|
|
70
76
|
async getConversationById(id: string) {
|
|
71
|
-
const data = await this.#
|
|
77
|
+
const data = await this.#worker.action(
|
|
72
78
|
"conversations.getConversationById",
|
|
73
79
|
{
|
|
74
80
|
id,
|
|
75
81
|
},
|
|
76
82
|
);
|
|
77
83
|
if (data) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
switch (data.metadata.conversationType) {
|
|
85
|
+
case ConversationType.Group:
|
|
86
|
+
return new Group<ContentTypes>(
|
|
87
|
+
this.#worker,
|
|
88
|
+
this.#codecRegistry,
|
|
89
|
+
data.id,
|
|
90
|
+
data,
|
|
91
|
+
);
|
|
92
|
+
case ConversationType.Dm:
|
|
93
|
+
return new Dm<ContentTypes>(
|
|
94
|
+
this.#worker,
|
|
95
|
+
this.#codecRegistry,
|
|
96
|
+
data.id,
|
|
97
|
+
data,
|
|
98
|
+
);
|
|
99
|
+
default:
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
81
102
|
}
|
|
82
103
|
return undefined;
|
|
83
104
|
}
|
|
@@ -89,13 +110,12 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
89
110
|
* @returns Promise that resolves with the decoded message, if found
|
|
90
111
|
*/
|
|
91
112
|
async getMessageById(id: string) {
|
|
92
|
-
const data = await this.#
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return data ? new DecodedMessage(this.#client, data) : undefined;
|
|
113
|
+
const data = await this.#worker.action("conversations.getMessageById", {
|
|
114
|
+
id,
|
|
115
|
+
});
|
|
116
|
+
return data
|
|
117
|
+
? new DecodedMessage<ContentTypes>(this.#codecRegistry, data)
|
|
118
|
+
: undefined;
|
|
99
119
|
}
|
|
100
120
|
|
|
101
121
|
/**
|
|
@@ -105,23 +125,24 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
105
125
|
* @returns Promise that resolves with the DM, if found
|
|
106
126
|
*/
|
|
107
127
|
async getDmByInboxId(inboxId: string) {
|
|
108
|
-
const data = await this.#
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return data ? new Dm(this.#client, data.id, data) : undefined;
|
|
128
|
+
const data = await this.#worker.action("conversations.getDmByInboxId", {
|
|
129
|
+
inboxId,
|
|
130
|
+
});
|
|
131
|
+
return data
|
|
132
|
+
? new Dm(this.#worker, this.#codecRegistry, data.id, data)
|
|
133
|
+
: undefined;
|
|
115
134
|
}
|
|
116
135
|
|
|
117
136
|
/**
|
|
118
|
-
*
|
|
137
|
+
* Fetches a DM by identifier
|
|
119
138
|
*
|
|
120
139
|
* @param identifier - The identifier to look up
|
|
121
140
|
* @returns Promise that resolves with the DM, if found
|
|
122
141
|
*/
|
|
123
|
-
async
|
|
124
|
-
const inboxId = await this.#client.
|
|
142
|
+
async fetchDmByIdentifier(identifier: Identifier) {
|
|
143
|
+
const inboxId = await this.#worker.action("client.getInboxIdByIdentifier", {
|
|
144
|
+
identifier,
|
|
145
|
+
});
|
|
125
146
|
if (!inboxId) {
|
|
126
147
|
return undefined;
|
|
127
148
|
}
|
|
@@ -134,18 +155,28 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
134
155
|
* @param options - Optional filtering and pagination options
|
|
135
156
|
* @returns Promise that resolves with an array of conversations
|
|
136
157
|
*/
|
|
137
|
-
async list(options?:
|
|
138
|
-
const conversations = await this.#
|
|
158
|
+
async list(options?: ListConversationsOptions) {
|
|
159
|
+
const conversations = await this.#worker.action("conversations.list", {
|
|
139
160
|
options,
|
|
140
161
|
});
|
|
141
162
|
|
|
142
163
|
return conversations
|
|
143
164
|
.map((conversation) => {
|
|
144
165
|
switch (conversation.metadata.conversationType) {
|
|
145
|
-
case
|
|
146
|
-
return new Dm(
|
|
147
|
-
|
|
148
|
-
|
|
166
|
+
case ConversationType.Dm:
|
|
167
|
+
return new Dm<ContentTypes>(
|
|
168
|
+
this.#worker,
|
|
169
|
+
this.#codecRegistry,
|
|
170
|
+
conversation.id,
|
|
171
|
+
conversation,
|
|
172
|
+
);
|
|
173
|
+
case ConversationType.Group:
|
|
174
|
+
return new Group<ContentTypes>(
|
|
175
|
+
this.#worker,
|
|
176
|
+
this.#codecRegistry,
|
|
177
|
+
conversation.id,
|
|
178
|
+
conversation,
|
|
179
|
+
);
|
|
149
180
|
default:
|
|
150
181
|
return undefined;
|
|
151
182
|
}
|
|
@@ -160,9 +191,9 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
160
191
|
* @returns Promise that resolves with an array of groups
|
|
161
192
|
*/
|
|
162
193
|
async listGroups(
|
|
163
|
-
options?: Omit<
|
|
194
|
+
options?: Omit<ListConversationsOptions, "conversationType">,
|
|
164
195
|
) {
|
|
165
|
-
const conversations = await this.#
|
|
196
|
+
const conversations = await this.#worker.action(
|
|
166
197
|
"conversations.listGroups",
|
|
167
198
|
{
|
|
168
199
|
options,
|
|
@@ -170,7 +201,13 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
170
201
|
);
|
|
171
202
|
|
|
172
203
|
return conversations.map(
|
|
173
|
-
(conversation) =>
|
|
204
|
+
(conversation) =>
|
|
205
|
+
new Group<ContentTypes>(
|
|
206
|
+
this.#worker,
|
|
207
|
+
this.#codecRegistry,
|
|
208
|
+
conversation.id,
|
|
209
|
+
conversation,
|
|
210
|
+
),
|
|
174
211
|
);
|
|
175
212
|
}
|
|
176
213
|
|
|
@@ -180,36 +217,42 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
180
217
|
* @param options - Optional filtering and pagination options
|
|
181
218
|
* @returns Promise that resolves with an array of DMs
|
|
182
219
|
*/
|
|
183
|
-
async listDms(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
"conversations.listDms",
|
|
188
|
-
{
|
|
189
|
-
options,
|
|
190
|
-
},
|
|
191
|
-
);
|
|
220
|
+
async listDms(options?: Omit<ListConversationsOptions, "conversationType">) {
|
|
221
|
+
const conversations = await this.#worker.action("conversations.listDms", {
|
|
222
|
+
options,
|
|
223
|
+
});
|
|
192
224
|
|
|
193
225
|
return conversations.map(
|
|
194
|
-
(conversation) =>
|
|
226
|
+
(conversation) =>
|
|
227
|
+
new Dm<ContentTypes>(
|
|
228
|
+
this.#worker,
|
|
229
|
+
this.#codecRegistry,
|
|
230
|
+
conversation.id,
|
|
231
|
+
conversation,
|
|
232
|
+
),
|
|
195
233
|
);
|
|
196
234
|
}
|
|
197
235
|
|
|
198
236
|
/**
|
|
199
|
-
* Creates a new group without
|
|
237
|
+
* Creates a new group conversation without publishing to the network
|
|
200
238
|
*
|
|
201
239
|
* @param options - Optional group creation options
|
|
202
240
|
* @returns Promise that resolves with the new group
|
|
203
241
|
*/
|
|
204
|
-
async
|
|
205
|
-
const conversation = await this.#
|
|
206
|
-
"conversations.
|
|
242
|
+
async createGroupOptimistic(options?: CreateGroupOptions) {
|
|
243
|
+
const conversation = await this.#worker.action(
|
|
244
|
+
"conversations.createGroupOptimistic",
|
|
207
245
|
{
|
|
208
246
|
options,
|
|
209
247
|
},
|
|
210
248
|
);
|
|
211
249
|
|
|
212
|
-
return new Group(
|
|
250
|
+
return new Group<ContentTypes>(
|
|
251
|
+
this.#worker,
|
|
252
|
+
this.#codecRegistry,
|
|
253
|
+
conversation.id,
|
|
254
|
+
conversation,
|
|
255
|
+
);
|
|
213
256
|
}
|
|
214
257
|
|
|
215
258
|
/**
|
|
@@ -219,19 +262,24 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
219
262
|
* @param options - Optional group creation options
|
|
220
263
|
* @returns Promise that resolves with the new group
|
|
221
264
|
*/
|
|
222
|
-
async
|
|
265
|
+
async createGroupWithIdentifiers(
|
|
223
266
|
identifiers: Identifier[],
|
|
224
|
-
options?:
|
|
267
|
+
options?: CreateGroupOptions,
|
|
225
268
|
) {
|
|
226
|
-
const conversation = await this.#
|
|
227
|
-
"conversations.
|
|
269
|
+
const conversation = await this.#worker.action(
|
|
270
|
+
"conversations.createGroupWithIdentifiers",
|
|
228
271
|
{
|
|
229
272
|
identifiers,
|
|
230
273
|
options,
|
|
231
274
|
},
|
|
232
275
|
);
|
|
233
276
|
|
|
234
|
-
return new Group(
|
|
277
|
+
return new Group<ContentTypes>(
|
|
278
|
+
this.#worker,
|
|
279
|
+
this.#codecRegistry,
|
|
280
|
+
conversation.id,
|
|
281
|
+
conversation,
|
|
282
|
+
);
|
|
235
283
|
}
|
|
236
284
|
|
|
237
285
|
/**
|
|
@@ -241,16 +289,21 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
241
289
|
* @param options - Optional group creation options
|
|
242
290
|
* @returns Promise that resolves with the new group
|
|
243
291
|
*/
|
|
244
|
-
async
|
|
245
|
-
const conversation = await this.#
|
|
246
|
-
"conversations.
|
|
292
|
+
async createGroup(inboxIds: string[], options?: CreateGroupOptions) {
|
|
293
|
+
const conversation = await this.#worker.action(
|
|
294
|
+
"conversations.createGroup",
|
|
247
295
|
{
|
|
248
296
|
inboxIds,
|
|
249
297
|
options,
|
|
250
298
|
},
|
|
251
299
|
);
|
|
252
300
|
|
|
253
|
-
return new Group(
|
|
301
|
+
return new Group<ContentTypes>(
|
|
302
|
+
this.#worker,
|
|
303
|
+
this.#codecRegistry,
|
|
304
|
+
conversation.id,
|
|
305
|
+
conversation,
|
|
306
|
+
);
|
|
254
307
|
}
|
|
255
308
|
|
|
256
309
|
/**
|
|
@@ -260,19 +313,24 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
260
313
|
* @param options - Optional DM creation options
|
|
261
314
|
* @returns Promise that resolves with the new DM
|
|
262
315
|
*/
|
|
263
|
-
async
|
|
316
|
+
async createDmWithIdentifier(
|
|
264
317
|
identifier: Identifier,
|
|
265
|
-
options?:
|
|
318
|
+
options?: CreateDmOptions,
|
|
266
319
|
) {
|
|
267
|
-
const conversation = await this.#
|
|
268
|
-
"conversations.
|
|
320
|
+
const conversation = await this.#worker.action(
|
|
321
|
+
"conversations.createDmWithIdentifier",
|
|
269
322
|
{
|
|
270
323
|
identifier,
|
|
271
324
|
options,
|
|
272
325
|
},
|
|
273
326
|
);
|
|
274
327
|
|
|
275
|
-
return new Dm(
|
|
328
|
+
return new Dm<ContentTypes>(
|
|
329
|
+
this.#worker,
|
|
330
|
+
this.#codecRegistry,
|
|
331
|
+
conversation.id,
|
|
332
|
+
conversation,
|
|
333
|
+
);
|
|
276
334
|
}
|
|
277
335
|
|
|
278
336
|
/**
|
|
@@ -282,22 +340,27 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
282
340
|
* @param options - Optional DM creation options
|
|
283
341
|
* @returns Promise that resolves with the new DM
|
|
284
342
|
*/
|
|
285
|
-
async
|
|
286
|
-
const conversation = await this.#
|
|
343
|
+
async createDm(inboxId: string, options?: CreateDmOptions) {
|
|
344
|
+
const conversation = await this.#worker.action("conversations.createDm", {
|
|
287
345
|
inboxId,
|
|
288
346
|
options,
|
|
289
347
|
});
|
|
290
348
|
|
|
291
|
-
return new Dm(
|
|
349
|
+
return new Dm<ContentTypes>(
|
|
350
|
+
this.#worker,
|
|
351
|
+
this.#codecRegistry,
|
|
352
|
+
conversation.id,
|
|
353
|
+
conversation,
|
|
354
|
+
);
|
|
292
355
|
}
|
|
293
356
|
|
|
294
357
|
/**
|
|
295
|
-
*
|
|
358
|
+
* Gets the HMAC keys for all conversations
|
|
296
359
|
*
|
|
297
360
|
* @returns Promise that resolves with the HMAC keys for all conversations
|
|
298
361
|
*/
|
|
299
|
-
async
|
|
300
|
-
return this.#
|
|
362
|
+
async hmacKeys() {
|
|
363
|
+
return this.#worker.action("conversations.hmacKeys");
|
|
301
364
|
}
|
|
302
365
|
|
|
303
366
|
/**
|
|
@@ -320,18 +383,18 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
320
383
|
callback: StreamCallback<SafeConversation>,
|
|
321
384
|
onFail: () => void,
|
|
322
385
|
) => {
|
|
323
|
-
const streamId =
|
|
386
|
+
const streamId = uuid();
|
|
324
387
|
if (!options?.disableSync) {
|
|
325
388
|
// sync the conversation
|
|
326
389
|
await this.sync();
|
|
327
390
|
}
|
|
328
391
|
// start the stream
|
|
329
|
-
await this.#
|
|
392
|
+
await this.#worker.action("conversations.stream", {
|
|
330
393
|
streamId,
|
|
331
394
|
conversationType: options?.conversationType,
|
|
332
395
|
});
|
|
333
396
|
// handle stream messages
|
|
334
|
-
return this.#
|
|
397
|
+
return this.#worker.handleStreamMessage<SafeConversation, T>(
|
|
335
398
|
streamId,
|
|
336
399
|
callback,
|
|
337
400
|
{
|
|
@@ -341,9 +404,26 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
341
404
|
);
|
|
342
405
|
};
|
|
343
406
|
const convertConversation = (value: SafeConversation) => {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
407
|
+
switch (value.metadata.conversationType) {
|
|
408
|
+
case ConversationType.Group:
|
|
409
|
+
return new Group<ContentTypes>(
|
|
410
|
+
this.#worker,
|
|
411
|
+
this.#codecRegistry,
|
|
412
|
+
value.id,
|
|
413
|
+
value,
|
|
414
|
+
) as T;
|
|
415
|
+
case ConversationType.Dm:
|
|
416
|
+
return new Dm<ContentTypes>(
|
|
417
|
+
this.#worker,
|
|
418
|
+
this.#codecRegistry,
|
|
419
|
+
value.id,
|
|
420
|
+
value,
|
|
421
|
+
) as T;
|
|
422
|
+
default:
|
|
423
|
+
throw new Error(
|
|
424
|
+
`Unknown conversation type: ${value.metadata.conversationType}`,
|
|
425
|
+
);
|
|
426
|
+
}
|
|
347
427
|
};
|
|
348
428
|
|
|
349
429
|
return createStream(stream, convertConversation, options);
|
|
@@ -386,37 +466,40 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
386
466
|
* @returns Stream instance for new messages
|
|
387
467
|
*/
|
|
388
468
|
async streamAllMessages(
|
|
389
|
-
options?: StreamOptions<
|
|
469
|
+
options?: StreamOptions<
|
|
470
|
+
XmtpDecodedMessage,
|
|
471
|
+
DecodedMessage<ContentTypes>
|
|
472
|
+
> & {
|
|
390
473
|
conversationType?: ConversationType;
|
|
391
474
|
consentStates?: ConsentState[];
|
|
392
475
|
},
|
|
393
476
|
) {
|
|
394
477
|
const stream = async (
|
|
395
|
-
callback: StreamCallback<
|
|
478
|
+
callback: StreamCallback<XmtpDecodedMessage>,
|
|
396
479
|
onFail: () => void,
|
|
397
480
|
) => {
|
|
398
|
-
const streamId =
|
|
481
|
+
const streamId = uuid();
|
|
399
482
|
if (!options?.disableSync) {
|
|
400
483
|
// sync the conversation
|
|
401
484
|
await this.sync();
|
|
402
485
|
}
|
|
403
486
|
// start the stream
|
|
404
|
-
await this.#
|
|
487
|
+
await this.#worker.action("conversations.streamAllMessages", {
|
|
405
488
|
streamId,
|
|
406
489
|
conversationType: options?.conversationType,
|
|
407
490
|
consentStates: options?.consentStates,
|
|
408
491
|
});
|
|
409
492
|
// handle stream messages
|
|
410
|
-
return this.#
|
|
411
|
-
|
|
493
|
+
return this.#worker.handleStreamMessage<
|
|
494
|
+
XmtpDecodedMessage,
|
|
412
495
|
DecodedMessage<ContentTypes>
|
|
413
496
|
>(streamId, callback, {
|
|
414
497
|
...options,
|
|
415
498
|
onFail,
|
|
416
499
|
});
|
|
417
500
|
};
|
|
418
|
-
const convertMessage = (value:
|
|
419
|
-
return new DecodedMessage(this.#
|
|
501
|
+
const convertMessage = (value: XmtpDecodedMessage) => {
|
|
502
|
+
return new DecodedMessage<ContentTypes>(this.#codecRegistry, value);
|
|
420
503
|
};
|
|
421
504
|
|
|
422
505
|
return createStream(stream, convertMessage, options);
|
|
@@ -430,7 +513,10 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
430
513
|
* @returns Stream instance for new group messages
|
|
431
514
|
*/
|
|
432
515
|
async streamAllGroupMessages(
|
|
433
|
-
options?: StreamOptions<
|
|
516
|
+
options?: StreamOptions<
|
|
517
|
+
XmtpDecodedMessage,
|
|
518
|
+
DecodedMessage<ContentTypes>
|
|
519
|
+
> & {
|
|
434
520
|
consentStates?: ConsentState[];
|
|
435
521
|
},
|
|
436
522
|
) {
|
|
@@ -448,7 +534,10 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
448
534
|
* @returns Stream instance for new DM messages
|
|
449
535
|
*/
|
|
450
536
|
async streamAllDmMessages(
|
|
451
|
-
options?: StreamOptions<
|
|
537
|
+
options?: StreamOptions<
|
|
538
|
+
XmtpDecodedMessage,
|
|
539
|
+
DecodedMessage<ContentTypes>
|
|
540
|
+
> & {
|
|
452
541
|
consentStates?: ConsentState[];
|
|
453
542
|
},
|
|
454
543
|
) {
|
|
@@ -477,13 +566,13 @@ export class Conversations<ContentTypes = unknown> {
|
|
|
477
566
|
>,
|
|
478
567
|
) {
|
|
479
568
|
const stream = async (callback: StreamCallback<string>) => {
|
|
480
|
-
const streamId =
|
|
569
|
+
const streamId = uuid();
|
|
481
570
|
// start the stream
|
|
482
|
-
await this.#
|
|
571
|
+
await this.#worker.action("conversations.streamMessageDeletions", {
|
|
483
572
|
streamId,
|
|
484
573
|
});
|
|
485
574
|
// handle stream messages
|
|
486
|
-
return this.#
|
|
575
|
+
return this.#worker.handleStreamMessage<string>(
|
|
487
576
|
streamId,
|
|
488
577
|
callback,
|
|
489
578
|
options,
|
package/src/DebugInformation.ts
CHANGED
|
@@ -1,48 +1,31 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ClientWorkerAction } from "@/types/actions";
|
|
2
|
+
import type { WorkerBridge } from "@/utils/WorkerBridge";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Debug information helpers for the client
|
|
5
6
|
*
|
|
6
7
|
* This class is not intended to be initialized directly.
|
|
7
8
|
*/
|
|
8
|
-
export class DebugInformation
|
|
9
|
-
#
|
|
9
|
+
export class DebugInformation {
|
|
10
|
+
#worker: WorkerBridge<ClientWorkerAction>;
|
|
10
11
|
|
|
11
|
-
constructor(
|
|
12
|
-
this.#
|
|
12
|
+
constructor(worker: WorkerBridge<ClientWorkerAction>) {
|
|
13
|
+
this.#worker = worker;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
apiStatistics() {
|
|
16
|
-
return this.#
|
|
17
|
-
"debugInformation.apiStatistics",
|
|
18
|
-
undefined,
|
|
19
|
-
);
|
|
17
|
+
return this.#worker.action("debugInformation.apiStatistics");
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
apiIdentityStatistics() {
|
|
23
|
-
return this.#
|
|
24
|
-
"debugInformation.apiIdentityStatistics",
|
|
25
|
-
undefined,
|
|
26
|
-
);
|
|
21
|
+
return this.#worker.action("debugInformation.apiIdentityStatistics");
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
apiAggregateStatistics() {
|
|
30
|
-
return this.#
|
|
31
|
-
"debugInformation.apiAggregateStatistics",
|
|
32
|
-
undefined,
|
|
33
|
-
);
|
|
25
|
+
return this.#worker.action("debugInformation.apiAggregateStatistics");
|
|
34
26
|
}
|
|
35
27
|
|
|
36
28
|
clearAllStatistics() {
|
|
37
|
-
return this.#
|
|
38
|
-
"debugInformation.clearAllStatistics",
|
|
39
|
-
undefined,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
uploadDebugArchive(serverUrl?: string) {
|
|
44
|
-
return this.#client.sendMessage("debugInformation.uploadDebugArchive", {
|
|
45
|
-
serverUrl,
|
|
46
|
-
});
|
|
29
|
+
return this.#worker.action("debugInformation.clearAllStatistics");
|
|
47
30
|
}
|
|
48
31
|
}
|