From 74a0f96b6c16f81050224ee733f7da3d90d667fa Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 22 Oct 2021 02:24:39 +0300 Subject: [PATCH] Downloads (Follow-up) (#1510) --- src/components/middle/message/Photo.tsx | 2 +- src/components/middle/message/Video.tsx | 2 +- src/modules/helpers/messages.ts | 2 +- src/util/mediaLoader.ts | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/middle/message/Photo.tsx b/src/components/middle/message/Photo.tsx index 1d7b8b2e..ba37de79 100644 --- a/src/components/middle/message/Photo.tsx +++ b/src/components/middle/message/Photo.tsx @@ -88,7 +88,7 @@ const Photo: FC = ({ isUploading, isTransferring, transferProgress, } = getMediaTransferState( message, - uploadProgress || isDownloading ? downloadProgress : loadProgress, + uploadProgress || (isDownloading ? downloadProgress : loadProgress), shouldLoad && !fullMediaData, ); const wasLoadDisabled = usePrevious(isLoadAllowed) === false; diff --git a/src/components/middle/message/Video.tsx b/src/components/middle/message/Video.tsx index 9efcf811..9a514021 100644 --- a/src/components/middle/message/Video.tsx +++ b/src/components/middle/message/Video.tsx @@ -102,7 +102,7 @@ const Video: FC = ({ const { isBuffered, bufferingHandlers } = useBuffering(!shouldAutoLoad); const { isUploading, isTransferring, transferProgress } = getMediaTransferState( message, - uploadProgress || isDownloading ? downloadProgress : loadProgress, + uploadProgress || (isDownloading ? downloadProgress : loadProgress), (shouldLoad && !isBuffered) || isDownloading, ); const wasLoadDisabled = usePrevious(isLoadAllowed) === false; diff --git a/src/modules/helpers/messages.ts b/src/modules/helpers/messages.ts index d8a43766..fef24628 100644 --- a/src/modules/helpers/messages.ts +++ b/src/modules/helpers/messages.ts @@ -258,7 +258,7 @@ export function getMessageContentFilename(message: ApiMessage) { const baseFilename = getMessageKey(message); if (photo) { - return `${baseFilename}.png`; + return `${baseFilename}.jpg`; } if (content.voice) { diff --git a/src/util/mediaLoader.ts b/src/util/mediaLoader.ts index c31ebd04..4623db0c 100644 --- a/src/util/mediaLoader.ts +++ b/src/util/mediaLoader.ts @@ -84,7 +84,8 @@ export function cancelProgress(progressCallback: ApiOnProgress) { progressCallbacks.forEach((map, url) => { map.forEach((callback) => { if (callback === progressCallback) { - const parentCallback = cancellableCallbacks.get(url)!; + const parentCallback = cancellableCallbacks.get(url); + if (!parentCallback) return; cancelApiProgress(parentCallback); cancellableCallbacks.delete(url);