Fix adding downloaded files to Downloads.

This commit is contained in:
John Preston 2023-08-18 19:25:25 +02:00
parent 653d7aadb1
commit b610de30f4
3 changed files with 43 additions and 22 deletions

View File

@ -74,7 +74,8 @@ void DocumentOpenClickHandler::onClickImpl() const {
void DocumentSaveClickHandler::Save(
Data::FileOrigin origin,
not_null<DocumentData*> data,
Mode mode) {
Mode mode,
Fn<void()> 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<DocumentData*> 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<void()> 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 {

View File

@ -53,11 +53,13 @@ public:
static void Save(
Data::FileOrigin origin,
not_null<DocumentData*> document,
Mode mode = Mode::ToCacheOrFile);
Mode mode = Mode::ToCacheOrFile,
Fn<void()> started = nullptr);
static void SaveAndTrack(
FullMsgId itemId,
not_null<DocumentData*> document,
Mode mode = Mode::ToCacheOrFile);
Mode mode = Mode::ToCacheOrFile,
Fn<void()> started = nullptr);
protected:
void onClickImpl() const override;

View File

@ -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);