stream-chat 9.54.1 → 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 +42 -11
- package/dist/cjs/index.browser.js.map +2 -2
- package/dist/cjs/index.node.js +42 -11
- package/dist/cjs/index.node.js.map +2 -2
- package/dist/esm/index.mjs +42 -11
- 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/utils.d.ts +1 -0
- package/package.json +1 -1
- package/src/channel.ts +6 -0
- package/src/channel_state.ts +29 -0
- package/src/client.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/attachments.ts +19 -8
- package/src/poll_optimistic_votes.ts +6 -1
- 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,
|
|
@@ -10824,7 +10846,8 @@ var Channel = class {
|
|
|
10824
10846
|
}
|
|
10825
10847
|
const { messageSet, filteredMessageIds } = this._initializeState(
|
|
10826
10848
|
state,
|
|
10827
|
-
messageSetToAddToIfDoesNotExist
|
|
10849
|
+
messageSetToAddToIfDoesNotExist,
|
|
10850
|
+
!hasMessagePaginationCursor(options?.messages)
|
|
10828
10851
|
);
|
|
10829
10852
|
messageSet.pagination = {
|
|
10830
10853
|
...messageSet.pagination,
|
|
@@ -11442,7 +11465,7 @@ var Channel = class {
|
|
|
11442
11465
|
);
|
|
11443
11466
|
}
|
|
11444
11467
|
}
|
|
11445
|
-
_initializeState(state, messageSetToAddToIfDoesNotExist = "latest") {
|
|
11468
|
+
_initializeState(state, messageSetToAddToIfDoesNotExist = "latest", isNewestPage = true) {
|
|
11446
11469
|
const { state: clientState, user, userID } = this.getClient();
|
|
11447
11470
|
if (state.members) {
|
|
11448
11471
|
this._hydrateMembers({ members: state.members });
|
|
@@ -11457,6 +11480,9 @@ var Channel = class {
|
|
|
11457
11480
|
if (!this.state.messages) {
|
|
11458
11481
|
this.state.initMessages();
|
|
11459
11482
|
}
|
|
11483
|
+
if (messageSetToAddToIfDoesNotExist === "latest" && isNewestPage) {
|
|
11484
|
+
this.state._dropLatestMessagesDisjointFrom(messages);
|
|
11485
|
+
}
|
|
11460
11486
|
const { messageSet, filteredMessageIds } = this.state.addMessagesSorted(
|
|
11461
11487
|
messages,
|
|
11462
11488
|
false,
|
|
@@ -13386,9 +13412,14 @@ function applyOwnVoteDelta(state, { add = [], remove = [] }) {
|
|
|
13386
13412
|
}
|
|
13387
13413
|
voteCount = Math.max(voteCount - 1, 0);
|
|
13388
13414
|
if (latestVotesByOption?.[optionId]) {
|
|
13389
|
-
|
|
13415
|
+
const latestVotes = latestVotesByOption[optionId].filter(
|
|
13390
13416
|
(latestVote) => latestVote.id !== vote.id
|
|
13391
13417
|
);
|
|
13418
|
+
if (latestVotes.length) {
|
|
13419
|
+
latestVotesByOption[optionId] = latestVotes;
|
|
13420
|
+
} else {
|
|
13421
|
+
delete latestVotesByOption[optionId];
|
|
13422
|
+
}
|
|
13392
13423
|
}
|
|
13393
13424
|
}
|
|
13394
13425
|
for (const vote of add) {
|
|
@@ -15493,7 +15524,7 @@ var StreamChat = class _StreamChat {
|
|
|
15493
15524
|
return this.userAgent;
|
|
15494
15525
|
}
|
|
15495
15526
|
if (!this.cachedUserAgent) {
|
|
15496
|
-
const version = "9.54.
|
|
15527
|
+
const version = "9.54.2";
|
|
15497
15528
|
const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
|
|
15498
15529
|
const { name: appName, version: appVersion } = this.appIdentifier ?? {};
|
|
15499
15530
|
const { os, model: deviceModel } = this.deviceIdentifier ?? {};
|
|
@@ -16423,7 +16454,7 @@ var StreamChat = class _StreamChat {
|
|
|
16423
16454
|
...updatedMessagesSet.pagination,
|
|
16424
16455
|
...messageSetPagination({
|
|
16425
16456
|
parentSet: updatedMessagesSet,
|
|
16426
|
-
requestedPageSize: queryChannelsOptions?.message_limit
|
|
16457
|
+
requestedPageSize: queryChannelsOptions?.message_limit ?? DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE,
|
|
16427
16458
|
returnedPage: channelState.messages,
|
|
16428
16459
|
filteredReturnedPage: channelState.messages.filter(
|
|
16429
16460
|
(m) => !filteredMessageIds.includes(m.id)
|