From 8591d587985cf063d8a1ea48916b63c19e582b18 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 14 Jun 2021 09:51:14 +0300 Subject: [PATCH] Added ability to show content from Controller for Shared Media. --- Telegram/SourceFiles/data/data_document.cpp | 3 -- Telegram/SourceFiles/data/data_document.h | 9 ----- Telegram/SourceFiles/data/data_photo.cpp | 3 -- Telegram/SourceFiles/data/data_photo.h | 9 ----- .../info/media/info_media_list_widget.cpp | 10 ++++++ .../info/media/info_media_list_widget.h | 5 +++ .../SourceFiles/overview/overview_layout.cpp | 34 ++++++++++++++----- .../SourceFiles/overview/overview_layout.h | 2 +- .../overview/overview_layout_delegate.h | 5 +++ 9 files changed, 47 insertions(+), 33 deletions(-) diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 23be79539..b26c83310 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -329,9 +329,6 @@ void DocumentOpenClickHandler::onClickImpl() const { } } -void DocumentOpenClickHandlerOld::onClickImpl() const { -} - void DocumentOpenClickHandler::Open( Data::FileOrigin origin, not_null data, diff --git a/Telegram/SourceFiles/data/data_document.h b/Telegram/SourceFiles/data/data_document.h index eae0e94d3..9cd08a313 100644 --- a/Telegram/SourceFiles/data/data_document.h +++ b/Telegram/SourceFiles/data/data_document.h @@ -378,15 +378,6 @@ private: }; -class DocumentOpenClickHandlerOld : public DocumentClickHandler { -public: - using DocumentClickHandler::DocumentClickHandler; - -protected: - void onClickImpl() const override; - -}; - class DocumentCancelClickHandler : public DocumentClickHandler { public: using DocumentClickHandler::DocumentClickHandler; diff --git a/Telegram/SourceFiles/data/data_photo.cpp b/Telegram/SourceFiles/data/data_photo.cpp index 44f9f00e4..90e434f81 100644 --- a/Telegram/SourceFiles/data/data_photo.cpp +++ b/Telegram/SourceFiles/data/data_photo.cpp @@ -491,9 +491,6 @@ void PhotoOpenClickHandler::onClickImpl() const { } } -void PhotoOpenClickHandlerOld::onClickImpl() const { -} - void PhotoSaveClickHandler::onClickImpl() const { const auto data = photo(); if (!data->date) { diff --git a/Telegram/SourceFiles/data/data_photo.h b/Telegram/SourceFiles/data/data_photo.h index 8fafcff7a..db244f952 100644 --- a/Telegram/SourceFiles/data/data_photo.h +++ b/Telegram/SourceFiles/data/data_photo.h @@ -208,15 +208,6 @@ private: }; -class PhotoOpenClickHandlerOld : public PhotoClickHandler { -public: - using PhotoClickHandler::PhotoClickHandler; - -protected: - void onClickImpl() const override; - -}; - class PhotoSaveClickHandler : public PhotoClickHandler { public: using PhotoClickHandler::PhotoClickHandler; diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index 7b022a4cb..c46d3d5f9 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -887,6 +887,16 @@ void ListWidget::unregisterHeavyItem(not_null item) { } } +void ListWidget::openPhoto(not_null photo, FullMsgId id) { + _controller->parentController()->openPhoto(photo, id); +} + +void ListWidget::openDocument( + not_null document, + FullMsgId id) { + _controller->parentController()->openDocument(document, id); +} + SparseIdsMergedSlice::Key ListWidget::sliceKey( UniversalMsgId universalId) const { using Key = SparseIdsMergedSlice::Key; diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.h b/Telegram/SourceFiles/info/media/info_media_list_widget.h index 146c3b544..8d05a9066 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.h +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.h @@ -79,6 +79,11 @@ public: void registerHeavyItem(not_null item) override; void unregisterHeavyItem(not_null item) override; + void openPhoto(not_null photo, FullMsgId id) override; + void openDocument( + not_null document, + FullMsgId id) override; + private: struct Context; class Section; diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 2361ba623..9cfaa5c49 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -185,7 +185,11 @@ void RadialProgressItem::setDocumentLinks( not_null document) { const auto context = parent()->fullId(); setLinks( - std::make_shared(document, context), + std::make_shared( + document, + crl::guard(this, [=] { + delegate()->openDocument(document, context); + })), std::make_shared(document, context), std::make_shared(document, context)); } @@ -272,7 +276,9 @@ Photo::Photo( not_null photo) : ItemBase(delegate, parent) , _data(photo) -, _link(std::make_shared(photo, parent->fullId())) { +, _link(std::make_shared(photo, crl::guard(this, [=] { + delegate->openPhoto(photo, parent->fullId()); +}))) { if (_data->inlineThumbnailBytes().isEmpty() && (_data->hasExact(Data::PhotoSize::Small) || _data->hasExact(Data::PhotoSize::Thumbnail))) { @@ -593,7 +599,11 @@ Voice::Voice( const style::OverviewFileLayout &st) : RadialProgressItem(delegate, parent) , _data(voice) -, _namel(std::make_shared(_data, parent->fullId())) +, _namel(std::make_shared( + _data, + crl::guard(this, [=] { + delegate->openDocument(_data, parent->fullId()); + }))) , _st(st) { AddComponents(Info::Bit()); @@ -900,7 +910,11 @@ Document::Document( : RadialProgressItem(delegate, parent) , _data(document) , _msgl(goToMessageClickHandler(parent)) -, _namel(std::make_shared(_data, parent->fullId())) +, _namel(std::make_shared( + _data, + crl::guard(this, [=] { + delegate->openDocument(_data, parent->fullId()); + }))) , _st(st) , _date(langDateTime(base::unixtime::parse(_data->date))) , _datew(st::normalFont->width(_date)) @@ -1452,18 +1466,22 @@ Link::Link( if (_page) { mainUrl = _page->url; if (_page->document) { - _photol = std::make_shared( + _photol = std::make_shared( _page->document, - parent->fullId()); + crl::guard(this, [=] { + delegate->openDocument(_page->document, parent->fullId()); + })); } else if (_page->photo) { if (_page->type == WebPageType::Profile || _page->type == WebPageType::Video) { _photol = createHandler(_page->url); } else if (_page->type == WebPageType::Photo || _page->siteName == qstr("Twitter") || _page->siteName == qstr("Facebook")) { - _photol = std::make_shared( + _photol = std::make_shared( _page->photo, - parent->fullId()); + crl::guard(this, [=] { + delegate->openPhoto(_page->photo, parent->fullId()); + })); } else { _photol = createHandler(_page->url); } diff --git a/Telegram/SourceFiles/overview/overview_layout.h b/Telegram/SourceFiles/overview/overview_layout.h index 40bc22903..1d5480f63 100644 --- a/Telegram/SourceFiles/overview/overview_layout.h +++ b/Telegram/SourceFiles/overview/overview_layout.h @@ -40,7 +40,7 @@ public: }; -class ItemBase : public LayoutItemBase { +class ItemBase : public LayoutItemBase, public base::has_weak_ptr { public: ItemBase(not_null delegate, not_null parent); ~ItemBase(); diff --git a/Telegram/SourceFiles/overview/overview_layout_delegate.h b/Telegram/SourceFiles/overview/overview_layout_delegate.h index f57d9d418..e35608821 100644 --- a/Telegram/SourceFiles/overview/overview_layout_delegate.h +++ b/Telegram/SourceFiles/overview/overview_layout_delegate.h @@ -17,6 +17,11 @@ public: virtual void registerHeavyItem(not_null item) = 0; virtual void unregisterHeavyItem(not_null item) = 0; + virtual void openPhoto(not_null photo, FullMsgId id) = 0; + virtual void openDocument( + not_null document, + FullMsgId id) = 0; + }; } // namespace Layout