@xmtp/browser-sdk 2.0.13 → 2.1.1

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.
Files changed (43) hide show
  1. package/dist/index.d.ts +849 -678
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/workers/client.js +1 -1
  5. package/dist/workers/client.js.map +1 -1
  6. package/dist/workers/utils.js +1 -1
  7. package/dist/workers/utils.js.map +1 -1
  8. package/package.json +9 -11
  9. package/src/Client.ts +71 -31
  10. package/src/ClientWorkerClass.ts +62 -19
  11. package/src/Conversation.ts +60 -33
  12. package/src/Conversations.ts +96 -48
  13. package/src/DecodedMessage.ts +8 -5
  14. package/src/Dm.ts +14 -4
  15. package/src/Group.ts +27 -20
  16. package/src/Preferences.ts +21 -10
  17. package/src/Utils.ts +2 -2
  18. package/src/UtilsWorkerClass.ts +56 -15
  19. package/src/WorkerClient.ts +25 -3
  20. package/src/WorkerConversation.ts +11 -2
  21. package/src/WorkerConversations.ts +19 -4
  22. package/src/WorkerPreferences.ts +4 -0
  23. package/src/index.ts +3 -1
  24. package/src/types/actions/client.ts +181 -0
  25. package/src/types/actions/conversation.ts +146 -0
  26. package/src/types/actions/conversations.ts +146 -0
  27. package/src/types/actions/dm.ts +19 -0
  28. package/src/types/actions/group.ts +161 -0
  29. package/src/types/actions/preferences.ts +68 -0
  30. package/src/types/actions/streams.ts +44 -0
  31. package/src/types/actions/utils.ts +29 -0
  32. package/src/types/actions.ts +75 -0
  33. package/src/types/options.ts +18 -0
  34. package/src/utils/conversions.ts +60 -0
  35. package/src/utils/createClient.ts +6 -1
  36. package/src/utils/errors.ts +3 -1
  37. package/src/workers/client.ts +243 -190
  38. package/src/workers/utils.ts +25 -29
  39. package/src/types/clientEvents.ts +0 -693
  40. package/src/types/clientStreamEvents.ts +0 -45
  41. package/src/types/index.ts +0 -4
  42. package/src/types/utils.ts +0 -72
  43. package/src/types/utilsEvents.ts +0 -60
@@ -18,9 +18,9 @@ import { MissingContentTypeError } from "@/utils/errors";
18
18
  *
19
19
  * This class is not intended to be initialized directly.
20
20
  */
21
- export class Conversation {
21
+ export class Conversation<ContentTypes = unknown> {
22
22
  #addedByInboxId?: SafeConversation["addedByInboxId"];
23
- #client: Client;
23
+ #client: Client<ContentTypes>;
24
24
  #createdAtNs?: SafeConversation["createdAtNs"];
25
25
  #id: string;
26
26
  #isActive?: SafeConversation["isActive"];
@@ -33,7 +33,11 @@ export class Conversation {
33
33
  * @param id - The unique identifier for this conversation
34
34
  * @param data - Optional conversation data to initialize with
35
35
  */
36
- constructor(client: Client, id: string, data?: SafeConversation) {
36
+ constructor(
37
+ client: Client<ContentTypes>,
38
+ id: string,
39
+ data?: SafeConversation,
40
+ ) {
37
41
  this.#client = client;
38
42
  this.#id = id;
39
43
  this.#syncData(data);
@@ -76,7 +80,7 @@ export class Conversation {
76
80
  * @returns Promise that resolves with the conversation members
77
81
  */
78
82
  async members() {
79
- return this.#client.sendMessage("getGroupMembers", {
83
+ return this.#client.sendMessage("conversation.members", {
80
84
  id: this.#id,
81
85
  });
82
86
  }
@@ -87,7 +91,7 @@ export class Conversation {
87
91
  * @returns Promise that resolves with the updated conversation data
88
92
  */
89
93
  async sync() {
90
- const data = await this.#client.sendMessage("syncGroup", {
94
+ const data = await this.#client.sendMessage("conversation.sync", {
91
95
  id: this.#id,
92
96
  });
93
97
  this.#syncData(data);
@@ -100,7 +104,7 @@ export class Conversation {
100
104
  * @returns Promise that resolves when publishing is complete
101
105
  */
102
106
  async publishMessages() {
103
- return this.#client.sendMessage("publishGroupMessages", {
107
+ return this.#client.sendMessage("conversation.publishMessages", {
104
108
  id: this.#id,
105
109
  });
106
110
  }
@@ -113,7 +117,7 @@ export class Conversation {
113
117
  * @returns Promise that resolves with the message ID
114
118
  * @throws {MissingContentTypeError} if content type is required but not provided
115
119
  */
116
- async sendOptimistic(content: unknown, contentType?: ContentTypeId) {
120
+ async sendOptimistic(content: ContentTypes, contentType?: ContentTypeId) {
117
121
  if (typeof content !== "string" && !contentType) {
118
122
  throw new MissingContentTypeError();
119
123
  }
@@ -124,7 +128,7 @@ export class Conversation {
124
128
  : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
125
129
  this.#client.encodeContent(content, contentType!);
126
130
 
127
- return this.#client.sendMessage("sendOptimisticGroupMessage", {
131
+ return this.#client.sendMessage("conversation.sendOptimistic", {
128
132
  id: this.#id,
129
133
  content: safeEncodedContent,
130
134
  });
@@ -138,7 +142,7 @@ export class Conversation {
138
142
  * @returns Promise that resolves with the message ID after it has been sent
139
143
  * @throws {MissingContentTypeError} if content type is required but not provided
140
144
  */
141
- async send(content: unknown, contentType?: ContentTypeId) {
145
+ async send(content: ContentTypes, contentType?: ContentTypeId) {
142
146
  if (typeof content !== "string" && !contentType) {
143
147
  throw new MissingContentTypeError();
144
148
  }
@@ -149,7 +153,7 @@ export class Conversation {
149
153
  : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
150
154
  this.#client.encodeContent(content, contentType!);
151
155
 
152
- return this.#client.sendMessage("sendGroupMessage", {
156
+ return this.#client.sendMessage("conversation.send", {
153
157
  id: this.#id,
154
158
  content: safeEncodedContent,
155
159
  });
@@ -162,7 +166,7 @@ export class Conversation {
162
166
  * @returns Promise that resolves with an array of decoded messages
163
167
  */
164
168
  async messages(options?: SafeListMessagesOptions) {
165
- const messages = await this.#client.sendMessage("getGroupMessages", {
169
+ const messages = await this.#client.sendMessage("conversation.messages", {
166
170
  id: this.#id,
167
171
  options,
168
172
  });
@@ -176,7 +180,7 @@ export class Conversation {
176
180
  * @returns Promise that resolves with the current consent state
177
181
  */
178
182
  async consentState() {
179
- return this.#client.sendMessage("getGroupConsentState", {
183
+ return this.#client.sendMessage("conversation.consentState", {
180
184
  id: this.#id,
181
185
  });
182
186
  }
@@ -188,7 +192,7 @@ export class Conversation {
188
192
  * @returns Promise that resolves when the update is complete
189
193
  */
190
194
  async updateConsentState(state: ConsentState) {
191
- return this.#client.sendMessage("updateGroupConsentState", {
195
+ return this.#client.sendMessage("conversation.updateConsentState", {
192
196
  id: this.#id,
193
197
  state,
194
198
  });
@@ -200,9 +204,12 @@ export class Conversation {
200
204
  * @returns Promise that resolves with the current message disappearing settings
201
205
  */
202
206
  async messageDisappearingSettings() {
203
- return this.#client.sendMessage("getGroupMessageDisappearingSettings", {
204
- id: this.#id,
205
- });
207
+ return this.#client.sendMessage(
208
+ "conversation.messageDisappearingSettings",
209
+ {
210
+ id: this.#id,
211
+ },
212
+ );
206
213
  }
207
214
 
208
215
  /**
@@ -213,11 +220,14 @@ export class Conversation {
213
220
  * @returns Promise that resolves when the update is complete
214
221
  */
215
222
  async updateMessageDisappearingSettings(fromNs: bigint, inNs: bigint) {
216
- return this.#client.sendMessage("updateGroupMessageDisappearingSettings", {
217
- id: this.#id,
218
- fromNs,
219
- inNs,
220
- });
223
+ return this.#client.sendMessage(
224
+ "conversation.updateMessageDisappearingSettings",
225
+ {
226
+ id: this.#id,
227
+ fromNs,
228
+ inNs,
229
+ },
230
+ );
221
231
  }
222
232
 
223
233
  /**
@@ -226,9 +236,12 @@ export class Conversation {
226
236
  * @returns Promise that resolves when the settings are removed
227
237
  */
228
238
  async removeMessageDisappearingSettings() {
229
- return this.#client.sendMessage("removeGroupMessageDisappearingSettings", {
230
- id: this.#id,
231
- });
239
+ return this.#client.sendMessage(
240
+ "conversation.removeMessageDisappearingSettings",
241
+ {
242
+ id: this.#id,
243
+ },
244
+ );
232
245
  }
233
246
 
234
247
  /**
@@ -237,9 +250,12 @@ export class Conversation {
237
250
  * @returns Promise that resolves with whether message disappearing is enabled
238
251
  */
239
252
  async isMessageDisappearingEnabled() {
240
- return this.#client.sendMessage("isGroupMessageDisappearingEnabled", {
241
- id: this.#id,
242
- });
253
+ return this.#client.sendMessage(
254
+ "conversation.isMessageDisappearingEnabled",
255
+ {
256
+ id: this.#id,
257
+ },
258
+ );
243
259
  }
244
260
 
245
261
  /**
@@ -248,14 +264,14 @@ export class Conversation {
248
264
  * @param callback - Optional callback function for handling new stream values
249
265
  * @returns Stream instance for new messages
250
266
  */
251
- async stream(callback?: StreamCallback<DecodedMessage>) {
267
+ async stream(callback?: StreamCallback<DecodedMessage<ContentTypes>>) {
252
268
  const streamId = v4();
253
- const asyncStream = new AsyncStream<DecodedMessage>();
269
+ const asyncStream = new AsyncStream<DecodedMessage<ContentTypes>>();
254
270
  const endStream = this.#client.handleStreamMessage<SafeMessage>(
255
271
  streamId,
256
272
  (error, value) => {
257
273
  let err: Error | null = error;
258
- let message: DecodedMessage | undefined;
274
+ let message: DecodedMessage<ContentTypes> | undefined;
259
275
 
260
276
  if (value) {
261
277
  try {
@@ -269,7 +285,7 @@ export class Conversation {
269
285
  void callback?.(err, message);
270
286
  },
271
287
  );
272
- await this.#client.sendMessage("streamGroupMessages", {
288
+ await this.#client.sendMessage("conversation.stream", {
273
289
  groupId: this.#id,
274
290
  streamId,
275
291
  });
@@ -283,7 +299,7 @@ export class Conversation {
283
299
  }
284
300
 
285
301
  async pausedForVersion() {
286
- return this.#client.sendMessage("getGroupPausedForVersion", {
302
+ return this.#client.sendMessage("conversation.pausedForVersion", {
287
303
  id: this.#id,
288
304
  });
289
305
  }
@@ -294,7 +310,18 @@ export class Conversation {
294
310
  * @returns Promise that resolves with the HMAC keys
295
311
  */
296
312
  async getHmacKeys() {
297
- return this.#client.sendMessage("getGroupHmacKeys", {
313
+ return this.#client.sendMessage("conversation.getHmacKeys", {
314
+ id: this.#id,
315
+ });
316
+ }
317
+
318
+ /**
319
+ * Retrieves information for this conversation to help with debugging
320
+ *
321
+ * @returns The debug information for this conversation
322
+ */
323
+ async debugInfo() {
324
+ return this.#client.sendMessage("conversation.debugInfo", {
298
325
  id: this.#id,
299
326
  });
300
327
  }
@@ -22,15 +22,15 @@ import type {
22
22
  *
23
23
  * This class is not intended to be initialized directly.
24
24
  */
25
- export class Conversations {
26
- #client: Client;
25
+ export class Conversations<ContentTypes = unknown> {
26
+ #client: Client<ContentTypes>;
27
27
 
28
28
  /**
29
29
  * Creates a new conversations instance
30
30
  *
31
31
  * @param client - The client instance managing the conversations
32
32
  */
33
- constructor(client: Client) {
33
+ constructor(client: Client<ContentTypes>) {
34
34
  this.#client = client;
35
35
  }
36
36
 
@@ -40,7 +40,7 @@ export class Conversations {
40
40
  * @returns Promise that resolves when sync is complete
41
41
  */
42
42
  async sync() {
43
- return this.#client.sendMessage("syncConversations", undefined);
43
+ return this.#client.sendMessage("conversations.sync", undefined);
44
44
  }
45
45
 
46
46
  /**
@@ -52,7 +52,7 @@ export class Conversations {
52
52
  * @returns Promise that resolves when sync is complete
53
53
  */
54
54
  async syncAll(consentStates?: ConsentState[]) {
55
- return this.#client.sendMessage("syncAllConversations", {
55
+ return this.#client.sendMessage("conversations.syncAll", {
56
56
  consentStates,
57
57
  });
58
58
  }
@@ -64,9 +64,12 @@ export class Conversations {
64
64
  * @returns Promise that resolves with the conversation, if found
65
65
  */
66
66
  async getConversationById(id: string) {
67
- const data = await this.#client.sendMessage("getConversationById", {
68
- id,
69
- });
67
+ const data = await this.#client.sendMessage(
68
+ "conversations.getConversationById",
69
+ {
70
+ id,
71
+ },
72
+ );
70
73
  if (data) {
71
74
  return data.metadata.conversationType === "group"
72
75
  ? new Group(this.#client, data.id, data)
@@ -81,11 +84,14 @@ export class Conversations {
81
84
  * @param id - The message ID to look up
82
85
  * @returns Promise that resolves with the decoded message, if found
83
86
  */
84
- async getMessageById<T = unknown>(id: string) {
85
- const data = await this.#client.sendMessage("getMessageById", {
86
- id,
87
- });
88
- return data ? new DecodedMessage<T>(this.#client, data) : undefined;
87
+ async getMessageById(id: string) {
88
+ const data = await this.#client.sendMessage(
89
+ "conversations.getMessageById",
90
+ {
91
+ id,
92
+ },
93
+ );
94
+ return data ? new DecodedMessage(this.#client, data) : undefined;
89
95
  }
90
96
 
91
97
  /**
@@ -95,9 +101,12 @@ export class Conversations {
95
101
  * @returns Promise that resolves with the DM, if found
96
102
  */
97
103
  async getDmByInboxId(inboxId: string) {
98
- const data = await this.#client.sendMessage("getDmByInboxId", {
99
- inboxId,
100
- });
104
+ const data = await this.#client.sendMessage(
105
+ "conversations.getDmByInboxId",
106
+ {
107
+ inboxId,
108
+ },
109
+ );
101
110
  return data ? new Dm(this.#client, data.id, data) : undefined;
102
111
  }
103
112
 
@@ -108,7 +117,7 @@ export class Conversations {
108
117
  * @returns Promise that resolves with an array of conversations
109
118
  */
110
119
  async list(options?: SafeListConversationsOptions) {
111
- const conversations = await this.#client.sendMessage("getConversations", {
120
+ const conversations = await this.#client.sendMessage("conversations.list", {
112
121
  options,
113
122
  });
114
123
 
@@ -135,9 +144,12 @@ export class Conversations {
135
144
  async listGroups(
136
145
  options?: Omit<SafeListConversationsOptions, "conversation_type">,
137
146
  ) {
138
- const conversations = await this.#client.sendMessage("getGroups", {
139
- options,
140
- });
147
+ const conversations = await this.#client.sendMessage(
148
+ "conversations.listGroups",
149
+ {
150
+ options,
151
+ },
152
+ );
141
153
 
142
154
  return conversations.map(
143
155
  (conversation) => new Group(this.#client, conversation.id, conversation),
@@ -153,15 +165,35 @@ export class Conversations {
153
165
  async listDms(
154
166
  options?: Omit<SafeListConversationsOptions, "conversation_type">,
155
167
  ) {
156
- const conversations = await this.#client.sendMessage("getDms", {
157
- options,
158
- });
168
+ const conversations = await this.#client.sendMessage(
169
+ "conversations.listDms",
170
+ {
171
+ options,
172
+ },
173
+ );
159
174
 
160
175
  return conversations.map(
161
176
  (conversation) => new Dm(this.#client, conversation.id, conversation),
162
177
  );
163
178
  }
164
179
 
180
+ /**
181
+ * Creates a new group without syncing to the network
182
+ *
183
+ * @param options - Optional group creation options
184
+ * @returns Promise that resolves with the new group
185
+ */
186
+ async newGroupOptimistic(options?: SafeCreateGroupOptions) {
187
+ const conversation = await this.#client.sendMessage(
188
+ "conversations.newGroupOptimistic",
189
+ {
190
+ options,
191
+ },
192
+ );
193
+
194
+ return new Group(this.#client, conversation.id, conversation);
195
+ }
196
+
165
197
  /**
166
198
  * Creates a new group conversation with the specified identifiers
167
199
  *
@@ -174,7 +206,7 @@ export class Conversations {
174
206
  options?: SafeCreateGroupOptions,
175
207
  ) {
176
208
  const conversation = await this.#client.sendMessage(
177
- "newGroupWithIdentifiers",
209
+ "conversations.newGroupWithIdentifiers",
178
210
  {
179
211
  identifiers,
180
212
  options,
@@ -193,7 +225,7 @@ export class Conversations {
193
225
  */
194
226
  async newGroup(inboxIds: string[], options?: SafeCreateGroupOptions) {
195
227
  const conversation = await this.#client.sendMessage(
196
- "newGroupWithInboxIds",
228
+ "conversations.newGroup",
197
229
  {
198
230
  inboxIds,
199
231
  options,
@@ -214,10 +246,13 @@ export class Conversations {
214
246
  identifier: Identifier,
215
247
  options?: SafeCreateDmOptions,
216
248
  ) {
217
- const conversation = await this.#client.sendMessage("newDmWithIdentifier", {
218
- identifier,
219
- options,
220
- });
249
+ const conversation = await this.#client.sendMessage(
250
+ "conversations.newDmWithIdentifier",
251
+ {
252
+ identifier,
253
+ options,
254
+ },
255
+ );
221
256
 
222
257
  return new Dm(this.#client, conversation.id, conversation);
223
258
  }
@@ -230,7 +265,7 @@ export class Conversations {
230
265
  * @returns Promise that resolves with the new DM
231
266
  */
232
267
  async newDm(inboxId: string, options?: SafeCreateDmOptions) {
233
- const conversation = await this.#client.sendMessage("newDmWithInboxId", {
268
+ const conversation = await this.#client.sendMessage("conversations.newDm", {
234
269
  inboxId,
235
270
  options,
236
271
  });
@@ -244,7 +279,7 @@ export class Conversations {
244
279
  * @returns Promise that resolves with the HMAC keys for all conversations
245
280
  */
246
281
  async getHmacKeys() {
247
- return this.#client.sendMessage("getHmacKeys", undefined);
282
+ return this.#client.sendMessage("conversations.getHmacKeys", undefined);
248
283
  }
249
284
 
250
285
  /**
@@ -254,10 +289,11 @@ export class Conversations {
254
289
  * @param conversationType - Optional type to filter conversations
255
290
  * @returns Stream instance for new conversations
256
291
  */
257
- async stream<T extends Group | Dm = Group | Dm>(
258
- callback?: StreamCallback<T>,
259
- conversationType?: ConversationType,
260
- ) {
292
+ async stream<
293
+ T extends Group<ContentTypes> | Dm<ContentTypes> =
294
+ | Group<ContentTypes>
295
+ | Dm<ContentTypes>,
296
+ >(callback?: StreamCallback<T>, conversationType?: ConversationType) {
261
297
  const streamId = v4();
262
298
  const asyncStream = new AsyncStream<T>();
263
299
  const endStream = this.#client.handleStreamMessage<SafeConversation>(
@@ -281,7 +317,7 @@ export class Conversations {
281
317
  void callback?.(err, streamValue);
282
318
  },
283
319
  );
284
- await this.#client.sendMessage("streamAllGroups", {
320
+ await this.#client.sendMessage("conversations.stream", {
285
321
  streamId,
286
322
  conversationType,
287
323
  });
@@ -300,8 +336,8 @@ export class Conversations {
300
336
  * @param callback - Optional callback function for handling new stream value
301
337
  * @returns Stream instance for new group conversations
302
338
  */
303
- async streamGroups(callback?: StreamCallback<Group>) {
304
- return this.stream<Group>(callback, ConversationType.Group);
339
+ async streamGroups(callback?: StreamCallback<Group<ContentTypes>>) {
340
+ return this.stream(callback, ConversationType.Group);
305
341
  }
306
342
 
307
343
  /**
@@ -310,8 +346,8 @@ export class Conversations {
310
346
  * @param callback - Optional callback function for handling new stream value
311
347
  * @returns Stream instance for new DM conversations
312
348
  */
313
- async streamDms(callback?: StreamCallback<Dm>) {
314
- return this.stream<Dm>(callback, ConversationType.Dm);
349
+ async streamDms(callback?: StreamCallback<Dm<ContentTypes>>) {
350
+ return this.stream(callback, ConversationType.Dm);
315
351
  }
316
352
 
317
353
  /**
@@ -322,16 +358,17 @@ export class Conversations {
322
358
  * @returns Stream instance for new messages
323
359
  */
324
360
  async streamAllMessages(
325
- callback?: StreamCallback<DecodedMessage>,
361
+ callback?: StreamCallback<DecodedMessage<ContentTypes>>,
326
362
  conversationType?: ConversationType,
363
+ consentStates?: ConsentState[],
327
364
  ) {
328
365
  const streamId = v4();
329
- const asyncStream = new AsyncStream<DecodedMessage>();
366
+ const asyncStream = new AsyncStream<DecodedMessage<ContentTypes>>();
330
367
  const endStream = this.#client.handleStreamMessage<SafeMessage>(
331
368
  streamId,
332
369
  (error, value) => {
333
370
  let err: Error | null = error;
334
- let message: DecodedMessage | undefined;
371
+ let message: DecodedMessage<ContentTypes> | undefined;
335
372
 
336
373
  if (value) {
337
374
  try {
@@ -345,9 +382,10 @@ export class Conversations {
345
382
  void callback?.(err, message);
346
383
  },
347
384
  );
348
- await this.#client.sendMessage("streamAllMessages", {
385
+ await this.#client.sendMessage("conversations.streamAllMessages", {
349
386
  streamId,
350
387
  conversationType,
388
+ consentStates,
351
389
  });
352
390
  asyncStream.onReturn = () => {
353
391
  void this.#client.sendMessage("endStream", {
@@ -364,8 +402,15 @@ export class Conversations {
364
402
  * @param callback - Optional callback function for handling new stream value
365
403
  * @returns Stream instance for new group messages
366
404
  */
367
- async streamAllGroupMessages(callback?: StreamCallback<DecodedMessage>) {
368
- return this.streamAllMessages(callback, ConversationType.Group);
405
+ async streamAllGroupMessages(
406
+ callback?: StreamCallback<DecodedMessage<ContentTypes>>,
407
+ consentStates?: ConsentState[],
408
+ ) {
409
+ return this.streamAllMessages(
410
+ callback,
411
+ ConversationType.Group,
412
+ consentStates,
413
+ );
369
414
  }
370
415
 
371
416
  /**
@@ -374,7 +419,10 @@ export class Conversations {
374
419
  * @param callback - Optional callback function for handling new stream value
375
420
  * @returns Stream instance for new DM messages
376
421
  */
377
- async streamAllDmMessages(callback?: StreamCallback<DecodedMessage>) {
378
- return this.streamAllMessages(callback, ConversationType.Dm);
422
+ async streamAllDmMessages(
423
+ callback?: StreamCallback<DecodedMessage<ContentTypes>>,
424
+ consentStates?: ConsentState[],
425
+ ) {
426
+ return this.streamAllMessages(callback, ConversationType.Dm, consentStates);
379
427
  }
380
428
  }
@@ -26,9 +26,9 @@ export type MessageDeliveryStatus = "unpublished" | "published" | "failed";
26
26
  * @property {string} senderInboxId - Identifier for the sender's inbox
27
27
  * @property {bigint} sentAtNs - Timestamp when the message was sent (in nanoseconds)
28
28
  */
29
- export class DecodedMessage<T = unknown> {
30
- #client: Client;
31
- content: T | undefined;
29
+ export class DecodedMessage<ContentTypes = unknown> {
30
+ #client: Client<ContentTypes>;
31
+ content: ContentTypes | undefined;
32
32
  contentType: ContentTypeId;
33
33
  conversationId: string;
34
34
  deliveryStatus: MessageDeliveryStatus;
@@ -41,7 +41,7 @@ export class DecodedMessage<T = unknown> {
41
41
  senderInboxId: string;
42
42
  sentAtNs: bigint;
43
43
 
44
- constructor(client: Client, message: SafeMessage) {
44
+ constructor(client: Client<ContentTypes>, message: SafeMessage) {
45
45
  this.#client = client;
46
46
  this.id = message.id;
47
47
  this.sentAtNs = message.sentAtNs;
@@ -78,7 +78,10 @@ export class DecodedMessage<T = unknown> {
78
78
  this.compression = message.content.compression;
79
79
 
80
80
  try {
81
- this.content = this.#client.decodeContent<T>(message, this.contentType);
81
+ this.content = this.#client.decodeContent<ContentTypes>(
82
+ message,
83
+ this.contentType,
84
+ );
82
85
  } catch {
83
86
  this.content = undefined;
84
87
  }
package/src/Dm.ts CHANGED
@@ -7,8 +7,8 @@ import type { SafeConversation } from "@/utils/conversions";
7
7
  *
8
8
  * This class is not intended to be initialized directly.
9
9
  */
10
- export class Dm extends Conversation {
11
- #client: Client;
10
+ export class Dm<ContentTypes = unknown> extends Conversation<ContentTypes> {
11
+ #client: Client<ContentTypes>;
12
12
  #id: string;
13
13
 
14
14
  /**
@@ -18,7 +18,11 @@ export class Dm extends Conversation {
18
18
  * @param id - Identifier for the direct message conversation
19
19
  * @param data - Optional conversation data to initialize with
20
20
  */
21
- constructor(client: Client, id: string, data?: SafeConversation) {
21
+ constructor(
22
+ client: Client<ContentTypes>,
23
+ id: string,
24
+ data?: SafeConversation,
25
+ ) {
22
26
  super(client, id, data);
23
27
  this.#client = client;
24
28
  this.#id = id;
@@ -30,7 +34,13 @@ export class Dm extends Conversation {
30
34
  * @returns Promise that resolves with the peer's inbox ID
31
35
  */
32
36
  async peerInboxId() {
33
- return this.#client.sendMessage("getDmPeerInboxId", {
37
+ return this.#client.sendMessage("dm.peerInboxId", {
38
+ id: this.#id,
39
+ });
40
+ }
41
+
42
+ async getDuplicateDms() {
43
+ return this.#client.sendMessage("dm.getDuplicateDms", {
34
44
  id: this.#id,
35
45
  });
36
46
  }