@xmtp/browser-sdk 2.0.13 → 2.1.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 +849 -678
- 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/utils.js +1 -1
- package/dist/workers/utils.js.map +1 -1
- package/package.json +9 -11
- package/src/Client.ts +71 -31
- package/src/ClientWorkerClass.ts +62 -19
- package/src/Conversation.ts +60 -33
- package/src/Conversations.ts +96 -48
- package/src/DecodedMessage.ts +8 -5
- package/src/Dm.ts +14 -4
- package/src/Group.ts +27 -20
- package/src/Preferences.ts +21 -10
- package/src/Utils.ts +2 -2
- package/src/UtilsWorkerClass.ts +56 -15
- package/src/WorkerClient.ts +25 -3
- package/src/WorkerConversation.ts +11 -2
- package/src/WorkerConversations.ts +19 -4
- package/src/WorkerPreferences.ts +4 -0
- package/src/index.ts +3 -1
- package/src/types/actions/client.ts +181 -0
- package/src/types/actions/conversation.ts +146 -0
- package/src/types/actions/conversations.ts +146 -0
- package/src/types/actions/dm.ts +19 -0
- package/src/types/actions/group.ts +161 -0
- package/src/types/actions/preferences.ts +68 -0
- package/src/types/actions/streams.ts +44 -0
- package/src/types/actions/utils.ts +29 -0
- package/src/types/actions.ts +75 -0
- package/src/types/options.ts +18 -0
- package/src/utils/conversions.ts +60 -0
- package/src/utils/createClient.ts +6 -1
- package/src/utils/errors.ts +3 -1
- package/src/workers/client.ts +243 -190
- package/src/workers/utils.ts +25 -29
- package/src/types/clientEvents.ts +0 -693
- package/src/types/clientStreamEvents.ts +0 -45
- package/src/types/index.ts +0 -4
- package/src/types/utils.ts +0 -72
- package/src/types/utilsEvents.ts +0 -60
package/src/workers/client.ts
CHANGED
|
@@ -6,22 +6,26 @@ import init, {
|
|
|
6
6
|
type UserPreference,
|
|
7
7
|
} from "@xmtp/wasm-bindings";
|
|
8
8
|
import type {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
ActionErrorData,
|
|
10
|
+
ActionName,
|
|
11
|
+
ActionWithoutResult,
|
|
12
|
+
ClientWorkerAction,
|
|
13
|
+
ExtractActionWithoutData,
|
|
14
|
+
} from "@/types/actions";
|
|
14
15
|
import type {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from "@/types/
|
|
16
|
+
ExtractStreamAction,
|
|
17
|
+
StreamActionErrorData,
|
|
18
|
+
StreamActionName,
|
|
19
|
+
} from "@/types/actions/streams";
|
|
19
20
|
import {
|
|
20
21
|
fromEncodedContent,
|
|
21
22
|
fromSafeEncodedContent,
|
|
23
|
+
toSafeApiStats,
|
|
22
24
|
toSafeConsent,
|
|
23
25
|
toSafeConversation,
|
|
26
|
+
toSafeConversationDebugInfo,
|
|
24
27
|
toSafeHmacKey,
|
|
28
|
+
toSafeIdentityStats,
|
|
25
29
|
toSafeInboxState,
|
|
26
30
|
toSafeKeyPackageStatus,
|
|
27
31
|
toSafeMessage,
|
|
@@ -43,8 +47,8 @@ const streamClosers = new Map<string, StreamCloser>();
|
|
|
43
47
|
/**
|
|
44
48
|
* Type-safe postMessage
|
|
45
49
|
*/
|
|
46
|
-
const postMessage = <A extends
|
|
47
|
-
data:
|
|
50
|
+
const postMessage = <A extends ActionName<ClientWorkerAction>>(
|
|
51
|
+
data: ExtractActionWithoutData<ClientWorkerAction, A>,
|
|
48
52
|
) => {
|
|
49
53
|
self.postMessage(data);
|
|
50
54
|
};
|
|
@@ -52,15 +56,15 @@ const postMessage = <A extends ClientEventsActions>(
|
|
|
52
56
|
/**
|
|
53
57
|
* Type-safe postMessage for errors
|
|
54
58
|
*/
|
|
55
|
-
const postMessageError = (data:
|
|
59
|
+
const postMessageError = (data: ActionErrorData<ClientWorkerAction>) => {
|
|
56
60
|
self.postMessage(data);
|
|
57
61
|
};
|
|
58
62
|
|
|
59
63
|
/**
|
|
60
64
|
* Type-safe postMessage for streams
|
|
61
65
|
*/
|
|
62
|
-
const postStreamMessage = <A extends
|
|
63
|
-
data:
|
|
66
|
+
const postStreamMessage = <A extends StreamActionName>(
|
|
67
|
+
data: ExtractStreamAction<A>,
|
|
64
68
|
) => {
|
|
65
69
|
self.postMessage(data);
|
|
66
70
|
};
|
|
@@ -68,11 +72,13 @@ const postStreamMessage = <A extends ClientStreamEventsTypes>(
|
|
|
68
72
|
/**
|
|
69
73
|
* Type-safe postMessage for stream errors
|
|
70
74
|
*/
|
|
71
|
-
const postStreamMessageError = (data:
|
|
75
|
+
const postStreamMessageError = (data: StreamActionErrorData) => {
|
|
72
76
|
self.postMessage(data);
|
|
73
77
|
};
|
|
74
78
|
|
|
75
|
-
self.onmessage = async (
|
|
79
|
+
self.onmessage = async (
|
|
80
|
+
event: MessageEvent<ActionWithoutResult<ClientWorkerAction>>,
|
|
81
|
+
) => {
|
|
76
82
|
const { action, id, data } = event.data;
|
|
77
83
|
|
|
78
84
|
if (enableLogging) {
|
|
@@ -84,7 +90,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
84
90
|
|
|
85
91
|
try {
|
|
86
92
|
// init is a special action that initializes the client
|
|
87
|
-
if (action === "init" && !maybeClient) {
|
|
93
|
+
if (action === "client.init" && !maybeClient) {
|
|
88
94
|
maybeClient = await WorkerClient.create(data.identifier, data.options);
|
|
89
95
|
enableLogging =
|
|
90
96
|
data.options?.loggingLevel !== undefined &&
|
|
@@ -137,45 +143,45 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
137
143
|
/**
|
|
138
144
|
* Client actions
|
|
139
145
|
*/
|
|
140
|
-
case "createInboxSignatureText": {
|
|
146
|
+
case "client.createInboxSignatureText": {
|
|
141
147
|
const result = client.createInboxSignatureText();
|
|
142
148
|
postMessage({ id, action, result });
|
|
143
149
|
break;
|
|
144
150
|
}
|
|
145
|
-
case "addAccountSignatureText": {
|
|
151
|
+
case "client.addAccountSignatureText": {
|
|
146
152
|
const result = await client.addAccountSignatureText(data.newIdentifier);
|
|
147
153
|
postMessage({ id, action, result });
|
|
148
154
|
break;
|
|
149
155
|
}
|
|
150
|
-
case "removeAccountSignatureText": {
|
|
156
|
+
case "client.removeAccountSignatureText": {
|
|
151
157
|
const result = await client.removeAccountSignatureText(data.identifier);
|
|
152
158
|
postMessage({ id, action, result });
|
|
153
159
|
break;
|
|
154
160
|
}
|
|
155
|
-
case "revokeAllOtherInstallationsSignatureText": {
|
|
161
|
+
case "client.revokeAllOtherInstallationsSignatureText": {
|
|
156
162
|
const result = await client.revokeAllAOtherInstallationsSignatureText();
|
|
157
163
|
postMessage({ id, action, result });
|
|
158
164
|
break;
|
|
159
165
|
}
|
|
160
|
-
case "revokeInstallationsSignatureText": {
|
|
166
|
+
case "client.revokeInstallationsSignatureText": {
|
|
161
167
|
const result = await client.revokeInstallationsSignatureText(
|
|
162
168
|
data.installationIds,
|
|
163
169
|
);
|
|
164
170
|
postMessage({ id, action, result });
|
|
165
171
|
break;
|
|
166
172
|
}
|
|
167
|
-
case "changeRecoveryIdentifierSignatureText": {
|
|
173
|
+
case "client.changeRecoveryIdentifierSignatureText": {
|
|
168
174
|
const result = await client.changeRecoveryIdentifierSignatureText(
|
|
169
175
|
data.identifier,
|
|
170
176
|
);
|
|
171
177
|
postMessage({ id, action, result });
|
|
172
178
|
break;
|
|
173
179
|
}
|
|
174
|
-
case "addEcdsaSignature":
|
|
180
|
+
case "client.addEcdsaSignature":
|
|
175
181
|
await client.addEcdsaSignature(data.type, data.bytes);
|
|
176
182
|
postMessage({ id, action, result: undefined });
|
|
177
183
|
break;
|
|
178
|
-
case "addScwSignature":
|
|
184
|
+
case "client.addScwSignature":
|
|
179
185
|
await client.addScwSignature(
|
|
180
186
|
data.type,
|
|
181
187
|
data.bytes,
|
|
@@ -184,73 +190,35 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
184
190
|
);
|
|
185
191
|
postMessage({ id, action, result: undefined });
|
|
186
192
|
break;
|
|
187
|
-
case "applySignatures":
|
|
193
|
+
case "client.applySignatures":
|
|
188
194
|
await client.applySignatures();
|
|
189
195
|
postMessage({ id, action, result: undefined });
|
|
190
196
|
break;
|
|
191
|
-
case "registerIdentity":
|
|
197
|
+
case "client.registerIdentity":
|
|
192
198
|
await client.registerIdentity();
|
|
193
199
|
postMessage({ id, action, result: undefined });
|
|
194
200
|
break;
|
|
195
|
-
case "isRegistered": {
|
|
201
|
+
case "client.isRegistered": {
|
|
196
202
|
const result = client.isRegistered;
|
|
197
203
|
postMessage({ id, action, result });
|
|
198
204
|
break;
|
|
199
205
|
}
|
|
200
|
-
case "canMessage": {
|
|
206
|
+
case "client.canMessage": {
|
|
201
207
|
const result = await client.canMessage(data.identifiers);
|
|
202
208
|
postMessage({ id, action, result });
|
|
203
209
|
break;
|
|
204
210
|
}
|
|
205
|
-
case "
|
|
206
|
-
const inboxState = await client.preferences.inboxState(
|
|
207
|
-
data.refreshFromNetwork,
|
|
208
|
-
);
|
|
209
|
-
const result = toSafeInboxState(inboxState);
|
|
210
|
-
postMessage({ id, action, result });
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
case "inboxStateFromInboxIds": {
|
|
214
|
-
const inboxStates = await client.preferences.inboxStateFromInboxIds(
|
|
215
|
-
data.inboxIds,
|
|
216
|
-
data.refreshFromNetwork,
|
|
217
|
-
);
|
|
218
|
-
const result = inboxStates.map(toSafeInboxState);
|
|
219
|
-
postMessage({ id, action, result });
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
case "getLatestInboxState": {
|
|
223
|
-
const inboxState = await client.preferences.getLatestInboxState(
|
|
224
|
-
data.inboxId,
|
|
225
|
-
);
|
|
226
|
-
const result = toSafeInboxState(inboxState);
|
|
227
|
-
postMessage({ id, action, result });
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
case "setConsentStates": {
|
|
231
|
-
await client.preferences.setConsentStates(data.records);
|
|
232
|
-
postMessage({ id, action, result: undefined });
|
|
233
|
-
break;
|
|
234
|
-
}
|
|
235
|
-
case "getConsentState": {
|
|
236
|
-
const result = await client.preferences.getConsentState(
|
|
237
|
-
data.entityType,
|
|
238
|
-
data.entity,
|
|
239
|
-
);
|
|
240
|
-
postMessage({ id, action, result });
|
|
241
|
-
break;
|
|
242
|
-
}
|
|
243
|
-
case "findInboxIdByIdentifier": {
|
|
211
|
+
case "client.findInboxIdByIdentifier": {
|
|
244
212
|
const result = await client.findInboxIdByIdentifier(data.identifier);
|
|
245
213
|
postMessage({ id, action, result });
|
|
246
214
|
break;
|
|
247
215
|
}
|
|
248
|
-
case "signWithInstallationKey": {
|
|
216
|
+
case "client.signWithInstallationKey": {
|
|
249
217
|
const result = client.signWithInstallationKey(data.signatureText);
|
|
250
218
|
postMessage({ id, action, result });
|
|
251
219
|
break;
|
|
252
220
|
}
|
|
253
|
-
case "verifySignedWithInstallationKey": {
|
|
221
|
+
case "client.verifySignedWithInstallationKey": {
|
|
254
222
|
const result = client.verifySignedWithInstallationKey(
|
|
255
223
|
data.signatureText,
|
|
256
224
|
data.signatureBytes,
|
|
@@ -258,7 +226,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
258
226
|
postMessage({ id, action, result });
|
|
259
227
|
break;
|
|
260
228
|
}
|
|
261
|
-
case "verifySignedWithPublicKey": {
|
|
229
|
+
case "client.verifySignedWithPublicKey": {
|
|
262
230
|
const result = client.verifySignedWithPublicKey(
|
|
263
231
|
data.signatureText,
|
|
264
232
|
data.signatureBytes,
|
|
@@ -267,7 +235,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
267
235
|
postMessage({ id, action, result });
|
|
268
236
|
break;
|
|
269
237
|
}
|
|
270
|
-
case "getKeyPackageStatusesForInstallationIds": {
|
|
238
|
+
case "client.getKeyPackageStatusesForInstallationIds": {
|
|
271
239
|
const result = await client.getKeyPackageStatusesForInstallationIds(
|
|
272
240
|
data.installationIds,
|
|
273
241
|
);
|
|
@@ -284,125 +252,194 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
284
252
|
});
|
|
285
253
|
break;
|
|
286
254
|
}
|
|
255
|
+
case "client.apiStatistics": {
|
|
256
|
+
const apiStats = client.apiStatistics();
|
|
257
|
+
const result = toSafeApiStats(apiStats);
|
|
258
|
+
postMessage({ id, action, result });
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case "client.apiIdentityStatistics": {
|
|
262
|
+
const apiIdentityStats = client.apiIdentityStatistics();
|
|
263
|
+
const result = toSafeIdentityStats(apiIdentityStats);
|
|
264
|
+
postMessage({ id, action, result });
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
case "client.apiAggregateStatistics": {
|
|
268
|
+
const result = client.apiAggregateStatistics();
|
|
269
|
+
postMessage({ id, action, result });
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case "client.uploadDebugArchive": {
|
|
273
|
+
const result = await client.uploadDebugArchive(data.serverUrl);
|
|
274
|
+
postMessage({ id, action, result });
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
287
277
|
/**
|
|
288
|
-
*
|
|
278
|
+
* Preferences actions
|
|
289
279
|
*/
|
|
290
|
-
case "
|
|
291
|
-
const
|
|
280
|
+
case "preferences.inboxState": {
|
|
281
|
+
const inboxState = await client.preferences.inboxState(
|
|
282
|
+
data.refreshFromNetwork,
|
|
283
|
+
);
|
|
284
|
+
const result = toSafeInboxState(inboxState);
|
|
285
|
+
postMessage({ id, action, result });
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
case "preferences.inboxStateFromInboxIds": {
|
|
289
|
+
const inboxStates = await client.preferences.inboxStateFromInboxIds(
|
|
290
|
+
data.inboxIds,
|
|
291
|
+
data.refreshFromNetwork,
|
|
292
|
+
);
|
|
293
|
+
const result = inboxStates.map(toSafeInboxState);
|
|
294
|
+
postMessage({ id, action, result });
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
case "preferences.getLatestInboxState": {
|
|
298
|
+
const inboxState = await client.preferences.getLatestInboxState(
|
|
299
|
+
data.inboxId,
|
|
300
|
+
);
|
|
301
|
+
const result = toSafeInboxState(inboxState);
|
|
302
|
+
postMessage({ id, action, result });
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
case "preferences.setConsentStates": {
|
|
306
|
+
await client.preferences.setConsentStates(data.records);
|
|
307
|
+
postMessage({ id, action, result: undefined });
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
case "preferences.getConsentState": {
|
|
311
|
+
const result = await client.preferences.getConsentState(
|
|
312
|
+
data.entityType,
|
|
313
|
+
data.entity,
|
|
314
|
+
);
|
|
315
|
+
postMessage({ id, action, result });
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
case "preferences.sync": {
|
|
319
|
+
const result = await client.preferences.sync();
|
|
320
|
+
postMessage({ id, action, result });
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
case "preferences.streamConsent": {
|
|
324
|
+
const streamCallback = (
|
|
292
325
|
error: Error | null,
|
|
293
|
-
value:
|
|
326
|
+
value: Consent[] | undefined,
|
|
294
327
|
) => {
|
|
295
328
|
if (error) {
|
|
296
329
|
postStreamMessageError({
|
|
297
|
-
|
|
330
|
+
action: "stream.consent",
|
|
298
331
|
streamId: data.streamId,
|
|
299
332
|
error,
|
|
300
333
|
});
|
|
301
334
|
} else {
|
|
302
335
|
postStreamMessage({
|
|
303
|
-
|
|
336
|
+
action: "stream.consent",
|
|
304
337
|
streamId: data.streamId,
|
|
305
|
-
result: value
|
|
306
|
-
? await toSafeConversation(
|
|
307
|
-
new WorkerConversation(client, value),
|
|
308
|
-
)
|
|
309
|
-
: undefined,
|
|
338
|
+
result: value?.map(toSafeConsent) ?? [],
|
|
310
339
|
});
|
|
311
340
|
}
|
|
312
341
|
};
|
|
313
|
-
const streamCloser = client.
|
|
314
|
-
streamCallback,
|
|
315
|
-
data.conversationType,
|
|
316
|
-
);
|
|
342
|
+
const streamCloser = client.preferences.streamConsent(streamCallback);
|
|
317
343
|
streamClosers.set(data.streamId, streamCloser);
|
|
318
|
-
postMessage({
|
|
344
|
+
postMessage({
|
|
345
|
+
id,
|
|
346
|
+
action,
|
|
347
|
+
result: undefined,
|
|
348
|
+
});
|
|
319
349
|
break;
|
|
320
350
|
}
|
|
321
|
-
case "
|
|
351
|
+
case "preferences.streamPreferences": {
|
|
322
352
|
const streamCallback = (
|
|
323
353
|
error: Error | null,
|
|
324
|
-
value:
|
|
354
|
+
value: UserPreference[] | undefined,
|
|
325
355
|
) => {
|
|
326
356
|
if (error) {
|
|
327
357
|
postStreamMessageError({
|
|
328
|
-
|
|
358
|
+
action: "stream.preferences",
|
|
329
359
|
streamId: data.streamId,
|
|
330
360
|
error,
|
|
331
361
|
});
|
|
332
362
|
} else {
|
|
333
363
|
postStreamMessage({
|
|
334
|
-
|
|
364
|
+
action: "stream.preferences",
|
|
335
365
|
streamId: data.streamId,
|
|
336
|
-
result: value
|
|
366
|
+
result: value ?? undefined,
|
|
337
367
|
});
|
|
338
368
|
}
|
|
339
369
|
};
|
|
340
|
-
const streamCloser =
|
|
341
|
-
streamCallback
|
|
342
|
-
data.conversationType,
|
|
343
|
-
);
|
|
370
|
+
const streamCloser =
|
|
371
|
+
client.preferences.streamPreferences(streamCallback);
|
|
344
372
|
streamClosers.set(data.streamId, streamCloser);
|
|
345
|
-
postMessage({
|
|
373
|
+
postMessage({
|
|
374
|
+
id,
|
|
375
|
+
action,
|
|
376
|
+
result: undefined,
|
|
377
|
+
});
|
|
346
378
|
break;
|
|
347
379
|
}
|
|
348
|
-
|
|
349
|
-
|
|
380
|
+
/**
|
|
381
|
+
* Conversations actions
|
|
382
|
+
*/
|
|
383
|
+
case "conversations.stream": {
|
|
384
|
+
const streamCallback = async (
|
|
350
385
|
error: Error | null,
|
|
351
|
-
value:
|
|
386
|
+
value: Conversation | undefined,
|
|
352
387
|
) => {
|
|
353
388
|
if (error) {
|
|
354
389
|
postStreamMessageError({
|
|
355
|
-
|
|
390
|
+
action: "stream.conversation",
|
|
356
391
|
streamId: data.streamId,
|
|
357
392
|
error,
|
|
358
393
|
});
|
|
359
394
|
} else {
|
|
360
395
|
postStreamMessage({
|
|
361
|
-
|
|
396
|
+
action: "stream.conversation",
|
|
362
397
|
streamId: data.streamId,
|
|
363
|
-
result: value
|
|
398
|
+
result: value
|
|
399
|
+
? await toSafeConversation(
|
|
400
|
+
new WorkerConversation(client, value),
|
|
401
|
+
)
|
|
402
|
+
: undefined,
|
|
364
403
|
});
|
|
365
404
|
}
|
|
366
405
|
};
|
|
367
|
-
const streamCloser = client.
|
|
406
|
+
const streamCloser = client.conversations.stream(
|
|
407
|
+
streamCallback,
|
|
408
|
+
data.conversationType,
|
|
409
|
+
);
|
|
368
410
|
streamClosers.set(data.streamId, streamCloser);
|
|
369
|
-
postMessage({
|
|
370
|
-
id,
|
|
371
|
-
action,
|
|
372
|
-
result: undefined,
|
|
373
|
-
});
|
|
411
|
+
postMessage({ id, action, result: undefined });
|
|
374
412
|
break;
|
|
375
413
|
}
|
|
376
|
-
case "
|
|
414
|
+
case "conversations.streamAllMessages": {
|
|
377
415
|
const streamCallback = (
|
|
378
416
|
error: Error | null,
|
|
379
|
-
value:
|
|
417
|
+
value: Message | undefined,
|
|
380
418
|
) => {
|
|
381
419
|
if (error) {
|
|
382
420
|
postStreamMessageError({
|
|
383
|
-
|
|
421
|
+
action: "stream.message",
|
|
384
422
|
streamId: data.streamId,
|
|
385
423
|
error,
|
|
386
424
|
});
|
|
387
425
|
} else {
|
|
388
426
|
postStreamMessage({
|
|
389
|
-
|
|
427
|
+
action: "stream.message",
|
|
390
428
|
streamId: data.streamId,
|
|
391
|
-
result: value
|
|
429
|
+
result: value ? toSafeMessage(value) : undefined,
|
|
392
430
|
});
|
|
393
431
|
}
|
|
394
432
|
};
|
|
395
|
-
const streamCloser =
|
|
396
|
-
|
|
433
|
+
const streamCloser = client.conversations.streamAllMessages(
|
|
434
|
+
streamCallback,
|
|
435
|
+
data.conversationType,
|
|
436
|
+
data.consentStates,
|
|
437
|
+
);
|
|
397
438
|
streamClosers.set(data.streamId, streamCloser);
|
|
398
|
-
postMessage({
|
|
399
|
-
id,
|
|
400
|
-
action,
|
|
401
|
-
result: undefined,
|
|
402
|
-
});
|
|
439
|
+
postMessage({ id, action, result: undefined });
|
|
403
440
|
break;
|
|
404
441
|
}
|
|
405
|
-
case "
|
|
442
|
+
case "conversations.list": {
|
|
406
443
|
const conversations = client.conversations.list(data.options);
|
|
407
444
|
const result = await Promise.all(
|
|
408
445
|
conversations.map((conversation) => toSafeConversation(conversation)),
|
|
@@ -410,7 +447,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
410
447
|
postMessage({ id, action, result });
|
|
411
448
|
break;
|
|
412
449
|
}
|
|
413
|
-
case "
|
|
450
|
+
case "conversations.listGroups": {
|
|
414
451
|
const conversations = client.conversations.listGroups(data.options);
|
|
415
452
|
const result = await Promise.all(
|
|
416
453
|
conversations.map((conversation) => toSafeConversation(conversation)),
|
|
@@ -418,7 +455,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
418
455
|
postMessage({ id, action, result });
|
|
419
456
|
break;
|
|
420
457
|
}
|
|
421
|
-
case "
|
|
458
|
+
case "conversations.listDms": {
|
|
422
459
|
const conversations = client.conversations.listDms(data.options);
|
|
423
460
|
const result = await Promise.all(
|
|
424
461
|
conversations.map((conversation) => toSafeConversation(conversation)),
|
|
@@ -426,7 +463,15 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
426
463
|
postMessage({ id, action, result });
|
|
427
464
|
break;
|
|
428
465
|
}
|
|
429
|
-
case "
|
|
466
|
+
case "conversations.newGroupOptimistic": {
|
|
467
|
+
const conversation = client.conversations.newGroupOptimistic(
|
|
468
|
+
data.options,
|
|
469
|
+
);
|
|
470
|
+
const result = await toSafeConversation(conversation);
|
|
471
|
+
postMessage({ id, action, result });
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
case "conversations.newGroupWithIdentifiers": {
|
|
430
475
|
const conversation = await client.conversations.newGroupWithIdentifiers(
|
|
431
476
|
data.identifiers,
|
|
432
477
|
data.options,
|
|
@@ -435,7 +480,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
435
480
|
postMessage({ id, action, result });
|
|
436
481
|
break;
|
|
437
482
|
}
|
|
438
|
-
case "
|
|
483
|
+
case "conversations.newGroup": {
|
|
439
484
|
const conversation = await client.conversations.newGroup(
|
|
440
485
|
data.inboxIds,
|
|
441
486
|
data.options,
|
|
@@ -444,7 +489,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
444
489
|
postMessage({ id, action, result });
|
|
445
490
|
break;
|
|
446
491
|
}
|
|
447
|
-
case "newDmWithIdentifier": {
|
|
492
|
+
case "conversations.newDmWithIdentifier": {
|
|
448
493
|
const conversation = await client.conversations.newDmWithIdentifier(
|
|
449
494
|
data.identifier,
|
|
450
495
|
data.options,
|
|
@@ -453,7 +498,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
453
498
|
postMessage({ id, action, result });
|
|
454
499
|
break;
|
|
455
500
|
}
|
|
456
|
-
case "
|
|
501
|
+
case "conversations.newDm": {
|
|
457
502
|
const conversation = await client.conversations.newDm(
|
|
458
503
|
data.inboxId,
|
|
459
504
|
data.options,
|
|
@@ -462,25 +507,17 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
462
507
|
postMessage({ id, action, result });
|
|
463
508
|
break;
|
|
464
509
|
}
|
|
465
|
-
case "
|
|
510
|
+
case "conversations.sync": {
|
|
466
511
|
await client.conversations.sync();
|
|
467
|
-
postMessage({
|
|
468
|
-
id,
|
|
469
|
-
action,
|
|
470
|
-
result: undefined,
|
|
471
|
-
});
|
|
512
|
+
postMessage({ id, action, result: undefined });
|
|
472
513
|
break;
|
|
473
514
|
}
|
|
474
|
-
case "
|
|
515
|
+
case "conversations.syncAll": {
|
|
475
516
|
await client.conversations.syncAll(data.consentStates);
|
|
476
|
-
postMessage({
|
|
477
|
-
id,
|
|
478
|
-
action,
|
|
479
|
-
result: undefined,
|
|
480
|
-
});
|
|
517
|
+
postMessage({ id, action, result: undefined });
|
|
481
518
|
break;
|
|
482
519
|
}
|
|
483
|
-
case "getConversationById": {
|
|
520
|
+
case "conversations.getConversationById": {
|
|
484
521
|
const conversation = client.conversations.getConversationById(data.id);
|
|
485
522
|
const result = conversation
|
|
486
523
|
? await toSafeConversation(conversation)
|
|
@@ -488,13 +525,13 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
488
525
|
postMessage({ id, action, result });
|
|
489
526
|
break;
|
|
490
527
|
}
|
|
491
|
-
case "getMessageById": {
|
|
528
|
+
case "conversations.getMessageById": {
|
|
492
529
|
const message = client.conversations.getMessageById(data.id);
|
|
493
530
|
const result = message ? toSafeMessage(message) : undefined;
|
|
494
531
|
postMessage({ id, action, result });
|
|
495
532
|
break;
|
|
496
533
|
}
|
|
497
|
-
case "getDmByInboxId": {
|
|
534
|
+
case "conversations.getDmByInboxId": {
|
|
498
535
|
const conversation = client.conversations.getDmByInboxId(data.inboxId);
|
|
499
536
|
const result = conversation
|
|
500
537
|
? await toSafeConversation(conversation)
|
|
@@ -502,7 +539,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
502
539
|
postMessage({ id, action, result });
|
|
503
540
|
break;
|
|
504
541
|
}
|
|
505
|
-
case "getHmacKeys": {
|
|
542
|
+
case "conversations.getHmacKeys": {
|
|
506
543
|
const hmacKeys = client.conversations.getHmacKeys();
|
|
507
544
|
const result = Object.fromEntries(
|
|
508
545
|
Array.from(hmacKeys.entries()).map(([groupId, hmacKeys]) => [
|
|
@@ -516,32 +553,44 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
516
553
|
/**
|
|
517
554
|
* Group actions
|
|
518
555
|
*/
|
|
519
|
-
case "
|
|
556
|
+
case "conversation.sync": {
|
|
520
557
|
const group = getGroup(data.id);
|
|
521
558
|
await group.sync();
|
|
522
559
|
const result = await toSafeConversation(group);
|
|
523
560
|
postMessage({ id, action, result });
|
|
524
561
|
break;
|
|
525
562
|
}
|
|
526
|
-
case "
|
|
563
|
+
case "conversation.consentState": {
|
|
564
|
+
const group = getGroup(data.id);
|
|
565
|
+
const result = group.consentState;
|
|
566
|
+
postMessage({ id, action, result });
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
case "conversation.updateConsentState": {
|
|
570
|
+
const group = getGroup(data.id);
|
|
571
|
+
group.updateConsentState(data.state);
|
|
572
|
+
postMessage({ id, action, result: undefined });
|
|
573
|
+
break;
|
|
574
|
+
}
|
|
575
|
+
case "group.updateName": {
|
|
527
576
|
const group = getGroup(data.id);
|
|
528
577
|
await group.updateName(data.name);
|
|
529
578
|
postMessage({ id, action, result: undefined });
|
|
530
579
|
break;
|
|
531
580
|
}
|
|
532
|
-
case "
|
|
581
|
+
case "group.updateDescription": {
|
|
533
582
|
const group = getGroup(data.id);
|
|
534
583
|
await group.updateDescription(data.description);
|
|
535
584
|
postMessage({ id, action, result: undefined });
|
|
536
585
|
break;
|
|
537
586
|
}
|
|
538
|
-
case "
|
|
587
|
+
case "group.updateImageUrl": {
|
|
539
588
|
const group = getGroup(data.id);
|
|
540
589
|
await group.updateImageUrl(data.imageUrl);
|
|
541
590
|
postMessage({ id, action, result: undefined });
|
|
542
591
|
break;
|
|
543
592
|
}
|
|
544
|
-
case "
|
|
593
|
+
case "conversation.send": {
|
|
545
594
|
const group = getGroup(data.id);
|
|
546
595
|
const result = await group.send(
|
|
547
596
|
fromEncodedContent(fromSafeEncodedContent(data.content)),
|
|
@@ -549,7 +598,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
549
598
|
postMessage({ id, action, result });
|
|
550
599
|
break;
|
|
551
600
|
}
|
|
552
|
-
case "
|
|
601
|
+
case "conversation.sendOptimistic": {
|
|
553
602
|
const group = getGroup(data.id);
|
|
554
603
|
const result = group.sendOptimistic(
|
|
555
604
|
fromEncodedContent(fromSafeEncodedContent(data.content)),
|
|
@@ -557,116 +606,104 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
557
606
|
postMessage({ id, action, result });
|
|
558
607
|
break;
|
|
559
608
|
}
|
|
560
|
-
case "
|
|
609
|
+
case "conversation.publishMessages": {
|
|
561
610
|
const group = getGroup(data.id);
|
|
562
611
|
await group.publishMessages();
|
|
563
612
|
postMessage({ id, action, result: undefined });
|
|
564
613
|
break;
|
|
565
614
|
}
|
|
566
|
-
case "
|
|
615
|
+
case "conversation.messages": {
|
|
567
616
|
const group = getGroup(data.id);
|
|
568
617
|
const messages = await group.messages(data.options);
|
|
569
618
|
const result = messages.map((message) => toSafeMessage(message));
|
|
570
619
|
postMessage({ id, action, result });
|
|
571
620
|
break;
|
|
572
621
|
}
|
|
573
|
-
case "
|
|
622
|
+
case "conversation.members": {
|
|
574
623
|
const group = getGroup(data.id);
|
|
575
624
|
const result = await group.members();
|
|
576
625
|
postMessage({ id, action, result });
|
|
577
626
|
break;
|
|
578
627
|
}
|
|
579
|
-
case "
|
|
628
|
+
case "group.listAdmins": {
|
|
580
629
|
const group = getGroup(data.id);
|
|
581
630
|
const result = group.admins;
|
|
582
631
|
postMessage({ id, action, result });
|
|
583
632
|
break;
|
|
584
633
|
}
|
|
585
|
-
case "
|
|
634
|
+
case "group.listSuperAdmins": {
|
|
586
635
|
const group = getGroup(data.id);
|
|
587
636
|
const result = group.superAdmins;
|
|
588
637
|
postMessage({ id, action, result });
|
|
589
638
|
break;
|
|
590
639
|
}
|
|
591
|
-
case "
|
|
592
|
-
const group = getGroup(data.id);
|
|
593
|
-
const result = group.consentState;
|
|
594
|
-
postMessage({ id, action, result });
|
|
595
|
-
break;
|
|
596
|
-
}
|
|
597
|
-
case "updateGroupConsentState": {
|
|
598
|
-
const group = getGroup(data.id);
|
|
599
|
-
group.updateConsentState(data.state);
|
|
600
|
-
postMessage({ id, action, result: undefined });
|
|
601
|
-
break;
|
|
602
|
-
}
|
|
603
|
-
case "addGroupAdmin": {
|
|
640
|
+
case "group.addAdmin": {
|
|
604
641
|
const group = getGroup(data.id);
|
|
605
642
|
await group.addAdmin(data.inboxId);
|
|
606
643
|
postMessage({ id, action, result: undefined });
|
|
607
644
|
break;
|
|
608
645
|
}
|
|
609
|
-
case "
|
|
646
|
+
case "group.removeAdmin": {
|
|
610
647
|
const group = getGroup(data.id);
|
|
611
648
|
await group.removeAdmin(data.inboxId);
|
|
612
649
|
postMessage({ id, action, result: undefined });
|
|
613
650
|
break;
|
|
614
651
|
}
|
|
615
|
-
case "
|
|
652
|
+
case "group.addSuperAdmin": {
|
|
616
653
|
const group = getGroup(data.id);
|
|
617
654
|
await group.addSuperAdmin(data.inboxId);
|
|
618
655
|
postMessage({ id, action, result: undefined });
|
|
619
656
|
break;
|
|
620
657
|
}
|
|
621
|
-
case "
|
|
658
|
+
case "group.removeSuperAdmin": {
|
|
622
659
|
const group = getGroup(data.id);
|
|
623
660
|
await group.removeSuperAdmin(data.inboxId);
|
|
624
661
|
postMessage({ id, action, result: undefined });
|
|
625
662
|
break;
|
|
626
663
|
}
|
|
627
|
-
case "
|
|
664
|
+
case "group.addMembersByIdentifiers": {
|
|
628
665
|
const group = getGroup(data.id);
|
|
629
666
|
await group.addMembersByIdentifiers(data.identifiers);
|
|
630
667
|
postMessage({ id, action, result: undefined });
|
|
631
668
|
break;
|
|
632
669
|
}
|
|
633
|
-
case "
|
|
670
|
+
case "group.removeMembersByIdentifiers": {
|
|
634
671
|
const group = getGroup(data.id);
|
|
635
672
|
await group.removeMembersByIdentifiers(data.identifiers);
|
|
636
673
|
postMessage({ id, action, result: undefined });
|
|
637
674
|
break;
|
|
638
675
|
}
|
|
639
|
-
case "
|
|
676
|
+
case "group.addMembers": {
|
|
640
677
|
const group = getGroup(data.id);
|
|
641
678
|
await group.addMembers(data.inboxIds);
|
|
642
679
|
postMessage({ id, action, result: undefined });
|
|
643
680
|
break;
|
|
644
681
|
}
|
|
645
|
-
case "
|
|
682
|
+
case "group.removeMembers": {
|
|
646
683
|
const group = getGroup(data.id);
|
|
647
684
|
await group.removeMembers(data.inboxIds);
|
|
648
685
|
postMessage({ id, action, result: undefined });
|
|
649
686
|
break;
|
|
650
687
|
}
|
|
651
|
-
case "
|
|
688
|
+
case "group.isAdmin": {
|
|
652
689
|
const group = getGroup(data.id);
|
|
653
690
|
const result = group.isAdmin(data.inboxId);
|
|
654
691
|
postMessage({ id, action, result });
|
|
655
692
|
break;
|
|
656
693
|
}
|
|
657
|
-
case "
|
|
694
|
+
case "group.isSuperAdmin": {
|
|
658
695
|
const group = getGroup(data.id);
|
|
659
696
|
const result = group.isSuperAdmin(data.inboxId);
|
|
660
697
|
postMessage({ id, action, result });
|
|
661
698
|
break;
|
|
662
699
|
}
|
|
663
|
-
case "
|
|
700
|
+
case "dm.peerInboxId": {
|
|
664
701
|
const group = getGroup(data.id);
|
|
665
702
|
const result = group.dmPeerInboxId();
|
|
666
703
|
postMessage({ id, action, result });
|
|
667
704
|
break;
|
|
668
705
|
}
|
|
669
|
-
case "
|
|
706
|
+
case "group.updatePermission": {
|
|
670
707
|
const group = getGroup(data.id);
|
|
671
708
|
await group.updatePermission(
|
|
672
709
|
data.permissionType,
|
|
@@ -676,14 +713,14 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
676
713
|
postMessage({ id, action, result: undefined });
|
|
677
714
|
break;
|
|
678
715
|
}
|
|
679
|
-
case "
|
|
716
|
+
case "group.permissions": {
|
|
680
717
|
const group = getGroup(data.id);
|
|
681
718
|
const safeConversation = await toSafeConversation(group);
|
|
682
719
|
const result = safeConversation.permissions;
|
|
683
720
|
postMessage({ id, action, result });
|
|
684
721
|
break;
|
|
685
722
|
}
|
|
686
|
-
case "
|
|
723
|
+
case "conversation.messageDisappearingSettings": {
|
|
687
724
|
const group = getGroup(data.id);
|
|
688
725
|
const settings = group.messageDisappearingSettings();
|
|
689
726
|
const result = settings
|
|
@@ -692,25 +729,25 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
692
729
|
postMessage({ id, action, result });
|
|
693
730
|
break;
|
|
694
731
|
}
|
|
695
|
-
case "
|
|
732
|
+
case "conversation.updateMessageDisappearingSettings": {
|
|
696
733
|
const group = getGroup(data.id);
|
|
697
734
|
await group.updateMessageDisappearingSettings(data.fromNs, data.inNs);
|
|
698
735
|
postMessage({ id, action, result: undefined });
|
|
699
736
|
break;
|
|
700
737
|
}
|
|
701
|
-
case "
|
|
738
|
+
case "conversation.removeMessageDisappearingSettings": {
|
|
702
739
|
const group = getGroup(data.id);
|
|
703
740
|
await group.removeMessageDisappearingSettings();
|
|
704
741
|
postMessage({ id, action, result: undefined });
|
|
705
742
|
break;
|
|
706
743
|
}
|
|
707
|
-
case "
|
|
744
|
+
case "conversation.isMessageDisappearingEnabled": {
|
|
708
745
|
const group = getGroup(data.id);
|
|
709
746
|
const result = group.isMessageDisappearingEnabled();
|
|
710
747
|
postMessage({ id, action, result });
|
|
711
748
|
break;
|
|
712
749
|
}
|
|
713
|
-
case "
|
|
750
|
+
case "conversation.stream": {
|
|
714
751
|
const group = getGroup(data.groupId);
|
|
715
752
|
const streamCallback = (
|
|
716
753
|
error: Error | null,
|
|
@@ -718,13 +755,13 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
718
755
|
) => {
|
|
719
756
|
if (error) {
|
|
720
757
|
postStreamMessageError({
|
|
721
|
-
|
|
758
|
+
action: "stream.message",
|
|
722
759
|
streamId: data.streamId,
|
|
723
760
|
error,
|
|
724
761
|
});
|
|
725
762
|
} else {
|
|
726
763
|
postStreamMessage({
|
|
727
|
-
|
|
764
|
+
action: "stream.message",
|
|
728
765
|
streamId: data.streamId,
|
|
729
766
|
result: value ? toSafeMessage(value) : undefined,
|
|
730
767
|
});
|
|
@@ -735,18 +772,34 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
735
772
|
postMessage({ id, action, result: undefined });
|
|
736
773
|
break;
|
|
737
774
|
}
|
|
738
|
-
case "
|
|
775
|
+
case "conversation.pausedForVersion": {
|
|
739
776
|
const group = getGroup(data.id);
|
|
740
777
|
const result = group.pausedForVersion();
|
|
741
778
|
postMessage({ id, action, result });
|
|
742
779
|
break;
|
|
743
780
|
}
|
|
744
|
-
case "
|
|
781
|
+
case "conversation.getHmacKeys": {
|
|
745
782
|
const group = getGroup(data.id);
|
|
746
783
|
const result = group.getHmacKeys();
|
|
747
784
|
postMessage({ id, action, result });
|
|
748
785
|
break;
|
|
749
786
|
}
|
|
787
|
+
case "dm.getDuplicateDms": {
|
|
788
|
+
const group = getGroup(data.id);
|
|
789
|
+
const dms = await group.getDuplicateDms();
|
|
790
|
+
const result = await Promise.all(
|
|
791
|
+
dms.map((dm) => toSafeConversation(dm)),
|
|
792
|
+
);
|
|
793
|
+
postMessage({ id, action, result });
|
|
794
|
+
break;
|
|
795
|
+
}
|
|
796
|
+
case "conversation.debugInfo": {
|
|
797
|
+
const group = getGroup(data.id);
|
|
798
|
+
const debugInfo = await group.debugInfo();
|
|
799
|
+
const result = toSafeConversationDebugInfo(debugInfo);
|
|
800
|
+
postMessage({ id, action, result });
|
|
801
|
+
break;
|
|
802
|
+
}
|
|
750
803
|
}
|
|
751
804
|
} catch (e) {
|
|
752
805
|
postMessageError({
|