diff --git a/Telegram/SourceFiles/data/data_file_click_handler.cpp b/Telegram/SourceFiles/data/data_file_click_handler.cpp index a128d943f2..191c7b06f5 100644 --- a/Telegram/SourceFiles/data/data_file_click_handler.cpp +++ b/Telegram/SourceFiles/data/data_file_click_handler.cpp @@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_photo.h" #include "data/data_session.h" #include "main/main_session.h" -#include "mainwidget.h" // App::main FileClickHandler::FileClickHandler( not_null session, @@ -111,18 +110,20 @@ void DocumentSaveClickHandler::onClickImpl() const { Save(context(), document()); } +DocumentCancelClickHandler::DocumentCancelClickHandler( + not_null document, + Fn &&callback, + FullMsgId context) +: DocumentClickHandler(document, context) +, _handler(std::move(callback)) { +} + void DocumentCancelClickHandler::onClickImpl() const { const auto data = document(); if (!data->date) { return; - } else if (data->uploading()) { - if (const auto item = data->owner().message(context())) { - if (const auto m = App::main()) { // multi good - if (&m->session() == &data->session()) { - m->cancelUploadLayer(item); - } - } - } + } else if (data->uploading() && _handler) { + _handler(context()); } else { data->cancel(); } @@ -191,18 +192,20 @@ void PhotoSaveClickHandler::onClickImpl() const { } } +PhotoCancelClickHandler::PhotoCancelClickHandler( + not_null photo, + Fn &&callback, + FullMsgId context) +: PhotoClickHandler(photo, context) +, _handler(std::move(callback)) { +} + void PhotoCancelClickHandler::onClickImpl() const { const auto data = photo(); if (!data->date) { return; - } else if (data->uploading()) { - if (const auto item = data->owner().message(context())) { - if (const auto m = App::main()) { // multi good - if (&m->session() == &data->session()) { - m->cancelUploadLayer(item); - } - } - } + } else if (data->uploading() && _handler) { + _handler(context()); } else { data->cancel(); } diff --git a/Telegram/SourceFiles/data/data_file_click_handler.h b/Telegram/SourceFiles/data/data_file_click_handler.h index 33b410e3de..aae526b2c9 100644 --- a/Telegram/SourceFiles/data/data_file_click_handler.h +++ b/Telegram/SourceFiles/data/data_file_click_handler.h @@ -87,11 +87,17 @@ private: class DocumentCancelClickHandler : public DocumentClickHandler { public: - using DocumentClickHandler::DocumentClickHandler; + DocumentCancelClickHandler( + not_null document, + Fn &&callback, + FullMsgId context = FullMsgId()); protected: void onClickImpl() const override; +private: + const Fn _handler; + }; class DocumentOpenWithClickHandler : public DocumentClickHandler { @@ -173,9 +179,15 @@ protected: class PhotoCancelClickHandler : public PhotoClickHandler { public: - using PhotoClickHandler::PhotoClickHandler; + PhotoCancelClickHandler( + not_null photo, + Fn &&callback, + FullMsgId context = FullMsgId()); protected: void onClickImpl() const override; +private: + const Fn _handler; + }; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index d37a2cef8c..1cbbc03ced 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -616,6 +616,12 @@ void InnerWidget::elementOpenDocument( _controller->openDocument(document, context, showInMediaView); } +void InnerWidget::elementCancelUpload(const FullMsgId &context) { + if (const auto item = session().data().message(context)) { + _controller->content()->cancelUploadLayer(item); + } +} + void InnerWidget::elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) { diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h index 7142fe6f42..85b24efff4 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -115,6 +115,7 @@ public: not_null document, FullMsgId context, bool showInMediaView = false) override; + void elementCancelUpload(const FullMsgId &context) override; void elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) override; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 87c675827b..1a6e6cbf8a 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2581,6 +2581,12 @@ void HistoryInner::elementOpenDocument( _controller->openDocument(document, context, showInMediaView); } +void HistoryInner::elementCancelUpload(const FullMsgId &context) { + if (const auto item = session().data().message(context)) { + _controller->content()->cancelUploadLayer(item); + } +} + void HistoryInner::elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) { @@ -3477,6 +3483,11 @@ not_null HistoryInner::ElementDelegate() { showInMediaView); } } + void elementCancelUpload(const FullMsgId &context) override { + if (Instance) { + Instance->elementCancelUpload(context); + } + } void elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) override { diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index 0c3517b91b..39952148dd 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -95,6 +95,7 @@ public: not_null document, FullMsgId context, bool showInMediaView = false); + void elementCancelUpload(const FullMsgId &context); void elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback); diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index b2387373a0..2e94df4e61 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -118,6 +118,9 @@ void SimpleElementDelegate::elementOpenDocument( bool showInMediaView) { } +void SimpleElementDelegate::elementCancelUpload(const FullMsgId &context) { +} + void SimpleElementDelegate::elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) { diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index c1f5d13e00..d7a2f6a458 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -67,6 +67,7 @@ public: not_null document, FullMsgId context, bool showInMediaView = false) = 0; + virtual void elementCancelUpload(const FullMsgId &context) = 0; virtual void elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) = 0; @@ -111,6 +112,7 @@ public: not_null document, FullMsgId context, bool showInMediaView = false) override; + void elementCancelUpload(const FullMsgId &context) override; void elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) override; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index d38f4817ac..506fb1d090 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1314,6 +1314,12 @@ void ListWidget::elementOpenDocument( _controller->openDocument(document, context, showInMediaView); } +void ListWidget::elementCancelUpload(const FullMsgId &context) { + if (const auto item = session().data().message(context)) { + _controller->content()->cancelUploadLayer(item); + } +} + void ListWidget::elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) { diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index af4bf4d87b..a9a04bf433 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -241,6 +241,7 @@ public: not_null document, FullMsgId context, bool showInMediaView = false) override; + void elementCancelUpload(const FullMsgId &context) override; void elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) override; diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index 46774f047b..2a5be9ee11 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -218,6 +218,9 @@ void Document::createComponents(bool caption) { _realParent->fullId()); thumbed->_linkcancell = std::make_shared( _data, + crl::guard(this, [=](FullMsgId id) { + _parent->delegate()->elementCancelUpload(id); + }), _realParent->fullId()); } if (const auto voice = Get()) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_file.cpp b/Telegram/SourceFiles/history/view/media/history_view_file.cpp index 21a583f942..45cc23e052 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_file.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_file.cpp @@ -120,7 +120,12 @@ void File::setDocumentLinks( }), context), std::make_shared(document, context), - std::make_shared(document, context)); + std::make_shared( + document, + crl::guard(this, [=](FullMsgId id) { + _parent->delegate()->elementCancelUpload(id); + }), + context)); } File::~File() = default; diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp index a738896462..3047e1cfb3 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -92,7 +92,12 @@ void Photo::create(FullMsgId contextId, PeerData *chat) { crl::guard(this, [=](FullMsgId id) { showPhoto(id); }), contextId), std::make_shared(_data, contextId, chat), - std::make_shared(_data, contextId, chat)); + std::make_shared( + _data, + crl::guard(this, [=](FullMsgId id) { + _parent->delegate()->elementCancelUpload(id); + }), + contextId)); if ((_dataMedia = _data->activeMediaView())) { dataMediaCreated(); } else if (_data->inlineThumbnailBytes().isEmpty() diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp index 110901d8f7..f3c593d1eb 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_result.cpp @@ -343,9 +343,9 @@ Media::View::OpenRequest Result::openRequest() { void Result::cancelFile() { if (_document) { - DocumentCancelClickHandler(_document).onClick({}); + DocumentCancelClickHandler(_document, nullptr).onClick({}); } else if (_photo) { - PhotoCancelClickHandler(_photo).onClick({}); + PhotoCancelClickHandler(_photo, nullptr).onClick({}); } } diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 2a70527b4e..dd7b7fcb26 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -193,7 +193,10 @@ void RadialProgressItem::setDocumentLinks( }), context), std::make_shared(document, context), - std::make_shared(document, context)); + std::make_shared( + document, + nullptr, + context)); } void RadialProgressItem::clickHandlerActiveChanged(