stream-chat 10.1.1 → 10.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.
Files changed (109) hide show
  1. package/dist/cjs/index.browser.js +4736 -2819
  2. package/dist/cjs/index.browser.js.map +4 -4
  3. package/dist/cjs/index.node.js +4757 -2819
  4. package/dist/cjs/index.node.js.map +4 -4
  5. package/dist/esm/index.mjs +4736 -2819
  6. package/dist/esm/index.mjs.map +4 -4
  7. package/dist/types/channel.d.ts +62 -3
  8. package/dist/types/client.d.ts +9 -1
  9. package/dist/types/configuration/types.d.ts +2 -0
  10. package/dist/types/connection/ConnectionRecoveryManager.d.ts +1 -0
  11. package/dist/types/gen/chat/ChatApi.d.ts +12 -1
  12. package/dist/types/gen/models/index.d.ts +659 -11
  13. package/dist/types/gen/moderation/ModerationApi.d.ts +3 -1
  14. package/dist/types/index.d.ts +2 -0
  15. package/dist/types/messageComposer/attachmentManager.d.ts +2 -0
  16. package/dist/types/messageComposer/index.d.ts +1 -0
  17. package/dist/types/messageComposer/linkPreviewsManager.d.ts +1 -0
  18. package/dist/types/messageComposer/messageComposer.d.ts +33 -7
  19. package/dist/types/messageComposer/middleware/messageComposer/compositionValidation.d.ts +1 -2
  20. package/dist/types/messageComposer/middleware/messageComposer/index.d.ts +1 -0
  21. package/dist/types/messageComposer/middleware/messageComposer/scheduledMessage.d.ts +4 -0
  22. package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +1 -0
  23. package/dist/types/messageComposer/scheduledMessageComposition.d.ts +32 -0
  24. package/dist/types/messageMarks/MessageMarkManager.d.ts +44 -0
  25. package/dist/types/messageMarks/index.d.ts +1 -0
  26. package/dist/types/messageOperations/MessageOperations.d.ts +12 -1
  27. package/dist/types/messageOperations/index.d.ts +1 -0
  28. package/dist/types/messageOperations/reflectMessageMarkEvent.d.ts +9 -0
  29. package/dist/types/messageOperations/sendOrdering.d.ts +4 -3
  30. package/dist/types/messageOperations/types.d.ts +6 -2
  31. package/dist/types/notifications/types.d.ts +4 -0
  32. package/dist/types/offline-support/offline_support_api.d.ts +19 -1
  33. package/dist/types/offline-support/types.d.ts +19 -1
  34. package/dist/types/pagination/PaginatorView.d.ts +55 -0
  35. package/dist/types/pagination/index.d.ts +1 -0
  36. package/dist/types/pagination/paginators/BasePaginator.d.ts +49 -0
  37. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +0 -9
  38. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +6 -0
  39. package/dist/types/pagination/paginators/MessageMarkPaginator.d.ts +61 -0
  40. package/dist/types/pagination/paginators/ScheduledMessagePaginator.d.ts +83 -0
  41. package/dist/types/pagination/paginators/index.d.ts +2 -0
  42. package/dist/types/scheduledMessages/ScheduledMessagePaginatorsManager.d.ts +47 -0
  43. package/dist/types/scheduledMessages/ScheduledMessageStatePolicy.d.ts +12 -0
  44. package/dist/types/scheduledMessages/ScheduledMessagesView.d.ts +38 -0
  45. package/dist/types/scheduledMessages/composition.d.ts +5 -0
  46. package/dist/types/scheduledMessages/constants.d.ts +56 -0
  47. package/dist/types/scheduledMessages/editResolvers.d.ts +4 -0
  48. package/dist/types/scheduledMessages/errors.d.ts +3 -0
  49. package/dist/types/scheduledMessages/eventHandlers.d.ts +8 -0
  50. package/dist/types/scheduledMessages/index.d.ts +7 -0
  51. package/dist/types/scheduledMessages/limits.d.ts +6 -0
  52. package/dist/types/scheduledMessages/types.d.ts +65 -0
  53. package/dist/types/thread.d.ts +12 -1
  54. package/dist/types/utils.d.ts +7 -0
  55. package/package.json +1 -1
  56. package/src/channel.ts +231 -7
  57. package/src/client.ts +46 -2
  58. package/src/configuration/keys.ts +2 -0
  59. package/src/configuration/shape.ts +15 -0
  60. package/src/configuration/types.ts +3 -1
  61. package/src/connection/ConnectionRecoveryManager.ts +7 -0
  62. package/src/errors.ts +11 -0
  63. package/src/gen/chat/ChatApi.ts +60 -3
  64. package/src/gen/models/index.ts +794 -23
  65. package/src/gen/moderation/ModerationApi.ts +24 -3
  66. package/src/index.ts +2 -0
  67. package/src/messageComposer/attachmentManager.ts +43 -24
  68. package/src/messageComposer/index.ts +1 -0
  69. package/src/messageComposer/messageComposer.ts +140 -32
  70. package/src/messageComposer/middleware/messageComposer/MessageComposerMiddlewareExecutor.ts +2 -0
  71. package/src/messageComposer/middleware/messageComposer/compositionValidation.ts +40 -47
  72. package/src/messageComposer/middleware/messageComposer/index.ts +1 -0
  73. package/src/messageComposer/middleware/messageComposer/scheduledMessage.ts +38 -0
  74. package/src/messageComposer/middleware/textComposer/commandUtils.ts +8 -0
  75. package/src/messageComposer/scheduledMessageComposition.ts +324 -0
  76. package/src/messageMarks/MessageMarkManager.ts +145 -0
  77. package/src/messageMarks/index.ts +1 -0
  78. package/src/messageOperations/MessageOperationStatePolicy.ts +7 -0
  79. package/src/messageOperations/MessageOperations.ts +154 -1
  80. package/src/messageOperations/index.ts +1 -0
  81. package/src/messageOperations/reflectMessageMarkEvent.ts +47 -0
  82. package/src/messageOperations/reflectReactionEvent.ts +3 -0
  83. package/src/messageOperations/sendOrdering.ts +11 -4
  84. package/src/messageOperations/types.ts +6 -2
  85. package/src/notifications/types.ts +4 -0
  86. package/src/offline-support/offline_support_api.ts +61 -1
  87. package/src/offline-support/queueableOperations.ts +6 -0
  88. package/src/offline-support/types.ts +28 -0
  89. package/src/pagination/PaginatorView.ts +103 -0
  90. package/src/pagination/index.ts +1 -0
  91. package/src/pagination/paginators/BasePaginator.ts +204 -29
  92. package/src/pagination/paginators/ChannelPaginator.ts +8 -28
  93. package/src/pagination/paginators/MessageIntervalPaginator.ts +14 -1
  94. package/src/pagination/paginators/MessageMarkPaginator.ts +222 -0
  95. package/src/pagination/paginators/ScheduledMessagePaginator.ts +352 -0
  96. package/src/pagination/paginators/index.ts +2 -0
  97. package/src/scheduledMessages/ScheduledMessagePaginatorsManager.ts +268 -0
  98. package/src/scheduledMessages/ScheduledMessageStatePolicy.ts +42 -0
  99. package/src/scheduledMessages/ScheduledMessagesView.ts +57 -0
  100. package/src/scheduledMessages/composition.ts +129 -0
  101. package/src/scheduledMessages/constants.ts +79 -0
  102. package/src/scheduledMessages/editResolvers.ts +51 -0
  103. package/src/scheduledMessages/errors.ts +45 -0
  104. package/src/scheduledMessages/eventHandlers.ts +58 -0
  105. package/src/scheduledMessages/index.ts +7 -0
  106. package/src/scheduledMessages/limits.ts +32 -0
  107. package/src/scheduledMessages/types.ts +124 -0
  108. package/src/thread.ts +41 -17
  109. package/src/utils.ts +18 -0
@@ -217,6 +217,15 @@ export type PlaceQueryPageParams<T, Q> = QueryPagePlacement<Q> & {
217
217
  results: PaginationQueryReturnValue<T> | null;
218
218
  };
219
219
 
220
+ type EmptyCompleteFirstPagePlacement = {
221
+ isFirstPage: boolean;
222
+ isHead: boolean;
223
+ isTail: boolean;
224
+ isSeparateInterval: boolean;
225
+ keepPreviousItems: boolean;
226
+ updateState: boolean;
227
+ };
228
+
220
229
  /**
221
230
  * What the preparing step of the query pipeline hands to the next ones (see
222
231
  * `BasePaginator.executeQuery`): the parameters for fetching and for placing the page, and the
@@ -280,6 +289,12 @@ export type PaginatorState<T> = {
280
289
  hasMoreHead: boolean;
281
290
  hasMoreTail: boolean;
282
291
  isLoading: boolean;
292
+ /**
293
+ * The direction of the running query while it loads a page at an edge of the loaded items
294
+ * (`toHead()`, `toTail()`). `undefined` while no query runs, and for a query that loads no such
295
+ * page: a first page, a refresh, or a page at a query shape the caller gives (a jump).
296
+ */
297
+ loadingDirection?: PaginationDirection;
283
298
  items: T[] | undefined;
284
299
  lastQueryError?: Error;
285
300
  cursor?: PaginatorCursor;
@@ -397,6 +412,15 @@ export type PaginatorOptions<T, Q> = {
397
412
  * Does not hold across interval changes or page jumps.
398
413
  */
399
414
  lockItemOrder?: boolean;
415
+ /**
416
+ * Where a newly ingested item lands in a loaded list that is already empty and complete. When the
417
+ * sort order follows arrival (recency lists: messages by `created_at`, channels by
418
+ * `last_message_at`), a new item is the newest and waits in the logical head, leaving the list
419
+ * re-queryable — so this stays `false`. When the sort order is independent of arrival (scheduled
420
+ * messages, by `scheduled_at`), completeness makes its slot known, so it anchors a real interval
421
+ * there instead; such paginators set this `true`. Defaults to `false`.
422
+ */
423
+ newItemsAnchorBySortPosition?: boolean;
400
424
  /**
401
425
  * Caps the loaded items: when the head interval exceeds it, the oldest are released as new ones
402
426
  * arrive and the tailward edge re-opens, so scrolling back re-fetches. Unset: unbounded. Values
@@ -448,6 +472,7 @@ export const DEFAULT_PAGINATION_OPTIONS: BasePaginatorConfig<any, any> = deepFre
448
472
  {
449
473
  debounceMs: 300,
450
474
  lockItemOrder: false,
475
+ newItemsAnchorBySortPosition: false,
451
476
  pageSize: 10,
452
477
  hasPaginationQueryShapeChanged: baseHasPaginationQueryShapeChanged,
453
478
  retryCount: 0,
@@ -537,6 +562,11 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
537
562
  protected _lastQueryShape?: Q;
538
563
  /** Set by `setItems`, which loads a page (even an empty one) without a query. */
539
564
  private _pageSetWithoutQuery = false;
565
+ /**
566
+ * The IDs of the offline database's page (see {@link preloadFirstPageFromOfflineDb}) that no live
567
+ * event has touched since, until a page from the server takes their place.
568
+ */
569
+ private _offlineOnlyItemIds: Set<string> | undefined;
540
570
 
541
571
  /**
542
572
  * Stable, purely data-driven comparison (age, timestamps, ...). Default for
@@ -606,6 +636,12 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
606
636
  cursor: this.config.initialCursor,
607
637
  offset: this.config.initialOffset ?? 0,
608
638
  });
639
+ // A query has a loading direction only while it loads: every path that ends a query clears it.
640
+ this.state.addPreprocessor((next) => {
641
+ if (!next.isLoading && next.loadingDirection !== undefined) {
642
+ next.loadingDirection = undefined;
643
+ }
644
+ });
609
645
  // Called directly: `onChanged` fires on changes, not on the initial build.
610
646
  this.rebuildStatePublishThrottles(this.config.stateThrottleMs);
611
647
  this.intervalViews = new StateStore<PaginatorIntervalViews<T>>({
@@ -645,6 +681,11 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
645
681
  return this.state.getLatestValue().isLoading;
646
682
  }
647
683
 
684
+ /** See {@link PaginatorState.loadingDirection}. */
685
+ get loadingDirection() {
686
+ return this.state.getLatestValue().loadingDirection;
687
+ }
688
+
648
689
  /**
649
690
  * True once a query has run or a non-empty interval was loaded without one (`setItems`, or a
650
691
  * subclass calling `recordLoadedIntervalQueryShape`). Cleared by `resetState`.
@@ -665,6 +706,41 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
665
706
  return this._pageSetWithoutQuery || this.isInitialized;
666
707
  }
667
708
 
709
+ private get isLoadedEmptyAndComplete() {
710
+ const { hasMoreHead, hasMoreTail } = this.state.getLatestValue();
711
+ return (
712
+ this.hasLoadedPage &&
713
+ !hasMoreHead &&
714
+ !hasMoreTail &&
715
+ this.itemIntervals.every((itv) => isLogicalInterval(itv) || !itv.itemIds.length)
716
+ );
717
+ }
718
+
719
+ private placeEmptyCompleteFirstPage({
720
+ isFirstPage,
721
+ isHead,
722
+ isTail,
723
+ isSeparateInterval,
724
+ keepPreviousItems,
725
+ updateState,
726
+ }: EmptyCompleteFirstPagePlacement): Interval | null {
727
+ const placesEmptyCompleteFirstPage =
728
+ this.config.newItemsAnchorBySortPosition &&
729
+ updateState &&
730
+ isFirstPage &&
731
+ !isSeparateInterval &&
732
+ !keepPreviousItems &&
733
+ isHead &&
734
+ isTail;
735
+
736
+ if (!placesEmptyCompleteFirstPage) return null;
737
+
738
+ const page = [...this.logicalHeadItems, ...this.logicalTailItems].sort(
739
+ this.sortComparator,
740
+ );
741
+ return this.ingestPage({ page, isHead: true, isTail: true });
742
+ }
743
+
668
744
  get isOfflineSupportEnabled() {
669
745
  return false;
670
746
  }
@@ -678,6 +754,7 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
678
754
  hasMoreHead: true,
679
755
  hasMoreTail: true,
680
756
  isLoading: false,
757
+ loadingDirection: undefined,
681
758
  items: undefined,
682
759
  lastQueryError: undefined,
683
760
  cursor: this.config.initialCursor,
@@ -940,6 +1017,7 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
940
1017
  * publishes.
941
1018
  */
942
1019
  protected clearItemStorage() {
1020
+ this._offlineOnlyItemIds = undefined;
943
1021
  this.setIntervals([]);
944
1022
  this.setActiveInterval(undefined);
945
1023
  this._itemIndex.clear();
@@ -2364,6 +2442,8 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
2364
2442
  * interval whose sort bounds contain it, and re-emits `state.items` when that interval is active.
2365
2443
  */
2366
2444
  ingestItem(ingestedItem: T): boolean {
2445
+ // A live event confirms the item: it outlives the offline page it may belong to.
2446
+ this._offlineOnlyItemIds?.delete(this.getItemId(ingestedItem));
2367
2447
  let ingested = false;
2368
2448
  this.withSingleActiveIntervalPublish(() => {
2369
2449
  ingested = this.applyItemIngestion(ingestedItem);
@@ -2436,12 +2516,15 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
2436
2516
  // unloaded).
2437
2517
  if (this._itemIntervals.size === 0) {
2438
2518
  // No pages yet: keep it in the logical head.
2439
- targetInterval = {
2440
- id: LOGICAL_HEAD_INTERVAL_ID,
2441
- itemIds: [this.getItemId(ingestedItem)],
2442
- };
2519
+ targetInterval =
2520
+ this.config.newItemsAnchorBySortPosition && this.isLoadedEmptyAndComplete
2521
+ ? this.makeInterval({ page: [ingestedItem], isHead: true, isTail: true })
2522
+ : {
2523
+ id: LOGICAL_HEAD_INTERVAL_ID,
2524
+ itemIds: [this.getItemId(ingestedItem)],
2525
+ };
2443
2526
  if (!this._activeIntervalId) {
2444
- this.setActiveInterval(targetInterval);
2527
+ this.setActiveInterval(targetInterval, { updateState: false });
2445
2528
  }
2446
2529
  } else {
2447
2530
  const intervals = this.itemIntervals;
@@ -2701,6 +2784,9 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
2701
2784
  this.setActiveInterval(interval, { updateState: false });
2702
2785
  newState.hasMoreHead = interval.hasMoreHead;
2703
2786
  newState.hasMoreTail = interval.hasMoreTail;
2787
+ } else if (isFirstPage && isLastPage) {
2788
+ newState.hasMoreHead = false;
2789
+ newState.hasMoreTail = false;
2704
2790
  }
2705
2791
 
2706
2792
  // Before the publish below: subscribers read `hasLoadedPage` from inside it.
@@ -2883,10 +2969,67 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
2883
2969
  };
2884
2970
  }
2885
2971
 
2972
+ /**
2973
+ * The offline database's copy of the first page, shown while the first query of a paginator not
2974
+ * initialized yet runs. It is stored like a page, so live items join it. The first page from the
2975
+ * server takes the place of its items no live event touched, as the copy can be arbitrarily old,
2976
+ * and merges with the rest, as a loaded page would. A failed query leaves it shown. `undefined`
2977
+ * (the default) shows nothing until the server answers.
2978
+ */
2886
2979
  preloadFirstPageFromOfflineDb = (
2887
2980
  _params: PaginationQueryParams<Q>,
2888
2981
  ): Promise<T[] | undefined> | T[] | undefined => undefined;
2889
2982
 
2983
+ /** Whether the shown items are the offline database's page, not yet replaced by the server's. */
2984
+ protected get showsOfflinePage() {
2985
+ return typeof this._offlineOnlyItemIds !== 'undefined';
2986
+ }
2987
+
2988
+ /**
2989
+ * Stores the offline database's page as the head interval and returns its items, ordered. Without
2990
+ * an interval behind them, the next live item would rebuild `state.items` without them.
2991
+ */
2992
+ private storeOfflinePage(page: T[]): T[] {
2993
+ const interval = this.ingestPage({ page, isHead: true });
2994
+ if (!interval) return page;
2995
+ this._offlineOnlyItemIds = new Set(page.map((item) => this.getItemId(item)));
2996
+ this.setActiveInterval(interval, { updateState: false });
2997
+ return this.intervalToItems(interval);
2998
+ }
2999
+
3000
+ /**
3001
+ * Shows the offline database's page without a query, for a subclass that defers its first query
3002
+ * (see `ChannelPaginator.executeQuery`). Like the page of {@link preloadFirstPageFromOfflineDb},
3003
+ * the first page from the server takes its place.
3004
+ */
3005
+ protected setItemsFromOfflineDb(items: T[]) {
3006
+ this.setItems({ valueOrFactory: items, isFirstPage: true });
3007
+ this._offlineOnlyItemIds = new Set(items.map((item) => this.getItemId(item)));
3008
+ }
3009
+
3010
+ /**
3011
+ * Takes the offline database's items no live event touched out of storage, without publishing:
3012
+ * the server's page placed next publishes the list once.
3013
+ */
3014
+ private removeOfflineOnlyItems() {
3015
+ const ids = this._offlineOnlyItemIds;
3016
+ this._offlineOnlyItemIds = undefined;
3017
+ if (!ids?.size) return;
3018
+ for (const interval of this.itemIntervals) {
3019
+ const itemIds = interval.itemIds.filter((id) => !ids.has(id));
3020
+ if (itemIds.length === interval.itemIds.length) continue;
3021
+ if (itemIds.length) {
3022
+ this.commitInterval({ ...interval, itemIds });
3023
+ continue;
3024
+ }
3025
+ this.dropInterval(interval.id);
3026
+ if (this.isActiveInterval(interval)) {
3027
+ this.setActiveInterval(undefined, { updateState: false });
3028
+ }
3029
+ }
3030
+ ids.forEach((id) => this._itemIndex.remove(id));
3031
+ }
3032
+
2890
3033
  populateOfflineDbAfterQuery = (_params: {
2891
3034
  items: T[] | undefined;
2892
3035
  queryShape: Q | undefined;
@@ -3174,14 +3317,22 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
3174
3317
  if (checkWasStateResetDuringQuery()) return;
3175
3318
  throw error;
3176
3319
  }
3320
+ // the page of a query started before a reset must not reach the reset storage
3177
3321
  if (checkWasStateResetDuringQuery()) return;
3178
- publishStateBeforeFirstQuery(items ?? stateBeforeFirstQuery.items);
3322
+ publishStateBeforeFirstQuery(
3323
+ items ? this.storeOfflinePage(items) : stateBeforeFirstQuery.items,
3324
+ );
3179
3325
  })();
3180
3326
  }
3181
3327
  } else if (!silent) {
3182
3328
  // A next page, or a refresh keeping the items: loading shows without blanking the list, and
3183
- // the page merges into the loaded intervals in `placeQueryPage`.
3184
- this.state.partialNext({ isLoading: true });
3329
+ // the page merges into the loaded intervals in `placeQueryPage`. Only a next page loads at an
3330
+ // edge of the loaded items; a page at the caller's shape has no known place.
3331
+ const loadsAtEdge = !isFirstPage && !forcedQueryShape;
3332
+ this.state.partialNext({
3333
+ isLoading: true,
3334
+ loadingDirection: loadsAtEdge ? direction : undefined,
3335
+ });
3185
3336
  }
3186
3337
 
3187
3338
  // a page at the caller's shape has no known place relative to the active interval
@@ -3215,6 +3366,18 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
3215
3366
  placeQueryPage(params: PlaceQueryPageParams<T, Q>): ExecuteQueryReturnValue<T> {
3216
3367
  this._lastQueryShape = params.queryShape;
3217
3368
  const { results } = params;
3369
+ if (results && this.showsOfflinePage) {
3370
+ // The server's page takes the place of the offline database's, which can be arbitrarily old,
3371
+ // as a first page. That holds for the next query after a failed one too, which continues the
3372
+ // offline page's position. Live items ingested meanwhile stay and the page merges with them.
3373
+ this.removeOfflineOnlyItems();
3374
+ params = {
3375
+ ...params,
3376
+ continuesIntervalId: undefined,
3377
+ isFirstPage: true,
3378
+ keepPreviousItems: false,
3379
+ };
3380
+ }
3218
3381
  if (!results) {
3219
3382
  const stateUpdate: Partial<PaginatorState<T>> = {
3220
3383
  isLoading: false,
@@ -3364,27 +3527,38 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
3364
3527
  : undefined;
3365
3528
  // Read before the ingest, which may merge them into the page's interval.
3366
3529
  const headIntervalIds = this.getHeadIntervalIds();
3367
- const interval = this.ingestPage({
3368
- page: stateUpdate.items,
3369
- policy: isSeparateInterval ? 'strict-overlap-only' : 'auto',
3370
- // a first page is the head unless its query started it elsewhere (at a cursor)
3371
- isHead: reachesHead
3372
- ? true
3373
- : isJumpQuery
3374
- ? undefined //head/tail doesn't apply / is unknown for this ingestion
3375
- : (isFirstPage && this.isHeadPageQueryShape(queryShape)) ||
3376
- (direction === 'headward' ? requestedPageSize > items.length : undefined),
3377
- // even though the page is first, we have to compare the requested vs returned page size;
3378
- // a first page queried towards the head says nothing about the tail
3379
- isTail: reachesTail
3380
- ? true
3381
- : isJumpQuery
3382
- ? undefined //head/tail doesn't apply / is unknown for this ingestion
3383
- : (isFirstPage && direction !== 'headward') || direction === 'tailward'
3384
- ? requestedPageSize > items.length
3385
- : undefined,
3386
- targetIntervalId: isSeparateInterval ? undefined : this._activeIntervalId,
3387
- });
3530
+ // a first page is the head unless its query started it elsewhere (at a cursor)
3531
+ const isHead = reachesHead
3532
+ ? true
3533
+ : isJumpQuery
3534
+ ? undefined //head/tail doesn't apply / is unknown for this ingestion
3535
+ : (isFirstPage && this.isHeadPageQueryShape(queryShape)) ||
3536
+ (direction === 'headward' ? requestedPageSize > items.length : undefined);
3537
+ // even though the page is first, we have to compare the requested vs returned page size;
3538
+ // a first page queried towards the head says nothing about the tail
3539
+ const isTail = reachesTail
3540
+ ? true
3541
+ : isJumpQuery
3542
+ ? undefined //head/tail doesn't apply / is unknown for this ingestion
3543
+ : (isFirstPage && direction !== 'headward') || direction === 'tailward'
3544
+ ? requestedPageSize > items.length
3545
+ : undefined;
3546
+ const interval =
3547
+ this.ingestPage({
3548
+ page: stateUpdate.items,
3549
+ policy: isSeparateInterval ? 'strict-overlap-only' : 'auto',
3550
+ isHead,
3551
+ isTail,
3552
+ targetIntervalId: isSeparateInterval ? undefined : this._activeIntervalId,
3553
+ }) ??
3554
+ this.placeEmptyCompleteFirstPage({
3555
+ isFirstPage,
3556
+ isHead: !!isHead,
3557
+ isTail: !!isTail,
3558
+ isSeparateInterval,
3559
+ keepPreviousItems: !!keepPreviousItems,
3560
+ updateState,
3561
+ });
3388
3562
  const intervalReachesHead =
3389
3563
  reachesHead ||
3390
3564
  (!!interval && this.inheritsHeadMark(interval, direction, headIntervalIds));
@@ -3589,6 +3763,7 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
3589
3763
  // the publish below, whose subscribers read `isInitialized` / `hasLoadedPage`.
3590
3764
  this._lastQueryShape = undefined;
3591
3765
  this._pageSetWithoutQuery = false;
3766
+ this._offlineOnlyItemIds = undefined;
3592
3767
  this.state.next(this.initialState);
3593
3768
  this.setIntervals([]);
3594
3769
  this.setActiveInterval(undefined);
@@ -329,15 +329,6 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
329
329
  protected _predefinedFilter: ParsedPredefinedFilterResponse | undefined;
330
330
  /** Metadata of the in-flight response, committed by `placeQueryPage` on a first page only. */
331
331
  private _pendingPredefinedFilter: ParsedPredefinedFilterResponse | undefined;
332
- /**
333
- * True while the loaded items came only from the offline cache (seeded by `setItems`, never
334
- * confirmed by a query). The seed's offset and query shape would make the next query a
335
- * continuation, but a cache has no pagination position, so `executeQuery` forces a first page that
336
- * keeps the items.
337
- */
338
- private _itemsLoadedFromOfflineDB = false;
339
- /** The query in flight refreshes a cache-only interval, so its response replaces the interval. */
340
- private _replaceOfflineSeedOnResponse = false;
341
332
  /** The query handed to the sync manager, from the cache read until it runs. See `executeQuery`. */
342
333
  private _queryAwaitingSync: ChannelQueryShape | undefined;
343
334
  /** The cids of the page the latest query returned, `undefined` when it failed. */
@@ -618,14 +609,6 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
618
609
  if (params.isFirstPage && params.results) {
619
610
  this.applyPredefinedFilterResponse(pendingPredefinedFilter);
620
611
  }
621
- const replaceOfflineSeed = this._replaceOfflineSeedOnResponse;
622
- this._replaceOfflineSeedOnResponse = false;
623
- if (replaceOfflineSeed && params.results) {
624
- // The cache can be arbitrarily old and hold channels the server dropped (hidden, deleted,
625
- // left): the page replaces the seed instead of merging into it.
626
- this.clearItemStorage();
627
- return super.placeQueryPage({ ...params, keepPreviousItems: false });
628
- }
629
612
  return super.placeQueryPage(params);
630
613
  }
631
614
 
@@ -770,8 +753,10 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
770
753
  }
771
754
  const { offlineDb } = this.client;
772
755
 
756
+ // Only the offline database's channels are shown (see `showsOfflinePage`): a cache has no
757
+ // pagination position, so the next query is a first page that keeps them until it lands.
773
758
  const effectiveParams: PaginationQueryParams<ChannelQueryShape> =
774
- this._itemsLoadedFromOfflineDB && params.reset !== 'yes'
759
+ this.showsOfflinePage && params.reset !== 'yes'
775
760
  ? { ...params, keepPreviousItems: true, reset: 'yes' as const }
776
761
  : params;
777
762
 
@@ -781,7 +766,7 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
781
766
  !!this.client.user?.id &&
782
767
  !offlineDb.syncManager.isSynced &&
783
768
  // A cache-seeded list is not a loaded one, so paginating it defers too.
784
- (this._itemsLoadedFromOfflineDB ||
769
+ (this.showsOfflinePage ||
785
770
  this.isFirstPageQuery({ queryShape, reset: effectiveParams.reset }));
786
771
 
787
772
  if (!shouldDeferUntilSynced) return await super.executeQuery(effectiveParams);
@@ -809,12 +794,10 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
809
794
  // the list's flags and loading state belong to the queries started since the reset
810
795
  if (checkWasStateResetDuringQuery()) return;
811
796
  if (cachedChannels?.length) {
812
- // Seed via `setItems`, which ingests the page into the interval/index storage.
813
797
  // TODO: Maybe find a better way to do this rather than 2 partialNext invocations
814
798
  // running. This all happens so fast it should never be noticeable but it's
815
799
  // a microoptimization.
816
- this.setItems({ valueOrFactory: cachedChannels, isFirstPage: true });
817
- this._itemsLoadedFromOfflineDB = true;
800
+ this.setItemsFromOfflineDb(cachedChannels);
818
801
  }
819
802
  // Nothing is in flight while waiting for the sync: `isLoading` would make `canExecuteQuery`
820
803
  // reject the query scheduled below.
@@ -824,7 +807,7 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
824
807
  const refreshParams: PaginationQueryParams<ChannelQueryShape> = {
825
808
  ...effectiveParams,
826
809
  keepPreviousItems: true,
827
- ...(this._itemsLoadedFromOfflineDB ? { reset: 'yes' as const } : {}),
810
+ ...(this.showsOfflinePage ? { reset: 'yes' as const } : {}),
828
811
  };
829
812
 
830
813
  // Already synced: the sync-status callback would never fire, so run the query now.
@@ -844,9 +827,6 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
844
827
  }: PaginationQueryParams<ChannelQueryShape> = {}): Promise<
845
828
  PaginationQueryReturnValue<Channel>
846
829
  > => {
847
- if (this._itemsLoadedFromOfflineDB) this._replaceOfflineSeedOnResponse = true;
848
- // A query is going out: the items stop being cache-only, whatever the response.
849
- this._itemsLoadedFromOfflineDB = false;
850
830
  const queryShape = preparedQueryShape ?? this.getNextQueryShape();
851
831
  const { stateOptions, ...request } = queryShape;
852
832
  const checkWasStateResetDuringQuery = this.makeStateResetWatcher();
@@ -1047,8 +1027,8 @@ export class ChannelPaginator extends BasePaginator<Channel, ChannelQueryShape>
1047
1027
  // `toTail()` there, and clearing afterwards would wipe what that query set.
1048
1028
  this._queryAwaitingSync = undefined;
1049
1029
  this._tailQueryAwaitingRecovery = false;
1050
- this._itemsLoadedFromOfflineDB = false;
1051
- this._replaceOfflineSeedOnResponse = false;
1030
+ // the offline page's flag (`showsOfflinePage`) is cleared by `super.resetState()` before it
1031
+ // publishes
1052
1032
  this._pendingPredefinedFilter = undefined;
1053
1033
  if (this._predefinedFilter) this.applyPredefinedFilterResponse(undefined);
1054
1034
  super.resetState();
@@ -1586,7 +1586,10 @@ export class MessageIntervalPaginator extends BasePaginator<
1586
1586
  ? await this.channel
1587
1587
  .getClient()
1588
1588
  .getReplies({ parent_id: this.parentMessageId }, pagination)
1589
- : await this.channel.query({ messages: pagination });
1589
+ : await this.channel.query({
1590
+ include_scheduled_messages: false,
1591
+ messages: pagination,
1592
+ });
1590
1593
  return Array.isArray(messages) && messages.length > 0;
1591
1594
  }
1592
1595
 
@@ -1862,6 +1865,16 @@ export class MessageIntervalPaginator extends BasePaginator<
1862
1865
  this.messageFocusSignal.next({ signal: null });
1863
1866
  };
1864
1867
 
1868
+ /**
1869
+ * Also drops the focus signal of an earlier jump. Whatever claims the active interval decides what
1870
+ * is shown, so the earlier target must not be scrolled to or highlighted there. A jump claims
1871
+ * before it emits its own signal, so it keeps that one.
1872
+ */
1873
+ protected override claimActiveInterval(): number {
1874
+ this.clearMessageFocusSignal();
1875
+ return super.claimActiveInterval();
1876
+ }
1877
+
1865
1878
  clearStateAndCache() {
1866
1879
  this.resetState();
1867
1880
  this._itemIndex.clear();