@talkjs/core 1.5.1 → 1.5.3
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 +11 -2
- package/dist/talkSession.cjs +1 -1
- package/dist/talkSession.d.ts +70 -14
- package/dist/talkSession.js +137 -118
- package/package.json +3 -2
package/dist/talkSession.d.ts
CHANGED
|
@@ -245,6 +245,8 @@ export declare interface ConversationListActiveState {
|
|
|
245
245
|
*
|
|
246
246
|
* You can expand this window by calling {@link ConversationListSubscription.loadMore}, which extends the window further into the past.
|
|
247
247
|
*
|
|
248
|
+
* Remember to `.unsubscribe` the subscription once you are done with it.
|
|
249
|
+
*
|
|
248
250
|
* @public
|
|
249
251
|
*/
|
|
250
252
|
export declare interface ConversationListSubscription {
|
|
@@ -287,6 +289,10 @@ export declare interface ConversationListSubscription {
|
|
|
287
289
|
* @remarks
|
|
288
290
|
* Calling `loadMore` multiple times in parallel will still only load one page of conversations.
|
|
289
291
|
*
|
|
292
|
+
* Avoid calling `.loadMore` in a loop until you have loaded all conversations.
|
|
293
|
+
* This is usually unnecessary: any time a conversation receives a message, it appears at the start of the list of conversations.
|
|
294
|
+
* If you do need to call loadMore in a loop, make sure you set a small upper bound (e.g. 100) on the number of conversations, where the loop will exit.
|
|
295
|
+
*
|
|
290
296
|
* @param count - The number of additional conversations to load. Must be between 1 and 30. Default 20.
|
|
291
297
|
* @returns A promise that resolves once the additional conversations have loaded
|
|
292
298
|
*/
|
|
@@ -460,30 +466,43 @@ export declare interface ConversationRef {
|
|
|
460
466
|
* Subscribes to the messages in the conversation.
|
|
461
467
|
*
|
|
462
468
|
* @remarks
|
|
463
|
-
* Initially, you will be subscribed to the 30 most recent messages and any new messages.
|
|
464
|
-
* Call `loadMore` to load additional older messages.
|
|
465
|
-
*
|
|
466
469
|
* While the subscription is active, `onSnapshot` will be called whenever the message snapshots change.
|
|
467
470
|
* This includes when a message is sent, edited, deleted, and when you load more messages.
|
|
468
471
|
* It also includes when nested data changes, such as when `snapshot[0].referencedMessage.sender.name` changes.
|
|
469
472
|
* `loadedAll` is true when `snapshot` contains all the messages in the conversation, and false if you could load more.
|
|
470
473
|
*
|
|
474
|
+
* The `snapshot` list is ordered chronologically with the most recent messages at the start.
|
|
475
|
+
* When a new message is received, it will be added to the start of the list.
|
|
476
|
+
*
|
|
471
477
|
* The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
|
|
478
|
+
*
|
|
479
|
+
* Initially, you will be subscribed to the 30 most recent messages and any new messages.
|
|
480
|
+
* Call `loadMore` to load additional older messages. This will trigger `onSnapshot`.
|
|
481
|
+
*
|
|
482
|
+
* Tip: If you only care about the most recent message in the conversation, use `ConversationRef.subscribe` or `Session.subscribeConversations`.
|
|
483
|
+
* Then use the `ConversationSnapshot.lastMessage` property. This is easier to use and slightly more efficient.
|
|
484
|
+
*
|
|
485
|
+
* Remember to call `.unsubscribe` on the subscription once you are done with it.
|
|
472
486
|
*/
|
|
473
487
|
subscribeMessages(onSnapshot?: (snapshot: MessageSnapshot[] | null, loadedAll: boolean) => void): MessageSubscription;
|
|
474
488
|
/**
|
|
475
489
|
* Subscribes to the participants in the conversation.
|
|
476
490
|
*
|
|
477
491
|
* @remarks
|
|
478
|
-
* Initially, you will be subscribed to the 10 participants who joined most recently, and any new participants.
|
|
479
|
-
* Call `loadMore` to load additional older participants.
|
|
480
|
-
*
|
|
481
492
|
* While the subscription is active, `onSnapshot` will be called whenever the participant snapshots change.
|
|
482
493
|
* This includes when someone joins or leaves, when their participant attributes are edited, and when you load more participants.
|
|
483
494
|
* It also includes when nested data changes, such as when `snapshot[0].user.name` changes.
|
|
484
495
|
* `loadedAll` is true when `snapshot` contains all the participants in the conversation, and false if you could load more.
|
|
485
496
|
*
|
|
497
|
+
* The `snapshot` list is ordered chronologically with the participants who joined most recently at the start.
|
|
498
|
+
* When someone joins the conversation, they will be added to the start of the list.
|
|
499
|
+
*
|
|
486
500
|
* The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
|
|
501
|
+
*
|
|
502
|
+
* Initially, you will be subscribed to the 10 participants who joined most recently, and any new participants.
|
|
503
|
+
* Call `loadMore` to load additional older participants. This will trigger `onSnapshot`.
|
|
504
|
+
*
|
|
505
|
+
* Remember to call `.unsubscribe` on the subscription once you are done with it.
|
|
487
506
|
*/
|
|
488
507
|
subscribeParticipants(onSnapshot?: (snapshot: ParticipantSnapshot[] | null, loadedAll: boolean) => void): ParticipantSubscription;
|
|
489
508
|
/**
|
|
@@ -494,6 +513,8 @@ export declare interface ConversationRef {
|
|
|
494
513
|
* This includes changes to nested data. As an extreme example, `onSnapshot` would be called when `snapshot.lastMessage.referencedMessage.sender.name` changes.
|
|
495
514
|
*
|
|
496
515
|
* The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
|
|
516
|
+
*
|
|
517
|
+
* Remember to call `.unsubscribe` on the subscription once you are done with it.
|
|
497
518
|
*/
|
|
498
519
|
subscribe(onSnapshot?: (snapshot: ConversationSnapshot | null) => void): ConversationSubscription;
|
|
499
520
|
/**
|
|
@@ -505,6 +526,8 @@ export declare interface ConversationRef {
|
|
|
505
526
|
* You will not be notified when there are already "many" people typing, and another person starts typing, because the snapshot does not change.
|
|
506
527
|
*
|
|
507
528
|
* The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
|
|
529
|
+
*
|
|
530
|
+
* Remember to call `.unsubscribe` on the subscription once you are done with it.
|
|
508
531
|
*/
|
|
509
532
|
subscribeTyping(onSnapshot?: (snapshot: TypingSnapshot | null) => void): TypingSubscription;
|
|
510
533
|
/**
|
|
@@ -532,7 +555,8 @@ export declare interface ConversationRef {
|
|
|
532
555
|
*
|
|
533
556
|
* const now = Date.now();
|
|
534
557
|
*
|
|
535
|
-
* //
|
|
558
|
+
* // Call `markAsTyping` sparingly - not on every keystroke
|
|
559
|
+
* // Only call if it has been at least 5 seconds since last time
|
|
536
560
|
* if (now - lastMarkedAsTyping > 5000) {
|
|
537
561
|
* lastMarkedAsTyping = now;
|
|
538
562
|
* convRef.markAsTyping();
|
|
@@ -642,6 +666,8 @@ export declare interface ConversationSnapshot {
|
|
|
642
666
|
* @remarks
|
|
643
667
|
* Get a ConversationSubscription by calling {@link ConversationRef.subscribe}
|
|
644
668
|
*
|
|
669
|
+
* Remember to `.unsubscribe` the subscription once you are done with it.
|
|
670
|
+
*
|
|
645
671
|
* @public
|
|
646
672
|
*/
|
|
647
673
|
export declare interface ConversationSubscription {
|
|
@@ -1383,6 +1409,8 @@ export declare interface MessageSnapshot {
|
|
|
1383
1409
|
*
|
|
1384
1410
|
* You can expand this window by calling {@link MessageSubscription.loadMore}, which extends the window further into the past.
|
|
1385
1411
|
*
|
|
1412
|
+
* Remember to `.unsubscribe` the subscription once you are done with it.
|
|
1413
|
+
*
|
|
1386
1414
|
* @public
|
|
1387
1415
|
*/
|
|
1388
1416
|
export declare interface MessageSubscription {
|
|
@@ -1425,6 +1453,9 @@ export declare interface MessageSubscription {
|
|
|
1425
1453
|
* @remarks
|
|
1426
1454
|
* Calling `loadMore` multiple times in parallel will still only load one page of messages.
|
|
1427
1455
|
*
|
|
1456
|
+
* Avoid calling `.loadMore` in a loop until you have loaded all messages.
|
|
1457
|
+
* If you do need to call loadMore in a loop, make sure you set an upper bound (e.g. 1000) on the number of messages, where the loop will exit.
|
|
1458
|
+
*
|
|
1428
1459
|
* @param count - The number of additional messages to load. Must be between 1 and 100. Default 30.
|
|
1429
1460
|
* @returns A promise that resolves once the additional messages have loaded
|
|
1430
1461
|
*/
|
|
@@ -1575,6 +1606,9 @@ export declare interface ParticipantSnapshot {
|
|
|
1575
1606
|
* By default, you subscribe to the 10 most recent participants, and any participants who joined after you subscribe.
|
|
1576
1607
|
*
|
|
1577
1608
|
* You can expand this window by calling {@link ParticipantSubscription.loadMore}, which extends the window further into the past.
|
|
1609
|
+
* Do not call `.loadMore` in a loop until you have loaded all participants, unless you know that the maximum number of participants is small (under 100).
|
|
1610
|
+
*
|
|
1611
|
+
* Remember to `.unsubscribe` the subscription once you are done with it.
|
|
1578
1612
|
*
|
|
1579
1613
|
* @public
|
|
1580
1614
|
*/
|
|
@@ -1618,6 +1652,9 @@ export declare interface ParticipantSubscription {
|
|
|
1618
1652
|
* @remarks
|
|
1619
1653
|
* Calling `loadMore` multiple times in parallel will still only load one page of participants.
|
|
1620
1654
|
*
|
|
1655
|
+
* Avoid calling `.loadMore` in a loop until you have loaded all participants.
|
|
1656
|
+
* If you do need to call loadMore in a loop, make sure you set a small upper bound (e.g. 100) on the number of participants, where the loop will exit.
|
|
1657
|
+
*
|
|
1621
1658
|
* @param count - The number of additional participants to load. Must be between 1 and 50. Default 10.
|
|
1622
1659
|
* @returns A promise that resolves once the additional participants have loaded
|
|
1623
1660
|
*/
|
|
@@ -2178,18 +2215,27 @@ export declare interface TalkSession {
|
|
|
2178
2215
|
* Subscribes to your most recently active conversations.
|
|
2179
2216
|
*
|
|
2180
2217
|
* @remarks
|
|
2181
|
-
* The subscription is 'windowed'. Initially, this window contains the 20 most recent conversations.
|
|
2182
|
-
* Conversations are ordered by last activity. The last activity of a conversation is either `joinedAt` or `lastMessage.createdAt`, whichever is higher.
|
|
2183
|
-
*
|
|
2184
|
-
* If an older conversation receives a new message, or you are added to a conversation, it will appear at the start of the list.
|
|
2185
|
-
* Call `loadMore` to load additional older conversations.
|
|
2186
|
-
*
|
|
2187
2218
|
* While the subscription is active, `onSnapshot` will be called whenever the conversation snapshots change.
|
|
2188
2219
|
* This includes when you join or leave a conversation, when the conversation attributes change, and when you load more conversations.
|
|
2189
2220
|
* It also includes when nested data changes, such as when `snapshot[0].lastMessage.referencedMessage.sender.name` changes.
|
|
2221
|
+
* Be careful when doing heavy computation inside `onSnapshot`, and consider caching the result. `onSnapshot` is called extremely often.
|
|
2190
2222
|
* `loadedAll` is true when `snapshot` contains all your conversations, and false if you could load more.
|
|
2191
2223
|
*
|
|
2192
|
-
*
|
|
2224
|
+
* The `snapshot` list is ordered chronologically with the most recently active conversations at the start.
|
|
2225
|
+
* The last activity of a conversation is either when the last message was sent or when you joined, whichever is later.
|
|
2226
|
+
* In other words, it's the max of `lastMessage.createdAt` and `joinedAt`.
|
|
2227
|
+
* If you join a new conversation, or you receive a message in a conversation, that conversation will appear at the start of the list.
|
|
2228
|
+
*
|
|
2229
|
+
* The snapshot is an empty list if the current user does not exist yet.
|
|
2230
|
+
*
|
|
2231
|
+
* Initially, you will be subscribed to the 20 most recently active conversations and any conversations that have activity after you subscribe.
|
|
2232
|
+
* Call `loadMore` to load additional older conversations. This will trigger `onSnapshot`.
|
|
2233
|
+
*
|
|
2234
|
+
* Tip: `ConversationSnapshot` has a `lastMessage` property. Whenever you are sent a message, that message will be at `snapshot[0].lastMessage`.
|
|
2235
|
+
* If you just want to react to newly received messages, you can use this instead of calling `ConversationRef.subscribeMessages`.
|
|
2236
|
+
* This is much easier and more efficient.
|
|
2237
|
+
*
|
|
2238
|
+
* Remember to call `.unsubscribe` on the subscription once you are done with it.
|
|
2193
2239
|
*/
|
|
2194
2240
|
subscribeConversations(onSnapshot?: (snapshot: ConversationSnapshot[], loadedAll: boolean) => void): ConversationListSubscription;
|
|
2195
2241
|
/**
|
|
@@ -2402,6 +2448,8 @@ export declare type TypingSnapshot = FewTypingSnapshot | ManyTypingSnapshot;
|
|
|
2402
2448
|
* When there are "many" people typing (meaning you received {@link ManyTypingSnapshot}), the next update you receive will be {@link FewTypingSnapshot} once enough people stop typing.
|
|
2403
2449
|
* Until then, your {@link ManyTypingSnapshot} is still valid and does not need to changed, so `onSnapshot` will not be called.
|
|
2404
2450
|
*
|
|
2451
|
+
* Remember to `.unsubscribe` the subscription once you are done with it.
|
|
2452
|
+
*
|
|
2405
2453
|
* @public
|
|
2406
2454
|
*/
|
|
2407
2455
|
export declare interface TypingSubscription {
|
|
@@ -2514,6 +2562,8 @@ export declare interface UserOnlineSnapshot {
|
|
|
2514
2562
|
* @remarks
|
|
2515
2563
|
* Get a UserOnlineSubscription by calling {@link UserRef.subscribeOnline}.
|
|
2516
2564
|
*
|
|
2565
|
+
* Remember to `.unsubscribe` the subscription once you are done with it.
|
|
2566
|
+
*
|
|
2517
2567
|
* @public
|
|
2518
2568
|
*/
|
|
2519
2569
|
export declare interface UserOnlineSubscription {
|
|
@@ -2610,6 +2660,8 @@ export declare interface UserRef {
|
|
|
2610
2660
|
* @remarks
|
|
2611
2661
|
* While the subscription is active, `onSnapshot` will be called when the user is created or the snapshot changes.
|
|
2612
2662
|
*
|
|
2663
|
+
* Remember to call `.unsubscribe` on the subscription once you are done with it.
|
|
2664
|
+
*
|
|
2613
2665
|
* @returns A subscription to the user
|
|
2614
2666
|
*/
|
|
2615
2667
|
subscribe(onSnapshot?: (event: UserSnapshot | null) => void): UserSubscription;
|
|
@@ -2619,6 +2671,8 @@ export declare interface UserRef {
|
|
|
2619
2671
|
* @remarks
|
|
2620
2672
|
* While the subscription is active, `onSnapshot` will be called when the user is created or the snapshot changes (including changes to the nested UserSnapshot).
|
|
2621
2673
|
*
|
|
2674
|
+
* Remember to call `.unsubscribe` on the subscription once you are done with it.
|
|
2675
|
+
*
|
|
2622
2676
|
* @returns A subscription to the user's online status
|
|
2623
2677
|
*/
|
|
2624
2678
|
subscribeOnline(onSnapshot?: (event: UserOnlineSnapshot | null) => void): UserOnlineSubscription;
|
|
@@ -2675,6 +2729,8 @@ export declare interface UserSnapshot {
|
|
|
2675
2729
|
* @remarks
|
|
2676
2730
|
* Get a UserSubscription by calling {@link UserRef.subscribe}
|
|
2677
2731
|
*
|
|
2732
|
+
* Remember to `.unsubscribe` the subscription once you are done with it.
|
|
2733
|
+
*
|
|
2678
2734
|
* @public
|
|
2679
2735
|
*/
|
|
2680
2736
|
export declare interface UserSubscription {
|