sceyt-chat-react-uikit 1.9.0-beta.7 → 1.9.0-beta.8

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.
Files changed (3) hide show
  1. package/index.js +232 -48
  2. package/index.modern.js +232 -48
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -16895,6 +16895,7 @@ var idleSnapshot = {
16895
16895
  var jobs = new Map();
16896
16896
  var snapshots = new Map();
16897
16897
  var listeners = new Map();
16898
+ var jobVersions = new Map();
16898
16899
  var notify = function notify(key) {
16899
16900
  var _listeners$get;
16900
16901
  (_listeners$get = listeners.get(key)) === null || _listeners$get === void 0 ? void 0 : _listeners$get.forEach(function (listener) {
@@ -16907,6 +16908,10 @@ var setSnapshot = function setSnapshot(key, snapshot) {
16907
16908
  if (job) job.snapshot = snapshot;
16908
16909
  notify(key);
16909
16910
  };
16911
+ var setJobSnapshot = function setJobSnapshot(key, job, snapshot) {
16912
+ if (jobVersions.get(key) !== job.version) return;
16913
+ setSnapshot(key, snapshot);
16914
+ };
16910
16915
  var normalizeProgress = function normalizeProgress(progress, fallbackTotal) {
16911
16916
  var _ref, _progress$loaded, _progress$total;
16912
16917
  if (fallbackTotal === void 0) {
@@ -16986,7 +16991,7 @@ var download = function download(request, job) {
16986
16991
  return;
16987
16992
  }
16988
16993
  var normalized = normalizeProgress(progress, request.size);
16989
- setSnapshot(request.key, _extends({
16994
+ setJobSnapshot(request.key, job, _extends({
16990
16995
  state: 'loading'
16991
16996
  }, normalized));
16992
16997
  };
@@ -17079,6 +17084,7 @@ var requestMediaDownload = function requestMediaDownload(request) {
17079
17084
  return active.promise;
17080
17085
  }
17081
17086
  var job = {
17087
+ version: (jobVersions.get(request.key) || 0) + 1,
17082
17088
  snapshot: {
17083
17089
  state: 'loading',
17084
17090
  loaded: 0,
@@ -17088,8 +17094,9 @@ var requestMediaDownload = function requestMediaDownload(request) {
17088
17094
  promise: undefined,
17089
17095
  cacheKeys: new Set([request.cacheKey].concat(request.cacheKeys || []))
17090
17096
  };
17097
+ jobVersions.set(request.key, job.version);
17091
17098
  jobs.set(request.key, job);
17092
- setSnapshot(request.key, job.snapshot);
17099
+ setJobSnapshot(request.key, job, job.snapshot);
17093
17100
  var promise = Promise.resolve().then(function () {
17094
17101
  try {
17095
17102
  var _temp5 = function _temp5(cachedResult) {
@@ -17105,7 +17112,8 @@ var requestMediaDownload = function requestMediaDownload(request) {
17105
17112
  return Promise.reject(e);
17106
17113
  }
17107
17114
  }).then(function (result) {
17108
- setSnapshot(request.key, {
17115
+ throwIfCancelled(job);
17116
+ setJobSnapshot(request.key, job, {
17109
17117
  state: 'completed',
17110
17118
  loaded: result.blob.size,
17111
17119
  total: result.blob.size,
@@ -17113,8 +17121,8 @@ var requestMediaDownload = function requestMediaDownload(request) {
17113
17121
  });
17114
17122
  return result;
17115
17123
  })["catch"](function (error) {
17116
- var cancelled = (error === null || error === void 0 ? void 0 : error.name) === 'AbortError';
17117
- setSnapshot(request.key, {
17124
+ var cancelled = job.cancelled || (error === null || error === void 0 ? void 0 : error.name) === 'AbortError';
17125
+ setJobSnapshot(request.key, job, {
17118
17126
  state: cancelled ? 'cancelled' : 'failed',
17119
17127
  loaded: 0,
17120
17128
  total: 0,
@@ -17122,7 +17130,9 @@ var requestMediaDownload = function requestMediaDownload(request) {
17122
17130
  });
17123
17131
  throw error;
17124
17132
  })["finally"](function () {
17125
- jobs["delete"](request.key);
17133
+ if (jobs.get(request.key) === job) {
17134
+ jobs["delete"](request.key);
17135
+ }
17126
17136
  });
17127
17137
  job.promise = promise;
17128
17138
  return promise;
@@ -17132,6 +17142,13 @@ var cancelMediaDownload = function cancelMediaDownload(key) {
17132
17142
  var job = jobs.get(key);
17133
17143
  if (!job) return;
17134
17144
  job.cancelled = true;
17145
+ jobs["delete"](key);
17146
+ setSnapshot(key, {
17147
+ state: 'cancelled',
17148
+ loaded: 0,
17149
+ total: 0,
17150
+ progress: 0
17151
+ });
17135
17152
  if (job.abortController) job.abortController.abort();
17136
17153
  if (job.customRequest) (_getCustomUploader = getCustomUploader()) === null || _getCustomUploader === void 0 ? void 0 : _getCustomUploader.cancelRequest(job.customRequest);
17137
17154
  };
@@ -39643,6 +39660,9 @@ var VideoIcon = styled__default.div(_templateObject0$6 || (_templateObject0$6 =
39643
39660
  });
39644
39661
 
39645
39662
  var _templateObject$t, _templateObject2$q, _templateObject3$m, _templateObject4$j, _templateObject5$g, _templateObject6$c, _templateObject7$b, _templateObject8$9, _templateObject9$8, _templateObject0$7, _templateObject1$6, _templateObject10$4, _templateObject11$3, _templateObject12$3, _templateObject13$3, _templateObject14$3, _templateObject15$2;
39663
+ var isMediaDownloadCancellation = function isMediaDownloadCancellation(error) {
39664
+ return (error === null || error === void 0 ? void 0 : error.name) === 'AbortError' || (error === null || error === void 0 ? void 0 : error.name) === 'DOWNLOAD_CANCELLED' || (error === null || error === void 0 ? void 0 : error.message) === 'DOWNLOAD_CANCELLED';
39665
+ };
39646
39666
  var Attachment = function Attachment(_ref) {
39647
39667
  var attachment = _ref.attachment,
39648
39668
  _ref$isPreview = _ref.isPreview,
@@ -39738,9 +39758,15 @@ var Attachment = function Attachment(_ref) {
39738
39758
  imageDownloadRetry = _useState0[0],
39739
39759
  setImageDownloadRetry = _useState0[1];
39740
39760
  var _useState1 = React.useState(false),
39741
- isOriginalVideoRestarting = _useState1[0],
39742
- setIsOriginalVideoRestarting = _useState1[1];
39761
+ isOriginalImageRestarting = _useState1[0],
39762
+ setIsOriginalImageRestarting = _useState1[1];
39763
+ var _useState10 = React.useState(false),
39764
+ isOriginalVideoRestarting = _useState10[0],
39765
+ setIsOriginalVideoRestarting = _useState10[1];
39743
39766
  var originalVideoDownloadStartedRef = React.useRef(false);
39767
+ var videoDownloadRequestRef = React.useRef(0);
39768
+ var imageDownloadRequestRef = React.useRef(0);
39769
+ var imageResumeStartedRef = React.useRef(false);
39744
39770
  var fileNameRef = React.useRef(null);
39745
39771
  var customDownloader = getCustomDownloader();
39746
39772
  var previewFileType = isPreview && attachment.data.type.split('/')[0];
@@ -39772,15 +39798,23 @@ var Attachment = function Attachment(_ref) {
39772
39798
  var isPreparingVideo = attachmentCompilationState[attachment.tid] === UPLOAD_STATE.PREPARING;
39773
39799
  var isSharedOriginalVideoDownloading = sharedOriginalVideoDownload.state === 'loading';
39774
39800
  var isSharedOriginalVideoCancelled = sharedOriginalVideoDownload.state === 'cancelled';
39801
+ var shouldShowVideoDownloadRetry = !isSharedOriginalVideoDownloading && !isOriginalVideoRestarting && (isSharedOriginalVideoCancelled || !originalVideoDownloadKey && downloadIsCancelled);
39775
39802
  var isVideoDownloading = downloadingFile || isSharedOriginalVideoDownloading;
39776
39803
  var isVideoDownloadActive = isVideoDownloading || isOriginalVideoRestarting;
39804
+ var shouldRenderVideoDownloadProgress = Boolean(!isRepliedMessage && !isPreview && (isInUploadingState || isVideoDownloadActive));
39777
39805
  var videoProgress = isSharedOriginalVideoDownloading ? sharedOriginalVideoDownload.progress || 3 : progress;
39778
39806
  var videoSizeProgress = isSharedOriginalVideoDownloading ? {
39779
39807
  loaded: sharedOriginalVideoDownload.loaded,
39780
39808
  total: sharedOriginalVideoDownload.total
39781
39809
  } : sizeProgress;
39782
- var isImageDownloading = downloadingFile || sharedOriginalImageDownload.state === 'loading';
39810
+ React.useEffect(function () {
39811
+ if (isSharedOriginalVideoDownloading && downloadIsCancelled) {
39812
+ setDownloadIsCancelled(false);
39813
+ }
39814
+ }, [downloadIsCancelled, isSharedOriginalVideoDownloading]);
39815
+ var isImageDownloading = downloadingFile || sharedOriginalImageDownload.state === 'loading' || isOriginalImageRestarting;
39783
39816
  var isSharedOriginalImageCancelled = sharedOriginalImageDownload.state === 'cancelled';
39817
+ var shouldShowImageDownloadRetry = !isOriginalImageRestarting && (isSharedOriginalImageCancelled || downloadIsCancelled && sharedOriginalImageDownload.state !== 'loading');
39784
39818
  var imageProgress = sharedOriginalImageDownload.state === 'loading' ? sharedOriginalImageDownload.progress || 3 : progress;
39785
39819
  var imageSizeProgress = sharedOriginalImageDownload.state === 'loading' ? {
39786
39820
  loaded: sharedOriginalImageDownload.loaded,
@@ -40127,6 +40161,9 @@ var Attachment = function Attachment(_ref) {
40127
40161
  if (attachment.type !== attachmentTypes.video) {
40128
40162
  return;
40129
40163
  }
40164
+ if (isSharedOriginalVideoCancelled) {
40165
+ return;
40166
+ }
40130
40167
  var _getVideoAttachmentCa = getVideoAttachmentCacheKeys(attachment.url, attachment.metadata),
40131
40168
  videoThumb = _getVideoAttachmentCa.videoThumb,
40132
40169
  originalVideoCacheKey = _getVideoAttachmentCa.originalVideo;
@@ -40141,11 +40178,12 @@ var Attachment = function Attachment(_ref) {
40141
40178
  return;
40142
40179
  }
40143
40180
  var cancelled = false;
40181
+ var videoDownloadRequest = videoDownloadRequestRef.current;
40144
40182
  var loadVideoThumbAndOriginal = function loadVideoThumbAndOriginal() {
40145
40183
  try {
40146
40184
  var _temp18 = function _temp18(_result2) {
40147
40185
  if (_exit) return _result2;
40148
- if (isDetailsView) return;
40186
+ if (isDetailsView && videoDownloadRetry === 0) return;
40149
40187
  return Promise.resolve(getAttachmentUrlFromCache(originalVideoCacheKey)["catch"](function () {
40150
40188
  return false;
40151
40189
  })).then(function (cachedOriginalVideo) {
@@ -40169,15 +40207,16 @@ var Attachment = function Attachment(_ref) {
40169
40207
  size: Number(attachment.size) || 0
40170
40208
  }).then(function (_ref4) {
40171
40209
  var objectUrl = _ref4.objectUrl;
40172
- if (cancelled) return;
40210
+ if (cancelled || videoDownloadRequest !== videoDownloadRequestRef.current) return;
40173
40211
  dispatch(setUpdateMessageAttachmentAC(originalVideoCacheKey, objectUrl));
40174
40212
  setAttachmentUrl(objectUrl);
40175
40213
  setIsCached(true);
40176
40214
  setDownloadIsCancelled(false);
40177
40215
  setIsOriginalVideoRestarting(false);
40178
40216
  })["catch"](function (error) {
40217
+ if (videoDownloadRequest !== videoDownloadRequestRef.current) return;
40179
40218
  setIsOriginalVideoRestarting(false);
40180
- if (!cancelled) log.error('Error downloading video attachment:', error);
40219
+ if (!cancelled && !isMediaDownloadCancellation(error)) log.error('Error downloading video attachment:', error);
40181
40220
  });
40182
40221
  });
40183
40222
  };
@@ -40206,39 +40245,107 @@ var Attachment = function Attachment(_ref) {
40206
40245
  return function () {
40207
40246
  cancelled = true;
40208
40247
  };
40209
- }, [attachment.id, attachment.type, attachment.url, attachment.metadata, attachment.attachmentUrl, isDetailsView, originalVideoUrlFromMap, connectionStatus, dispatch, messageType, attachment.size, videoDownloadRetry]);
40248
+ }, [attachment.id, attachment.type, attachment.url, attachment.metadata, attachment.attachmentUrl, isDetailsView, originalVideoUrlFromMap, connectionStatus, dispatch, messageType, attachment.size, videoDownloadRetry, isSharedOriginalVideoCancelled]);
40210
40249
  var handleResumeOriginalVideoDownload = function handleResumeOriginalVideoDownload(event) {
40211
40250
  event.stopPropagation();
40251
+ if (!attachment.url) return;
40252
+ var _getVideoAttachmentCa2 = getVideoAttachmentCacheKeys(attachment.url, attachment.metadata),
40253
+ originalVideoCacheKey = _getVideoAttachmentCa2.originalVideo;
40254
+ var videoDownloadRequest = videoDownloadRequestRef.current + 1;
40255
+ videoDownloadRequestRef.current = videoDownloadRequest;
40212
40256
  originalVideoDownloadStartedRef.current = false;
40213
40257
  setDownloadIsCancelled(false);
40214
40258
  setIsOriginalVideoRestarting(true);
40215
40259
  setVideoDownloadRetry(function (retry) {
40216
40260
  return retry + 1;
40217
40261
  });
40262
+ originalVideoDownloadStartedRef.current = true;
40263
+ requestMediaDownload({
40264
+ key: "original-video:" + attachment.url,
40265
+ url: attachment.url,
40266
+ cacheKey: originalVideoCacheKey,
40267
+ kind: 'original-video',
40268
+ messageType: messageType,
40269
+ size: Number(attachment.size) || 0
40270
+ }).then(function (_ref5) {
40271
+ var objectUrl = _ref5.objectUrl;
40272
+ if (videoDownloadRequest !== videoDownloadRequestRef.current) return;
40273
+ dispatch(setUpdateMessageAttachmentAC(originalVideoCacheKey, objectUrl));
40274
+ setAttachmentUrl(objectUrl);
40275
+ setIsCached(true);
40276
+ setDownloadIsCancelled(false);
40277
+ setIsOriginalVideoRestarting(false);
40278
+ })["catch"](function (error) {
40279
+ if (videoDownloadRequest !== videoDownloadRequestRef.current) return;
40280
+ setIsOriginalVideoRestarting(false);
40281
+ if (!isMediaDownloadCancellation(error)) log.error('Error restarting video attachment download:', error);
40282
+ });
40218
40283
  };
40219
40284
  var handleResumeOriginalImageDownload = function handleResumeOriginalImageDownload(event) {
40220
40285
  event.stopPropagation();
40286
+ if (!attachment.url) return;
40287
+ var imageDownloadRequest = imageDownloadRequestRef.current + 1;
40288
+ imageDownloadRequestRef.current = imageDownloadRequest;
40289
+ imageResumeStartedRef.current = true;
40221
40290
  setDownloadIsCancelled(false);
40291
+ setIsOriginalImageRestarting(true);
40222
40292
  setImageDownloadRetry(function (retry) {
40223
40293
  return retry + 1;
40224
40294
  });
40295
+ requestMediaDownload({
40296
+ key: "original-image:" + attachment.url,
40297
+ url: attachment.url,
40298
+ cacheKey: attachment.url,
40299
+ cacheKeys: [attachment.url + '_original_image_url'],
40300
+ kind: 'original-image',
40301
+ messageType: messageType,
40302
+ size: Number(attachment.size) || 0
40303
+ }).then(function (_ref6) {
40304
+ var objectUrl = _ref6.objectUrl;
40305
+ try {
40306
+ if (imageDownloadRequest !== imageDownloadRequestRef.current) return Promise.resolve();
40307
+ return Promise.resolve(compressAndCacheImage(objectUrl, attachment.url, renderWidth, renderHeight)).then(function (compressedUrl) {
40308
+ if (imageDownloadRequest !== imageDownloadRequestRef.current) return;
40309
+ var displayedUrl = compressedUrl || objectUrl;
40310
+ setAttachmentUrl(displayedUrl);
40311
+ dispatch(setUpdateMessageAttachmentAC(attachment.url, displayedUrl));
40312
+ dispatch(setUpdateMessageAttachmentAC(attachment.url + '_original_image_url', objectUrl));
40313
+ setIsCached(true);
40314
+ setDownloadIsCancelled(false);
40315
+ setIsOriginalImageRestarting(false);
40316
+ imageResumeStartedRef.current = false;
40317
+ });
40318
+ } catch (e) {
40319
+ return Promise.reject(e);
40320
+ }
40321
+ })["catch"](function (error) {
40322
+ if (imageDownloadRequest !== imageDownloadRequestRef.current) return;
40323
+ imageResumeStartedRef.current = false;
40324
+ setIsOriginalImageRestarting(false);
40325
+ log.error('Error restarting image attachment download:', error);
40326
+ });
40225
40327
  };
40226
40328
  var handleCancelOriginalVideoDownload = function handleCancelOriginalVideoDownload(event) {
40227
40329
  event.stopPropagation();
40228
40330
  if (isSharedOriginalVideoDownloading && originalVideoDownloadKey) {
40229
- cancelMediaDownload(originalVideoDownloadKey);
40230
- originalVideoDownloadStartedRef.current = false;
40331
+ videoDownloadRequestRef.current += 1;
40231
40332
  setDownloadIsCancelled(true);
40232
40333
  setIsOriginalVideoRestarting(false);
40334
+ cancelMediaDownload(originalVideoDownloadKey);
40335
+ originalVideoDownloadStartedRef.current = false;
40233
40336
  return;
40234
40337
  }
40235
40338
  handleStopStartDownloadFile();
40236
40339
  };
40237
40340
  React.useEffect(function () {
40341
+ if (imageResumeStartedRef.current) return;
40342
+ if (isSharedOriginalImageCancelled) return;
40238
40343
  if (!attachment.attachmentUrl && connectionStatus === CONNECTION_STATUS.CONNECTED && attachment.id && !attachmentUrlFromMap && attachment.type !== attachmentTypes.video && !(attachment.type === attachmentTypes.file || attachment.type === attachmentTypes.link)) {
40239
40344
  var requestAttachmentKey = attachmentKey;
40345
+ var imageDownloadRequest = imageDownloadRequestRef.current;
40240
40346
  getAttachmentUrlFromCache(attachment.url).then(function (cachedUrl) {
40241
40347
  try {
40348
+ if (imageDownloadRequest !== imageDownloadRequestRef.current) return Promise.resolve();
40242
40349
  if (attachment.type === attachmentTypes.image && !isPreview) {
40243
40350
  if (cachedUrl) {
40244
40351
  setAttachmentUrl(cachedUrl);
@@ -40254,23 +40361,27 @@ var Attachment = function Attachment(_ref) {
40254
40361
  kind: 'original-image',
40255
40362
  messageType: messageType,
40256
40363
  size: Number(attachment.size) || 0
40257
- }).then(function (_ref5) {
40258
- var objectUrl = _ref5.objectUrl;
40364
+ }).then(function (_ref7) {
40365
+ var objectUrl = _ref7.objectUrl;
40259
40366
  try {
40260
- if (requestAttachmentKey !== currentAttachmentKeyRef.current) return Promise.resolve();
40367
+ if (requestAttachmentKey !== currentAttachmentKeyRef.current || imageDownloadRequest !== imageDownloadRequestRef.current) return Promise.resolve();
40261
40368
  return Promise.resolve(compressAndCacheImage(objectUrl, attachment.url, renderWidth, renderHeight)).then(function (compressedUrl) {
40262
- if (requestAttachmentKey !== currentAttachmentKeyRef.current) return;
40369
+ if (requestAttachmentKey !== currentAttachmentKeyRef.current || imageDownloadRequest !== imageDownloadRequestRef.current) return;
40263
40370
  var displayedUrl = compressedUrl || objectUrl;
40264
40371
  setAttachmentUrl(displayedUrl);
40265
40372
  dispatch(setUpdateMessageAttachmentAC(attachment.url, displayedUrl));
40266
40373
  dispatch(setUpdateMessageAttachmentAC(attachment.url + '_original_image_url', objectUrl));
40267
40374
  setIsCached(true);
40375
+ setIsOriginalImageRestarting(false);
40268
40376
  });
40269
40377
  } catch (e) {
40270
40378
  return Promise.reject(e);
40271
40379
  }
40272
40380
  })["catch"](function (error) {
40273
- if (requestAttachmentKey === currentAttachmentKeyRef.current) {
40381
+ if (imageDownloadRequest === imageDownloadRequestRef.current) {
40382
+ setIsOriginalImageRestarting(false);
40383
+ }
40384
+ if (requestAttachmentKey === currentAttachmentKeyRef.current && imageDownloadRequest === imageDownloadRequestRef.current) {
40274
40385
  log.error('Error downloading image attachment:', error);
40275
40386
  }
40276
40387
  });
@@ -40289,8 +40400,8 @@ var Attachment = function Attachment(_ref) {
40289
40400
  kind: kind,
40290
40401
  messageType: messageType,
40291
40402
  size: Number(attachment.size) || 0
40292
- }).then(function (_ref6) {
40293
- var objectUrl = _ref6.objectUrl;
40403
+ }).then(function (_ref8) {
40404
+ var objectUrl = _ref8.objectUrl;
40294
40405
  if (requestAttachmentKey !== currentAttachmentKeyRef.current) return;
40295
40406
  setAttachmentUrl(objectUrl);
40296
40407
  dispatch(setUpdateMessageAttachmentAC(attachment.url, objectUrl));
@@ -40350,7 +40461,7 @@ var Attachment = function Attachment(_ref) {
40350
40461
  }
40351
40462
  });
40352
40463
  }
40353
- }, [imageDownloadRetry]);
40464
+ }, [imageDownloadRetry, isSharedOriginalImageCancelled]);
40354
40465
  useDidUpdate(function () {
40355
40466
  if (connectionStatus === CONNECTION_STATUS.CONNECTED && isInUploadingState) {
40356
40467
  setFailTimeout(setTimeout(function () {
@@ -40422,7 +40533,7 @@ var Attachment = function Attachment(_ref) {
40422
40533
  })), attachment.type === attachmentTypes.image ? (/*#__PURE__*/React__default.createElement(AttachmentImgCont, {
40423
40534
  draggable: false,
40424
40535
  onClick: function onClick() {
40425
- return handleMediaItemClick && !isInUploadingState && !isSharedOriginalImageCancelled && handleMediaItemClick(attachment);
40536
+ return handleMediaItemClick && !isInUploadingState && !isImageDownloading && !shouldShowImageDownloadRetry && handleMediaItemClick(attachment);
40426
40537
  },
40427
40538
  isPreview: isPreview,
40428
40539
  ref: imageContRef,
@@ -40483,15 +40594,18 @@ var Attachment = function Attachment(_ref) {
40483
40594
  }, isInUploadingState ? (/*#__PURE__*/React__default.createElement(CancelResumeWrapper, {
40484
40595
  onClick: handlePauseResumeUpload
40485
40596
  }, attachmentCompilationState[attachment.tid] === UPLOAD_STATE.UPLOADING ? (/*#__PURE__*/React__default.createElement(SvgCancel, null)) : (/*#__PURE__*/React__default.createElement(SvgUpload, null)))) : !isCached && (/*#__PURE__*/React__default.createElement(CancelResumeWrapper, {
40597
+ "aria-label": 'Cancel image download',
40486
40598
  onClick: function onClick(e) {
40487
40599
  e.stopPropagation();
40488
40600
  if (sharedOriginalImageDownload.state === 'loading' && originalImageDownloadKey) {
40601
+ setDownloadIsCancelled(true);
40602
+ setIsOriginalImageRestarting(false);
40489
40603
  cancelMediaDownload(originalImageDownloadKey);
40490
40604
  } else {
40491
40605
  handlePauseResumeDownload(e.nativeEvent);
40492
40606
  }
40493
40607
  }
40494
- }, downloadIsCancelled ? /*#__PURE__*/React__default.createElement(SvgDownload, null) : /*#__PURE__*/React__default.createElement(SvgCancel, null))), (isImageDownloading || attachmentCompilationState[attachment.tid] === UPLOAD_STATE.UPLOADING) && (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(ProgressWrapper, null, /*#__PURE__*/React__default.createElement(reactCircularProgressbar.CircularProgressbar, {
40608
+ }, shouldShowImageDownloadRetry ? /*#__PURE__*/React__default.createElement(SvgDownload, null) : /*#__PURE__*/React__default.createElement(SvgCancel, null))), (isImageDownloading || attachmentCompilationState[attachment.tid] === UPLOAD_STATE.UPLOADING) && (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(ProgressWrapper, null, /*#__PURE__*/React__default.createElement(reactCircularProgressbar.CircularProgressbar, {
40495
40609
  minValue: 0,
40496
40610
  maxValue: 100,
40497
40611
  value: imageProgress,
@@ -40513,7 +40627,7 @@ var Attachment = function Attachment(_ref) {
40513
40627
  }
40514
40628
  })), imageSizeProgress && (/*#__PURE__*/React__default.createElement(SizeProgress, {
40515
40629
  color: textOnPrimary
40516
- }, bytesToSize(imageSizeProgress.loaded, 1), " / ", bytesToSize(imageSizeProgress.total, 1))))))))) : null, isSharedOriginalImageCancelled && !isPreview && !isRepliedMessage && (/*#__PURE__*/React__default.createElement(UploadProgress, {
40630
+ }, bytesToSize(imageSizeProgress.loaded, 1), " / ", bytesToSize(imageSizeProgress.total, 1))))))))) : null, shouldShowImageDownloadRetry && !isPreview && !isRepliedMessage && (/*#__PURE__*/React__default.createElement(UploadProgress, {
40517
40631
  backgroundImage: !attachmentUrlFromMap ? attachmentThumb : '',
40518
40632
  isRepliedMessage: isRepliedMessage,
40519
40633
  width: renderWidth,
@@ -40531,7 +40645,8 @@ var Attachment = function Attachment(_ref) {
40531
40645
  isDetailsView: isDetailsView,
40532
40646
  backgroundColor: overlayBackground2
40533
40647
  }, /*#__PURE__*/React__default.createElement(CancelResumeWrapper, {
40534
- onClick: handleResumeOriginalImageDownload
40648
+ onClick: handleResumeOriginalImageDownload,
40649
+ "aria-label": 'Download image'
40535
40650
  }, /*#__PURE__*/React__default.createElement(SvgDownload, null))))), isPreview && (/*#__PURE__*/React__default.createElement(RemoveChosenFile, {
40536
40651
  "$backgroundColor": background,
40537
40652
  color: iconInactive,
@@ -40540,10 +40655,10 @@ var Attachment = function Attachment(_ref) {
40540
40655
  }
40541
40656
  })))) : attachment.type === attachmentTypes.video ? (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, !isPreview ? (/*#__PURE__*/React__default.createElement(VideoCont, {
40542
40657
  onClick: function onClick() {
40543
- return handleMediaItemClick && !isVideoDownloadActive && !isSharedOriginalVideoCancelled && !isInUploadingState && (attachmentCompilationState[attachment.tid] ? attachmentCompilationState[attachment.tid] !== UPLOAD_STATE.FAIL || attachmentCompilationState[attachment.tid] !== UPLOAD_STATE.UPLOADING : true) && handleMediaItemClick(attachment);
40658
+ return handleMediaItemClick && !isVideoDownloadActive && !shouldShowVideoDownloadRetry && !isInUploadingState && (attachmentCompilationState[attachment.tid] ? attachmentCompilationState[attachment.tid] !== UPLOAD_STATE.FAIL || attachmentCompilationState[attachment.tid] !== UPLOAD_STATE.UPLOADING : true) && handleMediaItemClick(attachment);
40544
40659
  },
40545
40660
  isDetailsView: isDetailsView
40546
- }, (isInUploadingState || isVideoDownloadActive) && !isRepliedMessage && !isPreview ? (/*#__PURE__*/React__default.createElement(UploadProgress, {
40661
+ }, shouldRenderVideoDownloadProgress ? (/*#__PURE__*/React__default.createElement(UploadProgress, {
40547
40662
  isDetailsView: isDetailsView,
40548
40663
  isRepliedMessage: isRepliedMessage,
40549
40664
  withPrefix: downloadedVideoPreviewImage ? false : withPrefix,
@@ -40561,8 +40676,9 @@ var Attachment = function Attachment(_ref) {
40561
40676
  }, isInUploadingState ? (/*#__PURE__*/React__default.createElement(CancelResumeWrapper, {
40562
40677
  onClick: handlePauseResumeUpload
40563
40678
  }, attachmentCompilationState[attachment.tid] === UPLOAD_STATE.UPLOADING || isPreparingVideo ? (/*#__PURE__*/React__default.createElement(SvgCancel, null)) : (/*#__PURE__*/React__default.createElement(SvgUpload, null)))) : (/*#__PURE__*/React__default.createElement(CancelResumeWrapper, {
40564
- onClick: handleCancelOriginalVideoDownload
40565
- }, downloadIsCancelled ? /*#__PURE__*/React__default.createElement(SvgDownload, null) : /*#__PURE__*/React__default.createElement(SvgCancel, null))), (isPreparingVideo || attachmentCompilationState[attachment.tid] === UPLOAD_STATE.UPLOADING || isVideoDownloadActive && !downloadIsCancelled) && (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(ProgressWrapper, null, /*#__PURE__*/React__default.createElement(reactCircularProgressbar.CircularProgressbar, {
40679
+ onClick: handleCancelOriginalVideoDownload,
40680
+ "aria-label": 'Cancel video download'
40681
+ }, shouldShowVideoDownloadRetry ? /*#__PURE__*/React__default.createElement(SvgDownload, null) : /*#__PURE__*/React__default.createElement(SvgCancel, null))), (isPreparingVideo || attachmentCompilationState[attachment.tid] === UPLOAD_STATE.UPLOADING || isVideoDownloadActive && !downloadIsCancelled) && (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(ProgressWrapper, null, /*#__PURE__*/React__default.createElement(reactCircularProgressbar.CircularProgressbar, {
40566
40682
  minValue: 0,
40567
40683
  maxValue: 100,
40568
40684
  value: isPreparingVideo ? 3 : videoProgress,
@@ -40584,7 +40700,7 @@ var Attachment = function Attachment(_ref) {
40584
40700
  }
40585
40701
  })), videoSizeProgress && !isRepliedMessage && (/*#__PURE__*/React__default.createElement(SizeProgress, {
40586
40702
  color: textOnPrimary
40587
- }, bytesToSize(isPreparingVideo ? 0 : videoSizeProgress.loaded, 1), " /", ' ', bytesToSize(videoSizeProgress.total, 1)))))))) : null, isSharedOriginalVideoCancelled && !isRepliedMessage && !isPreview && (/*#__PURE__*/React__default.createElement(UploadProgress, {
40703
+ }, bytesToSize(isPreparingVideo ? 0 : videoSizeProgress.loaded, 1), " /", ' ', bytesToSize(videoSizeProgress.total, 1)))))))) : null, shouldShowVideoDownloadRetry && !isRepliedMessage && !isPreview && (/*#__PURE__*/React__default.createElement(UploadProgress, {
40588
40704
  isDetailsView: isDetailsView,
40589
40705
  isRepliedMessage: isRepliedMessage,
40590
40706
  withPrefix: downloadedVideoPreviewImage ? false : withPrefix,
@@ -40600,12 +40716,13 @@ var Attachment = function Attachment(_ref) {
40600
40716
  isDetailsView: isDetailsView,
40601
40717
  backgroundColor: overlayBackground2
40602
40718
  }, /*#__PURE__*/React__default.createElement(CancelResumeWrapper, {
40603
- onClick: handleResumeOriginalVideoDownload
40719
+ onClick: handleResumeOriginalVideoDownload,
40720
+ "aria-label": 'Download video'
40604
40721
  }, /*#__PURE__*/React__default.createElement(SvgDownload, null))))), /*#__PURE__*/React__default.createElement(VideoPreview, {
40605
40722
  onlyVideoImage: onlyVideoImage,
40606
40723
  width: isRepliedMessage ? '40px' : isDetailsView ? '100%' : (renderWidth || videoAttachmentMaxWidth || 420) + "px",
40607
40724
  height: isRepliedMessage ? '40px' : isDetailsView ? '100%' : (renderHeight || videoAttachmentMaxHeight || 240) + "px",
40608
- downloading: isVideoDownloadActive || isSharedOriginalVideoCancelled,
40725
+ downloading: isVideoDownloadActive || shouldShowVideoDownloadRetry,
40609
40726
  file: attachment,
40610
40727
  messageType: messageType,
40611
40728
  src: attachmentUrlFromMap || attachment.attachmentUrl || attachmentUrl,
@@ -40846,7 +40963,7 @@ var AttachmentImg = styled__default.img(_templateObject13$3 || (_templateObject1
40846
40963
  }, function (props) {
40847
40964
  return props.$fadeIn && styled.css(_templateObject14$3 || (_templateObject14$3 = _taggedTemplateLiteralLoose(["\n opacity: 0;\n animation: ", " 100ms ease-in-out forwards;\n "])), mediaCrossFade);
40848
40965
  });
40849
- var VideoCont = styled__default.div(_templateObject15$2 || (_templateObject15$2 = _taggedTemplateLiteralLoose(["\n position: relative;\n cursor: pointer;\n height: ", ";\n"])), function (props) {
40966
+ var VideoCont = styled__default.div(_templateObject15$2 || (_templateObject15$2 = _taggedTemplateLiteralLoose(["\n position: relative;\n cursor: pointer;\n width: 100%;\n height: ", ";\n"])), function (props) {
40850
40967
  return props.isDetailsView && '100%';
40851
40968
  });
40852
40969
 
@@ -59307,8 +59424,76 @@ var DisappearingMessagesStatus = styled__default.span(_templateObject19$4 || (_t
59307
59424
  var ChevronRightIconWrapper$1 = styled__default.span(_templateObject20$4 || (_templateObject20$4 = _taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n\n & > svg {\n width: 16px;\n height: 16px;\n transform: rotate(-90deg);\n }\n"])));
59308
59425
 
59309
59426
  var _templateObject$11, _templateObject2$Z, _templateObject3$P, _templateObject4$H, _templateObject5$D, _templateObject6$y, _templateObject7$v, _templateObject8$s, _templateObject9$n, _templateObject0$l;
59310
- var Media = function Media(_ref) {
59311
- var channel = _ref.channel;
59427
+ var startMediaVideoDownload = function startMediaVideoDownload(file) {
59428
+ if (file.type !== 'video' || !file.url) return;
59429
+ var _getVideoAttachmentCa = getVideoAttachmentCacheKeys(file.url, file.metadata),
59430
+ originalVideo = _getVideoAttachmentCa.originalVideo;
59431
+ return requestMediaDownload({
59432
+ key: "original-video:" + file.url,
59433
+ url: file.url,
59434
+ cacheKey: originalVideo,
59435
+ kind: 'original-video',
59436
+ size: Number(file.size) || 0
59437
+ });
59438
+ };
59439
+ var MediaTile = function MediaTile(_ref) {
59440
+ var file = _ref.file,
59441
+ background = _ref.background,
59442
+ onOpen = _ref.onOpen;
59443
+ var elementRef = React.useRef(null);
59444
+ var downloadStartedRef = React.useRef(false);
59445
+ var dispatch = useDispatch();
59446
+ React.useEffect(function () {
59447
+ if (file.type !== 'video' || !file.url || downloadStartedRef.current) return;
59448
+ var startDownload = function startDownload() {
59449
+ var _startMediaVideoDownl;
59450
+ if (downloadStartedRef.current) return;
59451
+ if (getMediaDownloadSnapshot("original-video:" + file.url).state === 'cancelled') return;
59452
+ downloadStartedRef.current = true;
59453
+ var _getVideoAttachmentCa2 = getVideoAttachmentCacheKeys(file.url, file.metadata),
59454
+ originalVideo = _getVideoAttachmentCa2.originalVideo;
59455
+ (_startMediaVideoDownl = startMediaVideoDownload(file)) === null || _startMediaVideoDownl === void 0 ? void 0 : _startMediaVideoDownl.then(function (_ref2) {
59456
+ var objectUrl = _ref2.objectUrl;
59457
+ dispatch(setUpdateMessageAttachmentAC(originalVideo, objectUrl));
59458
+ })["catch"](function (error) {
59459
+ log.error('Failed to start media-tab video download:', error);
59460
+ });
59461
+ };
59462
+ var element = elementRef.current;
59463
+ if (!element) return;
59464
+ if (typeof IntersectionObserver === 'undefined') {
59465
+ startDownload();
59466
+ return;
59467
+ }
59468
+ var observer = new IntersectionObserver(function (entries) {
59469
+ if (entries.some(function (entry) {
59470
+ return entry.isIntersecting;
59471
+ })) {
59472
+ startDownload();
59473
+ observer.disconnect();
59474
+ }
59475
+ }, {
59476
+ rootMargin: '200px 0px'
59477
+ });
59478
+ observer.observe(element);
59479
+ return function () {
59480
+ return observer.disconnect();
59481
+ };
59482
+ }, [dispatch, file.id, file.type, file.url, file.metadata, file.size]);
59483
+ return /*#__PURE__*/React__default.createElement(MediaItem, {
59484
+ ref: elementRef
59485
+ }, /*#__PURE__*/React__default.createElement(Attachment$1, {
59486
+ attachment: _extends({}, file, {
59487
+ metadata: isJSON(file.metadata) ? JSON.parse(file.metadata) : file.metadata
59488
+ }),
59489
+ handleMediaItemClick: onOpen,
59490
+ backgroundColor: background,
59491
+ borderRadius: '8px',
59492
+ isDetailsView: true
59493
+ }));
59494
+ };
59495
+ var Media = function Media(_ref3) {
59496
+ var channel = _ref3.channel;
59312
59497
  var _useColor = useColors(),
59313
59498
  background = _useColor[THEME_COLORS.BACKGROUND],
59314
59499
  textSecondary = _useColor[THEME_COLORS.TEXT_SECONDARY],
@@ -59327,6 +59512,10 @@ var Media = function Media(_ref) {
59327
59512
  resource: typeof (file === null || file === void 0 ? void 0 : file.url) === 'string' ? file.url.split(/[?#]/)[0] : null
59328
59513
  }));
59329
59514
  if (file !== null && file !== void 0 && file.id) {
59515
+ var _startMediaVideoDownl2;
59516
+ (_startMediaVideoDownl2 = startMediaVideoDownload(file)) === null || _startMediaVideoDownl2 === void 0 ? void 0 : _startMediaVideoDownl2["catch"](function (error) {
59517
+ log.error('Failed to start media-tab video download:', error);
59518
+ });
59330
59519
  dispatch(setAttachmentsForPopupAC([file]));
59331
59520
  setMediaFile(file);
59332
59521
  log.info('[MEDIA_IMAGE_SLIDER] slider state requested ' + JSON.stringify({
@@ -59379,17 +59568,12 @@ var Media = function Media(_ref) {
59379
59568
  month: 'long',
59380
59569
  year: 'numeric'
59381
59570
  })), /*#__PURE__*/React__default.createElement(ItemsGrid, null, group.items.map(function (file, index) {
59382
- return /*#__PURE__*/React__default.createElement(MediaItem, {
59383
- key: file.id || file.messageId + "_" + index
59384
- }, /*#__PURE__*/React__default.createElement(Attachment$1, {
59385
- attachment: _extends({}, file, {
59386
- metadata: isJSON(file.metadata) ? JSON.parse(file.metadata) : file.metadata
59387
- }),
59388
- handleMediaItemClick: handleMediaItemClick,
59389
- backgroundColor: background,
59390
- borderRadius: '8px',
59391
- isDetailsView: true
59392
- }));
59571
+ return /*#__PURE__*/React__default.createElement(MediaTile, {
59572
+ key: file.id || file.messageId + "_" + index,
59573
+ file: file,
59574
+ background: background,
59575
+ onOpen: handleMediaItemClick
59576
+ });
59393
59577
  })));
59394
59578
  }), loadingState === LOADING_STATE.LOADING && (/*#__PURE__*/React__default.createElement(SkeletonGrid, null, Array.from({
59395
59579
  length: 3
package/index.modern.js CHANGED
@@ -16875,6 +16875,7 @@ var idleSnapshot = {
16875
16875
  var jobs = new Map();
16876
16876
  var snapshots = new Map();
16877
16877
  var listeners = new Map();
16878
+ var jobVersions = new Map();
16878
16879
  var notify = function notify(key) {
16879
16880
  var _listeners$get;
16880
16881
  (_listeners$get = listeners.get(key)) === null || _listeners$get === void 0 ? void 0 : _listeners$get.forEach(function (listener) {
@@ -16887,6 +16888,10 @@ var setSnapshot = function setSnapshot(key, snapshot) {
16887
16888
  if (job) job.snapshot = snapshot;
16888
16889
  notify(key);
16889
16890
  };
16891
+ var setJobSnapshot = function setJobSnapshot(key, job, snapshot) {
16892
+ if (jobVersions.get(key) !== job.version) return;
16893
+ setSnapshot(key, snapshot);
16894
+ };
16890
16895
  var normalizeProgress = function normalizeProgress(progress, fallbackTotal) {
16891
16896
  var _ref, _progress$loaded, _progress$total;
16892
16897
  if (fallbackTotal === void 0) {
@@ -16966,7 +16971,7 @@ var download = function download(request, job) {
16966
16971
  return;
16967
16972
  }
16968
16973
  var normalized = normalizeProgress(progress, request.size);
16969
- setSnapshot(request.key, _extends({
16974
+ setJobSnapshot(request.key, job, _extends({
16970
16975
  state: 'loading'
16971
16976
  }, normalized));
16972
16977
  };
@@ -17059,6 +17064,7 @@ var requestMediaDownload = function requestMediaDownload(request) {
17059
17064
  return active.promise;
17060
17065
  }
17061
17066
  var job = {
17067
+ version: (jobVersions.get(request.key) || 0) + 1,
17062
17068
  snapshot: {
17063
17069
  state: 'loading',
17064
17070
  loaded: 0,
@@ -17068,8 +17074,9 @@ var requestMediaDownload = function requestMediaDownload(request) {
17068
17074
  promise: undefined,
17069
17075
  cacheKeys: new Set([request.cacheKey].concat(request.cacheKeys || []))
17070
17076
  };
17077
+ jobVersions.set(request.key, job.version);
17071
17078
  jobs.set(request.key, job);
17072
- setSnapshot(request.key, job.snapshot);
17079
+ setJobSnapshot(request.key, job, job.snapshot);
17073
17080
  var promise = Promise.resolve().then(function () {
17074
17081
  try {
17075
17082
  var _temp5 = function _temp5(cachedResult) {
@@ -17085,7 +17092,8 @@ var requestMediaDownload = function requestMediaDownload(request) {
17085
17092
  return Promise.reject(e);
17086
17093
  }
17087
17094
  }).then(function (result) {
17088
- setSnapshot(request.key, {
17095
+ throwIfCancelled(job);
17096
+ setJobSnapshot(request.key, job, {
17089
17097
  state: 'completed',
17090
17098
  loaded: result.blob.size,
17091
17099
  total: result.blob.size,
@@ -17093,8 +17101,8 @@ var requestMediaDownload = function requestMediaDownload(request) {
17093
17101
  });
17094
17102
  return result;
17095
17103
  })["catch"](function (error) {
17096
- var cancelled = (error === null || error === void 0 ? void 0 : error.name) === 'AbortError';
17097
- setSnapshot(request.key, {
17104
+ var cancelled = job.cancelled || (error === null || error === void 0 ? void 0 : error.name) === 'AbortError';
17105
+ setJobSnapshot(request.key, job, {
17098
17106
  state: cancelled ? 'cancelled' : 'failed',
17099
17107
  loaded: 0,
17100
17108
  total: 0,
@@ -17102,7 +17110,9 @@ var requestMediaDownload = function requestMediaDownload(request) {
17102
17110
  });
17103
17111
  throw error;
17104
17112
  })["finally"](function () {
17105
- jobs["delete"](request.key);
17113
+ if (jobs.get(request.key) === job) {
17114
+ jobs["delete"](request.key);
17115
+ }
17106
17116
  });
17107
17117
  job.promise = promise;
17108
17118
  return promise;
@@ -17112,6 +17122,13 @@ var cancelMediaDownload = function cancelMediaDownload(key) {
17112
17122
  var job = jobs.get(key);
17113
17123
  if (!job) return;
17114
17124
  job.cancelled = true;
17125
+ jobs["delete"](key);
17126
+ setSnapshot(key, {
17127
+ state: 'cancelled',
17128
+ loaded: 0,
17129
+ total: 0,
17130
+ progress: 0
17131
+ });
17115
17132
  if (job.abortController) job.abortController.abort();
17116
17133
  if (job.customRequest) (_getCustomUploader = getCustomUploader()) === null || _getCustomUploader === void 0 ? void 0 : _getCustomUploader.cancelRequest(job.customRequest);
17117
17134
  };
@@ -39623,6 +39640,9 @@ var VideoIcon = styled.div(_templateObject0$6 || (_templateObject0$6 = _taggedTe
39623
39640
  });
39624
39641
 
39625
39642
  var _templateObject$t, _templateObject2$q, _templateObject3$m, _templateObject4$j, _templateObject5$g, _templateObject6$c, _templateObject7$b, _templateObject8$9, _templateObject9$8, _templateObject0$7, _templateObject1$6, _templateObject10$4, _templateObject11$3, _templateObject12$3, _templateObject13$3, _templateObject14$3, _templateObject15$2;
39643
+ var isMediaDownloadCancellation = function isMediaDownloadCancellation(error) {
39644
+ return (error === null || error === void 0 ? void 0 : error.name) === 'AbortError' || (error === null || error === void 0 ? void 0 : error.name) === 'DOWNLOAD_CANCELLED' || (error === null || error === void 0 ? void 0 : error.message) === 'DOWNLOAD_CANCELLED';
39645
+ };
39626
39646
  var Attachment = function Attachment(_ref) {
39627
39647
  var attachment = _ref.attachment,
39628
39648
  _ref$isPreview = _ref.isPreview,
@@ -39718,9 +39738,15 @@ var Attachment = function Attachment(_ref) {
39718
39738
  imageDownloadRetry = _useState0[0],
39719
39739
  setImageDownloadRetry = _useState0[1];
39720
39740
  var _useState1 = useState(false),
39721
- isOriginalVideoRestarting = _useState1[0],
39722
- setIsOriginalVideoRestarting = _useState1[1];
39741
+ isOriginalImageRestarting = _useState1[0],
39742
+ setIsOriginalImageRestarting = _useState1[1];
39743
+ var _useState10 = useState(false),
39744
+ isOriginalVideoRestarting = _useState10[0],
39745
+ setIsOriginalVideoRestarting = _useState10[1];
39723
39746
  var originalVideoDownloadStartedRef = useRef(false);
39747
+ var videoDownloadRequestRef = useRef(0);
39748
+ var imageDownloadRequestRef = useRef(0);
39749
+ var imageResumeStartedRef = useRef(false);
39724
39750
  var fileNameRef = useRef(null);
39725
39751
  var customDownloader = getCustomDownloader();
39726
39752
  var previewFileType = isPreview && attachment.data.type.split('/')[0];
@@ -39752,15 +39778,23 @@ var Attachment = function Attachment(_ref) {
39752
39778
  var isPreparingVideo = attachmentCompilationState[attachment.tid] === UPLOAD_STATE.PREPARING;
39753
39779
  var isSharedOriginalVideoDownloading = sharedOriginalVideoDownload.state === 'loading';
39754
39780
  var isSharedOriginalVideoCancelled = sharedOriginalVideoDownload.state === 'cancelled';
39781
+ var shouldShowVideoDownloadRetry = !isSharedOriginalVideoDownloading && !isOriginalVideoRestarting && (isSharedOriginalVideoCancelled || !originalVideoDownloadKey && downloadIsCancelled);
39755
39782
  var isVideoDownloading = downloadingFile || isSharedOriginalVideoDownloading;
39756
39783
  var isVideoDownloadActive = isVideoDownloading || isOriginalVideoRestarting;
39784
+ var shouldRenderVideoDownloadProgress = Boolean(!isRepliedMessage && !isPreview && (isInUploadingState || isVideoDownloadActive));
39757
39785
  var videoProgress = isSharedOriginalVideoDownloading ? sharedOriginalVideoDownload.progress || 3 : progress;
39758
39786
  var videoSizeProgress = isSharedOriginalVideoDownloading ? {
39759
39787
  loaded: sharedOriginalVideoDownload.loaded,
39760
39788
  total: sharedOriginalVideoDownload.total
39761
39789
  } : sizeProgress;
39762
- var isImageDownloading = downloadingFile || sharedOriginalImageDownload.state === 'loading';
39790
+ useEffect(function () {
39791
+ if (isSharedOriginalVideoDownloading && downloadIsCancelled) {
39792
+ setDownloadIsCancelled(false);
39793
+ }
39794
+ }, [downloadIsCancelled, isSharedOriginalVideoDownloading]);
39795
+ var isImageDownloading = downloadingFile || sharedOriginalImageDownload.state === 'loading' || isOriginalImageRestarting;
39763
39796
  var isSharedOriginalImageCancelled = sharedOriginalImageDownload.state === 'cancelled';
39797
+ var shouldShowImageDownloadRetry = !isOriginalImageRestarting && (isSharedOriginalImageCancelled || downloadIsCancelled && sharedOriginalImageDownload.state !== 'loading');
39764
39798
  var imageProgress = sharedOriginalImageDownload.state === 'loading' ? sharedOriginalImageDownload.progress || 3 : progress;
39765
39799
  var imageSizeProgress = sharedOriginalImageDownload.state === 'loading' ? {
39766
39800
  loaded: sharedOriginalImageDownload.loaded,
@@ -40107,6 +40141,9 @@ var Attachment = function Attachment(_ref) {
40107
40141
  if (attachment.type !== attachmentTypes.video) {
40108
40142
  return;
40109
40143
  }
40144
+ if (isSharedOriginalVideoCancelled) {
40145
+ return;
40146
+ }
40110
40147
  var _getVideoAttachmentCa = getVideoAttachmentCacheKeys(attachment.url, attachment.metadata),
40111
40148
  videoThumb = _getVideoAttachmentCa.videoThumb,
40112
40149
  originalVideoCacheKey = _getVideoAttachmentCa.originalVideo;
@@ -40121,11 +40158,12 @@ var Attachment = function Attachment(_ref) {
40121
40158
  return;
40122
40159
  }
40123
40160
  var cancelled = false;
40161
+ var videoDownloadRequest = videoDownloadRequestRef.current;
40124
40162
  var loadVideoThumbAndOriginal = function loadVideoThumbAndOriginal() {
40125
40163
  try {
40126
40164
  var _temp18 = function _temp18(_result2) {
40127
40165
  if (_exit) return _result2;
40128
- if (isDetailsView) return;
40166
+ if (isDetailsView && videoDownloadRetry === 0) return;
40129
40167
  return Promise.resolve(getAttachmentUrlFromCache(originalVideoCacheKey)["catch"](function () {
40130
40168
  return false;
40131
40169
  })).then(function (cachedOriginalVideo) {
@@ -40149,15 +40187,16 @@ var Attachment = function Attachment(_ref) {
40149
40187
  size: Number(attachment.size) || 0
40150
40188
  }).then(function (_ref4) {
40151
40189
  var objectUrl = _ref4.objectUrl;
40152
- if (cancelled) return;
40190
+ if (cancelled || videoDownloadRequest !== videoDownloadRequestRef.current) return;
40153
40191
  dispatch(setUpdateMessageAttachmentAC(originalVideoCacheKey, objectUrl));
40154
40192
  setAttachmentUrl(objectUrl);
40155
40193
  setIsCached(true);
40156
40194
  setDownloadIsCancelled(false);
40157
40195
  setIsOriginalVideoRestarting(false);
40158
40196
  })["catch"](function (error) {
40197
+ if (videoDownloadRequest !== videoDownloadRequestRef.current) return;
40159
40198
  setIsOriginalVideoRestarting(false);
40160
- if (!cancelled) log.error('Error downloading video attachment:', error);
40199
+ if (!cancelled && !isMediaDownloadCancellation(error)) log.error('Error downloading video attachment:', error);
40161
40200
  });
40162
40201
  });
40163
40202
  };
@@ -40186,39 +40225,107 @@ var Attachment = function Attachment(_ref) {
40186
40225
  return function () {
40187
40226
  cancelled = true;
40188
40227
  };
40189
- }, [attachment.id, attachment.type, attachment.url, attachment.metadata, attachment.attachmentUrl, isDetailsView, originalVideoUrlFromMap, connectionStatus, dispatch, messageType, attachment.size, videoDownloadRetry]);
40228
+ }, [attachment.id, attachment.type, attachment.url, attachment.metadata, attachment.attachmentUrl, isDetailsView, originalVideoUrlFromMap, connectionStatus, dispatch, messageType, attachment.size, videoDownloadRetry, isSharedOriginalVideoCancelled]);
40190
40229
  var handleResumeOriginalVideoDownload = function handleResumeOriginalVideoDownload(event) {
40191
40230
  event.stopPropagation();
40231
+ if (!attachment.url) return;
40232
+ var _getVideoAttachmentCa2 = getVideoAttachmentCacheKeys(attachment.url, attachment.metadata),
40233
+ originalVideoCacheKey = _getVideoAttachmentCa2.originalVideo;
40234
+ var videoDownloadRequest = videoDownloadRequestRef.current + 1;
40235
+ videoDownloadRequestRef.current = videoDownloadRequest;
40192
40236
  originalVideoDownloadStartedRef.current = false;
40193
40237
  setDownloadIsCancelled(false);
40194
40238
  setIsOriginalVideoRestarting(true);
40195
40239
  setVideoDownloadRetry(function (retry) {
40196
40240
  return retry + 1;
40197
40241
  });
40242
+ originalVideoDownloadStartedRef.current = true;
40243
+ requestMediaDownload({
40244
+ key: "original-video:" + attachment.url,
40245
+ url: attachment.url,
40246
+ cacheKey: originalVideoCacheKey,
40247
+ kind: 'original-video',
40248
+ messageType: messageType,
40249
+ size: Number(attachment.size) || 0
40250
+ }).then(function (_ref5) {
40251
+ var objectUrl = _ref5.objectUrl;
40252
+ if (videoDownloadRequest !== videoDownloadRequestRef.current) return;
40253
+ dispatch(setUpdateMessageAttachmentAC(originalVideoCacheKey, objectUrl));
40254
+ setAttachmentUrl(objectUrl);
40255
+ setIsCached(true);
40256
+ setDownloadIsCancelled(false);
40257
+ setIsOriginalVideoRestarting(false);
40258
+ })["catch"](function (error) {
40259
+ if (videoDownloadRequest !== videoDownloadRequestRef.current) return;
40260
+ setIsOriginalVideoRestarting(false);
40261
+ if (!isMediaDownloadCancellation(error)) log.error('Error restarting video attachment download:', error);
40262
+ });
40198
40263
  };
40199
40264
  var handleResumeOriginalImageDownload = function handleResumeOriginalImageDownload(event) {
40200
40265
  event.stopPropagation();
40266
+ if (!attachment.url) return;
40267
+ var imageDownloadRequest = imageDownloadRequestRef.current + 1;
40268
+ imageDownloadRequestRef.current = imageDownloadRequest;
40269
+ imageResumeStartedRef.current = true;
40201
40270
  setDownloadIsCancelled(false);
40271
+ setIsOriginalImageRestarting(true);
40202
40272
  setImageDownloadRetry(function (retry) {
40203
40273
  return retry + 1;
40204
40274
  });
40275
+ requestMediaDownload({
40276
+ key: "original-image:" + attachment.url,
40277
+ url: attachment.url,
40278
+ cacheKey: attachment.url,
40279
+ cacheKeys: [attachment.url + '_original_image_url'],
40280
+ kind: 'original-image',
40281
+ messageType: messageType,
40282
+ size: Number(attachment.size) || 0
40283
+ }).then(function (_ref6) {
40284
+ var objectUrl = _ref6.objectUrl;
40285
+ try {
40286
+ if (imageDownloadRequest !== imageDownloadRequestRef.current) return Promise.resolve();
40287
+ return Promise.resolve(compressAndCacheImage(objectUrl, attachment.url, renderWidth, renderHeight)).then(function (compressedUrl) {
40288
+ if (imageDownloadRequest !== imageDownloadRequestRef.current) return;
40289
+ var displayedUrl = compressedUrl || objectUrl;
40290
+ setAttachmentUrl(displayedUrl);
40291
+ dispatch(setUpdateMessageAttachmentAC(attachment.url, displayedUrl));
40292
+ dispatch(setUpdateMessageAttachmentAC(attachment.url + '_original_image_url', objectUrl));
40293
+ setIsCached(true);
40294
+ setDownloadIsCancelled(false);
40295
+ setIsOriginalImageRestarting(false);
40296
+ imageResumeStartedRef.current = false;
40297
+ });
40298
+ } catch (e) {
40299
+ return Promise.reject(e);
40300
+ }
40301
+ })["catch"](function (error) {
40302
+ if (imageDownloadRequest !== imageDownloadRequestRef.current) return;
40303
+ imageResumeStartedRef.current = false;
40304
+ setIsOriginalImageRestarting(false);
40305
+ log.error('Error restarting image attachment download:', error);
40306
+ });
40205
40307
  };
40206
40308
  var handleCancelOriginalVideoDownload = function handleCancelOriginalVideoDownload(event) {
40207
40309
  event.stopPropagation();
40208
40310
  if (isSharedOriginalVideoDownloading && originalVideoDownloadKey) {
40209
- cancelMediaDownload(originalVideoDownloadKey);
40210
- originalVideoDownloadStartedRef.current = false;
40311
+ videoDownloadRequestRef.current += 1;
40211
40312
  setDownloadIsCancelled(true);
40212
40313
  setIsOriginalVideoRestarting(false);
40314
+ cancelMediaDownload(originalVideoDownloadKey);
40315
+ originalVideoDownloadStartedRef.current = false;
40213
40316
  return;
40214
40317
  }
40215
40318
  handleStopStartDownloadFile();
40216
40319
  };
40217
40320
  useEffect(function () {
40321
+ if (imageResumeStartedRef.current) return;
40322
+ if (isSharedOriginalImageCancelled) return;
40218
40323
  if (!attachment.attachmentUrl && connectionStatus === CONNECTION_STATUS.CONNECTED && attachment.id && !attachmentUrlFromMap && attachment.type !== attachmentTypes.video && !(attachment.type === attachmentTypes.file || attachment.type === attachmentTypes.link)) {
40219
40324
  var requestAttachmentKey = attachmentKey;
40325
+ var imageDownloadRequest = imageDownloadRequestRef.current;
40220
40326
  getAttachmentUrlFromCache(attachment.url).then(function (cachedUrl) {
40221
40327
  try {
40328
+ if (imageDownloadRequest !== imageDownloadRequestRef.current) return Promise.resolve();
40222
40329
  if (attachment.type === attachmentTypes.image && !isPreview) {
40223
40330
  if (cachedUrl) {
40224
40331
  setAttachmentUrl(cachedUrl);
@@ -40234,23 +40341,27 @@ var Attachment = function Attachment(_ref) {
40234
40341
  kind: 'original-image',
40235
40342
  messageType: messageType,
40236
40343
  size: Number(attachment.size) || 0
40237
- }).then(function (_ref5) {
40238
- var objectUrl = _ref5.objectUrl;
40344
+ }).then(function (_ref7) {
40345
+ var objectUrl = _ref7.objectUrl;
40239
40346
  try {
40240
- if (requestAttachmentKey !== currentAttachmentKeyRef.current) return Promise.resolve();
40347
+ if (requestAttachmentKey !== currentAttachmentKeyRef.current || imageDownloadRequest !== imageDownloadRequestRef.current) return Promise.resolve();
40241
40348
  return Promise.resolve(compressAndCacheImage(objectUrl, attachment.url, renderWidth, renderHeight)).then(function (compressedUrl) {
40242
- if (requestAttachmentKey !== currentAttachmentKeyRef.current) return;
40349
+ if (requestAttachmentKey !== currentAttachmentKeyRef.current || imageDownloadRequest !== imageDownloadRequestRef.current) return;
40243
40350
  var displayedUrl = compressedUrl || objectUrl;
40244
40351
  setAttachmentUrl(displayedUrl);
40245
40352
  dispatch(setUpdateMessageAttachmentAC(attachment.url, displayedUrl));
40246
40353
  dispatch(setUpdateMessageAttachmentAC(attachment.url + '_original_image_url', objectUrl));
40247
40354
  setIsCached(true);
40355
+ setIsOriginalImageRestarting(false);
40248
40356
  });
40249
40357
  } catch (e) {
40250
40358
  return Promise.reject(e);
40251
40359
  }
40252
40360
  })["catch"](function (error) {
40253
- if (requestAttachmentKey === currentAttachmentKeyRef.current) {
40361
+ if (imageDownloadRequest === imageDownloadRequestRef.current) {
40362
+ setIsOriginalImageRestarting(false);
40363
+ }
40364
+ if (requestAttachmentKey === currentAttachmentKeyRef.current && imageDownloadRequest === imageDownloadRequestRef.current) {
40254
40365
  log.error('Error downloading image attachment:', error);
40255
40366
  }
40256
40367
  });
@@ -40269,8 +40380,8 @@ var Attachment = function Attachment(_ref) {
40269
40380
  kind: kind,
40270
40381
  messageType: messageType,
40271
40382
  size: Number(attachment.size) || 0
40272
- }).then(function (_ref6) {
40273
- var objectUrl = _ref6.objectUrl;
40383
+ }).then(function (_ref8) {
40384
+ var objectUrl = _ref8.objectUrl;
40274
40385
  if (requestAttachmentKey !== currentAttachmentKeyRef.current) return;
40275
40386
  setAttachmentUrl(objectUrl);
40276
40387
  dispatch(setUpdateMessageAttachmentAC(attachment.url, objectUrl));
@@ -40330,7 +40441,7 @@ var Attachment = function Attachment(_ref) {
40330
40441
  }
40331
40442
  });
40332
40443
  }
40333
- }, [imageDownloadRetry]);
40444
+ }, [imageDownloadRetry, isSharedOriginalImageCancelled]);
40334
40445
  useDidUpdate(function () {
40335
40446
  if (connectionStatus === CONNECTION_STATUS.CONNECTED && isInUploadingState) {
40336
40447
  setFailTimeout(setTimeout(function () {
@@ -40402,7 +40513,7 @@ var Attachment = function Attachment(_ref) {
40402
40513
  })), attachment.type === attachmentTypes.image ? (/*#__PURE__*/React__default.createElement(AttachmentImgCont, {
40403
40514
  draggable: false,
40404
40515
  onClick: function onClick() {
40405
- return handleMediaItemClick && !isInUploadingState && !isSharedOriginalImageCancelled && handleMediaItemClick(attachment);
40516
+ return handleMediaItemClick && !isInUploadingState && !isImageDownloading && !shouldShowImageDownloadRetry && handleMediaItemClick(attachment);
40406
40517
  },
40407
40518
  isPreview: isPreview,
40408
40519
  ref: imageContRef,
@@ -40463,15 +40574,18 @@ var Attachment = function Attachment(_ref) {
40463
40574
  }, isInUploadingState ? (/*#__PURE__*/React__default.createElement(CancelResumeWrapper, {
40464
40575
  onClick: handlePauseResumeUpload
40465
40576
  }, attachmentCompilationState[attachment.tid] === UPLOAD_STATE.UPLOADING ? (/*#__PURE__*/React__default.createElement(SvgCancel, null)) : (/*#__PURE__*/React__default.createElement(SvgUpload, null)))) : !isCached && (/*#__PURE__*/React__default.createElement(CancelResumeWrapper, {
40577
+ "aria-label": 'Cancel image download',
40466
40578
  onClick: function onClick(e) {
40467
40579
  e.stopPropagation();
40468
40580
  if (sharedOriginalImageDownload.state === 'loading' && originalImageDownloadKey) {
40581
+ setDownloadIsCancelled(true);
40582
+ setIsOriginalImageRestarting(false);
40469
40583
  cancelMediaDownload(originalImageDownloadKey);
40470
40584
  } else {
40471
40585
  handlePauseResumeDownload(e.nativeEvent);
40472
40586
  }
40473
40587
  }
40474
- }, downloadIsCancelled ? /*#__PURE__*/React__default.createElement(SvgDownload, null) : /*#__PURE__*/React__default.createElement(SvgCancel, null))), (isImageDownloading || attachmentCompilationState[attachment.tid] === UPLOAD_STATE.UPLOADING) && (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(ProgressWrapper, null, /*#__PURE__*/React__default.createElement(CircularProgressbar, {
40588
+ }, shouldShowImageDownloadRetry ? /*#__PURE__*/React__default.createElement(SvgDownload, null) : /*#__PURE__*/React__default.createElement(SvgCancel, null))), (isImageDownloading || attachmentCompilationState[attachment.tid] === UPLOAD_STATE.UPLOADING) && (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(ProgressWrapper, null, /*#__PURE__*/React__default.createElement(CircularProgressbar, {
40475
40589
  minValue: 0,
40476
40590
  maxValue: 100,
40477
40591
  value: imageProgress,
@@ -40493,7 +40607,7 @@ var Attachment = function Attachment(_ref) {
40493
40607
  }
40494
40608
  })), imageSizeProgress && (/*#__PURE__*/React__default.createElement(SizeProgress, {
40495
40609
  color: textOnPrimary
40496
- }, bytesToSize(imageSizeProgress.loaded, 1), " / ", bytesToSize(imageSizeProgress.total, 1))))))))) : null, isSharedOriginalImageCancelled && !isPreview && !isRepliedMessage && (/*#__PURE__*/React__default.createElement(UploadProgress, {
40610
+ }, bytesToSize(imageSizeProgress.loaded, 1), " / ", bytesToSize(imageSizeProgress.total, 1))))))))) : null, shouldShowImageDownloadRetry && !isPreview && !isRepliedMessage && (/*#__PURE__*/React__default.createElement(UploadProgress, {
40497
40611
  backgroundImage: !attachmentUrlFromMap ? attachmentThumb : '',
40498
40612
  isRepliedMessage: isRepliedMessage,
40499
40613
  width: renderWidth,
@@ -40511,7 +40625,8 @@ var Attachment = function Attachment(_ref) {
40511
40625
  isDetailsView: isDetailsView,
40512
40626
  backgroundColor: overlayBackground2
40513
40627
  }, /*#__PURE__*/React__default.createElement(CancelResumeWrapper, {
40514
- onClick: handleResumeOriginalImageDownload
40628
+ onClick: handleResumeOriginalImageDownload,
40629
+ "aria-label": 'Download image'
40515
40630
  }, /*#__PURE__*/React__default.createElement(SvgDownload, null))))), isPreview && (/*#__PURE__*/React__default.createElement(RemoveChosenFile, {
40516
40631
  "$backgroundColor": background,
40517
40632
  color: iconInactive,
@@ -40520,10 +40635,10 @@ var Attachment = function Attachment(_ref) {
40520
40635
  }
40521
40636
  })))) : attachment.type === attachmentTypes.video ? (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, !isPreview ? (/*#__PURE__*/React__default.createElement(VideoCont, {
40522
40637
  onClick: function onClick() {
40523
- return handleMediaItemClick && !isVideoDownloadActive && !isSharedOriginalVideoCancelled && !isInUploadingState && (attachmentCompilationState[attachment.tid] ? attachmentCompilationState[attachment.tid] !== UPLOAD_STATE.FAIL || attachmentCompilationState[attachment.tid] !== UPLOAD_STATE.UPLOADING : true) && handleMediaItemClick(attachment);
40638
+ return handleMediaItemClick && !isVideoDownloadActive && !shouldShowVideoDownloadRetry && !isInUploadingState && (attachmentCompilationState[attachment.tid] ? attachmentCompilationState[attachment.tid] !== UPLOAD_STATE.FAIL || attachmentCompilationState[attachment.tid] !== UPLOAD_STATE.UPLOADING : true) && handleMediaItemClick(attachment);
40524
40639
  },
40525
40640
  isDetailsView: isDetailsView
40526
- }, (isInUploadingState || isVideoDownloadActive) && !isRepliedMessage && !isPreview ? (/*#__PURE__*/React__default.createElement(UploadProgress, {
40641
+ }, shouldRenderVideoDownloadProgress ? (/*#__PURE__*/React__default.createElement(UploadProgress, {
40527
40642
  isDetailsView: isDetailsView,
40528
40643
  isRepliedMessage: isRepliedMessage,
40529
40644
  withPrefix: downloadedVideoPreviewImage ? false : withPrefix,
@@ -40541,8 +40656,9 @@ var Attachment = function Attachment(_ref) {
40541
40656
  }, isInUploadingState ? (/*#__PURE__*/React__default.createElement(CancelResumeWrapper, {
40542
40657
  onClick: handlePauseResumeUpload
40543
40658
  }, attachmentCompilationState[attachment.tid] === UPLOAD_STATE.UPLOADING || isPreparingVideo ? (/*#__PURE__*/React__default.createElement(SvgCancel, null)) : (/*#__PURE__*/React__default.createElement(SvgUpload, null)))) : (/*#__PURE__*/React__default.createElement(CancelResumeWrapper, {
40544
- onClick: handleCancelOriginalVideoDownload
40545
- }, downloadIsCancelled ? /*#__PURE__*/React__default.createElement(SvgDownload, null) : /*#__PURE__*/React__default.createElement(SvgCancel, null))), (isPreparingVideo || attachmentCompilationState[attachment.tid] === UPLOAD_STATE.UPLOADING || isVideoDownloadActive && !downloadIsCancelled) && (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(ProgressWrapper, null, /*#__PURE__*/React__default.createElement(CircularProgressbar, {
40659
+ onClick: handleCancelOriginalVideoDownload,
40660
+ "aria-label": 'Cancel video download'
40661
+ }, shouldShowVideoDownloadRetry ? /*#__PURE__*/React__default.createElement(SvgDownload, null) : /*#__PURE__*/React__default.createElement(SvgCancel, null))), (isPreparingVideo || attachmentCompilationState[attachment.tid] === UPLOAD_STATE.UPLOADING || isVideoDownloadActive && !downloadIsCancelled) && (/*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(ProgressWrapper, null, /*#__PURE__*/React__default.createElement(CircularProgressbar, {
40546
40662
  minValue: 0,
40547
40663
  maxValue: 100,
40548
40664
  value: isPreparingVideo ? 3 : videoProgress,
@@ -40564,7 +40680,7 @@ var Attachment = function Attachment(_ref) {
40564
40680
  }
40565
40681
  })), videoSizeProgress && !isRepliedMessage && (/*#__PURE__*/React__default.createElement(SizeProgress, {
40566
40682
  color: textOnPrimary
40567
- }, bytesToSize(isPreparingVideo ? 0 : videoSizeProgress.loaded, 1), " /", ' ', bytesToSize(videoSizeProgress.total, 1)))))))) : null, isSharedOriginalVideoCancelled && !isRepliedMessage && !isPreview && (/*#__PURE__*/React__default.createElement(UploadProgress, {
40683
+ }, bytesToSize(isPreparingVideo ? 0 : videoSizeProgress.loaded, 1), " /", ' ', bytesToSize(videoSizeProgress.total, 1)))))))) : null, shouldShowVideoDownloadRetry && !isRepliedMessage && !isPreview && (/*#__PURE__*/React__default.createElement(UploadProgress, {
40568
40684
  isDetailsView: isDetailsView,
40569
40685
  isRepliedMessage: isRepliedMessage,
40570
40686
  withPrefix: downloadedVideoPreviewImage ? false : withPrefix,
@@ -40580,12 +40696,13 @@ var Attachment = function Attachment(_ref) {
40580
40696
  isDetailsView: isDetailsView,
40581
40697
  backgroundColor: overlayBackground2
40582
40698
  }, /*#__PURE__*/React__default.createElement(CancelResumeWrapper, {
40583
- onClick: handleResumeOriginalVideoDownload
40699
+ onClick: handleResumeOriginalVideoDownload,
40700
+ "aria-label": 'Download video'
40584
40701
  }, /*#__PURE__*/React__default.createElement(SvgDownload, null))))), /*#__PURE__*/React__default.createElement(VideoPreview, {
40585
40702
  onlyVideoImage: onlyVideoImage,
40586
40703
  width: isRepliedMessage ? '40px' : isDetailsView ? '100%' : (renderWidth || videoAttachmentMaxWidth || 420) + "px",
40587
40704
  height: isRepliedMessage ? '40px' : isDetailsView ? '100%' : (renderHeight || videoAttachmentMaxHeight || 240) + "px",
40588
- downloading: isVideoDownloadActive || isSharedOriginalVideoCancelled,
40705
+ downloading: isVideoDownloadActive || shouldShowVideoDownloadRetry,
40589
40706
  file: attachment,
40590
40707
  messageType: messageType,
40591
40708
  src: attachmentUrlFromMap || attachment.attachmentUrl || attachmentUrl,
@@ -40826,7 +40943,7 @@ var AttachmentImg = styled.img(_templateObject13$3 || (_templateObject13$3 = _ta
40826
40943
  }, function (props) {
40827
40944
  return props.$fadeIn && css(_templateObject14$3 || (_templateObject14$3 = _taggedTemplateLiteralLoose(["\n opacity: 0;\n animation: ", " 100ms ease-in-out forwards;\n "])), mediaCrossFade);
40828
40945
  });
40829
- var VideoCont = styled.div(_templateObject15$2 || (_templateObject15$2 = _taggedTemplateLiteralLoose(["\n position: relative;\n cursor: pointer;\n height: ", ";\n"])), function (props) {
40946
+ var VideoCont = styled.div(_templateObject15$2 || (_templateObject15$2 = _taggedTemplateLiteralLoose(["\n position: relative;\n cursor: pointer;\n width: 100%;\n height: ", ";\n"])), function (props) {
40830
40947
  return props.isDetailsView && '100%';
40831
40948
  });
40832
40949
 
@@ -59287,8 +59404,76 @@ var DisappearingMessagesStatus = styled.span(_templateObject19$4 || (_templateOb
59287
59404
  var ChevronRightIconWrapper$1 = styled.span(_templateObject20$4 || (_templateObject20$4 = _taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n\n & > svg {\n width: 16px;\n height: 16px;\n transform: rotate(-90deg);\n }\n"])));
59288
59405
 
59289
59406
  var _templateObject$11, _templateObject2$Z, _templateObject3$P, _templateObject4$H, _templateObject5$D, _templateObject6$y, _templateObject7$v, _templateObject8$s, _templateObject9$n, _templateObject0$l;
59290
- var Media = function Media(_ref) {
59291
- var channel = _ref.channel;
59407
+ var startMediaVideoDownload = function startMediaVideoDownload(file) {
59408
+ if (file.type !== 'video' || !file.url) return;
59409
+ var _getVideoAttachmentCa = getVideoAttachmentCacheKeys(file.url, file.metadata),
59410
+ originalVideo = _getVideoAttachmentCa.originalVideo;
59411
+ return requestMediaDownload({
59412
+ key: "original-video:" + file.url,
59413
+ url: file.url,
59414
+ cacheKey: originalVideo,
59415
+ kind: 'original-video',
59416
+ size: Number(file.size) || 0
59417
+ });
59418
+ };
59419
+ var MediaTile = function MediaTile(_ref) {
59420
+ var file = _ref.file,
59421
+ background = _ref.background,
59422
+ onOpen = _ref.onOpen;
59423
+ var elementRef = useRef(null);
59424
+ var downloadStartedRef = useRef(false);
59425
+ var dispatch = useDispatch();
59426
+ useEffect(function () {
59427
+ if (file.type !== 'video' || !file.url || downloadStartedRef.current) return;
59428
+ var startDownload = function startDownload() {
59429
+ var _startMediaVideoDownl;
59430
+ if (downloadStartedRef.current) return;
59431
+ if (getMediaDownloadSnapshot("original-video:" + file.url).state === 'cancelled') return;
59432
+ downloadStartedRef.current = true;
59433
+ var _getVideoAttachmentCa2 = getVideoAttachmentCacheKeys(file.url, file.metadata),
59434
+ originalVideo = _getVideoAttachmentCa2.originalVideo;
59435
+ (_startMediaVideoDownl = startMediaVideoDownload(file)) === null || _startMediaVideoDownl === void 0 ? void 0 : _startMediaVideoDownl.then(function (_ref2) {
59436
+ var objectUrl = _ref2.objectUrl;
59437
+ dispatch(setUpdateMessageAttachmentAC(originalVideo, objectUrl));
59438
+ })["catch"](function (error) {
59439
+ log.error('Failed to start media-tab video download:', error);
59440
+ });
59441
+ };
59442
+ var element = elementRef.current;
59443
+ if (!element) return;
59444
+ if (typeof IntersectionObserver === 'undefined') {
59445
+ startDownload();
59446
+ return;
59447
+ }
59448
+ var observer = new IntersectionObserver(function (entries) {
59449
+ if (entries.some(function (entry) {
59450
+ return entry.isIntersecting;
59451
+ })) {
59452
+ startDownload();
59453
+ observer.disconnect();
59454
+ }
59455
+ }, {
59456
+ rootMargin: '200px 0px'
59457
+ });
59458
+ observer.observe(element);
59459
+ return function () {
59460
+ return observer.disconnect();
59461
+ };
59462
+ }, [dispatch, file.id, file.type, file.url, file.metadata, file.size]);
59463
+ return /*#__PURE__*/React__default.createElement(MediaItem, {
59464
+ ref: elementRef
59465
+ }, /*#__PURE__*/React__default.createElement(Attachment$1, {
59466
+ attachment: _extends({}, file, {
59467
+ metadata: isJSON(file.metadata) ? JSON.parse(file.metadata) : file.metadata
59468
+ }),
59469
+ handleMediaItemClick: onOpen,
59470
+ backgroundColor: background,
59471
+ borderRadius: '8px',
59472
+ isDetailsView: true
59473
+ }));
59474
+ };
59475
+ var Media = function Media(_ref3) {
59476
+ var channel = _ref3.channel;
59292
59477
  var _useColor = useColors(),
59293
59478
  background = _useColor[THEME_COLORS.BACKGROUND],
59294
59479
  textSecondary = _useColor[THEME_COLORS.TEXT_SECONDARY],
@@ -59307,6 +59492,10 @@ var Media = function Media(_ref) {
59307
59492
  resource: typeof (file === null || file === void 0 ? void 0 : file.url) === 'string' ? file.url.split(/[?#]/)[0] : null
59308
59493
  }));
59309
59494
  if (file !== null && file !== void 0 && file.id) {
59495
+ var _startMediaVideoDownl2;
59496
+ (_startMediaVideoDownl2 = startMediaVideoDownload(file)) === null || _startMediaVideoDownl2 === void 0 ? void 0 : _startMediaVideoDownl2["catch"](function (error) {
59497
+ log.error('Failed to start media-tab video download:', error);
59498
+ });
59310
59499
  dispatch(setAttachmentsForPopupAC([file]));
59311
59500
  setMediaFile(file);
59312
59501
  log.info('[MEDIA_IMAGE_SLIDER] slider state requested ' + JSON.stringify({
@@ -59359,17 +59548,12 @@ var Media = function Media(_ref) {
59359
59548
  month: 'long',
59360
59549
  year: 'numeric'
59361
59550
  })), /*#__PURE__*/React__default.createElement(ItemsGrid, null, group.items.map(function (file, index) {
59362
- return /*#__PURE__*/React__default.createElement(MediaItem, {
59363
- key: file.id || file.messageId + "_" + index
59364
- }, /*#__PURE__*/React__default.createElement(Attachment$1, {
59365
- attachment: _extends({}, file, {
59366
- metadata: isJSON(file.metadata) ? JSON.parse(file.metadata) : file.metadata
59367
- }),
59368
- handleMediaItemClick: handleMediaItemClick,
59369
- backgroundColor: background,
59370
- borderRadius: '8px',
59371
- isDetailsView: true
59372
- }));
59551
+ return /*#__PURE__*/React__default.createElement(MediaTile, {
59552
+ key: file.id || file.messageId + "_" + index,
59553
+ file: file,
59554
+ background: background,
59555
+ onOpen: handleMediaItemClick
59556
+ });
59373
59557
  })));
59374
59558
  }), loadingState === LOADING_STATE.LOADING && (/*#__PURE__*/React__default.createElement(SkeletonGrid, null, Array.from({
59375
59559
  length: 3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sceyt-chat-react-uikit",
3
- "version": "1.9.0-beta.7",
3
+ "version": "1.9.0-beta.8",
4
4
  "description": "Interactive React UI Components for Sceyt Chat.",
5
5
  "author": "Sceyt",
6
6
  "license": "MIT",