stream-chat 9.50.2 → 10.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/dist/cjs/index.browser.js +18869 -13986
  2. package/dist/cjs/index.browser.js.map +4 -4
  3. package/dist/cjs/index.node.js +18888 -13992
  4. package/dist/cjs/index.node.js.map +4 -4
  5. package/dist/esm/index.mjs +18866 -13983
  6. package/dist/esm/index.mjs.map +4 -4
  7. package/dist/types/ChannelPaginatorsOrchestrator.d.ts +130 -0
  8. package/dist/types/EventHandlerPipeline.d.ts +104 -0
  9. package/dist/types/api-client.d.ts +26 -0
  10. package/dist/types/campaign.d.ts +0 -44
  11. package/dist/types/channel.d.ts +436 -480
  12. package/dist/types/channel_batch_updater.d.ts +0 -93
  13. package/dist/types/channel_manager.d.ts +8 -10
  14. package/dist/types/channel_state.d.ts +53 -201
  15. package/dist/types/client.d.ts +440 -1910
  16. package/dist/types/client_state.d.ts +4 -4
  17. package/dist/types/configuration/InstanceConfigurationService.d.ts +26 -0
  18. package/dist/types/configuration/index.d.ts +1 -0
  19. package/dist/types/configuration/types.d.ts +53 -0
  20. package/dist/types/connection.d.ts +49 -41
  21. package/dist/types/connection_fallback.d.ts +6 -4
  22. package/dist/types/constants.d.ts +0 -4
  23. package/dist/types/custom_types.d.ts +2 -0
  24. package/dist/types/errors.d.ts +2 -2
  25. package/dist/types/gen/chat/ChannelApi.d.ts +45 -0
  26. package/dist/types/gen/chat/ChatApi.d.ts +334 -0
  27. package/dist/types/gen/model-decoders/decoders.d.ts +3 -0
  28. package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +6 -0
  29. package/dist/types/gen/models/index.d.ts +8836 -0
  30. package/dist/types/gen/moderation/ModerationApi.d.ts +50 -0
  31. package/dist/types/gen-imports.d.ts +3 -0
  32. package/dist/types/index.d.ts +5 -5
  33. package/dist/types/insights.d.ts +7 -6
  34. package/dist/types/logger.d.ts +9 -0
  35. package/dist/types/messageComposer/LocationComposer.d.ts +7 -4
  36. package/dist/types/messageComposer/attachmentIdentity.d.ts +2 -2
  37. package/dist/types/messageComposer/attachmentManager.d.ts +8 -4
  38. package/dist/types/messageComposer/configuration/types.d.ts +11 -11
  39. package/dist/types/messageComposer/linkPreviewsManager.d.ts +25 -13
  40. package/dist/types/messageComposer/messageComposer.d.ts +10 -10
  41. package/dist/types/messageComposer/middleware/messageComposer/types.d.ts +3 -3
  42. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +4 -7
  43. package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +3 -3
  44. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +7 -7
  45. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +218 -4
  46. package/dist/types/messageComposer/middleware/textComposer/types.d.ts +9 -4
  47. package/dist/types/messageComposer/pollComposer.d.ts +5 -4
  48. package/dist/types/messageComposer/textComposer.d.ts +8 -3
  49. package/dist/types/messageComposer/types.d.ts +6 -28
  50. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +40 -25
  51. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +53 -12
  52. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +19 -0
  53. package/dist/types/messageOperations/MessageOperations.d.ts +17 -0
  54. package/dist/types/messageOperations/index.d.ts +3 -0
  55. package/dist/types/messageOperations/types.d.ts +49 -0
  56. package/dist/types/moderation.d.ts +21 -203
  57. package/dist/types/notifications/types.d.ts +8 -7
  58. package/dist/types/offline-support/offline_support_api.d.ts +110 -87
  59. package/dist/types/offline-support/types.d.ts +19 -23
  60. package/dist/types/offline-support/util.d.ts +4 -2
  61. package/dist/types/pagination/FilterBuilder.d.ts +1 -1
  62. package/dist/types/pagination/ItemIndex.d.ts +82 -0
  63. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +9 -0
  64. package/dist/types/pagination/cursorDerivation/idAroundPaginationFlags.d.ts +6 -0
  65. package/dist/types/pagination/cursorDerivation/index.d.ts +1 -0
  66. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +6 -0
  67. package/dist/types/pagination/filterCompiler.d.ts +7 -0
  68. package/dist/types/pagination/index.d.ts +1 -3
  69. package/dist/types/pagination/paginators/BasePaginator.d.ts +709 -0
  70. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +58 -0
  71. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +260 -0
  72. package/dist/types/pagination/paginators/MessagePaginator.d.ts +208 -0
  73. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +39 -0
  74. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +19 -0
  75. package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +24 -0
  76. package/dist/types/pagination/paginators/index.d.ts +7 -0
  77. package/dist/types/pagination/sortCompiler.d.ts +49 -0
  78. package/dist/types/pagination/types.normalization.d.ts +11 -0
  79. package/dist/types/pagination/utility.normalization.d.ts +18 -0
  80. package/dist/types/pagination/utility.queryChannel.d.ts +26 -0
  81. package/dist/types/pagination/utility.search.d.ts +13 -0
  82. package/dist/types/permissions.d.ts +1 -1
  83. package/dist/types/poll.d.ts +29 -32
  84. package/dist/types/poll_manager.d.ts +2 -2
  85. package/dist/types/reminders/Reminder.d.ts +2 -5
  86. package/dist/types/reminders/ReminderManager.d.ts +2 -9
  87. package/dist/types/search/MessageSearchSource.d.ts +4 -4
  88. package/dist/types/search/UserSearchSource.d.ts +1 -1
  89. package/dist/types/search/types.d.ts +3 -3
  90. package/dist/types/segment.d.ts +0 -34
  91. package/dist/types/signing.d.ts +105 -65
  92. package/dist/types/store.d.ts +1 -0
  93. package/dist/types/thread.d.ts +51 -34
  94. package/dist/types/thread_manager.d.ts +3 -3
  95. package/dist/types/token_manager.d.ts +15 -10
  96. package/dist/types/types.d.ts +196 -3384
  97. package/dist/types/utils/FixedSizeQueueCache.d.ts +12 -6
  98. package/dist/types/utils/WithSubscriptions.d.ts +2 -1
  99. package/dist/types/utils/concurrency.d.ts +4 -4
  100. package/dist/types/utils/mergeWith/mergeWith.d.ts +3 -3
  101. package/dist/types/utils/mergeWith/mergeWithCore.d.ts +8 -3
  102. package/dist/types/utils/retryable.d.ts +34 -0
  103. package/dist/types/utils.d.ts +104 -137
  104. package/package.json +7 -3
  105. package/src/ChannelPaginatorsOrchestrator.ts +545 -0
  106. package/src/CooldownTimer.ts +2 -2
  107. package/src/EventHandlerPipeline.ts +228 -0
  108. package/src/LiveLocationManager.ts +12 -11
  109. package/src/api-client.ts +275 -0
  110. package/src/campaign.ts +1 -77
  111. package/src/channel.ts +1262 -1277
  112. package/src/channel_batch_updater.ts +1 -211
  113. package/src/channel_manager.ts +92 -88
  114. package/src/channel_state.ts +144 -1013
  115. package/src/client.ts +888 -3944
  116. package/src/client_state.ts +4 -4
  117. package/src/configuration/InstanceConfigurationService.ts +73 -0
  118. package/src/configuration/index.ts +1 -0
  119. package/src/configuration/types.ts +81 -0
  120. package/src/connection.ts +145 -94
  121. package/src/connection_fallback.ts +29 -27
  122. package/src/constants.ts +1 -5
  123. package/src/custom_types.ts +4 -1
  124. package/src/errors.ts +2 -2
  125. package/src/gen/chat/ChannelApi.ts +275 -0
  126. package/src/gen/chat/ChatApi.ts +2554 -0
  127. package/src/gen/model-decoders/decoders.ts +2680 -0
  128. package/src/gen/model-decoders/event-decoder-mapping.ts +198 -0
  129. package/src/gen/models/index.ts +12673 -0
  130. package/src/gen/moderation/ModerationApi.ts +607 -0
  131. package/src/gen-imports.ts +3 -0
  132. package/src/index.ts +5 -10
  133. package/src/insights.ts +6 -5
  134. package/src/logger.ts +28 -0
  135. package/src/messageComposer/LocationComposer.ts +9 -5
  136. package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -0
  137. package/src/messageComposer/attachmentIdentity.ts +16 -9
  138. package/src/messageComposer/attachmentManager.ts +13 -8
  139. package/src/messageComposer/configuration/types.ts +11 -11
  140. package/src/messageComposer/linkPreviewsManager.ts +9 -10
  141. package/src/messageComposer/messageComposer.ts +57 -53
  142. package/src/messageComposer/middleware/messageComposer/attachments.ts +1 -2
  143. package/src/messageComposer/middleware/messageComposer/cleanData.ts +1 -1
  144. package/src/messageComposer/middleware/messageComposer/compositionValidation.ts +2 -2
  145. package/src/messageComposer/middleware/messageComposer/messageComposerState.ts +2 -2
  146. package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +4 -3
  147. package/src/messageComposer/middleware/messageComposer/textComposer.ts +2 -2
  148. package/src/messageComposer/middleware/messageComposer/types.ts +3 -4
  149. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +9 -5
  150. package/src/messageComposer/middleware/pollComposer/state.ts +0 -2
  151. package/src/messageComposer/middleware/pollComposer/types.ts +4 -7
  152. package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +10 -1
  153. package/src/messageComposer/middleware/textComposer/commandEffects.ts +4 -4
  154. package/src/messageComposer/middleware/textComposer/commandUtils.ts +3 -6
  155. package/src/messageComposer/middleware/textComposer/commands.ts +3 -3
  156. package/src/messageComposer/middleware/textComposer/mentionUtils.ts +1 -1
  157. package/src/messageComposer/middleware/textComposer/mentions.ts +31 -15
  158. package/src/messageComposer/middleware/textComposer/types.ts +9 -4
  159. package/src/messageComposer/pollComposer.ts +6 -8
  160. package/src/messageComposer/textComposer.ts +27 -2
  161. package/src/messageComposer/types.ts +6 -28
  162. package/src/messageDelivery/MessageDeliveryReporter.ts +101 -45
  163. package/src/messageDelivery/MessageReceiptsTracker.ts +294 -21
  164. package/src/messageOperations/MessageOperationStatePolicy.ts +77 -0
  165. package/src/messageOperations/MessageOperations.ts +212 -0
  166. package/src/messageOperations/index.ts +10 -0
  167. package/src/messageOperations/types.ts +64 -0
  168. package/src/moderation.ts +38 -431
  169. package/src/notifications/types.ts +8 -7
  170. package/src/offline-support/offline_support_api.ts +198 -132
  171. package/src/offline-support/offline_sync_manager.ts +17 -7
  172. package/src/offline-support/types.ts +23 -26
  173. package/src/offline-support/util.ts +5 -4
  174. package/src/pagination/FilterBuilder.ts +4 -1
  175. package/src/pagination/ItemIndex.ts +112 -0
  176. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +73 -0
  177. package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +53 -0
  178. package/src/pagination/cursorDerivation/index.ts +1 -0
  179. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +86 -0
  180. package/src/pagination/filterCompiler.ts +196 -0
  181. package/src/pagination/index.ts +1 -3
  182. package/src/pagination/paginators/BasePaginator.ts +2393 -0
  183. package/src/pagination/paginators/ChannelPaginator.ts +427 -0
  184. package/src/pagination/paginators/MessageIntervalPaginator.ts +1073 -0
  185. package/src/pagination/paginators/MessagePaginator.ts +496 -0
  186. package/src/pagination/paginators/PinnedMessagePaginator.ts +105 -0
  187. package/src/pagination/paginators/ReminderPaginator.ts +105 -0
  188. package/src/pagination/paginators/UserGroupPaginator.ts +125 -0
  189. package/src/pagination/paginators/index.ts +7 -0
  190. package/src/pagination/sortCompiler.ts +178 -0
  191. package/src/pagination/types.normalization.ts +14 -0
  192. package/src/pagination/utility.normalization.ts +106 -0
  193. package/src/pagination/utility.queryChannel.ts +84 -0
  194. package/src/pagination/utility.search.ts +80 -0
  195. package/src/permissions.ts +7 -8
  196. package/src/poll.ts +101 -110
  197. package/src/poll_manager.ts +14 -8
  198. package/src/reminders/Reminder.ts +2 -5
  199. package/src/reminders/ReminderManager.ts +19 -21
  200. package/src/search/BaseSearchSource.ts +0 -3
  201. package/src/search/ChannelMemberSearchSource.ts +7 -1
  202. package/src/search/ChannelSearchSource.ts +10 -3
  203. package/src/search/MessageSearchSource.ts +29 -30
  204. package/src/search/UserSearchSource.ts +12 -8
  205. package/src/search/types.ts +3 -4
  206. package/src/segment.ts +1 -95
  207. package/src/signing.ts +107 -67
  208. package/src/store.ts +2 -1
  209. package/src/thread.ts +439 -236
  210. package/src/thread_manager.ts +36 -15
  211. package/src/token_manager.ts +21 -10
  212. package/src/types.ts +375 -4524
  213. package/src/uploadManager.ts +8 -0
  214. package/src/utils/FixedSizeQueueCache.ts +12 -6
  215. package/src/utils/WithSubscriptions.ts +2 -1
  216. package/src/utils/concurrency.ts +4 -4
  217. package/src/utils/mergeWith/mergeWith.ts +3 -3
  218. package/src/utils/mergeWith/mergeWithCore.ts +140 -164
  219. package/src/utils/mergeWith/mergeWithDiff.ts +3 -3
  220. package/src/utils/retryable.ts +117 -0
  221. package/src/utils.ts +133 -524
  222. package/dist/types/events.d.ts +0 -72
  223. package/dist/types/pagination/BasePaginator.d.ts +0 -69
  224. package/dist/types/pagination/ReminderPaginator.d.ts +0 -16
  225. package/dist/types/pagination/UserGroupPaginator.d.ts +0 -21
  226. package/src/events.ts +0 -75
  227. package/src/pagination/BasePaginator.ts +0 -184
  228. package/src/pagination/ReminderPaginator.ts +0 -56
  229. package/src/pagination/UserGroupPaginator.ts +0 -93
@@ -3,15 +3,16 @@ import { Channel } from '../channel';
3
3
  import type { ThreadUserReadState } from '../thread';
4
4
  import { Thread } from '../thread';
5
5
  import type {
6
- ErrorFromResponse,
7
6
  EventAPIResponse,
8
7
  LocalMessage,
9
- MarkDeliveredOptions,
10
- MarkReadOptions,
8
+ MarkDeliveredRequest,
9
+ MarkReadRequest,
10
+ StreamAPIError,
11
+ StreamResponse,
11
12
  } from '../types';
12
- import { type APIErrorResponse } from '../types';
13
13
  import { throttle, userHasReadReceipts } from '../utils';
14
14
  import { isAPIError, isErrorRetryable } from '../errors';
15
+ import type { MarkReadResponse as Gen_MarkReadResponse } from '../gen/models';
15
16
 
16
17
  const MAX_DELIVERED_MESSAGE_COUNT_IN_PAYLOAD = 100 as const;
17
18
  const MARK_AS_DELIVERED_BUFFER_TIMEOUT = 1000 as const;
@@ -25,7 +26,7 @@ type MessageId = string;
25
26
  type ChannelThreadCompositeId = string;
26
27
 
27
28
  export type AnnounceDeliveryOptions = Omit<
28
- MarkDeliveredOptions,
29
+ MarkDeliveredRequest,
29
30
  'latest_delivered_messages'
30
31
  >;
31
32
 
@@ -41,7 +42,7 @@ export class MessageDeliveryReporter {
41
42
  protected nextDeliveryReportCandidates: Map<ChannelThreadCompositeId, MessageId> =
42
43
  new Map();
43
44
 
44
- protected markDeliveredRequestPromise: Promise<EventAPIResponse | void> | null = null;
45
+ protected markDeliveredRequestPromise: Promise<void> | null = null;
45
46
  protected markDeliveredTimeout: ReturnType<typeof setTimeout> | null = null;
46
47
 
47
48
  protected requestTimeoutMs: number = MARK_AS_DELIVERED_BUFFER_TIMEOUT;
@@ -85,7 +86,11 @@ export class MessageDeliveryReporter {
85
86
  }
86
87
 
87
88
  /**
88
- * Build latest_delivered_messages payload from an arbitrary buffer (deliveryReportCandidates / nextDeliveryReportCandidates)
89
+ * Builds the `latest_delivered_messages` payload from an arbitrary buffer
90
+ * (`deliveryReportCandidates` or `nextDeliveryReportCandidates`).
91
+ *
92
+ * @param map - The buffer mapping channel/thread composite IDs to the latest delivered message ID.
93
+ * @returns The payload entries ready to be sent to the server.
89
94
  */
90
95
  private confirmationsFrom(map: Map<ChannelThreadCompositeId, MessageId>) {
91
96
  return Array.from(map.entries()).map(([key, messageId]) => {
@@ -107,9 +112,10 @@ export class MessageDeliveryReporter {
107
112
  }
108
113
 
109
114
  /**
110
- * Generate candidate key for storing in the candidates buffer
111
- * @param collection
112
- * @private
115
+ * Generates a candidate key for storing in the candidates buffer.
116
+ *
117
+ * @param collection - The channel or thread to derive a candidate key for.
118
+ * @returns The composite identifier, or `undefined` when the collection is neither a Channel nor a Thread.
113
119
  */
114
120
  private candidateKeyFor(
115
121
  collection: Channel | Thread,
@@ -119,8 +125,11 @@ export class MessageDeliveryReporter {
119
125
  }
120
126
 
121
127
  /**
122
- * Retrieve the reference to the latest message in the state that is nor read neither reported as delivered
123
- * @param collection
128
+ * Retrieves a reference to the latest message in the state that is neither read nor reported as
129
+ * delivered.
130
+ *
131
+ * @param collection - The channel or thread to inspect.
132
+ * @returns The next candidate to report as delivered, or `undefined` when none applies.
124
133
  */
125
134
  private getNextDeliveryReportCandidate = (
126
135
  collection: Channel | Thread,
@@ -133,14 +142,18 @@ export class MessageDeliveryReporter {
133
142
  let lastReadAt: Date | undefined;
134
143
  let key: string | undefined = undefined;
135
144
 
145
+ // todo: unify the API for read state access btw channel and threads
136
146
  if (isChannel(collection)) {
137
- latestMessages = collection.state.latestMessages;
147
+ latestMessages = collection.messagePaginator.headItems;
138
148
  const ownReadState = collection.state.read[ownUserId] ?? {};
139
149
  lastReadAt = ownReadState?.last_read;
140
150
  lastDeliveredAt = ownReadState?.last_delivered_at;
141
151
  key = collection.cid;
142
152
  } else if (isThread(collection)) {
143
- latestMessages = collection.state.getLatestValue().replies;
153
+ // Use the head (newest-loaded) window, not the active/visible interval: the candidate logic
154
+ // below inspects the newest message, which the active interval only reflects when scrolled to
155
+ // the head. Mirrors the channel branch above.
156
+ latestMessages = collection.messagePaginator.headItems;
144
157
  const ownReadState =
145
158
  collection.state.getLatestValue().read[ownUserId] ?? ({} as ThreadUserReadState);
146
159
  lastReadAt = ownReadState?.lastReadAt;
@@ -168,8 +181,9 @@ export class MessageDeliveryReporter {
168
181
  };
169
182
 
170
183
  /**
171
- * Updates the delivery candidates buffer with the latest delivery candidates
172
- * @param collection
184
+ * Updates the delivery candidates buffer with the latest delivery candidates.
185
+ *
186
+ * @param collection - The channel or thread whose latest delivery candidate to track.
173
187
  */
174
188
  private trackDeliveredCandidate(collection: Channel | Thread) {
175
189
  if (!MessageDeliveryReporter.hasPermissionToReportDeliveryFor(collection)) return;
@@ -183,9 +197,9 @@ export class MessageDeliveryReporter {
183
197
  }
184
198
 
185
199
  /**
186
- * Removes candidate from the delivery report buffer
187
- * @param collection
188
- * @private
200
+ * Removes a candidate from the delivery report buffer.
201
+ *
202
+ * @param collection - The channel or thread whose candidate should be removed.
189
203
  */
190
204
  private removeCandidateFor(collection: Channel | Thread) {
191
205
  const candidateKey = this.candidateKeyFor(collection);
@@ -195,10 +209,11 @@ export class MessageDeliveryReporter {
195
209
  }
196
210
 
197
211
  /**
198
- * Records the latest message delivered for Channel or Thread instances and schedules the next report
199
- * if not already scheduled and candidates exist.
200
- * Should be used for WS handling (message.new) as well as for ingesting HTTP channel query results.
201
- * @param collections
212
+ * Records the latest message delivered for Channel or Thread instances and schedules the next
213
+ * report if not already scheduled and candidates exist. Should be used for WS handling
214
+ * (`message.new`) as well as for ingesting HTTP channel query results.
215
+ *
216
+ * @param collections - The channels or threads whose candidates should be synced.
202
217
  */
203
218
  public syncDeliveredCandidates(collections: (Channel | Thread)[]) {
204
219
  if (this.client.user?.privacy_settings?.delivery_receipts?.enabled === false) return;
@@ -207,8 +222,9 @@ export class MessageDeliveryReporter {
207
222
  }
208
223
 
209
224
  /**
210
- * Fires delivery announcement request followed by immediate delivery candidate buffer reset.
211
- * @param options
225
+ * Fires a delivery announcement request followed by an immediate delivery candidate buffer reset.
226
+ *
227
+ * @param options - Flags forwarded to `client.markDelivered` (optional).
212
228
  */
213
229
  public announceDelivery = (options?: AnnounceDeliveryOptions) => {
214
230
  if (!this.canExecuteRequest) return;
@@ -240,7 +256,7 @@ export class MessageDeliveryReporter {
240
256
  postFlightReconcile();
241
257
  };
242
258
 
243
- const handleError = (error: ErrorFromResponse<APIErrorResponse> | Error) => {
259
+ const handleError = (error: StreamAPIError | Error) => {
244
260
  // re-populate relevant candidates for the next report
245
261
  // but make sure to keep the items that failed to be reported the first next time
246
262
  const newDeliveryReportCandidates = new Map(sendBuffer);
@@ -251,7 +267,9 @@ export class MessageDeliveryReporter {
251
267
 
252
268
  if (
253
269
  (isAPIError(error) && isErrorRetryable(error)) ||
254
- (error as ErrorFromResponse<APIErrorResponse>).status >= 500
270
+ (typeof (error as StreamAPIError).status === 'number' &&
271
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
272
+ (error as StreamAPIError).status! >= 500)
255
273
  ) {
256
274
  this.increaseBackOff();
257
275
  postFlightReconcile();
@@ -261,7 +279,7 @@ export class MessageDeliveryReporter {
261
279
  };
262
280
 
263
281
  this.markDeliveredRequestPromise = this.client
264
- .markChannelsDelivered(payload)
282
+ .markDelivered(payload)
265
283
  .then(handleSuccess, handleError);
266
284
  };
267
285
 
@@ -274,21 +292,47 @@ export class MessageDeliveryReporter {
274
292
  };
275
293
 
276
294
  /**
277
- * Delegates the mark-read call to the Channel or Thread instance
278
- * @param collection
279
- * @param options
295
+ * Delegates the mark-read call to the Channel or Thread instance.
296
+ *
297
+ * @param collection - The channel or thread to mark as read.
298
+ * @param options - Flags forwarded to the underlying `markRead` call (optional).
299
+ * @returns The server response, or `null` when the collection is unsupported.
280
300
  */
281
- public markRead = async (collection: Channel | Thread, options?: MarkReadOptions) => {
301
+ public markRead = async (collection: Channel | Thread, options?: MarkReadRequest) => {
282
302
  if (!userHasReadReceipts(this.client)) return null;
283
-
284
- let result: EventAPIResponse | null = null;
285
- if (isChannel(collection)) {
286
- result = await collection.markAsReadRequest(options);
287
- } else if (isThread(collection)) {
288
- result = await collection.channel.markAsReadRequest({
289
- ...options,
290
- thread_id: collection.id,
291
- });
303
+ const isThreadCollection = isThread(collection);
304
+ const channel = isThreadCollection ? collection.channel : collection;
305
+ const requestOptions = isThreadCollection
306
+ ? { ...options, thread_id: collection.id }
307
+ : options;
308
+
309
+ let result: EventAPIResponse | StreamResponse<Gen_MarkReadResponse> | null = null;
310
+
311
+ if (isThreadCollection) {
312
+ const markReadRequestHandler = collection.configState.getLatestValue()
313
+ .requestHandlers?.markReadRequest as
314
+ | ((params: {
315
+ thread: Thread;
316
+ options?: MarkReadRequest;
317
+ }) => Promise<EventAPIResponse | null> | void)
318
+ | undefined;
319
+ result = markReadRequestHandler
320
+ ? ((await markReadRequestHandler({
321
+ options: requestOptions,
322
+ thread: collection,
323
+ })) ?? null)
324
+ : await channel.markRead(requestOptions);
325
+ } else {
326
+ const markReadRequestHandler = channel.configState.getLatestValue().requestHandlers
327
+ ?.markReadRequest as
328
+ | ((params: {
329
+ channel: Channel;
330
+ options?: MarkReadRequest;
331
+ }) => Promise<EventAPIResponse | null> | void)
332
+ | undefined;
333
+ result = markReadRequestHandler
334
+ ? ((await markReadRequestHandler({ channel, options: requestOptions })) ?? null)
335
+ : await channel.markRead(requestOptions);
292
336
  }
293
337
 
294
338
  this.removeCandidateFor(collection);
@@ -297,11 +341,23 @@ export class MessageDeliveryReporter {
297
341
 
298
342
  /**
299
343
  * Throttles the MessageDeliveryReporter.markRead call
344
+ *
300
345
  * @param collection
301
346
  * @param options
302
347
  */
303
- public throttledMarkRead = throttle(this.markRead, MARK_AS_READ_THROTTLE_TIMEOUT, {
304
- leading: false,
305
- trailing: true,
306
- });
348
+ // Auto mark-read is throttled and fire-and-forget: it's triggered by state changes / WS events,
349
+ // not by an awaiting caller, so a rejection here has nowhere to propagate and would otherwise
350
+ // surface as an unhandled rejection (e.g. `channel.markRead` throwing when read events are
351
+ // disabled, or a transient network error). Swallow it — the auto path retries on the next
352
+ // trigger, and explicit `markRead()` callers still receive the error.
353
+ public throttledMarkRead = throttle(
354
+ (collection: Channel | Thread, options?: MarkReadRequest) => {
355
+ void this.markRead(collection, options).catch(() => undefined);
356
+ },
357
+ MARK_AS_READ_THROTTLE_TIMEOUT,
358
+ {
359
+ leading: true,
360
+ trailing: true,
361
+ },
362
+ );
307
363
  }