@xmtp/browser-sdk 0.0.17 → 0.0.19
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/README.md +2 -3
- package/dist/index.d.ts +186 -31
- 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/package.json +2 -2
- package/src/AsyncStream.ts +80 -0
- package/src/ClientWorkerClass.ts +28 -0
- package/src/Conversation.ts +55 -15
- package/src/Conversations.ts +107 -3
- package/src/WorkerClient.ts +2 -2
- package/src/WorkerConversation.ts +38 -16
- package/src/WorkerConversations.ts +89 -11
- package/src/types/clientEvents.ts +95 -10
- package/src/types/clientStreamEvents.ts +30 -0
- package/src/types/utils.ts +26 -0
- package/src/utils/conversions.ts +63 -18
- package/src/workers/client.ts +252 -20
package/src/utils/conversions.ts
CHANGED
|
@@ -4,11 +4,13 @@ import {
|
|
|
4
4
|
} from "@xmtp/content-type-primitives";
|
|
5
5
|
import {
|
|
6
6
|
Consent,
|
|
7
|
+
CreateDMOptions,
|
|
7
8
|
CreateGroupOptions,
|
|
8
9
|
GroupMember,
|
|
9
10
|
GroupPermissionsOptions,
|
|
10
11
|
ListConversationsOptions,
|
|
11
12
|
ListMessagesOptions,
|
|
13
|
+
MessageDisappearingSettings,
|
|
12
14
|
PermissionPolicySet,
|
|
13
15
|
ContentTypeId as WasmContentTypeId,
|
|
14
16
|
EncodedContent as WasmEncodedContent,
|
|
@@ -175,9 +177,12 @@ export const fromSafeListMessagesOptions = (
|
|
|
175
177
|
|
|
176
178
|
export type SafeListConversationsOptions = {
|
|
177
179
|
allowedStates?: GroupMembershipState[];
|
|
180
|
+
consentStates?: ConsentState[];
|
|
178
181
|
conversationType?: ConversationType;
|
|
179
182
|
createdAfterNs?: bigint;
|
|
180
183
|
createdBeforeNs?: bigint;
|
|
184
|
+
includeDuplicateDms?: boolean;
|
|
185
|
+
includeSyncGroups?: boolean;
|
|
181
186
|
limit?: bigint;
|
|
182
187
|
};
|
|
183
188
|
|
|
@@ -185,9 +190,12 @@ export const toSafeListConversationsOptions = (
|
|
|
185
190
|
options: ListConversationsOptions,
|
|
186
191
|
): SafeListConversationsOptions => ({
|
|
187
192
|
allowedStates: options.allowedStates,
|
|
193
|
+
consentStates: options.consentStates,
|
|
188
194
|
conversationType: options.conversationType,
|
|
189
195
|
createdAfterNs: options.createdAfterNs,
|
|
190
196
|
createdBeforeNs: options.createdBeforeNs,
|
|
197
|
+
includeDuplicateDms: options.includeDuplicateDms,
|
|
198
|
+
includeSyncGroups: options.includeSyncGroups,
|
|
191
199
|
limit: options.limit,
|
|
192
200
|
});
|
|
193
201
|
|
|
@@ -196,9 +204,12 @@ export const fromSafeListConversationsOptions = (
|
|
|
196
204
|
): ListConversationsOptions =>
|
|
197
205
|
new ListConversationsOptions(
|
|
198
206
|
options.allowedStates,
|
|
207
|
+
options.consentStates,
|
|
199
208
|
options.conversationType,
|
|
200
209
|
options.createdAfterNs,
|
|
201
210
|
options.createdBeforeNs,
|
|
211
|
+
options.includeDuplicateDms ?? false,
|
|
212
|
+
options.includeSyncGroups ?? false,
|
|
202
213
|
options.limit,
|
|
203
214
|
);
|
|
204
215
|
|
|
@@ -210,8 +221,7 @@ export type SafePermissionPolicySet = {
|
|
|
210
221
|
updateGroupDescriptionPolicy: PermissionPolicy;
|
|
211
222
|
updateGroupImageUrlSquarePolicy: PermissionPolicy;
|
|
212
223
|
updateGroupNamePolicy: PermissionPolicy;
|
|
213
|
-
|
|
214
|
-
updateMessageExpirationPolicy: PermissionPolicy;
|
|
224
|
+
updateMessageDisappearingPolicy: PermissionPolicy;
|
|
215
225
|
};
|
|
216
226
|
|
|
217
227
|
export const toSafePermissionPolicySet = (
|
|
@@ -224,8 +234,7 @@ export const toSafePermissionPolicySet = (
|
|
|
224
234
|
updateGroupDescriptionPolicy: policySet.updateGroupDescriptionPolicy,
|
|
225
235
|
updateGroupImageUrlSquarePolicy: policySet.updateGroupImageUrlSquarePolicy,
|
|
226
236
|
updateGroupNamePolicy: policySet.updateGroupNamePolicy,
|
|
227
|
-
|
|
228
|
-
updateMessageExpirationPolicy: policySet.updateMessageExpirationPolicy,
|
|
237
|
+
updateMessageDisappearingPolicy: policySet.updateMessageDisappearingPolicy,
|
|
229
238
|
});
|
|
230
239
|
|
|
231
240
|
export const fromSafePermissionPolicySet = (
|
|
@@ -239,28 +248,29 @@ export const fromSafePermissionPolicySet = (
|
|
|
239
248
|
policySet.updateGroupNamePolicy,
|
|
240
249
|
policySet.updateGroupDescriptionPolicy,
|
|
241
250
|
policySet.updateGroupImageUrlSquarePolicy,
|
|
242
|
-
policySet.
|
|
243
|
-
policySet.updateMessageExpirationPolicy,
|
|
251
|
+
policySet.updateMessageDisappearingPolicy,
|
|
244
252
|
);
|
|
245
253
|
|
|
246
254
|
export type SafeCreateGroupOptions = {
|
|
247
255
|
customPermissionPolicySet?: SafePermissionPolicySet;
|
|
248
256
|
description?: string;
|
|
249
257
|
imageUrlSquare?: string;
|
|
258
|
+
messageDisappearingSettings?: SafeMessageDisappearingSettings;
|
|
250
259
|
name?: string;
|
|
251
260
|
permissions?: GroupPermissionsOptions;
|
|
252
|
-
pinnedFrameUrl?: string;
|
|
253
261
|
};
|
|
254
262
|
|
|
255
263
|
export const toSafeCreateGroupOptions = (
|
|
256
264
|
options: CreateGroupOptions,
|
|
257
265
|
): SafeCreateGroupOptions => ({
|
|
266
|
+
customPermissionPolicySet: options.customPermissionPolicySet,
|
|
258
267
|
description: options.groupDescription,
|
|
259
268
|
imageUrlSquare: options.groupImageUrlSquare,
|
|
269
|
+
messageDisappearingSettings: options.messageDisappearingSettings
|
|
270
|
+
? toSafeMessageDisappearingSettings(options.messageDisappearingSettings)
|
|
271
|
+
: undefined,
|
|
260
272
|
name: options.groupName,
|
|
261
|
-
pinnedFrameUrl: options.groupPinnedFrameUrl,
|
|
262
273
|
permissions: options.permissions,
|
|
263
|
-
customPermissionPolicySet: options.customPermissionPolicySet,
|
|
264
274
|
});
|
|
265
275
|
|
|
266
276
|
export const fromSafeCreateGroupOptions = (
|
|
@@ -271,12 +281,35 @@ export const fromSafeCreateGroupOptions = (
|
|
|
271
281
|
options.name,
|
|
272
282
|
options.imageUrlSquare,
|
|
273
283
|
options.description,
|
|
274
|
-
options.pinnedFrameUrl,
|
|
275
284
|
// only include custom policy set if permissions are set to CustomPolicy
|
|
276
285
|
options.customPermissionPolicySet &&
|
|
277
286
|
options.permissions === GroupPermissionsOptions.CustomPolicy
|
|
278
287
|
? fromSafePermissionPolicySet(options.customPermissionPolicySet)
|
|
279
288
|
: undefined,
|
|
289
|
+
options.messageDisappearingSettings
|
|
290
|
+
? fromSafeMessageDisappearingSettings(options.messageDisappearingSettings)
|
|
291
|
+
: undefined,
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
export type SafeCreateDmOptions = {
|
|
295
|
+
messageDisappearingSettings?: SafeMessageDisappearingSettings;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
export const toSafeCreateDmOptions = (
|
|
299
|
+
options: CreateDMOptions,
|
|
300
|
+
): SafeCreateDmOptions => ({
|
|
301
|
+
messageDisappearingSettings: options.messageDisappearingSettings
|
|
302
|
+
? toSafeMessageDisappearingSettings(options.messageDisappearingSettings)
|
|
303
|
+
: undefined,
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
export const fromSafeCreateDmOptions = (
|
|
307
|
+
options: SafeCreateDmOptions,
|
|
308
|
+
): CreateDMOptions =>
|
|
309
|
+
new CreateDMOptions(
|
|
310
|
+
options.messageDisappearingSettings
|
|
311
|
+
? fromSafeMessageDisappearingSettings(options.messageDisappearingSettings)
|
|
312
|
+
: undefined,
|
|
280
313
|
);
|
|
281
314
|
|
|
282
315
|
export type SafeConversation = {
|
|
@@ -284,7 +317,6 @@ export type SafeConversation = {
|
|
|
284
317
|
name: string;
|
|
285
318
|
imageUrl: string;
|
|
286
319
|
description: string;
|
|
287
|
-
pinnedFrameUrl: string;
|
|
288
320
|
permissions: {
|
|
289
321
|
policyType: GroupPermissionsOptions;
|
|
290
322
|
policySet: {
|
|
@@ -295,8 +327,7 @@ export type SafeConversation = {
|
|
|
295
327
|
updateGroupDescriptionPolicy: PermissionPolicy;
|
|
296
328
|
updateGroupImageUrlSquarePolicy: PermissionPolicy;
|
|
297
329
|
updateGroupNamePolicy: PermissionPolicy;
|
|
298
|
-
|
|
299
|
-
updateMessageExpirationPolicy: PermissionPolicy;
|
|
330
|
+
updateMessageDisappearingPolicy: PermissionPolicy;
|
|
300
331
|
};
|
|
301
332
|
};
|
|
302
333
|
isActive: boolean;
|
|
@@ -317,7 +348,6 @@ export const toSafeConversation = async (
|
|
|
317
348
|
const name = conversation.name;
|
|
318
349
|
const imageUrl = conversation.imageUrl;
|
|
319
350
|
const description = conversation.description;
|
|
320
|
-
const pinnedFrameUrl = conversation.pinnedFrameUrl;
|
|
321
351
|
const permissions = conversation.permissions;
|
|
322
352
|
const isActive = conversation.isActive;
|
|
323
353
|
const addedByInboxId = conversation.addedByInboxId;
|
|
@@ -332,7 +362,6 @@ export const toSafeConversation = async (
|
|
|
332
362
|
name,
|
|
333
363
|
imageUrl,
|
|
334
364
|
description,
|
|
335
|
-
pinnedFrameUrl,
|
|
336
365
|
permissions: {
|
|
337
366
|
policyType,
|
|
338
367
|
policySet: {
|
|
@@ -344,9 +373,8 @@ export const toSafeConversation = async (
|
|
|
344
373
|
updateGroupImageUrlSquarePolicy:
|
|
345
374
|
policySet.updateGroupImageUrlSquarePolicy,
|
|
346
375
|
updateGroupNamePolicy: policySet.updateGroupNamePolicy,
|
|
347
|
-
|
|
348
|
-
policySet.
|
|
349
|
-
updateMessageExpirationPolicy: policySet.updateMessageExpirationPolicy,
|
|
376
|
+
updateMessageDisappearingPolicy:
|
|
377
|
+
policySet.updateMessageDisappearingPolicy,
|
|
350
378
|
},
|
|
351
379
|
},
|
|
352
380
|
isActive,
|
|
@@ -438,3 +466,20 @@ export const toSafeHmacKey = (hmacKey: HmacKey): SafeHmacKey => ({
|
|
|
438
466
|
|
|
439
467
|
export type HmacKeys = Map<string, HmacKey[]>;
|
|
440
468
|
export type SafeHmacKeys = Record<string, SafeHmacKey[]>;
|
|
469
|
+
|
|
470
|
+
export type SafeMessageDisappearingSettings = {
|
|
471
|
+
fromNs: bigint;
|
|
472
|
+
inNs: bigint;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
export const toSafeMessageDisappearingSettings = (
|
|
476
|
+
settings: MessageDisappearingSettings,
|
|
477
|
+
): SafeMessageDisappearingSettings => ({
|
|
478
|
+
fromNs: settings.fromNs,
|
|
479
|
+
inNs: settings.inNs,
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
export const fromSafeMessageDisappearingSettings = (
|
|
483
|
+
settings: SafeMessageDisappearingSettings,
|
|
484
|
+
): MessageDisappearingSettings =>
|
|
485
|
+
new MessageDisappearingSettings(settings.fromNs, settings.inNs);
|
package/src/workers/client.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import type { Conversation, Message, StreamCloser } from "@xmtp/wasm-bindings";
|
|
1
2
|
import type {
|
|
2
3
|
ClientEventsActions,
|
|
3
4
|
ClientEventsClientMessageData,
|
|
4
5
|
ClientEventsErrorData,
|
|
5
6
|
ClientEventsWorkerPostMessageData,
|
|
6
7
|
} from "@/types";
|
|
8
|
+
import type {
|
|
9
|
+
ClientStreamEventsErrorData,
|
|
10
|
+
ClientStreamEventsTypes,
|
|
11
|
+
ClientStreamEventsWorkerPostMessageData,
|
|
12
|
+
} from "@/types/clientStreamEvents";
|
|
7
13
|
import {
|
|
8
14
|
fromEncodedContent,
|
|
9
15
|
fromSafeEncodedContent,
|
|
@@ -11,12 +17,16 @@ import {
|
|
|
11
17
|
toSafeHmacKey,
|
|
12
18
|
toSafeInboxState,
|
|
13
19
|
toSafeMessage,
|
|
20
|
+
toSafeMessageDisappearingSettings,
|
|
14
21
|
} from "@/utils/conversions";
|
|
15
22
|
import { WorkerClient } from "@/WorkerClient";
|
|
23
|
+
import { WorkerConversation } from "@/WorkerConversation";
|
|
16
24
|
|
|
17
25
|
let client: WorkerClient;
|
|
18
26
|
let enableLogging = false;
|
|
19
27
|
|
|
28
|
+
const streamClosers = new Map<string, StreamCloser>();
|
|
29
|
+
|
|
20
30
|
/**
|
|
21
31
|
* Type-safe postMessage
|
|
22
32
|
*/
|
|
@@ -33,6 +43,22 @@ const postMessageError = (data: ClientEventsErrorData) => {
|
|
|
33
43
|
self.postMessage(data);
|
|
34
44
|
};
|
|
35
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Type-safe postMessage for streams
|
|
48
|
+
*/
|
|
49
|
+
const postStreamMessage = <A extends ClientStreamEventsTypes>(
|
|
50
|
+
data: ClientStreamEventsWorkerPostMessageData<A>,
|
|
51
|
+
) => {
|
|
52
|
+
self.postMessage(data);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Type-safe postMessage for stream errors
|
|
57
|
+
*/
|
|
58
|
+
const postStreamMessageError = (data: ClientStreamEventsErrorData) => {
|
|
59
|
+
self.postMessage(data);
|
|
60
|
+
};
|
|
61
|
+
|
|
36
62
|
self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
37
63
|
const { action, id, data } = event.data;
|
|
38
64
|
|
|
@@ -53,6 +79,28 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
53
79
|
|
|
54
80
|
try {
|
|
55
81
|
switch (action) {
|
|
82
|
+
/**
|
|
83
|
+
* Stream actions
|
|
84
|
+
*/
|
|
85
|
+
case "endStream": {
|
|
86
|
+
const streamCloser = streamClosers.get(data.streamId);
|
|
87
|
+
if (streamCloser) {
|
|
88
|
+
streamCloser.end();
|
|
89
|
+
streamClosers.delete(data.streamId);
|
|
90
|
+
postMessage({
|
|
91
|
+
id,
|
|
92
|
+
action,
|
|
93
|
+
result: undefined,
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
postMessageError({
|
|
97
|
+
id,
|
|
98
|
+
action,
|
|
99
|
+
error: `Stream "${data.streamId}" not found`,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
56
104
|
/**
|
|
57
105
|
* Client actions
|
|
58
106
|
*/
|
|
@@ -76,7 +124,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
76
124
|
});
|
|
77
125
|
break;
|
|
78
126
|
case "createInboxSignatureText": {
|
|
79
|
-
const result =
|
|
127
|
+
const result = client.createInboxSignatureText();
|
|
80
128
|
postMessage({
|
|
81
129
|
id,
|
|
82
130
|
action,
|
|
@@ -266,6 +314,72 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
266
314
|
/**
|
|
267
315
|
* Conversations actions
|
|
268
316
|
*/
|
|
317
|
+
case "streamAllGroups": {
|
|
318
|
+
const streamCallback = async (
|
|
319
|
+
error: Error | null,
|
|
320
|
+
value: Conversation | undefined,
|
|
321
|
+
) => {
|
|
322
|
+
if (error) {
|
|
323
|
+
postStreamMessageError({
|
|
324
|
+
type: "group",
|
|
325
|
+
streamId: data.streamId,
|
|
326
|
+
error: error.message,
|
|
327
|
+
});
|
|
328
|
+
} else {
|
|
329
|
+
postStreamMessage({
|
|
330
|
+
type: "group",
|
|
331
|
+
streamId: data.streamId,
|
|
332
|
+
result: value
|
|
333
|
+
? await toSafeConversation(
|
|
334
|
+
new WorkerConversation(client, value),
|
|
335
|
+
)
|
|
336
|
+
: undefined,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
const streamCloser = client.conversations.stream(
|
|
341
|
+
streamCallback,
|
|
342
|
+
data.conversationType,
|
|
343
|
+
);
|
|
344
|
+
streamClosers.set(data.streamId, streamCloser);
|
|
345
|
+
postMessage({
|
|
346
|
+
id,
|
|
347
|
+
action,
|
|
348
|
+
result: undefined,
|
|
349
|
+
});
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
case "streamAllMessages": {
|
|
353
|
+
const streamCallback = (
|
|
354
|
+
error: Error | null,
|
|
355
|
+
value: Message | undefined,
|
|
356
|
+
) => {
|
|
357
|
+
if (error) {
|
|
358
|
+
postStreamMessageError({
|
|
359
|
+
type: "message",
|
|
360
|
+
streamId: data.streamId,
|
|
361
|
+
error: error.message,
|
|
362
|
+
});
|
|
363
|
+
} else {
|
|
364
|
+
postStreamMessage({
|
|
365
|
+
type: "message",
|
|
366
|
+
streamId: data.streamId,
|
|
367
|
+
result: value ? toSafeMessage(value) : undefined,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
const streamCloser = client.conversations.streamAllMessages(
|
|
372
|
+
streamCallback,
|
|
373
|
+
data.conversationType,
|
|
374
|
+
);
|
|
375
|
+
streamClosers.set(data.streamId, streamCloser);
|
|
376
|
+
postMessage({
|
|
377
|
+
id,
|
|
378
|
+
action,
|
|
379
|
+
result: undefined,
|
|
380
|
+
});
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
269
383
|
case "getConversations": {
|
|
270
384
|
const conversations = client.conversations.list(data.options);
|
|
271
385
|
postMessage({
|
|
@@ -317,9 +431,34 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
317
431
|
});
|
|
318
432
|
break;
|
|
319
433
|
}
|
|
434
|
+
case "newGroupByInboxIds": {
|
|
435
|
+
const conversation = await client.conversations.newGroupByInboxIds(
|
|
436
|
+
data.inboxIds,
|
|
437
|
+
data.options,
|
|
438
|
+
);
|
|
439
|
+
postMessage({
|
|
440
|
+
id,
|
|
441
|
+
action,
|
|
442
|
+
result: await toSafeConversation(conversation),
|
|
443
|
+
});
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
320
446
|
case "newDm": {
|
|
321
447
|
const conversation = await client.conversations.newDm(
|
|
322
448
|
data.accountAddress,
|
|
449
|
+
data.options,
|
|
450
|
+
);
|
|
451
|
+
postMessage({
|
|
452
|
+
id,
|
|
453
|
+
action,
|
|
454
|
+
result: await toSafeConversation(conversation),
|
|
455
|
+
});
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
case "newDmByInboxId": {
|
|
459
|
+
const conversation = await client.conversations.newDmByInboxId(
|
|
460
|
+
data.inboxId,
|
|
461
|
+
data.options,
|
|
323
462
|
);
|
|
324
463
|
postMessage({
|
|
325
464
|
id,
|
|
@@ -338,7 +477,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
338
477
|
break;
|
|
339
478
|
}
|
|
340
479
|
case "syncAllConversations": {
|
|
341
|
-
await client.conversations.syncAll();
|
|
480
|
+
await client.conversations.syncAll(data.consentStates);
|
|
342
481
|
postMessage({
|
|
343
482
|
id,
|
|
344
483
|
action,
|
|
@@ -466,24 +605,6 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
466
605
|
}
|
|
467
606
|
break;
|
|
468
607
|
}
|
|
469
|
-
case "updateGroupPinnedFrameUrl": {
|
|
470
|
-
const group = client.conversations.getConversationById(data.id);
|
|
471
|
-
if (group) {
|
|
472
|
-
await group.updatePinnedFrameUrl(data.pinnedFrameUrl);
|
|
473
|
-
postMessage({
|
|
474
|
-
id,
|
|
475
|
-
action,
|
|
476
|
-
result: undefined,
|
|
477
|
-
});
|
|
478
|
-
} else {
|
|
479
|
-
postMessageError({
|
|
480
|
-
id,
|
|
481
|
-
action,
|
|
482
|
-
error: "Group not found",
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
break;
|
|
486
|
-
}
|
|
487
608
|
case "sendGroupMessage": {
|
|
488
609
|
const group = client.conversations.getConversationById(data.id);
|
|
489
610
|
if (group) {
|
|
@@ -885,6 +1006,117 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
885
1006
|
}
|
|
886
1007
|
break;
|
|
887
1008
|
}
|
|
1009
|
+
case "getGroupMessageDisappearingSettings": {
|
|
1010
|
+
const group = client.conversations.getConversationById(data.id);
|
|
1011
|
+
if (group) {
|
|
1012
|
+
const result = group.messageDisappearingSettings();
|
|
1013
|
+
postMessage({
|
|
1014
|
+
id,
|
|
1015
|
+
action,
|
|
1016
|
+
result: result
|
|
1017
|
+
? toSafeMessageDisappearingSettings(result)
|
|
1018
|
+
: undefined,
|
|
1019
|
+
});
|
|
1020
|
+
} else {
|
|
1021
|
+
postMessageError({
|
|
1022
|
+
id,
|
|
1023
|
+
action,
|
|
1024
|
+
error: "Group not found",
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
break;
|
|
1028
|
+
}
|
|
1029
|
+
case "updateGroupMessageDisappearingSettings": {
|
|
1030
|
+
const group = client.conversations.getConversationById(data.id);
|
|
1031
|
+
if (group) {
|
|
1032
|
+
await group.updateMessageDisappearingSettings(data.fromNs, data.inNs);
|
|
1033
|
+
postMessage({
|
|
1034
|
+
id,
|
|
1035
|
+
action,
|
|
1036
|
+
result: undefined,
|
|
1037
|
+
});
|
|
1038
|
+
} else {
|
|
1039
|
+
postMessageError({
|
|
1040
|
+
id,
|
|
1041
|
+
action,
|
|
1042
|
+
error: "Group not found",
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
break;
|
|
1046
|
+
}
|
|
1047
|
+
case "removeGroupMessageDisappearingSettings": {
|
|
1048
|
+
const group = client.conversations.getConversationById(data.id);
|
|
1049
|
+
if (group) {
|
|
1050
|
+
await group.removeMessageDisappearingSettings();
|
|
1051
|
+
postMessage({
|
|
1052
|
+
id,
|
|
1053
|
+
action,
|
|
1054
|
+
result: undefined,
|
|
1055
|
+
});
|
|
1056
|
+
} else {
|
|
1057
|
+
postMessageError({
|
|
1058
|
+
id,
|
|
1059
|
+
action,
|
|
1060
|
+
error: "Group not found",
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
break;
|
|
1064
|
+
}
|
|
1065
|
+
case "isGroupMessageDisappearingEnabled": {
|
|
1066
|
+
const group = client.conversations.getConversationById(data.id);
|
|
1067
|
+
if (group) {
|
|
1068
|
+
const result = group.isMessageDisappearingEnabled();
|
|
1069
|
+
postMessage({
|
|
1070
|
+
id,
|
|
1071
|
+
action,
|
|
1072
|
+
result,
|
|
1073
|
+
});
|
|
1074
|
+
} else {
|
|
1075
|
+
postMessageError({
|
|
1076
|
+
id,
|
|
1077
|
+
action,
|
|
1078
|
+
error: "Group not found",
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
break;
|
|
1082
|
+
}
|
|
1083
|
+
case "streamGroupMessages": {
|
|
1084
|
+
const group = client.conversations.getConversationById(data.groupId);
|
|
1085
|
+
if (group) {
|
|
1086
|
+
const streamCallback = (
|
|
1087
|
+
error: Error | null,
|
|
1088
|
+
value: Message | undefined,
|
|
1089
|
+
) => {
|
|
1090
|
+
if (error) {
|
|
1091
|
+
postStreamMessageError({
|
|
1092
|
+
type: "message",
|
|
1093
|
+
streamId: data.streamId,
|
|
1094
|
+
error: error.message,
|
|
1095
|
+
});
|
|
1096
|
+
} else {
|
|
1097
|
+
postStreamMessage({
|
|
1098
|
+
type: "message",
|
|
1099
|
+
streamId: data.streamId,
|
|
1100
|
+
result: value ? toSafeMessage(value) : undefined,
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
const streamCloser = group.stream(streamCallback);
|
|
1105
|
+
streamClosers.set(data.streamId, streamCloser);
|
|
1106
|
+
postMessage({
|
|
1107
|
+
id,
|
|
1108
|
+
action,
|
|
1109
|
+
result: undefined,
|
|
1110
|
+
});
|
|
1111
|
+
} else {
|
|
1112
|
+
postMessageError({
|
|
1113
|
+
id,
|
|
1114
|
+
action,
|
|
1115
|
+
error: "Group not found",
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
break;
|
|
1119
|
+
}
|
|
888
1120
|
}
|
|
889
1121
|
} catch (e) {
|
|
890
1122
|
postMessageError({
|