stream-chat 9.41.0 → 9.42.0
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 +226 -79
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +227 -79
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +226 -79
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/channel.d.ts +1 -0
- package/dist/types/channel_state.d.ts +2 -0
- package/dist/types/client.d.ts +5 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/messageComposer/LocationComposer.d.ts +1 -1
- package/dist/types/messageComposer/attachmentManager.d.ts +1 -0
- package/dist/types/messageComposer/configuration/types.d.ts +6 -1
- package/dist/types/messageComposer/fileUtils.d.ts +1 -1
- package/dist/types/messageComposer/messageComposer.d.ts +4 -4
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +2 -2
- package/dist/types/messageComposer/pollComposer.d.ts +2 -2
- package/dist/types/messageComposer/textComposer.d.ts +2 -2
- package/dist/types/uploadManager.d.ts +45 -0
- package/dist/types/utils.d.ts +4 -3
- package/package.json +2 -2
- package/src/channel.ts +9 -2
- package/src/channel_state.ts +5 -1
- package/src/client.ts +17 -2
- package/src/index.ts +1 -0
- package/src/messageComposer/attachmentManager.ts +65 -69
- package/src/messageComposer/configuration/types.ts +6 -1
- package/src/uploadManager.ts +176 -0
- package/src/utils.ts +26 -10
package/dist/cjs/index.node.js
CHANGED
|
@@ -117,6 +117,7 @@ __export(index_exports, {
|
|
|
117
117
|
ThreadManager: () => ThreadManager,
|
|
118
118
|
TokenManager: () => TokenManager,
|
|
119
119
|
UPDATE_LIVE_LOCATION_REQUEST_MIN_THROTTLE_TIMEOUT: () => UPDATE_LIVE_LOCATION_REQUEST_MIN_THROTTLE_TIMEOUT,
|
|
120
|
+
UploadManager: () => UploadManager,
|
|
120
121
|
UserFromToken: () => UserFromToken,
|
|
121
122
|
UserSearchSource: () => UserSearchSource,
|
|
122
123
|
VALID_MAX_VOTES_VALUE_REGEX: () => VALID_MAX_VOTES_VALUE_REGEX,
|
|
@@ -1013,6 +1014,7 @@ var messagePaginationCreatedAtAround = ({
|
|
|
1013
1014
|
parentSet,
|
|
1014
1015
|
requestedPageSize,
|
|
1015
1016
|
returnedPage,
|
|
1017
|
+
filteredReturnedPage,
|
|
1016
1018
|
messagePaginationOptions
|
|
1017
1019
|
}) => {
|
|
1018
1020
|
const newPagination = { ...parentSet.pagination };
|
|
@@ -1045,9 +1047,13 @@ var messagePaginationCreatedAtAround = ({
|
|
|
1045
1047
|
hasNext = hasPrev = false;
|
|
1046
1048
|
updateHasPrev = updateHasNext = true;
|
|
1047
1049
|
} else {
|
|
1050
|
+
const [firstFilteredPageMsg, lastFilteredPageMsg] = [
|
|
1051
|
+
filteredReturnedPage[0],
|
|
1052
|
+
filteredReturnedPage.slice(-1)[0]
|
|
1053
|
+
];
|
|
1048
1054
|
const [firstPageMsgIsFirstInSet, lastPageMsgIsLastInSet] = [
|
|
1049
|
-
|
|
1050
|
-
|
|
1055
|
+
firstFilteredPageMsg?.id && firstFilteredPageMsg.id === parentSet.messages[0]?.id,
|
|
1056
|
+
lastFilteredPageMsg?.id && lastFilteredPageMsg.id === parentSet.messages.slice(-1)[0]?.id
|
|
1051
1057
|
];
|
|
1052
1058
|
updateHasPrev = firstPageMsgIsFirstInSet;
|
|
1053
1059
|
updateHasNext = lastPageMsgIsLastInSet;
|
|
@@ -1069,6 +1075,7 @@ var messagePaginationIdAround = ({
|
|
|
1069
1075
|
parentSet,
|
|
1070
1076
|
requestedPageSize,
|
|
1071
1077
|
returnedPage,
|
|
1078
|
+
filteredReturnedPage,
|
|
1072
1079
|
messagePaginationOptions
|
|
1073
1080
|
}) => {
|
|
1074
1081
|
const newPagination = { ...parentSet.pagination };
|
|
@@ -1076,10 +1083,13 @@ var messagePaginationIdAround = ({
|
|
|
1076
1083
|
if (!id_around) return newPagination;
|
|
1077
1084
|
let hasPrev;
|
|
1078
1085
|
let hasNext;
|
|
1079
|
-
const [
|
|
1086
|
+
const [firstFilteredPageMsg, lastFilteredPageMsg] = [
|
|
1087
|
+
filteredReturnedPage[0],
|
|
1088
|
+
filteredReturnedPage.slice(-1)[0]
|
|
1089
|
+
];
|
|
1080
1090
|
const [firstPageMsgIsFirstInSet, lastPageMsgIsLastInSet] = [
|
|
1081
|
-
|
|
1082
|
-
|
|
1091
|
+
firstFilteredPageMsg?.id === parentSet.messages[0]?.id,
|
|
1092
|
+
lastFilteredPageMsg?.id === parentSet.messages.slice(-1)[0]?.id
|
|
1083
1093
|
];
|
|
1084
1094
|
let updateHasPrev = firstPageMsgIsFirstInSet;
|
|
1085
1095
|
let updateHasNext = lastPageMsgIsLastInSet;
|
|
@@ -1114,15 +1124,19 @@ var messagePaginationLinear = ({
|
|
|
1114
1124
|
parentSet,
|
|
1115
1125
|
requestedPageSize,
|
|
1116
1126
|
returnedPage,
|
|
1127
|
+
filteredReturnedPage,
|
|
1117
1128
|
messagePaginationOptions
|
|
1118
1129
|
}) => {
|
|
1119
1130
|
const newPagination = { ...parentSet.pagination };
|
|
1120
1131
|
let hasPrev;
|
|
1121
1132
|
let hasNext;
|
|
1122
|
-
const [
|
|
1133
|
+
const [firstFilteredPageMsg, lastFilteredPageMsg] = [
|
|
1134
|
+
filteredReturnedPage[0],
|
|
1135
|
+
filteredReturnedPage.slice(-1)[0]
|
|
1136
|
+
];
|
|
1123
1137
|
const [firstPageMsgIsFirstInSet, lastPageMsgIsLastInSet] = [
|
|
1124
|
-
|
|
1125
|
-
|
|
1138
|
+
firstFilteredPageMsg?.id && firstFilteredPageMsg.id === parentSet.messages[0]?.id,
|
|
1139
|
+
lastFilteredPageMsg?.id && lastFilteredPageMsg.id === parentSet.messages.slice(-1)[0]?.id
|
|
1126
1140
|
];
|
|
1127
1141
|
const queriedNextMessages = messagePaginationOptions && (messagePaginationOptions.created_at_after_or_equal || messagePaginationOptions.created_at_after || messagePaginationOptions.id_gt || messagePaginationOptions.id_gte);
|
|
1128
1142
|
const queriedPrevMessages = typeof messagePaginationOptions === "undefined" ? true : messagePaginationOptions.created_at_before_or_equal || messagePaginationOptions.created_at_before || messagePaginationOptions.id_lt || messagePaginationOptions.id_lte || messagePaginationOptions.offset;
|
|
@@ -1142,8 +1156,7 @@ var messagePaginationLinear = ({
|
|
|
1142
1156
|
return newPagination;
|
|
1143
1157
|
};
|
|
1144
1158
|
var messageSetPagination = (params) => {
|
|
1145
|
-
|
|
1146
|
-
if (params.parentSet.messages.length + messagesFilteredLocally.length < params.returnedPage.length) {
|
|
1159
|
+
if (params.parentSet.messages.length + (params.returnedPage.length - params.filteredReturnedPage.length) < params.returnedPage.length) {
|
|
1147
1160
|
params.logger?.(
|
|
1148
1161
|
"error",
|
|
1149
1162
|
"Corrupted message set state: parent set size < returned page size"
|
|
@@ -1490,9 +1503,11 @@ var ChannelState = class {
|
|
|
1490
1503
|
addIfDoesNotExist,
|
|
1491
1504
|
messageSetToAddToIfDoesNotExist
|
|
1492
1505
|
);
|
|
1506
|
+
const filteredMessageIds = [];
|
|
1493
1507
|
for (let i = 0; i < messagesToAdd.length; i += 1) {
|
|
1494
1508
|
const isFromShadowBannedUser = messagesToAdd[i].shadowed;
|
|
1495
|
-
if (isFromShadowBannedUser) {
|
|
1509
|
+
if (isFromShadowBannedUser && addIfDoesNotExist) {
|
|
1510
|
+
filteredMessageIds.push(messagesToAdd[i].id);
|
|
1496
1511
|
continue;
|
|
1497
1512
|
}
|
|
1498
1513
|
const isMessageFormatted = messagesToAdd[i].created_at instanceof Date;
|
|
@@ -1534,7 +1549,8 @@ var ChannelState = class {
|
|
|
1534
1549
|
}
|
|
1535
1550
|
}
|
|
1536
1551
|
return {
|
|
1537
|
-
messageSet: this.messageSets[targetMessageSetIndex]
|
|
1552
|
+
messageSet: this.messageSets[targetMessageSetIndex],
|
|
1553
|
+
filteredMessageIds
|
|
1538
1554
|
};
|
|
1539
1555
|
}
|
|
1540
1556
|
/**
|
|
@@ -3263,11 +3279,11 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3263
3279
|
return attachments;
|
|
3264
3280
|
}
|
|
3265
3281
|
}
|
|
3266
|
-
return
|
|
3282
|
+
return stateAttachments;
|
|
3267
3283
|
};
|
|
3268
3284
|
this.updateAttachment = (attachmentToUpdate) => {
|
|
3269
3285
|
const updatedAttachments = this.prepareAttachmentUpdate(attachmentToUpdate);
|
|
3270
|
-
if (updatedAttachments) {
|
|
3286
|
+
if (updatedAttachments && updatedAttachments !== this.attachments) {
|
|
3271
3287
|
this.state.partialNext({ attachments: updatedAttachments });
|
|
3272
3288
|
}
|
|
3273
3289
|
};
|
|
@@ -3277,15 +3293,15 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3277
3293
|
let hasUpdates = false;
|
|
3278
3294
|
attachmentsToUpsert.forEach((attachment) => {
|
|
3279
3295
|
const updatedAttachments = this.prepareAttachmentUpdate(attachment);
|
|
3280
|
-
if (updatedAttachments) {
|
|
3281
|
-
attachments = updatedAttachments;
|
|
3282
|
-
hasUpdates = true;
|
|
3283
|
-
} else {
|
|
3296
|
+
if (updatedAttachments === null) {
|
|
3284
3297
|
const localAttachment = ensureIsLocalAttachment(attachment);
|
|
3285
3298
|
if (localAttachment) {
|
|
3286
3299
|
attachments.push(localAttachment);
|
|
3287
3300
|
hasUpdates = true;
|
|
3288
3301
|
}
|
|
3302
|
+
} else if (updatedAttachments !== this.attachments) {
|
|
3303
|
+
attachments = updatedAttachments;
|
|
3304
|
+
hasUpdates = true;
|
|
3289
3305
|
}
|
|
3290
3306
|
});
|
|
3291
3307
|
if (hasUpdates) {
|
|
@@ -3293,11 +3309,15 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3293
3309
|
}
|
|
3294
3310
|
};
|
|
3295
3311
|
this.removeAttachments = (localAttachmentIds) => {
|
|
3312
|
+
if (!localAttachmentIds.length) return;
|
|
3296
3313
|
this.state.partialNext({
|
|
3297
3314
|
attachments: this.attachments.filter(
|
|
3298
3315
|
(attachment) => !localAttachmentIds.includes(attachment.localMetadata?.id)
|
|
3299
3316
|
)
|
|
3300
3317
|
});
|
|
3318
|
+
for (const id of localAttachmentIds) {
|
|
3319
|
+
this.client.uploadManager.deleteUploadRecord(id);
|
|
3320
|
+
}
|
|
3301
3321
|
};
|
|
3302
3322
|
this.getUploadConfigCheck = async (fileLike) => {
|
|
3303
3323
|
const client = this.channel.getClient();
|
|
@@ -3386,13 +3406,17 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3386
3406
|
const percent = progressEvent.lengthComputable && progressEvent.total ? Math.round(progressEvent.loaded * 100 / progressEvent.total) : void 0;
|
|
3387
3407
|
options.onProgress?.(percent);
|
|
3388
3408
|
} : void 0;
|
|
3409
|
+
const axiosUploadConfig = progressHandler || options?.abortSignal ? {
|
|
3410
|
+
...progressHandler ? { onUploadProgress: progressHandler } : {},
|
|
3411
|
+
...options?.abortSignal ? { signal: options.abortSignal } : {}
|
|
3412
|
+
} : void 0;
|
|
3389
3413
|
if (isFileReference(fileLike)) {
|
|
3390
3414
|
return this.channel[isImageFile(fileLike) ? "sendImage" : "sendFile"](
|
|
3391
3415
|
fileLike.uri,
|
|
3392
3416
|
fileLike.name,
|
|
3393
3417
|
fileLike.type,
|
|
3394
3418
|
void 0,
|
|
3395
|
-
|
|
3419
|
+
axiosUploadConfig
|
|
3396
3420
|
);
|
|
3397
3421
|
}
|
|
3398
3422
|
const file = isFile(fileLike) ? fileLike : createFileFromBlobs({
|
|
@@ -3400,13 +3424,7 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3400
3424
|
fileName: generateFileName(fileLike.type),
|
|
3401
3425
|
mimeType: fileLike.type
|
|
3402
3426
|
});
|
|
3403
|
-
const { duration, ...result } = await this.channel[isImageFile(fileLike) ? "sendImage" : "sendFile"](
|
|
3404
|
-
file,
|
|
3405
|
-
void 0,
|
|
3406
|
-
void 0,
|
|
3407
|
-
void 0,
|
|
3408
|
-
progressHandler ? { onUploadProgress: progressHandler } : void 0
|
|
3409
|
-
);
|
|
3427
|
+
const { duration, ...result } = await this.channel[isImageFile(fileLike) ? "sendImage" : "sendFile"](file, void 0, void 0, void 0, axiosUploadConfig);
|
|
3410
3428
|
return result;
|
|
3411
3429
|
};
|
|
3412
3430
|
/**
|
|
@@ -3441,33 +3459,9 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3441
3459
|
});
|
|
3442
3460
|
return localAttachment;
|
|
3443
3461
|
}
|
|
3444
|
-
const shouldTrackProgress = this.config.trackUploadProgress;
|
|
3445
|
-
const uploadingAttachment = {
|
|
3446
|
-
...attachment,
|
|
3447
|
-
localMetadata: {
|
|
3448
|
-
...attachment.localMetadata,
|
|
3449
|
-
uploadState: "uploading",
|
|
3450
|
-
...shouldTrackProgress && { uploadProgress: 0 }
|
|
3451
|
-
}
|
|
3452
|
-
};
|
|
3453
|
-
this.upsertAttachments([uploadingAttachment]);
|
|
3454
|
-
const uploadOptions = shouldTrackProgress ? {
|
|
3455
|
-
onProgress: (percent) => {
|
|
3456
|
-
this.updateAttachment({
|
|
3457
|
-
...uploadingAttachment,
|
|
3458
|
-
localMetadata: {
|
|
3459
|
-
...uploadingAttachment.localMetadata,
|
|
3460
|
-
uploadProgress: percent
|
|
3461
|
-
}
|
|
3462
|
-
});
|
|
3463
|
-
}
|
|
3464
|
-
} : void 0;
|
|
3465
3462
|
let response;
|
|
3466
3463
|
try {
|
|
3467
|
-
response = await this.
|
|
3468
|
-
localAttachment.localMetadata.file,
|
|
3469
|
-
uploadOptions
|
|
3470
|
-
);
|
|
3464
|
+
response = await this.upload(attachment);
|
|
3471
3465
|
} catch (error) {
|
|
3472
3466
|
const reason = error instanceof Error ? error.message : "unknown error";
|
|
3473
3467
|
const failedAttachment = {
|
|
@@ -3536,31 +3530,10 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3536
3530
|
this.upsertAttachments([attachment]);
|
|
3537
3531
|
return preUpload.state.attachment;
|
|
3538
3532
|
}
|
|
3539
|
-
const shouldTrackProgress = this.config.trackUploadProgress;
|
|
3540
|
-
attachment = {
|
|
3541
|
-
...attachment,
|
|
3542
|
-
localMetadata: {
|
|
3543
|
-
...attachment.localMetadata,
|
|
3544
|
-
uploadState: "uploading",
|
|
3545
|
-
...shouldTrackProgress && { uploadProgress: 0 }
|
|
3546
|
-
}
|
|
3547
|
-
};
|
|
3548
|
-
this.upsertAttachments([attachment]);
|
|
3549
|
-
const uploadOptions = shouldTrackProgress ? {
|
|
3550
|
-
onProgress: (percent) => {
|
|
3551
|
-
this.updateAttachment({
|
|
3552
|
-
...attachment,
|
|
3553
|
-
localMetadata: {
|
|
3554
|
-
...attachment.localMetadata,
|
|
3555
|
-
uploadProgress: percent
|
|
3556
|
-
}
|
|
3557
|
-
});
|
|
3558
|
-
}
|
|
3559
|
-
} : void 0;
|
|
3560
3533
|
let response;
|
|
3561
3534
|
let error;
|
|
3562
3535
|
try {
|
|
3563
|
-
response = await this.
|
|
3536
|
+
response = await this.upload(attachment);
|
|
3564
3537
|
} catch (err) {
|
|
3565
3538
|
error = err instanceof Error ? err : void 0;
|
|
3566
3539
|
}
|
|
@@ -3687,6 +3660,40 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3687
3660
|
({ localMetadata }) => localMetadata.uploadState === state
|
|
3688
3661
|
);
|
|
3689
3662
|
}
|
|
3663
|
+
upload(attachment) {
|
|
3664
|
+
const localId = attachment.localMetadata.id;
|
|
3665
|
+
this.upsertAttachments([
|
|
3666
|
+
{
|
|
3667
|
+
...attachment,
|
|
3668
|
+
localMetadata: {
|
|
3669
|
+
...attachment.localMetadata,
|
|
3670
|
+
uploadState: "uploading",
|
|
3671
|
+
uploadProgress: this.config.trackUploadProgress ? 0 : void 0
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
]);
|
|
3675
|
+
const unsubscribe = this.client.uploadManager.state.subscribeWithSelector(
|
|
3676
|
+
(s) => ({ upload: s.uploads[localId] }),
|
|
3677
|
+
({ upload: nextUpload }) => {
|
|
3678
|
+
if (!nextUpload) return;
|
|
3679
|
+
this.updateAttachment({
|
|
3680
|
+
...attachment,
|
|
3681
|
+
localMetadata: {
|
|
3682
|
+
...attachment.localMetadata,
|
|
3683
|
+
uploadState: "uploading",
|
|
3684
|
+
uploadProgress: nextUpload.uploadProgress
|
|
3685
|
+
}
|
|
3686
|
+
});
|
|
3687
|
+
}
|
|
3688
|
+
);
|
|
3689
|
+
return this.client.uploadManager.upload({
|
|
3690
|
+
id: localId,
|
|
3691
|
+
channelCid: this.channel.cid,
|
|
3692
|
+
file: attachment.localMetadata.file
|
|
3693
|
+
}).finally(() => {
|
|
3694
|
+
unsubscribe();
|
|
3695
|
+
});
|
|
3696
|
+
}
|
|
3690
3697
|
};
|
|
3691
3698
|
_AttachmentManager.toLocalUploadAttachment = (fileLike) => {
|
|
3692
3699
|
const file = isFileReference(fileLike) || isFile(fileLike) ? fileLike : createFileFromBlobs({
|
|
@@ -9270,7 +9277,10 @@ var Channel = class {
|
|
|
9270
9277
|
location: { enabled: state.channel.config.shared_locations }
|
|
9271
9278
|
});
|
|
9272
9279
|
}
|
|
9273
|
-
const { messageSet } = this._initializeState(
|
|
9280
|
+
const { messageSet, filteredMessageIds } = this._initializeState(
|
|
9281
|
+
state,
|
|
9282
|
+
messageSetToAddToIfDoesNotExist
|
|
9283
|
+
);
|
|
9274
9284
|
messageSet.pagination = {
|
|
9275
9285
|
...messageSet.pagination,
|
|
9276
9286
|
...messageSetPagination({
|
|
@@ -9278,6 +9288,9 @@ var Channel = class {
|
|
|
9278
9288
|
messagePaginationOptions: options?.messages,
|
|
9279
9289
|
requestedPageSize: options?.messages?.limit ?? DEFAULT_QUERY_CHANNEL_MESSAGE_LIST_PAGE_SIZE,
|
|
9280
9290
|
returnedPage: state.messages,
|
|
9291
|
+
filteredReturnedPage: state.messages.filter(
|
|
9292
|
+
(m) => !filteredMessageIds.includes(m.id)
|
|
9293
|
+
),
|
|
9281
9294
|
logger: this.getClient().logger
|
|
9282
9295
|
})
|
|
9283
9296
|
};
|
|
@@ -9897,7 +9910,7 @@ var Channel = class {
|
|
|
9897
9910
|
if (!this.state.messages) {
|
|
9898
9911
|
this.state.initMessages();
|
|
9899
9912
|
}
|
|
9900
|
-
const { messageSet } = this.state.addMessagesSorted(
|
|
9913
|
+
const { messageSet, filteredMessageIds } = this.state.addMessagesSorted(
|
|
9901
9914
|
messages,
|
|
9902
9915
|
false,
|
|
9903
9916
|
true,
|
|
@@ -9949,7 +9962,8 @@ var Channel = class {
|
|
|
9949
9962
|
this.messageReceiptsTracker.ingestInitial(state.read);
|
|
9950
9963
|
}
|
|
9951
9964
|
return {
|
|
9952
|
-
messageSet
|
|
9965
|
+
messageSet,
|
|
9966
|
+
filteredMessageIds
|
|
9953
9967
|
};
|
|
9954
9968
|
}
|
|
9955
9969
|
_extendEventWithOwnReactions(event) {
|
|
@@ -10556,6 +10570,131 @@ var StableWSConnection = class {
|
|
|
10556
10570
|
}
|
|
10557
10571
|
};
|
|
10558
10572
|
|
|
10573
|
+
// src/uploadManager.ts
|
|
10574
|
+
var initState7 = () => ({ uploads: {} });
|
|
10575
|
+
var upsertById = (uploads, record) => ({
|
|
10576
|
+
...uploads,
|
|
10577
|
+
[record.id]: { ...uploads[record.id], ...record }
|
|
10578
|
+
});
|
|
10579
|
+
var updateById = (uploads, record) => {
|
|
10580
|
+
if (!(record.id in uploads)) return null;
|
|
10581
|
+
const current = uploads[record.id];
|
|
10582
|
+
return { ...uploads, [record.id]: { ...current, ...record } };
|
|
10583
|
+
};
|
|
10584
|
+
var UploadManager = class {
|
|
10585
|
+
constructor(client) {
|
|
10586
|
+
this.client = client;
|
|
10587
|
+
this.inFlightUploads = /* @__PURE__ */ new Map();
|
|
10588
|
+
this.getUpload = (id) => this.uploads[id];
|
|
10589
|
+
/**
|
|
10590
|
+
* Clears all upload records.
|
|
10591
|
+
* Invoked when the user disconnects so a later session does not inherit stale upload state.
|
|
10592
|
+
* Aborts every in-flight upload request via its `UploadRequestOptions.abortSignal`.
|
|
10593
|
+
*/
|
|
10594
|
+
this.reset = () => {
|
|
10595
|
+
for (const { abortController } of this.inFlightUploads.values()) {
|
|
10596
|
+
abortController.abort();
|
|
10597
|
+
}
|
|
10598
|
+
this.inFlightUploads.clear();
|
|
10599
|
+
this.state.next(initState7());
|
|
10600
|
+
};
|
|
10601
|
+
/**
|
|
10602
|
+
* Removes the upload record for `id` if present.
|
|
10603
|
+
* If an upload is still in progress, aborts its `UploadRequestOptions.abortSignal`.
|
|
10604
|
+
*/
|
|
10605
|
+
this.deleteUploadRecord = (id) => {
|
|
10606
|
+
const flight = this.inFlightUploads.get(id);
|
|
10607
|
+
if (flight) {
|
|
10608
|
+
this.inFlightUploads.delete(id);
|
|
10609
|
+
flight.abortController.abort();
|
|
10610
|
+
}
|
|
10611
|
+
this.state.next((current) => {
|
|
10612
|
+
if (!(id in current.uploads)) return current;
|
|
10613
|
+
const uploads = { ...current.uploads };
|
|
10614
|
+
delete uploads[id];
|
|
10615
|
+
return { ...current, uploads };
|
|
10616
|
+
});
|
|
10617
|
+
};
|
|
10618
|
+
/**
|
|
10619
|
+
* Starts an upload for `id`, or returns the existing in-flight promise if one is already running.
|
|
10620
|
+
* Uses {@link StreamChat.channel}(`channelCid`) → `messageComposer.attachmentManager.doUploadRequest`.
|
|
10621
|
+
* Resolves with that result; rejects if the upload rejects (the record is removed from state either way).
|
|
10622
|
+
*/
|
|
10623
|
+
this.upload = ({
|
|
10624
|
+
id,
|
|
10625
|
+
channelCid,
|
|
10626
|
+
file
|
|
10627
|
+
}) => {
|
|
10628
|
+
const existing = this.inFlightUploads.get(id);
|
|
10629
|
+
if (existing) return existing.promise;
|
|
10630
|
+
let resolvePromise;
|
|
10631
|
+
let rejectPromise;
|
|
10632
|
+
const promise = new Promise((resolve, reject) => {
|
|
10633
|
+
resolvePromise = resolve;
|
|
10634
|
+
rejectPromise = reject;
|
|
10635
|
+
});
|
|
10636
|
+
const abortController = new AbortController();
|
|
10637
|
+
this.inFlightUploads.set(id, { promise, abortController });
|
|
10638
|
+
void (async () => {
|
|
10639
|
+
const attachmentManager = this.resolveAttachmentManager(channelCid);
|
|
10640
|
+
const trackProgress = attachmentManager.config.trackUploadProgress;
|
|
10641
|
+
try {
|
|
10642
|
+
this.upsertUpload({
|
|
10643
|
+
id,
|
|
10644
|
+
uploadProgress: trackProgress ? 0 : void 0
|
|
10645
|
+
});
|
|
10646
|
+
const onProgress = trackProgress ? (progress) => {
|
|
10647
|
+
this.updateUpload({
|
|
10648
|
+
id,
|
|
10649
|
+
uploadProgress: progress
|
|
10650
|
+
});
|
|
10651
|
+
} : void 0;
|
|
10652
|
+
const uploadRequestOptions = {
|
|
10653
|
+
abortSignal: abortController.signal,
|
|
10654
|
+
...onProgress ? { onProgress } : {}
|
|
10655
|
+
};
|
|
10656
|
+
const response = await attachmentManager.doUploadRequest(
|
|
10657
|
+
file,
|
|
10658
|
+
uploadRequestOptions
|
|
10659
|
+
);
|
|
10660
|
+
resolvePromise(response);
|
|
10661
|
+
} catch (error) {
|
|
10662
|
+
rejectPromise(error);
|
|
10663
|
+
} finally {
|
|
10664
|
+
this.inFlightUploads.delete(id);
|
|
10665
|
+
this.deleteUploadRecord(id);
|
|
10666
|
+
}
|
|
10667
|
+
})();
|
|
10668
|
+
return promise;
|
|
10669
|
+
};
|
|
10670
|
+
this.upsertUpload = (record) => {
|
|
10671
|
+
this.state.partialNext({
|
|
10672
|
+
uploads: upsertById(this.uploads, record)
|
|
10673
|
+
});
|
|
10674
|
+
};
|
|
10675
|
+
this.updateUpload = (record) => {
|
|
10676
|
+
this.state.next((current) => {
|
|
10677
|
+
const nextUploads = updateById(current.uploads, record);
|
|
10678
|
+
if (!nextUploads) return current;
|
|
10679
|
+
return { ...current, uploads: nextUploads };
|
|
10680
|
+
});
|
|
10681
|
+
};
|
|
10682
|
+
this.state = new StateStore(initState7());
|
|
10683
|
+
}
|
|
10684
|
+
resolveAttachmentManager(channelCid) {
|
|
10685
|
+
const colon = channelCid.indexOf(":");
|
|
10686
|
+
if (colon <= 0 || colon === channelCid.length - 1) {
|
|
10687
|
+
throw new Error(`Invalid channelCid: ${channelCid}`);
|
|
10688
|
+
}
|
|
10689
|
+
const channelType = channelCid.slice(0, colon);
|
|
10690
|
+
const channelId = channelCid.slice(colon + 1);
|
|
10691
|
+
return this.client.channel(channelType, channelId).messageComposer.attachmentManager;
|
|
10692
|
+
}
|
|
10693
|
+
get uploads() {
|
|
10694
|
+
return this.state.getLatestValue().uploads;
|
|
10695
|
+
}
|
|
10696
|
+
};
|
|
10697
|
+
|
|
10559
10698
|
// src/signing.ts
|
|
10560
10699
|
var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
|
10561
10700
|
var import_crypto = __toESM(require("crypto"));
|
|
@@ -13028,6 +13167,7 @@ var StreamChat = class _StreamChat {
|
|
|
13028
13167
|
this.activeChannels = {};
|
|
13029
13168
|
this.state = new ClientState({ client: this });
|
|
13030
13169
|
this.threads.resetState();
|
|
13170
|
+
this.uploadManager.reset();
|
|
13031
13171
|
closePromise.finally(() => {
|
|
13032
13172
|
this.tokenManager.reset();
|
|
13033
13173
|
}).catch((err) => console.error(err));
|
|
@@ -13434,6 +13574,7 @@ var StreamChat = class _StreamChat {
|
|
|
13434
13574
|
this.blockedUsers = new StateStore({ userIds: [] });
|
|
13435
13575
|
this.moderation = new Moderation(this);
|
|
13436
13576
|
this.notifications = options?.notifications ?? new NotificationManager();
|
|
13577
|
+
this.uploadManager = new UploadManager(this);
|
|
13437
13578
|
if (secretOrOptions && isString2(secretOrOptions)) {
|
|
13438
13579
|
this.secret = secretOrOptions;
|
|
13439
13580
|
}
|
|
@@ -14152,12 +14293,15 @@ var StreamChat = class _StreamChat {
|
|
|
14152
14293
|
c.initialized = !offlineMode;
|
|
14153
14294
|
c.push_preferences = channelState.push_preferences;
|
|
14154
14295
|
let updatedMessagesSet;
|
|
14296
|
+
let filteredMessageIds = [];
|
|
14155
14297
|
if (skipInitialization === void 0) {
|
|
14156
|
-
const { messageSet } = c._initializeState(channelState, "latest");
|
|
14298
|
+
const { messageSet, filteredMessageIds: _filteredMessageIds } = c._initializeState(channelState, "latest");
|
|
14299
|
+
filteredMessageIds = _filteredMessageIds;
|
|
14157
14300
|
updatedMessagesSet = messageSet;
|
|
14158
14301
|
} else if (!skipInitialization.includes(channelState.channel.id)) {
|
|
14159
14302
|
c.state.clearMessages();
|
|
14160
|
-
const { messageSet } = c._initializeState(channelState, "latest");
|
|
14303
|
+
const { messageSet, filteredMessageIds: _filteredMessageIds } = c._initializeState(channelState, "latest");
|
|
14304
|
+
filteredMessageIds = _filteredMessageIds;
|
|
14161
14305
|
updatedMessagesSet = messageSet;
|
|
14162
14306
|
}
|
|
14163
14307
|
if (updatedMessagesSet) {
|
|
@@ -14167,6 +14311,9 @@ var StreamChat = class _StreamChat {
|
|
|
14167
14311
|
parentSet: updatedMessagesSet,
|
|
14168
14312
|
requestedPageSize: queryChannelsOptions?.message_limit || DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE,
|
|
14169
14313
|
returnedPage: channelState.messages,
|
|
14314
|
+
filteredReturnedPage: channelState.messages.filter(
|
|
14315
|
+
(m) => !filteredMessageIds.includes(m.id)
|
|
14316
|
+
),
|
|
14170
14317
|
logger: this.logger
|
|
14171
14318
|
})
|
|
14172
14319
|
};
|
|
@@ -15217,7 +15364,7 @@ var StreamChat = class _StreamChat {
|
|
|
15217
15364
|
if (this.userAgent) {
|
|
15218
15365
|
return this.userAgent;
|
|
15219
15366
|
}
|
|
15220
|
-
const version = "9.
|
|
15367
|
+
const version = "9.42.0";
|
|
15221
15368
|
const clientBundle = "node-cjs";
|
|
15222
15369
|
let userAgentString = "";
|
|
15223
15370
|
if (this.sdkIdentifier) {
|
|
@@ -17907,6 +18054,7 @@ var FixedSizeQueueCache = class {
|
|
|
17907
18054
|
ThreadManager,
|
|
17908
18055
|
TokenManager,
|
|
17909
18056
|
UPDATE_LIVE_LOCATION_REQUEST_MIN_THROTTLE_TIMEOUT,
|
|
18057
|
+
UploadManager,
|
|
17910
18058
|
UserFromToken,
|
|
17911
18059
|
UserSearchSource,
|
|
17912
18060
|
VALID_MAX_VOTES_VALUE_REGEX,
|