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.
- package/dist/cjs/index.browser.js +18869 -13986
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +18888 -13992
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +18866 -13983
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelPaginatorsOrchestrator.d.ts +130 -0
- package/dist/types/EventHandlerPipeline.d.ts +104 -0
- package/dist/types/api-client.d.ts +26 -0
- package/dist/types/campaign.d.ts +0 -44
- package/dist/types/channel.d.ts +436 -480
- package/dist/types/channel_batch_updater.d.ts +0 -93
- package/dist/types/channel_manager.d.ts +8 -10
- package/dist/types/channel_state.d.ts +53 -201
- package/dist/types/client.d.ts +440 -1910
- package/dist/types/client_state.d.ts +4 -4
- package/dist/types/configuration/InstanceConfigurationService.d.ts +26 -0
- package/dist/types/configuration/index.d.ts +1 -0
- package/dist/types/configuration/types.d.ts +53 -0
- package/dist/types/connection.d.ts +49 -41
- package/dist/types/connection_fallback.d.ts +6 -4
- package/dist/types/constants.d.ts +0 -4
- package/dist/types/custom_types.d.ts +2 -0
- package/dist/types/errors.d.ts +2 -2
- package/dist/types/gen/chat/ChannelApi.d.ts +45 -0
- package/dist/types/gen/chat/ChatApi.d.ts +334 -0
- package/dist/types/gen/model-decoders/decoders.d.ts +3 -0
- package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +6 -0
- package/dist/types/gen/models/index.d.ts +8836 -0
- package/dist/types/gen/moderation/ModerationApi.d.ts +50 -0
- package/dist/types/gen-imports.d.ts +3 -0
- package/dist/types/index.d.ts +5 -5
- package/dist/types/insights.d.ts +7 -6
- package/dist/types/logger.d.ts +9 -0
- package/dist/types/messageComposer/LocationComposer.d.ts +7 -4
- package/dist/types/messageComposer/attachmentIdentity.d.ts +2 -2
- package/dist/types/messageComposer/attachmentManager.d.ts +8 -4
- package/dist/types/messageComposer/configuration/types.d.ts +11 -11
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +25 -13
- package/dist/types/messageComposer/messageComposer.d.ts +10 -10
- package/dist/types/messageComposer/middleware/messageComposer/types.d.ts +3 -3
- package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +4 -7
- package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +3 -3
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +7 -7
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +218 -4
- package/dist/types/messageComposer/middleware/textComposer/types.d.ts +9 -4
- package/dist/types/messageComposer/pollComposer.d.ts +5 -4
- package/dist/types/messageComposer/textComposer.d.ts +8 -3
- package/dist/types/messageComposer/types.d.ts +6 -28
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +40 -25
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +53 -12
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +19 -0
- package/dist/types/messageOperations/MessageOperations.d.ts +17 -0
- package/dist/types/messageOperations/index.d.ts +3 -0
- package/dist/types/messageOperations/types.d.ts +49 -0
- package/dist/types/moderation.d.ts +21 -203
- package/dist/types/notifications/types.d.ts +8 -7
- package/dist/types/offline-support/offline_support_api.d.ts +110 -87
- package/dist/types/offline-support/types.d.ts +19 -23
- package/dist/types/offline-support/util.d.ts +4 -2
- package/dist/types/pagination/FilterBuilder.d.ts +1 -1
- package/dist/types/pagination/ItemIndex.d.ts +82 -0
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +9 -0
- package/dist/types/pagination/cursorDerivation/idAroundPaginationFlags.d.ts +6 -0
- package/dist/types/pagination/cursorDerivation/index.d.ts +1 -0
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +6 -0
- package/dist/types/pagination/filterCompiler.d.ts +7 -0
- package/dist/types/pagination/index.d.ts +1 -3
- package/dist/types/pagination/paginators/BasePaginator.d.ts +709 -0
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +58 -0
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +260 -0
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +208 -0
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +39 -0
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +19 -0
- package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +24 -0
- package/dist/types/pagination/paginators/index.d.ts +7 -0
- package/dist/types/pagination/sortCompiler.d.ts +49 -0
- package/dist/types/pagination/types.normalization.d.ts +11 -0
- package/dist/types/pagination/utility.normalization.d.ts +18 -0
- package/dist/types/pagination/utility.queryChannel.d.ts +26 -0
- package/dist/types/pagination/utility.search.d.ts +13 -0
- package/dist/types/permissions.d.ts +1 -1
- package/dist/types/poll.d.ts +29 -32
- package/dist/types/poll_manager.d.ts +2 -2
- package/dist/types/reminders/Reminder.d.ts +2 -5
- package/dist/types/reminders/ReminderManager.d.ts +2 -9
- package/dist/types/search/MessageSearchSource.d.ts +4 -4
- package/dist/types/search/UserSearchSource.d.ts +1 -1
- package/dist/types/search/types.d.ts +3 -3
- package/dist/types/segment.d.ts +0 -34
- package/dist/types/signing.d.ts +105 -65
- package/dist/types/store.d.ts +1 -0
- package/dist/types/thread.d.ts +51 -34
- package/dist/types/thread_manager.d.ts +3 -3
- package/dist/types/token_manager.d.ts +15 -10
- package/dist/types/types.d.ts +196 -3384
- package/dist/types/utils/FixedSizeQueueCache.d.ts +12 -6
- package/dist/types/utils/WithSubscriptions.d.ts +2 -1
- package/dist/types/utils/concurrency.d.ts +4 -4
- package/dist/types/utils/mergeWith/mergeWith.d.ts +3 -3
- package/dist/types/utils/mergeWith/mergeWithCore.d.ts +8 -3
- package/dist/types/utils/retryable.d.ts +34 -0
- package/dist/types/utils.d.ts +104 -137
- package/package.json +7 -3
- package/src/ChannelPaginatorsOrchestrator.ts +545 -0
- package/src/CooldownTimer.ts +2 -2
- package/src/EventHandlerPipeline.ts +228 -0
- package/src/LiveLocationManager.ts +12 -11
- package/src/api-client.ts +275 -0
- package/src/campaign.ts +1 -77
- package/src/channel.ts +1262 -1277
- package/src/channel_batch_updater.ts +1 -211
- package/src/channel_manager.ts +92 -88
- package/src/channel_state.ts +144 -1013
- package/src/client.ts +888 -3944
- package/src/client_state.ts +4 -4
- package/src/configuration/InstanceConfigurationService.ts +73 -0
- package/src/configuration/index.ts +1 -0
- package/src/configuration/types.ts +81 -0
- package/src/connection.ts +145 -94
- package/src/connection_fallback.ts +29 -27
- package/src/constants.ts +1 -5
- package/src/custom_types.ts +4 -1
- package/src/errors.ts +2 -2
- package/src/gen/chat/ChannelApi.ts +275 -0
- package/src/gen/chat/ChatApi.ts +2554 -0
- package/src/gen/model-decoders/decoders.ts +2680 -0
- package/src/gen/model-decoders/event-decoder-mapping.ts +198 -0
- package/src/gen/models/index.ts +12673 -0
- package/src/gen/moderation/ModerationApi.ts +607 -0
- package/src/gen-imports.ts +3 -0
- package/src/index.ts +5 -10
- package/src/insights.ts +6 -5
- package/src/logger.ts +28 -0
- package/src/messageComposer/LocationComposer.ts +9 -5
- package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -0
- package/src/messageComposer/attachmentIdentity.ts +16 -9
- package/src/messageComposer/attachmentManager.ts +13 -8
- package/src/messageComposer/configuration/types.ts +11 -11
- package/src/messageComposer/linkPreviewsManager.ts +9 -10
- package/src/messageComposer/messageComposer.ts +57 -53
- package/src/messageComposer/middleware/messageComposer/attachments.ts +1 -2
- package/src/messageComposer/middleware/messageComposer/cleanData.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/compositionValidation.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/messageComposerState.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +4 -3
- package/src/messageComposer/middleware/messageComposer/textComposer.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/types.ts +3 -4
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +9 -5
- package/src/messageComposer/middleware/pollComposer/state.ts +0 -2
- package/src/messageComposer/middleware/pollComposer/types.ts +4 -7
- package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +10 -1
- package/src/messageComposer/middleware/textComposer/commandEffects.ts +4 -4
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +3 -6
- package/src/messageComposer/middleware/textComposer/commands.ts +3 -3
- package/src/messageComposer/middleware/textComposer/mentionUtils.ts +1 -1
- package/src/messageComposer/middleware/textComposer/mentions.ts +31 -15
- package/src/messageComposer/middleware/textComposer/types.ts +9 -4
- package/src/messageComposer/pollComposer.ts +6 -8
- package/src/messageComposer/textComposer.ts +27 -2
- package/src/messageComposer/types.ts +6 -28
- package/src/messageDelivery/MessageDeliveryReporter.ts +101 -45
- package/src/messageDelivery/MessageReceiptsTracker.ts +294 -21
- package/src/messageOperations/MessageOperationStatePolicy.ts +77 -0
- package/src/messageOperations/MessageOperations.ts +212 -0
- package/src/messageOperations/index.ts +10 -0
- package/src/messageOperations/types.ts +64 -0
- package/src/moderation.ts +38 -431
- package/src/notifications/types.ts +8 -7
- package/src/offline-support/offline_support_api.ts +198 -132
- package/src/offline-support/offline_sync_manager.ts +17 -7
- package/src/offline-support/types.ts +23 -26
- package/src/offline-support/util.ts +5 -4
- package/src/pagination/FilterBuilder.ts +4 -1
- package/src/pagination/ItemIndex.ts +112 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +73 -0
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +53 -0
- package/src/pagination/cursorDerivation/index.ts +1 -0
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +86 -0
- package/src/pagination/filterCompiler.ts +196 -0
- package/src/pagination/index.ts +1 -3
- package/src/pagination/paginators/BasePaginator.ts +2393 -0
- package/src/pagination/paginators/ChannelPaginator.ts +427 -0
- package/src/pagination/paginators/MessageIntervalPaginator.ts +1073 -0
- package/src/pagination/paginators/MessagePaginator.ts +496 -0
- package/src/pagination/paginators/PinnedMessagePaginator.ts +105 -0
- package/src/pagination/paginators/ReminderPaginator.ts +105 -0
- package/src/pagination/paginators/UserGroupPaginator.ts +125 -0
- package/src/pagination/paginators/index.ts +7 -0
- package/src/pagination/sortCompiler.ts +178 -0
- package/src/pagination/types.normalization.ts +14 -0
- package/src/pagination/utility.normalization.ts +106 -0
- package/src/pagination/utility.queryChannel.ts +84 -0
- package/src/pagination/utility.search.ts +80 -0
- package/src/permissions.ts +7 -8
- package/src/poll.ts +101 -110
- package/src/poll_manager.ts +14 -8
- package/src/reminders/Reminder.ts +2 -5
- package/src/reminders/ReminderManager.ts +19 -21
- package/src/search/BaseSearchSource.ts +0 -3
- package/src/search/ChannelMemberSearchSource.ts +7 -1
- package/src/search/ChannelSearchSource.ts +10 -3
- package/src/search/MessageSearchSource.ts +29 -30
- package/src/search/UserSearchSource.ts +12 -8
- package/src/search/types.ts +3 -4
- package/src/segment.ts +1 -95
- package/src/signing.ts +107 -67
- package/src/store.ts +2 -1
- package/src/thread.ts +439 -236
- package/src/thread_manager.ts +36 -15
- package/src/token_manager.ts +21 -10
- package/src/types.ts +375 -4524
- package/src/uploadManager.ts +8 -0
- package/src/utils/FixedSizeQueueCache.ts +12 -6
- package/src/utils/WithSubscriptions.ts +2 -1
- package/src/utils/concurrency.ts +4 -4
- package/src/utils/mergeWith/mergeWith.ts +3 -3
- package/src/utils/mergeWith/mergeWithCore.ts +140 -164
- package/src/utils/mergeWith/mergeWithDiff.ts +3 -3
- package/src/utils/retryable.ts +117 -0
- package/src/utils.ts +133 -524
- package/dist/types/events.d.ts +0 -72
- package/dist/types/pagination/BasePaginator.d.ts +0 -69
- package/dist/types/pagination/ReminderPaginator.d.ts +0 -16
- package/dist/types/pagination/UserGroupPaginator.d.ts +0 -21
- package/src/events.ts +0 -75
- package/src/pagination/BasePaginator.ts +0 -184
- package/src/pagination/ReminderPaginator.ts +0 -56
- 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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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<
|
|
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
|
-
*
|
|
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
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* @
|
|
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
|
-
*
|
|
123
|
-
*
|
|
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.
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
188
|
-
* @
|
|
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
|
|
199
|
-
* if not already scheduled and candidates exist.
|
|
200
|
-
*
|
|
201
|
-
*
|
|
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
|
-
*
|
|
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:
|
|
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
|
|
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
|
-
.
|
|
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
|
-
*
|
|
279
|
-
* @param
|
|
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?:
|
|
301
|
+
public markRead = async (collection: Channel | Thread, options?: MarkReadRequest) => {
|
|
282
302
|
if (!userHasReadReceipts(this.client)) return null;
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
}
|