stream-chat 9.54.1 → 9.54.3
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 +51 -16
- package/dist/cjs/index.browser.js.map +2 -2
- package/dist/cjs/index.node.js +51 -16
- package/dist/cjs/index.node.js.map +2 -2
- package/dist/esm/index.mjs +51 -16
- 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_manager.ts +8 -4
- 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/dist/cjs/index.node.js
CHANGED
|
@@ -1240,7 +1240,11 @@ var messagePaginationLinear = ({
|
|
|
1240
1240
|
newPagination.hasNext = hasNext;
|
|
1241
1241
|
return newPagination;
|
|
1242
1242
|
};
|
|
1243
|
+
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);
|
|
1243
1244
|
var messageSetPagination = (params) => {
|
|
1245
|
+
if (params.requestedPageSize === 0 && params.parentSet.messages.length > 0) {
|
|
1246
|
+
return params.parentSet.pagination;
|
|
1247
|
+
}
|
|
1244
1248
|
if (params.parentSet.messages.length + (params.returnedPage.length - params.filteredReturnedPage.length) < params.returnedPage.length) {
|
|
1245
1249
|
params.logger?.(
|
|
1246
1250
|
"error",
|
|
@@ -1416,6 +1420,7 @@ var aOverlapsB = (a, b) => {
|
|
|
1416
1420
|
return oldestMessageA < oldestMessageB && oldestMessageB < newestMessageA && newestMessageA < newestMessageB;
|
|
1417
1421
|
};
|
|
1418
1422
|
var messageSetsOverlapByTimestamp = (a, b) => aContainsOrEqualsB(a, b) || aContainsOrEqualsB(b, a) || aOverlapsB(a, b) || aOverlapsB(b, a);
|
|
1423
|
+
var isLocalOnlyMessage = (message) => message.status === "sending" || message.status === "failed" || message.type === "error" || message.type === "ephemeral";
|
|
1419
1424
|
var ChannelState = class {
|
|
1420
1425
|
constructor(channel) {
|
|
1421
1426
|
/**
|
|
@@ -2075,6 +2080,22 @@ var ChannelState = class {
|
|
|
2075
2080
|
currentMessages.isCurrent = false;
|
|
2076
2081
|
this.messageSets[index].isCurrent = true;
|
|
2077
2082
|
}
|
|
2083
|
+
/**
|
|
2084
|
+
* Empties the latest message set if the newest page is newer than it and shares no messages
|
|
2085
|
+
* with it. Merging them would hide the messages in between from pagination.
|
|
2086
|
+
* Skipped while the set holds local-only messages, so they are not lost.
|
|
2087
|
+
*/
|
|
2088
|
+
_dropLatestMessagesDisjointFrom(newestPage) {
|
|
2089
|
+
const latestSet = this.messageSets.find((s) => s.isLatest);
|
|
2090
|
+
const newestLoaded = latestSet?.messages.slice(-1)[0];
|
|
2091
|
+
const oldestReturned = newestPage.find((m) => !m.parent_id || m.show_in_channel);
|
|
2092
|
+
if (!latestSet || !newestLoaded || !oldestReturned?.created_at) return;
|
|
2093
|
+
if (new Date(oldestReturned.created_at).getTime() <= newestLoaded.created_at.getTime() || this.areMessageSetsOverlap(latestSet.messages, newestPage) || latestSet.messages.some(isLocalOnlyMessage)) {
|
|
2094
|
+
return;
|
|
2095
|
+
}
|
|
2096
|
+
latestSet.messages = [];
|
|
2097
|
+
latestSet.pagination = { ...DEFAULT_MESSAGE_SET_PAGINATION };
|
|
2098
|
+
}
|
|
2078
2099
|
areMessageSetsOverlap(messages1, messages2) {
|
|
2079
2100
|
return messages1.some((m1) => messages2.find((m2) => m1.id === m2.id));
|
|
2080
2101
|
}
|
|
@@ -4057,13 +4078,14 @@ var localAttachmentToAttachment = (localAttachment) => {
|
|
|
4057
4078
|
const { localMetadata, ...attachment } = localAttachment;
|
|
4058
4079
|
return attachment;
|
|
4059
4080
|
};
|
|
4081
|
+
var isSendable = (attachment) => isFinishedUpload(attachment) || !isLocalUploadAttachment(attachment);
|
|
4060
4082
|
var composeWithPendingUploads = ({
|
|
4061
4083
|
composer,
|
|
4062
4084
|
state
|
|
4063
4085
|
}) => {
|
|
4064
4086
|
const composerIsKeptAsDraft = !!composer.pollId;
|
|
4065
4087
|
const relevantAttachments = composer.attachmentManager.attachments.filter(
|
|
4066
|
-
(attachment) =>
|
|
4088
|
+
(attachment) => isSendable(attachment) || !composerIsKeptAsDraft && isPendingUpload(attachment)
|
|
4067
4089
|
);
|
|
4068
4090
|
const localAttachments = (state.localMessage.attachments ?? []).concat(
|
|
4069
4091
|
relevantAttachments.map(
|
|
@@ -4071,7 +4093,7 @@ var composeWithPendingUploads = ({
|
|
|
4071
4093
|
)
|
|
4072
4094
|
);
|
|
4073
4095
|
const messageAttachments = (state.message.attachments ?? []).concat(
|
|
4074
|
-
relevantAttachments.filter(
|
|
4096
|
+
relevantAttachments.filter(isSendable).map(localAttachmentToAttachment)
|
|
4075
4097
|
);
|
|
4076
4098
|
if (!localAttachments.length && !messageAttachments.length) return state;
|
|
4077
4099
|
return {
|
|
@@ -4126,7 +4148,7 @@ var createAttachmentsCompositionMiddleware = (composer) => ({
|
|
|
4126
4148
|
return discard();
|
|
4127
4149
|
}
|
|
4128
4150
|
const attachments = (state.message.attachments ?? []).concat(
|
|
4129
|
-
attachmentManager.
|
|
4151
|
+
attachmentManager.attachments.filter(isSendable).map(localAttachmentToAttachment)
|
|
4130
4152
|
);
|
|
4131
4153
|
if (!attachments.length) return forward();
|
|
4132
4154
|
return next({
|
|
@@ -4153,9 +4175,9 @@ var createDraftAttachmentsCompositionMiddleware = (composer) => ({
|
|
|
4153
4175
|
}) => {
|
|
4154
4176
|
const { attachmentManager } = composer;
|
|
4155
4177
|
if (!attachmentManager) return forward();
|
|
4156
|
-
const
|
|
4157
|
-
const attachments =
|
|
4158
|
-
|
|
4178
|
+
const sendableAttachments = attachmentManager.attachments.filter(isSendable);
|
|
4179
|
+
const attachments = sendableAttachments.length ? (state.draft.attachments ?? []).concat(
|
|
4180
|
+
sendableAttachments.map(localAttachmentToAttachment)
|
|
4159
4181
|
) : void 0;
|
|
4160
4182
|
return next({
|
|
4161
4183
|
...state,
|
|
@@ -10793,7 +10815,8 @@ var Channel = class {
|
|
|
10793
10815
|
}
|
|
10794
10816
|
const { messageSet, filteredMessageIds } = this._initializeState(
|
|
10795
10817
|
state,
|
|
10796
|
-
messageSetToAddToIfDoesNotExist
|
|
10818
|
+
messageSetToAddToIfDoesNotExist,
|
|
10819
|
+
!hasMessagePaginationCursor(options?.messages)
|
|
10797
10820
|
);
|
|
10798
10821
|
messageSet.pagination = {
|
|
10799
10822
|
...messageSet.pagination,
|
|
@@ -11411,7 +11434,7 @@ var Channel = class {
|
|
|
11411
11434
|
);
|
|
11412
11435
|
}
|
|
11413
11436
|
}
|
|
11414
|
-
_initializeState(state, messageSetToAddToIfDoesNotExist = "latest") {
|
|
11437
|
+
_initializeState(state, messageSetToAddToIfDoesNotExist = "latest", isNewestPage = true) {
|
|
11415
11438
|
const { state: clientState, user, userID } = this.getClient();
|
|
11416
11439
|
if (state.members) {
|
|
11417
11440
|
this._hydrateMembers({ members: state.members });
|
|
@@ -11426,6 +11449,9 @@ var Channel = class {
|
|
|
11426
11449
|
if (!this.state.messages) {
|
|
11427
11450
|
this.state.initMessages();
|
|
11428
11451
|
}
|
|
11452
|
+
if (messageSetToAddToIfDoesNotExist === "latest" && isNewestPage) {
|
|
11453
|
+
this.state._dropLatestMessagesDisjointFrom(messages);
|
|
11454
|
+
}
|
|
11429
11455
|
const { messageSet, filteredMessageIds } = this.state.addMessagesSorted(
|
|
11430
11456
|
messages,
|
|
11431
11457
|
false,
|
|
@@ -13355,9 +13381,14 @@ function applyOwnVoteDelta(state, { add = [], remove = [] }) {
|
|
|
13355
13381
|
}
|
|
13356
13382
|
voteCount = Math.max(voteCount - 1, 0);
|
|
13357
13383
|
if (latestVotesByOption?.[optionId]) {
|
|
13358
|
-
|
|
13384
|
+
const latestVotes = latestVotesByOption[optionId].filter(
|
|
13359
13385
|
(latestVote) => latestVote.id !== vote.id
|
|
13360
13386
|
);
|
|
13387
|
+
if (latestVotes.length) {
|
|
13388
|
+
latestVotesByOption[optionId] = latestVotes;
|
|
13389
|
+
} else {
|
|
13390
|
+
delete latestVotesByOption[optionId];
|
|
13391
|
+
}
|
|
13361
13392
|
}
|
|
13362
13393
|
}
|
|
13363
13394
|
for (const vote of add) {
|
|
@@ -14017,11 +14048,15 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
14017
14048
|
sort
|
|
14018
14049
|
});
|
|
14019
14050
|
if (channelsFromDB) {
|
|
14020
|
-
const offlineChannels = this.client.hydrateActiveChannels(
|
|
14021
|
-
|
|
14022
|
-
|
|
14023
|
-
|
|
14024
|
-
|
|
14051
|
+
const offlineChannels = this.client.hydrateActiveChannels(
|
|
14052
|
+
channelsFromDB,
|
|
14053
|
+
{
|
|
14054
|
+
offlineMode: true,
|
|
14055
|
+
skipInitialization: []
|
|
14056
|
+
// passing empty array will clear out the existing messages from channel state, this removes the possibility of duplicate messages
|
|
14057
|
+
},
|
|
14058
|
+
options
|
|
14059
|
+
);
|
|
14025
14060
|
this.state.partialNext({ channels: offlineChannels });
|
|
14026
14061
|
}
|
|
14027
14062
|
}
|
|
@@ -15462,7 +15497,7 @@ var StreamChat = class _StreamChat {
|
|
|
15462
15497
|
return this.userAgent;
|
|
15463
15498
|
}
|
|
15464
15499
|
if (!this.cachedUserAgent) {
|
|
15465
|
-
const version = "9.54.
|
|
15500
|
+
const version = "9.54.3";
|
|
15466
15501
|
const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
|
|
15467
15502
|
const { name: appName, version: appVersion } = this.appIdentifier ?? {};
|
|
15468
15503
|
const { os, model: deviceModel } = this.deviceIdentifier ?? {};
|
|
@@ -16392,7 +16427,7 @@ var StreamChat = class _StreamChat {
|
|
|
16392
16427
|
...updatedMessagesSet.pagination,
|
|
16393
16428
|
...messageSetPagination({
|
|
16394
16429
|
parentSet: updatedMessagesSet,
|
|
16395
|
-
requestedPageSize: queryChannelsOptions?.message_limit
|
|
16430
|
+
requestedPageSize: queryChannelsOptions?.message_limit ?? DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE,
|
|
16396
16431
|
returnedPage: channelState.messages,
|
|
16397
16432
|
filteredReturnedPage: channelState.messages.filter(
|
|
16398
16433
|
(m) => !filteredMessageIds.includes(m.id)
|