@talkjs/core 1.3.0 → 1.4.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.
@@ -461,8 +461,10 @@ export declare interface ConversationRef {
461
461
  * Initially, you will be subscribed to the 30 most recent messages and any new messages.
462
462
  * Call `loadMore` to load additional older messages.
463
463
  *
464
- * Whenever `Subscription.state.type` is "active" and a message is sent, edited, deleted, or you load more messages, `onSnapshot` will fire and `Subscription.state.latestSnapshot` will be updated.
465
- * `loadedAll` is true when the snapshot contains all the messages in the conversation.
464
+ * While the subscription is active, `onSnapshot` will be called whenever the message snapshots change.
465
+ * This includes when a message is sent, edited, deleted, and when you load more messages.
466
+ * It also includes when nested data changes, such as when `snapshot[0].referencedMessage.sender.name` changes.
467
+ * `loadedAll` is true when `snapshot` contains all the messages in the conversation, and false if you could load more.
466
468
  *
467
469
  * The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
468
470
  */
@@ -474,8 +476,10 @@ export declare interface ConversationRef {
474
476
  * Initially, you will be subscribed to the 10 participants who joined most recently, and any new participants.
475
477
  * Call `loadMore` to load additional older participants.
476
478
  *
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
+ * While the subscription is active, `onSnapshot` will be called whenever the participant snapshots change.
480
+ * This includes when someone joins or leaves, when their participant attributes are edited, and when you load more participants.
481
+ * It also includes when nested data changes, such as when `snapshot[0].user.name` changes.
482
+ * `loadedAll` is true when `snapshot` contains all the participants in the conversation, and false if you could load more.
479
483
  *
480
484
  * The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
481
485
  */
@@ -484,7 +488,7 @@ export declare interface ConversationRef {
484
488
  * Subscribes to the conversation.
485
489
  *
486
490
  * @remarks
487
- * Whenever `Subscription.state.type` is "active" and something about the conversation changes, `onSnapshot` will fire and `Subscription.state.latestSnapshot` will be updated.
491
+ * While the subscription is active, `onSnapshot` will be called when you join or leave the conversation, or when the snapshot changes.
488
492
  * This includes changes to nested data. As an extreme example, `onSnapshot` would be called when `snapshot.lastMessage.referencedMessage.sender.name` changes.
489
493
  *
490
494
  * The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
@@ -494,13 +498,11 @@ export declare interface ConversationRef {
494
498
  * Subscribes to the typing status of the conversation.
495
499
  *
496
500
  * @remarks
497
- * Whenever `Subscription.state.type` is "active" and the typing status changes, `onSnapshot` will fire and `Subscription.state.latestSnapshot` will be updated.
498
- * This includes changes to nested data, such as when a user who is typing changes their name.
501
+ * While the subscription is active, `onSnapshot` will be called when you join or leave the conversation, or when the snapshot changes.
502
+ * This includes changes to the nested `UserSnapshot`s. If one of the people who is typing, changes their name, `onSnapshot` will be called.
503
+ * You will not be notified when there are already "many" people typing, and another person starts typing, because the snapshot does not change.
499
504
  *
500
505
  * The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
501
- *
502
- * Note that if there are "many" people typing and another person starts to type, `onSnapshot` will not be called.
503
- * This is because your existing {@link ManyTypingSnapshot} is still valid and did not change when the new person started to type.
504
506
  */
505
507
  subscribeTyping(onSnapshot?: (snapshot: TypingSnapshot | null) => void): TypingSubscription;
506
508
  /**
@@ -2033,8 +2035,10 @@ export declare interface TalkSession {
2033
2035
  * 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
2036
  * Call `loadMore` to load additional older conversations.
2035
2037
  *
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
+ * While the subscription is active, `onSnapshot` will be called whenever the conversation snapshots change.
2039
+ * This includes when you join or leave a conversation, when the conversation attributes change, and when you load more conversations.
2040
+ * It also includes when nested data changes, such as when `snapshot[0].lastMessage.referencedMessage.sender.name` changes.
2041
+ * `loadedAll` is true when `snapshot` contains all your conversations, and false if you could load more.
2038
2042
  *
2039
2043
  * If the current user does not exist yet, the snapshot will be an empty list.
2040
2044
  */
@@ -2312,6 +2316,97 @@ export declare interface UserActiveState {
2312
2316
  latestSnapshot: UserSnapshot | null;
2313
2317
  }
2314
2318
 
2319
+ /**
2320
+ * The state of a user online subscription when it is actively listening for changes
2321
+ *
2322
+ * @public
2323
+ */
2324
+ export declare interface UserOnlineActiveState {
2325
+ type: "active";
2326
+ /**
2327
+ * The most recently received snapshot
2328
+ */
2329
+ latestSnapshot: UserOnlineSnapshot | null;
2330
+ }
2331
+
2332
+ /**
2333
+ * A snapshot of a user's online status at a given moment in time.
2334
+ *
2335
+ * @remarks
2336
+ * Snapshots are immutable and we try to reuse them when possible. You should only re-render your UI when `oldSnapshot !== newSnapshot`.
2337
+ *
2338
+ * @public
2339
+ */
2340
+ export declare interface UserOnlineSnapshot {
2341
+ /**
2342
+ * The user this snapshot relates to
2343
+ */
2344
+ user: UserSnapshot;
2345
+ /**
2346
+ * Whether the user is connected right now
2347
+ *
2348
+ * @remarks
2349
+ * Users are considered connected whenever they have an active websocket connection to the TalkJS servers.
2350
+ * In practice, this means:
2351
+ *
2352
+ * People using the {@link https://talkjs.com/docs/Reference/JavaScript_Data_API/ | JS Data API} are considered connected if they are subscribed to something, or if they sent a request in the last few seconds.
2353
+ * Creating a `TalkSession` is not enough to appear connected.
2354
+ *
2355
+ * People using {@link https://talkjs.com/docs/Reference/Components/ | Components}, are considered connected if they have a UI open.
2356
+ *
2357
+ * People using the {@link https://talkjs.com/docs/Reference/JavaScript_Chat_SDK/ | JavaScript SDK}, {@link https://talkjs.com/docs/Reference/React_SDK/Installation/ | React SDK}, {@link https://talkjs.com/docs/Reference/React_Native_SDK/Installation/ | React Native SDK}, or {@link https://talkjs.com/docs/Reference/Flutter_SDK/Installation/ | Flutter SDK} are considered connected whenever they have an active `Session` object.
2358
+ */
2359
+ isConnected: boolean;
2360
+ }
2361
+
2362
+ /**
2363
+ * A subscription to the online status of a user
2364
+ *
2365
+ * @remarks
2366
+ * Get a UserOnlineSubscription by calling {@link UserRef.subscribeOnline}.
2367
+ *
2368
+ * @public
2369
+ */
2370
+ export declare interface UserOnlineSubscription {
2371
+ /**
2372
+ * The current state of the subscription
2373
+ *
2374
+ * @remarks
2375
+ * An object with the following fields:
2376
+ *
2377
+ * `type` is one of "pending", "active", "unsubscribed", or "error".
2378
+ *
2379
+ * When `type` is "active", includes `latestSnapshot: UserOnlineSnapshot | null`
2380
+ * `null` means the user does not exist.
2381
+ *
2382
+ * When `type` is "error", includes the `error` field. It is a JS `Error` object explaining what caused the subscription to be terminated.
2383
+ */
2384
+ state: PendingState | UserOnlineActiveState | UnsubscribedState | ErrorState;
2385
+ /**
2386
+ * Resolves when the subscription starts receiving updates from the server.
2387
+ *
2388
+ * @remarks
2389
+ * Wait for this promise if you want to perform some action as soon as the subscription is active.
2390
+ *
2391
+ * The promise rejects if the subscription is terminated before it connects.
2392
+ */
2393
+ connected: Promise<UserOnlineActiveState>;
2394
+ /**
2395
+ * Resolves when the subscription permanently stops receiving updates from the server.
2396
+ *
2397
+ * @remarks
2398
+ * This is either because you unsubscribed or because the subscription encountered an unrecoverable error.
2399
+ */
2400
+ terminated: Promise<UnsubscribedState | ErrorState>;
2401
+ /**
2402
+ * Unsubscribe from this resource and stop receiving updates.
2403
+ *
2404
+ * @remarks
2405
+ * If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.
2406
+ */
2407
+ unsubscribe(): void;
2408
+ }
2409
+
2315
2410
  /**
2316
2411
  * References the user with a given user ID.
2317
2412
  *
@@ -2364,11 +2459,20 @@ export declare interface UserRef {
2364
2459
  * Subscribe to this user's state.
2365
2460
  *
2366
2461
  * @remarks
2367
- * Whenever `Subscription.state.type` is "active" and the user is created or their attributes change, `onSnapshot` will fire and `Subscription.state.latestSnapshot` will be updated.
2462
+ * While the subscription is active, `onSnapshot` will be called when the user is created or the snapshot changes.
2368
2463
  *
2369
2464
  * @returns A subscription to the user
2370
2465
  */
2371
2466
  subscribe(onSnapshot?: (event: UserSnapshot | null) => void): UserSubscription;
2467
+ /**
2468
+ * Subscribe to this user and their online status.
2469
+ *
2470
+ * @remarks
2471
+ * While the subscription is active, `onSnapshot` will be called when the user is created or the snapshot changes (including changes to the nested UserSnapshot).
2472
+ *
2473
+ * @returns A subscription to the user's online status
2474
+ */
2475
+ subscribeOnline(onSnapshot?: (event: UserOnlineSnapshot | null) => void): UserOnlineSubscription;
2372
2476
  }
2373
2477
 
2374
2478
  /**