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
@@ -4,21 +4,16 @@ import type {
4
4
  LocalMessage,
5
5
  MessageResponse,
6
6
  PollResponseData,
7
- QueryPollsFilters,
8
- QueryPollsOptions,
9
- SortParamRequest,
7
+ StreamRequestOptions,
10
8
  } from './types';
9
+ import type { QueryPollsRequest } from './gen/models';
11
10
  import { Poll } from './poll';
12
11
  import { formatMessage } from './utils';
13
12
  import { WithSubscriptions } from './utils/WithSubscriptions';
14
13
 
15
14
  export class PollManager extends WithSubscriptions {
16
15
  private client: StreamChat;
17
- // The pollCache contains only polls that have been created and sent as messages
18
- // (i.e only polls that are coupled with a message, can be voted on and require a
19
- // reactive state). It shall work as a basic look-up table for our SDK to be able
20
- // to quickly consume poll state that will be reactive even without the polls being
21
- // rendered within the UI.
16
+ // Only polls attached to a sent message, so their state stays reactive without being rendered.
22
17
  private pollCache = new Map<string, Poll>();
23
18
 
24
19
  constructor({ client }: { client: StreamChat }) {
@@ -34,7 +29,6 @@ export class PollManager extends WithSubscriptions {
34
29
 
35
30
  public registerSubscriptions = () => {
36
31
  if (this.hasSubscriptions) {
37
- // Already listening for events and changes
38
32
  return;
39
33
  }
40
34
 
@@ -62,14 +56,13 @@ export class PollManager extends WithSubscriptions {
62
56
  public getPoll = async (id: string) => {
63
57
  const cachedPoll = this.fromState(id);
64
58
 
65
- // optimistically return the cached poll if it exists and update in the background
59
+ // Returns the cached poll right away and refreshes it in the background.
66
60
  if (cachedPoll) {
67
61
  this.client
68
62
  .getPoll({ poll_id: id })
69
63
  .then(({ poll }) => this.setOrOverwriteInCache(poll, true));
70
64
  return cachedPoll;
71
65
  }
72
- // fetch it, write to the cache and return otherwise
73
66
  const { poll } = await this.client.getPoll({ poll_id: id });
74
67
 
75
68
  this.setOrOverwriteInCache(poll);
@@ -77,16 +70,19 @@ export class PollManager extends WithSubscriptions {
77
70
  return this.fromState(id);
78
71
  };
79
72
 
73
+ /**
74
+ * Queries polls and caches them as `Poll` instances. Takes the same request as `client.queryPolls`.
75
+ *
76
+ * @param request - The filter, sort and pagination of the query (optional).
77
+ * @param requestOptions - Per-request options such as an abort `signal`. Never serialized
78
+ * into the request (optional).
79
+ * @returns The `Poll` instances and the cursor of the next page.
80
+ */
80
81
  public queryPolls = async (
81
- filter: QueryPollsFilters,
82
- sort: SortParamRequest[] = [],
83
- options: QueryPollsOptions = {},
82
+ request: QueryPollsRequest = {},
83
+ requestOptions?: StreamRequestOptions,
84
84
  ) => {
85
- const { polls, next } = await this.client.queryPolls({
86
- filter,
87
- sort,
88
- ...options,
89
- });
85
+ const { polls, next } = await this.client.queryPolls(request, requestOptions);
90
86
 
91
87
  const pollInstances = polls.map((poll) => {
92
88
  this.setOrOverwriteInCache(poll, true);
@@ -161,7 +157,7 @@ export class PollManager extends WithSubscriptions {
161
157
  }
162
158
  }).unsubscribe;
163
159
 
164
- // votes carry a copy of their voter, so a changed name or image reaches the polls only from here
160
+ // Votes carry a copy of their voter, so a changed name or image reaches the polls only from here.
165
161
  private subscribeUserUpdated = () =>
166
162
  this.client.on('user.updated', (event) => {
167
163
  const { user } = event;
@@ -20,12 +20,11 @@ type OwnVoteChange = { optionId: OptionId; vote?: PollVoteResponseData };
20
20
  const CATCH_UP_TIMEOUT_MS = 3000;
21
21
 
22
22
  /**
23
- * Optimistic updates for the current user's votes on a poll. Vote changes are shown right away.
24
- * While any of them is not confirmed by its WS event, vote events are only stored, as the server
25
- * state they carry does not contain the pending changes yet. Once all are confirmed (a failed
26
- * request counts as confirmed), the server's vote state is shown, which also reverts failed changes.
27
- * Vote requests are sent one after another, so the server applies them in the order they were made.
28
- * A lost WS event is recovered from after CATCH_UP_TIMEOUT_MS (see applySucceededChanges).
23
+ * Optimistic updates for the current user's votes on a poll. While any change awaits its WS event,
24
+ * vote events are only stored (the state they carry lacks the pending changes). Once all are
25
+ * confirmed (a failed request counts as confirmed), the server's vote state is shown, which reverts
26
+ * failed changes. A lost WS event is recovered from after CATCH_UP_TIMEOUT_MS (see
27
+ * applySucceededChanges).
29
28
  */
30
29
  export class OptimisticPollVotes {
31
30
  // The server's vote state. WS events only carry the vote that changed, so own votes are kept here.
@@ -67,7 +66,7 @@ export class OptimisticPollVotes {
67
66
  { vote: { option_id: optionId } },
68
67
  );
69
68
  const state = this.poll.data;
70
- // already voted for this option, there is nothing to show
69
+ // Already voted for this option: nothing to show.
71
70
  if (state.ownVotesByOptionId[optionId]) return this.send(sendRequest);
72
71
 
73
72
  const replacedVotes = state.enforce_unique_vote
@@ -85,7 +84,6 @@ export class OptimisticPollVotes {
85
84
  }));
86
85
  };
87
86
 
88
- // Removes a vote, right away.
89
87
  removeVote = (voteId: string, messageId: string) => {
90
88
  const sendRequest = (id: string) =>
91
89
  this.client.deletePollVote({
@@ -95,16 +93,16 @@ export class OptimisticPollVotes {
95
93
  });
96
94
  const state = this.poll.data;
97
95
  const vote = Object.values(state.ownVotesByOptionId).find(({ id }) => id === voteId);
98
- // not a shown own vote, there is nothing to show
96
+ // Not a shown own vote: nothing to show.
99
97
  if (!vote?.option_id) return this.send(() => sendRequest(voteId));
100
98
 
101
99
  const optionId = vote.option_id;
102
100
  this.poll.state.partialNext(applyOwnVoteDelta(state, { remove: [vote] }));
103
101
  return this.track(
104
- // runs when the removal's turn comes, so a preceding cast of the vote has finished
102
+ // Runs on the removal's turn, after a preceding cast of the vote has finished.
105
103
  () => {
106
104
  const serverVoteId = this.getServerVoteId(vote);
107
- // the vote's cast failed, so there is nothing to remove
105
+ // The cast failed: nothing to remove.
108
106
  return serverVoteId ? sendRequest(serverVoteId) : Promise.resolve(undefined);
109
107
  },
110
108
  () => ({ optionId }),
@@ -116,7 +114,7 @@ export class OptimisticPollVotes {
116
114
  try {
117
115
  return (await withoutConcurrency(this.requestTag, sendRequest)) as T;
118
116
  } finally {
119
- // once nothing is left to send, wait for the WS events of the pending changes
117
+ // Nothing left to send: wait for the WS events of the pending changes.
120
118
  if (!hasPending(this.requestTag)) this.scheduleCatchUp();
121
119
  }
122
120
  };
@@ -163,7 +161,7 @@ export class OptimisticPollVotes {
163
161
  try {
164
162
  response = await this.send(async () => {
165
163
  const result = await sendRequest();
166
- // recorded before the next request is sent, as a removal looks up the vote id in here
164
+ // Recorded before the next request is sent: a removal looks up the vote ID in here.
167
165
  if (result !== undefined) this.succeededChanges.push(toChange(result));
168
166
  return result;
169
167
  });
@@ -196,10 +194,9 @@ export class OptimisticPollVotes {
196
194
  };
197
195
 
198
196
  /**
199
- * The server id of a vote to remove, once everything sent before the removal has finished. Casts
200
- * and removals of an option alternate, so the option's last succeeded change tells: a cast is the
201
- * vote being removed (e.g. a placeholder), a removal means the cast in between failed. Without
202
- * one, the server's own vote of the option is the vote being removed.
197
+ * The server ID of the vote to remove. Casts and removals of an option alternate, so the option's
198
+ * last succeeded change tells: a cast is the vote being removed (e.g. a placeholder), a removal
199
+ * means the cast in between failed. Without one, the server's own vote of the option is used.
203
200
  */
204
201
  private getServerVoteId = (vote: PollVoteResponseData) => {
205
202
  for (let i = this.succeededChanges.length - 1; i >= 0; i--) {
@@ -226,10 +223,8 @@ export class OptimisticPollVotes {
226
223
 
227
224
  /**
228
225
  * A WS event of an own vote change got lost, so the server's own votes are stale. All requests
229
- * have finished (the timeout starts once nothing is left to send and a new request cancels it),
230
- * so applying the succeeded changes in order gives the server's own votes (changes whose events
231
- * did arrive end up the same). They are shown with the vote counts of the last WS event, which
232
- * contain the other users' votes too.
226
+ * have finished, so replaying the succeeded changes in order gives the server's own votes. They
227
+ * are shown with the vote counts of the last WS event, which include other users' votes.
233
228
  */
234
229
  private applySucceededChanges = () => {
235
230
  const { enforce_unique_vote } = this.poll.data;
@@ -283,7 +278,7 @@ function applyOwnVoteDelta(
283
278
  const optionId = vote.option_id;
284
279
  if (!optionId) continue;
285
280
  delete ownVotesByOptionId[optionId];
286
- // the server omits options without votes, so a count that drops to 0 is removed
281
+ // The server omits options without votes, so a count that drops to 0 is removed.
287
282
  const optionVoteCount = (voteCountsByOption[optionId] ?? 0) - 1;
288
283
  if (optionVoteCount > 0) {
289
284
  voteCountsByOption[optionId] = optionVoteCount;
@@ -10,10 +10,10 @@ import type {
10
10
  } from '../types';
11
11
 
12
12
  /**
13
- * Milliseconds until `remindAt`, negative once it has passed.
13
+ * Computes the time left until a reminder is due.
14
14
  *
15
- * @param remindAt - Unix nanoseconds, as the API sends it. The subtraction happens in the wire unit
16
- * and is converted once, so the returned duration stays in the milliseconds `setTimeout` speaks.
15
+ * @param remindAt - Unix nanoseconds, as the API sends it.
16
+ * @returns Milliseconds until `remindAt`, negative once it has passed.
17
17
  */
18
18
  export const timeLeftMs = (remindAt: TimestampNS) => nsToMs(remindAt - nowNs());
19
19
 
@@ -27,7 +27,7 @@ export type ReminderState = {
27
27
  message_id: string;
28
28
  /** Unix nanoseconds, as the API sends it. */
29
29
  remind_at: TimestampNS | null;
30
- /** A duration, so milliseconds — see {@link timeLeftMs}. */
30
+ /** Milliseconds. See {@link timeLeftMs}. */
31
31
  timeLeftMs: number | null;
32
32
  /** Unix nanoseconds, as the API sends it. */
33
33
  updated_at: TimestampNS;
@@ -54,8 +54,7 @@ export class Reminder {
54
54
  created_at: data.created_at,
55
55
  message: data.message || null,
56
56
  remind_at: data.remind_at ?? null,
57
- // Nullish rather than truthy: `0` is a legitimate timestamp (the epoch), and treating it as
58
- // "no reminder set" is a real bug now that these are numbers rather than `Date` objects.
57
+ // Nullish, not truthy: `0` is a valid timestamp.
59
58
  timeLeftMs: data.remind_at != null ? timeLeftMs(data.remind_at) : null,
60
59
  updated_at: data.updated_at,
61
60
  user: data.user || null,
@@ -54,14 +54,8 @@ export type ReminderManagerOptions = {
54
54
 
55
55
  export class ReminderManager extends WithSubscriptions {
56
56
  private client: StreamChat;
57
- /** The shared configuration machinery — see {@link ConfigController}. */
58
57
  private readonly configController: ConfigController<ReminderManagerConfig>;
59
58
 
60
- /**
61
- * Resolved configuration, as a store — the shape every configurable class exposes
62
- * (`configState` / `config` / `updateConfig`). Delegates rather than holding a copy, so the field and
63
- * the controller's store cannot drift.
64
- */
65
59
  get configState(): StateStore<ReminderManagerConfig> {
66
60
  return this.configController.state;
67
61
  }
@@ -74,8 +68,7 @@ export class ReminderManager extends WithSubscriptions {
74
68
  this.configController = new ConfigController<ReminderManagerConfig>({
75
69
  defaults: DEFAULT_REMINDER_MANAGER_CONFIG,
76
70
  constructorOptions: config,
77
- // Live timers hold the boundary, so a change has to be pushed to them. Previously this sat inside
78
- // `updateConfig` and so ran only on that route; here it covers every write.
71
+ // Live timers hold the boundary, so a change is pushed to them.
79
72
  onChanged: (next, previous) => {
80
73
  if (next.stopTimerRefreshBoundaryMs === previous.stopTimerRefreshBoundaryMs)
81
74
  return;
@@ -88,32 +81,24 @@ export class ReminderManager extends WithSubscriptions {
88
81
  this.paginator = new ReminderPaginator(client);
89
82
  }
90
83
 
91
- // Config API START //
92
- /**
93
- * The current resolved configuration. `Readonly` because the value is the store's live object —
94
- * assigning to a field of it would change state without notifying anyone. Use {@link updateConfig}.
95
- */
96
84
  get config(): Readonly<ReminderManagerConfig> {
97
85
  return this.configState.getLatestValue();
98
86
  }
99
87
 
88
+ /**
89
+ * Merges a partial configuration into the resolved config.
90
+ *
91
+ * @param config - Fields to merge into the resolved config.
92
+ */
100
93
  updateConfig(config: Partial<ReminderManagerConfig>) {
101
94
  this.configController.patch(config);
102
95
  }
103
96
 
104
97
  /**
105
- * Rebuilds the resolved configuration from package defaults plus the declarative slice.
98
+ * Re-derives the configuration from the declarative slice.
106
99
  *
107
- * The derivation entry point every configurable entity exposes, so the owner routes a slice here and
108
- * knows nothing about ReminderManager's defaults or merge semantics. This logic used to live in the owner,
109
- * which is how `reset()` became a no-op for the client key (F4) and how a registered
110
- * `notifications.sortComparator` became unremovable (G8) — an owner writing another object's
111
- * derivation gets that object's rules wrong sooner or later.
112
- *
113
- * Routed through {@link updateConfig} rather than replacing the store, which is exact here because
114
- * every field of `ReminderManagerConfig` is required and present in the defaults, so a patch naming all of
115
- * them amounts to a replacement. `NotificationManager` cannot do this — its `sortComparator` is
116
- * optional with no default, so a patch can never remove one — which is why it replaces outright.
100
+ * @param config - The declarative slice. Leave it out to rebuild from the defaults and the
101
+ * constructor's `config`.
117
102
  */
118
103
  initializeConfig(config?: Partial<ReminderManagerConfig>) {
119
104
  this.configController.initialize(config);
@@ -126,9 +111,7 @@ export class ReminderManager extends WithSubscriptions {
126
111
  get scheduledOffsetsMs() {
127
112
  return this.configState.getLatestValue().scheduledOffsetsMs;
128
113
  }
129
- // Config API END //
130
114
 
131
- // State API START //
132
115
  get reminders() {
133
116
  return this.state.getLatestValue().reminders;
134
117
  }
@@ -174,9 +157,7 @@ export class ReminderManager extends WithSubscriptions {
174
157
  }
175
158
  });
176
159
  };
177
- // State API END //
178
160
 
179
- // Timers API START //
180
161
  initTimers = () => {
181
162
  this.reminders.forEach((reminder) => reminder.initTimer());
182
163
  };
@@ -184,9 +165,7 @@ export class ReminderManager extends WithSubscriptions {
184
165
  clearTimers = () => {
185
166
  this.reminders.forEach((reminder) => reminder.clearTimer());
186
167
  };
187
- // Timers API END //
188
168
 
189
- // WS event handling START //
190
169
  static isReminderWsEventPayload = (event: Event): event is ReminderEvent =>
191
170
  'reminder' in event &&
192
171
  !!event.reminder &&
@@ -270,9 +249,7 @@ export class ReminderManager extends WithSubscriptions {
270
249
  }
271
250
  },
272
251
  );
273
- // WS event handling END //
274
252
 
275
- // API calls START //
276
253
  upsertReminder = async (...args: Parameters<ChatApi['createReminder']>) => {
277
254
  const [{ message_id }] = args;
278
255
  if (this.getFromState(message_id)) {
@@ -318,6 +295,4 @@ export class ReminderManager extends WithSubscriptions {
318
295
  queryPreviousReminders = async () => {
319
296
  await this.paginator.toHead();
320
297
  };
321
-
322
- // API calls END //
323
298
  }
@@ -60,8 +60,7 @@ export class ReminderTimer {
60
60
  const timeoutLength = this.getRefreshIntervalLength();
61
61
  if (timeoutLength === null) return null;
62
62
 
63
- // `stopRefreshBoundaryMs` is a duration in milliseconds, so it is applied after the wire
64
- // timestamp has been converted rather than added to it.
63
+ // Stops refreshing once the deadline is more than `stopRefreshBoundaryMs` in the past.
65
64
  const timeLeftToBoundary =
66
65
  timeLeftMs(this.reminder.remindAt) + this.stopRefreshBoundaryMs;
67
66
 
@@ -10,10 +10,8 @@ import type { APIError } from '../errors';
10
10
  import { isAPIError, isErrorRetryable } from '../errors';
11
11
 
12
12
  /**
13
- * Passed to a search source's `query()`. Carries a cancellation handle and makes no
14
- * claim that the query performs a request: a source may resolve from local data and
15
- * ignore the signal. Where a source does issue requests, forward this straight through
16
- * as the request options.
13
+ * Passed to a search source's `query()`. A source that issues requests forwards it as the request
14
+ * options; one that resolves from local data may ignore the signal.
17
15
  */
18
16
  export type SearchQueryOptions = {
19
17
  /** Aborted once a newer query supersedes this one. */
@@ -35,10 +33,7 @@ interface ISearchSource<T = any> {
35
33
 
36
34
  deactivate(): void;
37
35
 
38
- /**
39
- * Releases what the source holds outside itself. Optional; a source that holds nothing outside
40
- * itself leaves it out.
41
- */
36
+ /** Releases what the source holds outside itself. */
42
37
  dispose?(): void;
43
38
 
44
39
  readonly hasNext: boolean;
@@ -51,7 +46,7 @@ interface ISearchSource<T = any> {
51
46
  readonly next: string | undefined | null;
52
47
  readonly offset: number | undefined;
53
48
 
54
- /** Takes again what {@link ISearchSource.dispose} released. Optional, like `dispose`. */
49
+ /** Takes again what {@link ISearchSource.dispose} released. */
55
50
  registerSubscriptions?(): void;
56
51
 
57
52
  resetState(): void;
@@ -83,11 +78,7 @@ const DEFAULT_SEARCH_SOURCE_OPTIONS: Required<
83
78
  resetOnNewSearchQuery: true,
84
79
  } as const;
85
80
 
86
- /**
87
- * An explicit `debounceMs` applies to both buckets, so integrators who already tuned it
88
- * keep exactly their configured interval. Only when it is absent do the 500/300 defaults
89
- * kick in.
90
- */
81
+ /** An explicit `debounceMs` applies to both buckets. The 500/300 defaults apply only without it. */
91
82
  const resolveDebounceOptions = ({
92
83
  debounceMs,
93
84
  shortQueryDebounceMs,
@@ -123,8 +114,7 @@ abstract class BaseSearchSourceBase<
123
114
  this.allowEmptySearchString = allowEmptySearchString;
124
115
  this.resetOnNewSearchQuery = resetOnNewSearchQuery;
125
116
  this.state = new StateStore<SearchSourceState<T>>(this.initialState);
126
- // Field initializers run before this body, so setDebounceOptions is already
127
- // assigned; it only captures getDebounceMs lazily.
117
+ // `setDebounceOptions` is a field initializer, so it is already assigned here.
128
118
  this.setDebounceOptions(options ?? {});
129
119
  }
130
120
 
@@ -142,7 +132,7 @@ abstract class BaseSearchSourceBase<
142
132
 
143
133
  /**
144
134
  * Short queries match too much and are slow server-side, so they get a longer debounce.
145
- * Resolved per call, which is what lets the interval switch as the user keeps typing.
135
+ * Resolved per call, so the interval switches as the user keeps typing.
146
136
  */
147
137
  protected getDebounceMs = (searchString?: string) => {
148
138
  const { length } = searchString ?? this.searchQuery;
@@ -250,7 +240,7 @@ abstract class BaseSearchSourceBase<
250
240
  const current = this.state.getLatestValue();
251
241
  return {
252
242
  ...current,
253
- lastQueryError: undefined, // reset lastQueryError that can be overridden by the stateUpdate
243
+ lastQueryError: undefined, // cleared unless `stateUpdate` sets it
254
244
  ...stateUpdate,
255
245
  isLoading: false,
256
246
  items: isFirstPage
@@ -301,7 +291,7 @@ export abstract class BaseSearchSource<T>
301
291
  extends BaseSearchSourceBase<T, Promise<void>>
302
292
  implements SearchSource<T>
303
293
  {
304
- /** Aborts the in-flight request, if any, once a newer query is dispatched. */
294
+ /** Aborted when a newer query is dispatched. */
305
295
  protected queryAbortController: AbortController | null = null;
306
296
 
307
297
  protected abstract query(
@@ -311,7 +301,7 @@ export abstract class BaseSearchSource<T>
311
301
 
312
302
  protected abstract filterQueryResults(items: T[]): T[] | Promise<T[]>;
313
303
 
314
- /** Aborts the in-flight request, if any. Returns true when one was aborted. */
304
+ /** Returns true when a request was aborted. */
315
305
  protected abortInFlightQuery() {
316
306
  if (!this.queryAbortController) return false;
317
307
  this.queryAbortController.abort();
@@ -326,11 +316,9 @@ export abstract class BaseSearchSource<T>
326
316
  }
327
317
 
328
318
  async executeQuery(newSearchString?: string) {
329
- // Checked before anything is dispatched, so that the abort below always has a
330
- // successor that will clear isLoading.
319
+ // Checked first, so the abort below always has a successor that clears `isLoading`.
331
320
  if (!this.canExecuteQuery(newSearchString)) return;
332
321
 
333
- // cancel the previous request before dispatching the new one
334
322
  this.abortInFlightQuery();
335
323
  const { signal } = (this.queryAbortController = new AbortController());
336
324
 
@@ -351,8 +339,7 @@ export abstract class BaseSearchSource<T>
351
339
  stateUpdate.hasNext = false;
352
340
  }
353
341
  } finally {
354
- // A newer query owns the state now - publishing here would clobber it with a
355
- // stale result (and with the abort error).
342
+ // A newer query owns the state: publishing here would overwrite it with a stale result.
356
343
  if (!signal.aborted) {
357
344
  this.state.next(this.getStateAfterQuery(stateUpdate, hasNewSearchQuery));
358
345
  }
@@ -361,16 +348,14 @@ export abstract class BaseSearchSource<T>
361
348
 
362
349
  cancelScheduledQuery() {
363
350
  this.searchDebounced.cancel();
364
- // Nothing will dispatch a successor query, so release the loading state the
365
- // aborted query owned - its own finally block skips the state write.
351
+ // No successor will clear `isLoading`, and the aborted query's `finally` skips the write.
366
352
  if (this.abortInFlightQuery() && this.isLoading) {
367
353
  this.state.partialNext({ isLoading: false });
368
354
  }
369
355
  }
370
356
  }
371
357
 
372
- // Queries are resolved locally, so there is nothing to cancel here - only the
373
- // dynamic debounce applies.
358
+ // Queries resolve locally: nothing to cancel, only the debounce applies.
374
359
  export abstract class BaseSearchSourceSync<T>
375
360
  extends BaseSearchSourceBase<T, void>
376
361
  implements SearchSourceSync<T>
@@ -17,8 +17,8 @@ export type ChannelSearchSourceOptions = SearchSourceOptions & {
17
17
  filters?: ChannelFilters;
18
18
  sort?: SortParamRequest[];
19
19
  /**
20
- * Query options. Results are not watched unless `watch: true` is passed: not watched channels serve as a preview,
21
- * and opening one is what watches it.
20
+ * Query options. Results are not watched unless `watch: true`: they are previews, and opening
21
+ * one watches it.
22
22
  */
23
23
  searchOptions?: Omit<ChannelOptions, 'limit' | 'offset'>;
24
24
  };
@@ -67,7 +67,7 @@ export class ChannelSearchSource<
67
67
  },
68
68
  });
69
69
 
70
- // A subscription to the source's own state, so it lives and goes with the source itself.
70
+ // Subscribed to the source's own state, so it goes away with the source.
71
71
  this.state.subscribeWithSelector(
72
72
  ({ isActive }) => ({ isActive }),
73
73
  () => this.registerSubscriptions(),
@@ -75,9 +75,9 @@ export class ChannelSearchSource<
75
75
  }
76
76
 
77
77
  /**
78
- * While the search is active its results are on screen, so they count as used in the channel store
79
- * (see `EntityStore.addClaim`). Follows `isActive`; also called by
80
- * `SearchController.registerSubscriptions()` to take the registration again after `dispose()`.
78
+ * While active, the results count as used in the channel store (see `EntityStore.addClaim`).
79
+ * Follows `isActive`; `SearchController.registerSubscriptions()` also calls it to re-register
80
+ * after `dispose()`.
81
81
  */
82
82
  registerSubscriptions() {
83
83
  if (!this.isActive) {
@@ -91,8 +91,8 @@ export class ChannelSearchSource<
91
91
  }
92
92
 
93
93
  /**
94
- * Removes the registration that keeps the results in the channel store, so a source that is
95
- * dropped while active doesn't keep them, or itself, alive. A later activation registers again.
94
+ * Removes the channel-store claim, so the results' channels are no longer held and a dropped
95
+ * source can be collected.
96
96
  */
97
97
  dispose() {
98
98
  this.removeClaim?.();
@@ -14,20 +14,17 @@ import type { Channel } from '../channel';
14
14
 
15
15
  type CustomContext = Record<string, unknown>;
16
16
 
17
- // Built-in contexts per builder
18
17
  type BuiltInContexts = {
19
18
  messageSearchChannel: { searchQuery?: string };
20
19
  messageSearch: { searchQuery?: string };
21
20
  channelQuery: { cids?: string[] };
22
21
  };
23
22
 
24
- // Merge Built-in with user-provided Custom context
25
23
  type MergeContext<
26
24
  B extends Record<string, unknown>,
27
25
  C extends CustomContext | undefined,
28
26
  > = B & (C extends object ? C : {});
29
27
 
30
- // User can provide custom context for each builder
31
28
  type MessageSearchSourceContexts = Partial<{
32
29
  messageSearchChannelContext: Record<string, unknown>;
33
30
  messageSearchContext: Record<string, unknown>;
@@ -64,9 +61,8 @@ export type MessageSearchSourceOptions = SearchSourceOptions & {
64
61
  channelQueryFilters?: ChannelFilters;
65
62
  channelQuerySort?: SortParamRequest[];
66
63
  /**
67
- * Options for the follow-up query that hydrates unknown channels. Those channels are not watched
68
- * unless `watch: true` is passed: a result is a preview, and opening one is what watches its
69
- * channel.
64
+ * Options for the follow-up query that hydrates unknown channels. They are not watched unless
65
+ * `watch: true`: a result is a preview, and opening one watches its channel.
70
66
  */
71
67
  channelQueryOptions?: Omit<ChannelOptions, 'limit' | 'offset'>;
72
68
  };
@@ -162,7 +158,7 @@ export class MessageSearchSource<
162
158
  },
163
159
  });
164
160
 
165
- // A subscription to the source's own state, so it lives and goes with the source itself.
161
+ // Subscribed to the source's own state, so it goes away with the source.
166
162
  this.state.subscribeWithSelector(
167
163
  ({ isActive }) => ({ isActive }),
168
164
  () => this.registerSubscriptions(),
@@ -170,10 +166,9 @@ export class MessageSearchSource<
170
166
  }
171
167
 
172
168
  /**
173
- * While the search is active its results are on screen, so the channels they were found in count
174
- * as used in the channel store (see `EntityStore.addClaim`), and stay the instances the results
175
- * open. Follows `isActive`; also called by `SearchController.registerSubscriptions()` to take the
176
- * registration again after `dispose()`.
169
+ * While active, the channels the results come from count as used in the channel store (see
170
+ * `EntityStore.addClaim`), so they stay the instances the results open. Follows `isActive`;
171
+ * `SearchController.registerSubscriptions()` also calls it to re-register after `dispose()`.
177
172
  */
178
173
  registerSubscriptions() {
179
174
  if (!this.isActive) {
@@ -187,8 +182,8 @@ export class MessageSearchSource<
187
182
  }
188
183
 
189
184
  /**
190
- * Removes the registration that keeps the results' channels in the channel store, so a source that
191
- * is dropped while active doesn't keep them, or itself, alive. A later activation registers again.
185
+ * Removes the channel-store claim, so the results' channels are no longer held and a dropped
186
+ * source can be collected.
192
187
  */
193
188
  dispose() {
194
189
  this.removeClaim?.();
@@ -232,6 +227,13 @@ export class MessageSearchSource<
232
227
  >,
233
228
  });
234
229
 
230
+ const customSort = this.messageSearchSort ?? [];
231
+ const createdAtSort = customSort.find(({ field }) => field === 'created_at');
232
+ const sort: SortParamRequest[] = [
233
+ { field: 'created_at', direction: createdAtSort?.direction ?? -1 },
234
+ ...customSort.filter(({ field }) => field !== 'created_at'),
235
+ ];
236
+
235
237
  const { next, results } = await this.client.search(
236
238
  {
237
239
  payload: {
@@ -239,13 +241,7 @@ export class MessageSearchSource<
239
241
  message_filter_conditions: messageFilters,
240
242
  limit: this.pageSize,
241
243
  next: this.next,
242
- sort: [
243
- {
244
- field: 'created_at',
245
- direction: -1,
246
- },
247
- ...(this.messageSearchSort ?? []),
248
- ],
244
+ sort,
249
245
  },
250
246
  },
251
247
  queryOptions,
@@ -255,7 +251,7 @@ export class MessageSearchSource<
255
251
  .map(({ message }) => message)
256
252
  .filter((m): m is NonNullable<typeof m> => Boolean(m));
257
253
 
258
- // a newer query already replaced this one - skip the cid scan and the hydration request
254
+ // Superseded by a newer query: skip the hydration.
259
255
  if (queryOptions.signal?.aborted) return { items, next };
260
256
 
261
257
  const cids = Array.from(
@@ -287,10 +283,8 @@ export class MessageSearchSource<
287
283
 
288
284
  if (queryOptions.signal?.aborted) return { items, next };
289
285
 
290
- // The query above doesn't return every result's channel: it leaves out hidden channels by
291
- // default, and those its filters exclude. Each result carries its channel's data, so such a
292
- // channel is stored from it, unwatched and not loaded, and every result has a channel to show and
293
- // to open (opening loads and watches it).
286
+ // The hydration query can miss a result's channel (hidden or filtered out): store it from the
287
+ // message's channel data, unwatched, so every result has a channel to open.
294
288
  for (const message of items) {
295
289
  if (!message.cid) continue;
296
290
  const stored = this.client.channelManager.get(message.cid);