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/esm/index.mjs
CHANGED
|
@@ -845,6 +845,7 @@ var messagePaginationCreatedAtAround = ({
|
|
|
845
845
|
parentSet,
|
|
846
846
|
requestedPageSize,
|
|
847
847
|
returnedPage,
|
|
848
|
+
filteredReturnedPage,
|
|
848
849
|
messagePaginationOptions
|
|
849
850
|
}) => {
|
|
850
851
|
const newPagination = { ...parentSet.pagination };
|
|
@@ -877,9 +878,13 @@ var messagePaginationCreatedAtAround = ({
|
|
|
877
878
|
hasNext = hasPrev = false;
|
|
878
879
|
updateHasPrev = updateHasNext = true;
|
|
879
880
|
} else {
|
|
881
|
+
const [firstFilteredPageMsg, lastFilteredPageMsg] = [
|
|
882
|
+
filteredReturnedPage[0],
|
|
883
|
+
filteredReturnedPage.slice(-1)[0]
|
|
884
|
+
];
|
|
880
885
|
const [firstPageMsgIsFirstInSet, lastPageMsgIsLastInSet] = [
|
|
881
|
-
|
|
882
|
-
|
|
886
|
+
firstFilteredPageMsg?.id && firstFilteredPageMsg.id === parentSet.messages[0]?.id,
|
|
887
|
+
lastFilteredPageMsg?.id && lastFilteredPageMsg.id === parentSet.messages.slice(-1)[0]?.id
|
|
883
888
|
];
|
|
884
889
|
updateHasPrev = firstPageMsgIsFirstInSet;
|
|
885
890
|
updateHasNext = lastPageMsgIsLastInSet;
|
|
@@ -901,6 +906,7 @@ var messagePaginationIdAround = ({
|
|
|
901
906
|
parentSet,
|
|
902
907
|
requestedPageSize,
|
|
903
908
|
returnedPage,
|
|
909
|
+
filteredReturnedPage,
|
|
904
910
|
messagePaginationOptions
|
|
905
911
|
}) => {
|
|
906
912
|
const newPagination = { ...parentSet.pagination };
|
|
@@ -908,10 +914,13 @@ var messagePaginationIdAround = ({
|
|
|
908
914
|
if (!id_around) return newPagination;
|
|
909
915
|
let hasPrev;
|
|
910
916
|
let hasNext;
|
|
911
|
-
const [
|
|
917
|
+
const [firstFilteredPageMsg, lastFilteredPageMsg] = [
|
|
918
|
+
filteredReturnedPage[0],
|
|
919
|
+
filteredReturnedPage.slice(-1)[0]
|
|
920
|
+
];
|
|
912
921
|
const [firstPageMsgIsFirstInSet, lastPageMsgIsLastInSet] = [
|
|
913
|
-
|
|
914
|
-
|
|
922
|
+
firstFilteredPageMsg?.id === parentSet.messages[0]?.id,
|
|
923
|
+
lastFilteredPageMsg?.id === parentSet.messages.slice(-1)[0]?.id
|
|
915
924
|
];
|
|
916
925
|
let updateHasPrev = firstPageMsgIsFirstInSet;
|
|
917
926
|
let updateHasNext = lastPageMsgIsLastInSet;
|
|
@@ -946,15 +955,19 @@ var messagePaginationLinear = ({
|
|
|
946
955
|
parentSet,
|
|
947
956
|
requestedPageSize,
|
|
948
957
|
returnedPage,
|
|
958
|
+
filteredReturnedPage,
|
|
949
959
|
messagePaginationOptions
|
|
950
960
|
}) => {
|
|
951
961
|
const newPagination = { ...parentSet.pagination };
|
|
952
962
|
let hasPrev;
|
|
953
963
|
let hasNext;
|
|
954
|
-
const [
|
|
964
|
+
const [firstFilteredPageMsg, lastFilteredPageMsg] = [
|
|
965
|
+
filteredReturnedPage[0],
|
|
966
|
+
filteredReturnedPage.slice(-1)[0]
|
|
967
|
+
];
|
|
955
968
|
const [firstPageMsgIsFirstInSet, lastPageMsgIsLastInSet] = [
|
|
956
|
-
|
|
957
|
-
|
|
969
|
+
firstFilteredPageMsg?.id && firstFilteredPageMsg.id === parentSet.messages[0]?.id,
|
|
970
|
+
lastFilteredPageMsg?.id && lastFilteredPageMsg.id === parentSet.messages.slice(-1)[0]?.id
|
|
958
971
|
];
|
|
959
972
|
const queriedNextMessages = messagePaginationOptions && (messagePaginationOptions.created_at_after_or_equal || messagePaginationOptions.created_at_after || messagePaginationOptions.id_gt || messagePaginationOptions.id_gte);
|
|
960
973
|
const queriedPrevMessages = typeof messagePaginationOptions === "undefined" ? true : messagePaginationOptions.created_at_before_or_equal || messagePaginationOptions.created_at_before || messagePaginationOptions.id_lt || messagePaginationOptions.id_lte || messagePaginationOptions.offset;
|
|
@@ -974,8 +987,7 @@ var messagePaginationLinear = ({
|
|
|
974
987
|
return newPagination;
|
|
975
988
|
};
|
|
976
989
|
var messageSetPagination = (params) => {
|
|
977
|
-
|
|
978
|
-
if (params.parentSet.messages.length + messagesFilteredLocally.length < params.returnedPage.length) {
|
|
990
|
+
if (params.parentSet.messages.length + (params.returnedPage.length - params.filteredReturnedPage.length) < params.returnedPage.length) {
|
|
979
991
|
params.logger?.(
|
|
980
992
|
"error",
|
|
981
993
|
"Corrupted message set state: parent set size < returned page size"
|
|
@@ -1322,9 +1334,11 @@ var ChannelState = class {
|
|
|
1322
1334
|
addIfDoesNotExist,
|
|
1323
1335
|
messageSetToAddToIfDoesNotExist
|
|
1324
1336
|
);
|
|
1337
|
+
const filteredMessageIds = [];
|
|
1325
1338
|
for (let i = 0; i < messagesToAdd.length; i += 1) {
|
|
1326
1339
|
const isFromShadowBannedUser = messagesToAdd[i].shadowed;
|
|
1327
|
-
if (isFromShadowBannedUser) {
|
|
1340
|
+
if (isFromShadowBannedUser && addIfDoesNotExist) {
|
|
1341
|
+
filteredMessageIds.push(messagesToAdd[i].id);
|
|
1328
1342
|
continue;
|
|
1329
1343
|
}
|
|
1330
1344
|
const isMessageFormatted = messagesToAdd[i].created_at instanceof Date;
|
|
@@ -1366,7 +1380,8 @@ var ChannelState = class {
|
|
|
1366
1380
|
}
|
|
1367
1381
|
}
|
|
1368
1382
|
return {
|
|
1369
|
-
messageSet: this.messageSets[targetMessageSetIndex]
|
|
1383
|
+
messageSet: this.messageSets[targetMessageSetIndex],
|
|
1384
|
+
filteredMessageIds
|
|
1370
1385
|
};
|
|
1371
1386
|
}
|
|
1372
1387
|
/**
|
|
@@ -3095,11 +3110,11 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3095
3110
|
return attachments;
|
|
3096
3111
|
}
|
|
3097
3112
|
}
|
|
3098
|
-
return
|
|
3113
|
+
return stateAttachments;
|
|
3099
3114
|
};
|
|
3100
3115
|
this.updateAttachment = (attachmentToUpdate) => {
|
|
3101
3116
|
const updatedAttachments = this.prepareAttachmentUpdate(attachmentToUpdate);
|
|
3102
|
-
if (updatedAttachments) {
|
|
3117
|
+
if (updatedAttachments && updatedAttachments !== this.attachments) {
|
|
3103
3118
|
this.state.partialNext({ attachments: updatedAttachments });
|
|
3104
3119
|
}
|
|
3105
3120
|
};
|
|
@@ -3109,15 +3124,15 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3109
3124
|
let hasUpdates = false;
|
|
3110
3125
|
attachmentsToUpsert.forEach((attachment) => {
|
|
3111
3126
|
const updatedAttachments = this.prepareAttachmentUpdate(attachment);
|
|
3112
|
-
if (updatedAttachments) {
|
|
3113
|
-
attachments = updatedAttachments;
|
|
3114
|
-
hasUpdates = true;
|
|
3115
|
-
} else {
|
|
3127
|
+
if (updatedAttachments === null) {
|
|
3116
3128
|
const localAttachment = ensureIsLocalAttachment(attachment);
|
|
3117
3129
|
if (localAttachment) {
|
|
3118
3130
|
attachments.push(localAttachment);
|
|
3119
3131
|
hasUpdates = true;
|
|
3120
3132
|
}
|
|
3133
|
+
} else if (updatedAttachments !== this.attachments) {
|
|
3134
|
+
attachments = updatedAttachments;
|
|
3135
|
+
hasUpdates = true;
|
|
3121
3136
|
}
|
|
3122
3137
|
});
|
|
3123
3138
|
if (hasUpdates) {
|
|
@@ -3125,11 +3140,15 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3125
3140
|
}
|
|
3126
3141
|
};
|
|
3127
3142
|
this.removeAttachments = (localAttachmentIds) => {
|
|
3143
|
+
if (!localAttachmentIds.length) return;
|
|
3128
3144
|
this.state.partialNext({
|
|
3129
3145
|
attachments: this.attachments.filter(
|
|
3130
3146
|
(attachment) => !localAttachmentIds.includes(attachment.localMetadata?.id)
|
|
3131
3147
|
)
|
|
3132
3148
|
});
|
|
3149
|
+
for (const id of localAttachmentIds) {
|
|
3150
|
+
this.client.uploadManager.deleteUploadRecord(id);
|
|
3151
|
+
}
|
|
3133
3152
|
};
|
|
3134
3153
|
this.getUploadConfigCheck = async (fileLike) => {
|
|
3135
3154
|
const client = this.channel.getClient();
|
|
@@ -3218,13 +3237,17 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3218
3237
|
const percent = progressEvent.lengthComputable && progressEvent.total ? Math.round(progressEvent.loaded * 100 / progressEvent.total) : void 0;
|
|
3219
3238
|
options.onProgress?.(percent);
|
|
3220
3239
|
} : void 0;
|
|
3240
|
+
const axiosUploadConfig = progressHandler || options?.abortSignal ? {
|
|
3241
|
+
...progressHandler ? { onUploadProgress: progressHandler } : {},
|
|
3242
|
+
...options?.abortSignal ? { signal: options.abortSignal } : {}
|
|
3243
|
+
} : void 0;
|
|
3221
3244
|
if (isFileReference(fileLike)) {
|
|
3222
3245
|
return this.channel[isImageFile(fileLike) ? "sendImage" : "sendFile"](
|
|
3223
3246
|
fileLike.uri,
|
|
3224
3247
|
fileLike.name,
|
|
3225
3248
|
fileLike.type,
|
|
3226
3249
|
void 0,
|
|
3227
|
-
|
|
3250
|
+
axiosUploadConfig
|
|
3228
3251
|
);
|
|
3229
3252
|
}
|
|
3230
3253
|
const file = isFile(fileLike) ? fileLike : createFileFromBlobs({
|
|
@@ -3232,13 +3255,7 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3232
3255
|
fileName: generateFileName(fileLike.type),
|
|
3233
3256
|
mimeType: fileLike.type
|
|
3234
3257
|
});
|
|
3235
|
-
const { duration, ...result } = await this.channel[isImageFile(fileLike) ? "sendImage" : "sendFile"](
|
|
3236
|
-
file,
|
|
3237
|
-
void 0,
|
|
3238
|
-
void 0,
|
|
3239
|
-
void 0,
|
|
3240
|
-
progressHandler ? { onUploadProgress: progressHandler } : void 0
|
|
3241
|
-
);
|
|
3258
|
+
const { duration, ...result } = await this.channel[isImageFile(fileLike) ? "sendImage" : "sendFile"](file, void 0, void 0, void 0, axiosUploadConfig);
|
|
3242
3259
|
return result;
|
|
3243
3260
|
};
|
|
3244
3261
|
/**
|
|
@@ -3273,33 +3290,9 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3273
3290
|
});
|
|
3274
3291
|
return localAttachment;
|
|
3275
3292
|
}
|
|
3276
|
-
const shouldTrackProgress = this.config.trackUploadProgress;
|
|
3277
|
-
const uploadingAttachment = {
|
|
3278
|
-
...attachment,
|
|
3279
|
-
localMetadata: {
|
|
3280
|
-
...attachment.localMetadata,
|
|
3281
|
-
uploadState: "uploading",
|
|
3282
|
-
...shouldTrackProgress && { uploadProgress: 0 }
|
|
3283
|
-
}
|
|
3284
|
-
};
|
|
3285
|
-
this.upsertAttachments([uploadingAttachment]);
|
|
3286
|
-
const uploadOptions = shouldTrackProgress ? {
|
|
3287
|
-
onProgress: (percent) => {
|
|
3288
|
-
this.updateAttachment({
|
|
3289
|
-
...uploadingAttachment,
|
|
3290
|
-
localMetadata: {
|
|
3291
|
-
...uploadingAttachment.localMetadata,
|
|
3292
|
-
uploadProgress: percent
|
|
3293
|
-
}
|
|
3294
|
-
});
|
|
3295
|
-
}
|
|
3296
|
-
} : void 0;
|
|
3297
3293
|
let response;
|
|
3298
3294
|
try {
|
|
3299
|
-
response = await this.
|
|
3300
|
-
localAttachment.localMetadata.file,
|
|
3301
|
-
uploadOptions
|
|
3302
|
-
);
|
|
3295
|
+
response = await this.upload(attachment);
|
|
3303
3296
|
} catch (error) {
|
|
3304
3297
|
const reason = error instanceof Error ? error.message : "unknown error";
|
|
3305
3298
|
const failedAttachment = {
|
|
@@ -3368,31 +3361,10 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3368
3361
|
this.upsertAttachments([attachment]);
|
|
3369
3362
|
return preUpload.state.attachment;
|
|
3370
3363
|
}
|
|
3371
|
-
const shouldTrackProgress = this.config.trackUploadProgress;
|
|
3372
|
-
attachment = {
|
|
3373
|
-
...attachment,
|
|
3374
|
-
localMetadata: {
|
|
3375
|
-
...attachment.localMetadata,
|
|
3376
|
-
uploadState: "uploading",
|
|
3377
|
-
...shouldTrackProgress && { uploadProgress: 0 }
|
|
3378
|
-
}
|
|
3379
|
-
};
|
|
3380
|
-
this.upsertAttachments([attachment]);
|
|
3381
|
-
const uploadOptions = shouldTrackProgress ? {
|
|
3382
|
-
onProgress: (percent) => {
|
|
3383
|
-
this.updateAttachment({
|
|
3384
|
-
...attachment,
|
|
3385
|
-
localMetadata: {
|
|
3386
|
-
...attachment.localMetadata,
|
|
3387
|
-
uploadProgress: percent
|
|
3388
|
-
}
|
|
3389
|
-
});
|
|
3390
|
-
}
|
|
3391
|
-
} : void 0;
|
|
3392
3364
|
let response;
|
|
3393
3365
|
let error;
|
|
3394
3366
|
try {
|
|
3395
|
-
response = await this.
|
|
3367
|
+
response = await this.upload(attachment);
|
|
3396
3368
|
} catch (err) {
|
|
3397
3369
|
error = err instanceof Error ? err : void 0;
|
|
3398
3370
|
}
|
|
@@ -3519,6 +3491,40 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3519
3491
|
({ localMetadata }) => localMetadata.uploadState === state
|
|
3520
3492
|
);
|
|
3521
3493
|
}
|
|
3494
|
+
upload(attachment) {
|
|
3495
|
+
const localId = attachment.localMetadata.id;
|
|
3496
|
+
this.upsertAttachments([
|
|
3497
|
+
{
|
|
3498
|
+
...attachment,
|
|
3499
|
+
localMetadata: {
|
|
3500
|
+
...attachment.localMetadata,
|
|
3501
|
+
uploadState: "uploading",
|
|
3502
|
+
uploadProgress: this.config.trackUploadProgress ? 0 : void 0
|
|
3503
|
+
}
|
|
3504
|
+
}
|
|
3505
|
+
]);
|
|
3506
|
+
const unsubscribe = this.client.uploadManager.state.subscribeWithSelector(
|
|
3507
|
+
(s) => ({ upload: s.uploads[localId] }),
|
|
3508
|
+
({ upload: nextUpload }) => {
|
|
3509
|
+
if (!nextUpload) return;
|
|
3510
|
+
this.updateAttachment({
|
|
3511
|
+
...attachment,
|
|
3512
|
+
localMetadata: {
|
|
3513
|
+
...attachment.localMetadata,
|
|
3514
|
+
uploadState: "uploading",
|
|
3515
|
+
uploadProgress: nextUpload.uploadProgress
|
|
3516
|
+
}
|
|
3517
|
+
});
|
|
3518
|
+
}
|
|
3519
|
+
);
|
|
3520
|
+
return this.client.uploadManager.upload({
|
|
3521
|
+
id: localId,
|
|
3522
|
+
channelCid: this.channel.cid,
|
|
3523
|
+
file: attachment.localMetadata.file
|
|
3524
|
+
}).finally(() => {
|
|
3525
|
+
unsubscribe();
|
|
3526
|
+
});
|
|
3527
|
+
}
|
|
3522
3528
|
};
|
|
3523
3529
|
_AttachmentManager.toLocalUploadAttachment = (fileLike) => {
|
|
3524
3530
|
const file = isFileReference(fileLike) || isFile(fileLike) ? fileLike : createFileFromBlobs({
|
|
@@ -9102,7 +9108,10 @@ var Channel = class {
|
|
|
9102
9108
|
location: { enabled: state.channel.config.shared_locations }
|
|
9103
9109
|
});
|
|
9104
9110
|
}
|
|
9105
|
-
const { messageSet } = this._initializeState(
|
|
9111
|
+
const { messageSet, filteredMessageIds } = this._initializeState(
|
|
9112
|
+
state,
|
|
9113
|
+
messageSetToAddToIfDoesNotExist
|
|
9114
|
+
);
|
|
9106
9115
|
messageSet.pagination = {
|
|
9107
9116
|
...messageSet.pagination,
|
|
9108
9117
|
...messageSetPagination({
|
|
@@ -9110,6 +9119,9 @@ var Channel = class {
|
|
|
9110
9119
|
messagePaginationOptions: options?.messages,
|
|
9111
9120
|
requestedPageSize: options?.messages?.limit ?? DEFAULT_QUERY_CHANNEL_MESSAGE_LIST_PAGE_SIZE,
|
|
9112
9121
|
returnedPage: state.messages,
|
|
9122
|
+
filteredReturnedPage: state.messages.filter(
|
|
9123
|
+
(m) => !filteredMessageIds.includes(m.id)
|
|
9124
|
+
),
|
|
9113
9125
|
logger: this.getClient().logger
|
|
9114
9126
|
})
|
|
9115
9127
|
};
|
|
@@ -9729,7 +9741,7 @@ var Channel = class {
|
|
|
9729
9741
|
if (!this.state.messages) {
|
|
9730
9742
|
this.state.initMessages();
|
|
9731
9743
|
}
|
|
9732
|
-
const { messageSet } = this.state.addMessagesSorted(
|
|
9744
|
+
const { messageSet, filteredMessageIds } = this.state.addMessagesSorted(
|
|
9733
9745
|
messages,
|
|
9734
9746
|
false,
|
|
9735
9747
|
true,
|
|
@@ -9781,7 +9793,8 @@ var Channel = class {
|
|
|
9781
9793
|
this.messageReceiptsTracker.ingestInitial(state.read);
|
|
9782
9794
|
}
|
|
9783
9795
|
return {
|
|
9784
|
-
messageSet
|
|
9796
|
+
messageSet,
|
|
9797
|
+
filteredMessageIds
|
|
9785
9798
|
};
|
|
9786
9799
|
}
|
|
9787
9800
|
_extendEventWithOwnReactions(event) {
|
|
@@ -10388,6 +10401,131 @@ var StableWSConnection = class {
|
|
|
10388
10401
|
}
|
|
10389
10402
|
};
|
|
10390
10403
|
|
|
10404
|
+
// src/uploadManager.ts
|
|
10405
|
+
var initState7 = () => ({ uploads: {} });
|
|
10406
|
+
var upsertById = (uploads, record) => ({
|
|
10407
|
+
...uploads,
|
|
10408
|
+
[record.id]: { ...uploads[record.id], ...record }
|
|
10409
|
+
});
|
|
10410
|
+
var updateById = (uploads, record) => {
|
|
10411
|
+
if (!(record.id in uploads)) return null;
|
|
10412
|
+
const current = uploads[record.id];
|
|
10413
|
+
return { ...uploads, [record.id]: { ...current, ...record } };
|
|
10414
|
+
};
|
|
10415
|
+
var UploadManager = class {
|
|
10416
|
+
constructor(client) {
|
|
10417
|
+
this.client = client;
|
|
10418
|
+
this.inFlightUploads = /* @__PURE__ */ new Map();
|
|
10419
|
+
this.getUpload = (id) => this.uploads[id];
|
|
10420
|
+
/**
|
|
10421
|
+
* Clears all upload records.
|
|
10422
|
+
* Invoked when the user disconnects so a later session does not inherit stale upload state.
|
|
10423
|
+
* Aborts every in-flight upload request via its `UploadRequestOptions.abortSignal`.
|
|
10424
|
+
*/
|
|
10425
|
+
this.reset = () => {
|
|
10426
|
+
for (const { abortController } of this.inFlightUploads.values()) {
|
|
10427
|
+
abortController.abort();
|
|
10428
|
+
}
|
|
10429
|
+
this.inFlightUploads.clear();
|
|
10430
|
+
this.state.next(initState7());
|
|
10431
|
+
};
|
|
10432
|
+
/**
|
|
10433
|
+
* Removes the upload record for `id` if present.
|
|
10434
|
+
* If an upload is still in progress, aborts its `UploadRequestOptions.abortSignal`.
|
|
10435
|
+
*/
|
|
10436
|
+
this.deleteUploadRecord = (id) => {
|
|
10437
|
+
const flight = this.inFlightUploads.get(id);
|
|
10438
|
+
if (flight) {
|
|
10439
|
+
this.inFlightUploads.delete(id);
|
|
10440
|
+
flight.abortController.abort();
|
|
10441
|
+
}
|
|
10442
|
+
this.state.next((current) => {
|
|
10443
|
+
if (!(id in current.uploads)) return current;
|
|
10444
|
+
const uploads = { ...current.uploads };
|
|
10445
|
+
delete uploads[id];
|
|
10446
|
+
return { ...current, uploads };
|
|
10447
|
+
});
|
|
10448
|
+
};
|
|
10449
|
+
/**
|
|
10450
|
+
* Starts an upload for `id`, or returns the existing in-flight promise if one is already running.
|
|
10451
|
+
* Uses {@link StreamChat.channel}(`channelCid`) → `messageComposer.attachmentManager.doUploadRequest`.
|
|
10452
|
+
* Resolves with that result; rejects if the upload rejects (the record is removed from state either way).
|
|
10453
|
+
*/
|
|
10454
|
+
this.upload = ({
|
|
10455
|
+
id,
|
|
10456
|
+
channelCid,
|
|
10457
|
+
file
|
|
10458
|
+
}) => {
|
|
10459
|
+
const existing = this.inFlightUploads.get(id);
|
|
10460
|
+
if (existing) return existing.promise;
|
|
10461
|
+
let resolvePromise;
|
|
10462
|
+
let rejectPromise;
|
|
10463
|
+
const promise = new Promise((resolve, reject) => {
|
|
10464
|
+
resolvePromise = resolve;
|
|
10465
|
+
rejectPromise = reject;
|
|
10466
|
+
});
|
|
10467
|
+
const abortController = new AbortController();
|
|
10468
|
+
this.inFlightUploads.set(id, { promise, abortController });
|
|
10469
|
+
void (async () => {
|
|
10470
|
+
const attachmentManager = this.resolveAttachmentManager(channelCid);
|
|
10471
|
+
const trackProgress = attachmentManager.config.trackUploadProgress;
|
|
10472
|
+
try {
|
|
10473
|
+
this.upsertUpload({
|
|
10474
|
+
id,
|
|
10475
|
+
uploadProgress: trackProgress ? 0 : void 0
|
|
10476
|
+
});
|
|
10477
|
+
const onProgress = trackProgress ? (progress) => {
|
|
10478
|
+
this.updateUpload({
|
|
10479
|
+
id,
|
|
10480
|
+
uploadProgress: progress
|
|
10481
|
+
});
|
|
10482
|
+
} : void 0;
|
|
10483
|
+
const uploadRequestOptions = {
|
|
10484
|
+
abortSignal: abortController.signal,
|
|
10485
|
+
...onProgress ? { onProgress } : {}
|
|
10486
|
+
};
|
|
10487
|
+
const response = await attachmentManager.doUploadRequest(
|
|
10488
|
+
file,
|
|
10489
|
+
uploadRequestOptions
|
|
10490
|
+
);
|
|
10491
|
+
resolvePromise(response);
|
|
10492
|
+
} catch (error) {
|
|
10493
|
+
rejectPromise(error);
|
|
10494
|
+
} finally {
|
|
10495
|
+
this.inFlightUploads.delete(id);
|
|
10496
|
+
this.deleteUploadRecord(id);
|
|
10497
|
+
}
|
|
10498
|
+
})();
|
|
10499
|
+
return promise;
|
|
10500
|
+
};
|
|
10501
|
+
this.upsertUpload = (record) => {
|
|
10502
|
+
this.state.partialNext({
|
|
10503
|
+
uploads: upsertById(this.uploads, record)
|
|
10504
|
+
});
|
|
10505
|
+
};
|
|
10506
|
+
this.updateUpload = (record) => {
|
|
10507
|
+
this.state.next((current) => {
|
|
10508
|
+
const nextUploads = updateById(current.uploads, record);
|
|
10509
|
+
if (!nextUploads) return current;
|
|
10510
|
+
return { ...current, uploads: nextUploads };
|
|
10511
|
+
});
|
|
10512
|
+
};
|
|
10513
|
+
this.state = new StateStore(initState7());
|
|
10514
|
+
}
|
|
10515
|
+
resolveAttachmentManager(channelCid) {
|
|
10516
|
+
const colon = channelCid.indexOf(":");
|
|
10517
|
+
if (colon <= 0 || colon === channelCid.length - 1) {
|
|
10518
|
+
throw new Error(`Invalid channelCid: ${channelCid}`);
|
|
10519
|
+
}
|
|
10520
|
+
const channelType = channelCid.slice(0, colon);
|
|
10521
|
+
const channelId = channelCid.slice(colon + 1);
|
|
10522
|
+
return this.client.channel(channelType, channelId).messageComposer.attachmentManager;
|
|
10523
|
+
}
|
|
10524
|
+
get uploads() {
|
|
10525
|
+
return this.state.getLatestValue().uploads;
|
|
10526
|
+
}
|
|
10527
|
+
};
|
|
10528
|
+
|
|
10391
10529
|
// src/signing.ts
|
|
10392
10530
|
var import_jsonwebtoken = __toESM(require_jsonwebtoken());
|
|
10393
10531
|
var import_crypto = __toESM(require_crypto());
|
|
@@ -12860,6 +12998,7 @@ var StreamChat = class _StreamChat {
|
|
|
12860
12998
|
this.activeChannels = {};
|
|
12861
12999
|
this.state = new ClientState({ client: this });
|
|
12862
13000
|
this.threads.resetState();
|
|
13001
|
+
this.uploadManager.reset();
|
|
12863
13002
|
closePromise.finally(() => {
|
|
12864
13003
|
this.tokenManager.reset();
|
|
12865
13004
|
}).catch((err) => console.error(err));
|
|
@@ -13266,6 +13405,7 @@ var StreamChat = class _StreamChat {
|
|
|
13266
13405
|
this.blockedUsers = new StateStore({ userIds: [] });
|
|
13267
13406
|
this.moderation = new Moderation(this);
|
|
13268
13407
|
this.notifications = options?.notifications ?? new NotificationManager();
|
|
13408
|
+
this.uploadManager = new UploadManager(this);
|
|
13269
13409
|
if (secretOrOptions && isString2(secretOrOptions)) {
|
|
13270
13410
|
this.secret = secretOrOptions;
|
|
13271
13411
|
}
|
|
@@ -13984,12 +14124,15 @@ var StreamChat = class _StreamChat {
|
|
|
13984
14124
|
c.initialized = !offlineMode;
|
|
13985
14125
|
c.push_preferences = channelState.push_preferences;
|
|
13986
14126
|
let updatedMessagesSet;
|
|
14127
|
+
let filteredMessageIds = [];
|
|
13987
14128
|
if (skipInitialization === void 0) {
|
|
13988
|
-
const { messageSet } = c._initializeState(channelState, "latest");
|
|
14129
|
+
const { messageSet, filteredMessageIds: _filteredMessageIds } = c._initializeState(channelState, "latest");
|
|
14130
|
+
filteredMessageIds = _filteredMessageIds;
|
|
13989
14131
|
updatedMessagesSet = messageSet;
|
|
13990
14132
|
} else if (!skipInitialization.includes(channelState.channel.id)) {
|
|
13991
14133
|
c.state.clearMessages();
|
|
13992
|
-
const { messageSet } = c._initializeState(channelState, "latest");
|
|
14134
|
+
const { messageSet, filteredMessageIds: _filteredMessageIds } = c._initializeState(channelState, "latest");
|
|
14135
|
+
filteredMessageIds = _filteredMessageIds;
|
|
13993
14136
|
updatedMessagesSet = messageSet;
|
|
13994
14137
|
}
|
|
13995
14138
|
if (updatedMessagesSet) {
|
|
@@ -13999,6 +14142,9 @@ var StreamChat = class _StreamChat {
|
|
|
13999
14142
|
parentSet: updatedMessagesSet,
|
|
14000
14143
|
requestedPageSize: queryChannelsOptions?.message_limit || DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE,
|
|
14001
14144
|
returnedPage: channelState.messages,
|
|
14145
|
+
filteredReturnedPage: channelState.messages.filter(
|
|
14146
|
+
(m) => !filteredMessageIds.includes(m.id)
|
|
14147
|
+
),
|
|
14002
14148
|
logger: this.logger
|
|
14003
14149
|
})
|
|
14004
14150
|
};
|
|
@@ -15049,7 +15195,7 @@ var StreamChat = class _StreamChat {
|
|
|
15049
15195
|
if (this.userAgent) {
|
|
15050
15196
|
return this.userAgent;
|
|
15051
15197
|
}
|
|
15052
|
-
const version = "9.
|
|
15198
|
+
const version = "9.42.0";
|
|
15053
15199
|
const clientBundle = "browser-esm";
|
|
15054
15200
|
let userAgentString = "";
|
|
15055
15201
|
if (this.sdkIdentifier) {
|
|
@@ -17738,6 +17884,7 @@ export {
|
|
|
17738
17884
|
ThreadManager,
|
|
17739
17885
|
TokenManager,
|
|
17740
17886
|
UPDATE_LIVE_LOCATION_REQUEST_MIN_THROTTLE_TIMEOUT,
|
|
17887
|
+
UploadManager,
|
|
17741
17888
|
UserFromToken,
|
|
17742
17889
|
UserSearchSource,
|
|
17743
17890
|
VALID_MAX_VOTES_VALUE_REGEX,
|