From dc0aaec4a4dee5afa20c4cae052784da734044ed Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 17 Jun 2021 00:31:15 +0300 Subject: [PATCH] Added ability to show document from Controller for sections. --- Telegram/SourceFiles/data/data_document.cpp | 20 +++++++++++++++---- Telegram/SourceFiles/data/data_document.h | 16 ++++++++++++++- .../admin_log/history_admin_log_inner.cpp | 7 +++++++ .../admin_log/history_admin_log_inner.h | 4 ++++ .../history/history_inner_widget.cpp | 18 +++++++++++++++++ .../history/history_inner_widget.h | 4 ++++ .../history/view/history_view_element.cpp | 6 ++++++ .../history/view/history_view_element.h | 8 ++++++++ .../history/view/history_view_list_widget.cpp | 7 +++++++ .../history/view/history_view_list_widget.h | 4 ++++ .../view/media/history_view_document.cpp | 4 +--- .../history/view/media/history_view_file.cpp | 7 ++++++- .../view/media/history_view_sticker.cpp | 6 +++++- .../SourceFiles/overview/overview_layout.cpp | 8 ++++---- .../window/window_session_controller.cpp | 9 ++++++++- .../window/window_session_controller.h | 5 ++++- 16 files changed, 117 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index c09ea3d2e0..23be795395 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -316,6 +316,22 @@ DocumentClickHandler::DocumentClickHandler( , _document(document) { } +DocumentOpenClickHandler::DocumentOpenClickHandler( + not_null document, + Fn &&callback) +: DocumentClickHandler(document) +, _handler(std::move(callback)) { +} + +void DocumentOpenClickHandler::onClickImpl() const { + if (_handler) { + _handler(); + } +} + +void DocumentOpenClickHandlerOld::onClickImpl() const { +} + void DocumentOpenClickHandler::Open( Data::FileOrigin origin, not_null data, @@ -323,10 +339,6 @@ void DocumentOpenClickHandler::Open( Data::ResolveDocument(data, context); } -void DocumentOpenClickHandler::onClickImpl() const { - Open(context(), document(), getActionItem()); -} - void DocumentSaveClickHandler::Save( Data::FileOrigin origin, not_null data, diff --git a/Telegram/SourceFiles/data/data_document.h b/Telegram/SourceFiles/data/data_document.h index 92cd8ba306..eae0e94d38 100644 --- a/Telegram/SourceFiles/data/data_document.h +++ b/Telegram/SourceFiles/data/data_document.h @@ -362,7 +362,9 @@ protected: class DocumentOpenClickHandler : public DocumentClickHandler { public: - using DocumentClickHandler::DocumentClickHandler; + DocumentOpenClickHandler( + not_null document, + Fn &&callback); static void Open( Data::FileOrigin origin, not_null document, @@ -371,6 +373,18 @@ public: protected: void onClickImpl() const override; +private: + Fn _handler; + +}; + +class DocumentOpenClickHandlerOld : public DocumentClickHandler { +public: + using DocumentClickHandler::DocumentClickHandler; + +protected: + void onClickImpl() const override; + }; class DocumentCancelClickHandler : public DocumentClickHandler { 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 d3ae6b762b..094e4e5279 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -608,6 +608,13 @@ void InnerWidget::elementOpenPhoto( _controller->openPhoto(photo, context); } +void InnerWidget::elementOpenDocument( + not_null document, + FullMsgId context, + bool showInMediaView) { + _controller->openDocument(document, context, showInMediaView); +} + 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 62180739bb..7142fe6f42 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -111,6 +111,10 @@ public: void elementOpenPhoto( not_null photo, FullMsgId context) override; + void elementOpenDocument( + not_null document, + FullMsgId context, + bool showInMediaView = false) 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 6a12fc17d4..5a08d51be3 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2573,6 +2573,13 @@ void HistoryInner::elementOpenPhoto( _controller->openPhoto(photo, context); } +void HistoryInner::elementOpenDocument( + not_null document, + FullMsgId context, + bool showInMediaView) { + _controller->openDocument(document, context, showInMediaView); +} + void HistoryInner::elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) { @@ -3458,6 +3465,17 @@ not_null HistoryInner::ElementDelegate() { Instance->elementOpenPhoto(photo, context); } } + void elementOpenDocument( + not_null document, + FullMsgId context, + bool showInMediaView = false) override { + if (Instance) { + Instance->elementOpenDocument( + document, + context, + showInMediaView); + } + } 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 54ebef43c9..0c3517b91b 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -91,6 +91,10 @@ public: void elementOpenPhoto( not_null photo, FullMsgId context); + void elementOpenDocument( + not_null document, + FullMsgId context, + bool showInMediaView = false); 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 507c8d793e..b2387373a0 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -112,6 +112,12 @@ void SimpleElementDelegate::elementOpenPhoto( FullMsgId context) { } +void SimpleElementDelegate::elementOpenDocument( + not_null document, + FullMsgId context, + bool showInMediaView) { +} + 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 e56b1010ac..c1f5d13e00 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -63,6 +63,10 @@ public: virtual void elementOpenPhoto( not_null photo, FullMsgId context) = 0; + virtual void elementOpenDocument( + not_null document, + FullMsgId context, + bool showInMediaView = false) = 0; virtual void elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) = 0; @@ -103,6 +107,10 @@ public: void elementOpenPhoto( not_null photo, FullMsgId context) override; + void elementOpenDocument( + not_null document, + FullMsgId context, + bool showInMediaView = false) 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 8788cc7801..3a3d6e524c 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1306,6 +1306,13 @@ void ListWidget::elementOpenPhoto( _controller->openPhoto(photo, context); } +void ListWidget::elementOpenDocument( + not_null document, + FullMsgId context, + bool showInMediaView) { + _controller->openDocument(document, context, showInMediaView); +} + 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 56ae57d0d8..af4bf4d87b 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -237,6 +237,10 @@ public: void elementOpenPhoto( not_null photo, FullMsgId context) override; + void elementOpenDocument( + not_null document, + FullMsgId context, + bool showInMediaView = false) 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 c48f410ca2..b915e6c28e 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -220,9 +220,7 @@ void Document::createComponents(bool caption) { _realParent->fullId()); } if (const auto voice = Get()) { - voice->_seekl = std::make_shared( - _data, - _realParent->fullId()); + voice->_seekl = std::make_shared(_data, [] {}); } } diff --git a/Telegram/SourceFiles/history/view/media/history_view_file.cpp b/Telegram/SourceFiles/history/view/media/history_view_file.cpp index 78dea0fb1b..f5c82f92c2 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_file.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_file.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/format_values.h" #include "history/history_item.h" #include "history/history.h" +#include "history/view/history_view_element.h" #include "data/data_document.h" #include "data/data_session.h" #include "styles/style_chat.h" @@ -103,7 +104,11 @@ void File::setDocumentLinks( not_null realParent) { const auto context = realParent->fullId(); setLinks( - std::make_shared(document, context), + std::make_shared( + document, + crl::guard(this, [=] { + _parent->delegate()->elementOpenDocument(document, context); + })), std::make_shared(document, context), std::make_shared(document, context)); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index 24f4829c35..e9f0e3d685 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -286,7 +286,11 @@ void Sticker::refreshLink() { // .webp image and we allow to open it in media viewer. _link = std::make_shared( _data, - _parent->data()->fullId()); + crl::guard(this, [=] { + _parent->delegate()->elementOpenDocument( + _data, + _parent->data()->fullId()); + })); } } diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index b26d4ab9fb..2361ba6232 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -185,7 +185,7 @@ void RadialProgressItem::setDocumentLinks( not_null document) { const auto context = parent()->fullId(); setLinks( - std::make_shared(document, context), + std::make_shared(document, context), std::make_shared(document, context), std::make_shared(document, context)); } @@ -593,7 +593,7 @@ Voice::Voice( const style::OverviewFileLayout &st) : RadialProgressItem(delegate, parent) , _data(voice) -, _namel(std::make_shared(_data, parent->fullId())) +, _namel(std::make_shared(_data, parent->fullId())) , _st(st) { AddComponents(Info::Bit()); @@ -900,7 +900,7 @@ Document::Document( : RadialProgressItem(delegate, parent) , _data(document) , _msgl(goToMessageClickHandler(parent)) -, _namel(std::make_shared(_data, parent->fullId())) +, _namel(std::make_shared(_data, parent->fullId())) , _st(st) , _date(langDateTime(base::unixtime::parse(_data->date))) , _datew(st::normalFont->width(_date)) @@ -1452,7 +1452,7 @@ Link::Link( if (_page) { mainUrl = _page->url; if (_page->document) { - _photol = std::make_shared( + _photol = std::make_shared( _page->document, parent->fullId()); } else if (_page->photo) { diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 05b0d28191..51bc0f6882 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -1235,8 +1235,15 @@ void SessionController::openPhoto( void SessionController::openDocument( not_null document, - FullMsgId contextId) { + FullMsgId contextId, + bool showInMediaView) { // TEMP. + if (showInMediaView) { + _window->openInMediaView(Media::View::OpenRequest( + document, + session().data().message(contextId))); + return; + } Data::ResolveDocument(document, session().data().message(contextId)); } diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index ffa6e047b5..d33526c7da 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -349,7 +349,10 @@ public: void openPhoto(not_null photo, FullMsgId contextId); void openPhoto(not_null photo, not_null peer); - void openDocument(not_null document, FullMsgId contextId); + void openDocument( + not_null document, + FullMsgId contextId, + bool showInMediaView = false); void showChooseReportMessages( not_null peer,