stream-chat 10.0.0-rc.9 → 10.0.1

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 (361) hide show
  1. package/README.md +7 -6
  2. package/dist/cjs/index.browser.js +21653 -19788
  3. package/dist/cjs/index.browser.js.map +4 -4
  4. package/dist/cjs/index.node.js +21693 -19796
  5. package/dist/cjs/index.node.js.map +4 -4
  6. package/dist/esm/index.mjs +21651 -19786
  7. package/dist/esm/index.mjs.map +4 -4
  8. package/dist/types/ChannelManager.d.ts +216 -135
  9. package/dist/types/CooldownTimer.d.ts +13 -27
  10. package/dist/types/EventHandlerPipeline.d.ts +18 -38
  11. package/dist/types/LiveLocationManager.d.ts +24 -52
  12. package/dist/types/api-client.d.ts +17 -5
  13. package/dist/types/channel.d.ts +432 -470
  14. package/dist/types/channel_state.d.ts +68 -112
  15. package/dist/types/client.d.ts +321 -435
  16. package/dist/types/client_state.d.ts +1 -3
  17. package/dist/types/configuration/ConfigController.d.ts +31 -125
  18. package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +32 -124
  19. package/dist/types/configuration/keys.d.ts +5 -19
  20. package/dist/types/configuration/shape.d.ts +12 -29
  21. package/dist/types/configuration/types.d.ts +64 -79
  22. package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +14 -36
  23. package/dist/types/configuration/utils/copyConfigPatch.d.ts +8 -0
  24. package/dist/types/configuration/utils/declarativeSlices.d.ts +5 -16
  25. package/dist/types/configuration/utils/deepFreezeConfig.d.ts +3 -17
  26. package/dist/types/configuration/utils/serverAuthority.d.ts +9 -29
  27. package/dist/types/connection/ConnectionIdManager.d.ts +45 -0
  28. package/dist/types/connection/ConnectionRecoveryManager.d.ts +84 -0
  29. package/dist/types/connection/index.d.ts +4 -0
  30. package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +82 -0
  31. package/dist/types/connection/networkConnection/index.d.ts +3 -0
  32. package/dist/types/connection/networkConnection/reporters.d.ts +20 -0
  33. package/dist/types/connection/networkConnection/types.d.ts +40 -0
  34. package/dist/types/connection/wsConnection/StableWSConnection.d.ts +137 -0
  35. package/dist/types/connection/wsConnection/WSConnection.d.ts +105 -0
  36. package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +47 -0
  37. package/dist/types/connection/wsConnection/config.d.ts +31 -0
  38. package/dist/types/connection/wsConnection/index.d.ts +4 -0
  39. package/dist/types/connection/wsConnection/types.d.ts +46 -0
  40. package/dist/types/constants.d.ts +2 -0
  41. package/dist/types/custom_types.d.ts +0 -2
  42. package/dist/types/entityStore/EntityStore.d.ts +226 -65
  43. package/dist/types/entityStore/StoreBackedItemIndex.d.ts +19 -33
  44. package/dist/types/entityStore/index.d.ts +0 -1
  45. package/dist/types/errors.d.ts +16 -19
  46. package/dist/types/formatMessageMemo.d.ts +5 -0
  47. package/dist/types/gen/chat/ChannelApi.d.ts +5 -1
  48. package/dist/types/gen/chat/ChatApi.d.ts +149 -105
  49. package/dist/types/gen/models/index.d.ts +2528 -690
  50. package/dist/types/gen/models/timestamp-guard.d.ts +22 -0
  51. package/dist/types/gen/moderation/ModerationApi.d.ts +33 -14
  52. package/dist/types/index.d.ts +10 -6
  53. package/dist/types/{i18n/languageNames.d.ts → languageNames.d.ts} +9 -24
  54. package/dist/types/logger.d.ts +1 -3
  55. package/dist/types/messageComposer/CustomDataManager.d.ts +7 -1
  56. package/dist/types/messageComposer/LocationComposer.d.ts +7 -1
  57. package/dist/types/messageComposer/attachmentIdentity.d.ts +24 -0
  58. package/dist/types/messageComposer/attachmentManager.d.ts +52 -24
  59. package/dist/types/messageComposer/attachmentUtils.d.ts +23 -0
  60. package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
  61. package/dist/types/messageComposer/configuration/types.d.ts +38 -50
  62. package/dist/types/messageComposer/index.d.ts +1 -0
  63. package/dist/types/messageComposer/linkPreviewsManager.d.ts +12 -9
  64. package/dist/types/messageComposer/messageComposer.d.ts +60 -128
  65. package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +10 -1
  66. package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +4 -0
  67. package/dist/types/messageComposer/middleware/messageComposer/commandInjection.d.ts +5 -0
  68. package/dist/types/messageComposer/middleware/messageComposer/index.d.ts +2 -0
  69. package/dist/types/messageComposer/middleware/messageComposer/pollOnly.d.ts +6 -0
  70. package/dist/types/messageComposer/middleware/messageComposer/userDataInjection.d.ts +5 -0
  71. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +2 -4
  72. package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +7 -19
  73. package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +4 -0
  74. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +11 -2
  75. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +19 -18
  76. package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
  77. package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
  78. package/dist/types/messageComposer/pollComposer.d.ts +15 -5
  79. package/dist/types/messageComposer/textComposer.d.ts +14 -7
  80. package/dist/types/messageComposer/types.d.ts +27 -7
  81. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +27 -80
  82. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +40 -73
  83. package/dist/types/messageOperations/FailedSendCache.d.ts +29 -0
  84. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +16 -22
  85. package/dist/types/messageOperations/MessageOperations.d.ts +63 -34
  86. package/dist/types/messageOperations/applyReactionLocally.d.ts +15 -0
  87. package/dist/types/messageOperations/createMessageOperations.d.ts +9 -0
  88. package/dist/types/messageOperations/index.d.ts +6 -4
  89. package/dist/types/messageOperations/reflectReactionEvent.d.ts +16 -0
  90. package/dist/types/messageOperations/sendOrdering.d.ts +14 -0
  91. package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +20 -0
  92. package/dist/types/messageOperations/types.d.ts +43 -14
  93. package/dist/types/middleware.d.ts +10 -0
  94. package/dist/types/moderation.d.ts +21 -14
  95. package/dist/types/notifications/NotificationManager.d.ts +10 -23
  96. package/dist/types/notifications/types.d.ts +21 -57
  97. package/dist/types/offline-support/offline_support_api.d.ts +150 -528
  98. package/dist/types/offline-support/offline_sync_manager.d.ts +21 -42
  99. package/dist/types/offline-support/queueableOperations.d.ts +35 -37
  100. package/dist/types/offline-support/types.d.ts +40 -186
  101. package/dist/types/pagination/FilterBuilder.d.ts +1 -18
  102. package/dist/types/pagination/ItemIndex.d.ts +4 -12
  103. package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +13 -0
  104. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +4 -5
  105. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +19 -5
  106. package/dist/types/pagination/index.d.ts +1 -0
  107. package/dist/types/pagination/paginators/BasePaginator.d.ts +604 -550
  108. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +123 -106
  109. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +576 -334
  110. package/dist/types/pagination/paginators/MessagePaginator.d.ts +239 -131
  111. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +15 -26
  112. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +4 -3
  113. package/dist/types/pagination/paginators/ThreadPaginator.d.ts +44 -0
  114. package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +5 -8
  115. package/dist/types/pagination/paginators/index.d.ts +1 -0
  116. package/dist/types/pagination/sortCompiler.d.ts +11 -22
  117. package/dist/types/pagination/utility.normalization.d.ts +5 -23
  118. package/dist/types/pagination/utility.search.d.ts +3 -8
  119. package/dist/types/poll.d.ts +34 -8
  120. package/dist/types/poll_manager.d.ts +12 -2
  121. package/dist/types/poll_optimistic_votes.d.ts +57 -0
  122. package/dist/types/reminders/Reminder.d.ts +11 -11
  123. package/dist/types/reminders/ReminderManager.d.ts +13 -25
  124. package/dist/types/search/BaseSearchSource.d.ts +10 -8
  125. package/dist/types/search/ChannelSearchSource.d.ts +16 -0
  126. package/dist/types/search/MessageSearchSource.d.ts +17 -0
  127. package/dist/types/search/SearchController.d.ts +26 -28
  128. package/dist/types/search/types.d.ts +6 -10
  129. package/dist/types/signing.d.ts +12 -3
  130. package/dist/types/thread.d.ts +63 -129
  131. package/dist/types/thread_manager.d.ts +95 -66
  132. package/dist/types/token_manager.d.ts +8 -13
  133. package/dist/types/types.d.ts +81 -199
  134. package/dist/types/types.utility.d.ts +3 -3
  135. package/dist/types/upload-utils.d.ts +5 -10
  136. package/dist/types/uploadManager.d.ts +31 -11
  137. package/dist/types/utils/FixedSizeQueueCache.d.ts +8 -11
  138. package/dist/types/utils/WithSubscriptions.d.ts +6 -16
  139. package/dist/types/utils/abort.d.ts +17 -0
  140. package/dist/types/utils/concurrency.d.ts +12 -20
  141. package/dist/types/utils/mergeWith/mergeWith.d.ts +8 -11
  142. package/dist/types/utils/mergeWith/mergeWithCore.d.ts +5 -13
  143. package/dist/types/utils/mergeWith/mergeWithDiff.d.ts +22 -0
  144. package/dist/types/utils/objectPath.d.ts +6 -41
  145. package/dist/types/utils/retryable.d.ts +8 -12
  146. package/dist/types/utils/throttling/throttle.d.ts +8 -23
  147. package/dist/types/utils/time.d.ts +33 -57
  148. package/dist/types/utils.d.ts +72 -91
  149. package/package.json +14 -40
  150. package/src/ChannelManager.ts +494 -303
  151. package/src/CooldownTimer.ts +28 -38
  152. package/src/EventHandlerPipeline.ts +22 -45
  153. package/src/LiveLocationManager.ts +37 -76
  154. package/src/api-client.ts +113 -50
  155. package/src/campaign.ts +1 -1
  156. package/src/channel.ts +1067 -1276
  157. package/src/channel_batch_updater.ts +1 -1
  158. package/src/channel_state.ts +73 -168
  159. package/src/client.ts +744 -974
  160. package/src/client_state.ts +3 -8
  161. package/src/configuration/ConfigController.ts +42 -158
  162. package/src/configuration/InstanceConfigurationRegistry.ts +43 -172
  163. package/src/configuration/index.ts +1 -1
  164. package/src/configuration/keys.ts +13 -32
  165. package/src/configuration/shape.ts +169 -59
  166. package/src/configuration/types.ts +69 -92
  167. package/src/configuration/utils/applyInstanceConfiguration.ts +22 -54
  168. package/src/configuration/utils/copyConfigPatch.ts +11 -32
  169. package/src/configuration/utils/declarativeSlices.ts +9 -39
  170. package/src/configuration/utils/deepFreezeConfig.ts +3 -17
  171. package/src/configuration/utils/index.ts +2 -4
  172. package/src/configuration/utils/serverAuthority.ts +20 -68
  173. package/src/connection/ConnectionIdManager.ts +111 -0
  174. package/src/connection/ConnectionRecoveryManager.ts +257 -0
  175. package/src/connection/index.ts +4 -0
  176. package/src/connection/networkConnection/NetworkConnectionObserver.ts +204 -0
  177. package/src/connection/networkConnection/index.ts +3 -0
  178. package/src/connection/networkConnection/reporters.ts +58 -0
  179. package/src/connection/networkConnection/types.ts +45 -0
  180. package/src/{connection.ts → connection/wsConnection/StableWSConnection.ts} +230 -232
  181. package/src/connection/wsConnection/WSConnection.ts +270 -0
  182. package/src/connection/wsConnection/WSConnectionFallback.ts +250 -0
  183. package/src/connection/wsConnection/config.ts +73 -0
  184. package/src/connection/wsConnection/index.ts +4 -0
  185. package/src/connection/wsConnection/types.ts +48 -0
  186. package/src/constants.ts +6 -5
  187. package/src/custom_types.ts +0 -1
  188. package/src/entityStore/EntityStore.ts +415 -79
  189. package/src/entityStore/StoreBackedItemIndex.ts +37 -41
  190. package/src/entityStore/index.ts +0 -1
  191. package/src/errors.ts +39 -20
  192. package/src/formatMessageMemo.ts +17 -0
  193. package/src/gen/chat/ChannelApi.ts +122 -36
  194. package/src/gen/chat/ChatApi.ts +578 -1540
  195. package/src/gen/models/index.ts +2498 -3383
  196. package/src/gen/models/timestamp-guard.ts +27 -0
  197. package/src/gen/moderation/ModerationApi.ts +170 -367
  198. package/src/index.ts +22 -10
  199. package/src/languageNames.ts +88 -0
  200. package/src/logger.ts +1 -3
  201. package/src/messageComposer/CustomDataManager.ts +19 -6
  202. package/src/messageComposer/LocationComposer.ts +19 -23
  203. package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
  204. package/src/messageComposer/attachmentIdentity.ts +54 -0
  205. package/src/messageComposer/attachmentManager.ts +170 -185
  206. package/src/messageComposer/attachmentUtils.ts +44 -0
  207. package/src/messageComposer/configuration/configuration.ts +15 -8
  208. package/src/messageComposer/configuration/types.ts +38 -50
  209. package/src/messageComposer/fileUtils.ts +1 -1
  210. package/src/messageComposer/index.ts +1 -0
  211. package/src/messageComposer/linkPreviewsManager.ts +18 -21
  212. package/src/messageComposer/messageComposer.ts +223 -174
  213. package/src/messageComposer/middleware/attachmentManager/postUpload/AttachmentPostUploadMiddlewareExecutor.ts +1 -1
  214. package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +46 -33
  215. package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +4 -1
  216. package/src/messageComposer/middleware/attachmentManager/preUpload/blockedUploadNotification.ts +1 -1
  217. package/src/messageComposer/middleware/messageComposer/MessageComposerMiddlewareExecutor.ts +6 -0
  218. package/src/messageComposer/middleware/messageComposer/attachments.ts +76 -5
  219. package/src/messageComposer/middleware/messageComposer/commandInjection.ts +10 -4
  220. package/src/messageComposer/middleware/messageComposer/customData.ts +17 -5
  221. package/src/messageComposer/middleware/messageComposer/index.ts +2 -0
  222. package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +22 -12
  223. package/src/messageComposer/middleware/messageComposer/pollOnly.ts +9 -1
  224. package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
  225. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +12 -12
  226. package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
  227. package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
  228. package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
  229. package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +8 -6
  230. package/src/messageComposer/middleware/textComposer/commandUtils.ts +10 -3
  231. package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
  232. package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
  233. package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
  234. package/src/messageComposer/middleware/textComposer/types.ts +1 -6
  235. package/src/messageComposer/pollComposer.ts +21 -9
  236. package/src/messageComposer/textComposer.ts +37 -57
  237. package/src/messageComposer/types.ts +39 -11
  238. package/src/messageDelivery/MessageDeliveryReporter.ts +86 -125
  239. package/src/messageDelivery/MessageReceiptsTracker.ts +88 -101
  240. package/src/messageOperations/FailedSendCache.ts +85 -0
  241. package/src/messageOperations/MessageOperationStatePolicy.ts +121 -112
  242. package/src/messageOperations/MessageOperations.ts +297 -175
  243. package/src/{entityStore → messageOperations}/applyReactionLocally.ts +9 -28
  244. package/src/messageOperations/createMessageOperations.ts +176 -0
  245. package/src/messageOperations/index.ts +6 -14
  246. package/src/messageOperations/reflectReactionEvent.ts +43 -0
  247. package/src/messageOperations/sendOrdering.ts +25 -0
  248. package/src/messageOperations/settlePendingAttachmentUploads.ts +98 -0
  249. package/src/messageOperations/types.ts +51 -13
  250. package/src/middleware.ts +13 -5
  251. package/src/moderation.ts +25 -21
  252. package/src/notifications/NotificationManager.ts +19 -28
  253. package/src/notifications/types.ts +21 -57
  254. package/src/offline-support/offline_support_api.ts +226 -669
  255. package/src/offline-support/offline_sync_manager.ts +51 -80
  256. package/src/offline-support/queueableOperations.ts +98 -73
  257. package/src/offline-support/types.ts +43 -186
  258. package/src/pagination/FilterBuilder.ts +1 -22
  259. package/src/pagination/ItemIndex.ts +4 -12
  260. package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
  261. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +15 -63
  262. package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
  263. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +53 -33
  264. package/src/pagination/filterCompiler.ts +11 -25
  265. package/src/pagination/index.ts +1 -0
  266. package/src/pagination/paginators/BasePaginator.ts +1415 -1041
  267. package/src/pagination/paginators/ChannelPaginator.ts +479 -217
  268. package/src/pagination/paginators/MessageIntervalPaginator.ts +1351 -772
  269. package/src/pagination/paginators/MessagePaginator.ts +518 -233
  270. package/src/pagination/paginators/PinnedMessagePaginator.ts +32 -40
  271. package/src/pagination/paginators/ReminderPaginator.ts +21 -16
  272. package/src/pagination/paginators/ThreadPaginator.ts +170 -0
  273. package/src/pagination/paginators/UserGroupPaginator.ts +16 -19
  274. package/src/pagination/paginators/index.ts +1 -0
  275. package/src/pagination/paginators/stateThrottling.ts +5 -10
  276. package/src/pagination/sortCompiler.ts +23 -50
  277. package/src/pagination/utility.normalization.ts +8 -30
  278. package/src/pagination/utility.search.ts +4 -11
  279. package/src/poll.ts +177 -98
  280. package/src/poll_manager.ts +24 -22
  281. package/src/poll_optimistic_votes.ts +335 -0
  282. package/src/reminders/Reminder.ts +16 -12
  283. package/src/reminders/ReminderManager.ts +22 -55
  284. package/src/reminders/ReminderTimer.ts +1 -2
  285. package/src/search/BaseSearchSource.ts +19 -25
  286. package/src/search/ChannelSearchSource.ts +43 -1
  287. package/src/search/MessageSearchSource.ts +77 -13
  288. package/src/search/SearchController.ts +39 -36
  289. package/src/search/types.ts +6 -10
  290. package/src/segment.ts +1 -1
  291. package/src/signing.ts +23 -3
  292. package/src/thread.ts +418 -703
  293. package/src/thread_manager.ts +300 -234
  294. package/src/token_manager.ts +12 -22
  295. package/src/types.ts +102 -216
  296. package/src/types.utility.ts +3 -3
  297. package/src/upload-utils.ts +5 -10
  298. package/src/uploadManager.ts +64 -18
  299. package/src/utils/FixedSizeQueueCache.ts +18 -21
  300. package/src/utils/WithSubscriptions.ts +6 -16
  301. package/src/utils/abort.ts +45 -0
  302. package/src/utils/concurrency.ts +16 -55
  303. package/src/utils/mergeWith/mergeWith.ts +10 -13
  304. package/src/utils/mergeWith/mergeWithCore.ts +24 -81
  305. package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
  306. package/src/utils/objectPath.ts +6 -41
  307. package/src/utils/retryable.ts +10 -14
  308. package/src/utils/throttling/throttle.ts +9 -25
  309. package/src/utils/time.ts +40 -60
  310. package/src/utils.ts +181 -174
  311. package/codegen/i18n/callSites.ts +0 -126
  312. package/codegen/i18n/generate.ts +0 -226
  313. package/codegen/i18n/guards.ts +0 -178
  314. package/codegen/i18n/index.ts +0 -29
  315. package/codegen/i18n/stringMaps.ts +0 -91
  316. package/codegen/i18n/types.ts +0 -100
  317. package/dist/cjs/i18n.browser.js +0 -1131
  318. package/dist/cjs/i18n.browser.js.map +0 -7
  319. package/dist/cjs/i18n.node.js +0 -1160
  320. package/dist/cjs/i18n.node.js.map +0 -7
  321. package/dist/esm/i18n-codegen.mjs +0 -409
  322. package/dist/esm/i18n-codegen.mjs.map +0 -7
  323. package/dist/esm/i18n.mjs +0 -1098
  324. package/dist/esm/i18n.mjs.map +0 -7
  325. package/dist/types/ConnectionRecoveryManager.d.ts +0 -156
  326. package/dist/types/connection.d.ts +0 -139
  327. package/dist/types/entityStore/applyReactionLocally.d.ts +0 -32
  328. package/dist/types/i18n/Streami18n.d.ts +0 -168
  329. package/dist/types/i18n/TranslationBuilder.d.ts +0 -70
  330. package/dist/types/i18n/TranslationStore.d.ts +0 -57
  331. package/dist/types/i18n/dayjs.d.ts +0 -104
  332. package/dist/types/i18n/formatters.d.ts +0 -91
  333. package/dist/types/i18n/index.d.ts +0 -15
  334. package/dist/types/i18n/translator.d.ts +0 -29
  335. package/dist/types/i18n/types.d.ts +0 -262
  336. package/dist/types/i18n-codegen/callSites.d.ts +0 -10
  337. package/dist/types/i18n-codegen/generate.d.ts +0 -15
  338. package/dist/types/i18n-codegen/guards.d.ts +0 -61
  339. package/dist/types/i18n-codegen/index.d.ts +0 -29
  340. package/dist/types/i18n-codegen/stringMaps.d.ts +0 -14
  341. package/dist/types/i18n-codegen/types.d.ts +0 -94
  342. package/dist/types/insights.d.ts +0 -56
  343. package/dist/types/messageOperations/optimistic.d.ts +0 -118
  344. package/dist/types/messageOperations/persistence.d.ts +0 -21
  345. package/dist/types/pagination/utility.queryChannel.d.ts +0 -26
  346. package/dist/types/store.d.ts +0 -125
  347. package/src/ConnectionRecoveryManager.ts +0 -293
  348. package/src/i18n/Streami18n.ts +0 -520
  349. package/src/i18n/TranslationBuilder.ts +0 -176
  350. package/src/i18n/TranslationStore.ts +0 -96
  351. package/src/i18n/dayjs.ts +0 -228
  352. package/src/i18n/formatters.ts +0 -461
  353. package/src/i18n/index.ts +0 -15
  354. package/src/i18n/languageNames.ts +0 -103
  355. package/src/i18n/translator.ts +0 -76
  356. package/src/i18n/types.ts +0 -375
  357. package/src/insights.ts +0 -82
  358. package/src/messageOperations/optimistic.ts +0 -257
  359. package/src/messageOperations/persistence.ts +0 -40
  360. package/src/pagination/utility.queryChannel.ts +0 -84
  361. package/src/store.ts +0 -304
@@ -1,8 +1,9 @@
1
- import type { BasePaginatorConfig, PaginationDirection, PaginationQueryParams, PaginatorState } from './BasePaginator';
1
+ import type { BasePaginatorConfig, DoRequestResponse, ExecuteQueryReturnValue, Interval, PaginationDirection, PaginationQueryParams, PaginatorState, QueryPagePlacement } from './BasePaginator';
2
2
  import { BasePaginator, type PaginationQueryReturnValue, type PaginatorOptions } from './BasePaginator';
3
- import type { LocalMessage, MessagePaginationParams, MessageResponse, PinnedMessagePaginationOptions, ReactionResponse, SortParamRequest, UserResponse } from '../../types';
3
+ import type { ChannelStateResponse, GetRepliesResponse, LocalMessage, MessagePaginationParams, PinnedMessagePaginationOptions, SortParamRequest, StreamResponse, TimestampNS, UserResponse } from '../../types';
4
4
  import type { Channel } from '../../channel';
5
- import { StateStore } from '../../store';
5
+ import type { Thread } from '../../thread';
6
+ import { StateStore } from '@stream-io/state-store';
6
7
  import type { ItemIndexApi } from '../ItemIndex';
7
8
  import type { EntityStoreChangeBatch } from '../../entityStore/EntityStore';
8
9
  export type MessageFocusReason = 'jump-to-message' | 'jump-to-first-unread' | 'jump-to-latest';
@@ -18,20 +19,19 @@ export type MessageFocusSignalState = {
18
19
  };
19
20
  export type JumpToMessageOptions = {
20
21
  pageSize?: number;
21
- /**
22
- * Optional reason attached to emitted focus signal.
23
- * Defaults to `jump-to-message`.
24
- */
22
+ /** Reason attached to the emitted focus signal. Defaults to `jump-to-message`. */
25
23
  focusReason?: MessageFocusReason;
26
- /**
27
- * TTL for the emitted focus signal in milliseconds.
28
- * Defaults to `3000`.
29
- */
24
+ /** TTL of the emitted focus signal in milliseconds. Defaults to `3000`. */
30
25
  focusSignalTtlMs?: number;
26
+ /** Suppresses the focus signal after a successful jump. */
27
+ suppressFocusSignal?: boolean;
31
28
  /**
32
- * If true, suppresses focus signal emission after a successful jump.
29
+ * Also watches the channel (so it receives events) when it is not watched yet. The request that
30
+ * loads the interval around the message asks to watch too, so it stays one request, and a message
31
+ * already loaded is loaded again. Ignored for a thread's reply list (its request cannot watch)
32
+ * and when the paginator's `doRequest` loads the messages.
33
33
  */
34
- suppressFocusSignal?: boolean;
34
+ watchChannel?: boolean;
35
35
  };
36
36
  export type MessagePaginatorSort = SortParamRequest[];
37
37
  export type MessagePaginatorFilter = {
@@ -40,164 +40,177 @@ export type MessagePaginatorFilter = {
40
40
  };
41
41
  export type MessagePaginatorState = PaginatorState<LocalMessage>;
42
42
  export type MessageQueryShape = MessagePaginationParams | PinnedMessagePaginationOptions;
43
- /**
44
- * A message's `created_at` as the comparable wire timestamp (unix nanoseconds), or `null` when it
45
- * is absent or not a finite number.
46
- *
47
- * Accepts `null`/`undefined` so callers holding an optional message (e.g.
48
- * `MessagePaginator.lastMessage`) do not each repeat the guard.
49
- */
50
- export declare const getMessageCreatedAtTimestamp: (message: LocalMessage | null | undefined) => number | null;
43
+ /** A message's `created_at` (unix nanoseconds), or `null` when absent or not finite. */
44
+ export declare const getMessageCreatedAtTimestamp: (message: LocalMessage | null | undefined) => TimestampNS | null;
51
45
  export type MessagePaginatorOptions = {
52
46
  channel: Channel;
53
47
  id?: string;
54
48
  itemIndex?: ItemIndexApi<LocalMessage>;
55
49
  parentMessageId?: string;
56
- /**
57
- * Sort passed to backend message/replies query.
58
- * Does not affect in-memory item ordering.
59
- */
50
+ /** Sort sent to the backend messages/replies query. Does not affect in-memory ordering. */
60
51
  requestSort?: MessagePaginatorSort;
61
52
  /**
62
53
  * @deprecated Use `requestSort` instead.
63
54
  */
64
55
  sort?: MessagePaginatorSort;
65
- /**
66
- * In-memory ordering for items exposed by paginator state.
67
- */
56
+ /** In-memory ordering of the items exposed by paginator state. */
68
57
  itemOrder?: MessagePaginatorSort;
58
+ /** The thread whose replies this paginator lists; without it, it lists the channel's messages. */
59
+ thread?: Thread;
69
60
  paginatorOptions?: PaginatorOptions<LocalMessage, MessageQueryShape>;
70
61
  };
71
62
  /**
72
- * Options for {@link MessageIntervalPaginator.mergeNewestPage} that enable destructive
73
- * reconciliation — removing messages that were hard-deleted (by anyone) while the client was
74
- * offline. A hard delete emits no event to other clients, and the merge is otherwise additive, so
75
- * without this such a message lingers as a ghost after reconnect.
76
- *
77
- * Throughout, `page` is the newest window the server returned for `mergeNewestPage`, and "`page`'s
78
- * newest / oldest message" are its bounds by `created_at`. With NO options, `mergeNewestPage` prunes
79
- * any loaded message that falls WITHIN `page`'s `created_at` span but is absent from it —
80
- * unconditionally safe (a message that arrived live during the caller's fetch is always strictly
81
- * newer than `page`'s newest message, so it can never fall in that span). `candidateIds` widens the
82
- * reconcilable window at the TOP edge; `requestedLimit` only tunes the `hasMoreTail` affordance and
83
- * can never remove a message:
63
+ * Options for {@link MessageIntervalPaginator.reconcileNewestMessages} that enable reconciling
64
+ * messages hard-deleted while the client received no events (no event reaches other clients). With
65
+ * no options it prunes loaded messages inside `page`'s `created_at` span that are absent from it,
66
+ * which is always safe: a live arrival is newer than `page`'s newest message.
67
+ * `headIntervalItemIdsAtRequest` widens reconciliation at the top edge; `requestedLimit` says
68
+ * whether the page reached the channel start.
84
69
  */
85
- export type MergeNewestPageOptions = {
86
- /**
87
- * The `limit` the caller passed to the query that produced `page`. Used ONLY to derive
88
- * `hasMoreTail` — whether `page` reached the channel's own oldest message — by comparing it to
89
- * `page.length`. It NEVER removes a message (reconciliation stays window-only regardless), so the
90
- * worst a wrong value can do is show/hide the "load older" affordance for one settle. Trusted only
91
- * when no larger than the paginator's own `pageSize` (see
92
- * {@link MessageIntervalPaginator.pageReachedChannelStart}); a larger over-request — e.g.
93
- * `channel.reload` re-fetching the whole loaded window to reconcile as much as possible — may have
94
- * been silently server-capped, so its short page is ignored rather than mistaken for reaching the
95
- * start.
70
+ export type ReconcileNewestMessagesOptions = {
71
+ /**
72
+ * The `limit` the caller passed to the query that produced `page`. Compared to `page.length`, it
73
+ * says whether `page` reached the channel start (see
74
+ * {@link MessageIntervalPaginator.pageReachedChannelStart}, which ignores a limit above
75
+ * `pageSize`), deciding `hasMoreTail`, whether `page` can be separated from the head interval by
76
+ * a gap, and whether a reload asks the server about messages deleted below the page (see
77
+ * {@link MessageIntervalPaginator.removeIdsTailwardOfPageIfNothingOlder}). On its own it never
78
+ * removes a message. Pass the limit actually sent: a larger one makes a short page look like the
79
+ * channel start, welding it to the head interval across a real gap.
96
80
  */
97
81
  requestedLimit?: number;
98
82
  /**
99
- * A snapshot of the loaded message ids taken BEFORE the caller's fetch await. Required to prune
100
- * messages NEWER than `page`'s newest message (a hard-deleted newest message) and to reconcile an
101
- * empty `page` (a fully-emptied channel): at/above that top edge a just-deleted message and a
102
- * message that arrived live during the fetch are indistinguishable by timestamp — only the pre-fetch
103
- * snapshot separates them (a live arrival is not in it). Must be captured before the await; the
104
- * paginator's own items at merge time already include any live arrival.
83
+ * The IDs of the head interval's server-confirmed items when the request for `page` went out,
84
+ * taken with {@link MessageIntervalPaginator.getHeadIntervalItemIdsAtRequest} before the request
85
+ * is awaited. Only these prove what `page` says about the head interval:
86
+ *
87
+ * - deletion: at or above `page`'s newest message, and for an empty `page`, only this snapshot
88
+ * tells a just-deleted message from one that arrived live, or was sent, during the request;
89
+ * - contiguity: `page` starts inside the head interval only if its oldest message the head
90
+ * interval could hold is in this snapshot (see `isSeparatedFromHeadByGap`).
91
+ *
92
+ * Only the head interval receives live messages, so only its IDs are needed.
105
93
  */
106
- candidateIds?: ReadonlySet<string>;
94
+ headIntervalItemIdsAtRequest?: ReadonlySet<string>;
95
+ };
96
+ /** An external query prepared by {@link MessageIntervalPaginator.prepareExternalQuery}. */
97
+ export type PreparedExternalQuery = {
98
+ messagePaginationParams: MessagePaginationParams;
99
+ isNewestPage: boolean;
100
+ placePage: (page: LocalMessage[]) => boolean;
107
101
  };
108
102
  /**
109
- * Options for {@link MessageIntervalPaginator.seedFirstPageSync}, the synchronous channel-open seed.
103
+ * What one of the message paginator's own queries got back, before its page is extracted (see
104
+ * {@link MessageIntervalPaginator.fetchQueryResponse}), by where it came from.
110
105
  */
111
- export type SeedFirstPageOptions = {
112
- /**
113
- * When true and the paginator has already been seeded once, fold the fresh page via
114
- * {@link MessageIntervalPaginator.mergeNewestPage} — merge in place, reconcile offline hard-deletes,
115
- * re-derive the tail cursor, rebuild on a disjoint window, and skip when jumped away from the head —
116
- * instead of a plain first-page ingest. Lets callers (channel.reload, the channel-list hydrate,
117
- * connection recovery) share one reconciling seed path. Left false for the differently-sorted
118
- * pinned list, and a no-op on a cold open (nothing loaded to fold).
119
- */
120
- reconcile?: boolean;
121
- /**
122
- * Pre-fetch snapshot of loaded message ids (captured before the caller's network await), forwarded
123
- * to {@link MergeNewestPageOptions.candidateIds} so a hard-deleted NEWEST message is reconciled
124
- * without mistaking a message that arrived live during the fetch for a delete. Only consulted when
125
- * {@link reconcile} is set and a window is already loaded.
126
- */
127
- candidateIds?: ReadonlySet<string>;
106
+ export type MessageQueryResponse = {
107
+ /** what a custom `doRequest` returned: the page, used as is */
108
+ doRequestResponse: DoRequestResponse<LocalMessage>;
109
+ source: 'doRequest';
110
+ } | {
111
+ /** the replies endpoint's response for a thread's reply list */
112
+ repliesResponse: GetRepliesResponse;
113
+ source: 'replies';
114
+ } | {
115
+ /** the response of a channel query: its messages, and the rest, applied once they are placed */
116
+ channelResponse: StreamResponse<ChannelStateResponse>;
117
+ source: 'channel';
118
+ /** whether the query watched the channel, which applying the response records */
119
+ watch: boolean;
128
120
  };
129
121
  /**
130
- * MessageIntervalPaginator allows configuring backend request sort, while keeping internal item ordering stable.
131
- * Filtering of ingested items is still limited to local predicates (`filterQueryResults`).
122
+ * A message list with a configurable backend request sort and a stable in-memory item order.
123
+ * Ingested items are filtered only by local predicates (`filterQueryResults`).
132
124
  */
133
- export declare class MessageIntervalPaginator extends BasePaginator<LocalMessage, MessageQueryShape> {
125
+ export declare class MessageIntervalPaginator extends BasePaginator<LocalMessage, MessageQueryShape, MessageQueryResponse> {
126
+ /**
127
+ * Holder name of this list's index in the message store. A getter, so a subclass's value is in
128
+ * place while the base constructor builds the index.
129
+ */
130
+ protected get holderName(): string;
134
131
  state: StateStore<MessagePaginatorState>;
135
132
  private readonly _id;
136
- protected channel: Channel;
137
- protected parentMessageId?: string;
133
+ /** The channel this list belongs to. A thread's reply list holds its parent channel. */
134
+ readonly channel: Channel;
135
+ /** See {@link MessagePaginatorOptions.thread}. */
136
+ readonly thread?: Thread;
137
+ /** Set when this is a thread's reply list, to the parent message's ID. */
138
+ readonly parentMessageId?: string;
138
139
  readonly messageFocusSignal: StateStore<MessageFocusSignalState>;
139
140
  private clearMessageFocusSignalTimeoutId;
140
141
  private messageFocusSignalToken;
141
142
  protected _requestSort: MessagePaginatorSort;
142
143
  protected _itemOrder: MessagePaginatorSort;
143
- protected _nextQueryShape: MessageQueryShape | undefined;
144
- /** Pending below-window reached-start probe (exposed for deterministic test awaiting). */
145
- private _belowWindowReconcile?;
144
+ /** The pending {@link removeIdsTailwardOfPageIfNothingOlder} (kept so tests can await it). */
145
+ private _pendingTailwardOfPageRemoval?;
146
+ /**
147
+ * The ID of the newest server-confirmed message of the interval whose head mark was cleared last
148
+ * (see {@link unmarkedHeadInterval}). Forgotten once a newest page is reconciled with no head
149
+ * interval loaded, and when the loaded intervals are cleared.
150
+ */
151
+ private unmarkedHeadEdgeId;
146
152
  sortComparator: (a: LocalMessage, b: LocalMessage) => number;
147
153
  /**
148
- * Single source of truth for whether a message should be included in paginator intervals/state.
149
- * Keep this consistent with `filterQueryResults` AND cursor flag derivation.
154
+ * Whether a message belongs in intervals and state. Keep it consistent with `filterQueryResults`
155
+ * and with the page the linear cursor flag derivation reads (see {@link deriveCursorFromPage}).
150
156
  */
151
157
  shouldIncludeMessageInInterval(message: LocalMessage): boolean;
152
158
  /**
153
- * Entity-store adapter (this paginator is an `EntityStoreSubscriber`): the `EntityStore` calls this
154
- * on each holder with the subset of its watched ids that changed. Unwraps the batch and delegates to
155
- * the base's store-agnostic {@link BasePaginator.reconcileChangedIds}. Lives here, not on the generic
156
- * `BasePaginator`, so the base stays free of `EntityStore` types — only message paginators are
157
- * store-backed.
159
+ * Reconciles the held messages that changed in the entity store.
160
+ *
161
+ * @internal
162
+ * @param batch - The change batch from the store.
163
+ * @param batch.changedIds - IDs of the watched messages that changed.
158
164
  */
159
165
  onEntitiesChanged({ changedIds }: EntityStoreChangeBatch): void;
160
166
  /**
161
- * Entity-store subscriber flush (the optional `EntityStoreSubscriber.flushState`): the `EntityStore`
162
- * calls this after an optimistic (local-user) write so the change renders without throttle delay.
163
- * Delegates to the base's generic {@link BasePaginator.flushPendingPublishes}.
167
+ * Drops a message from this paginator's intervals after the entity store removed it.
168
+ *
169
+ * @internal
170
+ * @param id - ID of the removed message.
171
+ * @param message - The removed message.
164
172
  */
173
+ onEntityRemoved(id: string, message: unknown): void;
174
+ /** Entity-store subscriber flush after an optimistic (local-user) write: skips the throttle. */
165
175
  flushState(): void;
176
+ /** UI-driven "hold off on pruning" signal ({@link setPruningSuspended}). Off by default. */
177
+ protected get isPruningSuspended(): boolean;
178
+ private _pruningSuspended;
179
+ /**
180
+ * Holds off dropping the oldest loaded messages, so pruning does not pull content from under a user
181
+ * reading near them: the interval may grow past `maxLoadedItems` until they scroll back. A plain
182
+ * field, not a `StateStore`: nothing observes it and a scroll-driven signal must not cost a render.
183
+ */
184
+ setPruningSuspended: (suspended: boolean) => void;
185
+ /**
186
+ * A message anchors pagination once the server has acknowledged it. This keeps an unsent message
187
+ * out of both halves of a prune and stops its ID from becoming the tailward cursor (`id_lt`).
188
+ */
189
+ protected isPaginationAnchorable(item: LocalMessage | undefined): boolean;
166
190
  protected get intervalItemIdsAreHeadFirst(): boolean;
167
191
  protected get intervalSortDirection(): 'asc' | 'desc';
168
- constructor({ channel, id, itemIndex, parentMessageId, requestSort, sort, itemOrder, paginatorOptions, }: MessagePaginatorOptions, builtInDefaults?: Partial<BasePaginatorConfig<LocalMessage, MessageQueryShape>>);
192
+ constructor({ channel, id, itemIndex, parentMessageId, requestSort, sort, itemOrder, paginatorOptions, thread, }: MessagePaginatorOptions, builtInDefaults?: Partial<BasePaginatorConfig<LocalMessage, MessageQueryShape>>);
169
193
  /**
170
- * Memoized so every derivation sees the *same* two functions. `initializeConfig` folds this into the
171
- * config it publishes and skips the publish when nothing moved — which only works if these references
172
- * are stable.
173
- *
174
- * Safe to build once: both close over `this` and read `_itemOrder`, which is assigned in the
175
- * constructor and has no setter.
194
+ * Memoized: `initializeConfig` folds it in and skips the publish when nothing moved, which needs
195
+ * stable references. Safe to build once: `_itemOrder` is set in the constructor, with no setter.
176
196
  */
177
197
  private intervalBehaviour?;
178
198
  private buildIntervalBehaviour;
179
199
  /**
180
- * Cursor derivation and in-memory item ordering, which this class installs on `config` rather than
181
- * passing as constructor options.
182
- *
183
- * Contributed to the base derivation rather than written after it — see
184
- * {@link BasePaginator.getBehaviourOverrides}. That is what keeps one re-derivation to one publish,
185
- * and stops the intermediate publish that had these two stripped.
200
+ * Installs cursor derivation and item ordering on `config` through the base derivation
201
+ * ({@link BasePaginator.getBehaviourOverrides}), so one re-derivation is one publish.
186
202
  */
187
203
  protected getBehaviourOverrides(): Partial<BasePaginatorConfig<LocalMessage, MessageQueryShape>>;
188
204
  /**
189
- * The constructor's route to the same overlay. Deliberately calls the private builder rather than the
190
- * overridable hook: this runs inside the constructor, and a subclass override would execute before its
191
- * own fields were initialized.
205
+ * The constructor's route to the same overlay. It calls the private builder, not the overridable
206
+ * hook, which would run a subclass override before its fields are initialized.
192
207
  */
193
208
  protected installIntervalBehaviour(): void;
194
209
  get id(): string;
195
210
  get sort(): MessagePaginatorSort;
196
211
  get requestSort(): MessagePaginatorSort;
197
212
  get itemOrder(): MessagePaginatorSort;
198
- /**
199
- * Even though we do not send filters object to the server, we need to have filters for client-side item ingestion logic.
200
- */
213
+ /** Not sent to the server: drives client-side item ingestion. */
201
214
  buildMatchFilters: () => MessagePaginatorFilter;
202
215
  protected getNextQueryShape({ direction, }: Omit<PaginationQueryParams<MessageQueryShape>, 'isFirstPageQuery'>): MessageQueryShape;
203
216
  getCursorFromQueryResults: ({ direction, items, }: {
@@ -207,168 +220,430 @@ export declare class MessageIntervalPaginator extends BasePaginator<LocalMessage
207
220
  tailward: string | undefined;
208
221
  headward: string | undefined;
209
222
  };
210
- query: ({ direction, }: PaginationQueryParams<MessageQueryShape>) => Promise<PaginationQueryReturnValue<LocalMessage>>;
211
223
  /**
212
- * Seed the paginator with the page a channel-open query just fetched (`Channel.query` for
213
- * `watch`/`create`, and `client.hydrateActiveChannels`).
224
+ * Runs the query pipeline (see `BasePaginator.executeQuery`). A query that goes to the channel —
225
+ * not a thread's reply list, not a custom `doRequest` — runs as a tracked query of the channel
226
+ * (`Channel.runTrackedQuery`), so the channel store keeps the channel until the query ends. A
227
+ * disposed channel's query is not tracked: its fetch step is refused, and fails as any failed
228
+ * request does.
229
+ */
230
+ executeQuery(params?: PaginationQueryParams<MessageQueryShape>): Promise<ExecuteQueryReturnValue<LocalMessage> | void>;
231
+ /**
232
+ * The fetching step of the query pipeline: requests a page through a custom `doRequest`, the
233
+ * replies endpoint for a thread's reply list, or the channel query otherwise, which takes in what
234
+ * the response says about the channel itself and leaves the rest for the last step (see
235
+ * `Channel.requestChannelState`). Reads `requestOptions.watch`: `true` also watches the channel
236
+ * with the request. Ignored for a thread's reply list and with `doRequest`.
237
+ */
238
+ protected fetchQueryResponse: ({ direction, queryShape, requestOptions, }: PaginationQueryParams<MessageQueryShape>) => Promise<MessageQueryResponse>;
239
+ /**
240
+ * The extracting step of the query pipeline: the messages in item order and their cursors, which
241
+ * a custom `doRequest` reports and which are derived from the messages otherwise.
242
+ */
243
+ protected extractQueryPage(response: MessageQueryResponse, { direction }: PaginationQueryParams<MessageQueryShape>): PaginationQueryReturnValue<LocalMessage>;
244
+ /**
245
+ * The last step of the query pipeline: the rest of a channel query's response, applied once its
246
+ * page is placed (see `Channel.applyChannelStateFromResponse`). The other sources return nothing
247
+ * else.
248
+ */
249
+ protected applyQueryResponseRest(response: MessageQueryResponse, _placeParams: QueryPagePlacement<MessageQueryShape>): void;
250
+ /**
251
+ * Whether this paginator is active: the thread it lists is active (see `Thread.activate()`), or,
252
+ * without a thread, its channel is (see `Channel.activate()`). A page from a query an active
253
+ * paginator did not run leaves its active interval active; an inactive paginator shows a fresh
254
+ * newest page instead, also one separated from the loaded messages by a gap (see
255
+ * {@link reconcileNewestMessages}).
256
+ */
257
+ private isActivePaginator;
258
+ /**
259
+ * Places a page from an external query — one this paginator did not run, whose page the caller
260
+ * chose — in the intervals it belongs to, never removing anything loaded. Bringing the loaded
261
+ * newest messages up to date with a fresh newest page, removals included, is
262
+ * {@link reconcileNewestMessages}'s job instead.
263
+ *
264
+ * External queries are a channel query (`watch()`, see {@link prepareExternalQuery}), the
265
+ * channel list's query (`client.hydrateChannels`), and the channel state the pinned list's first
266
+ * page comes with. `messagePaginationParams` are the
267
+ * options the page was queried with; they decide where it goes:
268
+ *
269
+ * - The newest page: when no interval is active yet (nothing loaded, or only live messages), its
270
+ * interval becomes the active one, as the channel's first page. When the active interval is the
271
+ * newest interval, the page lands in it.
272
+ * - Any other page — a page at a cursor or around a message, or the newest page while an older
273
+ * interval is active — is only stored, as a separate interval merged only with an interval it
274
+ * overlaps.
275
+ *
276
+ * The active interval stays active: changing it is this paginator's own methods' job
277
+ * (`jumpToMessage()` and the like). The exception is an inactive paginator (see
278
+ * {@link isActivePaginator}), where the newest page is shown as when no interval is
279
+ * active. A newest
280
+ * page for loaded messages goes to {@link reconcileNewestMessages} instead
281
+ * (`prepareExternalQuery`, the channel list's query). When a page lands in the active interval,
282
+ * overlaps it, or takes in an active interval of live messages only, that interval is shown again
283
+ * with the page. The paginator's own queries are left alone too: a running one keeps its loading
284
+ * flag, and its last query error and query shape stay.
285
+ *
286
+ * It runs synchronously, so a caller can apply the rest of the response right after with the page
287
+ * in place, as it has to: read and delivery positions that come without a message id are looked
288
+ * up among the loaded messages.
289
+ *
290
+ * Returns whether it showed the page as a first page.
291
+ */
292
+ placeExternalQueryPage(page: LocalMessage[], requestedPageSize: number, messagePaginationParams?: MessagePaginationParams): boolean;
293
+ /**
294
+ * Whether messages are loaded for {@link reconcileNewestMessages} to bring up to date. A list
295
+ * loaded empty has none (no interval, not even live messages), so a fresh newest page is placed
296
+ * as a first page instead ({@link placeExternalQueryPage}); reconciling would find nothing to
297
+ * merge it into and drop it.
298
+ */
299
+ get canReconcileNewestMessages(): boolean;
300
+ /**
301
+ * The snapshot a newest page is reconciled against (see
302
+ * {@link ReconcileNewestMessagesOptions.headIntervalItemIdsAtRequest}): the IDs of the head
303
+ * interval's server-confirmed messages. Take it right before the request goes out. Unsent messages
304
+ * are left out: one confirmed during the request proves neither that the page connects to the
305
+ * head interval nor, when the page lacks it, that it was deleted. `undefined` while no head
306
+ * interval is loaded.
307
+ *
308
+ * @internal
309
+ */
310
+ getHeadIntervalItemIdsAtRequest(): ReadonlySet<string> | undefined;
311
+ /**
312
+ * Whether the loaded message with this ID is server-confirmed
313
+ * (see {@link isServerConfirmedMessage}).
314
+ */
315
+ private isServerConfirmedItemId;
316
+ /**
317
+ * Prepares an external query for a page of these messages: the watch query the channel sends
318
+ * (`channel.watch()`, `channel.reload()`) with the `messages` options its caller gave. Call it
319
+ * before sending the query, and place the returned page with `placePage` before the response's
320
+ * read state is applied: the read state is resolved against the loaded messages.
214
321
  *
215
- * These paths hydrate the channel read state in the SAME synchronous tick they add messages
216
- * (`Channel._initializeState`), and the read patch drives `MessageReceiptsTracker`, which resolves
217
- * read/delivered cursors against this paginator (`findItemByTimestamp`) whenever the server omits
218
- * the `last_read_message_id` / `last_delivered_message_id`. `postQueryReconcile` is fully
219
- * synchronous (filtering is a local predicate), so seeding here guarantees the paginator is
220
- * populated before the reconcile runs. First-page reconciliation also takes the unread snapshot.
322
+ * - `messagePaginationParams`: the options to send as the query's `messages`, with `limit` set to
323
+ * the page size when not given.
324
+ * - `isNewestPage`: whether the query asks for the newest page — no cursor, not around a message,
325
+ * and some messages.
326
+ * - `placePage`: places the returned page. The newest page goes to
327
+ * {@link placeExternalNewestPage}, reconciled against the messages loaded when the query was
328
+ * prepared; any other page is placed by {@link placeExternalQueryPage}. A query for no messages
329
+ * (`limit: 0`) places nothing. Returns whether it showed a first page.
330
+ */
331
+ prepareExternalQuery(messages?: MessagePaginationParams): PreparedExternalQuery;
332
+ /**
333
+ * Places the newest page of an external query (a channel query, the channel list's query): it
334
+ * reconciles the loaded newest messages ({@link reconcileNewestMessages}), or is placed as a
335
+ * first page when none are loaded ({@link placeExternalQueryPage}). A query for no messages
336
+ * (`requestedLimit: 0`) places nothing. Returns whether it showed a first page.
221
337
  *
222
- * The fetched page is NOT always the latest window: a channel can be opened AROUND a message
223
- * (`messages: { id_around }` / `{ created_at_around }`), so the original pagination options are
224
- * threaded through as the query shape. For an around/jump open this lets `postQueryReconcile`
225
- * apply jump semantics (no forced head/tail; cursor flags derived from the around position)
226
- * instead of wrongly flagging the window as the head (newest) page.
338
+ * @internal
227
339
  */
228
- seedFirstPageSync(messages: LocalMessage[], requestedPageSize: number, messagePaginationOptions?: MessagePaginationParams, options?: SeedFirstPageOptions): void;
340
+ placeExternalNewestPage(page: LocalMessage[], { headIntervalItemIdsAtRequest, requestedLimit, }: ReconcileNewestMessagesOptions & {
341
+ requestedLimit: number;
342
+ }): boolean;
229
343
  isJumpQueryShape(queryShape: MessageQueryShape): boolean;
230
- jumpToMessage: (messageId: string, { focusReason, focusSignalTtlMs, pageSize, suppressFocusSignal, }?: JumpToMessageOptions) => Promise<boolean>;
344
+ /** Only a query without a cursor and not around a message returns the newest page. */
345
+ protected isHeadPageQueryShape(queryShape: MessageQueryShape | undefined): boolean;
346
+ /** A jump sends its own `limit`: head/tail flags are derived against it, not `pageSize`. */
347
+ protected getRequestedPageSize(queryShape: MessageQueryShape | undefined): number;
348
+ /**
349
+ * Makes the interval holding the message the active one, querying the page around it when it is
350
+ * not loaded. Resolves `false` when the message cannot be shown, or when a later claim on the
351
+ * active interval (see `claimActiveInterval`) was made before the page arrived.
352
+ */
353
+ jumpToMessage: (messageId: string, { focusReason, focusSignalTtlMs, pageSize, suppressFocusSignal, watchChannel, }?: JumpToMessageOptions) => Promise<boolean>;
354
+ /**
355
+ * Shows a loaded interval as it is: its items, its own pagination flags and the cursor continuing
356
+ * it. Claiming the active interval is the caller's choice (see `claimActiveInterval`).
357
+ */
358
+ protected showLoadedInterval(interval: Interval): void;
359
+ /** Makes `interval` the active interval and publishes `state` for it in one update. */
360
+ private showInterval;
361
+ /**
362
+ * Shows the interval holding the latest message and jumps to that message. Without a loaded head
363
+ * interval (see {@link latestHeadInterval}), the newest page is queried first: no cursor, so it
364
+ * holds the latest message however many pages are missing. The page merges with an interval it
365
+ * overlaps and is an interval of its own otherwise, and is shown either way. Resolves `false` when
366
+ * the latest message cannot be shown, or when a later claim on the active interval (see
367
+ * `claimActiveInterval`) was made before the page arrived: that page is then only stored.
368
+ */
231
369
  jumpToTheLatestMessage: (options?: JumpToMessageOptions) => Promise<boolean>;
232
370
  /**
233
- * Fold an already fetched newest (head) page into the currently loaded items without issuing a
234
- * query. The caller supplies a page it obtained on its own and this reconciles it against what is
235
- * loaded, instead of rerunning the first page query, so the loaded set is updated in place rather
236
- * than blanked and reloaded. Two cases, decided by whether the incoming page overlaps the loaded
237
- * head:
238
- *
239
- * 1. OVERLAP - the incoming page shares at least one id with the loaded head (fewer than a full
240
- * page is new). Merge in place: existing items are reconciled by id (edits, soft deletes), new
241
- * items are appended and every already loaded item (including older pages already paged in) is
242
- * kept. The tail boundary (`hasMoreTail`/`cursor.tailward`) is set from whether the page reached
243
- * the channel start ({@link pageReachedChannelStart}): a bounded page that came back short means
244
- * no more older, otherwise "load older" stays enabled and the cursor re-anchors to the true loaded
245
- * oldest (which also clears a stale offline-DB cursor). Then destructive reconciliation
246
- * ({@link reconcileHeadAgainstPage}) removes any loaded message
247
- * that the authoritative page proves was hard-deleted while offline (see that method + the
248
- * {@link MergeNewestPageOptions} for the exact, safe window).
249
- *
250
- * 2. DISJOINT - the incoming page shares no id with the loaded head (at least a full page is new).
251
- * Merging would weld the two across the gap (the interval merge treats two head intervals as
252
- * overlapping when one reaches further headward), hiding the items in between with no way to
253
- * reach them. Instead the loaded set is discarded and rebuilt from the incoming page as a fresh
254
- * contiguous head (`hasMoreTail: true`, cursor reanchored to the page's oldest item) so the
255
- * gap and older history load again when paginating older. No separate reconciliation is needed:
256
- * the rebuilt window IS the server truth, so any hard-deleted message is simply absent from it.
257
- *
258
- * Never blanks the loaded set. Noop unless the newest slice is both loaded AND the interval
259
- * currently in view (the head interval is anchored at the head and active); when the caller has
260
- * jumped to a separate older window the merge is skipped so their position is preserved, and the
261
- * incoming page is picked up on a later load. An empty page never wipes the list on its own, but
262
- * — given a pre-fetch snapshot via `options.candidateIds` — is reconciled as "the channel has no
263
- * messages" (every server-confirmed loaded message removed).
264
- *
265
- * @param page - The fetched newest window (may be empty). `created_at` order is normalized on ingest.
266
- * @param options - See {@link MergeNewestPageOptions}. Omit to prune only within the page's own span.
267
- */
268
- mergeNewestPage: (page: LocalMessage[], options?: MergeNewestPageOptions) => void;
269
- /**
270
- * Whether `page` proves it reached the channel's own oldest message: the caller's request was
271
- * bounded by this paginator's OWN `pageSize` AND `page` came back shorter than that request.
272
- *
273
- * `pageSize <= the server's max page size` is already the invariant normal pagination
274
- * (`executeQuery`) relies on — `page.length < pageSize` ⟹ reached the end — so a request no larger
275
- * than `pageSize` returns exactly what was asked unless the channel ended. This needs no hardcoded
276
- * max page size and is per-paginator, so a thread reply paginator uses its own `pageSize`.
277
- *
278
- * An OVER-request (larger than `pageSize`, e.g. `channel.reload` re-fetching the whole loaded window
279
- * to reconcile as much as possible) may have been silently capped by the server, so a short page
280
- * there is NOT proof of reaching the start — return `false` and stay conservative. This only ever
281
- * gates the `hasMoreTail` affordance; it never removes a message.
371
+ * The head interval when it is the newest loaded interval, so its newest message is the latest
372
+ * one; `undefined` while no head interval is loaded or live messages newer than it are.
373
+ */
374
+ private get latestHeadInterval();
375
+ /**
376
+ * Reconciles the loaded newest messages with a fresh newest page, without issuing a query: they
377
+ * are brought up to date in place — messages added and updated, those the page proves were
378
+ * hard-deleted removed — rather than blanked and reloaded. The page comes from an external query
379
+ * (a reload, a channel-list query, connection recovery). In an active paginator (see
380
+ * {@link isActivePaginator}) the active interval stays active, the head interval included
381
+ * (changing it is `jumpToTheLatestMessage()`'s job); in an inactive one, the head interval is
382
+ * shown.
383
+ *
384
+ * Where the page goes depends on the head interval, the loaded interval reaching the newest
385
+ * message:
386
+ *
387
+ * 1. NO HEAD INTERVAL (only live messages, a jumped-to interval, or a cleared head mark, see
388
+ * {@link unmarkHead}) - the page becomes the head interval, merging with the intervals it
389
+ * overlaps, live messages included, minus what it proves was hard-deleted. It is shown if the
390
+ * live messages it absorbed were active; an active interval that it overlaps grows. A
391
+ * page separated by a gap from the interval whose head mark was cleared is placed as in 2.
392
+ *
393
+ * 2. SEPARATED BY A GAP (see {@link isSeparatedFromHeadByGap}) - merging would weld the two
394
+ * across the gap, hiding the messages in between, so the page takes the place of the head
395
+ * interval (see {@link placeNewestPageAcrossGap}): stored beside the active interval when that
396
+ * is an older interval, shown in place of the loaded intervals otherwise.
397
+ *
398
+ * 3. OTHERWISE - the page merges into the head interval, which keeps every loaded message and
399
+ * drops what the page proves was hard-deleted (see {@link reconcileHeadAgainstPage}). An
400
+ * active head interval gets its tail boundary from the page (see {@link showHeadInterval});
401
+ * otherwise the active interval stays active, and grows into the head interval if the page
402
+ * overlaps it.
403
+ *
404
+ * Only a gap drops loaded intervals, never an older active interval, and with nothing loaded it
405
+ * does nothing: placing a first page is {@link placeQueryPage}'s job. An empty page changes
406
+ * nothing on its own but, given a pre-fetch snapshot (`options.headIntervalItemIdsAtRequest`), is
407
+ * reconciled as "the channel has no messages": every server-confirmed message of the head interval
408
+ * is removed.
409
+ *
410
+ * The query shape of the loaded interval is recorded on every exit (see
411
+ * `recordLoadedIntervalQueryShape`): an interval left without one loses itself on the next
412
+ * pagination.
413
+ *
414
+ * @param page - The fetched newest interval (may be empty). `created_at` order is normalized on
415
+ * ingest.
416
+ * @param options - See {@link ReconcileNewestMessagesOptions}. Omit to prune only within the
417
+ * page's own span.
418
+ */
419
+ reconcileNewestMessages: (page: LocalMessage[], options?: ReconcileNewestMessagesOptions) => void;
420
+ private _reconcileNewestMessages;
421
+ /**
422
+ * Shows the head interval a fresh newest page merged into, with no newer messages to load. It has
423
+ * older ones unless the page reached the channel start (see {@link pageReachedChannelStart});
424
+ * `isTail` follows, which also clears a stale offline-DB `isTail: true` that would let
425
+ * `intervalsOverlap` weld a far page across a gap.
426
+ */
427
+ private showHeadInterval;
428
+ /**
429
+ * Whether a fresh newest page and the head interval (or the interval whose head mark was cleared,
430
+ * see {@link unmarkedHeadInterval}) are separated by a gap, with messages between them possibly
431
+ * not loaded. They are not when the two together form one unbroken stretch of the channel:
432
+ *
433
+ * - the page starts inside the head interval (see {@link pageStartsInsideHead});
434
+ * - the page covers the head interval (see {@link pageCoversHead});
435
+ * - the page reached the channel start (see {@link pageReachedChannelStart}), so nothing older
436
+ * than it exists to be missing.
437
+ *
438
+ * Sharing a message is not enough on its own: a message the user sent while offline is confirmed
439
+ * by the server before the reconnect's newest page is requested, so it sits at the top of the
440
+ * head interval and in the page, with the messages missed below it in neither. For example, the
441
+ * interval holds m1–m100 and the user's queued "hello"; the server got m101–m210 meanwhile. A page
442
+ * of 25 holds m187–m210 and "hello": it does not start inside the interval (m187 was never loaded)
443
+ * nor cover it (m1 is not in it), so it is past a gap. When the user wrote the last 10 loaded
444
+ * messages and others sent 20 since, a page of 25 holds the user's last 5 and the 20 new ones:
445
+ * its oldest was loaded, so it starts inside the interval.
446
+ *
447
+ * A message missed while the socket was down comes with connection recovery's newest page.
448
+ */
449
+ private isSeparatedFromHeadByGap;
450
+ /**
451
+ * Whether the page's oldest message the head interval could hold (see
452
+ * {@link getPageOldestHoldableMessage}) was in the head interval when the request went out. The
453
+ * page runs unbroken from that message to the newest and the interval is taken to run unbroken
454
+ * below it, so nothing between them is missing.
455
+ *
456
+ * With a snapshot of the request (`options.headIntervalItemIdsAtRequest`), the message must be
457
+ * in it and held by no interval other than the head interval: a message that reached the interval
458
+ * during the request, live or as a send confirmed meanwhile, may sit above messages the interval
459
+ * never loaded. One no longer loaded at all still counts: if the head interval holds messages
460
+ * older than it, the interval ran unbroken through it and it was removed (e.g. hard-deleted);
461
+ * if not, the page covers the interval anyway. Without a snapshot, the message must be in the
462
+ * head interval and server-confirmed now.
463
+ *
464
+ * The interval is not unbroken below a send the server confirmed while the channel received no
465
+ * events, such as one replayed from the offline queue before the reconnect's newest page is
466
+ * requested. If that send is exactly the page's oldest (as many newer messages as the page has
467
+ * room for were sent after it), the page is taken to start inside the interval although messages
468
+ * below the send were missed. The page and the interval cannot tell this apart from a send
469
+ * confirmed while events were arriving.
470
+ */
471
+ private pageStartsInsideHead;
472
+ /**
473
+ * Whether the page spans the whole head interval: the interval holds no server-confirmed message
474
+ * older than the page. What the interval holds beyond the page is newer (it arrived as an event
475
+ * after the page was produced) or unsent (it carries the device's clock).
476
+ */
477
+ private pageCoversHead;
478
+ /**
479
+ * The page's oldest message that the head interval could have loaded: server-confirmed and kept
480
+ * in intervals (see {@link filterQueryResults}). A message the interval filters out, such as a
481
+ * shadowed one, would never be found in it. {@link pageCoversHead} compares with the page's
482
+ * oldest message of any kind instead: it only needs the page's span.
483
+ */
484
+ private getPageOldestHoldableMessage;
485
+ /**
486
+ * The interval whose head mark was cleared last (see {@link unmarkHead}), while it is still
487
+ * loaded. It reached the newest message until then, so a newest page is judged against it while
488
+ * no head interval is loaded.
489
+ */
490
+ private get unmarkedHeadInterval();
491
+ /**
492
+ * Remembers the interval by a message that stays in it: a server-confirmed one, as an unsent one
493
+ * may be deleted or retried; the raw newest item only when the interval holds none.
494
+ */
495
+ protected unmarkHead(interval: Interval): void;
496
+ protected clearItemStorage(): void;
497
+ resetState(): void;
498
+ private getPageOldestMessage;
499
+ /**
500
+ * Places a fresh newest page separated by a gap from `headInterval` (the head interval, or the
501
+ * interval whose head mark was cleared, see {@link isSeparatedFromHeadByGap}). The page becomes
502
+ * the head interval either way, and the intervals nothing brought up to date are dropped, as a
503
+ * message deleted meanwhile would come back with them:
504
+ *
505
+ * - an active interval other than the head interval (see {@link getActiveIntervalApartFromHead})
506
+ * stays active, and the page is stored beside it (see
507
+ * {@link storeNewestPageBesideActiveInterval});
508
+ * - otherwise the page replaces the loaded intervals and is shown (see
509
+ * {@link replaceIntervalsWithNewestPage}).
510
+ */
511
+ private placeNewestPageAcrossGap;
512
+ /**
513
+ * The active loaded interval when it is not `headInterval`, such as an interval jumped to;
514
+ * `undefined` when `headInterval` or live messages only are active, and in an inactive paginator
515
+ * (see {@link isActivePaginator}).
516
+ */
517
+ private getActiveIntervalApartFromHead;
518
+ /**
519
+ * Replaces the loaded intervals with a fresh newest page separated from the head interval by a gap
520
+ * (see {@link placeNewestPageAcrossGap}) and shows it. The page's interval keeps the loaded
521
+ * messages that must not be lost (see {@link getMessagesKeptAcrossGap}) and has older messages
522
+ * to load.
523
+ */
524
+ private replaceIntervalsWithNewestPage;
525
+ /**
526
+ * Stores a fresh newest page separated from the head interval by a gap (see
527
+ * {@link placeNewestPageAcrossGap}) as the head interval, beside `activeInterval`, which stays
528
+ * active and shown as it is. Every other loaded interval is dropped and loads again on
529
+ * demand. The page's interval keeps the messages of the dropped intervals that must not be lost
530
+ * (see {@link getMessagesKeptAcrossGap}) and has older messages to load.
531
+ *
532
+ * The active interval keeps all its messages, unsent ones included, so nothing moves in the
533
+ * shown list, and it is not brought up to date: a message deleted or edited meanwhile stays as it was
534
+ * loaded. It can load newer messages, up to the head interval it then joins.
535
+ */
536
+ private storeNewestPageBesideActiveInterval;
537
+ /**
538
+ * Ingests a fresh newest page placed across a gap, with `keptMessages`, as the head interval,
539
+ * which has older messages to load, and removes from it what the page proves was hard-deleted (see
540
+ * {@link reconcileHeadAgainstPage}). Returns the interval the page landed in.
541
+ */
542
+ private ingestPageAsHeadInterval;
543
+ /**
544
+ * Drops `intervals` from storage and releases their messages, except those with `keepingIds`,
545
+ * which the caller ingests again.
546
+ */
547
+ private dropIntervals;
548
+ /**
549
+ * Marks the active interval, which does not reach the newest message, as able to load newer
550
+ * messages. Publishes the flag and cursor only when they changed, so the interval shown stays as
551
+ * it is.
552
+ */
553
+ private markActiveIntervalBelowHead;
554
+ /**
555
+ * The messages of `intervals`, missing from a newest page placed across a gap, that the page's
556
+ * interval keeps:
557
+ *
558
+ * - unsent messages (see {@link isServerConfirmedMessage});
559
+ * - messages from the page's oldest on: those that arrived during the request stay, and
560
+ * reconciling removes those the page proves were hard-deleted.
561
+ */
562
+ private getMessagesKeptAcrossGap;
563
+ /**
564
+ * Merges a fresh newest page, not separated by a gap, into the head interval while another
565
+ * interval is shown. That interval stays active and grows into the head interval if the page
566
+ * overlaps it. In an inactive paginator (see {@link isActivePaginator}), the head interval is
567
+ * shown instead.
568
+ */
569
+ private mergePageIntoInactiveHead;
570
+ /** Publishes the active interval once a newest page grew it into the head interval. */
571
+ private publishActiveIntervalGrownIntoHead;
572
+ /**
573
+ * Whether `page` proves it reached the channel's oldest message: the request was bounded by this
574
+ * paginator's own `pageSize` and `page` came back shorter. A larger over-request (e.g.
575
+ * `channel.reload`) may have been server-capped and never proves it. Gates `hasMoreTail` and the
576
+ * gap rule ({@link isSeparatedFromHeadByGap}), never removing a message.
282
577
  */
283
578
  private pageReachedChannelStart;
284
579
  /**
285
- * Settle the below-window leftovers {@link reconcileHeadAgainstPage} handed back (loaded messages
286
- * older than `anchorId` — the returned page's oldest — and absent from the page). From the page alone
287
- * they're ambiguous: a hard-deleted oldest vs a server-capped over-request. Ask the server "anything
288
- * older than `anchorId`?" — the only cap-free way to tell. Nothing older ⇒ genuine deletes ⇒ remove
289
- * them and settle the tail. A probe failure or a head change across the await keeps them (never a false
290
- * delete). The caller decides WHEN this runs.
580
+ * Settles the loaded messages {@link reconcileHeadAgainstPage} found tailward of the page (older
581
+ * than `pageTailId`, the page's oldest, and absent from it): from the page alone a hard-deleted
582
+ * oldest message looks like one the page was too short to include. It asks the server whether
583
+ * anything is older than `pageTailId`. When nothing is, those messages were deleted: they are
584
+ * removed and the head interval becomes the tail. A failed request, or a head interval replaced
585
+ * while waiting, keeps them. The caller decides when this runs.
291
586
  */
292
- private pruneBelowWindowIfReachedStart;
587
+ private removeIdsTailwardOfPageIfNothingOlder;
293
588
  /** One `limit: 1` fetch of messages older than `id` (channel main list or thread replies). */
294
589
  private hasMessagesOlderThan;
295
590
  /**
296
- * Whether a loaded message is server-confirmed and therefore eligible to be reconciled away when
297
- * absent from an authoritative page. Excludes local-only messages the server has never
298
- * acknowledged — optimistic (`sending`) and `failed` sends, and client-side `error` placeholders —
299
- * so a legitimately-unsent message is never mistaken for a hard delete.
591
+ * Whether a loaded message is server-confirmed, so it may be reconciled away when absent from an
592
+ * authoritative page. Optimistic (`sending`), `failed` and client-side `error` messages are not, so
593
+ * an unsent message is never mistaken for a hard delete.
300
594
  */
301
595
  protected isServerConfirmedMessage(message: LocalMessage): boolean;
302
596
  /**
303
- * Destructive half of {@link mergeNewestPage}: remove messages in the loaded head interval that
304
- * `page` proves were hard-deleted while offline (a hard delete emits no event to other clients, and
305
- * the merge is additive, so they would otherwise linger forever).
306
- *
307
- * Here `page` is the freshly-fetched newest window the server returned for the query that produced
308
- * it. Its two bounds are its NEWEST message (`page`'s last item by `created_at`) and its OLDEST
309
- * message (`page`'s first item). Reconciliation removes ONLY messages `page` actually covers — no
310
- * hardcoded page size is involved — in two regions, by a loaded message's `created_at`:
311
- *
312
- * - WITHIN `page` (strictly between `page`'s oldest and newest message): a server-confirmed loaded
313
- * message absent from `page` was hard-deleted. Safe with no snapshot — a message that arrived live
314
- * during the caller's fetch is always strictly newer than `page`'s newest message, so it can never
315
- * fall in this span.
316
- * - AT/ABOVE `page`'s newest message (a hard-deleted newest message), and the empty-`page` case:
317
- * only reconcilable with a pre-fetch `candidateIds` snapshot, which alone tells a just-deleted
318
- * message from one that arrived live during the fetch at that top edge.
319
- *
320
- * A loaded message BELOW `page`'s oldest is NOT removed here (window-only) — from the page alone a
321
- * hard-deleted oldest is indistinguishable from a server-capped over-request. Those messages are
322
- * instead RETURNED (the below-window leftovers) so {@link pruneBelowWindowIfReachedStart} can settle
323
- * them with a `limit: 1` "anything older?" probe — the only cap-free proof — and remove them only if
324
- * the server confirms nothing older exists. Absent that proof they are kept (a later cold/fresh query
325
- * omits any real delete).
326
- *
327
- * Removal goes through {@link removeItem} (batched) so the item index, intervals, shared message
328
- * store and — via the {@link MessagePaginator} override — the tracked last message all stay correct;
329
- * the active window is then re-emitted once.
330
- *
331
- * @returns the below-window leftover ids (loaded, server-confirmed, older than `page`'s oldest, absent
332
- * from it) for the caller's reached-start probe. Empty for the no-head / empty-page paths.
333
- */
334
- protected reconcileHeadAgainstPage(page: LocalMessage[], options?: MergeNewestPageOptions): string[];
335
- /**
336
- * Remove a set of reconciled (hard-deleted) ids from this paginator's loaded state in one coalesced
337
- * batch. Each id goes through {@link removeItem}, which drops it from THREE places — not a single
338
- * interval:
339
- *
340
- * 1. the item index — unlinks this paginator's membership from the shared entity store (GC'ing the
341
- * content if this was the last holder);
342
- * 2. the interval that holds it — located by id, so it is NOT head-specific in general; in practice
343
- * it is always the head interval, because the sole caller ({@link reconcileHeadAgainstPage})
344
- * sources these ids from `headInterval.itemIds` and an item has single-interval membership;
345
- * 3. the active window (`state.items`) if visible — blanking to `[]` when the window empties, per
346
- * {@link flushWindowPublish}.
347
- *
348
- * The coalesced batch collapses all of that into a single `state.items` publish. Then mirror the
349
- * removal into the offline DB (see {@link purgeReconciledFromOfflineDb}) so a cold start does not
350
- * re-seed the ghosts from SQLite. No-op for an empty set, so an unaffected merge does not touch
351
- * state a second time.
597
+ * Whether this list holds `message`: it passes the filter and, in a channel's main list (no
598
+ * `parentMessageId`), is not a reply only its thread lists (see `isThreadOnlyReply`).
352
599
  */
353
- private removeReconciledItems;
600
+ private isListedMessage;
354
601
  /**
355
- * Mirror a destructive reconciliation into the offline DB. A hard delete performed while the client
356
- * was offline reaches it via no event, so the offline store never ran its own hard-delete for these
357
- * ids; the reconnect query re-hydrates the DB by UPSERT (which never removes what is absent from the
358
- * page), so without this the ghosts survive in SQLite and a cold start would re-seed them after the
359
- * in-memory list already dropped them.
602
+ * The failed messages a reload restores with {@link restoreFailedMessages}: those of the shown
603
+ * interval and the head interval, and those of `persisted` (e.g. the offline database's rows of
604
+ * the channel) this list holds (see {@link isListedMessage}). The loaded copy wins, as it is at
605
+ * least as fresh. Take them before the reload's request.
606
+ *
607
+ * @internal
608
+ */
609
+ getFailedMessagesToRestore(persisted?: LocalMessage[]): LocalMessage[];
610
+ /**
611
+ * Ingests again each failed message taken before a reload (see
612
+ * {@link getFailedMessagesToRestore}) that no interval holds after it, so a reload never loses the
613
+ * user's unsent work. One an interval holds is left as it is: it may have been resent.
614
+ *
615
+ * @internal
616
+ */
617
+ restoreFailedMessages(failedMessages: LocalMessage[]): void;
618
+ /**
619
+ * Destructive half of {@link reconcileNewestMessages}: removes loaded head-interval messages
620
+ * that `page` (the fresh newest interval) proves were hard-deleted while the client received no
621
+ * events, by `created_at`:
622
+ *
623
+ * - within `page`'s span: a server-confirmed message absent from `page` was deleted (a live
624
+ * arrival is newer than `page`'s newest, so this needs no snapshot);
625
+ * - at or above `page`'s newest, and for an empty `page`: only IDs in the pre-fetch
626
+ * `headIntervalItemIdsAtRequest` snapshot, which tells a just-deleted message from a live
627
+ * arrival or a send confirmed during the request.
628
+ *
629
+ * Messages below `page`'s oldest are kept (a hard-deleted oldest looks like a server-capped
630
+ * over-request) and returned for {@link removeIdsTailwardOfPageIfNothingOlder}. Removal goes through
631
+ * {@link removeItem}, so the index, intervals, message store and any subclass bookkeeping (e.g.
632
+ * the latest message of {@link MessagePaginator}) stay correct.
360
633
  *
361
- * Owned by the state layer, NOT the SDK: the SDK only supplies the platform `offlineDb`
362
- * implementation and never orchestrates DB writes for reconciliation. Fire-and-forget and
363
- * best-effort — the in-memory removal is the source of truth for the live list, so a failed/absent
364
- * DB write is no worse than before (the ghost merely re-appears on a cold start until the next
365
- * reconcile). No-op when offline support is off (`client.offlineDb` undefined). The ids are already
366
- * server-confirmed (the reconcile excludes pending/failed/optimistic), so a plain hard delete —
367
- * without the pending-task teardown of a local failed message — is correct.
634
+ * @returns The below-interval leftover IDs. Empty for the no-head and empty-page paths.
635
+ */
636
+ protected reconcileHeadAgainstPage(page: LocalMessage[], options?: ReconcileNewestMessagesOptions): string[];
637
+ /** Removes reconciled IDs in one coalesced batch (one publish), then mirrors it offline. */
638
+ private removeReconciledItems;
639
+ /**
640
+ * Mirrors a reconciliation into the offline DB: a hard delete done while offline reaches it via no
641
+ * event and the reconnect query upserts (never removing absent rows), so a cold start would re-seed
642
+ * the ghosts. Fire-and-forget, no-op without offline support.
368
643
  */
369
644
  private purgeReconciledFromOfflineDb;
370
645
  protected resolveUnreadBoundaryIdsByTimestamp: ({ lastReadAt, messages, }: {
371
- lastReadAt: number;
646
+ lastReadAt: TimestampNS;
372
647
  messages: LocalMessage[];
373
648
  }) => {
374
649
  firstUnreadMessageId: string | null;
@@ -380,10 +655,9 @@ export declare class MessageIntervalPaginator extends BasePaginator<LocalMessage
380
655
  ttlMs?: number;
381
656
  }) => MessageFocusSignal;
382
657
  /**
383
- * Starts the auto-dismissal countdown for the currently active focus signal. Call this once the
384
- * focused message has been viewed (rendered and visible), so the highlight's lifetime is measured
385
- * from when the user could actually see it rather than from when the jump resolved. No-op if the
386
- * signal has already been cleared or superseded (guarded by `token`).
658
+ * Starts the auto-dismiss countdown for the active focus signal. Call it once the focused message
659
+ * is viewed, so the highlight lasts from when the user could see it. No-op if the signal was
660
+ * cleared or superseded (guarded by `token`).
387
661
  */
388
662
  scheduleMessageFocusSignalClear: ({ token, ttlMs, }?: {
389
663
  token?: number;
@@ -394,92 +668,60 @@ export declare class MessageIntervalPaginator extends BasePaginator<LocalMessage
394
668
  }) => void;
395
669
  clearStateAndCache(): void;
396
670
  /**
397
- * Partial truncation for `channel.truncated` carrying a `truncated_at`: drop every loaded
398
- * message strictly older than the cutoff (keeping newer ones) across all loaded windows,
399
- * mirroring the legacy per-message-set pruning. For a full truncation (no `truncated_at`) use
400
- * {@link MessageIntervalPaginator.clearStateAndCache} instead.
401
- *
402
- * Batched and edge-classified: because messages are chronological, each interval is classified by
403
- * its `tail` (oldest) and `head` (newest) edges, so only the single interval that *straddles* the
404
- * cutoff is scanned member-by-member — the rest are kept or dropped wholesale. The straddling
405
- * interval becomes the new global tail (nothing older than the cutoff exists anymore), so its
406
- * `isTail`/`hasMoreTail` are set; intervals entirely newer keep their flags (unloaded older
407
- * messages may still sit between them and the cutoff). The active window is re-emitted once.
671
+ * Partial truncation for `channel.truncated` with a `truncated_at`: drops every loaded message
672
+ * strictly older than the cutoff across all intervals (a full truncation uses
673
+ * {@link MessageIntervalPaginator.clearStateAndCache}). Only the interval straddling the cutoff is
674
+ * scanned member by member and becomes the new global tail; intervals entirely newer keep their
675
+ * flags, since unloaded older messages may sit between them and the cutoff. The active interval is
676
+ * re-emitted once.
677
+ */
678
+ truncate({ truncatedAt }: {
679
+ truncatedAt: TimestampNS;
680
+ }): void;
681
+ /**
682
+ * Deletes `userId`'s loaded messages (removes them on a hard delete) and marks the quotes of them
683
+ * as deleted. Returns the messages it deleted, as they were before.
408
684
  */
409
- truncate: ({ truncatedAt }: {
410
- truncatedAt: number;
411
- }) => void;
412
685
  applyMessageDeletionForUser: ({ userId, hardDelete, deletedAt, }: {
413
686
  userId: string;
414
687
  hardDelete?: boolean;
415
- deletedAt: number;
416
- }) => void;
688
+ deletedAt: TimestampNS;
689
+ }) => LocalMessage[];
690
+ /** Updates the quoted-message snapshot of every cached message that quotes `message`. */
691
+ reflectQuotedMessageUpdate: (message: LocalMessage) => void;
417
692
  /**
418
- * Ensures quoted-message snapshots across loaded paginator cache are in sync
419
- * with the provided message.
420
- *
421
- * Scans cached messages and updates any item where `quoted_message_id`
422
- * matches `message.id`.
693
+ * Reflects an updated `user` onto every cached message authored by that user (not
694
+ * `quoted_message.user`). Patches the shared item index in one batch and re-emits the active
695
+ * interval once, if it held an affected message.
423
696
  */
424
- reflectQuotedMessageUpdate: (message: LocalMessage) => void;
697
+ reflectUserUpdate(user: UserResponse): void;
425
698
  /**
426
- * Reflect an updated `user` object onto every cached message authored by that user, mirroring
427
- * the legacy `ChannelState.updateUserMessages` for the main message list (does not touch
428
- * `quoted_message.user` — that is not part of the legacy behavior).
429
- *
430
- * Batched: a user rename can affect many messages, so this patches the shared item index and
431
- * re-emits the active window a single time (if it held an affected message) rather than one
432
- * `ingestItem` re-emit per message.
433
- */
434
- reflectUserUpdate: (user: UserResponse) => void;
435
- /**
436
- * Apply a reaction WS event (`reaction.new` / `reaction.updated` / `reaction.deleted`) to the
437
- * cached message. The event's `message` already carries the server-updated
438
- * `reaction_groups` / `latest_reactions`; only `own_reactions` needs local preservation so a
439
- * cross-user reaction does not wipe the current user's reactions. This re-homes what
440
- * `ChannelState.addReaction` / `removeReaction` used to do off the now-removed
441
- * `channel.state.messages` / `channel.state.threads` caches (the same logic backs the thread
442
- * paginator via `Thread.messagePaginator`).
443
- *
444
- * `own_reactions` is seeded from the currently cached item (so another user's reaction keeps ours),
445
- * falling back to the event's own_reactions when the message is not loaded — matching the legacy
446
- * behavior where `_updateMessage` only mutated a message that existed locally.
447
- *
448
- * @param params - The reaction event payload.
449
- * @param params.message - The reaction event's message, carrying the
450
- * server-computed `reaction_groups` / `latest_reactions`. Ingested as-is except for `own_reactions`.
451
- * @param params.reaction - The reaction from the event. Only added to/removed from
452
- * `own_reactions` when its `user_id` is the current user; otherwise the current user's
453
- * `own_reactions` are left untouched.
454
- * @param [params.removed=false] - `true` for `reaction.deleted` (remove the reaction from
455
- * `own_reactions`); `false` for `reaction.new` / `reaction.updated` (add it).
456
- * @param [params.enforceUnique=false] - When adding, first clear the current user's existing
457
- * `own_reactions` so only the incoming one remains (used by `reaction.updated`, where a user's
458
- * reaction replaces their previous one).
459
- *
460
- * TODO(reactive-store): reflect reactions ONCE at the store level, not per-paginator. Both the
461
- * channel handler (channel.ts) and the thread handler (thread.ts) call this on every reaction.*
462
- * event, so a message held in more than one collection (a show_in_channel reply, or the thread
463
- * parent) is reflected TWICE: two writes to the same canonical slot, each fanning out to the
464
- * other holder (double re-projection) and minting a fresh ref that defeats the reconcile
465
- * ref-equality bail. Idempotent (counts come wholesale from the event) so the result is correct,
466
- * just wasteful. The store already fans out to every holder, so reflect once (by id, if held) and
467
- * retire the per-collection reflect calls + parent path + enforce_unique branch.
468
- */
469
- reflectReaction: ({ enforceUnique, message, reaction, removed, }: {
470
- message: MessageResponse | LocalMessage;
471
- reaction: ReactionResponse;
472
- enforceUnique?: boolean;
473
- removed?: boolean;
474
- }) => void;
699
+ * The last loaded message created at or before `timestamp` (a floor), or `null` when it precedes
700
+ * every loaded message. With `exactTsMatch`, only a message created exactly at `timestamp` matches.
701
+ * Searches the loaded intervals from the head down (each already sorted, O(log n) per interval):
702
+ * the first holding a message at or before `timestamp` holds the answer. Used by the receipts
703
+ * tracker to resolve read/delivered cursors.
704
+ */
705
+ findItemByTimestamp: (timestamp: TimestampNS, exactTsMatch?: boolean) => LocalMessage | null;
475
706
  /**
476
- * Map a timestamp to a loaded message — the first message in the latest (head) window whose
477
- * `created_at` is >= `timestamp` (mirrors the legacy `ChannelState.findMessageByTimestamp`
478
- * lower-bound search), or the newest loaded message when the timestamp is beyond it. Used by the
479
- * receipts tracker to resolve read/delivered cursors. Searches the newest loaded window — where
480
- * read cursors live — which is already sorted, so this is O(log n) with no re-sort.
707
+ * {@link findItemByTimestamp} within one interval (`items` ascending by `created_at`). `undefined`
708
+ * when every item is newer than `timestamp`, so an older interval has to be searched.
481
709
  */
482
- findItemByTimestamp: (timestamp: number, exactTsMatch?: boolean) => LocalMessage | null;
483
- filterQueryResults: (items: LocalMessage[]) => LocalMessage[];
710
+ private findItemByTimestampIn;
711
+ filterQueryResults(items: LocalMessage[]): LocalMessage[];
712
+ /**
713
+ * The sort of a replies request. A page newer than a cursor (`id_gt`, `created_at_after`, ...)
714
+ * must hold the replies right after the cursor, so it is requested oldest first: newest first
715
+ * returns the newest replies and skips the ones in between. The page is put in item order
716
+ * afterwards, so the request sort only decides which replies the page holds.
717
+ */
718
+ private getRepliesRequestSort;
484
719
  private getCanonicalQueryItems;
720
+ /**
721
+ * The cursor and more-messages flags after a page is placed (`deriveCursor`). A page around a
722
+ * point counts the messages the server returned on each side of it. Any other page is compared
723
+ * with the interval's outermost server-known messages (see {@link getServerKnownEdges}): a page
724
+ * never holds an unsent message, so one at an edge must not hide that the page reached the edge.
725
+ */
726
+ private deriveCursorFromPage;
485
727
  }