@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/Preferences.ts
CHANGED
|
@@ -1,72 +1,85 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type {
|
|
2
|
+
Consent,
|
|
3
|
+
ConsentEntityType,
|
|
4
|
+
ConsentState,
|
|
5
|
+
UserPreferenceUpdate,
|
|
6
|
+
} from "@xmtp/wasm-bindings";
|
|
7
|
+
import type { ClientWorkerAction } from "@/types/actions";
|
|
4
8
|
import {
|
|
5
9
|
createStream,
|
|
6
10
|
type StreamCallback,
|
|
7
11
|
type StreamOptions,
|
|
8
12
|
} from "@/utils/streams";
|
|
9
|
-
import
|
|
13
|
+
import { uuid } from "@/utils/uuid";
|
|
14
|
+
import type { WorkerBridge } from "@/utils/WorkerBridge";
|
|
10
15
|
|
|
11
16
|
/**
|
|
12
17
|
* Manages user preferences and consent states
|
|
13
18
|
*
|
|
14
19
|
* This class is not intended to be initialized directly.
|
|
15
20
|
*/
|
|
16
|
-
export class Preferences
|
|
17
|
-
#
|
|
21
|
+
export class Preferences {
|
|
22
|
+
#worker: WorkerBridge<ClientWorkerAction>;
|
|
18
23
|
|
|
19
24
|
/**
|
|
20
25
|
* Creates a new preferences instance
|
|
21
26
|
*
|
|
22
27
|
* @param client - The client instance managing preferences
|
|
23
28
|
*/
|
|
24
|
-
constructor(
|
|
25
|
-
this.#
|
|
29
|
+
constructor(worker: WorkerBridge<ClientWorkerAction>) {
|
|
30
|
+
this.#worker = worker;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
sync() {
|
|
29
|
-
return this.#
|
|
34
|
+
return this.#worker.action("preferences.sync");
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
/**
|
|
33
|
-
* Retrieves the current inbox state
|
|
38
|
+
* Retrieves the current inbox state of this client from the local database
|
|
34
39
|
*
|
|
35
|
-
* @param refreshFromNetwork - Optional flag to force refresh from network
|
|
36
40
|
* @returns Promise that resolves with the inbox state
|
|
37
41
|
*/
|
|
38
|
-
async inboxState(
|
|
39
|
-
return this.#
|
|
40
|
-
refreshFromNetwork:
|
|
42
|
+
async inboxState() {
|
|
43
|
+
return this.#worker.action("preferences.inboxState", {
|
|
44
|
+
refreshFromNetwork: false,
|
|
41
45
|
});
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
/**
|
|
45
|
-
* Retrieves inbox state
|
|
49
|
+
* Retrieves the latest inbox state of this client from the network
|
|
50
|
+
*
|
|
51
|
+
* @returns Promise that resolves with the inbox state
|
|
52
|
+
*/
|
|
53
|
+
async fetchInboxState() {
|
|
54
|
+
return this.#worker.action("preferences.inboxState", {
|
|
55
|
+
refreshFromNetwork: true,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves the current inbox states for specified inbox IDs from the local
|
|
61
|
+
* database
|
|
46
62
|
*
|
|
47
63
|
* @param inboxIds - Array of inbox IDs to get state for
|
|
48
|
-
* @
|
|
49
|
-
* @returns Promise that resolves with the inbox state for the inbox IDs
|
|
64
|
+
* @returns Promise that resolves with the inbox states for the inbox IDs
|
|
50
65
|
*/
|
|
51
|
-
async
|
|
52
|
-
|
|
53
|
-
refreshFromNetwork?: boolean,
|
|
54
|
-
) {
|
|
55
|
-
return this.#client.sendMessage("preferences.inboxStateFromInboxIds", {
|
|
66
|
+
async getInboxStates(inboxIds: string[]) {
|
|
67
|
+
return this.#worker.action("preferences.getInboxStates", {
|
|
56
68
|
inboxIds,
|
|
57
|
-
refreshFromNetwork:
|
|
69
|
+
refreshFromNetwork: false,
|
|
58
70
|
});
|
|
59
71
|
}
|
|
60
72
|
|
|
61
73
|
/**
|
|
62
|
-
*
|
|
74
|
+
* Retrieves the latest inbox states for specified inbox IDs from the network
|
|
63
75
|
*
|
|
64
|
-
* @param
|
|
65
|
-
* @returns Promise that resolves with the
|
|
76
|
+
* @param inboxIds - Array of inbox IDs to get state for
|
|
77
|
+
* @returns Promise that resolves with the inbox states for the inbox IDs
|
|
66
78
|
*/
|
|
67
|
-
async
|
|
68
|
-
return this.#
|
|
69
|
-
|
|
79
|
+
async fetchInboxStates(inboxIds: string[]) {
|
|
80
|
+
return this.#worker.action("preferences.getInboxStates", {
|
|
81
|
+
inboxIds,
|
|
82
|
+
refreshFromNetwork: true,
|
|
70
83
|
});
|
|
71
84
|
}
|
|
72
85
|
|
|
@@ -76,8 +89,8 @@ export class Preferences<ContentTypes = unknown> {
|
|
|
76
89
|
* @param records - Array of consent records to update
|
|
77
90
|
* @returns Promise that resolves when consent states are updated
|
|
78
91
|
*/
|
|
79
|
-
async setConsentStates(records:
|
|
80
|
-
return this.#
|
|
92
|
+
async setConsentStates(records: Consent[]) {
|
|
93
|
+
return this.#worker.action("preferences.setConsentStates", {
|
|
81
94
|
records,
|
|
82
95
|
});
|
|
83
96
|
}
|
|
@@ -89,8 +102,11 @@ export class Preferences<ContentTypes = unknown> {
|
|
|
89
102
|
* @param entity - Entity identifier
|
|
90
103
|
* @returns Promise that resolves with the consent state
|
|
91
104
|
*/
|
|
92
|
-
async getConsentState(
|
|
93
|
-
|
|
105
|
+
async getConsentState(
|
|
106
|
+
entityType: ConsentEntityType,
|
|
107
|
+
entity: string,
|
|
108
|
+
): Promise<ConsentState> {
|
|
109
|
+
return this.#worker.action("preferences.getConsentState", {
|
|
94
110
|
entityType,
|
|
95
111
|
entity,
|
|
96
112
|
});
|
|
@@ -102,27 +118,25 @@ export class Preferences<ContentTypes = unknown> {
|
|
|
102
118
|
* @param options - Optional stream options
|
|
103
119
|
* @returns Stream instance for consent updates
|
|
104
120
|
*/
|
|
105
|
-
async streamConsent(options?: StreamOptions<
|
|
121
|
+
async streamConsent(options?: StreamOptions<Consent[]>) {
|
|
106
122
|
const stream = async (
|
|
107
|
-
callback: StreamCallback<
|
|
123
|
+
callback: StreamCallback<Consent[]>,
|
|
108
124
|
onFail: () => void,
|
|
109
125
|
) => {
|
|
110
|
-
const streamId =
|
|
126
|
+
const streamId = uuid();
|
|
111
127
|
// sync the conversation
|
|
112
|
-
|
|
128
|
+
if (!options?.disableSync) {
|
|
129
|
+
await this.sync();
|
|
130
|
+
}
|
|
113
131
|
// start the stream
|
|
114
|
-
await this.#
|
|
132
|
+
await this.#worker.action("preferences.streamConsent", {
|
|
115
133
|
streamId,
|
|
116
134
|
});
|
|
117
135
|
// handle stream messages
|
|
118
|
-
return this.#
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
...options,
|
|
123
|
-
onFail,
|
|
124
|
-
},
|
|
125
|
-
);
|
|
136
|
+
return this.#worker.handleStreamMessage<Consent[]>(streamId, callback, {
|
|
137
|
+
...options,
|
|
138
|
+
onFail,
|
|
139
|
+
});
|
|
126
140
|
};
|
|
127
141
|
|
|
128
142
|
return createStream(stream, undefined, options);
|
|
@@ -134,20 +148,22 @@ export class Preferences<ContentTypes = unknown> {
|
|
|
134
148
|
* @param options - Optional stream options
|
|
135
149
|
* @returns Stream instance for preference updates
|
|
136
150
|
*/
|
|
137
|
-
async streamPreferences(options?: StreamOptions<
|
|
151
|
+
async streamPreferences(options?: StreamOptions<UserPreferenceUpdate[]>) {
|
|
138
152
|
const stream = async (
|
|
139
|
-
callback: StreamCallback<
|
|
153
|
+
callback: StreamCallback<UserPreferenceUpdate[]>,
|
|
140
154
|
onFail: () => void,
|
|
141
155
|
) => {
|
|
142
|
-
const streamId =
|
|
156
|
+
const streamId = uuid();
|
|
143
157
|
// sync the conversation
|
|
144
|
-
|
|
158
|
+
if (!options?.disableSync) {
|
|
159
|
+
await this.sync();
|
|
160
|
+
}
|
|
145
161
|
// start the stream
|
|
146
|
-
await this.#
|
|
162
|
+
await this.#worker.action("preferences.streamPreferences", {
|
|
147
163
|
streamId,
|
|
148
164
|
});
|
|
149
165
|
// handle stream messages
|
|
150
|
-
return this.#
|
|
166
|
+
return this.#worker.handleStreamMessage<UserPreferenceUpdate[]>(
|
|
151
167
|
streamId,
|
|
152
168
|
callback,
|
|
153
169
|
{
|
package/src/WorkerClient.ts
CHANGED
|
@@ -18,11 +18,11 @@ export class WorkerClient {
|
|
|
18
18
|
#debugInformation: WorkerDebugInformation;
|
|
19
19
|
#preferences: WorkerPreferences;
|
|
20
20
|
|
|
21
|
-
constructor(client: Client
|
|
21
|
+
constructor(client: Client) {
|
|
22
22
|
this.#client = client;
|
|
23
23
|
const conversations = client.conversations();
|
|
24
24
|
this.#conversations = new WorkerConversations(this, conversations);
|
|
25
|
-
this.#debugInformation = new WorkerDebugInformation(client
|
|
25
|
+
this.#debugInformation = new WorkerDebugInformation(client);
|
|
26
26
|
this.#preferences = new WorkerPreferences(client, conversations);
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -31,7 +31,7 @@ export class WorkerClient {
|
|
|
31
31
|
options?: Omit<ClientOptions, "codecs">,
|
|
32
32
|
) {
|
|
33
33
|
const client = await createClient(identifier, options);
|
|
34
|
-
return new WorkerClient(client
|
|
34
|
+
return new WorkerClient(client);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
get libxmtpVersion() {
|
|
@@ -143,7 +143,7 @@ export class WorkerClient {
|
|
|
143
143
|
await this.#client.registerIdentity(signatureRequest);
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
async
|
|
146
|
+
async getInboxIdByIdentifier(identifier: Identifier) {
|
|
147
147
|
return this.#client.findInboxIdByIdentifier(identifier);
|
|
148
148
|
}
|
|
149
149
|
|
|
@@ -179,7 +179,7 @@ export class WorkerClient {
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
async
|
|
182
|
+
async fetchKeyPackageStatuses(installationIds: string[]) {
|
|
183
183
|
return this.#client.getKeyPackageStatusesForInstallationIds(
|
|
184
184
|
installationIds,
|
|
185
185
|
) as Promise<Map<string, KeyPackageStatus>>;
|
|
@@ -1,41 +1,42 @@
|
|
|
1
1
|
import {
|
|
2
2
|
GroupMembershipState,
|
|
3
|
-
MessageDisappearingSettings,
|
|
4
3
|
SortDirection,
|
|
4
|
+
type Actions,
|
|
5
|
+
type Attachment,
|
|
5
6
|
type ConsentState,
|
|
6
7
|
type Conversation,
|
|
7
8
|
type ConversationDebugInfo,
|
|
9
|
+
type DecodedMessage,
|
|
8
10
|
type EncodedContent,
|
|
9
11
|
type GroupMember,
|
|
10
12
|
type HmacKey,
|
|
11
13
|
type Identifier,
|
|
14
|
+
type Intent,
|
|
15
|
+
type ListMessagesOptions,
|
|
12
16
|
type Message,
|
|
17
|
+
type MessageDisappearingSettings,
|
|
13
18
|
type MetadataField,
|
|
19
|
+
type MultiRemoteAttachment,
|
|
14
20
|
type PermissionPolicy,
|
|
15
21
|
type PermissionUpdateType,
|
|
22
|
+
type Reaction,
|
|
23
|
+
type RemoteAttachment,
|
|
24
|
+
type Reply,
|
|
16
25
|
type SendMessageOpts,
|
|
26
|
+
type TransactionReference,
|
|
27
|
+
type WalletSendCalls,
|
|
17
28
|
} from "@xmtp/wasm-bindings";
|
|
18
|
-
import {
|
|
19
|
-
fromSafeListMessagesOptions,
|
|
20
|
-
toSafeGroupMember,
|
|
21
|
-
type SafeListMessagesOptions,
|
|
22
|
-
} from "@/utils/conversions";
|
|
29
|
+
import type { LastReadTimes } from "@/utils/conversions";
|
|
23
30
|
import type { StreamCallback } from "@/utils/streams";
|
|
24
31
|
import type { WorkerClient } from "@/WorkerClient";
|
|
25
32
|
|
|
26
33
|
export class WorkerConversation {
|
|
27
34
|
#client: WorkerClient;
|
|
28
35
|
#group: Conversation;
|
|
29
|
-
#isCommitLogForked?: boolean;
|
|
30
36
|
|
|
31
|
-
constructor(
|
|
32
|
-
client: WorkerClient,
|
|
33
|
-
group: Conversation,
|
|
34
|
-
isCommitLogForked?: boolean,
|
|
35
|
-
) {
|
|
37
|
+
constructor(client: WorkerClient, group: Conversation) {
|
|
36
38
|
this.#client = client;
|
|
37
39
|
this.#group = group;
|
|
38
|
-
this.#isCommitLogForked = isCommitLogForked;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
get id() {
|
|
@@ -83,10 +84,6 @@ export class WorkerConversation {
|
|
|
83
84
|
return this.#group.isActive();
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
get isCommitLogForked() {
|
|
87
|
-
return this.#isCommitLogForked;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
87
|
get addedByInboxId() {
|
|
91
88
|
return this.#group.addedByInboxId();
|
|
92
89
|
}
|
|
@@ -107,31 +104,27 @@ export class WorkerConversation {
|
|
|
107
104
|
}
|
|
108
105
|
|
|
109
106
|
async metadata() {
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
creatorInboxId: metadata.creatorInboxId(),
|
|
113
|
-
conversationType: metadata.conversationType(),
|
|
114
|
-
};
|
|
107
|
+
return this.#group.groupMetadata();
|
|
115
108
|
}
|
|
116
109
|
|
|
117
110
|
async members() {
|
|
118
111
|
const members = (await this.#group.listMembers()) as GroupMember[];
|
|
119
|
-
return members
|
|
112
|
+
return members;
|
|
120
113
|
}
|
|
121
114
|
|
|
122
|
-
|
|
115
|
+
listAdmins() {
|
|
123
116
|
return this.#group.adminList();
|
|
124
117
|
}
|
|
125
118
|
|
|
126
|
-
|
|
119
|
+
listSuperAdmins() {
|
|
127
120
|
return this.#group.superAdminList();
|
|
128
121
|
}
|
|
129
122
|
|
|
130
|
-
|
|
123
|
+
permissions() {
|
|
131
124
|
const permissions = this.#group.groupPermissions();
|
|
132
125
|
return {
|
|
133
|
-
policyType: permissions.policyType
|
|
134
|
-
policySet: permissions.policySet
|
|
126
|
+
policyType: permissions.policyType,
|
|
127
|
+
policySet: permissions.policySet,
|
|
135
128
|
};
|
|
136
129
|
}
|
|
137
130
|
|
|
@@ -195,29 +188,85 @@ export class WorkerConversation {
|
|
|
195
188
|
return this.#group.publishMessages();
|
|
196
189
|
}
|
|
197
190
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
191
|
+
async send(encodedContent: EncodedContent, opts?: SendMessageOpts) {
|
|
192
|
+
return this.#group.send(encodedContent, opts ?? { shouldPush: true });
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async sendText(text: string, isOptimistic?: boolean) {
|
|
196
|
+
return this.#group.sendText(text, isOptimistic);
|
|
201
197
|
}
|
|
202
198
|
|
|
203
|
-
async
|
|
204
|
-
|
|
205
|
-
return this.#group.send(encodedContent, opts);
|
|
199
|
+
async sendMarkdown(markdown: string, isOptimistic?: boolean) {
|
|
200
|
+
return this.#group.sendMarkdown(markdown, isOptimistic);
|
|
206
201
|
}
|
|
207
202
|
|
|
208
|
-
async
|
|
209
|
-
return this.#group.
|
|
210
|
-
|
|
203
|
+
async sendReaction(reaction: Reaction, isOptimistic?: boolean) {
|
|
204
|
+
return this.#group.sendReaction(reaction, isOptimistic);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async sendReadReceipt(isOptimistic?: boolean) {
|
|
208
|
+
return this.#group.sendReadReceipt(isOptimistic);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async sendReply(reply: Reply, isOptimistic?: boolean) {
|
|
212
|
+
return this.#group.sendReply(reply, isOptimistic);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async sendTransactionReference(
|
|
216
|
+
transactionReference: TransactionReference,
|
|
217
|
+
isOptimistic?: boolean,
|
|
218
|
+
) {
|
|
219
|
+
return this.#group.sendTransactionReference(
|
|
220
|
+
transactionReference,
|
|
221
|
+
isOptimistic,
|
|
211
222
|
);
|
|
212
223
|
}
|
|
213
224
|
|
|
214
|
-
async
|
|
215
|
-
|
|
216
|
-
|
|
225
|
+
async sendWalletSendCalls(
|
|
226
|
+
walletSendCalls: WalletSendCalls,
|
|
227
|
+
isOptimistic?: boolean,
|
|
228
|
+
) {
|
|
229
|
+
return this.#group.sendWalletSendCalls(walletSendCalls, isOptimistic);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async sendActions(actions: Actions, isOptimistic?: boolean) {
|
|
233
|
+
return this.#group.sendActions(actions, isOptimistic);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async sendIntent(intent: Intent, isOptimistic?: boolean) {
|
|
237
|
+
return this.#group.sendIntent(intent, isOptimistic);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async sendAttachment(attachment: Attachment, isOptimistic?: boolean) {
|
|
241
|
+
return this.#group.sendAttachment(attachment, isOptimistic);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async sendMultiRemoteAttachment(
|
|
245
|
+
multiRemoteAttachment: MultiRemoteAttachment,
|
|
246
|
+
isOptimistic?: boolean,
|
|
247
|
+
) {
|
|
248
|
+
return this.#group.sendMultiRemoteAttachment(
|
|
249
|
+
multiRemoteAttachment,
|
|
250
|
+
isOptimistic,
|
|
217
251
|
);
|
|
218
252
|
}
|
|
219
253
|
|
|
220
|
-
|
|
254
|
+
async sendRemoteAttachment(
|
|
255
|
+
remoteAttachment: RemoteAttachment,
|
|
256
|
+
isOptimistic?: boolean,
|
|
257
|
+
) {
|
|
258
|
+
return this.#group.sendRemoteAttachment(remoteAttachment, isOptimistic);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async messages(options?: ListMessagesOptions): Promise<DecodedMessage[]> {
|
|
262
|
+
return this.#group.findEnrichedMessages(options);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async countMessages(options?: ListMessagesOptions) {
|
|
266
|
+
return this.#group.countMessages(options);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
consentState() {
|
|
221
270
|
return this.#group.consentState();
|
|
222
271
|
}
|
|
223
272
|
|
|
@@ -234,7 +283,7 @@ export class WorkerConversation {
|
|
|
234
283
|
}
|
|
235
284
|
|
|
236
285
|
async updateMessageDisappearingSettings(fromNs: bigint, inNs: bigint) {
|
|
237
|
-
const settings =
|
|
286
|
+
const settings: MessageDisappearingSettings = { fromNs, inNs };
|
|
238
287
|
return this.#group.updateMessageDisappearingSettings(settings);
|
|
239
288
|
}
|
|
240
289
|
|
|
@@ -263,7 +312,7 @@ export class WorkerConversation {
|
|
|
263
312
|
return this.#group.pausedForVersion();
|
|
264
313
|
}
|
|
265
314
|
|
|
266
|
-
|
|
315
|
+
hmacKeys() {
|
|
267
316
|
return this.#group.getHmacKeys() as Map<string, HmacKey[]>;
|
|
268
317
|
}
|
|
269
318
|
|
|
@@ -271,7 +320,7 @@ export class WorkerConversation {
|
|
|
271
320
|
return (await this.#group.getDebugInfo()) as ConversationDebugInfo;
|
|
272
321
|
}
|
|
273
322
|
|
|
274
|
-
async
|
|
323
|
+
async duplicateDms() {
|
|
275
324
|
const dms = await this.#group.findDuplicateDms();
|
|
276
325
|
return dms.map((dm) => new WorkerConversation(this.#client, dm));
|
|
277
326
|
}
|
|
@@ -280,7 +329,11 @@ export class WorkerConversation {
|
|
|
280
329
|
return this.#group.leaveGroup();
|
|
281
330
|
}
|
|
282
331
|
|
|
283
|
-
|
|
332
|
+
isPendingRemoval() {
|
|
284
333
|
return this.#group.membershipState() === GroupMembershipState.PendingRemove;
|
|
285
334
|
}
|
|
335
|
+
|
|
336
|
+
async lastReadTimes() {
|
|
337
|
+
return this.#group.getLastReadTimes() as Promise<LastReadTimes>;
|
|
338
|
+
}
|
|
286
339
|
}
|
|
@@ -4,18 +4,14 @@ import {
|
|
|
4
4
|
type Conversation,
|
|
5
5
|
type ConversationListItem,
|
|
6
6
|
type Conversations,
|
|
7
|
+
type CreateDmOptions,
|
|
8
|
+
type CreateGroupOptions,
|
|
9
|
+
type DecodedMessage,
|
|
7
10
|
type Identifier,
|
|
11
|
+
type ListConversationsOptions,
|
|
8
12
|
type Message,
|
|
9
13
|
} from "@xmtp/wasm-bindings";
|
|
10
|
-
import {
|
|
11
|
-
fromSafeCreateDmOptions,
|
|
12
|
-
fromSafeCreateGroupOptions,
|
|
13
|
-
fromSafeListConversationsOptions,
|
|
14
|
-
type HmacKeys,
|
|
15
|
-
type SafeCreateDmOptions,
|
|
16
|
-
type SafeCreateGroupOptions,
|
|
17
|
-
type SafeListConversationsOptions,
|
|
18
|
-
} from "@/utils/conversions";
|
|
14
|
+
import { type HmacKeys } from "@/utils/conversions";
|
|
19
15
|
import type { StreamCallback } from "@/utils/streams";
|
|
20
16
|
import type { WorkerClient } from "@/WorkerClient";
|
|
21
17
|
import { WorkerConversation } from "@/WorkerConversation";
|
|
@@ -48,10 +44,9 @@ export class WorkerConversations {
|
|
|
48
44
|
}
|
|
49
45
|
}
|
|
50
46
|
|
|
51
|
-
getMessageById(id: string) {
|
|
47
|
+
async getMessageById(id: string): Promise<DecodedMessage | undefined> {
|
|
52
48
|
try {
|
|
53
|
-
|
|
54
|
-
return this.#conversations.findMessageById(id);
|
|
49
|
+
return await this.#conversations.findEnrichedMessageById(id);
|
|
55
50
|
} catch {
|
|
56
51
|
return undefined;
|
|
57
52
|
}
|
|
@@ -66,102 +61,68 @@ export class WorkerConversations {
|
|
|
66
61
|
}
|
|
67
62
|
}
|
|
68
63
|
|
|
69
|
-
list(options?:
|
|
70
|
-
const groups = this.#conversations.list(
|
|
71
|
-
options ? fromSafeListConversationsOptions(options) : undefined,
|
|
72
|
-
) as ConversationListItem[];
|
|
64
|
+
list(options?: ListConversationsOptions) {
|
|
65
|
+
const groups = this.#conversations.list(options) as ConversationListItem[];
|
|
73
66
|
return groups.map(
|
|
74
|
-
(item) =>
|
|
75
|
-
new WorkerConversation(
|
|
76
|
-
this.#client,
|
|
77
|
-
item.conversation,
|
|
78
|
-
item.isCommitLogForked,
|
|
79
|
-
),
|
|
67
|
+
(item) => new WorkerConversation(this.#client, item.conversation),
|
|
80
68
|
);
|
|
81
69
|
}
|
|
82
70
|
|
|
83
|
-
listGroups(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
...(options ?? {}),
|
|
89
|
-
conversationType: ConversationType.Group,
|
|
90
|
-
}),
|
|
91
|
-
) as ConversationListItem[];
|
|
71
|
+
listGroups(options?: Omit<ListConversationsOptions, "conversationType">) {
|
|
72
|
+
const groups = this.#conversations.list({
|
|
73
|
+
...(options ?? {}),
|
|
74
|
+
conversationType: ConversationType.Group,
|
|
75
|
+
}) as ConversationListItem[];
|
|
92
76
|
return groups.map(
|
|
93
|
-
(item) =>
|
|
94
|
-
new WorkerConversation(
|
|
95
|
-
this.#client,
|
|
96
|
-
item.conversation,
|
|
97
|
-
item.isCommitLogForked,
|
|
98
|
-
),
|
|
77
|
+
(item) => new WorkerConversation(this.#client, item.conversation),
|
|
99
78
|
);
|
|
100
79
|
}
|
|
101
80
|
|
|
102
|
-
listDms(options?: Omit<
|
|
103
|
-
const groups = this.#conversations.list(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}),
|
|
108
|
-
) as ConversationListItem[];
|
|
81
|
+
listDms(options?: Omit<ListConversationsOptions, "conversationType">) {
|
|
82
|
+
const groups = this.#conversations.list({
|
|
83
|
+
...(options ?? {}),
|
|
84
|
+
conversationType: ConversationType.Dm,
|
|
85
|
+
}) as ConversationListItem[];
|
|
109
86
|
return groups.map(
|
|
110
|
-
(item) =>
|
|
111
|
-
new WorkerConversation(
|
|
112
|
-
this.#client,
|
|
113
|
-
item.conversation,
|
|
114
|
-
item.isCommitLogForked,
|
|
115
|
-
),
|
|
87
|
+
(item) => new WorkerConversation(this.#client, item.conversation),
|
|
116
88
|
);
|
|
117
89
|
}
|
|
118
90
|
|
|
119
|
-
|
|
120
|
-
const group = this.#conversations.createGroupOptimistic(
|
|
121
|
-
options ? fromSafeCreateGroupOptions(options) : undefined,
|
|
122
|
-
);
|
|
91
|
+
createGroupOptimistic(options?: CreateGroupOptions) {
|
|
92
|
+
const group = this.#conversations.createGroupOptimistic(options);
|
|
123
93
|
return new WorkerConversation(this.#client, group);
|
|
124
94
|
}
|
|
125
95
|
|
|
126
|
-
async
|
|
96
|
+
async createGroupWithIdentifiers(
|
|
127
97
|
identifiers: Identifier[],
|
|
128
|
-
options?:
|
|
98
|
+
options?: CreateGroupOptions,
|
|
129
99
|
) {
|
|
130
|
-
const group = await this.#conversations.createGroup(
|
|
131
|
-
identifiers,
|
|
132
|
-
options ? fromSafeCreateGroupOptions(options) : undefined,
|
|
133
|
-
);
|
|
100
|
+
const group = await this.#conversations.createGroup(identifiers, options);
|
|
134
101
|
return new WorkerConversation(this.#client, group);
|
|
135
102
|
}
|
|
136
103
|
|
|
137
|
-
async
|
|
104
|
+
async createGroup(inboxIds: string[], options?: CreateGroupOptions) {
|
|
138
105
|
const group = await this.#conversations.createGroupByInboxIds(
|
|
139
106
|
inboxIds,
|
|
140
|
-
options
|
|
107
|
+
options,
|
|
141
108
|
);
|
|
142
109
|
return new WorkerConversation(this.#client, group);
|
|
143
110
|
}
|
|
144
111
|
|
|
145
|
-
async
|
|
112
|
+
async createDmWithIdentifier(
|
|
146
113
|
identifier: Identifier,
|
|
147
|
-
options?:
|
|
114
|
+
options?: CreateDmOptions,
|
|
148
115
|
) {
|
|
149
|
-
const group = await this.#conversations.createDm(
|
|
150
|
-
identifier,
|
|
151
|
-
options ? fromSafeCreateDmOptions(options) : undefined,
|
|
152
|
-
);
|
|
116
|
+
const group = await this.#conversations.createDm(identifier, options);
|
|
153
117
|
return new WorkerConversation(this.#client, group);
|
|
154
118
|
}
|
|
155
119
|
|
|
156
|
-
async
|
|
157
|
-
const group = await this.#conversations.createDmByInboxId(
|
|
158
|
-
inboxId,
|
|
159
|
-
options ? fromSafeCreateDmOptions(options) : undefined,
|
|
160
|
-
);
|
|
120
|
+
async createDm(inboxId: string, options?: CreateDmOptions) {
|
|
121
|
+
const group = await this.#conversations.createDmByInboxId(inboxId, options);
|
|
161
122
|
return new WorkerConversation(this.#client, group);
|
|
162
123
|
}
|
|
163
124
|
|
|
164
|
-
|
|
125
|
+
hmacKeys() {
|
|
165
126
|
return this.#conversations.getHmacKeys() as HmacKeys;
|
|
166
127
|
}
|
|
167
128
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { Client } from "@xmtp/wasm-bindings";
|
|
2
|
-
import { HistorySyncUrls } from "@/constants";
|
|
3
|
-
import type { ClientOptions } from "@/types/options";
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Debug information helpers for the client
|
|
@@ -9,11 +7,9 @@ import type { ClientOptions } from "@/types/options";
|
|
|
9
7
|
*/
|
|
10
8
|
export class WorkerDebugInformation {
|
|
11
9
|
#client: Client;
|
|
12
|
-
#options?: ClientOptions;
|
|
13
10
|
|
|
14
|
-
constructor(client: Client
|
|
11
|
+
constructor(client: Client) {
|
|
15
12
|
this.#client = client;
|
|
16
|
-
this.#options = options;
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
apiStatistics() {
|
|
@@ -31,11 +27,4 @@ export class WorkerDebugInformation {
|
|
|
31
27
|
clearAllStatistics() {
|
|
32
28
|
this.#client.clearAllStatistics();
|
|
33
29
|
}
|
|
34
|
-
|
|
35
|
-
uploadDebugArchive(serverUrl?: string) {
|
|
36
|
-
const env = this.#options?.env || "dev";
|
|
37
|
-
const historySyncUrl =
|
|
38
|
-
this.#options?.historySyncUrl || HistorySyncUrls[env];
|
|
39
|
-
return this.#client.uploadDebugArchive(serverUrl || historySyncUrl);
|
|
40
|
-
}
|
|
41
30
|
}
|