stream-chat 10.0.0-rc.25 → 10.0.0-rc.27
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/README.md +1 -1
- package/dist/cjs/index.browser.js +261 -46
- package/dist/cjs/index.browser.js.map +2 -2
- package/dist/cjs/index.node.js +261 -46
- package/dist/cjs/index.node.js.map +2 -2
- package/dist/esm/index.mjs +261 -46
- package/dist/esm/index.mjs.map +2 -2
- package/dist/types/ChannelManager.d.ts +2 -2
- package/dist/types/channel_state.d.ts +6 -5
- package/dist/types/connection/wsConnection/StableWSConnection.d.ts +14 -2
- package/dist/types/gen/chat/ChannelApi.d.ts +4 -1
- package/dist/types/gen/chat/ChatApi.d.ts +16 -2
- package/dist/types/gen/models/index.d.ts +563 -103
- package/dist/types/gen/moderation/ModerationApi.d.ts +2 -1
- package/dist/types/pagination/paginators/BasePaginator.d.ts +2 -0
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +22 -2
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +7 -0
- package/dist/types/utils/concurrency.d.ts +1 -1
- package/package.json +1 -1
- package/src/ChannelManager.ts +2 -2
- package/src/channel.ts +2 -11
- package/src/channel_state.ts +5 -3
- package/src/connection/wsConnection/StableWSConnection.ts +68 -5
- package/src/gen/chat/ChannelApi.ts +57 -0
- package/src/gen/chat/ChatApi.ts +56 -2
- package/src/gen/models/index.ts +620 -105
- package/src/gen/moderation/ModerationApi.ts +17 -0
- package/src/messageComposer/middleware/messageComposer/attachments.ts +19 -9
- package/src/messageComposer/middleware/messageComposer/customData.ts +5 -5
- package/src/messageDelivery/MessageReceiptsTracker.ts +1 -1
- package/src/messageOperations/MessageOperations.ts +14 -9
- package/src/notifications/NotificationManager.ts +1 -1
- package/src/pagination/paginators/BasePaginator.ts +9 -1
- package/src/pagination/paginators/ChannelPaginator.ts +100 -10
- package/src/pagination/paginators/MessageIntervalPaginator.ts +17 -3
- package/src/poll_optimistic_votes.ts +6 -1
package/README.md
CHANGED
|
@@ -102,7 +102,7 @@ message.custom_property; // in the response object as well
|
|
|
102
102
|
```
|
|
103
103
|
|
|
104
104
|
> [!WARNING]
|
|
105
|
-
> Generics mechanism has been removed in version `9.0.0` in favour of the module augmentation, please see [the release guide](https://getstream.io/chat/docs/
|
|
105
|
+
> Generics mechanism has been removed in version `9.0.0` in favour of the module augmentation, please see [the release guide](https://getstream.io/chat/docs/javascript/upgrade-stream-chat-to-v9/) on how to migrate.
|
|
106
106
|
|
|
107
107
|
## 🔗 (Optional) Development Setup in Combination With Our SDKs
|
|
108
108
|
|
|
@@ -3407,22 +3407,24 @@ var localAttachmentToAttachment = (localAttachment) => {
|
|
|
3407
3407
|
const { localMetadata: _localMetadata, ...attachment } = localAttachment;
|
|
3408
3408
|
return attachment;
|
|
3409
3409
|
};
|
|
3410
|
+
var isSendable = (attachment) => isFinishedUpload(attachment) || !isLocalUploadAttachment(attachment);
|
|
3410
3411
|
var composeWithPendingUploads = ({
|
|
3411
3412
|
composer,
|
|
3412
3413
|
state
|
|
3413
3414
|
}) => {
|
|
3414
3415
|
const composerIsKeptAsDraft = composer.retainsCompositionOnSubmit;
|
|
3415
3416
|
const relevantAttachments = composer.attachmentManager.attachments.filter(
|
|
3416
|
-
(attachment) =>
|
|
3417
|
+
(attachment) => isSendable(attachment) || !composerIsKeptAsDraft && (isPendingUpload(attachment) || isFailedUpload(attachment))
|
|
3417
3418
|
);
|
|
3418
3419
|
const localAttachments = (state.localMessage.attachments ?? []).concat(
|
|
3419
|
-
//
|
|
3420
|
+
// A finished upload or a non-upload is final; the rest keep `localMetadata` (joined to the upload
|
|
3421
|
+
// record).
|
|
3420
3422
|
relevantAttachments.map(
|
|
3421
|
-
(attachment) =>
|
|
3423
|
+
(attachment) => isSendable(attachment) ? localAttachmentToAttachment(attachment) : attachment
|
|
3422
3424
|
)
|
|
3423
3425
|
);
|
|
3424
3426
|
const messageAttachments = (state.message.attachments ?? []).concat(
|
|
3425
|
-
relevantAttachments.filter(
|
|
3427
|
+
relevantAttachments.filter(isSendable).map(localAttachmentToAttachment)
|
|
3426
3428
|
);
|
|
3427
3429
|
if (!localAttachments.length && !messageAttachments.length) return state;
|
|
3428
3430
|
return {
|
|
@@ -3465,7 +3467,7 @@ var createAttachmentsCompositionMiddleware = (composer) => ({
|
|
|
3465
3467
|
return discard();
|
|
3466
3468
|
}
|
|
3467
3469
|
const attachments = (state.message.attachments ?? []).concat(
|
|
3468
|
-
attachmentManager.
|
|
3470
|
+
attachmentManager.attachments.filter(isSendable).map(localAttachmentToAttachment)
|
|
3469
3471
|
);
|
|
3470
3472
|
if (!attachments.length) return forward();
|
|
3471
3473
|
return next({
|
|
@@ -3492,9 +3494,9 @@ var createDraftAttachmentsCompositionMiddleware = (composer) => ({
|
|
|
3492
3494
|
}) => {
|
|
3493
3495
|
const { attachmentManager } = composer;
|
|
3494
3496
|
if (!attachmentManager) return forward();
|
|
3495
|
-
const
|
|
3496
|
-
const attachments =
|
|
3497
|
-
|
|
3497
|
+
const sendableAttachments = attachmentManager.attachments.filter(isSendable);
|
|
3498
|
+
const attachments = sendableAttachments.length ? (state.draft.attachments ?? []).concat(
|
|
3499
|
+
sendableAttachments.map(localAttachmentToAttachment)
|
|
3498
3500
|
) : void 0;
|
|
3499
3501
|
return next({
|
|
3500
3502
|
...state,
|
|
@@ -3548,16 +3550,16 @@ var createCustomDataCompositionMiddleware = (composer) => ({
|
|
|
3548
3550
|
forward
|
|
3549
3551
|
}) => {
|
|
3550
3552
|
const data = composer.customDataManager.customMessageData;
|
|
3551
|
-
if (!data) return forward();
|
|
3553
|
+
if (!data || !Object.keys(data).length) return forward();
|
|
3552
3554
|
return next({
|
|
3553
3555
|
...state,
|
|
3554
3556
|
localMessage: {
|
|
3555
3557
|
...state.localMessage,
|
|
3556
|
-
...data
|
|
3558
|
+
custom: { ...state.localMessage.custom, ...data }
|
|
3557
3559
|
},
|
|
3558
3560
|
message: {
|
|
3559
3561
|
...state.message,
|
|
3560
|
-
...data
|
|
3562
|
+
custom: { ...state.message.custom, ...data }
|
|
3561
3563
|
}
|
|
3562
3564
|
});
|
|
3563
3565
|
}
|
|
@@ -3572,12 +3574,12 @@ var createDraftCustomDataCompositionMiddleware = (composer) => ({
|
|
|
3572
3574
|
forward
|
|
3573
3575
|
}) => {
|
|
3574
3576
|
const data = composer.customDataManager.customMessageData;
|
|
3575
|
-
if (!data) return forward();
|
|
3577
|
+
if (!data || !Object.keys(data).length) return forward();
|
|
3576
3578
|
return next({
|
|
3577
3579
|
...state,
|
|
3578
3580
|
draft: {
|
|
3579
3581
|
...state.draft,
|
|
3580
|
-
...data
|
|
3582
|
+
custom: { ...state.draft.custom, ...data }
|
|
3581
3583
|
}
|
|
3582
3584
|
});
|
|
3583
3585
|
}
|
|
@@ -6915,10 +6917,12 @@ var BasePaginator = class {
|
|
|
6915
6917
|
const claims = claimsActiveInterval ?? this.decidesActiveInterval({ queryShape: forcedQueryShape, reset, updateState });
|
|
6916
6918
|
const activeIntervalClaim = claims ? this.claimActiveInterval() : void 0;
|
|
6917
6919
|
const isForcedReset = reset === "yes" && !keepPreviousItems;
|
|
6920
|
+
let positionBeforeReset;
|
|
6918
6921
|
if (isForcedReset) {
|
|
6919
6922
|
this.clearItemStorage();
|
|
6920
6923
|
this.state.next(this.getStateBeforeFirstQuery());
|
|
6921
6924
|
} else if (reset === "yes" && !forcedQueryShape) {
|
|
6925
|
+
positionBeforeReset = { cursor: this.cursor, offset: this.offset };
|
|
6922
6926
|
this.state.partialNext({
|
|
6923
6927
|
cursor: this.config.initialCursor,
|
|
6924
6928
|
offset: this.config.initialOffset ?? 0
|
|
@@ -6967,6 +6971,7 @@ var BasePaginator = class {
|
|
|
6967
6971
|
direction,
|
|
6968
6972
|
isFirstPage,
|
|
6969
6973
|
keepPreviousItems,
|
|
6974
|
+
positionBeforeReset,
|
|
6970
6975
|
queryShape,
|
|
6971
6976
|
requestedPageSize: this.getRequestedPageSize(queryShape),
|
|
6972
6977
|
updateState
|
|
@@ -6982,7 +6987,10 @@ var BasePaginator = class {
|
|
|
6982
6987
|
this._lastQueryShape = params.queryShape;
|
|
6983
6988
|
const { results } = params;
|
|
6984
6989
|
if (!results) {
|
|
6985
|
-
const stateUpdate = {
|
|
6990
|
+
const stateUpdate = {
|
|
6991
|
+
isLoading: false,
|
|
6992
|
+
...params.positionBeforeReset
|
|
6993
|
+
};
|
|
6986
6994
|
this.state.partialNext(stateUpdate);
|
|
6987
6995
|
return { stateCandidate: stateUpdate, targetInterval: null };
|
|
6988
6996
|
}
|
|
@@ -7417,6 +7425,12 @@ var ChannelPaginator = class extends BasePaginator {
|
|
|
7417
7425
|
this._itemsLoadedFromOfflineDB = false;
|
|
7418
7426
|
/** The query in flight refreshes a cache-only interval, so its response replaces the interval. */
|
|
7419
7427
|
this._replaceOfflineSeedOnResponse = false;
|
|
7428
|
+
/** Whether `recoverLoadedItems` runs: its pages own the list's position until it ends. */
|
|
7429
|
+
this._isRecoveringLoadedItems = false;
|
|
7430
|
+
/** A recovery asked for while one runs: the running pass stops and a new one starts. */
|
|
7431
|
+
this._recoveryRequestedAgain = false;
|
|
7432
|
+
/** A next page refused while recovering, queried once the recovery ends. See `executeQuery`. */
|
|
7433
|
+
this._tailQueryAwaitingRecovery = false;
|
|
7420
7434
|
/**
|
|
7421
7435
|
* Filters sent with the next query and used as the offline-db query key. Built from the local
|
|
7422
7436
|
* filters only: the backend-resolved filter would change the query shape after the first response,
|
|
@@ -7444,11 +7458,15 @@ var ChannelPaginator = class extends BasePaginator {
|
|
|
7444
7458
|
if (cachedQuery.predefinedFilter) {
|
|
7445
7459
|
this.applyPredefinedFilterResponse(cachedQuery.predefinedFilter);
|
|
7446
7460
|
}
|
|
7447
|
-
return this.client.hydrateChannels(
|
|
7448
|
-
|
|
7449
|
-
|
|
7450
|
-
|
|
7451
|
-
|
|
7461
|
+
return this.client.hydrateChannels(
|
|
7462
|
+
cachedQuery.channels,
|
|
7463
|
+
{
|
|
7464
|
+
offlineMode: true,
|
|
7465
|
+
skipInitialization: []
|
|
7466
|
+
// an empty array clears existing channel messages (no duplicates)
|
|
7467
|
+
},
|
|
7468
|
+
request
|
|
7469
|
+
);
|
|
7452
7470
|
}
|
|
7453
7471
|
} catch (error) {
|
|
7454
7472
|
chatLoggerSystem.getLogger("channel").error(error.message);
|
|
@@ -7489,16 +7507,60 @@ var ChannelPaginator = class extends BasePaginator {
|
|
|
7489
7507
|
};
|
|
7490
7508
|
/**
|
|
7491
7509
|
* The reconnect refresh. Re-queries every loaded page, then drops the loaded channels no page
|
|
7492
|
-
* returned: they were deleted, left, hidden, or no longer
|
|
7510
|
+
* returned that sort within the re-queried range: they were deleted, left, hidden, or no longer
|
|
7511
|
+
* match the filter. Those sorting below it were not re-queried and stay.
|
|
7493
7512
|
*
|
|
7494
7513
|
* Each page asks for everything still to cover and the next one starts where it ended, so the
|
|
7495
7514
|
* server's page cap decides the step. A failed page removes nothing. At most
|
|
7496
|
-
* {@link MAX_RECOVERED_ITEMS} channels are re-queried
|
|
7515
|
+
* {@link MAX_RECOVERED_ITEMS} channels are re-queried.
|
|
7516
|
+
*
|
|
7517
|
+
* Paging is held meanwhile: a next page asked for is queried once the recovery ends, as the list
|
|
7518
|
+
* end that asked for it does not ask again when the recovery changed nothing. A query of the
|
|
7519
|
+
* list's own already in flight is waited for, as it would make the recovery's refused.
|
|
7520
|
+
*
|
|
7521
|
+
* A call while a recovery runs returns at once and the running pass starts over from the first page
|
|
7522
|
+
* once its page in flight lands, as the pages before were watched on a connection that is gone.
|
|
7497
7523
|
*/
|
|
7498
7524
|
this.recoverLoadedItems = async () => {
|
|
7525
|
+
if (this._isRecoveringLoadedItems) {
|
|
7526
|
+
this._recoveryRequestedAgain = true;
|
|
7527
|
+
return;
|
|
7528
|
+
}
|
|
7529
|
+
this._isRecoveringLoadedItems = true;
|
|
7530
|
+
try {
|
|
7531
|
+
do {
|
|
7532
|
+
this._recoveryRequestedAgain = false;
|
|
7533
|
+
await this.waitForQueryToSettle();
|
|
7534
|
+
await this.recoverLoadedPages();
|
|
7535
|
+
} while (this._recoveryRequestedAgain);
|
|
7536
|
+
} finally {
|
|
7537
|
+
this._isRecoveringLoadedItems = false;
|
|
7538
|
+
}
|
|
7539
|
+
if (!this._tailQueryAwaitingRecovery) return;
|
|
7540
|
+
this._tailQueryAwaitingRecovery = false;
|
|
7541
|
+
runDetached(this.toTail(), { context: "ChannelPaginator.recoverLoadedItems" });
|
|
7542
|
+
};
|
|
7543
|
+
/** Resolves once the list has no query of its own in flight. */
|
|
7544
|
+
this.waitForQueryToSettle = () => new Promise((resolve) => {
|
|
7545
|
+
if (!this.isLoading) {
|
|
7546
|
+
resolve();
|
|
7547
|
+
return;
|
|
7548
|
+
}
|
|
7549
|
+
const unsubscribe = this.state.subscribeWithSelector(
|
|
7550
|
+
({ isLoading }) => ({ isLoading }),
|
|
7551
|
+
({ isLoading }) => {
|
|
7552
|
+
if (isLoading) return;
|
|
7553
|
+
unsubscribe();
|
|
7554
|
+
resolve();
|
|
7555
|
+
}
|
|
7556
|
+
);
|
|
7557
|
+
});
|
|
7558
|
+
this.recoverLoadedPages = async () => {
|
|
7499
7559
|
const loadedCids = new Set((this.items ?? []).map((channel) => channel.cid));
|
|
7500
7560
|
const recoveredCount = Math.min(loadedCids.size, MAX_RECOVERED_ITEMS);
|
|
7501
7561
|
const returnedCids = /* @__PURE__ */ new Set();
|
|
7562
|
+
let lastReturnedCid;
|
|
7563
|
+
let reachedEnd = false;
|
|
7502
7564
|
const shape = this.getNextQueryShape();
|
|
7503
7565
|
let interval = null;
|
|
7504
7566
|
let offset = 0;
|
|
@@ -7513,21 +7575,36 @@ var ChannelPaginator = class extends BasePaginator {
|
|
|
7513
7575
|
updateState: false
|
|
7514
7576
|
});
|
|
7515
7577
|
const page = this.getLastPageCids();
|
|
7516
|
-
if (!result || !page)
|
|
7578
|
+
if (!result || !page || this._recoveryRequestedAgain) {
|
|
7579
|
+
this.state.partialNext({ offset: this.items?.length ?? 0 });
|
|
7580
|
+
return;
|
|
7581
|
+
}
|
|
7517
7582
|
if (result.targetInterval) {
|
|
7518
7583
|
interval = result.targetInterval;
|
|
7519
7584
|
this.setActiveInterval(interval, { updateState: offset === 0 });
|
|
7520
7585
|
}
|
|
7586
|
+
const requested = offset === 0 ? Math.max(this.pageSize, loadedCids.size) : recoveredCount - offset;
|
|
7587
|
+
if (page.length < Math.min(this.pageSize, requested)) reachedEnd = true;
|
|
7521
7588
|
if (!page.length) break;
|
|
7522
7589
|
pageCount++;
|
|
7523
7590
|
for (const channel of result.stateCandidate.items ?? [])
|
|
7524
7591
|
returnedCids.add(channel.cid);
|
|
7592
|
+
lastReturnedCid = page[page.length - 1];
|
|
7525
7593
|
offset += page.length;
|
|
7526
7594
|
} while (offset < recoveredCount);
|
|
7595
|
+
const lastReturned = lastReturnedCid ? this.client.channelManager.get(lastReturnedCid) : void 0;
|
|
7596
|
+
const isWithinRecoveredRange = (cid) => {
|
|
7597
|
+
if (reachedEnd) return true;
|
|
7598
|
+
const channel = this.getItem(cid);
|
|
7599
|
+
if (!channel || !lastReturned) return false;
|
|
7600
|
+
return this.sortComparator(channel, lastReturned) < 0;
|
|
7601
|
+
};
|
|
7527
7602
|
this.batch(
|
|
7528
7603
|
() => {
|
|
7529
7604
|
for (const cid of loadedCids) {
|
|
7530
|
-
if (!returnedCids.has(cid)
|
|
7605
|
+
if (!returnedCids.has(cid) && isWithinRecoveredRange(cid)) {
|
|
7606
|
+
this.removeItem({ id: cid });
|
|
7607
|
+
}
|
|
7531
7608
|
}
|
|
7532
7609
|
},
|
|
7533
7610
|
{ coalesce: true }
|
|
@@ -7661,8 +7738,14 @@ var ChannelPaginator = class extends BasePaginator {
|
|
|
7661
7738
|
* The metadata describes the query as a whole, so it is committed only when a first page lands (a
|
|
7662
7739
|
* failed query keeps the loaded list's). It is committed before `super`, which filters and ingests
|
|
7663
7740
|
* the page using `matchesFilter` and the comparator this metadata feeds.
|
|
7741
|
+
*
|
|
7742
|
+
* A recovery page (see `recoverLoadedItems`) starts where the one before it ended, so it extends
|
|
7743
|
+
* the shown interval, though a page at a caller's shape would otherwise start one of its own.
|
|
7664
7744
|
*/
|
|
7665
7745
|
placeQueryPage(params) {
|
|
7746
|
+
if (this._isRecoveringLoadedItems && params.startsSeparateInterval) {
|
|
7747
|
+
params = { ...params, startsSeparateInterval: false };
|
|
7748
|
+
}
|
|
7666
7749
|
this._lastPageCids = params.results?.items.map((channel) => channel.cid);
|
|
7667
7750
|
const pendingPredefinedFilter = this._pendingPredefinedFilter;
|
|
7668
7751
|
this._pendingPredefinedFilter = void 0;
|
|
@@ -7740,6 +7823,10 @@ var ChannelPaginator = class extends BasePaginator {
|
|
|
7740
7823
|
* network is not deferred.
|
|
7741
7824
|
*/
|
|
7742
7825
|
async executeQuery(params = {}) {
|
|
7826
|
+
if (this._isRecoveringLoadedItems && params.direction && params.reset !== "yes") {
|
|
7827
|
+
if (params.direction === "tailward") this._tailQueryAwaitingRecovery = true;
|
|
7828
|
+
return;
|
|
7829
|
+
}
|
|
7743
7830
|
const { offlineDb } = this.client;
|
|
7744
7831
|
const effectiveParams = this._itemsLoadedFromOfflineDB && params.reset !== "yes" ? { ...params, keepPreviousItems: true, reset: "yes" } : params;
|
|
7745
7832
|
const queryShape = effectiveParams.queryShape ?? this.getNextQueryShape();
|
|
@@ -7818,6 +7905,7 @@ var ChannelPaginator = class extends BasePaginator {
|
|
|
7818
7905
|
super.resetState();
|
|
7819
7906
|
this._itemIndex.clear();
|
|
7820
7907
|
this._queryAwaitingSync = void 0;
|
|
7908
|
+
this._tailQueryAwaitingRecovery = false;
|
|
7821
7909
|
}
|
|
7822
7910
|
removeItem(params) {
|
|
7823
7911
|
const coordinates = super.removeItem(params);
|
|
@@ -8069,7 +8157,7 @@ var MessageIntervalPaginator = class extends BasePaginator {
|
|
|
8069
8157
|
if (this.parentMessageId) {
|
|
8070
8158
|
const repliesResponse = await this.channel.getClient().getReplies(
|
|
8071
8159
|
{ parent_id: this.parentMessageId },
|
|
8072
|
-
{ ...options, sort: this.
|
|
8160
|
+
{ ...options, sort: this.getRepliesRequestSort(options) }
|
|
8073
8161
|
);
|
|
8074
8162
|
return { repliesResponse, source: "replies" };
|
|
8075
8163
|
}
|
|
@@ -9350,7 +9438,8 @@ var MessageIntervalPaginator = class extends BasePaginator {
|
|
|
9350
9438
|
if (fallback) {
|
|
9351
9439
|
this.setActiveInterval(fallback);
|
|
9352
9440
|
} else {
|
|
9353
|
-
this.
|
|
9441
|
+
this.setActiveInterval(void 0);
|
|
9442
|
+
this.state.partialNext({ items: [], hasMoreTail: false });
|
|
9354
9443
|
}
|
|
9355
9444
|
}
|
|
9356
9445
|
/**
|
|
@@ -9395,6 +9484,16 @@ var MessageIntervalPaginator = class extends BasePaginator {
|
|
|
9395
9484
|
filterQueryResults(items) {
|
|
9396
9485
|
return items.filter(this.shouldIncludeMessageInInterval.bind(this));
|
|
9397
9486
|
}
|
|
9487
|
+
/**
|
|
9488
|
+
* The sort of a replies request. A page newer than a cursor (`id_gt`, `created_at_after`, ...)
|
|
9489
|
+
* must hold the replies right after the cursor, so it is requested oldest first: newest first
|
|
9490
|
+
* returns the newest replies and skips the ones in between. The page is put in item order
|
|
9491
|
+
* afterwards, so the request sort only decides which replies the page holds.
|
|
9492
|
+
*/
|
|
9493
|
+
getRepliesRequestSort(options) {
|
|
9494
|
+
if (getLinearQueryDirection(options) !== "headward") return this.requestSort;
|
|
9495
|
+
return this.requestSort.map((sort) => ({ ...sort, direction: 1 }));
|
|
9496
|
+
}
|
|
9398
9497
|
getCanonicalQueryItems(items) {
|
|
9399
9498
|
return [...items].sort(this.itemOrderComparator);
|
|
9400
9499
|
}
|
|
@@ -14343,7 +14442,7 @@ var MessageReceiptsTracker = class extends WithSubscriptions {
|
|
|
14343
14442
|
* cursor says nothing about whether anyone received the message.
|
|
14344
14443
|
*/
|
|
14345
14444
|
furthestRefByOthers(sorted, refOf) {
|
|
14346
|
-
const ownUserId = this.channel.getClient().
|
|
14445
|
+
const ownUserId = this.channel.getClient().userId;
|
|
14347
14446
|
for (let i = sorted.length - 1; i >= 0; i -= 1) {
|
|
14348
14447
|
if (sorted[i].user.id === ownUserId) continue;
|
|
14349
14448
|
const ref = refOf(sorted[i]);
|
|
@@ -14649,6 +14748,14 @@ var DEFAULT_MESSAGE_OPERATIONS_CONFIG = deepFreezeConfig({
|
|
|
14649
14748
|
failedSendCacheMaxSize: 100,
|
|
14650
14749
|
failedSendCacheTtlMs: 5 * 60 * 1e3
|
|
14651
14750
|
});
|
|
14751
|
+
var pickUpdateOptions = (options) => {
|
|
14752
|
+
if (!options) return void 0;
|
|
14753
|
+
const picked = {};
|
|
14754
|
+
if (typeof options.skip_enrich_url === "boolean")
|
|
14755
|
+
picked.skip_enrich_url = options.skip_enrich_url;
|
|
14756
|
+
if (typeof options.skip_push === "boolean") picked.skip_push = options.skip_push;
|
|
14757
|
+
return picked;
|
|
14758
|
+
};
|
|
14652
14759
|
var MessageOperations = class {
|
|
14653
14760
|
constructor(ctx) {
|
|
14654
14761
|
this.failedSendCache = new FailedSendCache(() => this.config);
|
|
@@ -14811,20 +14918,12 @@ var MessageOperations = class {
|
|
|
14811
14918
|
async update(params) {
|
|
14812
14919
|
this.failedSendCache.rewriteWithEdit(params.localMessage);
|
|
14813
14920
|
const handlers = this.ctx.handlers();
|
|
14814
|
-
let updateOptions;
|
|
14815
|
-
if (params.options) {
|
|
14816
|
-
updateOptions = {};
|
|
14817
|
-
if (typeof params.options.skip_enrich_url === "boolean")
|
|
14818
|
-
updateOptions.skip_enrich_url = params.options.skip_enrich_url;
|
|
14819
|
-
if (typeof params.options.skip_push === "boolean")
|
|
14820
|
-
updateOptions.skip_push = params.options.skip_push;
|
|
14821
|
-
}
|
|
14822
14921
|
return await this.run(
|
|
14823
14922
|
"update",
|
|
14824
14923
|
params,
|
|
14825
14924
|
this.resolveRequest(
|
|
14826
14925
|
handlers.update,
|
|
14827
|
-
async (p) => await this.ctx.defaults.update(p.localMessage,
|
|
14926
|
+
async (p) => await this.ctx.defaults.update(p.localMessage, pickUpdateOptions(p.options))
|
|
14828
14927
|
)
|
|
14829
14928
|
);
|
|
14830
14929
|
}
|
|
@@ -15324,6 +15423,30 @@ var ChannelApi = class {
|
|
|
15324
15423
|
requestOptions
|
|
15325
15424
|
);
|
|
15326
15425
|
}
|
|
15426
|
+
fork(request, requestOptions) {
|
|
15427
|
+
if (!this.id) {
|
|
15428
|
+
throw new Error(
|
|
15429
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`
|
|
15430
|
+
);
|
|
15431
|
+
}
|
|
15432
|
+
return this.chatApi.forkChannel(
|
|
15433
|
+
{ id: this.id, type: this.type },
|
|
15434
|
+
request,
|
|
15435
|
+
requestOptions
|
|
15436
|
+
);
|
|
15437
|
+
}
|
|
15438
|
+
forkMessageIDs(request, requestOptions) {
|
|
15439
|
+
if (!this.id) {
|
|
15440
|
+
throw new Error(
|
|
15441
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`
|
|
15442
|
+
);
|
|
15443
|
+
}
|
|
15444
|
+
return this.chatApi.forkMessageIDs(
|
|
15445
|
+
{ id: this.id, type: this.type },
|
|
15446
|
+
request,
|
|
15447
|
+
requestOptions
|
|
15448
|
+
);
|
|
15449
|
+
}
|
|
15327
15450
|
hide(request, requestOptions) {
|
|
15328
15451
|
if (!this.id) {
|
|
15329
15452
|
throw new Error(
|
|
@@ -15432,6 +15555,18 @@ var ChannelApi = class {
|
|
|
15432
15555
|
requestOptions
|
|
15433
15556
|
);
|
|
15434
15557
|
}
|
|
15558
|
+
rewind(request, requestOptions) {
|
|
15559
|
+
if (!this.id) {
|
|
15560
|
+
throw new Error(
|
|
15561
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`
|
|
15562
|
+
);
|
|
15563
|
+
}
|
|
15564
|
+
return this.chatApi.rewindChannel(
|
|
15565
|
+
{ id: this.id, type: this.type },
|
|
15566
|
+
request,
|
|
15567
|
+
requestOptions
|
|
15568
|
+
);
|
|
15569
|
+
}
|
|
15435
15570
|
show(request, requestOptions) {
|
|
15436
15571
|
if (!this.id) {
|
|
15437
15572
|
throw new Error(
|
|
@@ -17119,8 +17254,7 @@ var Channel = class extends ChannelApi {
|
|
|
17119
17254
|
if (event.user?.id && event.created_at != null) {
|
|
17120
17255
|
const eventUser = event.user;
|
|
17121
17256
|
const createdAt = event.created_at;
|
|
17122
|
-
const
|
|
17123
|
-
const resolvedDeliveredAt = Number.isFinite(parsedDeliveredAt) ? msToNs(parsedDeliveredAt) : createdAt;
|
|
17257
|
+
const resolvedDeliveredAt = event.last_delivered_at ?? createdAt;
|
|
17124
17258
|
this._upsertReadState(
|
|
17125
17259
|
eventUser.id,
|
|
17126
17260
|
(currentUserReadState) => {
|
|
@@ -19258,6 +19392,17 @@ var ModerationApi = class {
|
|
|
19258
19392
|
requestOptions
|
|
19259
19393
|
);
|
|
19260
19394
|
}
|
|
19395
|
+
revealMedia(request, requestOptions) {
|
|
19396
|
+
return this.apiClient.sendRequest(
|
|
19397
|
+
"POST",
|
|
19398
|
+
"/api/v2/moderation/reveal_media",
|
|
19399
|
+
void 0,
|
|
19400
|
+
void 0,
|
|
19401
|
+
request,
|
|
19402
|
+
"application/json",
|
|
19403
|
+
requestOptions
|
|
19404
|
+
);
|
|
19405
|
+
}
|
|
19261
19406
|
queryReviewQueue(request, requestOptions) {
|
|
19262
19407
|
return this.apiClient.sendRequest(
|
|
19263
19408
|
"POST",
|
|
@@ -19950,9 +20095,14 @@ function applyOwnVoteDelta(state, {
|
|
|
19950
20095
|
}
|
|
19951
20096
|
voteCount = Math.max(voteCount - 1, 0);
|
|
19952
20097
|
if (latestVotesByOption?.[optionId]) {
|
|
19953
|
-
|
|
20098
|
+
const latestVotes = latestVotesByOption[optionId].filter(
|
|
19954
20099
|
(latestVote) => latestVote.id !== vote.id
|
|
19955
20100
|
);
|
|
20101
|
+
if (latestVotes.length) {
|
|
20102
|
+
latestVotesByOption[optionId] = latestVotes;
|
|
20103
|
+
} else {
|
|
20104
|
+
delete latestVotesByOption[optionId];
|
|
20105
|
+
}
|
|
19956
20106
|
}
|
|
19957
20107
|
}
|
|
19958
20108
|
for (const vote of add) {
|
|
@@ -20814,8 +20964,8 @@ var _ChannelManager = class _ChannelManager extends WithSubscriptions {
|
|
|
20814
20964
|
* watches by default), those below it come back through `restoreInterruptedWatch`.
|
|
20815
20965
|
* Never-queried paginators are skipped: they run their own first query on mount, and querying them
|
|
20816
20966
|
* here would race it. Unlike {@link ChannelManager.reload}, it merges the page into the loaded
|
|
20817
|
-
* list (`keepPreviousItems`) instead of blanking it
|
|
20818
|
-
*
|
|
20967
|
+
* list (`keepPreviousItems`) instead of blanking it. Its pages are `silent` so paging is held while it
|
|
20968
|
+
* runs and a recovery asked for meanwhile supersedes it (see `ChannelPaginator.recoverLoadedItems`).
|
|
20819
20969
|
*/
|
|
20820
20970
|
this.recover = async () => await Promise.allSettled(
|
|
20821
20971
|
this.paginators.filter((paginator) => paginator.isInitialized).map(async (paginator) => {
|
|
@@ -21831,6 +21981,10 @@ var StableWSConnection = class {
|
|
|
21831
21981
|
if (data.type === "health.check" || data.type === "connection.ok") {
|
|
21832
21982
|
this.scheduleNextPing();
|
|
21833
21983
|
}
|
|
21984
|
+
if (data?.type === "connection.error" && data?.error?.code === chatCodes.TOKEN_EXPIRED) {
|
|
21985
|
+
logger15.withExtraTags("onmessage").debug("The server reported that the token expired.", { wsID: wsId });
|
|
21986
|
+
this.tokenExpiredByServer = true;
|
|
21987
|
+
}
|
|
21834
21988
|
this.client.dispatchEvent(decodedData);
|
|
21835
21989
|
this.scheduleConnectionCheck();
|
|
21836
21990
|
};
|
|
@@ -21857,7 +22011,7 @@ var StableWSConnection = class {
|
|
|
21857
22011
|
logger15.withExtraTags("onclose").warn("The WebSocket connection was closed. Attempting to reconnect.", {
|
|
21858
22012
|
event
|
|
21859
22013
|
});
|
|
21860
|
-
this.
|
|
22014
|
+
this._reconnectAfterFailure();
|
|
21861
22015
|
}
|
|
21862
22016
|
};
|
|
21863
22017
|
this.onerror = (wsId, event) => {
|
|
@@ -21868,7 +22022,7 @@ var StableWSConnection = class {
|
|
|
21868
22022
|
this.isConnecting = false;
|
|
21869
22023
|
this.rejectPromise?.(this._errorFromWSEvent(event));
|
|
21870
22024
|
logger15.withExtraTags("onerror").warn("The WebSocket connection raised an error.", { event });
|
|
21871
|
-
this.
|
|
22025
|
+
this._reconnectAfterFailure();
|
|
21872
22026
|
};
|
|
21873
22027
|
/** Applies a status change; on a drop, marks the channel watches as interrupted. */
|
|
21874
22028
|
this._setHealth = (healthy) => {
|
|
@@ -21905,6 +22059,7 @@ var StableWSConnection = class {
|
|
|
21905
22059
|
};
|
|
21906
22060
|
this._setupConnectionPromise = () => {
|
|
21907
22061
|
this.isResolved = false;
|
|
22062
|
+
this.tokenExpiredByServer = false;
|
|
21908
22063
|
this.connectionOpen = new Promise((resolve, reject) => {
|
|
21909
22064
|
this.resolvePromise = resolve;
|
|
21910
22065
|
this.rejectPromise = reject;
|
|
@@ -21950,6 +22105,7 @@ var StableWSConnection = class {
|
|
|
21950
22105
|
this.isHealthy = false;
|
|
21951
22106
|
this.wsID = 1;
|
|
21952
22107
|
this.lastEvent = null;
|
|
22108
|
+
this.tokenExpiredByServer = false;
|
|
21953
22109
|
}
|
|
21954
22110
|
/** Read live from the parent, so a config update reaches an already open socket. */
|
|
21955
22111
|
get config() {
|
|
@@ -22058,6 +22214,7 @@ var StableWSConnection = class {
|
|
|
22058
22214
|
this.wsID += 1;
|
|
22059
22215
|
this.isConnecting = false;
|
|
22060
22216
|
this.isDisconnected = true;
|
|
22217
|
+
this.tokenExpiredByServer = false;
|
|
22061
22218
|
this.client.connectionIdManager.invalidate();
|
|
22062
22219
|
if (this.healthCheckTimeoutRef) {
|
|
22063
22220
|
clearTimeout(this.healthCheckTimeoutRef);
|
|
@@ -22162,7 +22319,19 @@ var StableWSConnection = class {
|
|
|
22162
22319
|
logger15.withExtraTags("_reconnect").info("Destroying the current WebSocket connection.");
|
|
22163
22320
|
this._destroyCurrentWSConnection();
|
|
22164
22321
|
if (options.refreshToken) {
|
|
22165
|
-
|
|
22322
|
+
try {
|
|
22323
|
+
await this.client.tokenManager.loadToken();
|
|
22324
|
+
} catch (error) {
|
|
22325
|
+
this._applyHealth(false);
|
|
22326
|
+
this.consecutiveFailures += 1;
|
|
22327
|
+
logger15.withExtraTags("_reconnect").warn("Failed to reload the token. Retrying the reconnect.", { error });
|
|
22328
|
+
this._reconnect({ refreshToken: true });
|
|
22329
|
+
return;
|
|
22330
|
+
}
|
|
22331
|
+
if (this.isConnecting || this.isHealthy) {
|
|
22332
|
+
logger15.withExtraTags("_reconnect").debug("Aborting the reconnect: already connecting or healthy.");
|
|
22333
|
+
return;
|
|
22334
|
+
}
|
|
22166
22335
|
}
|
|
22167
22336
|
try {
|
|
22168
22337
|
await this._connect();
|
|
@@ -22205,6 +22374,19 @@ var StableWSConnection = class {
|
|
|
22205
22374
|
this._reconnect({ interval: WS_NETWORK_RECOVERY_RETRY_MS });
|
|
22206
22375
|
}
|
|
22207
22376
|
}
|
|
22377
|
+
/**
|
|
22378
|
+
* _reconnectAfterFailure - Reconnects after the socket closed or failed. If the server
|
|
22379
|
+
* reported that the token expired, the token is refreshed before reconnecting.
|
|
22380
|
+
* Static tokens cannot be refreshed and reconnect as before.
|
|
22381
|
+
*/
|
|
22382
|
+
_reconnectAfterFailure() {
|
|
22383
|
+
if (this.tokenExpiredByServer && !this.client.tokenManager.isStatic()) {
|
|
22384
|
+
logger15.withExtraTags("_reconnectAfterFailure").info("The token expired. Reloading the token and reconnecting.");
|
|
22385
|
+
this._reconnect({ refreshToken: true });
|
|
22386
|
+
return;
|
|
22387
|
+
}
|
|
22388
|
+
this._reconnect();
|
|
22389
|
+
}
|
|
22208
22390
|
/**
|
|
22209
22391
|
* Writes the status to the field and to `client.wsConnection.state`, and drops the connection ID
|
|
22210
22392
|
* when it goes down. Returns whether the status changed. Every transition goes through here
|
|
@@ -23479,6 +23661,28 @@ var ChatApi = class {
|
|
|
23479
23661
|
requestOptions
|
|
23480
23662
|
);
|
|
23481
23663
|
}
|
|
23664
|
+
forkChannel(pathParams, request, requestOptions) {
|
|
23665
|
+
return this.apiClient.sendRequest(
|
|
23666
|
+
"POST",
|
|
23667
|
+
"/api/v2/chat/channels/{type}/{id}/fork",
|
|
23668
|
+
pathParams,
|
|
23669
|
+
void 0,
|
|
23670
|
+
request,
|
|
23671
|
+
"application/json",
|
|
23672
|
+
requestOptions
|
|
23673
|
+
);
|
|
23674
|
+
}
|
|
23675
|
+
forkMessageIDs(pathParams, request, requestOptions) {
|
|
23676
|
+
return this.apiClient.sendRequest(
|
|
23677
|
+
"POST",
|
|
23678
|
+
"/api/v2/chat/channels/{type}/{id}/fork/message_ids",
|
|
23679
|
+
pathParams,
|
|
23680
|
+
void 0,
|
|
23681
|
+
request,
|
|
23682
|
+
"application/json",
|
|
23683
|
+
requestOptions
|
|
23684
|
+
);
|
|
23685
|
+
}
|
|
23482
23686
|
hideChannel(pathParams, request, requestOptions) {
|
|
23483
23687
|
return this.apiClient.sendRequest(
|
|
23484
23688
|
"POST",
|
|
@@ -23580,6 +23784,17 @@ var ChatApi = class {
|
|
|
23580
23784
|
requestOptions
|
|
23581
23785
|
);
|
|
23582
23786
|
}
|
|
23787
|
+
rewindChannel(pathParams, request, requestOptions) {
|
|
23788
|
+
return this.apiClient.sendRequest(
|
|
23789
|
+
"POST",
|
|
23790
|
+
"/api/v2/chat/channels/{type}/{id}/rewind",
|
|
23791
|
+
pathParams,
|
|
23792
|
+
void 0,
|
|
23793
|
+
request,
|
|
23794
|
+
"application/json",
|
|
23795
|
+
requestOptions
|
|
23796
|
+
);
|
|
23797
|
+
}
|
|
23583
23798
|
showChannel(pathParams, request, requestOptions) {
|
|
23584
23799
|
return this.apiClient.sendRequest(
|
|
23585
23800
|
"POST",
|
|
@@ -23993,12 +24208,12 @@ var ChatApi = class {
|
|
|
23993
24208
|
requestOptions
|
|
23994
24209
|
);
|
|
23995
24210
|
}
|
|
23996
|
-
unreadCounts(
|
|
24211
|
+
unreadCounts(request, requestOptions) {
|
|
23997
24212
|
return this.apiClient.sendRequest(
|
|
23998
24213
|
"GET",
|
|
23999
24214
|
"/api/v2/chat/unread",
|
|
24000
24215
|
void 0,
|
|
24001
|
-
|
|
24216
|
+
request,
|
|
24002
24217
|
void 0,
|
|
24003
24218
|
void 0,
|
|
24004
24219
|
requestOptions
|
|
@@ -24856,7 +25071,7 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
24856
25071
|
return this.userAgent;
|
|
24857
25072
|
}
|
|
24858
25073
|
if (!this.cachedUserAgent) {
|
|
24859
|
-
const version = "10.0.0-rc.
|
|
25074
|
+
const version = "10.0.0-rc.27";
|
|
24860
25075
|
const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
|
|
24861
25076
|
const { name: appName, version: appVersion } = this.appIdentifier ?? {};
|
|
24862
25077
|
const { os, model: deviceModel } = this.deviceIdentifier ?? {};
|