stream-chat 10.0.0-rc.21 → 10.0.0-rc.22
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 +308 -216
- package/dist/cjs/index.browser.js.map +3 -3
- package/dist/cjs/index.node.js +308 -216
- package/dist/cjs/index.node.js.map +3 -3
- package/dist/esm/index.mjs +311 -219
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/client.d.ts +22 -21
- package/dist/types/configuration/types.d.ts +31 -0
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +2 -2
- package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +14 -0
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -4
- package/dist/types/pagination/paginators/BasePaginator.d.ts +5 -1
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +2 -0
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +5 -3
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +5 -1
- package/dist/types/types.d.ts +1 -39
- package/package.json +7 -2
- package/src/ChannelManager.ts +7 -0
- package/src/EventHandlerPipeline.ts +2 -1
- package/src/api-client.ts +14 -8
- package/src/channel.ts +10 -0
- package/src/client.ts +44 -43
- package/src/configuration/keys.ts +5 -0
- package/src/configuration/shape.ts +36 -0
- package/src/configuration/types.ts +31 -0
- package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +30 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +12 -60
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
- package/src/pagination/paginators/BasePaginator.ts +43 -18
- package/src/pagination/paginators/ChannelPaginator.ts +39 -14
- package/src/pagination/paginators/MessageIntervalPaginator.ts +17 -11
- package/src/pagination/paginators/MessagePaginator.ts +51 -5
- package/src/types.ts +1 -40
package/dist/cjs/index.node.js
CHANGED
|
@@ -1525,10 +1525,11 @@ var ApiClient = class {
|
|
|
1525
1525
|
}
|
|
1526
1526
|
populateRequestConfigWithDefaults(additonalConfig) {
|
|
1527
1527
|
const token = this._getToken();
|
|
1528
|
+
const axiosRequestConfig = this.client.config.getConfig("client")?.axiosRequestConfig;
|
|
1528
1529
|
return {
|
|
1529
1530
|
...additonalConfig,
|
|
1530
1531
|
headers: {
|
|
1531
|
-
...
|
|
1532
|
+
...axiosRequestConfig?.headers,
|
|
1532
1533
|
...additonalConfig.headers,
|
|
1533
1534
|
Authorization: token,
|
|
1534
1535
|
"stream-auth-type": this.client.getAuthType(),
|
|
@@ -1538,9 +1539,8 @@ var ApiClient = class {
|
|
|
1538
1539
|
params: {
|
|
1539
1540
|
user_id: this.client.userId,
|
|
1540
1541
|
api_key: this.client.key,
|
|
1541
|
-
//
|
|
1542
|
-
|
|
1543
|
-
...this.client.options.axiosRequestConfig?.params,
|
|
1542
|
+
// Read per request, unlike the rest of `axiosRequestConfig`, which the axios instance took at construction.
|
|
1543
|
+
...axiosRequestConfig?.params,
|
|
1544
1544
|
...additonalConfig.params
|
|
1545
1545
|
}
|
|
1546
1546
|
};
|
|
@@ -1609,7 +1609,7 @@ var ApiClient = class {
|
|
|
1609
1609
|
delayBetweenRetries: (attemptNumber) => retryInterval(attemptNumber + 1),
|
|
1610
1610
|
retryAttempts: 10,
|
|
1611
1611
|
isRetryable: (error) => {
|
|
1612
|
-
if (!(
|
|
1612
|
+
if (!(0, import_axios2.isAxiosError)(error)) return false;
|
|
1613
1613
|
if (error.status === 429 || isTokenExpiredError(error)) return true;
|
|
1614
1614
|
return false;
|
|
1615
1615
|
}
|
|
@@ -1654,7 +1654,7 @@ var toAxiosRequestConfig = ({
|
|
|
1654
1654
|
...typeof timeout === "number" ? { timeout } : {}
|
|
1655
1655
|
});
|
|
1656
1656
|
var errorIsApiError = (error) => {
|
|
1657
|
-
if (!(
|
|
1657
|
+
if (!(0, import_axios2.isAxiosError)(error)) return false;
|
|
1658
1658
|
return typeof error.response?.data?.code === "number";
|
|
1659
1659
|
};
|
|
1660
1660
|
var isTokenExpiredError = (error) => errorIsApiError(error) && error.response?.data.code === chatCodes.TOKEN_EXPIRED;
|
|
@@ -6281,7 +6281,8 @@ var BasePaginator = class {
|
|
|
6281
6281
|
*/
|
|
6282
6282
|
locateByItemInInterval({
|
|
6283
6283
|
item,
|
|
6284
|
-
interval
|
|
6284
|
+
interval,
|
|
6285
|
+
plateauScan = true
|
|
6285
6286
|
}) {
|
|
6286
6287
|
const ids = interval.itemIds;
|
|
6287
6288
|
return binarySearch({
|
|
@@ -6291,7 +6292,7 @@ var BasePaginator = class {
|
|
|
6291
6292
|
itemIdentityEquals: (item1, item2) => this.getItemId(item1) === this.getItemId(item2),
|
|
6292
6293
|
// items in intervals are not sorted by effectiveComparator
|
|
6293
6294
|
compare: this.itemOrderComparator.bind(this),
|
|
6294
|
-
plateauScan
|
|
6295
|
+
plateauScan
|
|
6295
6296
|
});
|
|
6296
6297
|
}
|
|
6297
6298
|
locateIntervalForItem(item) {
|
|
@@ -6313,11 +6314,17 @@ var BasePaginator = class {
|
|
|
6313
6314
|
return void 0;
|
|
6314
6315
|
}
|
|
6315
6316
|
locateByItemInIntervals(item) {
|
|
6316
|
-
const
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6317
|
+
const locateIn = (interval, plateauScan) => {
|
|
6318
|
+
const location = interval && this.locateByItemInInterval({ item, interval, plateauScan });
|
|
6319
|
+
return interval && location ? { interval, ...location } : void 0;
|
|
6320
|
+
};
|
|
6321
|
+
const boundsInterval = this.locateIntervalForItem(item);
|
|
6322
|
+
if (!this._itemIndex.has(this.getItemId(item)))
|
|
6323
|
+
return locateIn(boundsInterval, false);
|
|
6324
|
+
const inBounds = locateIn(boundsInterval);
|
|
6325
|
+
if (inBounds && inBounds.currentIndex > -1) return inBounds;
|
|
6326
|
+
const holdingInterval = this.findIntervalHoldingItem(item);
|
|
6327
|
+
return holdingInterval ? locateIn(holdingInterval) : inBounds;
|
|
6321
6328
|
}
|
|
6322
6329
|
/**
|
|
6323
6330
|
* Locates the current position of the item and the index at which the item should be inserted
|
|
@@ -6983,6 +6990,10 @@ var BasePaginator = class {
|
|
|
6983
6990
|
isJumpQueryShape(_queryShape) {
|
|
6984
6991
|
return false;
|
|
6985
6992
|
}
|
|
6993
|
+
/** The page size a query's results are measured against when deriving the head/tail flags. */
|
|
6994
|
+
getRequestedPageSize(_queryShape) {
|
|
6995
|
+
return this.pageSize;
|
|
6996
|
+
}
|
|
6986
6997
|
getStateAfterQuery(stateUpdate, _isFirstPage) {
|
|
6987
6998
|
const current = this.state.getLatestValue();
|
|
6988
6999
|
return {
|
|
@@ -7086,7 +7097,7 @@ var BasePaginator = class {
|
|
|
7086
7097
|
isFirstPage,
|
|
7087
7098
|
keepPreviousItems,
|
|
7088
7099
|
queryShape,
|
|
7089
|
-
requestedPageSize: this.
|
|
7100
|
+
requestedPageSize: this.getRequestedPageSize(queryShape),
|
|
7090
7101
|
results,
|
|
7091
7102
|
updateState
|
|
7092
7103
|
});
|
|
@@ -7147,6 +7158,16 @@ var BasePaginator = class {
|
|
|
7147
7158
|
stateUpdate.cursor = cursor;
|
|
7148
7159
|
stateUpdate.hasMoreTail = hasMoreTail;
|
|
7149
7160
|
stateUpdate.hasMoreHead = hasMoreHead;
|
|
7161
|
+
} else if (this.config.deriveCursor && direction && !isFirstPage) {
|
|
7162
|
+
stateUpdate.cursor = direction === "headward" ? {
|
|
7163
|
+
headward: resolvedHeadward || null,
|
|
7164
|
+
tailward: this.cursor?.tailward ?? null
|
|
7165
|
+
} : {
|
|
7166
|
+
headward: this.cursor?.headward ?? null,
|
|
7167
|
+
tailward: resolvedTailward || null
|
|
7168
|
+
};
|
|
7169
|
+
if (direction === "headward") stateUpdate.hasMoreHead = !!resolvedHeadward;
|
|
7170
|
+
else stateUpdate.hasMoreTail = !!resolvedTailward;
|
|
7150
7171
|
} else {
|
|
7151
7172
|
stateUpdate.cursor = {
|
|
7152
7173
|
tailward: resolvedTailward || null,
|
|
@@ -7194,6 +7215,7 @@ var BasePaginator = class {
|
|
|
7194
7215
|
}
|
|
7195
7216
|
const state = this.getStateAfterQuery(stateUpdate, isFirstPage);
|
|
7196
7217
|
if (updateState) this.state.next(state);
|
|
7218
|
+
else if (this.isLoading) this.state.partialNext({ isLoading: false });
|
|
7197
7219
|
if (isFirstPage) this.populateOfflineDbAfterQuery({ items: state.items, queryShape });
|
|
7198
7220
|
return {
|
|
7199
7221
|
stateCandidate: state,
|
|
@@ -7286,6 +7308,12 @@ var FilterBuilder = class {
|
|
|
7286
7308
|
};
|
|
7287
7309
|
|
|
7288
7310
|
// src/pagination/paginators/ChannelPaginator.ts
|
|
7311
|
+
var hasSameItems = (current, next) => {
|
|
7312
|
+
if (current === next) return false;
|
|
7313
|
+
if (!current || !next || current.length !== next.length) return false;
|
|
7314
|
+
for (let i = 0; i < next.length; i++) if (current[i] !== next[i]) return false;
|
|
7315
|
+
return true;
|
|
7316
|
+
};
|
|
7289
7317
|
var DEFAULT_BACKEND_SORT = [
|
|
7290
7318
|
{ direction: -1, field: "last_message_at" },
|
|
7291
7319
|
{ direction: -1, field: "updated_at" }
|
|
@@ -7334,11 +7362,8 @@ var hiddenFilterResolver = {
|
|
|
7334
7362
|
};
|
|
7335
7363
|
var lastUpdatedFilterResolver = {
|
|
7336
7364
|
matchesField: (field) => field === "last_updated",
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
const updatedAt = channel.data?.updated_at;
|
|
7340
|
-
return lastMessageAt !== null && updatedAt !== void 0 ? Math.max(lastMessageAt, updatedAt) : lastMessageAt ?? updatedAt;
|
|
7341
|
-
}
|
|
7365
|
+
// the server uses the creation time for a channel without messages
|
|
7366
|
+
resolve: (channel) => channel.messagePaginator.lastMessageAt ?? channel.data?.created_at
|
|
7342
7367
|
};
|
|
7343
7368
|
var membersFilterResolver = {
|
|
7344
7369
|
matchesField: (field) => field === "members",
|
|
@@ -7540,6 +7565,10 @@ var ChannelPaginator = class extends BasePaginator {
|
|
|
7540
7565
|
memberUserNameFilterResolver,
|
|
7541
7566
|
dataFieldFilterResolver
|
|
7542
7567
|
]);
|
|
7568
|
+
this.state.addPreprocessor((next, previous) => {
|
|
7569
|
+
if (previous && hasSameItems(previous.items, next.items))
|
|
7570
|
+
next.items = previous.items;
|
|
7571
|
+
});
|
|
7543
7572
|
}
|
|
7544
7573
|
/**
|
|
7545
7574
|
* Builds the comparator for the given sort — the single construction point, so every rebuild (the
|
|
@@ -7756,11 +7785,21 @@ var ChannelPaginator = class extends BasePaginator {
|
|
|
7756
7785
|
const shouldDeferUntilSynced = !!offlineDb?.getChannelsForQuery && !!this.client.user?.id && !offlineDb.syncManager.isSynced && // Items seeded from the cache are not an already loaded list, so paginating them has to defer too.
|
|
7757
7786
|
(this._itemsLoadedFromOfflineDB || this.isFirstPageQuery({ queryShape, reset: effectiveParams.reset }));
|
|
7758
7787
|
if (!shouldDeferUntilSynced) return await super.executeQuery(effectiveParams);
|
|
7788
|
+
if (this._queryAwaitingSync && !this.config.hasPaginationQueryShapeChanged(this._queryAwaitingSync, queryShape)) {
|
|
7789
|
+
return;
|
|
7790
|
+
}
|
|
7791
|
+
this._queryAwaitingSync = queryShape;
|
|
7759
7792
|
if (!this.isInitialized) {
|
|
7760
|
-
|
|
7761
|
-
|
|
7762
|
-
|
|
7763
|
-
|
|
7793
|
+
let cachedChannels;
|
|
7794
|
+
try {
|
|
7795
|
+
cachedChannels = await this.preloadFirstPageFromOfflineDb({
|
|
7796
|
+
...effectiveParams,
|
|
7797
|
+
queryShape
|
|
7798
|
+
});
|
|
7799
|
+
} catch (error) {
|
|
7800
|
+
this._queryAwaitingSync = void 0;
|
|
7801
|
+
throw error;
|
|
7802
|
+
}
|
|
7764
7803
|
if (cachedChannels?.length) {
|
|
7765
7804
|
this.setItems({ valueOrFactory: cachedChannels, isFirstPage: true });
|
|
7766
7805
|
this._itemsLoadedFromOfflineDB = true;
|
|
@@ -7773,9 +7812,11 @@ var ChannelPaginator = class extends BasePaginator {
|
|
|
7773
7812
|
...this._itemsLoadedFromOfflineDB ? { reset: "yes" } : {}
|
|
7774
7813
|
};
|
|
7775
7814
|
if (offlineDb.syncManager.isSynced) {
|
|
7815
|
+
this._queryAwaitingSync = void 0;
|
|
7776
7816
|
return await super.executeQuery(refreshParams);
|
|
7777
7817
|
}
|
|
7778
7818
|
offlineDb.syncManager.scheduleSyncStatusChangeCallback(this.id, async () => {
|
|
7819
|
+
this._queryAwaitingSync = void 0;
|
|
7779
7820
|
await this.executeQuery(refreshParams);
|
|
7780
7821
|
});
|
|
7781
7822
|
}
|
|
@@ -7817,6 +7858,7 @@ var ChannelPaginator = class extends BasePaginator {
|
|
|
7817
7858
|
resetState() {
|
|
7818
7859
|
super.resetState();
|
|
7819
7860
|
this._itemIndex.clear();
|
|
7861
|
+
this._queryAwaitingSync = void 0;
|
|
7820
7862
|
}
|
|
7821
7863
|
removeItem(params) {
|
|
7822
7864
|
const coordinates = super.removeItem(params);
|
|
@@ -7842,56 +7884,41 @@ function lowerBound(length, predicate) {
|
|
|
7842
7884
|
return lo;
|
|
7843
7885
|
}
|
|
7844
7886
|
|
|
7887
|
+
// src/pagination/cursorDerivation/aroundPaginationFlags.ts
|
|
7888
|
+
var deriveAroundPaginationFlags = ({
|
|
7889
|
+
interval,
|
|
7890
|
+
newerCount,
|
|
7891
|
+
olderCount,
|
|
7892
|
+
pageLength,
|
|
7893
|
+
requestedPageSize
|
|
7894
|
+
}) => {
|
|
7895
|
+
const isPageFull = pageLength >= requestedPageSize;
|
|
7896
|
+
const minShare = Math.floor((olderCount + newerCount) / 2);
|
|
7897
|
+
return {
|
|
7898
|
+
hasMoreHead: !interval.isHead && isPageFull && newerCount >= minShare,
|
|
7899
|
+
hasMoreTail: !interval.isTail && isPageFull && olderCount >= minShare
|
|
7900
|
+
};
|
|
7901
|
+
};
|
|
7902
|
+
|
|
7845
7903
|
// src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts
|
|
7846
7904
|
var deriveCreatedAtAroundPaginationFlags = ({
|
|
7847
7905
|
hasMoreHead,
|
|
7848
7906
|
hasMoreTail,
|
|
7849
7907
|
interval,
|
|
7850
7908
|
page,
|
|
7851
|
-
paginator,
|
|
7852
7909
|
queryShape,
|
|
7853
7910
|
requestedPageSize
|
|
7854
7911
|
}) => {
|
|
7855
|
-
|
|
7856
|
-
if (!queryShape?.created_at_around) return flags;
|
|
7912
|
+
if (!queryShape?.created_at_around) return { hasMoreHead, hasMoreTail };
|
|
7857
7913
|
const createdAtAround = dateToNs(new Date(queryShape.created_at_around));
|
|
7858
|
-
const
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
flags.hasMoreTail = false;
|
|
7867
|
-
}
|
|
7868
|
-
} else if (isBelowTailBound) {
|
|
7869
|
-
flags.hasMoreTail = false;
|
|
7870
|
-
if (requestedPageSizeNotMet) {
|
|
7871
|
-
flags.hasMoreHead = false;
|
|
7872
|
-
}
|
|
7873
|
-
} else if (noMoreMessages) {
|
|
7874
|
-
flags = { hasMoreHead: false, hasMoreTail: false };
|
|
7875
|
-
} else {
|
|
7876
|
-
const [firstPageMsgIsFirstInSet, lastPageMsgIsLastInSet] = [
|
|
7877
|
-
firstPageItem?.id && firstPageItem.id === interval.itemIds[0],
|
|
7878
|
-
lastPageItem?.id && lastPageItem.id === interval.itemIds.slice(-1)[0]
|
|
7879
|
-
];
|
|
7880
|
-
const midPointByCount = Math.floor(page.length / 2);
|
|
7881
|
-
const { insertionIndex } = binarySearch({
|
|
7882
|
-
needle: { created_at: createdAtAround },
|
|
7883
|
-
length: page.length,
|
|
7884
|
-
getItemAt: (index) => page[index],
|
|
7885
|
-
compare: (a, b) => a.created_at - b.created_at,
|
|
7886
|
-
itemIdentityEquals: (a, b) => a.created_at === b.created_at,
|
|
7887
|
-
plateauScan: false
|
|
7888
|
-
});
|
|
7889
|
-
if (insertionIndex !== -1) {
|
|
7890
|
-
if (firstPageMsgIsFirstInSet) flags.hasMoreTail = midPointByCount <= insertionIndex;
|
|
7891
|
-
if (lastPageMsgIsLastInSet) flags.hasMoreHead = midPointByCount >= insertionIndex;
|
|
7892
|
-
}
|
|
7893
|
-
}
|
|
7894
|
-
return flags;
|
|
7914
|
+
const olderCount = page.filter((item) => item.created_at < createdAtAround).length;
|
|
7915
|
+
return deriveAroundPaginationFlags({
|
|
7916
|
+
interval,
|
|
7917
|
+
newerCount: page.length - olderCount,
|
|
7918
|
+
olderCount,
|
|
7919
|
+
pageLength: page.length,
|
|
7920
|
+
requestedPageSize
|
|
7921
|
+
});
|
|
7895
7922
|
};
|
|
7896
7923
|
|
|
7897
7924
|
// src/pagination/cursorDerivation/idAroundPaginationFlags.ts
|
|
@@ -7903,38 +7930,15 @@ var deriveIdAroundPaginationFlags = ({
|
|
|
7903
7930
|
queryShape,
|
|
7904
7931
|
requestedPageSize
|
|
7905
7932
|
}) => {
|
|
7906
|
-
|
|
7907
|
-
if (!queryShape?.id_around) return
|
|
7908
|
-
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
|
|
7915
|
-
const noMoreMessages = (requestedPageSize > interval.itemIds.length || interval.itemIds.length >= page.length) && requestedPageSize > page.length;
|
|
7916
|
-
if (noMoreMessages) {
|
|
7917
|
-
flags = { hasMoreHead: false, hasMoreTail: false };
|
|
7918
|
-
} else if (!page[midPoint]) {
|
|
7919
|
-
return flags;
|
|
7920
|
-
} else if (page[midPoint].id === id_around) {
|
|
7921
|
-
flags = { hasMoreHead: true, hasMoreTail: true };
|
|
7922
|
-
} else {
|
|
7923
|
-
const halves = [page.slice(0, midPoint), page.slice(midPoint)];
|
|
7924
|
-
if (firstPageMsgIsFirstInSet) {
|
|
7925
|
-
const targetMsg = halves[0].find((message) => message.id === id_around);
|
|
7926
|
-
if (targetMsg) {
|
|
7927
|
-
flags.hasMoreTail = false;
|
|
7928
|
-
}
|
|
7929
|
-
}
|
|
7930
|
-
if (lastPageMsgIsLastInSet) {
|
|
7931
|
-
const targetMsg = halves[1].find((message) => message.id === id_around);
|
|
7932
|
-
if (targetMsg) {
|
|
7933
|
-
flags.hasMoreHead = false;
|
|
7934
|
-
}
|
|
7935
|
-
}
|
|
7936
|
-
}
|
|
7937
|
-
return flags;
|
|
7933
|
+
const targetIndex = page.findIndex((item) => item.id === queryShape?.id_around);
|
|
7934
|
+
if (!queryShape?.id_around || targetIndex === -1) return { hasMoreHead, hasMoreTail };
|
|
7935
|
+
return deriveAroundPaginationFlags({
|
|
7936
|
+
interval,
|
|
7937
|
+
newerCount: page.length - 1 - targetIndex,
|
|
7938
|
+
olderCount: targetIndex,
|
|
7939
|
+
pageLength: page.length,
|
|
7940
|
+
requestedPageSize
|
|
7941
|
+
});
|
|
7938
7942
|
};
|
|
7939
7943
|
|
|
7940
7944
|
// src/pagination/cursorDerivation/linearPaginationFlags.ts
|
|
@@ -8154,7 +8158,9 @@ var MessageIntervalPaginator = class extends BasePaginator {
|
|
|
8154
8158
|
};
|
|
8155
8159
|
} else {
|
|
8156
8160
|
const result = await this.executeQuery({
|
|
8157
|
-
|
|
8161
|
+
// Always send a limit, since the replies endpoint ignores `id_around` without one and returns the
|
|
8162
|
+
// newest replies instead.
|
|
8163
|
+
queryShape: { id_around: messageId, limit: pageSize ?? this.pageSize },
|
|
8158
8164
|
...watch && { requestOptions: { watch: true } },
|
|
8159
8165
|
updateState: false
|
|
8160
8166
|
});
|
|
@@ -8429,65 +8435,6 @@ var MessageIntervalPaginator = class extends BasePaginator {
|
|
|
8429
8435
|
}
|
|
8430
8436
|
this.messageFocusSignal.next({ signal: null });
|
|
8431
8437
|
};
|
|
8432
|
-
/**
|
|
8433
|
-
* Partial truncation for `channel.truncated` carrying a `truncated_at`: drop every loaded
|
|
8434
|
-
* message strictly older than the cutoff (keeping newer ones) across all loaded windows,
|
|
8435
|
-
* mirroring the legacy per-message-set pruning. For a full truncation (no `truncated_at`) use
|
|
8436
|
-
* {@link MessageIntervalPaginator.clearStateAndCache} instead.
|
|
8437
|
-
*
|
|
8438
|
-
* Batched and edge-classified: because messages are chronological, each interval is classified by
|
|
8439
|
-
* its `tail` (oldest) and `head` (newest) edges, so only the single interval that *straddles* the
|
|
8440
|
-
* cutoff is scanned member-by-member — the rest are kept or dropped wholesale. The straddling
|
|
8441
|
-
* interval becomes the new global tail (nothing older than the cutoff exists anymore), so its
|
|
8442
|
-
* `isTail`/`hasMoreTail` are set; intervals entirely newer keep their flags (unloaded older
|
|
8443
|
-
* messages may still sit between them and the cutoff). The active window is re-emitted once.
|
|
8444
|
-
*/
|
|
8445
|
-
this.truncate = ({ truncatedAt }) => {
|
|
8446
|
-
const cutoff = truncatedAt;
|
|
8447
|
-
if (!Number.isFinite(cutoff)) return;
|
|
8448
|
-
const isOld = (item) => {
|
|
8449
|
-
const time = getMessageCreatedAtTimestamp(item);
|
|
8450
|
-
return time !== null && time < cutoff;
|
|
8451
|
-
};
|
|
8452
|
-
const removedIds = [];
|
|
8453
|
-
const survivingIntervals = [];
|
|
8454
|
-
for (const interval of this.itemIntervals) {
|
|
8455
|
-
const edges = this.getIntervalPaginationEdges(interval);
|
|
8456
|
-
if (!edges || !isOld(edges.tail)) {
|
|
8457
|
-
survivingIntervals.push(interval);
|
|
8458
|
-
} else if (isOld(edges.head)) {
|
|
8459
|
-
removedIds.push(...interval.itemIds);
|
|
8460
|
-
} else {
|
|
8461
|
-
const ids = interval.itemIds;
|
|
8462
|
-
const splitIndex = lowerBound(
|
|
8463
|
-
ids.length,
|
|
8464
|
-
(index) => !isOld(this._itemIndex.get(ids[index]))
|
|
8465
|
-
);
|
|
8466
|
-
removedIds.push(...ids.slice(0, splitIndex));
|
|
8467
|
-
const kept = ids.slice(splitIndex);
|
|
8468
|
-
survivingIntervals.push(
|
|
8469
|
-
isLogicalInterval(interval) ? { ...interval, itemIds: kept } : { ...interval, itemIds: kept, isTail: true, hasMoreTail: false }
|
|
8470
|
-
);
|
|
8471
|
-
}
|
|
8472
|
-
}
|
|
8473
|
-
if (!removedIds.length) return;
|
|
8474
|
-
for (const id of removedIds) this._itemIndex.remove(id);
|
|
8475
|
-
this.setIntervals(survivingIntervals);
|
|
8476
|
-
const active = this._activeIntervalId ? this._itemIntervals.get(this._activeIntervalId) : void 0;
|
|
8477
|
-
if (active && !isLogicalInterval(active)) {
|
|
8478
|
-
this.setActiveInterval(active);
|
|
8479
|
-
return;
|
|
8480
|
-
}
|
|
8481
|
-
const anchoredSurvivors = this.itemIntervals.filter(
|
|
8482
|
-
(itv) => !isLogicalInterval(itv)
|
|
8483
|
-
);
|
|
8484
|
-
const fallback = this.getTailIntervalFromSortedIntervals(anchoredSurvivors);
|
|
8485
|
-
if (fallback) {
|
|
8486
|
-
this.setActiveInterval(fallback);
|
|
8487
|
-
} else {
|
|
8488
|
-
this.state.partialNext({ items: [] });
|
|
8489
|
-
}
|
|
8490
|
-
};
|
|
8491
8438
|
this.applyMessageDeletionForUser = ({
|
|
8492
8439
|
userId,
|
|
8493
8440
|
hardDelete = false,
|
|
@@ -8545,32 +8492,6 @@ var MessageIntervalPaginator = class extends BasePaginator {
|
|
|
8545
8492
|
}
|
|
8546
8493
|
});
|
|
8547
8494
|
};
|
|
8548
|
-
/**
|
|
8549
|
-
* Reflect an updated `user` object onto every cached message authored by that user, mirroring
|
|
8550
|
-
* the legacy `ChannelState.updateUserMessages` for the main message list (does not touch
|
|
8551
|
-
* `quoted_message.user` — that is not part of the legacy behavior).
|
|
8552
|
-
*
|
|
8553
|
-
* Batched: a user rename can affect many messages, so this patches the shared item index and
|
|
8554
|
-
* re-emits the active window a single time (if it held an affected message) rather than one
|
|
8555
|
-
* `ingestItem` re-emit per message.
|
|
8556
|
-
*/
|
|
8557
|
-
this.reflectUserUpdate = (user) => {
|
|
8558
|
-
const activeIds = new Set((this.items ?? []).map((m) => this.getItemId(m)));
|
|
8559
|
-
let activeAffected = false;
|
|
8560
|
-
this.batch(() => {
|
|
8561
|
-
for (const message of this._itemIndex.values()) {
|
|
8562
|
-
if (message.user?.id !== user.id) continue;
|
|
8563
|
-
if (message.user === user) continue;
|
|
8564
|
-
this._itemIndex.setOne({ ...message, user });
|
|
8565
|
-
if (activeIds.has(this.getItemId(message))) activeAffected = true;
|
|
8566
|
-
}
|
|
8567
|
-
});
|
|
8568
|
-
if (activeAffected) {
|
|
8569
|
-
this.state.partialNext({
|
|
8570
|
-
items: (this.items ?? []).map((m) => this.getItem(this.getItemId(m)) ?? m)
|
|
8571
|
-
});
|
|
8572
|
-
}
|
|
8573
|
-
};
|
|
8574
8495
|
/**
|
|
8575
8496
|
* Map a timestamp to a loaded message — the first message in the latest (head) window whose
|
|
8576
8497
|
* `created_at` is >= `timestamp` (mirrors the legacy `ChannelState.findMessageByTimestamp`
|
|
@@ -8780,6 +8701,10 @@ var MessageIntervalPaginator = class extends BasePaginator {
|
|
|
8780
8701
|
isJumpQueryShape(queryShape) {
|
|
8781
8702
|
return !!queryShape?.id_around || !!queryShape?.created_at_around;
|
|
8782
8703
|
}
|
|
8704
|
+
/** A jump sends its own `limit`, so its head/tail flags are derived against that, not `pageSize`. */
|
|
8705
|
+
getRequestedPageSize(queryShape) {
|
|
8706
|
+
return queryShape && this.isJumpQueryShape(queryShape) ? queryShape.limit ?? this.pageSize : this.pageSize;
|
|
8707
|
+
}
|
|
8783
8708
|
/**
|
|
8784
8709
|
* Whether `page` proves it reached the channel's own oldest message: the caller's request was
|
|
8785
8710
|
* bounded by this paginator's OWN `pageSize` AND `page` came back shorter than that request.
|
|
@@ -8959,6 +8884,91 @@ var MessageIntervalPaginator = class extends BasePaginator {
|
|
|
8959
8884
|
this._itemIndex.clear();
|
|
8960
8885
|
this.clearMessageFocusSignal();
|
|
8961
8886
|
}
|
|
8887
|
+
/**
|
|
8888
|
+
* Partial truncation for `channel.truncated` carrying a `truncated_at`: drop every loaded
|
|
8889
|
+
* message strictly older than the cutoff (keeping newer ones) across all loaded windows,
|
|
8890
|
+
* mirroring the legacy per-message-set pruning. For a full truncation (no `truncated_at`) use
|
|
8891
|
+
* {@link MessageIntervalPaginator.clearStateAndCache} instead.
|
|
8892
|
+
*
|
|
8893
|
+
* Batched and edge-classified: because messages are chronological, each interval is classified by
|
|
8894
|
+
* its `tail` (oldest) and `head` (newest) edges, so only the single interval that *straddles* the
|
|
8895
|
+
* cutoff is scanned member-by-member — the rest are kept or dropped wholesale. The straddling
|
|
8896
|
+
* interval becomes the new global tail (nothing older than the cutoff exists anymore), so its
|
|
8897
|
+
* `isTail`/`hasMoreTail` are set; intervals entirely newer keep their flags (unloaded older
|
|
8898
|
+
* messages may still sit between them and the cutoff). The active window is re-emitted once.
|
|
8899
|
+
*/
|
|
8900
|
+
truncate({ truncatedAt }) {
|
|
8901
|
+
const cutoff = truncatedAt;
|
|
8902
|
+
if (!Number.isFinite(cutoff)) return;
|
|
8903
|
+
const isOld = (item) => {
|
|
8904
|
+
const time = getMessageCreatedAtTimestamp(item);
|
|
8905
|
+
return time !== null && time < cutoff;
|
|
8906
|
+
};
|
|
8907
|
+
const removedIds = [];
|
|
8908
|
+
const survivingIntervals = [];
|
|
8909
|
+
for (const interval of this.itemIntervals) {
|
|
8910
|
+
const edges = this.getIntervalPaginationEdges(interval);
|
|
8911
|
+
if (!edges || !isOld(edges.tail)) {
|
|
8912
|
+
survivingIntervals.push(interval);
|
|
8913
|
+
} else if (isOld(edges.head)) {
|
|
8914
|
+
removedIds.push(...interval.itemIds);
|
|
8915
|
+
} else {
|
|
8916
|
+
const ids = interval.itemIds;
|
|
8917
|
+
const splitIndex = lowerBound(
|
|
8918
|
+
ids.length,
|
|
8919
|
+
(index) => !isOld(this._itemIndex.get(ids[index]))
|
|
8920
|
+
);
|
|
8921
|
+
removedIds.push(...ids.slice(0, splitIndex));
|
|
8922
|
+
const kept = ids.slice(splitIndex);
|
|
8923
|
+
survivingIntervals.push(
|
|
8924
|
+
isLogicalInterval(interval) ? { ...interval, itemIds: kept } : { ...interval, itemIds: kept, isTail: true, hasMoreTail: false }
|
|
8925
|
+
);
|
|
8926
|
+
}
|
|
8927
|
+
}
|
|
8928
|
+
if (!removedIds.length) return;
|
|
8929
|
+
for (const id of removedIds) this._itemIndex.remove(id);
|
|
8930
|
+
this.setIntervals(survivingIntervals);
|
|
8931
|
+
const active = this._activeIntervalId ? this._itemIntervals.get(this._activeIntervalId) : void 0;
|
|
8932
|
+
if (active && !isLogicalInterval(active)) {
|
|
8933
|
+
this.setActiveInterval(active);
|
|
8934
|
+
return;
|
|
8935
|
+
}
|
|
8936
|
+
const anchoredSurvivors = this.itemIntervals.filter(
|
|
8937
|
+
(itv) => !isLogicalInterval(itv)
|
|
8938
|
+
);
|
|
8939
|
+
const fallback = this.getTailIntervalFromSortedIntervals(anchoredSurvivors);
|
|
8940
|
+
if (fallback) {
|
|
8941
|
+
this.setActiveInterval(fallback);
|
|
8942
|
+
} else {
|
|
8943
|
+
this.state.partialNext({ items: [] });
|
|
8944
|
+
}
|
|
8945
|
+
}
|
|
8946
|
+
/**
|
|
8947
|
+
* Reflect an updated `user` object onto every cached message authored by that user, mirroring
|
|
8948
|
+
* the legacy `ChannelState.updateUserMessages` for the main message list (does not touch
|
|
8949
|
+
* `quoted_message.user` — that is not part of the legacy behavior).
|
|
8950
|
+
*
|
|
8951
|
+
* Batched: a user rename can affect many messages, so this patches the shared item index and
|
|
8952
|
+
* re-emits the active window a single time (if it held an affected message) rather than one
|
|
8953
|
+
* `ingestItem` re-emit per message.
|
|
8954
|
+
*/
|
|
8955
|
+
reflectUserUpdate(user) {
|
|
8956
|
+
const activeIds = new Set((this.items ?? []).map((m) => this.getItemId(m)));
|
|
8957
|
+
let activeAffected = false;
|
|
8958
|
+
this.batch(() => {
|
|
8959
|
+
for (const message of this._itemIndex.values()) {
|
|
8960
|
+
if (message.user?.id !== user.id) continue;
|
|
8961
|
+
if (message.user === user) continue;
|
|
8962
|
+
this._itemIndex.setOne({ ...message, user });
|
|
8963
|
+
if (activeIds.has(this.getItemId(message))) activeAffected = true;
|
|
8964
|
+
}
|
|
8965
|
+
});
|
|
8966
|
+
if (activeAffected) {
|
|
8967
|
+
this.state.partialNext({
|
|
8968
|
+
items: (this.items ?? []).map((m) => this.getItem(this.getItemId(m)) ?? m)
|
|
8969
|
+
});
|
|
8970
|
+
}
|
|
8971
|
+
}
|
|
8962
8972
|
getCanonicalQueryItems(items) {
|
|
8963
8973
|
return [...items].sort(this.itemOrderComparator);
|
|
8964
8974
|
}
|
|
@@ -9002,7 +9012,6 @@ var makeDeriveCursor = (paginator) => (ctx) => {
|
|
|
9002
9012
|
return injectCursor(
|
|
9003
9013
|
deriveCreatedAtAroundPaginationFlags({
|
|
9004
9014
|
...ctx,
|
|
9005
|
-
paginator,
|
|
9006
9015
|
page: pageWithPermittedMessages,
|
|
9007
9016
|
requestedPageSize: requestedPageSizeAfterAdjustment
|
|
9008
9017
|
})
|
|
@@ -9122,7 +9131,7 @@ var MessagePaginator = class extends MessageIntervalPaginator {
|
|
|
9122
9131
|
queryShape: {
|
|
9123
9132
|
// `created_at_around` is a request field and still takes a `Date`.
|
|
9124
9133
|
created_at_around: nsToDate(lastReadBoundary),
|
|
9125
|
-
limit: options?.pageSize
|
|
9134
|
+
limit: options?.pageSize ?? this.pageSize
|
|
9126
9135
|
},
|
|
9127
9136
|
updateState: false
|
|
9128
9137
|
});
|
|
@@ -9274,15 +9283,48 @@ var MessagePaginator = class extends MessageIntervalPaginator {
|
|
|
9274
9283
|
}
|
|
9275
9284
|
return interval;
|
|
9276
9285
|
}
|
|
9286
|
+
onEntitiesChanged(batch) {
|
|
9287
|
+
super.onEntitiesChanged(batch);
|
|
9288
|
+
const { lastMessage } = this.aggregateState.getLatestValue();
|
|
9289
|
+
if (!lastMessage || !batch.changedIds.has(lastMessage.id)) return;
|
|
9290
|
+
const stored = this.getItem(lastMessage.id);
|
|
9291
|
+
if (stored) this.aggregateState.partialNext({ lastMessage: stored });
|
|
9292
|
+
}
|
|
9293
|
+
reflectUserUpdate(user) {
|
|
9294
|
+
super.reflectUserUpdate(user);
|
|
9295
|
+
const { lastMessage } = this.aggregateState.getLatestValue();
|
|
9296
|
+
if (lastMessage?.user?.id !== user.id) return;
|
|
9297
|
+
this.aggregateState.partialNext({ lastMessage: { ...lastMessage, user } });
|
|
9298
|
+
}
|
|
9277
9299
|
removeItem(params) {
|
|
9278
9300
|
const removedId = params.id ?? (params.item ? this.getItemId(params.item) : void 0);
|
|
9279
|
-
const
|
|
9301
|
+
const { lastMessage, seededLastMessageAt } = this.aggregateState.getLatestValue();
|
|
9302
|
+
const wasLatest = !!removedId && lastMessage?.id === removedId;
|
|
9280
9303
|
const result = super.removeItem(params);
|
|
9281
9304
|
if (wasLatest) {
|
|
9282
|
-
|
|
9305
|
+
const previous = this.recomputeLastMessage();
|
|
9306
|
+
const previousAt = getMessageCreatedAtTimestamp(previous);
|
|
9307
|
+
const removedAt = getMessageCreatedAtTimestamp(lastMessage);
|
|
9308
|
+
const isSeedFromRemovedMessage = seededLastMessageAt !== null && removedAt !== null && seededLastMessageAt <= removedAt;
|
|
9309
|
+
this.aggregateState.partialNext({
|
|
9310
|
+
lastMessage: previous,
|
|
9311
|
+
seededLastMessageAt: isSeedFromRemovedMessage && previousAt !== null ? previousAt : seededLastMessageAt
|
|
9312
|
+
});
|
|
9283
9313
|
}
|
|
9284
9314
|
return result;
|
|
9285
9315
|
}
|
|
9316
|
+
truncate(params) {
|
|
9317
|
+
super.truncate(params);
|
|
9318
|
+
const { lastMessage, seededLastMessageAt } = this.aggregateState.getLatestValue();
|
|
9319
|
+
const isTruncated = (timestamp) => timestamp !== null && timestamp < params.truncatedAt;
|
|
9320
|
+
const isLastMessageTruncated = isTruncated(getMessageCreatedAtTimestamp(lastMessage));
|
|
9321
|
+
const isSeedTruncated = isTruncated(seededLastMessageAt);
|
|
9322
|
+
if (!isLastMessageTruncated && !isSeedTruncated) return;
|
|
9323
|
+
this.aggregateState.partialNext({
|
|
9324
|
+
lastMessage: isLastMessageTruncated ? this.recomputeLastMessage() : lastMessage,
|
|
9325
|
+
seededLastMessageAt: isSeedTruncated ? null : seededLastMessageAt
|
|
9326
|
+
});
|
|
9327
|
+
}
|
|
9286
9328
|
/**
|
|
9287
9329
|
* The still-loaded message with the greatest `created_at` that passes
|
|
9288
9330
|
* {@link shouldAdvanceLastMessage} (skips system / thread-only per config), from the newest-loaded
|
|
@@ -16590,6 +16632,9 @@ var Channel = class extends ChannelApi {
|
|
|
16590
16632
|
const channel = this;
|
|
16591
16633
|
logger8.withExtraTags("_handleChannelEvent", this.cid).debug(`Received an event of type "${event.type}".`, { event });
|
|
16592
16634
|
const channelState = channel.state;
|
|
16635
|
+
if ((event.type === "message.new" || event.type === "notification.message_new") && channel.data?.hidden) {
|
|
16636
|
+
channel.data = { ...channel.data, hidden: false };
|
|
16637
|
+
}
|
|
16593
16638
|
switch (event.type) {
|
|
16594
16639
|
case "typing.start":
|
|
16595
16640
|
if (event.user?.id) {
|
|
@@ -16806,6 +16851,7 @@ var Channel = class extends ChannelApi {
|
|
|
16806
16851
|
}
|
|
16807
16852
|
break;
|
|
16808
16853
|
case "channel.truncated": {
|
|
16854
|
+
if (event.channel) channel.data = { ...channel.data, ...event.channel };
|
|
16809
16855
|
const truncatedAt = event.channel?.truncated_at;
|
|
16810
16856
|
if (truncatedAt != null) {
|
|
16811
16857
|
this._setOwnUnreadCount(this.countUnread(truncatedAt));
|
|
@@ -20341,8 +20387,9 @@ var EventHandlerPipeline = class {
|
|
|
20341
20387
|
ctx
|
|
20342
20388
|
});
|
|
20343
20389
|
if (result?.action === "stop") return;
|
|
20344
|
-
} catch {
|
|
20390
|
+
} catch (error) {
|
|
20345
20391
|
console.error(`[pipeline:${this.id}] handler failed`, {
|
|
20392
|
+
error,
|
|
20346
20393
|
handlerId: handler.id ?? "unknown",
|
|
20347
20394
|
handlerIndex: i
|
|
20348
20395
|
});
|
|
@@ -20450,6 +20497,10 @@ var channelTruncatedHandler = {
|
|
|
20450
20497
|
handle: reinsertItem,
|
|
20451
20498
|
id: "ChannelManager:default-handler:channel.truncated"
|
|
20452
20499
|
};
|
|
20500
|
+
var messageDeletedHandler = {
|
|
20501
|
+
handle: (context) => context.event.hard_delete ? reinsertItem(context) : void 0,
|
|
20502
|
+
id: "ChannelManager:default-handler:message.deleted"
|
|
20503
|
+
};
|
|
20453
20504
|
var channelVisibleHandler = {
|
|
20454
20505
|
handle: updateLists,
|
|
20455
20506
|
id: "ChannelManager:default-handler:channel.visible"
|
|
@@ -21188,6 +21239,7 @@ _ChannelManager.defaultEventHandlers = {
|
|
|
21188
21239
|
"channel.hidden": [channelHiddenHandler],
|
|
21189
21240
|
"channel.visible": [channelVisibleHandler],
|
|
21190
21241
|
"member.updated": [memberUpdatedHandler],
|
|
21242
|
+
"message.deleted": [messageDeletedHandler],
|
|
21191
21243
|
"message.new": [messageNewHandler],
|
|
21192
21244
|
"message.read": [readStateChangedHandler],
|
|
21193
21245
|
"message.read_locally": [readStateChangedHandler],
|
|
@@ -23141,6 +23193,11 @@ var CONSTRUCTION_ONLY_CONFIG_PATHS = {
|
|
|
23141
23193
|
// `messagePaginator` was silent while the identical field under `channel`/`thread` warned — the same
|
|
23142
23194
|
// read-once field, warned through one route and not the other.
|
|
23143
23195
|
messagePaginator: ["initialCursor", "initialOffset", "unreadReferencePolicy"],
|
|
23196
|
+
// Each is consumed while the client is being constructed — the axios instance, the base URL and the
|
|
23197
|
+
// notification manager are built from it — so a value registered once the client exists never
|
|
23198
|
+
// reaches them. `browser` and `persistUserOnConnectionFailure` are read when needed, so they are not
|
|
23199
|
+
// listed.
|
|
23200
|
+
client: ["axiosRequestConfig", "baseURL", "notificationManager"],
|
|
23144
23201
|
channel: [
|
|
23145
23202
|
"messagePaginator.initialCursor",
|
|
23146
23203
|
"messagePaginator.initialOffset",
|
|
@@ -24630,16 +24687,16 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
24630
24687
|
*
|
|
24631
24688
|
* @example <caption>initialize the client in user mode</caption>
|
|
24632
24689
|
* new StreamChat('api_key')
|
|
24633
|
-
* @example <caption>initialize the client with
|
|
24634
|
-
* new StreamChat('api_key', { axiosRequestConfig: { timeout: 5000 } })
|
|
24690
|
+
* @example <caption>initialize the client with configuration</caption>
|
|
24691
|
+
* new StreamChat('api_key', { client: { axiosRequestConfig: { timeout: 5000 } } })
|
|
24635
24692
|
*
|
|
24636
24693
|
* @param key - The API key.
|
|
24637
|
-
* @param
|
|
24638
|
-
*
|
|
24639
|
-
*
|
|
24640
|
-
* `
|
|
24694
|
+
* @param config - Declarative configuration, the same tree `client.config.set()` takes (optional).
|
|
24695
|
+
* Seeded before anything is built, so it reaches the client's own managers and the fields that are
|
|
24696
|
+
* read once during construction — `client.baseURL`, `client.axiosRequestConfig` and
|
|
24697
|
+
* `client.notificationManager`.
|
|
24641
24698
|
*/
|
|
24642
|
-
constructor(key,
|
|
24699
|
+
constructor(key, config) {
|
|
24643
24700
|
super(new ApiClient());
|
|
24644
24701
|
/**
|
|
24645
24702
|
* If true, we will not clean up threads when channel state is in initializing state.
|
|
@@ -24686,9 +24743,9 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
24686
24743
|
"Use client.disconnect() before trying to connect as a different user. connectUser was called twice."
|
|
24687
24744
|
);
|
|
24688
24745
|
}
|
|
24689
|
-
if (this.node && !this.
|
|
24746
|
+
if (this.node && !this.config.getConfig("client")?.allowServerSideConnect) {
|
|
24690
24747
|
logger19.withExtraTags("connectUser").warn(
|
|
24691
|
-
|
|
24748
|
+
"Do not use connectUser server-side. connectUser impacts MAU and concurrent connection usage, and therefore your bill. If you have a valid use case, set `client.allowServerSideConnect: true` in the client configuration to disable this warning."
|
|
24692
24749
|
);
|
|
24693
24750
|
}
|
|
24694
24751
|
const setTokenPromise = this._setToken(user, userTokenOrProvider);
|
|
@@ -24703,7 +24760,7 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
24703
24760
|
return await setUserPromise;
|
|
24704
24761
|
} catch (err) {
|
|
24705
24762
|
if (this.setUserPromise === setUserPromise && this.userId === user.id) {
|
|
24706
|
-
if (!this.persistUserOnConnectionFailure) {
|
|
24763
|
+
if (!this.config.getConfig("client")?.persistUserOnConnectionFailure) {
|
|
24707
24764
|
this.disconnectUser();
|
|
24708
24765
|
} else if (!isWSFailure(err)) {
|
|
24709
24766
|
this.closeConnection();
|
|
@@ -24878,9 +24935,9 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
24878
24935
|
* @returns A promise that resolves when the connection is set up.
|
|
24879
24936
|
*/
|
|
24880
24937
|
this.connectAnonymousUser = () => {
|
|
24881
|
-
if (this.node && !this.
|
|
24938
|
+
if (this.node && !this.config.getConfig("client")?.allowServerSideConnect) {
|
|
24882
24939
|
logger19.withExtraTags("connectAnonymousUser").warn(
|
|
24883
|
-
|
|
24940
|
+
"Do not use connectUser server-side. connectUser impacts MAU and concurrent connection usage, and therefore your bill. If you have a valid use case, set `client.allowServerSideConnect: true` in the client configuration to disable this warning."
|
|
24884
24941
|
);
|
|
24885
24942
|
}
|
|
24886
24943
|
const anonymousUser = {
|
|
@@ -25086,7 +25143,7 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
25086
25143
|
return this.userAgent;
|
|
25087
25144
|
}
|
|
25088
25145
|
if (!this.cachedUserAgent) {
|
|
25089
|
-
const version = "10.0.0-rc.
|
|
25146
|
+
const version = "10.0.0-rc.22";
|
|
25090
25147
|
const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
|
|
25091
25148
|
const { name: appName, version: appVersion } = this.appIdentifier ?? {};
|
|
25092
25149
|
const { os, model: deviceModel } = this.deviceIdentifier ?? {};
|
|
@@ -25137,6 +25194,8 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
25137
25194
|
});
|
|
25138
25195
|
this.apiClient.client = this;
|
|
25139
25196
|
this.key = key;
|
|
25197
|
+
if (config) this.config.set(config);
|
|
25198
|
+
const clientConfig = this.config.getConfig("client");
|
|
25140
25199
|
this.listeners = /* @__PURE__ */ new Map();
|
|
25141
25200
|
this.state = new ClientState({ client: this });
|
|
25142
25201
|
this.mutedChannels = [];
|
|
@@ -25148,18 +25207,15 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
25148
25207
|
});
|
|
25149
25208
|
this.blockedUsers = new import_state_store29.StateStore({ userIds: [] });
|
|
25150
25209
|
this.moderation = new Moderation(this);
|
|
25151
|
-
this.notifications =
|
|
25210
|
+
this.notifications = clientConfig?.notificationManager ?? new NotificationManager();
|
|
25152
25211
|
this.uploadManager = new UploadManager(this);
|
|
25153
|
-
this.browser = options.browser ?? typeof window !== "undefined";
|
|
25154
|
-
this.node = !this.browser;
|
|
25155
|
-
this.options = { ...options };
|
|
25156
25212
|
this.axiosInstance = import_axios5.default.create({
|
|
25157
25213
|
timeout: 3e3,
|
|
25158
25214
|
withCredentials: false,
|
|
25159
|
-
...
|
|
25215
|
+
...clientConfig?.axiosRequestConfig,
|
|
25160
25216
|
paramsSerializer: axiosParamsSerializer
|
|
25161
25217
|
});
|
|
25162
|
-
this.setBaseURL(
|
|
25218
|
+
this.setBaseURL(clientConfig?.baseURL || "https://chat.stream-io-api.com");
|
|
25163
25219
|
const streamLocalTestRun = getEnv("STREAM_LOCAL_TEST_RUN");
|
|
25164
25220
|
const streamLocalTestHost = getEnv("STREAM_LOCAL_TEST_HOST");
|
|
25165
25221
|
if (streamLocalTestRun) {
|
|
@@ -25175,7 +25231,6 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
25175
25231
|
this.wsConnection.registerSubscriptions();
|
|
25176
25232
|
this.wsPromise = null;
|
|
25177
25233
|
this.setUserPromise = null;
|
|
25178
|
-
this.persistUserOnConnectionFailure = this.options?.persistUserOnConnectionFailure;
|
|
25179
25234
|
this.tokenManager = new TokenManager();
|
|
25180
25235
|
this.messageStore = new EntityStore({
|
|
25181
25236
|
getEntityId: (message) => message.id
|
|
@@ -25192,9 +25247,18 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
25192
25247
|
heldBy: () => this.messageComposerCache.values().map((composer) => composer.channel),
|
|
25193
25248
|
name: "message-composer-cache"
|
|
25194
25249
|
});
|
|
25195
|
-
if (this.options.config) this.config.set(this.options.config);
|
|
25196
25250
|
this.wireClientConfiguration();
|
|
25197
25251
|
}
|
|
25252
|
+
/**
|
|
25253
|
+
* Whether the client runs in a browser. `client.browser` in the configuration when set, otherwise
|
|
25254
|
+
* whether a global `window` exists.
|
|
25255
|
+
*/
|
|
25256
|
+
get browser() {
|
|
25257
|
+
return this.config.getConfig("client")?.browser ?? typeof window !== "undefined";
|
|
25258
|
+
}
|
|
25259
|
+
get node() {
|
|
25260
|
+
return !this.browser;
|
|
25261
|
+
}
|
|
25198
25262
|
get anonymous() {
|
|
25199
25263
|
return this.tokenManager.isAnonymous;
|
|
25200
25264
|
}
|
|
@@ -25299,23 +25363,21 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
25299
25363
|
*
|
|
25300
25364
|
* This function always returns the same client instance to avoid issues raised by multiple client and WS connections.
|
|
25301
25365
|
*
|
|
25302
|
-
* **After the first call, the client configuration will not change if the key or
|
|
25366
|
+
* **After the first call, the client configuration will not change if the key or config parameters change.**
|
|
25303
25367
|
*
|
|
25304
25368
|
* @example <caption>initialize the client in user mode</caption>
|
|
25305
25369
|
* StreamChat.getInstance('api_key')
|
|
25306
|
-
* @example <caption>initialize the client with
|
|
25307
|
-
* StreamChat.getInstance('api_key', { axiosRequestConfig: { timeout: 5000 } })
|
|
25370
|
+
* @example <caption>initialize the client with configuration</caption>
|
|
25371
|
+
* StreamChat.getInstance('api_key', { client: { axiosRequestConfig: { timeout: 5000 } } })
|
|
25308
25372
|
*
|
|
25309
25373
|
* @param key - The API key.
|
|
25310
|
-
* @param
|
|
25311
|
-
*
|
|
25312
|
-
* @param options.axiosRequestConfig - Axios-level request configuration such as `timeout`,
|
|
25313
|
-
* `headers` or `httpsAgent`, spread into the client's axios instance (optional).
|
|
25374
|
+
* @param config - Declarative configuration, as for the constructor (optional). Ignored once the
|
|
25375
|
+
* instance exists.
|
|
25314
25376
|
* @returns The shared client instance.
|
|
25315
25377
|
*/
|
|
25316
|
-
static getInstance(key,
|
|
25378
|
+
static getInstance(key, config) {
|
|
25317
25379
|
if (!_StreamChat._instance) {
|
|
25318
|
-
_StreamChat._instance = new _StreamChat(key,
|
|
25380
|
+
_StreamChat._instance = new _StreamChat(key, config);
|
|
25319
25381
|
}
|
|
25320
25382
|
return _StreamChat._instance;
|
|
25321
25383
|
}
|
|
@@ -26501,6 +26563,26 @@ var WS_CONNECTION_FIELDS = {
|
|
|
26501
26563
|
}
|
|
26502
26564
|
};
|
|
26503
26565
|
var CLIENT_FIELDS = {
|
|
26566
|
+
allowServerSideConnect: {
|
|
26567
|
+
description: "Silences the warning logged when `connectUser` is called server-side, where a connection counts towards MAU and concurrent-connection billing. Was `StreamChatOptions.allowServerSideConnect`.",
|
|
26568
|
+
kind: "value",
|
|
26569
|
+
type: "boolean"
|
|
26570
|
+
},
|
|
26571
|
+
axiosRequestConfig: {
|
|
26572
|
+
description: "Axios-level request configuration \u2014 `timeout`, `headers`, `httpsAgent` and so on. Built into the client's axios instance at construction; `headers` and `params` are also read on every request. Was `StreamChatOptions.axiosRequestConfig`.",
|
|
26573
|
+
kind: "value",
|
|
26574
|
+
type: "object"
|
|
26575
|
+
},
|
|
26576
|
+
baseURL: {
|
|
26577
|
+
description: "Base URL of the API, such as `https://chat-proxy-dublin.stream-io-api.com`. Read at construction. Was `StreamChatOptions.baseURL`.",
|
|
26578
|
+
kind: "value",
|
|
26579
|
+
type: "string"
|
|
26580
|
+
},
|
|
26581
|
+
browser: {
|
|
26582
|
+
description: "Enforces browser (`true`) or Node (`false`) mode; detected from the global `window` when absent. Read live, through `client.browser` and `client.node`. Was `StreamChatOptions.browser`.",
|
|
26583
|
+
kind: "value",
|
|
26584
|
+
type: "boolean"
|
|
26585
|
+
},
|
|
26504
26586
|
connectionRecovery: {
|
|
26505
26587
|
description: "Bringing the channels, lists and threads you are reading back in line after a reconnect.",
|
|
26506
26588
|
fields: CONNECTION_RECOVERY_FIELDS,
|
|
@@ -26516,11 +26598,21 @@ var CLIENT_FIELDS = {
|
|
|
26516
26598
|
fields: NETWORK_CONNECTION_FIELDS,
|
|
26517
26599
|
kind: "group"
|
|
26518
26600
|
},
|
|
26601
|
+
notificationManager: {
|
|
26602
|
+
description: "A pre-built `NotificationManager` to use instead of the client constructing its own, to share one between clients or hand over one that already holds notifications. Read at construction. Was `StreamChatOptions.notifications`.",
|
|
26603
|
+
kind: "value",
|
|
26604
|
+
type: "object"
|
|
26605
|
+
},
|
|
26519
26606
|
notifications: {
|
|
26520
26607
|
description: "The client-wide notification (toast) manager.",
|
|
26521
26608
|
fields: NOTIFICATION_FIELDS,
|
|
26522
26609
|
kind: "group"
|
|
26523
26610
|
},
|
|
26611
|
+
persistUserOnConnectionFailure: {
|
|
26612
|
+
description: "Keeps the user on the client when `connectUser` fails, so an application working offline keeps `client.user` and need not call `connectUser` again to retry. Read when a connect fails. Was `StreamChatOptions.persistUserOnConnectionFailure`.",
|
|
26613
|
+
kind: "value",
|
|
26614
|
+
type: "boolean"
|
|
26615
|
+
},
|
|
26524
26616
|
reminders: {
|
|
26525
26617
|
description: "Message reminders and their scheduling offsets.",
|
|
26526
26618
|
fields: REMINDER_FIELDS,
|