stream-chat 9.54.0 → 9.54.2
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 +87 -19
- package/dist/cjs/index.browser.js.map +2 -2
- package/dist/cjs/index.node.js +87 -19
- package/dist/cjs/index.node.js.map +2 -2
- package/dist/esm/index.mjs +87 -19
- package/dist/esm/index.mjs.map +2 -2
- package/dist/types/channel.d.ts +1 -1
- package/dist/types/channel_state.d.ts +6 -0
- package/dist/types/client.d.ts +4 -68
- package/dist/types/connection.d.ts +12 -0
- package/dist/types/types.d.ts +26 -6
- package/dist/types/utils.d.ts +1 -0
- package/package.json +6 -1
- package/src/channel.ts +6 -0
- package/src/channel_state.ts +29 -0
- package/src/client.ts +4 -4
- package/src/connection.ts +47 -2
- package/src/messageComposer/middleware/messageComposer/attachments.ts +19 -8
- package/src/poll.ts +9 -1
- package/src/poll_optimistic_votes.ts +6 -1
- package/src/thread.ts +11 -4
- package/src/types.ts +27 -6
- package/src/utils.ts +20 -0
package/README.md
CHANGED
|
@@ -101,7 +101,7 @@ message.custom_property; // in the response object as well
|
|
|
101
101
|
```
|
|
102
102
|
|
|
103
103
|
> [!WARNING]
|
|
104
|
-
> 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/
|
|
104
|
+
> 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.
|
|
105
105
|
|
|
106
106
|
## 🔗 (Optional) Development Setup in Combination With Our SDKs
|
|
107
107
|
|
|
@@ -1271,7 +1271,11 @@ var messagePaginationLinear = ({
|
|
|
1271
1271
|
newPagination.hasNext = hasNext;
|
|
1272
1272
|
return newPagination;
|
|
1273
1273
|
};
|
|
1274
|
+
var hasMessagePaginationCursor = (options) => !!(options?.id_lt || options?.id_lte || options?.id_gt || options?.id_gte || options?.id_around || options?.created_at_before || options?.created_at_before_or_equal || options?.created_at_after || options?.created_at_after_or_equal || options?.created_at_around || options?.offset);
|
|
1274
1275
|
var messageSetPagination = (params) => {
|
|
1276
|
+
if (params.requestedPageSize === 0 && params.parentSet.messages.length > 0) {
|
|
1277
|
+
return params.parentSet.pagination;
|
|
1278
|
+
}
|
|
1275
1279
|
if (params.parentSet.messages.length + (params.returnedPage.length - params.filteredReturnedPage.length) < params.returnedPage.length) {
|
|
1276
1280
|
params.logger?.(
|
|
1277
1281
|
"error",
|
|
@@ -1447,6 +1451,7 @@ var aOverlapsB = (a, b) => {
|
|
|
1447
1451
|
return oldestMessageA < oldestMessageB && oldestMessageB < newestMessageA && newestMessageA < newestMessageB;
|
|
1448
1452
|
};
|
|
1449
1453
|
var messageSetsOverlapByTimestamp = (a, b) => aContainsOrEqualsB(a, b) || aContainsOrEqualsB(b, a) || aOverlapsB(a, b) || aOverlapsB(b, a);
|
|
1454
|
+
var isLocalOnlyMessage = (message) => message.status === "sending" || message.status === "failed" || message.type === "error" || message.type === "ephemeral";
|
|
1450
1455
|
var ChannelState = class {
|
|
1451
1456
|
constructor(channel) {
|
|
1452
1457
|
/**
|
|
@@ -2106,6 +2111,22 @@ var ChannelState = class {
|
|
|
2106
2111
|
currentMessages.isCurrent = false;
|
|
2107
2112
|
this.messageSets[index].isCurrent = true;
|
|
2108
2113
|
}
|
|
2114
|
+
/**
|
|
2115
|
+
* Empties the latest message set if the newest page is newer than it and shares no messages
|
|
2116
|
+
* with it. Merging them would hide the messages in between from pagination.
|
|
2117
|
+
* Skipped while the set holds local-only messages, so they are not lost.
|
|
2118
|
+
*/
|
|
2119
|
+
_dropLatestMessagesDisjointFrom(newestPage) {
|
|
2120
|
+
const latestSet = this.messageSets.find((s) => s.isLatest);
|
|
2121
|
+
const newestLoaded = latestSet?.messages.slice(-1)[0];
|
|
2122
|
+
const oldestReturned = newestPage.find((m) => !m.parent_id || m.show_in_channel);
|
|
2123
|
+
if (!latestSet || !newestLoaded || !oldestReturned?.created_at) return;
|
|
2124
|
+
if (new Date(oldestReturned.created_at).getTime() <= newestLoaded.created_at.getTime() || this.areMessageSetsOverlap(latestSet.messages, newestPage) || latestSet.messages.some(isLocalOnlyMessage)) {
|
|
2125
|
+
return;
|
|
2126
|
+
}
|
|
2127
|
+
latestSet.messages = [];
|
|
2128
|
+
latestSet.pagination = { ...DEFAULT_MESSAGE_SET_PAGINATION };
|
|
2129
|
+
}
|
|
2109
2130
|
areMessageSetsOverlap(messages1, messages2) {
|
|
2110
2131
|
return messages1.some((m1) => messages2.find((m2) => m1.id === m2.id));
|
|
2111
2132
|
}
|
|
@@ -4088,13 +4109,14 @@ var localAttachmentToAttachment = (localAttachment) => {
|
|
|
4088
4109
|
const { localMetadata, ...attachment } = localAttachment;
|
|
4089
4110
|
return attachment;
|
|
4090
4111
|
};
|
|
4112
|
+
var isSendable = (attachment) => isFinishedUpload(attachment) || !isLocalUploadAttachment(attachment);
|
|
4091
4113
|
var composeWithPendingUploads = ({
|
|
4092
4114
|
composer,
|
|
4093
4115
|
state
|
|
4094
4116
|
}) => {
|
|
4095
4117
|
const composerIsKeptAsDraft = !!composer.pollId;
|
|
4096
4118
|
const relevantAttachments = composer.attachmentManager.attachments.filter(
|
|
4097
|
-
(attachment) =>
|
|
4119
|
+
(attachment) => isSendable(attachment) || !composerIsKeptAsDraft && isPendingUpload(attachment)
|
|
4098
4120
|
);
|
|
4099
4121
|
const localAttachments = (state.localMessage.attachments ?? []).concat(
|
|
4100
4122
|
relevantAttachments.map(
|
|
@@ -4102,7 +4124,7 @@ var composeWithPendingUploads = ({
|
|
|
4102
4124
|
)
|
|
4103
4125
|
);
|
|
4104
4126
|
const messageAttachments = (state.message.attachments ?? []).concat(
|
|
4105
|
-
relevantAttachments.filter(
|
|
4127
|
+
relevantAttachments.filter(isSendable).map(localAttachmentToAttachment)
|
|
4106
4128
|
);
|
|
4107
4129
|
if (!localAttachments.length && !messageAttachments.length) return state;
|
|
4108
4130
|
return {
|
|
@@ -4157,7 +4179,7 @@ var createAttachmentsCompositionMiddleware = (composer) => ({
|
|
|
4157
4179
|
return discard();
|
|
4158
4180
|
}
|
|
4159
4181
|
const attachments = (state.message.attachments ?? []).concat(
|
|
4160
|
-
attachmentManager.
|
|
4182
|
+
attachmentManager.attachments.filter(isSendable).map(localAttachmentToAttachment)
|
|
4161
4183
|
);
|
|
4162
4184
|
if (!attachments.length) return forward();
|
|
4163
4185
|
return next({
|
|
@@ -4184,9 +4206,9 @@ var createDraftAttachmentsCompositionMiddleware = (composer) => ({
|
|
|
4184
4206
|
}) => {
|
|
4185
4207
|
const { attachmentManager } = composer;
|
|
4186
4208
|
if (!attachmentManager) return forward();
|
|
4187
|
-
const
|
|
4188
|
-
const attachments =
|
|
4189
|
-
|
|
4209
|
+
const sendableAttachments = attachmentManager.attachments.filter(isSendable);
|
|
4210
|
+
const attachments = sendableAttachments.length ? (state.draft.attachments ?? []).concat(
|
|
4211
|
+
sendableAttachments.map(localAttachmentToAttachment)
|
|
4190
4212
|
) : void 0;
|
|
4191
4213
|
return next({
|
|
4192
4214
|
...state,
|
|
@@ -8311,10 +8333,13 @@ var Thread = class extends WithSubscriptions {
|
|
|
8311
8333
|
}));
|
|
8312
8334
|
}
|
|
8313
8335
|
};
|
|
8314
|
-
const
|
|
8315
|
-
|
|
8316
|
-
|
|
8317
|
-
|
|
8336
|
+
const channelResponse = threadData.channel;
|
|
8337
|
+
const channelData = { name: channelResponse.name };
|
|
8338
|
+
const channel = client.channel(
|
|
8339
|
+
threadData.channel.type,
|
|
8340
|
+
threadData.channel.id,
|
|
8341
|
+
channelData
|
|
8342
|
+
);
|
|
8318
8343
|
channel._hydrateMembers({
|
|
8319
8344
|
members: threadData.channel.members ?? [],
|
|
8320
8345
|
overrideCurrentState: false
|
|
@@ -10821,7 +10846,8 @@ var Channel = class {
|
|
|
10821
10846
|
}
|
|
10822
10847
|
const { messageSet, filteredMessageIds } = this._initializeState(
|
|
10823
10848
|
state,
|
|
10824
|
-
messageSetToAddToIfDoesNotExist
|
|
10849
|
+
messageSetToAddToIfDoesNotExist,
|
|
10850
|
+
!hasMessagePaginationCursor(options?.messages)
|
|
10825
10851
|
);
|
|
10826
10852
|
messageSet.pagination = {
|
|
10827
10853
|
...messageSet.pagination,
|
|
@@ -11439,7 +11465,7 @@ var Channel = class {
|
|
|
11439
11465
|
);
|
|
11440
11466
|
}
|
|
11441
11467
|
}
|
|
11442
|
-
_initializeState(state, messageSetToAddToIfDoesNotExist = "latest") {
|
|
11468
|
+
_initializeState(state, messageSetToAddToIfDoesNotExist = "latest", isNewestPage = true) {
|
|
11443
11469
|
const { state: clientState, user, userID } = this.getClient();
|
|
11444
11470
|
if (state.members) {
|
|
11445
11471
|
this._hydrateMembers({ members: state.members });
|
|
@@ -11454,6 +11480,9 @@ var Channel = class {
|
|
|
11454
11480
|
if (!this.state.messages) {
|
|
11455
11481
|
this.state.initMessages();
|
|
11456
11482
|
}
|
|
11483
|
+
if (messageSetToAddToIfDoesNotExist === "latest" && isNewestPage) {
|
|
11484
|
+
this.state._dropLatestMessagesDisjointFrom(messages);
|
|
11485
|
+
}
|
|
11457
11486
|
const { messageSet, filteredMessageIds } = this.state.addMessagesSorted(
|
|
11458
11487
|
messages,
|
|
11459
11488
|
false,
|
|
@@ -11714,6 +11743,10 @@ var StableWSConnection = class {
|
|
|
11714
11743
|
if (data.type === "health.check") {
|
|
11715
11744
|
this.scheduleNextPing();
|
|
11716
11745
|
}
|
|
11746
|
+
if (data?.type === "connection.error" && data?.error?.code === chatCodes.TOKEN_EXPIRED) {
|
|
11747
|
+
this._log("onmessage() - server reported that the token expired", { wsID });
|
|
11748
|
+
this.tokenExpiredByServer = true;
|
|
11749
|
+
}
|
|
11717
11750
|
this.client.dispatchEvent(data);
|
|
11718
11751
|
this.scheduleConnectionCheck();
|
|
11719
11752
|
};
|
|
@@ -11737,7 +11770,7 @@ var StableWSConnection = class {
|
|
|
11737
11770
|
this.isConnecting = false;
|
|
11738
11771
|
this.rejectPromise?.(this._errorFromWSEvent(event));
|
|
11739
11772
|
this._log(`onclose() - WS connection closed. Calling reconnect ...`, { event });
|
|
11740
|
-
this.
|
|
11773
|
+
this._reconnectAfterFailure();
|
|
11741
11774
|
}
|
|
11742
11775
|
};
|
|
11743
11776
|
this.onerror = (wsID, event) => {
|
|
@@ -11748,7 +11781,7 @@ var StableWSConnection = class {
|
|
|
11748
11781
|
this.isConnecting = false;
|
|
11749
11782
|
this.rejectPromise?.(this._errorFromWSEvent(event));
|
|
11750
11783
|
this._log(`onerror() - WS connection resulted into error`, { event });
|
|
11751
|
-
this.
|
|
11784
|
+
this._reconnectAfterFailure();
|
|
11752
11785
|
};
|
|
11753
11786
|
/**
|
|
11754
11787
|
* _setHealth - Sets the connection to healthy or unhealthy.
|
|
@@ -11801,6 +11834,7 @@ var StableWSConnection = class {
|
|
|
11801
11834
|
*/
|
|
11802
11835
|
this._setupConnectionPromise = () => {
|
|
11803
11836
|
this.isResolved = false;
|
|
11837
|
+
this.tokenExpiredByServer = false;
|
|
11804
11838
|
this.connectionOpen = new Promise((resolve, reject) => {
|
|
11805
11839
|
this.resolvePromise = resolve;
|
|
11806
11840
|
this.rejectPromise = reject;
|
|
@@ -11848,6 +11882,7 @@ var StableWSConnection = class {
|
|
|
11848
11882
|
this.isHealthy = false;
|
|
11849
11883
|
this.wsID = 1;
|
|
11850
11884
|
this.lastEvent = null;
|
|
11885
|
+
this.tokenExpiredByServer = false;
|
|
11851
11886
|
this.pingInterval = 25 * 1e3;
|
|
11852
11887
|
this.connectionCheckTimeout = this.pingInterval + 10 * 1e3;
|
|
11853
11888
|
addConnectionEventListeners(this.onlineStatusChanged);
|
|
@@ -11946,6 +11981,7 @@ var StableWSConnection = class {
|
|
|
11946
11981
|
this.wsID += 1;
|
|
11947
11982
|
this.isConnecting = false;
|
|
11948
11983
|
this.isDisconnected = true;
|
|
11984
|
+
this.tokenExpiredByServer = false;
|
|
11949
11985
|
if (this.healthCheckTimeoutRef) {
|
|
11950
11986
|
clearInterval(this.healthCheckTimeoutRef);
|
|
11951
11987
|
}
|
|
@@ -12078,6 +12114,10 @@ var StableWSConnection = class {
|
|
|
12078
12114
|
this._destroyCurrentWSConnection();
|
|
12079
12115
|
if (options.refreshToken) {
|
|
12080
12116
|
await this.client.tokenManager.loadToken();
|
|
12117
|
+
if (this.isConnecting || this.isHealthy) {
|
|
12118
|
+
this._log("_reconnect() - Abort (4) since already connecting or healthy");
|
|
12119
|
+
return;
|
|
12120
|
+
}
|
|
12081
12121
|
}
|
|
12082
12122
|
try {
|
|
12083
12123
|
await this._connect();
|
|
@@ -12101,6 +12141,21 @@ var StableWSConnection = class {
|
|
|
12101
12141
|
}
|
|
12102
12142
|
this._log("_reconnect() - == END ==");
|
|
12103
12143
|
}
|
|
12144
|
+
/**
|
|
12145
|
+
* _reconnectAfterFailure - Reconnects after the socket closed or failed. If the server
|
|
12146
|
+
* reported that the token expired, the token is refreshed before reconnecting.
|
|
12147
|
+
* Static tokens cannot be refreshed and reconnect as before.
|
|
12148
|
+
*/
|
|
12149
|
+
_reconnectAfterFailure() {
|
|
12150
|
+
if (this.tokenExpiredByServer && !this.client.tokenManager.isStatic()) {
|
|
12151
|
+
this._log(
|
|
12152
|
+
"_reconnectAfterFailure() - token expired, so going to reload token and reconnect"
|
|
12153
|
+
);
|
|
12154
|
+
this._reconnect({ refreshToken: true });
|
|
12155
|
+
return;
|
|
12156
|
+
}
|
|
12157
|
+
this._reconnect();
|
|
12158
|
+
}
|
|
12104
12159
|
/**
|
|
12105
12160
|
* _destroyCurrentWSConnection - Removes the current WS connection
|
|
12106
12161
|
*
|
|
@@ -13357,9 +13412,14 @@ function applyOwnVoteDelta(state, { add = [], remove = [] }) {
|
|
|
13357
13412
|
}
|
|
13358
13413
|
voteCount = Math.max(voteCount - 1, 0);
|
|
13359
13414
|
if (latestVotesByOption?.[optionId]) {
|
|
13360
|
-
|
|
13415
|
+
const latestVotes = latestVotesByOption[optionId].filter(
|
|
13361
13416
|
(latestVote) => latestVote.id !== vote.id
|
|
13362
13417
|
);
|
|
13418
|
+
if (latestVotes.length) {
|
|
13419
|
+
latestVotesByOption[optionId] = latestVotes;
|
|
13420
|
+
} else {
|
|
13421
|
+
delete latestVotesByOption[optionId];
|
|
13422
|
+
}
|
|
13363
13423
|
}
|
|
13364
13424
|
}
|
|
13365
13425
|
for (const vote of add) {
|
|
@@ -13463,7 +13523,15 @@ var Poll = class {
|
|
|
13463
13523
|
if (!isPollUpdatedEvent(event)) return;
|
|
13464
13524
|
const { id, ...pollData } = extractPollData(event.poll);
|
|
13465
13525
|
if (pollData.is_closed) this.closeConfirmed = true;
|
|
13466
|
-
this.state.partialNext({
|
|
13526
|
+
this.state.partialNext({
|
|
13527
|
+
...pollData,
|
|
13528
|
+
// Server-owned translations, which `extractPollData` (an update request) leaves out. Copied
|
|
13529
|
+
// even when absent: the event carries the whole poll, and a change made under channel-only
|
|
13530
|
+
// translation drops the stale ones.
|
|
13531
|
+
description_i18n: event.poll.description_i18n,
|
|
13532
|
+
lastActivityAt: new Date(event.created_at),
|
|
13533
|
+
name_i18n: event.poll.name_i18n
|
|
13534
|
+
});
|
|
13467
13535
|
this.upsertOfflineDb();
|
|
13468
13536
|
};
|
|
13469
13537
|
this.handlePollClosed = (event) => {
|
|
@@ -15456,7 +15524,7 @@ var StreamChat = class _StreamChat {
|
|
|
15456
15524
|
return this.userAgent;
|
|
15457
15525
|
}
|
|
15458
15526
|
if (!this.cachedUserAgent) {
|
|
15459
|
-
const version = "9.54.
|
|
15527
|
+
const version = "9.54.2";
|
|
15460
15528
|
const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
|
|
15461
15529
|
const { name: appName, version: appVersion } = this.appIdentifier ?? {};
|
|
15462
15530
|
const { os, model: deviceModel } = this.deviceIdentifier ?? {};
|
|
@@ -16386,7 +16454,7 @@ var StreamChat = class _StreamChat {
|
|
|
16386
16454
|
...updatedMessagesSet.pagination,
|
|
16387
16455
|
...messageSetPagination({
|
|
16388
16456
|
parentSet: updatedMessagesSet,
|
|
16389
|
-
requestedPageSize: queryChannelsOptions?.message_limit
|
|
16457
|
+
requestedPageSize: queryChannelsOptions?.message_limit ?? DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE,
|
|
16390
16458
|
returnedPage: channelState.messages,
|
|
16391
16459
|
filteredReturnedPage: channelState.messages.filter(
|
|
16392
16460
|
(m) => !filteredMessageIds.includes(m.id)
|
|
@@ -17045,7 +17113,7 @@ var StreamChat = class _StreamChat {
|
|
|
17045
17113
|
* @param {string} messageId
|
|
17046
17114
|
* @param {string} language
|
|
17047
17115
|
*
|
|
17048
|
-
* @return {MessageResponse} Response that includes the message
|
|
17116
|
+
* @return {APIResponse & { message: MessageResponse }} Response that includes the translated message
|
|
17049
17117
|
*/
|
|
17050
17118
|
async translateMessage(messageId, language) {
|
|
17051
17119
|
return await this.post(
|