diff --git a/Telegram/SourceFiles/data/data_file_click_handler.cpp b/Telegram/SourceFiles/data/data_file_click_handler.cpp index ec746f5667..e42397d197 100644 --- a/Telegram/SourceFiles/data/data_file_click_handler.cpp +++ b/Telegram/SourceFiles/data/data_file_click_handler.cpp @@ -74,7 +74,8 @@ void DocumentOpenClickHandler::onClickImpl() const { void DocumentSaveClickHandler::Save( Data::FileOrigin origin, not_null data, - Mode mode) { + Mode mode, + Fn started) { if (data->isNull()) { return; } @@ -89,6 +90,9 @@ void DocumentSaveClickHandler::Save( // background thread timers from working which would // stop audio playback in voice chats / live streams. if (mode != Mode::ToNewFile && data->saveFromData()) { + if (started) { + started(); + } return; } const auto filepath = data->filepath(true); @@ -107,6 +111,9 @@ void DocumentSaveClickHandler::Save( filedir); if (!savename.isEmpty()) { data->save(origin, savename); + if (started) { + started(); + } } })); } @@ -114,16 +121,21 @@ void DocumentSaveClickHandler::Save( void DocumentSaveClickHandler::SaveAndTrack( FullMsgId itemId, not_null document, - Mode mode) { - Save(itemId ? itemId : Data::FileOrigin(), document, mode); - if (document->loading() && !document->loadingFilePath().isEmpty()) { - if (const auto item = document->owner().message(itemId)) { - Core::App().downloadManager().addLoading({ - .item = item, - .document = document, - }); + Mode mode, + Fn started) { + Save(itemId ? itemId : Data::FileOrigin(), document, mode, [=] { + if (document->loading() && !document->loadingFilePath().isEmpty()) { + if (const auto item = document->owner().message(itemId)) { + Core::App().downloadManager().addLoading({ + .item = item, + .document = document, + }); + } } - } + if (started) { + started(); + } + }); } void DocumentSaveClickHandler::onClickImpl() const { diff --git a/Telegram/SourceFiles/data/data_file_click_handler.h b/Telegram/SourceFiles/data/data_file_click_handler.h index 472d04d15e..46eaa5b824 100644 --- a/Telegram/SourceFiles/data/data_file_click_handler.h +++ b/Telegram/SourceFiles/data/data_file_click_handler.h @@ -53,11 +53,13 @@ public: static void Save( Data::FileOrigin origin, not_null document, - Mode mode = Mode::ToCacheOrFile); + Mode mode = Mode::ToCacheOrFile, + Fn started = nullptr); static void SaveAndTrack( FullMsgId itemId, not_null document, - Mode mode = Mode::ToCacheOrFile); + Mode mode = Mode::ToCacheOrFile, + Fn started = nullptr); protected: void onClickImpl() const override; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 0a58cdb5e5..d4c8686172 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -2512,19 +2512,26 @@ void OverlayWidget::downloadMedia() { } else { if (_document->filepath(true).isEmpty() && !_document->loading()) { + const auto document = _document; + const auto checkSaveStarted = [=] { + if (isHidden() || _document != document) { + return; + } + _documentLoadingTo = _document->loadingFilePath(); + if (_stories && _documentLoadingTo.isEmpty()) { + const auto toName = _document->filepath(true); + if (!toName.isEmpty()) { + showSaveMsgToast( + toName, + tr::lng_mediaview_video_saved_to); + } + } + }; DocumentSaveClickHandler::SaveAndTrack( _message ? _message->fullId() : FullMsgId(), _document, - DocumentSaveClickHandler::Mode::ToFile); - _documentLoadingTo = _document->loadingFilePath(); - if (_stories && _documentLoadingTo.isEmpty()) { - toName = _document->filepath(true); - if (!toName.isEmpty()) { - showSaveMsgToast( - toName, - tr::lng_mediaview_video_saved_to); - } - } + DocumentSaveClickHandler::Mode::ToFile, + crl::guard(_widget, checkSaveStarted)); } else { _saveVisible = computeSaveButtonVisible(); update(_saveNavOver);