@xmtp/browser-sdk 0.0.18 → 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 +82 -8
- 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/Conversation.ts +26 -0
- package/src/Conversations.ts +29 -4
- package/src/WorkerConversation.ts +27 -9
- package/src/WorkerConversations.ts +42 -10
- package/src/types/clientEvents.ts +56 -1
- package/src/utils/conversions.ts +57 -1
- package/src/workers/client.ts +101 -1
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ConversationType,
|
|
3
|
+
type ConsentState,
|
|
3
4
|
type Conversation,
|
|
5
|
+
type ConversationListItem,
|
|
4
6
|
type Conversations,
|
|
5
7
|
type Message,
|
|
6
8
|
} from "@xmtp/wasm-bindings";
|
|
7
9
|
import type { StreamCallback } from "@/AsyncStream";
|
|
8
10
|
import {
|
|
11
|
+
fromSafeCreateDmOptions,
|
|
9
12
|
fromSafeCreateGroupOptions,
|
|
10
13
|
fromSafeListConversationsOptions,
|
|
11
14
|
type HmacKeys,
|
|
15
|
+
type SafeCreateDmOptions,
|
|
12
16
|
type SafeCreateGroupOptions,
|
|
13
17
|
type SafeListConversationsOptions,
|
|
14
18
|
} from "@/utils/conversions";
|
|
@@ -29,8 +33,8 @@ export class WorkerConversations {
|
|
|
29
33
|
return this.#conversations.sync();
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
async syncAll() {
|
|
33
|
-
return this.#conversations.syncAllConversations();
|
|
36
|
+
async syncAll(consentStates?: ConsentState[]) {
|
|
37
|
+
return this.#conversations.syncAllConversations(consentStates);
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
getConversationById(id: string) {
|
|
@@ -64,8 +68,10 @@ export class WorkerConversations {
|
|
|
64
68
|
list(options?: SafeListConversationsOptions) {
|
|
65
69
|
const groups = this.#conversations.list(
|
|
66
70
|
options ? fromSafeListConversationsOptions(options) : undefined,
|
|
67
|
-
) as
|
|
68
|
-
return groups.map(
|
|
71
|
+
) as ConversationListItem[];
|
|
72
|
+
return groups.map(
|
|
73
|
+
(item) => new WorkerConversation(this.#client, item.conversation),
|
|
74
|
+
);
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
listGroups(
|
|
@@ -73,15 +79,19 @@ export class WorkerConversations {
|
|
|
73
79
|
) {
|
|
74
80
|
const groups = this.#conversations.listGroups(
|
|
75
81
|
options ? fromSafeListConversationsOptions(options) : undefined,
|
|
76
|
-
) as
|
|
77
|
-
return groups.map(
|
|
82
|
+
) as ConversationListItem[];
|
|
83
|
+
return groups.map(
|
|
84
|
+
(item) => new WorkerConversation(this.#client, item.conversation),
|
|
85
|
+
);
|
|
78
86
|
}
|
|
79
87
|
|
|
80
88
|
listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">) {
|
|
81
89
|
const groups = this.#conversations.listDms(
|
|
82
90
|
options ? fromSafeListConversationsOptions(options) : undefined,
|
|
83
|
-
) as
|
|
84
|
-
return groups.map(
|
|
91
|
+
) as ConversationListItem[];
|
|
92
|
+
return groups.map(
|
|
93
|
+
(item) => new WorkerConversation(this.#client, item.conversation),
|
|
94
|
+
);
|
|
85
95
|
}
|
|
86
96
|
|
|
87
97
|
async newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions) {
|
|
@@ -92,8 +102,30 @@ export class WorkerConversations {
|
|
|
92
102
|
return new WorkerConversation(this.#client, group);
|
|
93
103
|
}
|
|
94
104
|
|
|
95
|
-
async
|
|
96
|
-
|
|
105
|
+
async newGroupByInboxIds(
|
|
106
|
+
inboxIds: string[],
|
|
107
|
+
options?: SafeCreateGroupOptions,
|
|
108
|
+
) {
|
|
109
|
+
const group = await this.#conversations.createGroupByInboxIds(
|
|
110
|
+
inboxIds,
|
|
111
|
+
options ? fromSafeCreateGroupOptions(options) : undefined,
|
|
112
|
+
);
|
|
113
|
+
return new WorkerConversation(this.#client, group);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async newDm(accountAddress: string, options?: SafeCreateDmOptions) {
|
|
117
|
+
const group = await this.#conversations.createDm(
|
|
118
|
+
accountAddress,
|
|
119
|
+
options ? fromSafeCreateDmOptions(options) : undefined,
|
|
120
|
+
);
|
|
121
|
+
return new WorkerConversation(this.#client, group);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async newDmByInboxId(inboxId: string, options?: SafeCreateDmOptions) {
|
|
125
|
+
const group = await this.#conversations.createDmByInboxId(
|
|
126
|
+
inboxId,
|
|
127
|
+
options ? fromSafeCreateDmOptions(options) : undefined,
|
|
128
|
+
);
|
|
97
129
|
return new WorkerConversation(this.#client, group);
|
|
98
130
|
}
|
|
99
131
|
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
import type {
|
|
21
21
|
SafeConsent,
|
|
22
22
|
SafeConversation,
|
|
23
|
+
SafeCreateDmOptions,
|
|
23
24
|
SafeCreateGroupOptions,
|
|
24
25
|
SafeEncodedContent,
|
|
25
26
|
SafeGroupMember,
|
|
@@ -28,6 +29,7 @@ import type {
|
|
|
28
29
|
SafeListConversationsOptions,
|
|
29
30
|
SafeListMessagesOptions,
|
|
30
31
|
SafeMessage,
|
|
32
|
+
SafeMessageDisappearingSettings,
|
|
31
33
|
} from "@/utils/conversions";
|
|
32
34
|
|
|
33
35
|
export type ClientEvents =
|
|
@@ -269,12 +271,31 @@ export type ClientEvents =
|
|
|
269
271
|
options?: SafeCreateGroupOptions;
|
|
270
272
|
};
|
|
271
273
|
}
|
|
274
|
+
| {
|
|
275
|
+
action: "newGroupByInboxIds";
|
|
276
|
+
id: string;
|
|
277
|
+
result: SafeConversation;
|
|
278
|
+
data: {
|
|
279
|
+
inboxIds: string[];
|
|
280
|
+
options?: SafeCreateGroupOptions;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
272
283
|
| {
|
|
273
284
|
action: "newDm";
|
|
274
285
|
id: string;
|
|
275
286
|
result: SafeConversation;
|
|
276
287
|
data: {
|
|
277
288
|
accountAddress: string;
|
|
289
|
+
options?: SafeCreateDmOptions;
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
| {
|
|
293
|
+
action: "newDmByInboxId";
|
|
294
|
+
id: string;
|
|
295
|
+
result: SafeConversation;
|
|
296
|
+
data: {
|
|
297
|
+
inboxId: string;
|
|
298
|
+
options?: SafeCreateDmOptions;
|
|
278
299
|
};
|
|
279
300
|
}
|
|
280
301
|
| {
|
|
@@ -287,7 +308,9 @@ export type ClientEvents =
|
|
|
287
308
|
action: "syncAllConversations";
|
|
288
309
|
id: string;
|
|
289
310
|
result: undefined;
|
|
290
|
-
data:
|
|
311
|
+
data: {
|
|
312
|
+
consentStates?: ConsentState[];
|
|
313
|
+
};
|
|
291
314
|
}
|
|
292
315
|
| {
|
|
293
316
|
action: "getHmacKeys";
|
|
@@ -544,6 +567,38 @@ export type ClientEvents =
|
|
|
544
567
|
id: string;
|
|
545
568
|
};
|
|
546
569
|
}
|
|
570
|
+
| {
|
|
571
|
+
action: "getGroupMessageDisappearingSettings";
|
|
572
|
+
id: string;
|
|
573
|
+
result: SafeMessageDisappearingSettings | undefined;
|
|
574
|
+
data: {
|
|
575
|
+
id: string;
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
| {
|
|
579
|
+
action: "updateGroupMessageDisappearingSettings";
|
|
580
|
+
id: string;
|
|
581
|
+
result: undefined;
|
|
582
|
+
data: SafeMessageDisappearingSettings & {
|
|
583
|
+
id: string;
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
| {
|
|
587
|
+
action: "removeGroupMessageDisappearingSettings";
|
|
588
|
+
id: string;
|
|
589
|
+
result: undefined;
|
|
590
|
+
data: {
|
|
591
|
+
id: string;
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
| {
|
|
595
|
+
action: "isGroupMessageDisappearingEnabled";
|
|
596
|
+
id: string;
|
|
597
|
+
result: boolean;
|
|
598
|
+
data: {
|
|
599
|
+
id: string;
|
|
600
|
+
};
|
|
601
|
+
}
|
|
547
602
|
| {
|
|
548
603
|
action: "streamGroupMessages";
|
|
549
604
|
id: string;
|
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
|
|
|
@@ -244,6 +255,7 @@ export type SafeCreateGroupOptions = {
|
|
|
244
255
|
customPermissionPolicySet?: SafePermissionPolicySet;
|
|
245
256
|
description?: string;
|
|
246
257
|
imageUrlSquare?: string;
|
|
258
|
+
messageDisappearingSettings?: SafeMessageDisappearingSettings;
|
|
247
259
|
name?: string;
|
|
248
260
|
permissions?: GroupPermissionsOptions;
|
|
249
261
|
};
|
|
@@ -251,11 +263,14 @@ export type SafeCreateGroupOptions = {
|
|
|
251
263
|
export const toSafeCreateGroupOptions = (
|
|
252
264
|
options: CreateGroupOptions,
|
|
253
265
|
): SafeCreateGroupOptions => ({
|
|
266
|
+
customPermissionPolicySet: options.customPermissionPolicySet,
|
|
254
267
|
description: options.groupDescription,
|
|
255
268
|
imageUrlSquare: options.groupImageUrlSquare,
|
|
269
|
+
messageDisappearingSettings: options.messageDisappearingSettings
|
|
270
|
+
? toSafeMessageDisappearingSettings(options.messageDisappearingSettings)
|
|
271
|
+
: undefined,
|
|
256
272
|
name: options.groupName,
|
|
257
273
|
permissions: options.permissions,
|
|
258
|
-
customPermissionPolicySet: options.customPermissionPolicySet,
|
|
259
274
|
});
|
|
260
275
|
|
|
261
276
|
export const fromSafeCreateGroupOptions = (
|
|
@@ -271,6 +286,30 @@ export const fromSafeCreateGroupOptions = (
|
|
|
271
286
|
options.permissions === GroupPermissionsOptions.CustomPolicy
|
|
272
287
|
? fromSafePermissionPolicySet(options.customPermissionPolicySet)
|
|
273
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,
|
|
274
313
|
);
|
|
275
314
|
|
|
276
315
|
export type SafeConversation = {
|
|
@@ -427,3 +466,20 @@ export const toSafeHmacKey = (hmacKey: HmacKey): SafeHmacKey => ({
|
|
|
427
466
|
|
|
428
467
|
export type HmacKeys = Map<string, HmacKey[]>;
|
|
429
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
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
toSafeHmacKey,
|
|
18
18
|
toSafeInboxState,
|
|
19
19
|
toSafeMessage,
|
|
20
|
+
toSafeMessageDisappearingSettings,
|
|
20
21
|
} from "@/utils/conversions";
|
|
21
22
|
import { WorkerClient } from "@/WorkerClient";
|
|
22
23
|
import { WorkerConversation } from "@/WorkerConversation";
|
|
@@ -430,9 +431,34 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
430
431
|
});
|
|
431
432
|
break;
|
|
432
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
|
+
}
|
|
433
446
|
case "newDm": {
|
|
434
447
|
const conversation = await client.conversations.newDm(
|
|
435
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,
|
|
436
462
|
);
|
|
437
463
|
postMessage({
|
|
438
464
|
id,
|
|
@@ -451,7 +477,7 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
451
477
|
break;
|
|
452
478
|
}
|
|
453
479
|
case "syncAllConversations": {
|
|
454
|
-
await client.conversations.syncAll();
|
|
480
|
+
await client.conversations.syncAll(data.consentStates);
|
|
455
481
|
postMessage({
|
|
456
482
|
id,
|
|
457
483
|
action,
|
|
@@ -980,6 +1006,80 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
980
1006
|
}
|
|
981
1007
|
break;
|
|
982
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
|
+
}
|
|
983
1083
|
case "streamGroupMessages": {
|
|
984
1084
|
const group = client.conversations.getConversationById(data.groupId);
|
|
985
1085
|
if (group) {
|