@talkjs/core 1.1.1 → 1.3.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.
@@ -214,6 +214,92 @@ export declare interface ConversationActiveState {
214
214
  latestSnapshot: ConversationSnapshot | null;
215
215
  }
216
216
 
217
+ /**
218
+ * The state of a conversation list subscription when it is actively listening for changes
219
+ *
220
+ * @public
221
+ */
222
+ export declare interface ConversationListActiveState {
223
+ type: "active";
224
+ /**
225
+ * The most recently received snapshot for the conversations
226
+ */
227
+ latestSnapshot: ConversationSnapshot[];
228
+ /**
229
+ * True if `latestSnapshot` contains all conversations you are in.
230
+ * Use {@link ConversationListSubscription.loadMore} to load more.
231
+ */
232
+ loadedAll: boolean;
233
+ }
234
+
235
+ /**
236
+ * A subscription to your most recently active conversations.
237
+ *
238
+ * @remarks
239
+ * Get a ConversationListSubscription by calling {@link Session.subscribeConversations}.
240
+ *
241
+ * The subscription is 'windowed'. Initially, this window contains the 20 most recent conversations.
242
+ * Conversations are ordered by last activity. The last activity of a conversation is either `joinedAt` or `lastMessage.createdAt`, whichever is higher.
243
+ *
244
+ * The window will automatically expand to include any conversations you join, and any old conversations that receive new messages after subscribing.
245
+ *
246
+ * You can expand this window by calling {@link ConversationListSubscription.loadMore}, which extends the window further into the past.
247
+ *
248
+ * @public
249
+ */
250
+ export declare interface ConversationListSubscription {
251
+ /**
252
+ * The current state of the subscription
253
+ *
254
+ * @remarks
255
+ * An object with the following fields:
256
+ *
257
+ * `type` is one of "pending", "active", "unsubscribed", or "error".
258
+ *
259
+ * When `type` is "active", includes `latestSnapshot` and `loadedAll`.
260
+ *
261
+ * - `latestSnapshot: ConversationSnapshot[]` the current state of the conversations in the window
262
+ *
263
+ * - `loadedAll: boolean` true when `latestSnapshot` contains all the conversations you are in
264
+ *
265
+ * When `type` is "error", includes the `error` field. It is a JS `Error` object explaining what caused the subscription to be terminated.
266
+ */
267
+ state: PendingState | ConversationListActiveState | UnsubscribedState | ErrorState;
268
+ /**
269
+ * Resolves when the subscription starts receiving updates from the server.
270
+ *
271
+ * @remarks
272
+ * Wait for this promise if you want to perform some action as soon as the subscription is active.
273
+ *
274
+ * The promise rejects if the subscription is terminated before it connects.
275
+ */
276
+ connected: Promise<ConversationListActiveState>;
277
+ /**
278
+ * Resolves when the subscription permanently stops receiving updates from the server.
279
+ *
280
+ * @remarks
281
+ * This is either because you unsubscribed or because the subscription encountered an unrecoverable error.
282
+ */
283
+ terminated: Promise<UnsubscribedState | ErrorState>;
284
+ /**
285
+ * Expand the window to include older conversations
286
+ *
287
+ * @remarks
288
+ * Calling `loadMore` multiple times in parallel will still only load one page of conversations.
289
+ *
290
+ * @param count - The number of additional conversations to load. Must be between 1 and 30. Default 20.
291
+ * @returns A promise that resolves once the additional conversations have loaded
292
+ */
293
+ loadMore(count?: number): Promise<void>;
294
+ /**
295
+ * Unsubscribe from this resource and stop receiving updates.
296
+ *
297
+ * @remarks
298
+ * If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.
299
+ */
300
+ unsubscribe(): void;
301
+ }
302
+
217
303
  /**
218
304
  * References the conversation with a given conversation ID, from the perspective of the current user.
219
305
  *
@@ -381,6 +467,19 @@ export declare interface ConversationRef {
381
467
  * The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
382
468
  */
383
469
  subscribeMessages(onSnapshot?: (snapshot: MessageSnapshot[] | null, loadedAll: boolean) => void): MessageSubscription;
470
+ /**
471
+ * Subscribes to the participants in the conversation.
472
+ *
473
+ * @remarks
474
+ * Initially, you will be subscribed to the 10 participants who joined most recently, and any new participants.
475
+ * Call `loadMore` to load additional older participants.
476
+ *
477
+ * Whenever `Subscription.state.type` is "active" and a participant is created, edited, deleted, or you load more participants, `onSnapshot` will fire and `Subscription.state.latestSnapshot` will be updated.
478
+ * `loadedAll` is true when the snapshot contains all the participants in the conversation.
479
+ *
480
+ * The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
481
+ */
482
+ subscribeParticipants(onSnapshot?: (snapshot: ParticipantSnapshot[] | null, loadedAll: boolean) => void): ParticipantSubscription;
384
483
  /**
385
484
  * Subscribes to the conversation.
386
485
  *
@@ -1245,7 +1344,7 @@ export declare interface MessageSnapshot {
1245
1344
  * Get a MessageSubscription by calling {@link ConversationRef.subscribeMessages}
1246
1345
  *
1247
1346
  * The subscription is 'windowed'. It includes all messages since a certain point in time.
1248
- * By default, you subscribe to the 30 most recent messages, and any new messages are sent after you subscribe.
1347
+ * By default, you subscribe to the 30 most recent messages, and any new messages that are sent after you subscribe.
1249
1348
  *
1250
1349
  * You can expand this window by calling {@link MessageSubscription.loadMore}, which extends the window further into the past.
1251
1350
  *
@@ -1291,7 +1390,7 @@ export declare interface MessageSubscription {
1291
1390
  * @remarks
1292
1391
  * Calling `loadMore` multiple times in parallel will still only load one page of messages.
1293
1392
  *
1294
- * @param count - The number of additional messages to load. Must be between 1 and 100
1393
+ * @param count - The number of additional messages to load. Must be between 1 and 100. Default 30.
1295
1394
  * @returns A promise that resolves once the additional messages have loaded
1296
1395
  */
1297
1396
  loadMore(count?: number): Promise<void>;
@@ -1304,6 +1403,24 @@ export declare interface MessageSubscription {
1304
1403
  unsubscribe(): void;
1305
1404
  }
1306
1405
 
1406
+ /**
1407
+ * The state of a participants subscription when it is actively listening for changes
1408
+ *
1409
+ * @public
1410
+ */
1411
+ export declare interface ParticipantActiveState {
1412
+ type: "active";
1413
+ /**
1414
+ * The most recently received snapshot for the participants, or `null` if you are not a participant in that conversation.
1415
+ */
1416
+ latestSnapshot: ParticipantSnapshot[] | null;
1417
+ /**
1418
+ * True if `latestSnapshot` contains all participants in the conversation.
1419
+ * Use {@link ParticipantSubscription.loadMore} to load more.
1420
+ */
1421
+ loadedAll: boolean;
1422
+ }
1423
+
1307
1424
  /**
1308
1425
  * References a given user's participation in a conversation.
1309
1426
  *
@@ -1413,6 +1530,72 @@ export declare interface ParticipantSnapshot {
1413
1530
  joinedAt: number;
1414
1531
  }
1415
1532
 
1533
+ /**
1534
+ * A subscription to the participants in a specific conversation.
1535
+ *
1536
+ * @remarks
1537
+ * Get a ParticipantSubscription by calling {@link ConversationRef.subscribeParticipants}
1538
+ *
1539
+ * The subscription is 'windowed'. It includes everyone who joined since a certain point in time.
1540
+ * By default, you subscribe to the 10 most recent participants, and any participants who joined after you subscribe.
1541
+ *
1542
+ * You can expand this window by calling {@link ParticipantSubscription.loadMore}, which extends the window further into the past.
1543
+ *
1544
+ * @public
1545
+ */
1546
+ export declare interface ParticipantSubscription {
1547
+ /**
1548
+ * The current state of the subscription
1549
+ *
1550
+ * @remarks
1551
+ * An object with the following fields:
1552
+ *
1553
+ * `type` is one of "pending", "active", "unsubscribed", or "error".
1554
+ *
1555
+ * When `type` is "active", includes `latestSnapshot` and `loadedAll`.
1556
+ *
1557
+ * - `latestSnapshot: ParticipantSnapshot[] | null` the current state of the participants in the window, or null if you're not a participant in the conversation
1558
+ *
1559
+ * - `loadedAll: boolean` true when `latestSnapshot` contains all the participants in the conversation
1560
+ *
1561
+ * When `type` is "error", includes the `error` field. It is a JS `Error` object explaining what caused the subscription to be terminated.
1562
+ */
1563
+ state: PendingState | ParticipantActiveState | UnsubscribedState | ErrorState;
1564
+ /**
1565
+ * Resolves when the subscription starts receiving updates from the server.
1566
+ *
1567
+ * @remarks
1568
+ * Wait for this promise if you want to perform some action as soon as the subscription is active.
1569
+ *
1570
+ * The promise rejects if the subscription is terminated before it connects.
1571
+ */
1572
+ connected: Promise<ParticipantActiveState>;
1573
+ /**
1574
+ * Resolves when the subscription permanently stops receiving updates from the server.
1575
+ *
1576
+ * @remarks
1577
+ * This is either because you unsubscribed or because the subscription encountered an unrecoverable error.
1578
+ */
1579
+ terminated: Promise<UnsubscribedState | ErrorState>;
1580
+ /**
1581
+ * Expand the window to include older participants
1582
+ *
1583
+ * @remarks
1584
+ * Calling `loadMore` multiple times in parallel will still only load one page of participants.
1585
+ *
1586
+ * @param count - The number of additional participants to load. Must be between 1 and 50. Default 10.
1587
+ * @returns A promise that resolves once the additional participants have loaded
1588
+ */
1589
+ loadMore(count?: number): Promise<void>;
1590
+ /**
1591
+ * Unsubscribe from this resource and stop receiving updates.
1592
+ *
1593
+ * @remarks
1594
+ * If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.
1595
+ */
1596
+ unsubscribe(): void;
1597
+ }
1598
+
1416
1599
  /**
1417
1600
  * The state of a subscription before it has connected to the server
1418
1601
  *
@@ -1840,6 +2023,22 @@ export declare interface TalkSession {
1840
2023
  * @public
1841
2024
  */
1842
2025
  conversation(id: string): ConversationRef;
2026
+ /**
2027
+ * Subscribes to your most recently active conversations.
2028
+ *
2029
+ * @remarks
2030
+ * The subscription is 'windowed'. Initially, this window contains the 20 most recent conversations.
2031
+ * Conversations are ordered by last activity. The last activity of a conversation is either `joinedAt` or `lastMessage.createdAt`, whichever is higher.
2032
+ *
2033
+ * If an older conversation receives a new message, or you are added to a conversation, it will appear at the start of the list.
2034
+ * Call `loadMore` to load additional older conversations.
2035
+ *
2036
+ * Whenever `Subscription.state.type` is "active" and something changes in your conversations, `onSnapshot` will fire and `Subscription.state.latestSnapshot` will be updated.
2037
+ * `loadedAll` is true when the snapshot contains all your conversations.
2038
+ *
2039
+ * If the current user does not exist yet, the snapshot will be an empty list.
2040
+ */
2041
+ subscribeConversations(onSnapshot?: (snapshot: ConversationSnapshot[], loadedAll: boolean) => void): ConversationListSubscription;
1843
2042
  /**
1844
2043
  * Upload a generic file without any additional metadata.
1845
2044
  *