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
@@ -18,7 +18,7 @@ import {
18
18
  userResponseToMentionEntity,
19
19
  } from './middleware/textComposer/mentionUtils';
20
20
  import type { MessageComposer } from './messageComposer';
21
- import type { Command, DraftMessage, Event, LocalMessage, UserResponse } from '../types';
21
+ import type { Command, DraftMessage, LocalMessage, UserResponse } from '../types';
22
22
 
23
23
  export type TextComposerOptions = {
24
24
  composer: MessageComposer;
@@ -86,9 +86,7 @@ const getInitialMentions = (message?: DraftMessage | LocalMessage): MentionEntit
86
86
  })),
87
87
  );
88
88
  } else if (message.mentioned_group_ids?.length) {
89
- // Composer rehydration can still receive draft/local request-shaped data, where
90
- // group mentions are represented only by ids even though response/render paths use
91
- // `mentioned_groups` for presentation metadata.
89
+ // Request-shaped drafts carry group mentions as IDs only.
92
90
  mentions.push(
93
91
  ...message.mentioned_group_ids.map((groupId) => ({
94
92
  id: groupId,
@@ -120,7 +118,6 @@ const initState = ({
120
118
  mentionedUsers: [],
121
119
  mentions: [],
122
120
  text,
123
- typing: {},
124
121
  selection: { start: text.length, end: text.length },
125
122
  };
126
123
  }
@@ -134,7 +131,6 @@ const initState = ({
134
131
  mentionedUsers,
135
132
  mentions,
136
133
  text,
137
- typing: {},
138
134
  selection: { start: text.length, end: text.length },
139
135
  };
140
136
  };
@@ -163,11 +159,6 @@ export class TextComposer {
163
159
  }
164
160
 
165
161
  set enabled(enabled: boolean) {
166
- // No early return on "same value". The guard that used to be here compared against the *effective*
167
- // value, while the write it skipped records the *requested* one — so asking for a value the server
168
- // was currently masking recorded nothing, and the earlier request stayed in the patch layer to be
169
- // honoured the moment the server relented. `ConfigController.write` already skips a publish when the
170
- // resolved value does not move, which is the same guard applied to the right value.
171
162
  this.composer.updateConfig({ text: { enabled } });
172
163
  }
173
164
 
@@ -185,11 +176,8 @@ export class TextComposer {
185
176
  }
186
177
 
187
178
  set maxLengthOnEdit(maxLengthOnEdit: number | undefined) {
188
- // No early return on "same value". The guard that used to be here compared against the *effective*
189
- // value, while the write it skipped records the *requested* one — so asking for a value the server
190
- // was currently masking recorded nothing, and the earlier request stayed in the patch layer to be
191
- // honoured the moment the server relented. `ConfigController.write` already skips a publish when the
192
- // resolved value does not move, which is the same guard applied to the right value.
179
+ // No same-value early return: the getter reads the effective value, and a request the server
180
+ // masks must still be recorded.
193
181
  this.composer.updateConfig({ text: { maxLengthOnEdit } });
194
182
  }
195
183
 
@@ -198,11 +186,8 @@ export class TextComposer {
198
186
  }
199
187
 
200
188
  set maxLengthOnSend(maxLengthOnSend: number | undefined) {
201
- // No early return on "same value". The guard that used to be here compared against the *effective*
202
- // value, while the write it skipped records the *requested* one — so asking for a value the server
203
- // was currently masking recorded nothing, and the earlier request stayed in the patch layer to be
204
- // honoured the moment the server relented. `ConfigController.write` already skips a publish when the
205
- // resolved value does not move, which is the same guard applied to the right value.
189
+ // No same-value early return: the getter reads the effective value, and a request the server
190
+ // masks must still be recorded.
206
191
  this.composer.updateConfig({ text: { maxLengthOnSend } });
207
192
  }
208
193
 
@@ -215,8 +200,6 @@ export class TextComposer {
215
200
  this.composer.updateConfig({ text: { publishTypingEvents } });
216
201
  }
217
202
 
218
- // --- START STATE API ---
219
-
220
203
  get command() {
221
204
  return this.state.getLatestValue().command;
222
205
  }
@@ -241,29 +224,6 @@ export class TextComposer {
241
224
  return this.state.getLatestValue().text;
242
225
  }
243
226
 
244
- get typing() {
245
- return this.state.getLatestValue().typing;
246
- }
247
-
248
- set typing(typing: Record<string, Event>) {
249
- this.state.partialNext({ typing });
250
- }
251
-
252
- setTyping = (typing: Record<string, Event>) => {
253
- this.typing = typing;
254
- };
255
-
256
- setTypingEvent = (userId: string, event: Event) => {
257
- this.typing = { ...this.typing, [userId]: event };
258
- };
259
-
260
- removeTypingEvent = (userId: string) => {
261
- if (!this.typing[userId]) return;
262
- const typing = { ...this.typing };
263
- delete typing[userId];
264
- this.typing = typing;
265
- };
266
-
267
227
  get textIsEmpty() {
268
228
  return textIsEmpty(this.text);
269
229
  }
@@ -273,9 +233,8 @@ export class TextComposer {
273
233
  };
274
234
 
275
235
  /**
276
- * Takes over `source`'s text: the text, selection, mentions and command. Not its suggestions,
277
- * which belong to `source`'s open search, nor its typing events, which are the other users' in
278
- * `source`'s channel.
236
+ * Takes over `source`'s text, selection, mentions and command, not its suggestions (they belong to
237
+ * `source`'s open search).
279
238
  *
280
239
  * @internal
281
240
  */
@@ -444,12 +403,7 @@ export class TextComposer {
444
403
  selection?: TextSelection;
445
404
  }) => {
446
405
  if (!this.enabled) return;
447
- /**
448
- * Windows inserts \r\n; macOS inserts \n.
449
- * The caret can fall inside a CRLF pair during repeated pastes on Windows.
450
- * That corrupts newline alignment (a\nb\na\nba\nb\n\n).
451
- * Normalize the text to prevent it.
452
- */
406
+ // Normalize CRLF: a caret inside a CRLF pair during repeated pastes (Windows) corrupts newlines.
453
407
  const normalizedText = text.replace(/\r\n/g, '\n');
454
408
  const finalSelection: TextSelection = selection ?? this.selection;
455
409
  const { maxLengthOnEdit } = this.composer.config.text ?? {};
@@ -509,7 +463,6 @@ export class TextComposer {
509
463
  if (!suggestions) return;
510
464
  this.state.partialNext({ suggestions: undefined });
511
465
  };
512
- // --- END STATE API ---
513
466
 
514
467
  private commitState = (state: TextComposerMiddlewareExecutorState) => {
515
468
  const { change, effects, ...nextState } = state;
@@ -519,8 +472,6 @@ export class TextComposer {
519
472
  this.composer.applyEffects(effects);
520
473
  };
521
474
 
522
- // --- START TEXT PROCESSING ----
523
-
524
475
  handleChange = async ({
525
476
  text,
526
477
  selection,
@@ -563,5 +514,4 @@ export class TextComposer {
563
514
  if (output?.status === 'discard') return;
564
515
  this.commitState(output.state);
565
516
  };
566
- // --- END TEXT PROCESSING ----
567
517
  }
@@ -91,25 +91,22 @@ export type BaseLocalAttachmentMetadata = {
91
91
 
92
92
  export type LocalAttachmentUploadMetadata = {
93
93
  file: File | FileReference;
94
- /**
95
- * Local preview URI, typically a Blob URL from `URL.createObjectURL(file)`
96
- * or (for React Native `FileReference`) the provided `uri`.
97
- */
94
+ /** Local preview URI: a Blob URL for a `File`, or the `uri` of a React Native `FileReference`. */
98
95
  previewUri?: string;
99
96
  uploadState: AttachmentLoadingState;
100
97
  /**
101
- * Mirrors {@link UploadRecord.uploadConfirmationPending}: every byte has been sent, but the server has
102
- * not confirmed yet - not returned response to the upload request. Render an indeterminate indicator rather than a full bar.
98
+ * Mirrors {@link UploadRecord.uploadConfirmationPending}: every byte is sent but the server has not
99
+ * confirmed. Render an indeterminate indicator rather than a full bar.
103
100
  */
104
101
  uploadConfirmationPending?: boolean;
105
- uploadPermissionCheck?: UploadPermissionCheckResult; // added new
106
- /** 0–100 while uploading when progress tracking is enabled; undefined otherwise or when indeterminate */
102
+ uploadPermissionCheck?: UploadPermissionCheckResult;
103
+ /** 0 to 100 while uploading with progress tracking on; `undefined` otherwise or when indeterminate. */
107
104
  uploadProgress?: number;
108
105
  };
109
106
 
110
107
  export type LocalImageAttachmentUploadMetadata = LocalAttachmentUploadMetadata & {
111
108
  /**
112
- * @deprecated `previewUri` is now available on `LocalAttachmentUploadMetadata`.
109
+ * @deprecated Use `LocalAttachmentUploadMetadata.previewUri` instead.
113
110
  */
114
111
  previewUri?: string;
115
112
  };
@@ -137,14 +134,14 @@ export type FileLike = File | Blob;
137
134
  // todo: make sure that RN SDK passes MIME type in the type field
138
135
  export type FileReference = FileReferenceBase &
139
136
  Pick<File, 'name' | 'size'> & {
140
- // For images
137
+ // Images
141
138
  height?: number;
142
139
  width?: number;
143
140
 
144
- // For voice recordings
141
+ // Voice recordings
145
142
  duration?: number;
146
143
  waveform_data?: number[];
147
144
 
148
- // This is specially needed for video in camera roll
145
+ // Needed for video in the camera roll
149
146
  thumb_url?: string;
150
147
  };
@@ -18,19 +18,19 @@ import { throttle } from '../utils';
18
18
  import { isAPIError, isErrorRetryable } from '../errors';
19
19
 
20
20
  export type MessageDeliveryReporterConfig = {
21
- /** How long delivery reports are buffered before being sent as one batch (defaults to 1000ms). */
21
+ /** How long delivery reports are buffered before being sent as one batch. Defaults to 1000ms. */
22
22
  markAsDeliveredBufferTimeoutMs: number;
23
23
  /**
24
- * Minimum gap between automatic `markRead` calls (defaults to 1000ms).
25
- *
26
- * Read once, when the throttle is built — assigning it later does nothing, which is why
27
- * {@link MessageDeliveryReporter.setMarkAsReadThrottleOptions} exists and why the declarative path
28
- * routes through it.
24
+ * Minimum gap between automatic `markRead` calls for the same channel or thread. Changes rebuild
25
+ * the throttles. Defaults to 1000ms.
29
26
  */
30
27
  markAsReadThrottleTimeoutMs: number;
31
- /** Most delivery receipts sent in a single request; the remainder is carried to the next (100). */
28
+ /** Most delivery receipts sent in one request; the rest go in the next. Defaults to 100. */
32
29
  maxDeliveredMessageCountInPayload: number;
33
- /** Consecutive timeouts before the buffer window is widened (defaults to 3). */
30
+ /**
31
+ * Most times consecutive retryable failures double the buffer window. A success resets it.
32
+ * Defaults to 3.
33
+ */
34
34
  retryCountLimitForTimeoutIncrease: number;
35
35
  };
36
36
 
@@ -70,15 +70,10 @@ export class MessageDeliveryReporter {
70
70
 
71
71
  protected requestTimeoutMs: number =
72
72
  DEFAULT_MESSAGE_DELIVERY_REPORTER_CONFIG.markAsDeliveredBufferTimeoutMs;
73
- // increased up to config.retryCountLimitForTimeoutIncrease
73
+ // Capped at `config.retryCountLimitForTimeoutIncrease`.
74
74
  protected requestRetryCount: number = 0;
75
75
 
76
- /** The shared configuration machinery — see {@link ConfigController}. */
77
76
  private readonly configController: ConfigController<MessageDeliveryReporterConfig>;
78
- /**
79
- * Resolved configuration, as a store — the shape every configurable class exposes
80
- * (`configState` / `config` / `updateConfig`).
81
- */
82
77
  get configState(): StateStore<MessageDeliveryReporterConfig> {
83
78
  return this.configController.state;
84
79
  }
@@ -87,9 +82,7 @@ export class MessageDeliveryReporter {
87
82
  this.client = client;
88
83
  this.configController = new ConfigController<MessageDeliveryReporterConfig>({
89
84
  defaults: DEFAULT_MESSAGE_DELIVERY_REPORTER_CONFIG,
90
- // The markRead throttle captures its interval in a closure, so storing a new one is not enough —
91
- // it has to be rebuilt. Doing that here rather than in `updateConfig` is what makes the pairing
92
- // hold for *every* route, including a declarative change.
85
+ // The throttle captures its interval, so it is rebuilt whenever the interval changes.
93
86
  onChanged: (next, previous) => {
94
87
  if (next.markAsReadThrottleTimeoutMs === previous.markAsReadThrottleTimeoutMs)
95
88
  return;
@@ -100,49 +93,32 @@ export class MessageDeliveryReporter {
100
93
  });
101
94
  }
102
95
 
103
- /** The current resolved configuration. `Readonly` — change it through {@link updateConfig}. */
104
96
  get config(): Readonly<MessageDeliveryReporterConfig> {
105
97
  return this.configState.getLatestValue();
106
98
  }
107
99
 
108
100
  /**
109
- * Merges a partial configuration in. `markAsReadThrottleTimeoutMs` is routed through its rebuild
110
- * setter, because the throttle captured the old interval in a closure and would otherwise ignore it.
101
+ * Merges a partial configuration into the resolved config.
102
+ *
103
+ * @param config - Fields to merge into the resolved config.
111
104
  */
112
105
  updateConfig(config: Partial<MessageDeliveryReporterConfig>) {
113
106
  this.configController.patch(config);
114
107
  }
115
108
 
116
109
  /**
117
- * Rebuilds the resolved configuration from package defaults plus the declarative slice.
110
+ * Re-derives the configuration from the declarative slice.
118
111
  *
119
- * The derivation entry point every configurable entity exposes, so the owner routes a slice here and
120
- * knows nothing about MessageDeliveryReporter's defaults or merge semantics. This logic used to live in the owner,
121
- * which is how `reset()` became a no-op for the client key (F4) and how a registered
122
- * `notifications.sortComparator` became unremovable (G8) — an owner writing another object's
123
- * derivation gets that object's rules wrong sooner or later.
124
- *
125
- * Routed through {@link updateConfig} rather than replacing the store, which is exact here because
126
- * every field of `MessageDeliveryReporterConfig` is required and present in the defaults, so a patch naming all of
127
- * them amounts to a replacement. `NotificationManager` cannot do this — its `sortComparator` is
128
- * optional with no default, so a patch can never remove one — which is why it replaces outright.
112
+ * @param config - The declarative slice. Leave it out to rebuild from the defaults.
129
113
  */
130
114
  initializeConfig(config?: Partial<MessageDeliveryReporterConfig>) {
131
115
  this.configController.initialize(config);
132
116
  }
133
117
 
134
- /**
135
- * Rebuilds the `markRead` throttle for a new interval.
136
- *
137
- * Needed because the throttle is created as a field initializer — before any declarative
138
- * configuration has been applied — so the interval is captured once. Assigning the config value
139
- * alone would leave the original throttle in place, silently.
140
- */
118
+ /** Sets `markAsReadThrottleTimeoutMs`, which rebuilds the `markRead` throttle. */
141
119
  setMarkAsReadThrottleOptions = ({
142
120
  markAsReadThrottleTimeoutMs,
143
121
  }: Pick<MessageDeliveryReporterConfig, 'markAsReadThrottleTimeoutMs'>) => {
144
- // Kept as released surface, but it no longer has to pair the write with the rebuild — the
145
- // controller's `onChanged` does that for whichever route the value arrives by.
146
122
  this.updateConfig({ markAsReadThrottleTimeoutMs });
147
123
  };
148
124
 
@@ -178,13 +154,7 @@ export class MessageDeliveryReporter {
178
154
  this.requestRetryCount = 0;
179
155
  }
180
156
 
181
- /**
182
- * Builds the `latest_delivered_messages` payload from an arbitrary buffer
183
- * (`deliveryReportCandidates` or `nextDeliveryReportCandidates`).
184
- *
185
- * @param map - The buffer mapping channel/thread composite IDs to the latest delivered message ID.
186
- * @returns The payload entries ready to be sent to the server.
187
- */
157
+ /** Builds the `latest_delivered_messages` payload from a candidates buffer. */
188
158
  private confirmationsFrom(map: Map<ChannelThreadCompositeId, MessageId>) {
189
159
  return Array.from(map.entries()).map(([key, messageId]) => {
190
160
  const [type, id, parent_id] = key.split(':');
@@ -206,12 +176,7 @@ export class MessageDeliveryReporter {
206
176
  return { latest_delivered_messages: this.confirmationsFrom(sendBuffer), sendBuffer };
207
177
  }
208
178
 
209
- /**
210
- * Generates a candidate key for storing in the candidates buffer.
211
- *
212
- * @param collection - The channel or thread to derive a candidate key for.
213
- * @returns The composite identifier, or `undefined` when the collection is neither a Channel nor a Thread.
214
- */
179
+ /** The buffer key: the channel `cid`, or `cid:threadId` for a thread. */
215
180
  private candidateKeyFor(
216
181
  collection: Channel | Thread,
217
182
  ): ChannelThreadCompositeId | undefined {
@@ -219,13 +184,7 @@ export class MessageDeliveryReporter {
219
184
  if (isThread(collection)) return `${collection.channel.cid}:${collection.id}`;
220
185
  }
221
186
 
222
- /**
223
- * Retrieves a reference to the latest message in the state that is neither read nor reported as
224
- * delivered.
225
- *
226
- * @param collection - The channel or thread to inspect.
227
- * @returns The next candidate to report as delivered, or `undefined` when none applies.
228
- */
187
+ /** The latest message that is neither read nor reported as delivered (`id: null` when none). */
229
188
  private getNextDeliveryReportCandidate = (
230
189
  collection: Channel | Thread,
231
190
  ): { key: ChannelThreadCompositeId; id: MessageId | null } | undefined => {
@@ -233,7 +192,7 @@ export class MessageDeliveryReporter {
233
192
  if (!ownUserId) return;
234
193
 
235
194
  let latestMessages: LocalMessage[] = [];
236
- // Wire timestamps (unix nanoseconds), directly comparable against a message's `created_at`.
195
+ // Unix nanoseconds, comparable with a message's `created_at`.
237
196
  let lastDeliveredAt: TimestampNS | undefined;
238
197
  let lastReadAt: TimestampNS | undefined;
239
198
  let key: string | undefined = undefined;
@@ -246,9 +205,7 @@ export class MessageDeliveryReporter {
246
205
  lastDeliveredAt = ownReadState?.last_delivered_at;
247
206
  key = collection.cid;
248
207
  } else if (isThread(collection)) {
249
- // Use the head (newest-loaded) window, not the active/visible interval: the candidate logic
250
- // below inspects the newest message, which the active interval only reflects when scrolled to
251
- // the head. Mirrors the channel branch above.
208
+ // The head window, as for channels: the active interval may be scrolled away from the newest.
252
209
  latestMessages = collection.messagePaginator.headItems;
253
210
  const ownReadState =
254
211
  collection.state.getLatestValue().read[ownUserId] ?? ({} as ThreadUserReadState);
@@ -276,11 +233,7 @@ export class MessageDeliveryReporter {
276
233
  return { key, id: latestMessage.id || null };
277
234
  };
278
235
 
279
- /**
280
- * Updates the delivery candidates buffer with the latest delivery candidates.
281
- *
282
- * @param collection - The channel or thread whose latest delivery candidate to track.
283
- */
236
+ // Candidates found while a request is in flight wait in the next buffer.
284
237
  private trackDeliveredCandidate(collection: Channel | Thread) {
285
238
  if (!MessageDeliveryReporter.hasPermissionToReportDeliveryFor(collection)) return;
286
239
  const candidate = this.getNextDeliveryReportCandidate(collection);
@@ -292,11 +245,6 @@ export class MessageDeliveryReporter {
292
245
  else buffer.set(candidate.key, candidate.id);
293
246
  }
294
247
 
295
- /**
296
- * Removes a candidate from the delivery report buffer.
297
- *
298
- * @param collection - The channel or thread whose candidate should be removed.
299
- */
300
248
  private removeCandidateFor(collection: Channel | Thread) {
301
249
  const candidateKey = this.candidateKeyFor(collection);
302
250
  if (!candidateKey) return;
@@ -305,9 +253,8 @@ export class MessageDeliveryReporter {
305
253
  }
306
254
 
307
255
  /**
308
- * Records the latest message delivered for Channel or Thread instances and schedules the next
309
- * report if not already scheduled and candidates exist. Should be used for WS handling
310
- * (`message.new`) as well as for ingesting HTTP channel query results.
256
+ * Records each collection's latest undelivered message and schedules a report if none is
257
+ * pending. For WS handling (`message.new`) and for ingesting channel query results.
311
258
  *
312
259
  * @param collections - The channels or threads whose candidates should be synced.
313
260
  */
@@ -318,9 +265,9 @@ export class MessageDeliveryReporter {
318
265
  }
319
266
 
320
267
  /**
321
- * Fires a delivery announcement request followed by an immediate delivery candidate buffer reset.
268
+ * Sends the buffered report immediately, at most `maxDeliveredMessageCountInPayload` entries.
322
269
  *
323
- * @param options - Flags forwarded to `client.markDelivered` (optional).
270
+ * @param options - Flags forwarded to `client.markDelivered`.
324
271
  */
325
272
  public announceDelivery = (options?: AnnounceDeliveryOptions) => {
326
273
  if (!this.canExecuteRequest) return;
@@ -336,14 +283,14 @@ export class MessageDeliveryReporter {
336
283
  }: { preventSchedulingRetry?: boolean } = {}) => {
337
284
  this.markDeliveredRequestPromise = null;
338
285
 
339
- // promote anything that arrived during request
286
+ // Promote candidates that arrived during the request.
340
287
  for (const [k, v] of this.nextDeliveryReportCandidates.entries()) {
341
288
  this.deliveryReportCandidates.set(k, v);
342
289
  }
343
290
  this.nextDeliveryReportCandidates = new Map();
344
291
 
345
292
  if (preventSchedulingRetry) return;
346
- // checks internally whether there are candidates to announce
293
+ // Checks internally whether there are candidates to announce.
347
294
  this.announceDeliveryBuffered(options);
348
295
  };
349
296
 
@@ -353,8 +300,7 @@ export class MessageDeliveryReporter {
353
300
  };
354
301
 
355
302
  const handleError = (error: StreamAPIError | Error) => {
356
- // re-populate relevant candidates for the next report
357
- // but make sure to keep the items that failed to be reported the first next time
303
+ // Requeue the failed batch ahead of the remaining candidates, so it is retried first.
358
304
  const newDeliveryReportCandidates = new Map(sendBuffer);
359
305
  for (const [k, v] of this.deliveryReportCandidates.entries()) {
360
306
  newDeliveryReportCandidates.set(k, v);
@@ -388,11 +334,11 @@ export class MessageDeliveryReporter {
388
334
  };
389
335
 
390
336
  /**
391
- * Delegates the mark-read call to the Channel or Thread instance. A channel whose read events are
392
- * disabled is marked read locally instead, when the client opted into counting unread itself.
337
+ * Marks the channel or thread read. A channel with read events disabled is marked read locally when
338
+ * `localUnreadCountEnabled` is set.
393
339
  *
394
340
  * @param collection - The channel or thread to mark as read.
395
- * @param options - Flags forwarded to the underlying `markRead` call (optional).
341
+ * @param options - Flags forwarded to the underlying `markRead` call.
396
342
  * @returns The server response, or `null` when no request went out.
397
343
  */
398
344
  public markRead = async (collection: Channel | Thread, options?: MarkReadRequest) => {
@@ -416,11 +362,8 @@ export class MessageDeliveryReporter {
416
362
  } else {
417
363
  const { readEvents, requestHandlers } = channel.configState.getLatestValue();
418
364
  const markReadRequestHandler = requestHandlers?.markReadRequest;
419
- // Without read events there is no server-side read state to advance - `channel.markRead()`
420
- // throws. `localUnreadCountEnabled` is how an integrator asks to count unread anyway, so the
421
- // reset has to come from somewhere: `markReadLocally` clears it through the same read
422
- // handling a `message.read` would. Threads are deliberately outside this branch - their read
423
- // state is their own, and resetting the channel is not what a thread read means.
365
+ // Without read events `channel.markRead()` throws, so reset unread locally (threads have their own
366
+ // read state and are not affected).
424
367
  if (markReadRequestHandler) {
425
368
  result =
426
369
  (await markReadRequestHandler({ channel, options: requestOptions })) ?? null;
@@ -431,32 +374,36 @@ export class MessageDeliveryReporter {
431
374
  }
432
375
  }
433
376
 
434
- // A read implies delivery, so the candidate is only dropped once the request actually went
435
- // out. A `markReadRequest` handler that declines returns nothing, and those candidates must
436
- // survive for the next delivery report.
377
+ // A read implies delivery, so the candidate is dropped only if a request went out (a declining
378
+ // `markReadRequest` handler returns nothing).
437
379
  if (result) this.removeCandidateFor(collection);
438
380
  return result;
439
381
  };
440
382
 
441
- /**
442
- * Builds the throttled `markRead`. A factory rather than an inline `throttle(...)` so the interval can
443
- * be swapped later — see {@link setMarkAsReadThrottleOptions}.
444
- *
445
- * @param intervalMs - minimum gap between automatic `markRead` calls
446
- */
447
- // Auto mark-read is throttled and fire-and-forget: it's triggered by state changes / WS events,
448
- // not by an awaiting caller, so a rejection here has nowhere to propagate and would otherwise
449
- // surface as an unhandled rejection (e.g. `channel.markRead` throwing when read events are
450
- // disabled, or a transient network error). Swallow it — the auto path retries on the next
451
- // trigger, and explicit `markRead()` callers still receive the error.
452
- private buildThrottledMarkRead = (intervalMs: number) =>
453
- throttle(
454
- (collection: Channel | Thread, options?: MarkReadRequest) => {
455
- void this.markRead(collection, options).catch(() => undefined);
456
- },
457
- intervalMs,
458
- { leading: true, trailing: true },
459
- ).throttledFn;
383
+ // Fire-and-forget: no caller awaits an automatic mark-read, so rejections are swallowed (the next
384
+ // trigger retries; explicit `markRead()` callers still get the error). One throttle per collection:
385
+ // a shared one keeps only the latest call for its trailing edge and would drop another
386
+ // collection's pending mark-read.
387
+ private buildThrottledMarkRead = (intervalMs: number) => {
388
+ const throttled = new WeakMap<
389
+ Channel | Thread,
390
+ (options?: MarkReadRequest) => void
391
+ >();
392
+ return (collection: Channel | Thread, options?: MarkReadRequest) => {
393
+ let markRead = throttled.get(collection);
394
+ if (!markRead) {
395
+ markRead = throttle(
396
+ (markReadOptions?: MarkReadRequest) => {
397
+ void this.markRead(collection, markReadOptions).catch(() => undefined);
398
+ },
399
+ intervalMs,
400
+ { leading: true, trailing: true },
401
+ ).throttledFn;
402
+ throttled.set(collection, markRead);
403
+ }
404
+ markRead(options);
405
+ };
406
+ };
460
407
 
461
408
  public throttledMarkRead = this.buildThrottledMarkRead(
462
409
  DEFAULT_MESSAGE_DELIVERY_REPORTER_CONFIG.markAsReadThrottleTimeoutMs,