stream-chat 10.0.0-rc.21 → 10.0.0-rc.23

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 (269) hide show
  1. package/dist/cjs/index.browser.js +2196 -3902
  2. package/dist/cjs/index.browser.js.map +3 -3
  3. package/dist/cjs/index.node.js +2197 -3902
  4. package/dist/cjs/index.node.js.map +3 -3
  5. package/dist/esm/index.mjs +2199 -3905
  6. package/dist/esm/index.mjs.map +4 -4
  7. package/dist/types/ChannelManager.d.ts +120 -233
  8. package/dist/types/CooldownTimer.d.ts +8 -23
  9. package/dist/types/EventHandlerPipeline.d.ts +17 -37
  10. package/dist/types/LiveLocationManager.d.ts +22 -50
  11. package/dist/types/api-client.d.ts +9 -14
  12. package/dist/types/channel.d.ts +253 -448
  13. package/dist/types/channel_state.d.ts +48 -95
  14. package/dist/types/client.d.ts +245 -370
  15. package/dist/types/client_state.d.ts +1 -3
  16. package/dist/types/configuration/ConfigController.d.ts +30 -124
  17. package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +31 -123
  18. package/dist/types/configuration/keys.d.ts +5 -19
  19. package/dist/types/configuration/shape.d.ts +12 -29
  20. package/dist/types/configuration/types.d.ts +59 -87
  21. package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +13 -35
  22. package/dist/types/configuration/utils/copyConfigPatch.d.ts +8 -0
  23. package/dist/types/configuration/utils/declarativeSlices.d.ts +5 -16
  24. package/dist/types/configuration/utils/deepFreezeConfig.d.ts +3 -17
  25. package/dist/types/configuration/utils/serverAuthority.d.ts +9 -29
  26. package/dist/types/connection/ConnectionIdManager.d.ts +18 -40
  27. package/dist/types/connection/ConnectionRecoveryManager.d.ts +29 -120
  28. package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +32 -103
  29. package/dist/types/connection/networkConnection/reporters.d.ts +9 -32
  30. package/dist/types/connection/networkConnection/types.d.ts +12 -27
  31. package/dist/types/connection/wsConnection/StableWSConnection.d.ts +37 -116
  32. package/dist/types/connection/wsConnection/WSConnection.d.ts +41 -104
  33. package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +8 -16
  34. package/dist/types/connection/wsConnection/config.d.ts +8 -28
  35. package/dist/types/connection/wsConnection/types.d.ts +17 -70
  36. package/dist/types/entityStore/EntityStore.d.ts +153 -113
  37. package/dist/types/entityStore/StoreBackedItemIndex.d.ts +13 -46
  38. package/dist/types/errors.d.ts +7 -19
  39. package/dist/types/gen/chat/ChannelApi.d.ts +2 -1
  40. package/dist/types/gen/chat/ChatApi.d.ts +28 -14
  41. package/dist/types/gen/models/index.d.ts +769 -86
  42. package/dist/types/gen/moderation/ModerationApi.d.ts +4 -4
  43. package/dist/types/index.d.ts +2 -4
  44. package/dist/types/languageNames.d.ts +9 -24
  45. package/dist/types/logger.d.ts +1 -3
  46. package/dist/types/messageComposer/LocationComposer.d.ts +1 -1
  47. package/dist/types/messageComposer/attachmentIdentity.d.ts +1 -6
  48. package/dist/types/messageComposer/attachmentManager.d.ts +10 -32
  49. package/dist/types/messageComposer/attachmentUtils.d.ts +3 -14
  50. package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
  51. package/dist/types/messageComposer/configuration/types.d.ts +29 -56
  52. package/dist/types/messageComposer/linkPreviewsManager.d.ts +6 -9
  53. package/dist/types/messageComposer/messageComposer.d.ts +30 -164
  54. package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +4 -14
  55. package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +2 -9
  56. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +2 -4
  57. package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +7 -19
  58. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +9 -0
  59. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +11 -18
  60. package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
  61. package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
  62. package/dist/types/messageComposer/pollComposer.d.ts +8 -4
  63. package/dist/types/messageComposer/textComposer.d.ts +3 -9
  64. package/dist/types/messageComposer/types.d.ts +5 -8
  65. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +25 -79
  66. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +15 -82
  67. package/dist/types/messageOperations/FailedSendCache.d.ts +4 -9
  68. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +10 -20
  69. package/dist/types/messageOperations/MessageOperations.d.ts +20 -40
  70. package/dist/types/messageOperations/applyReactionLocally.d.ts +5 -22
  71. package/dist/types/messageOperations/createMessageOperations.d.ts +3 -5
  72. package/dist/types/messageOperations/reflectReactionEvent.d.ts +5 -13
  73. package/dist/types/messageOperations/sendOrdering.d.ts +4 -7
  74. package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +7 -15
  75. package/dist/types/messageOperations/types.d.ts +15 -30
  76. package/dist/types/middleware.d.ts +7 -5
  77. package/dist/types/moderation.d.ts +21 -14
  78. package/dist/types/notifications/NotificationManager.d.ts +8 -31
  79. package/dist/types/notifications/types.d.ts +19 -59
  80. package/dist/types/offline-support/offline_support_api.d.ts +145 -539
  81. package/dist/types/offline-support/offline_sync_manager.d.ts +18 -42
  82. package/dist/types/offline-support/queueableOperations.d.ts +24 -52
  83. package/dist/types/offline-support/types.d.ts +24 -187
  84. package/dist/types/pagination/ItemIndex.d.ts +4 -12
  85. package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +13 -0
  86. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -4
  87. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +2 -3
  88. package/dist/types/pagination/paginators/BasePaginator.d.ts +235 -622
  89. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +67 -125
  90. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +133 -292
  91. package/dist/types/pagination/paginators/MessagePaginator.d.ts +69 -118
  92. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +7 -26
  93. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +2 -2
  94. package/dist/types/pagination/paginators/ThreadPaginator.d.ts +15 -23
  95. package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +2 -6
  96. package/dist/types/pagination/sortCompiler.d.ts +11 -22
  97. package/dist/types/pagination/utility.normalization.d.ts +5 -23
  98. package/dist/types/pagination/utility.search.d.ts +3 -8
  99. package/dist/types/poll.d.ts +14 -14
  100. package/dist/types/poll_manager.d.ts +11 -2
  101. package/dist/types/poll_optimistic_votes.d.ts +10 -14
  102. package/dist/types/reminders/Reminder.d.ts +4 -4
  103. package/dist/types/reminders/ReminderManager.d.ts +7 -20
  104. package/dist/types/search/BaseSearchSource.d.ts +7 -12
  105. package/dist/types/search/ChannelSearchSource.d.ts +7 -7
  106. package/dist/types/search/MessageSearchSource.d.ts +7 -9
  107. package/dist/types/search/SearchController.d.ts +17 -22
  108. package/dist/types/search/types.d.ts +6 -10
  109. package/dist/types/signing.d.ts +12 -3
  110. package/dist/types/thread.d.ts +23 -71
  111. package/dist/types/thread_manager.d.ts +45 -70
  112. package/dist/types/token_manager.d.ts +8 -13
  113. package/dist/types/types.d.ts +64 -125
  114. package/dist/types/types.utility.d.ts +3 -3
  115. package/dist/types/upload-utils.d.ts +5 -10
  116. package/dist/types/uploadManager.d.ts +17 -45
  117. package/dist/types/utils/FixedSizeQueueCache.d.ts +6 -11
  118. package/dist/types/utils/WithSubscriptions.d.ts +5 -15
  119. package/dist/types/utils/concurrency.d.ts +11 -19
  120. package/dist/types/utils/mergeWith/mergeWith.d.ts +8 -11
  121. package/dist/types/utils/mergeWith/mergeWithCore.d.ts +5 -13
  122. package/dist/types/utils/mergeWith/mergeWithDiff.d.ts +22 -0
  123. package/dist/types/utils/objectPath.d.ts +6 -41
  124. package/dist/types/utils/retryable.d.ts +8 -12
  125. package/dist/types/utils/throttling/throttle.d.ts +8 -23
  126. package/dist/types/utils/time.d.ts +24 -64
  127. package/dist/types/utils.d.ts +40 -86
  128. package/package.json +7 -2
  129. package/src/ChannelManager.ts +159 -300
  130. package/src/CooldownTimer.ts +11 -29
  131. package/src/EventHandlerPipeline.ts +21 -44
  132. package/src/LiveLocationManager.ts +35 -74
  133. package/src/api-client.ts +43 -61
  134. package/src/campaign.ts +1 -1
  135. package/src/channel.ts +396 -749
  136. package/src/channel_batch_updater.ts +1 -1
  137. package/src/channel_state.ts +50 -105
  138. package/src/client.ts +360 -588
  139. package/src/client_state.ts +1 -6
  140. package/src/configuration/ConfigController.ts +41 -157
  141. package/src/configuration/InstanceConfigurationRegistry.ts +42 -171
  142. package/src/configuration/index.ts +1 -1
  143. package/src/configuration/keys.ts +13 -32
  144. package/src/configuration/shape.ts +67 -70
  145. package/src/configuration/types.ts +60 -100
  146. package/src/configuration/utils/applyInstanceConfiguration.ts +21 -53
  147. package/src/configuration/utils/copyConfigPatch.ts +11 -32
  148. package/src/configuration/utils/declarativeSlices.ts +9 -39
  149. package/src/configuration/utils/deepFreezeConfig.ts +3 -17
  150. package/src/configuration/utils/index.ts +2 -4
  151. package/src/configuration/utils/serverAuthority.ts +20 -68
  152. package/src/connection/ConnectionIdManager.ts +20 -49
  153. package/src/connection/ConnectionRecoveryManager.ts +51 -178
  154. package/src/connection/networkConnection/NetworkConnectionObserver.ts +37 -114
  155. package/src/connection/networkConnection/reporters.ts +9 -36
  156. package/src/connection/networkConnection/types.ts +12 -27
  157. package/src/connection/wsConnection/StableWSConnection.ts +73 -193
  158. package/src/connection/wsConnection/WSConnection.ts +56 -131
  159. package/src/connection/wsConnection/WSConnectionFallback.ts +22 -31
  160. package/src/connection/wsConnection/config.ts +13 -48
  161. package/src/connection/wsConnection/types.ts +17 -70
  162. package/src/constants.ts +4 -4
  163. package/src/entityStore/EntityStore.ts +162 -167
  164. package/src/entityStore/StoreBackedItemIndex.ts +14 -47
  165. package/src/errors.ts +7 -19
  166. package/src/formatMessageMemo.ts +3 -9
  167. package/src/gen/chat/ChannelApi.ts +19 -0
  168. package/src/gen/chat/ChatApi.ts +87 -13
  169. package/src/gen/models/index.ts +793 -71
  170. package/src/gen/moderation/ModerationApi.ts +0 -4
  171. package/src/index.ts +10 -14
  172. package/src/languageNames.ts +9 -24
  173. package/src/logger.ts +1 -3
  174. package/src/messageComposer/LocationComposer.ts +7 -23
  175. package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
  176. package/src/messageComposer/attachmentIdentity.ts +2 -13
  177. package/src/messageComposer/attachmentManager.ts +17 -63
  178. package/src/messageComposer/attachmentUtils.ts +3 -17
  179. package/src/messageComposer/configuration/configuration.ts +5 -8
  180. package/src/messageComposer/configuration/types.ts +29 -56
  181. package/src/messageComposer/fileUtils.ts +1 -1
  182. package/src/messageComposer/linkPreviewsManager.ts +8 -20
  183. package/src/messageComposer/messageComposer.ts +54 -222
  184. package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +4 -16
  185. package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +1 -2
  186. package/src/messageComposer/middleware/messageComposer/attachments.ts +14 -40
  187. package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +3 -4
  188. package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
  189. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +4 -11
  190. package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
  191. package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
  192. package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
  193. package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +1 -6
  194. package/src/messageComposer/middleware/textComposer/commandUtils.ts +1 -2
  195. package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
  196. package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
  197. package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
  198. package/src/messageComposer/middleware/textComposer/types.ts +1 -6
  199. package/src/messageComposer/pollComposer.ts +11 -8
  200. package/src/messageComposer/textComposer.ts +9 -59
  201. package/src/messageComposer/types.ts +9 -12
  202. package/src/messageDelivery/MessageDeliveryReporter.ts +60 -113
  203. package/src/messageDelivery/MessageReceiptsTracker.ts +21 -105
  204. package/src/messageOperations/FailedSendCache.ts +4 -9
  205. package/src/messageOperations/MessageOperationStatePolicy.ts +40 -67
  206. package/src/messageOperations/MessageOperations.ts +33 -62
  207. package/src/messageOperations/applyReactionLocally.ts +9 -28
  208. package/src/messageOperations/createMessageOperations.ts +17 -33
  209. package/src/messageOperations/reflectReactionEvent.ts +5 -13
  210. package/src/messageOperations/sendOrdering.ts +4 -7
  211. package/src/messageOperations/settlePendingAttachmentUploads.ts +10 -21
  212. package/src/messageOperations/types.ts +15 -30
  213. package/src/middleware.ts +7 -10
  214. package/src/moderation.ts +25 -21
  215. package/src/notifications/NotificationManager.ts +11 -35
  216. package/src/notifications/types.ts +19 -59
  217. package/src/offline-support/offline_support_api.ts +178 -608
  218. package/src/offline-support/offline_sync_manager.ts +25 -69
  219. package/src/offline-support/queueableOperations.ts +31 -84
  220. package/src/offline-support/types.ts +25 -188
  221. package/src/pagination/ItemIndex.ts +4 -12
  222. package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
  223. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +13 -62
  224. package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
  225. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +4 -6
  226. package/src/pagination/filterCompiler.ts +11 -25
  227. package/src/pagination/paginators/BasePaginator.ts +422 -976
  228. package/src/pagination/paginators/ChannelPaginator.ts +130 -190
  229. package/src/pagination/paginators/MessageIntervalPaginator.ts +226 -457
  230. package/src/pagination/paginators/MessagePaginator.ts +135 -175
  231. package/src/pagination/paginators/PinnedMessagePaginator.ts +13 -38
  232. package/src/pagination/paginators/ReminderPaginator.ts +12 -15
  233. package/src/pagination/paginators/ThreadPaginator.ts +16 -26
  234. package/src/pagination/paginators/UserGroupPaginator.ts +6 -17
  235. package/src/pagination/paginators/stateThrottling.ts +5 -10
  236. package/src/pagination/sortCompiler.ts +23 -50
  237. package/src/pagination/utility.normalization.ts +8 -30
  238. package/src/pagination/utility.search.ts +4 -11
  239. package/src/poll.ts +19 -19
  240. package/src/poll_manager.ts +16 -20
  241. package/src/poll_optimistic_votes.ts +17 -22
  242. package/src/reminders/Reminder.ts +5 -6
  243. package/src/reminders/ReminderManager.ts +9 -34
  244. package/src/reminders/ReminderTimer.ts +1 -2
  245. package/src/search/BaseSearchSource.ts +14 -29
  246. package/src/search/ChannelSearchSource.ts +8 -8
  247. package/src/search/MessageSearchSource.ts +19 -25
  248. package/src/search/SearchController.ts +18 -24
  249. package/src/search/types.ts +6 -10
  250. package/src/segment.ts +1 -1
  251. package/src/signing.ts +23 -3
  252. package/src/thread.ts +72 -173
  253. package/src/thread_manager.ts +59 -76
  254. package/src/token_manager.ts +11 -21
  255. package/src/types.ts +78 -126
  256. package/src/types.utility.ts +3 -3
  257. package/src/upload-utils.ts +5 -10
  258. package/src/uploadManager.ts +22 -54
  259. package/src/utils/FixedSizeQueueCache.ts +13 -21
  260. package/src/utils/WithSubscriptions.ts +5 -15
  261. package/src/utils/concurrency.ts +16 -55
  262. package/src/utils/mergeWith/mergeWith.ts +10 -13
  263. package/src/utils/mergeWith/mergeWithCore.ts +24 -81
  264. package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
  265. package/src/utils/objectPath.ts +6 -41
  266. package/src/utils/retryable.ts +10 -14
  267. package/src/utils/throttling/throttle.ts +9 -25
  268. package/src/utils/time.ts +26 -66
  269. package/src/utils.ts +72 -128
@@ -11,7 +11,8 @@ import {
11
11
  MessageIntervalPaginator,
12
12
  type MessageQueryShape,
13
13
  } from './MessageIntervalPaginator';
14
- import type { LocalMessage, TimestampNS } from '../../types';
14
+ import type { LocalMessage, TimestampNS, UserResponse } from '../../types';
15
+ import type { EntityStoreChangeBatch } from '../../entityStore/EntityStore';
15
16
  import { asTimestampNS, nsToDate } from '../../utils/time';
16
17
  import { StateStore } from '@stream-io/state-store';
17
18
 
@@ -30,44 +31,37 @@ export type {
30
31
  export { MessageIntervalPaginator } from './MessageIntervalPaginator';
31
32
 
32
33
  /**
33
- * Auxiliary (non-pagination) state for the message paginator: whole-collection aggregates that are
34
- * independent of the active pagination window (the dual of pagination — values over the entire set,
35
- * not a page of it). `lastMessageAt` is effectively `MAX(created_at)` over the channel-relevant
36
- * messages and is the source of truth for channel-list ordering
34
+ * Whole-collection aggregates, independent of the active pagination window. `lastMessageAt` is the
35
+ * max `created_at` over the channel-relevant messages and orders the channel list
37
36
  * (`channel.messagePaginator.lastMessageAt`): seeded from `ChannelResponse.last_message_at`, then
38
37
  * advanced monotonically as newer messages are ingested.
39
38
  */
40
39
  export type MessagePaginatorAggregateState = {
41
40
  /**
42
- * The newest channel-relevant message, for display (e.g. a channel/thread list item's last-message
43
- * preview or latest-reply avatar). A LIVE reference: it advances to a strictly newer message, is
44
- * refreshed in place when that message is edited/soft-deleted/reacted-to, and is recomputed to the
45
- * next newest when it is hard-removed. Respects `shouldAdvanceLastMessage` (skips system messages
46
- * per `skip_last_msg_update_for_system_msgs`, and thread-only replies). `null` until one is ingested.
41
+ * The newest channel-relevant message, for display (last-message preview, latest-reply avatar). A
42
+ * live reference: it advances to a strictly newer message, is refreshed in place on edit,
43
+ * soft-delete or reaction, and is recomputed when hard-removed. Follows `shouldAdvanceLastMessage`
44
+ * (skips system messages per `skip_last_msg_update_for_system_msgs`, and thread-only replies).
45
+ * `null` until one is ingested.
47
46
  *
48
- * Lives here, NOT derived from pagination `state`, so it stays reactive when a WS message lands in
49
- * the head interval while an older window is active — the pagination store only emits when the
50
- * active* interval is impacted (see `BasePaginator.ingestItem`), so a `state`-derived latest would
51
- * go stale in that case.
47
+ * It lives outside pagination `state`, which only emits when the active interval is affected: a
48
+ * message landing in the head interval while an older window is active would go stale there.
52
49
  */
53
50
  lastMessage: LocalMessage | null;
54
51
  /**
55
- * Server-provided `ChannelResponse.last_message_at` floor, for channels whose newest message is not
56
- * loaded (e.g. surfaced by a channel-list query). Kept SEPARATE from {@link lastMessage} so it can
57
- * outrank a stale/absent loaded message for sorting without overwriting the display message. The
58
- * sort key {@link MessagePaginator.lastMessageAt} is derived as the max of the two, so the two can
59
- * never drift out of sync.
52
+ * `ChannelResponse.last_message_at` floor, for channels whose newest message is not loaded. Kept
53
+ * apart from {@link lastMessage} so it can outrank a stale or absent loaded message for sorting
54
+ * without replacing the display message. {@link MessagePaginator.lastMessageAt} is the max of
55
+ * the two.
60
56
  */
61
57
  seededLastMessageAt: TimestampNS | null;
62
58
  };
63
59
 
64
60
  export type MessagePaginatorOptions = BaseMessagePaginatorOptions & {
65
61
  /**
66
- * Controls whether `jumpToTheFirstUnreadMessage()` should prefer the `unreadStateSnapshot`
67
- * state over `channel.state.read[...]`.
68
- *
69
- * - 'snapshot' (default): retrieve the first unread message id from the unreadStateSnapshot state when jumping to the first unread message
70
- * - 'read-state-only': retrieve the last read message id from the channel read state when jumping to the first unread message
62
+ * Where `jumpToTheFirstUnreadMessage()` reads the unread reference from: `'snapshot'`
63
+ * prefers `unreadStateSnapshot`, `'read-state-only'` uses only `channel.state.read[...]`.
64
+ * Defaults to `'snapshot'`.
71
65
  */
72
66
  unreadReferencePolicy?: 'snapshot' | 'read-state-only';
73
67
  };
@@ -76,34 +70,26 @@ export type UnreadSnapshotState = {
76
70
  lastReadAt: TimestampNS | null;
77
71
  unreadCount: number;
78
72
  /**
79
- * Snapshot of the first unread message id for the user.
80
- * This is intentionally decoupled from `channel.state.read[...]` because apps
81
- * may mark the channel read immediately on open, while still wanting to render
82
- * UI indicators that jump to the previously-unread location.
73
+ * First unread message ID. Decoupled from `channel.state.read[...]` because apps may mark the
74
+ * channel read on open yet still want UI that jumps to the previously unread location.
83
75
  */
84
76
  firstUnreadMessageId: string | null;
85
- /**
86
- * Snapshot of the last read message id for the user (fallback when first unread
87
- * is not known).
88
- */
77
+ /** Last read message ID, a fallback when the first unread is unknown. */
89
78
  lastReadMessageId: string | null;
90
79
  };
91
80
 
92
81
  /**
93
- * External, UI-driven signal: `true` while the user is actively viewing the latest messages of
94
- * this collection (app foregrounded AND the newest message on screen). The owning SDK sets it — the
95
- * state layer has no viewport. When live, an incoming message is NOT counted as unread (the count /
96
- * snapshot bump is skipped), so the "N new" separator/banner never flash for a message the user is
97
- * already looking at. Defaults to `false` (assume not viewing until the SDK proves otherwise).
82
+ * Set by the owning SDK (the state layer has no viewport): `true` while the user views the latest
83
+ * messages (app foregrounded and newest message on screen). While live, an incoming message does
84
+ * not bump the unread count or snapshot. Defaults to `false`.
98
85
  */
99
86
  export type LiveViewState = {
100
87
  isViewingLive: boolean;
101
88
  };
102
89
 
103
90
  /**
104
- * MessagePaginator extends {@link MessageIntervalPaginator} with the unread/live-view concern:
105
- * an independent unread reference snapshot, the UI-driven "viewing the latest messages" signal, and
106
- * the "jump to first unread" navigation built on top of them.
91
+ * Adds the unread snapshot, the UI-driven live-view signal and "jump to first unread" navigation to
92
+ * {@link MessageIntervalPaginator}.
107
93
  */
108
94
  export class MessagePaginator extends MessageIntervalPaginator {
109
95
  protected get holderName() {
@@ -111,22 +97,19 @@ export class MessagePaginator extends MessageIntervalPaginator {
111
97
  }
112
98
  private unreadReferencePolicy: 'snapshot' | 'read-state-only';
113
99
  /**
114
- * Independent unread reference state (not tied to `channel.state.read`).
115
- * Consumers may set this right before calling markRead / when opening a channel.
100
+ * Unread reference state, independent of `channel.state.read`. Seeded on each first page;
101
+ * consumers may also set it before `markRead`.
116
102
  */
117
103
  readonly unreadStateSnapshot: StateStore<UnreadSnapshotState>;
118
104
  /**
119
- * UI-driven "viewing the latest messages" signal (see {@link LiveViewState}). Set by the SDK via
120
- * {@link setViewingLive}; read by the channel to gate the unread bump on `message.new`. Subscribe to
121
- * this store for reactivity, or read the current boolean directly via the {@link isViewingLive} getter.
105
+ * The "viewing the latest messages" signal ({@link LiveViewState}), set via {@link setViewingLive}
106
+ * and read by the channel to gate the unread bump on `message.new`.
122
107
  */
123
108
  readonly liveViewState: StateStore<LiveViewState>;
124
109
  /**
125
- * Auxiliary (non-pagination) state — see {@link MessagePaginatorAggregateState}. A store separate
126
- * from `state` so `lastMessageAt` can be advanced from inside a `state.next` updater
127
- * (`ingestPage`) without being clobbered, and so consumers subscribe to a quiet signal that only
128
- * emits when the aggregate actually changes (not on every scroll/pagination emission). This is
129
- * distinct from the base's `intervalViews` interval-projection store.
110
+ * {@link MessagePaginatorAggregateState}, in a store apart from `state` so `lastMessageAt` can
111
+ * advance from inside a `state.next` updater (`ingestPage`) and subscribers only see aggregate
112
+ * changes.
130
113
  */
131
114
  readonly aggregateState: StateStore<MessagePaginatorAggregateState>;
132
115
 
@@ -134,21 +117,14 @@ export class MessagePaginator extends MessageIntervalPaginator {
134
117
  { unreadReferencePolicy = 'snapshot', ...options }: MessagePaginatorOptions,
135
118
  builtInDefaults: Partial<BasePaginatorConfig<LocalMessage, MessageQueryShape>> = {},
136
119
  ) {
137
- super(
138
- // NB: the store-backed item index is provided by MessageIntervalPaginator (the common
139
- // ancestor), so both the main list and the pinned list share the client-global message store.
140
- options,
141
- {
142
- // Throttle message-list `state` publishes to at most once per 500ms (leading + trailing), so a
143
- // burst of events coalesces into ~2 renders/sec instead of one per event. Optimistic
144
- // (local-user) writes bypass the throttle via EntityStore.flushSubscribers → flushState.
145
- // A default rather than a construction argument, so `paginatorOptions.stateThrottleMs` and a
146
- // declarative registration both override it — and so a re-derivation restores it without the
147
- // subclass having to re-inject it, which is what the old `initializeConfig` override existed for.
148
- stateThrottleMs: 500,
149
- ...builtInDefaults,
150
- },
151
- );
120
+ super(options, {
121
+ // Coalesce live `state.items` publishes to one per 500ms (leading + trailing). Optimistic
122
+ // (local-user) writes bypass it via `EntityStore.flushSubscribers`. A default, so
123
+ // `stateThrottleMs` options and declarative registrations override it and a re-derivation
124
+ // restores it.
125
+ stateThrottleMs: 500,
126
+ ...builtInDefaults,
127
+ });
152
128
  this.unreadReferencePolicy = unreadReferencePolicy;
153
129
  this.unreadStateSnapshot = new StateStore<UnreadSnapshotState>({
154
130
  lastReadAt: null,
@@ -167,8 +143,7 @@ export class MessagePaginator extends MessageIntervalPaginator {
167
143
 
168
144
  /**
169
145
  * Channel-list sort key: the later of the newest loaded message's `created_at` and the server seed.
170
- * **Derived** (never stored) so it cannot drift from {@link lastMessage}. `null` until seeded or a
171
- * message is ingested.
146
+ * Derived, so it cannot drift from {@link lastMessage}. `null` until seeded or a message arrives.
172
147
  */
173
148
  get lastMessageAt(): TimestampNS | null {
174
149
  const { lastMessage, seededLastMessageAt } = this.aggregateState.getLatestValue();
@@ -180,24 +155,18 @@ export class MessagePaginator extends MessageIntervalPaginator {
180
155
  }
181
156
 
182
157
  /**
183
- * The newest channel-relevant message (the monotonic tracked latest), for display. Convenience read
184
- * of {@link aggregateState}; subscribe to `aggregateState` for reactivity. `null` until a message is
185
- * ingested (a server-only seed advances {@link lastMessageAt} but leaves this `null`).
158
+ * The tracked newest channel-relevant message ({@link aggregateState}), for display. `null` until
159
+ * one is ingested (a server-only seed advances {@link lastMessageAt} but not this).
186
160
  */
187
161
  get lastMessage(): LocalMessage | null {
188
162
  return this.aggregateState.getLatestValue().lastMessage;
189
163
  }
190
164
 
191
165
  /**
192
- * The main channel list's notion of "latest message" for `channel.state.last_message_at`: on top of
193
- * the base rule (not shadowed) this excludes thread-only replies (a reply with a `parent_id` that is
194
- * not shown in the channel is not part of the channel list) and, when the channel is configured with
195
- * `skip_last_msg_update_for_system_msgs`, system messages. Mirrors the legacy
196
- * `Channel._trackLastMessage` skip logic.
197
- *
198
- * These exclusions are specific to the MAIN channel list. A reply list (thread paginator, which has
199
- * a `parentMessageId`) is made ENTIRELY of thread replies — there the newest reply is exactly the
200
- * "latest message", so the exclusions are skipped and only the base rule applies.
166
+ * Whether `message` may become the "latest message" behind `channel.state.last_message_at`: not
167
+ * shadowed and, in the main list, not a thread-only reply nor (with
168
+ * `skip_last_msg_update_for_system_msgs`) a system message. A reply list (`parentMessageId` set)
169
+ * holds only thread replies, so only the shadow rule applies there.
201
170
  */
202
171
  protected shouldAdvanceLastMessage(message: LocalMessage): boolean {
203
172
  if (message.shadowed) return false;
@@ -211,31 +180,24 @@ export class MessagePaginator extends MessageIntervalPaginator {
211
180
  }
212
181
 
213
182
  /**
214
- * Monotonically advance {@link lastMessageAt} to `message.created_at` when it is newer than the
215
- * current value and {@link shouldAdvanceLastMessage} permits it. Writes the dedicated
216
- * {@link aggregateState} store (not `state`), so it is safe to call from inside a `state.next`
217
- * updater (`ingestPage`). Returns `true` when the value moved.
218
- *
219
- * Called internally on ingest; also public for callers that advance the aggregate without a normal
220
- * in-window ingest — e.g. offline pending-message replay, where the sent message has not yet been
221
- * ingested via the `message.new` event.
183
+ * Advances the tracked latest message (and so {@link lastMessageAt}) to `message` when it is newer
184
+ * and {@link shouldAdvanceLastMessage} permits. Writes {@link aggregateState} only, so it is safe
185
+ * inside a `state.next` updater (`ingestPage`). Returns `true` when the value moved. Public for
186
+ * callers that advance it without an in-window ingest, e.g. offline pending-message replay.
222
187
  */
223
188
  trackLastMessage(message: LocalMessage): boolean {
224
189
  if (!this.shouldAdvanceLastMessage(message)) return false;
225
190
  const incoming = getMessageCreatedAtTimestamp(message);
226
191
  if (incoming === null) return false;
227
192
  const current = this.aggregateState.getLatestValue().lastMessage;
228
- // Refresh in place when this IS the current latest being updated — an edit, soft-delete,
229
- // reaction, or quoted-message update all re-ingest the same id (same `created_at`). This keeps
230
- // `lastMessage` a LIVE reference (so a preview shows "deleted"/edited text), and because
231
- // `aggregateState` emits regardless of the active interval, it stays reactive off-window.
193
+ // An edit, soft-delete, reaction or quote update re-ingests the current latest (same ID and
194
+ // `created_at`): refresh it in place so `lastMessage` stays live.
232
195
  if (current && current.id === message.id) {
233
196
  this.aggregateState.partialNext({ lastMessage: message });
234
197
  return true;
235
198
  }
236
- // Otherwise only advance to a strictly newer message. Guard against the current message's own
237
- // timestamp — NOT `lastMessageAt` (which the server seed can inflate); otherwise a seed newer than
238
- // the loaded window would reject the very message it was derived from.
199
+ // Otherwise only a strictly newer message advances. Compare against the current message's own
200
+ // timestamp, not `lastMessageAt`: a seed newer than the loaded window would reject the message.
239
201
  const currentTs = current ? getMessageCreatedAtTimestamp(current) : null;
240
202
  if (currentTs !== null && incoming <= currentTs) return false;
241
203
  this.aggregateState.partialNext({ lastMessage: message });
@@ -243,9 +205,8 @@ export class MessagePaginator extends MessageIntervalPaginator {
243
205
  }
244
206
 
245
207
  /**
246
- * Seed {@link lastMessageAt} from the server-provided `ChannelResponse.last_message_at`, the
247
- * authoritative whole-channel aggregate. Monotonic: a no-op when the paginator already advanced
248
- * past it (e.g. from ingested messages), so seed order does not matter.
208
+ * Seeds {@link lastMessageAt} from `ChannelResponse.last_message_at`. Monotonic: a value not newer
209
+ * than the current seed is ignored, so seed order does not matter.
249
210
  */
250
211
  seedLastMessageAt(value: TimestampNS | null | undefined) {
251
212
  if (value == null || !Number.isFinite(value)) return;
@@ -255,9 +216,7 @@ export class MessagePaginator extends MessageIntervalPaginator {
255
216
  }
256
217
 
257
218
  ingestItem(item: LocalMessage): boolean {
258
- // Only items that survive the filter advance the aggregate (`ingestItem` also handles removals
259
- // of items that no longer match). The advance writes the separate `aggregateState` store, so it
260
- // is independent of `super`'s `state`/index mutations.
219
+ // Only items passing the filter advance the aggregate (`ingestItem` also removes the others).
261
220
  if (this.matchesFilter(item)) {
262
221
  this.trackLastMessage(item);
263
222
  }
@@ -268,39 +227,76 @@ export class MessagePaginator extends MessageIntervalPaginator {
268
227
  params: Parameters<MessageIntervalPaginator['ingestPage']>[0],
269
228
  ): Interval | null {
270
229
  const interval = super.ingestPage(params);
271
- // Advance from each page item; the monotonic max over the page yields the newest. Comparison is
272
- // by `created_at` against `aggregateState` (no index lookup), so order vs `super` is irrelevant.
273
230
  if (params.page?.length) {
274
231
  for (const item of params.page) this.trackLastMessage(item);
275
232
  }
276
233
  return interval;
277
234
  }
278
235
 
236
+ onEntitiesChanged(batch: EntityStoreChangeBatch) {
237
+ super.onEntitiesChanged(batch);
238
+ const { lastMessage } = this.aggregateState.getLatestValue();
239
+ if (!lastMessage || !batch.changedIds.has(lastMessage.id)) return;
240
+ const stored = this.getItem(lastMessage.id);
241
+ if (stored) this.aggregateState.partialNext({ lastMessage: stored });
242
+ }
243
+
244
+ reflectUserUpdate(user: UserResponse) {
245
+ super.reflectUserUpdate(user);
246
+ const { lastMessage } = this.aggregateState.getLatestValue();
247
+ if (lastMessage?.user?.id !== user.id) return;
248
+ this.aggregateState.partialNext({ lastMessage: { ...lastMessage, user } });
249
+ }
250
+
279
251
  removeItem(
280
252
  params: Parameters<MessageIntervalPaginator['removeItem']>[0],
281
253
  ): ReturnType<MessageIntervalPaginator['removeItem']> {
282
254
  const removedId =
283
255
  params.id ?? (params.item ? this.getItemId(params.item) : undefined);
284
- const wasLatest =
285
- !!removedId && this.aggregateState.getLatestValue().lastMessage?.id === removedId;
256
+ const { lastMessage, seededLastMessageAt } = this.aggregateState.getLatestValue();
257
+ const wasLatest = !!removedId && lastMessage?.id === removedId;
286
258
  const result = super.removeItem(params);
287
259
  if (wasLatest) {
288
- // The tracked latest was hard-removed; fall back to the newest still-loaded message that
289
- // passes the filter. `trackLastMessage` cannot do this (it only advances), so recompute here.
290
- this.aggregateState.partialNext({ lastMessage: this.recomputeLastMessage() });
260
+ // The tracked latest was hard-removed: recompute it, since `trackLastMessage` only advances.
261
+ const previous = this.recomputeLastMessage();
262
+ const previousAt = getMessageCreatedAtTimestamp(previous);
263
+ const removedAt = getMessageCreatedAtTimestamp(lastMessage);
264
+ const isSeedFromRemovedMessage =
265
+ seededLastMessageAt !== null &&
266
+ removedAt !== null &&
267
+ seededLastMessageAt <= removedAt;
268
+ // The server moves `last_message_at` back to the previous message without sending it, so the
269
+ // seed takes the previous loaded message's time. With none loaded the new value is unknown,
270
+ // and the seed stays.
271
+ this.aggregateState.partialNext({
272
+ lastMessage: previous,
273
+ seededLastMessageAt:
274
+ isSeedFromRemovedMessage && previousAt !== null
275
+ ? previousAt
276
+ : seededLastMessageAt,
277
+ });
291
278
  }
292
279
  return result;
293
280
  }
294
281
 
282
+ truncate(params: Parameters<MessageIntervalPaginator['truncate']>[0]) {
283
+ super.truncate(params);
284
+ const { lastMessage, seededLastMessageAt } = this.aggregateState.getLatestValue();
285
+ const isTruncated = (timestamp: TimestampNS | null) =>
286
+ timestamp !== null && timestamp < params.truncatedAt;
287
+ const isLastMessageTruncated = isTruncated(getMessageCreatedAtTimestamp(lastMessage));
288
+ const isSeedTruncated = isTruncated(seededLastMessageAt);
289
+ if (!isLastMessageTruncated && !isSeedTruncated) return;
290
+ this.aggregateState.partialNext({
291
+ lastMessage: isLastMessageTruncated ? this.recomputeLastMessage() : lastMessage,
292
+ seededLastMessageAt: isSeedTruncated ? null : seededLastMessageAt,
293
+ });
294
+ }
295
+
295
296
  /**
296
- * The still-loaded message with the greatest `created_at` that passes
297
- * {@link shouldAdvanceLastMessage} (skips system / thread-only per config), from the newest-loaded
298
- * window. Used to recompute the tracked latest after the current one is removed. `null` when nothing
299
- * loaded qualifies.
300
- *
301
- * "Latest" is defined by `created_at` (matching {@link trackLastMessage}), NOT by the paginator's
302
- * display order — so this compares timestamps rather than assuming a position, and stays correct
303
- * whatever `itemOrder` / `requestSort` are configured to.
297
+ * The message in `headItems` with the greatest `created_at` that passes
298
+ * {@link shouldAdvanceLastMessage}, or `null`. It compares timestamps rather than positions, so it
299
+ * holds for any `itemOrder` / `requestSort`.
304
300
  */
305
301
  private recomputeLastMessage(): LocalMessage | null {
306
302
  let latest: LocalMessage | null = null;
@@ -316,23 +312,16 @@ export class MessagePaginator extends MessageIntervalPaginator {
316
312
  }
317
313
 
318
314
  /**
319
- * (Re)seed the unread state snapshot from the current own read state.
315
+ * (Re)seeds the unread snapshot from the own read state. Runs after the first-page query, and the
316
+ * SDK calls it again when a channel is reopened from a cached paginator (no first-page query), so
317
+ * the separator, unread count and jump target follow the current read boundary.
320
318
  *
321
- * Called after the first-page query, and can be called again by the SDK whenever a channel is
322
- * (re)opened from a cached paginator — where no fresh first-page query runs — so the snapshot
323
- * reflects the CURRENT read boundary rather than one frozen at the very first open. Without a
324
- * re-seed the separator position, unread count and "jump to first unread" target all go stale
325
- * across reopens.
326
- *
327
- * `firstUnreadMessageId` is intentionally reset to `null`: it represents an EXPLICIT mark-unread
328
- * (set by `notification.mark_unread`), not a live/computed boundary. Persisting a computed value
329
- * here would make the channel look explicitly marked-unread and suppress auto-mark-read.
319
+ * `firstUnreadMessageId` is reset to `null`: it holds only an explicit mark-unread
320
+ * (`notification.mark_unread`), and a computed value would suppress auto-mark-read.
330
321
  */
331
322
  seedUnreadSnapshot = () => {
332
- // A paginator query (BasePaginator.executeQuery) awaits the network before running its
333
- // synchronous postQueryReconcile, which calls this on the first page. If the channel was
334
- // disconnected (`disconnect()`) while that request was in flight, reading the client below
335
- // throws, so guard against that.
323
+ // The query awaits the network before this runs: the channel may be pending disposal by then,
324
+ // and `getClient()` throws.
336
325
  if (this.channel.pendingDisposal) return;
337
326
  const ownUserId = this.channel.getClient().user?.id;
338
327
  const ownReadState = ownUserId ? this.channel.state.read[ownUserId] : undefined;
@@ -345,11 +334,7 @@ export class MessagePaginator extends MessageIntervalPaginator {
345
334
  });
346
335
  };
347
336
 
348
- /**
349
- * Invokes super.postQueryReconcile() and takes an unread state snapshot on the first-page query.
350
- * The snapshot has to be taken immediately after the query as the viewed channel is marked read
351
- * immediately after opening it. The snapshot can be used to display unread UI indicators.
352
- */
337
+ /** Also seeds the unread snapshot on a first page, before the opened channel is marked read. */
353
338
  postQueryReconcile(
354
339
  params: PostQueryReconcileParams<LocalMessage, MessageQueryShape>,
355
340
  ): ExecuteQueryReturnValue<LocalMessage> {
@@ -362,22 +347,17 @@ export class MessagePaginator extends MessageIntervalPaginator {
362
347
  }
363
348
 
364
349
  /**
365
- * Jumps to the unread reference message.
366
- *
367
- * IMPORTANT: This intentionally does *not* rely on `channel.state.read[ownUserId]` only,
368
- * because apps may mark a channel read immediately after opening it, while still
369
- * wanting to keep "jump to unread" UI indicators alive (based on a snapshot).
350
+ * Jumps to the unread reference message. It does not rely on `channel.state.read` alone, since
351
+ * apps may mark a channel read on open yet keep "jump to unread" UI alive from the snapshot.
370
352
  *
371
353
  * Resolution order:
372
- * 1) explicit first-unread id from snapshot/read-state (mark-unread) — jump straight to it
373
- * 2) last-read timestamp: infer the FIRST UNREAD message from it — using the already-loaded
374
- * window when it straddles the boundary, otherwise a `created_at_around` query — and jump there
375
- * 3) last read id from snapshot/read-state (last-resort fallback when no timestamp is available)
354
+ * 1. an explicit first-unread ID (snapshot or read state): jump to it;
355
+ * 2. the last-read timestamp: infer the first unread message from the loaded window, or from a
356
+ * `created_at_around` query when the window does not straddle the boundary, and jump to it;
357
+ * 3. the last-read ID, when no timestamp is known.
376
358
  *
377
- * The timestamp inference (2) is preferred over jumping to the last-read id so that the jump lands
378
- * ON (and highlights) the first unread message rather than the last read one. The last-read id is
379
- * only used as a fallback when we cannot infer an unread boundary. The inference is NOT persisted
380
- * back into the snapshot (that is reserved for explicit mark-unread).
359
+ * The inference is not written to the snapshot: `firstUnreadMessageId` is reserved for an explicit
360
+ * mark-unread (it would suppress auto-mark-read).
381
361
  */
382
362
  jumpToTheFirstUnreadMessage = async (options?: JumpToMessageOptions) => {
383
363
  const ownUserId = this.channel.getClient().user?.id;
@@ -396,8 +376,6 @@ export class MessagePaginator extends MessageIntervalPaginator {
396
376
  const lastReadAtFromReadState = ownReadState?.last_read ?? null;
397
377
  const lastReadIdFromReadState = ownReadState?.last_read_message_id ?? null;
398
378
 
399
- // 1) A stable first-unread id is known (mark-unread, or a previously persisted inference):
400
- // jump straight to it.
401
379
  const firstUnreadMessageId = firstUnreadFromSnapshot ?? firstUnreadFromReadState;
402
380
  if (firstUnreadMessageId) {
403
381
  return await this.jumpToMessage(firstUnreadMessageId, {
@@ -407,24 +385,11 @@ export class MessagePaginator extends MessageIntervalPaginator {
407
385
  }
408
386
 
409
387
  const lastReadMessageId = lastReadIdFromSnapshot ?? lastReadIdFromReadState;
410
- // Prefer the SNAPSHOT timestamp over the fresh read-state one. The snapshot is the frozen UI
411
- // boundary the "N new" separator/banner render from, so a banner tap must jump to where that
412
- // indicator points. On (re)open the SDK marks the channel read (`markReadOnMount`) which advances
413
- // the read-state `last_read` to ~now and clears the server unread — so preferring read-state
414
- // would make a later banner tap infer "nothing unread" and jump to the latest message. The
415
- // snapshot is kept fresh on genuine catch-up (the SDK's mark-read resets it), so it is only
416
- // "frozen" precisely while there are unreads to jump to.
388
+ // The snapshot timestamp wins over the read state's: the snapshot is the frozen boundary the
389
+ // "N new" banner renders from, while mark-read on open advances the read state to ~now, so a
390
+ // banner tap would infer nothing unread and jump to the latest message.
417
391
  const lastReadAt = lastReadAtFromSnapshot ?? lastReadAtFromReadState;
418
392
 
419
- // 2) No explicit first-unread id, but we know when the channel was last read. Infer the first
420
- // unread message from that timestamp so we land ON (and highlight) the first unread message
421
- // instead of the last read one. Prefer the already-loaded window (the common "a few unreads at
422
- // the bottom" case — no extra request); only query a page around last-read when the loaded
423
- // window does not straddle the boundary (i.e. every loaded message is newer than last-read).
424
- //
425
- // We deliberately do NOT persist the inferred boundary back into the snapshot: writing
426
- // `firstUnreadMessageId` would make the channel look explicitly marked-unread and suppress
427
- // auto-mark-read at the bottom. The separator reads the (re-seeded) snapshot directly.
428
393
  const lastReadBoundary =
429
394
  lastReadAt != null && Number.isFinite(lastReadAt) ? lastReadAt : null;
430
395
 
@@ -442,7 +407,7 @@ export class MessagePaginator extends MessageIntervalPaginator {
442
407
  queryShape: {
443
408
  // `created_at_around` is a request field and still takes a `Date`.
444
409
  created_at_around: nsToDate(lastReadBoundary),
445
- limit: options?.pageSize,
410
+ limit: options?.pageSize ?? this.pageSize,
446
411
  },
447
412
  updateState: false,
448
413
  });
@@ -467,7 +432,6 @@ export class MessagePaginator extends MessageIntervalPaginator {
467
432
  }
468
433
  }
469
434
 
470
- // 3) Last resort: jump to the known last-read message when that is all we have.
471
435
  if (lastReadMessageId) {
472
436
  return await this.jumpToMessage(lastReadMessageId, {
473
437
  ...options,
@@ -483,18 +447,14 @@ export class MessagePaginator extends MessageIntervalPaginator {
483
447
  return this.unreadStateSnapshot.getLatestValue();
484
448
  };
485
449
 
486
- /**
487
- * Set the UI-driven "viewing the latest messages" signal (see {@link LiveViewState}). Called by
488
- * the SDK from its message-list viewability + app-state tracking. No-ops when unchanged.
489
- *
490
- * Intentionally NOT reset by `clearStateAndCache` — it is an external input owned by the SDK, not
491
- * derived pagination state.
492
- */
493
- /** Current "viewing the latest messages" boolean (convenience read of {@link liveViewState}). */
494
450
  get isViewingLive(): boolean {
495
451
  return this.liveViewState.getLatestValue().isViewingLive;
496
452
  }
497
453
 
454
+ /**
455
+ * Sets the live-view signal ({@link LiveViewState}). Not reset by `clearStateAndCache`: it is an
456
+ * external input owned by the SDK.
457
+ */
498
458
  setViewingLive = (isViewingLive: boolean) => {
499
459
  if (this.isViewingLive === isViewingLive) return;
500
460
  this.liveViewState.next({ isViewingLive });
@@ -33,23 +33,12 @@ export type PinnedMessagePaginatorOptions = {
33
33
  const PINNED_AT_SORT: SortParamRequest[] = [{ field: 'pinned_at', direction: 1 }];
34
34
 
35
35
  /**
36
- * Pinned-message list paginator.
36
+ * The channel's pinned messages, ordered by `pinned_at` ascending (oldest-pinned first). Extends
37
+ * {@link MessageIntervalPaginator} rather than {@link MessagePaginator}: pinned messages are a subset
38
+ * of the channel and take no part in read/unread or delivery-receipt tracking.
37
39
  *
38
- * Extends the unread-free {@link MessageIntervalPaginator} base — pinned messages are a subset of
39
- * the channel and MUST NOT participate in read/unread or delivery-receipt tracking (that belongs to
40
- * the channel and thread message timelines). By extending the base rather than {@link MessagePaginator}
41
- * it simply never gets the unread surface.
42
- *
43
- * Differences from the main list:
44
- * - fetches from the `/pinned_messages` endpoint (`channel.getPinnedMessages`) rather than
45
- * `channel.query({ messages })`;
46
- * - includes only pinned, non-shadowed messages (`shouldIncludeMessageInInterval`), and filters on
47
- * `{ cid, pinned: true }` so `ingestItem` auto-adds on pin and auto-removes on unpin;
48
- * - orders by `pinned_at` ascending (oldest-pinned first), matching the legacy
49
- * `channel.state.pinnedMessages` order.
50
- *
51
- * Navigation (`jumpToMessage` / `jumpToTheLatestMessage`) is inherited and meaningful — the endpoint
52
- * supports `id_around` — but no unread-coupled navigation exists.
40
+ * Fetches through `channel.getPinnedMessages`, includes only pinned, non-shadowed messages and
41
+ * matches `{ cid, pinned: true }`, so `ingestItem` adds on pin and removes on unpin.
53
42
  */
54
43
  export class PinnedMessagePaginator extends MessageIntervalPaginator {
55
44
  protected get holderName() {
@@ -65,9 +54,7 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
65
54
  super({
66
55
  channel,
67
56
  id: id ?? `pinned-message-paginator-${generateUUIDv4()}`,
68
- // No explicit index: inherit the store-backed item index from MessageIntervalPaginator so a
69
- // pinned message shares the single canonical copy with the main list / thread and reflects
70
- // reactions & edits applied elsewhere. A caller may still inject a custom `itemIndex`.
57
+ // Omitted: the inherited store-backed index shares one copy of each message with the main list.
71
58
  itemIndex,
72
59
  paginatorOptions,
73
60
  });
@@ -75,11 +62,7 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
75
62
  this.installPinnedMessageBehaviour();
76
63
  }
77
64
 
78
- /**
79
- * Memoized for the reason {@link MessageIntervalPaginator}'s overlay is: the base derivation folds
80
- * this in and skips the publish when nothing moved, which needs stable references. Both close over
81
- * `this` and over a fixed `pinned_at` sort, so there is nothing to rebuild.
82
- */
65
+ /** Memoized: stable references let the base derivation skip a publish when nothing moved. */
83
66
  private pinnedBehaviour?: Partial<BasePaginatorConfig<LocalMessage, MessageQueryShape>>;
84
67
 
85
68
  private buildPinnedBehaviour(): Partial<
@@ -93,9 +76,8 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
93
76
  tiebreaker: this.pinnedTiebreaker,
94
77
  }),
95
78
 
96
- // Fetch from the pinned-messages endpoint. The base `query` feeds the resolved query shape
97
- // (including `id_around` jumps) here as `options`; we return both cursors and let the base gate
98
- // them by direction.
79
+ // The base `query` passes the resolved shape (including `id_around` jumps) as `options`.
80
+ // Both cursors are returned and the base gates them by direction.
99
81
  doRequest: async (
100
82
  options: MessageQueryShape,
101
83
  ): Promise<{ cursor?: PaginatorCursor; items: LocalMessage[] }> => {
@@ -117,11 +99,7 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
117
99
  return leftId < rightId ? -1 : leftId > rightId ? 1 : 0;
118
100
  };
119
101
 
120
- /**
121
- * The ordering and request behaviour that makes this a *pinned*-message paginator, contributed to the
122
- * base derivation so a re-derivation cannot drop it and does not need a second write to restore it.
123
- * Spread over the interval overlay, so this class's `pinned_at` comparator wins.
124
- */
102
+ /** Adds the pinned ordering and request behaviour to the derivation, over the interval overlay. */
125
103
  protected override getBehaviourOverrides(): Partial<
126
104
  BasePaginatorConfig<LocalMessage, MessageQueryShape>
127
105
  > {
@@ -129,12 +107,9 @@ export class PinnedMessagePaginator extends MessageIntervalPaginator {
129
107
  }
130
108
 
131
109
  private installPinnedMessageBehaviour(): void {
132
- // Order by pinned_at (ascending), overriding the base's created_at comparators. Ascending keeps
133
- // the head edge (most-recently-pinned) at the end of an interval, matching the base's interval
134
- // direction getters (which are shared with created_at-asc semantics).
135
- //
136
- // A plain field rather than config, so a re-derivation never touches it — which is why only the
137
- // constructor sets it.
110
+ // Ascending `pinned_at` keeps the head edge (most recently pinned) at the end of an interval,
111
+ // like the base's `created_at` ascending. A plain field rather than config, so a re-derivation
112
+ // never touches it and only the constructor sets it.
138
113
  this.sortComparator = makeComparator<LocalMessage>({
139
114
  sort: PINNED_AT_SORT,
140
115
  resolvePathValue: resolveDotPathValue,