From 1ed83cf1930fd3d84a4f45611078729180243239 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 26 Mar 2019 15:26:34 +0300 Subject: [PATCH] Fixed subscribeToUploader. --- Telegram/SourceFiles/apiwrap.cpp | 4 +++- Telegram/SourceFiles/history/history_widget.cpp | 11 +++++------ Telegram/SourceFiles/history/history_widget.h | 2 +- Telegram/SourceFiles/mainwidget.cpp | 1 + Telegram/SourceFiles/storage/file_upload.cpp | 4 ++-- Telegram/SourceFiles/storage/file_upload.h | 3 +++ Telegram/SourceFiles/storage/localimageloader.cpp | 8 ++++++-- Telegram/SourceFiles/storage/localimageloader.h | 6 +++++- 8 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 1148f103c..1b8862580 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -4483,7 +4483,9 @@ void ApiWrap::editMedia( std::move(file.information), type, to, - caption)); + caption, + nullptr, + true)); } _fileLoader->addTasks(std::move(tasks)); } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index f66e4ba58..13c389dd9 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -4173,14 +4173,14 @@ void HistoryWidget::uploadFile( Auth().api().sendFile(fileContent, type, options); } -void HistoryWidget::subscribeToUploader(bool edit) { +void HistoryWidget::subscribeToUploader() { if (_uploaderSubscriptions) { return; } using namespace Storage; Auth().uploader().photoReady( ) | rpl::start_with_next([=](const UploadedPhoto &data) { - edit + data.edit ? photoEdited(data.fullId, data.silent, data.file) : photoUploaded(data.fullId, data.silent, data.file); }, _uploaderSubscriptions); @@ -4194,7 +4194,7 @@ void HistoryWidget::subscribeToUploader(bool edit) { }, _uploaderSubscriptions); Auth().uploader().documentReady( ) | rpl::start_with_next([=](const UploadedDocument &data) { - edit + data.edit ? documentEdited(data.fullId, data.silent, data.file) : documentUploaded(data.fullId, data.silent, data.file); }, _uploaderSubscriptions); @@ -4236,9 +4236,8 @@ void HistoryWidget::sendFileConfirmed( it->msgId = newId; } - - subscribeToUploader(isEditing); - + subscribeToUploader(); + file->edit = isEditing; Auth().uploader().upload(newId, file); const auto history = Auth().data().history(file->to.peer); diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index d81990dce..1d31de6c7 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -442,7 +442,7 @@ private: MsgId replyTo, std::shared_ptr album = nullptr); - void subscribeToUploader(bool edit = false); + void subscribeToUploader(); void photoUploaded( const FullMsgId &msgId, diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 8c21755b7..d0c5d98c8 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1319,6 +1319,7 @@ void MainWidget::onEditMedia( const std::shared_ptr &file, const FullMsgId &oldId) { LOG(("ON EDIT MEDIA")); + App::main()->setEditMedia(FullMsgId()); _history->sendFileConfirmed(file, oldId); } diff --git a/Telegram/SourceFiles/storage/file_upload.cpp b/Telegram/SourceFiles/storage/file_upload.cpp index ebe9ea362..c103b47dc 100644 --- a/Telegram/SourceFiles/storage/file_upload.cpp +++ b/Telegram/SourceFiles/storage/file_upload.cpp @@ -329,7 +329,7 @@ void Uploader::sendNext() { MTP_int(uploadingData.partsCount), MTP_string(photoFilename), MTP_bytes(md5)); - _photoReady.fire({ uploadingId, silent, file }); + _photoReady.fire({ uploadingId, silent, file, uploadingData.file->edit }); } else if (uploadingData.type() == SendMediaType::File || uploadingData.type() == SendMediaType::WallPaper || uploadingData.type() == SendMediaType::Audio) { @@ -364,7 +364,7 @@ void Uploader::sendNext() { file, thumb }); } else { - _documentReady.fire({ uploadingId, silent, file }); + _documentReady.fire({ uploadingId, silent, file, uploadingData.file->edit }); } } else if (uploadingData.type() == SendMediaType::Secure) { _secureReady.fire({ diff --git a/Telegram/SourceFiles/storage/file_upload.h b/Telegram/SourceFiles/storage/file_upload.h index db474df8e..6b05b7dd6 100644 --- a/Telegram/SourceFiles/storage/file_upload.h +++ b/Telegram/SourceFiles/storage/file_upload.h @@ -19,12 +19,14 @@ struct UploadedPhoto { FullMsgId fullId; bool silent = false; MTPInputFile file; + bool edit = false; }; struct UploadedDocument { FullMsgId fullId; bool silent = false; MTPInputFile file; + bool edit = false; }; struct UploadedThumbDocument { @@ -32,6 +34,7 @@ struct UploadedThumbDocument { bool silent = false; MTPInputFile file; MTPInputFile thumb; + bool edit = false; }; struct UploadSecureProgress { diff --git a/Telegram/SourceFiles/storage/localimageloader.cpp b/Telegram/SourceFiles/storage/localimageloader.cpp index 3179dfec8..b5c82c4ae 100644 --- a/Telegram/SourceFiles/storage/localimageloader.cpp +++ b/Telegram/SourceFiles/storage/localimageloader.cpp @@ -528,7 +528,8 @@ FileLoadTask::FileLoadTask( SendMediaType type, const FileLoadTo &to, const TextWithTags &caption, - std::shared_ptr album) + std::shared_ptr album, + std::optional edit) : _id(rand_value()) , _to(to) , _album(std::move(album)) @@ -536,7 +537,8 @@ FileLoadTask::FileLoadTask( , _content(content) , _information(std::move(information)) , _type(type) -, _caption(caption) { +, _caption(caption) +, _edit(edit) { } FileLoadTask::FileLoadTask( @@ -697,6 +699,8 @@ void FileLoadTask::process() { _caption, _album); + _result->edit = _edit.value_or(false); + QString filename, filemime; qint64 filesize = 0; QByteArray filedata; diff --git a/Telegram/SourceFiles/storage/localimageloader.h b/Telegram/SourceFiles/storage/localimageloader.h index b4b849b74..6b25d6d12 100644 --- a/Telegram/SourceFiles/storage/localimageloader.h +++ b/Telegram/SourceFiles/storage/localimageloader.h @@ -228,6 +228,8 @@ struct FileLoadResult { PreparedPhotoThumbs photoThumbs; TextWithTags caption; + bool edit = false; + void setFileData(const QByteArray &filedata); void setThumbData(const QByteArray &thumbdata); @@ -273,7 +275,8 @@ public: SendMediaType type, const FileLoadTo &to, const TextWithTags &caption, - std::shared_ptr album = nullptr); + std::shared_ptr album = nullptr, + std::optional edit = false); FileLoadTask( const QByteArray &voice, int32 duration, @@ -320,6 +323,7 @@ private: VoiceWaveform _waveform; SendMediaType _type; TextWithTags _caption; + std::optional _edit; std::shared_ptr _result;