From 653fd1bb63d072b749c68bd07e1c1c48a805d3e0 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 29 Mar 2019 17:17:46 +0300 Subject: [PATCH] Added initial implementation of cancel of media uploading for editing. --- Telegram/SourceFiles/history/history_item.h | 8 ++++++++ .../SourceFiles/history/history_message.cpp | 19 ++++++++++++++++++- .../SourceFiles/history/history_message.h | 1 + Telegram/SourceFiles/mainwidget.cpp | 11 ++++++++--- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 6a9a5a4e8..8ba04954b 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/runtime_composer.h" #include "base/flags.h" #include "base/value_ordering.h" +#include "data/data_media_types.h" enum class UnreadMentionType; struct HistoryMessageReplyMarkup; @@ -122,10 +123,16 @@ public: bool hasUnreadMediaFlag() const; void markMediaRead(); + bool isEditingMedia() const { + return _isEditingMedia; + } void setIsEditingMedia(bool edit) { _isEditingMedia = edit; } + // For edit media in history_message. + virtual void returnSavedMedia() {}; + // Zero result means this message is not self-destructing right now. virtual crl::time getSelfDestructIn(crl::time now) { return 0; @@ -315,6 +322,7 @@ protected: int _textHeight = 0; bool _isEditingMedia = false; + std::unique_ptr _savedMedia; std::unique_ptr _media; private: diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 964feb0ad..abf9c71ce 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -742,6 +742,7 @@ QString FormatViewsCount(int views) { void HistoryMessage::refreshMedia(const MTPMessageMedia *media) { _media = nullptr; + _savedMedia = nullptr; if (media) { setMedia(*media); } @@ -757,6 +758,19 @@ void HistoryMessage::refreshSentMedia(const MTPMessageMedia *media) { } } +void HistoryMessage::returnSavedMedia() { + if (!_savedMedia) { + return; + } + const auto wasGrouped = history()->owner().groups().isGrouped(this); + _media = std::move(_savedMedia); + if (wasGrouped) { + history()->owner().groups().refreshMessage(this); + } else { + history()->owner().requestItemViewRefresh(this); + } +} + void HistoryMessage::setMedia(const MTPMessageMedia &media) { _media = CreateMedia(this, media); if (const auto invoice = _media ? _media->invoice() : nullptr) { @@ -943,10 +957,13 @@ void HistoryMessage::updateSentMedia(const MTPMessageMedia *media) { _flags &= ~MTPDmessage_ClientFlag::f_from_inline_bot; } else { const auto shouldUpdate = _isEditingMedia ? true : !_media->updateSentMedia(*media); + if (_isEditingMedia) { + _savedMedia = _media->clone(this); + } if (!media || !_media || shouldUpdate) { refreshSentMedia(media); } - _isEditingMedia = false; + // _isEditingMedia = false; } history()->owner().requestItemResize(this); } diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index 9154b59b5..036ad4bff 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -89,6 +89,7 @@ public: void refreshMedia(const MTPMessageMedia *media); void refreshSentMedia(const MTPMessageMedia *media); + void returnSavedMedia() override; void setMedia(const MTPMessageMedia &media); static std::unique_ptr CreateMedia( not_null item, diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index d0c5d98c8..b603a7a34 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -842,11 +842,16 @@ void MainWidget::cancelUploadLayer(not_null item) { Ui::hideLayer(); if (const auto item = App::histItemById(itemId)) { const auto history = item->history(); - //item->destroy(); - history->requestChatListMessage(); + if (!item->isEditingMedia()) { + item->destroy(); + history->requestChatListMessage(); + } else { + item->returnSavedMedia(); + session().uploader().cancel(item->fullId()); + } session().data().sendHistoryChangeNotifications(); } - //session().uploader().unpause(); + session().uploader().unpause(); }; const auto continueUpload = [=] { session().uploader().unpause();