diff --git a/Telegram/SourceFiles/data/data_photo.cpp b/Telegram/SourceFiles/data/data_photo.cpp index c382511f8..44f9f00e4 100644 --- a/Telegram/SourceFiles/data/data_photo.cpp +++ b/Telegram/SourceFiles/data/data_photo.cpp @@ -478,8 +478,20 @@ PhotoClickHandler::PhotoClickHandler( , _peer(peer) { } +PhotoOpenClickHandler::PhotoOpenClickHandler( + not_null photo, + Fn &&callback) +: PhotoClickHandler(photo) +, _handler(std::move(callback)) { +} + void PhotoOpenClickHandler::onClickImpl() const { - Core::App().showPhoto(this); + if (_handler) { + _handler(); + } +} + +void PhotoOpenClickHandlerOld::onClickImpl() const { } void PhotoSaveClickHandler::onClickImpl() const { diff --git a/Telegram/SourceFiles/data/data_photo.h b/Telegram/SourceFiles/data/data_photo.h index bcd3f9ccf..8fafcff7a 100644 --- a/Telegram/SourceFiles/data/data_photo.h +++ b/Telegram/SourceFiles/data/data_photo.h @@ -197,6 +197,18 @@ private: }; class PhotoOpenClickHandler : public PhotoClickHandler { +public: + PhotoOpenClickHandler(not_null photo, Fn &&callback); + +protected: + void onClickImpl() const override; + +private: + Fn _handler; + +}; + +class PhotoOpenClickHandlerOld : public PhotoClickHandler { public: using PhotoClickHandler::PhotoClickHandler; 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 22f855017..d3ae6b762 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -602,6 +602,12 @@ void InnerWidget::elementShowPollResults( FullMsgId context) { } +void InnerWidget::elementOpenPhoto( + not_null photo, + FullMsgId context) { + _controller->openPhoto(photo, context); +} + 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 bc7b0d3f0..62180739b 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -108,6 +108,9 @@ public: void elementShowPollResults( not_null poll, FullMsgId context) override; + void elementOpenPhoto( + not_null photo, + 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 80a73756d..6a12fc17d 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2567,6 +2567,12 @@ void HistoryInner::elementShowPollResults( _controller->showPollResults(poll, context); } +void HistoryInner::elementOpenPhoto( + not_null photo, + FullMsgId context) { + _controller->openPhoto(photo, context); +} + void HistoryInner::elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) { @@ -3445,6 +3451,13 @@ not_null HistoryInner::ElementDelegate() { Instance->elementShowPollResults(poll, context); } } + void elementOpenPhoto( + not_null photo, + FullMsgId context) override { + if (Instance) { + Instance->elementOpenPhoto(photo, 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 f60b284ee..54ebef43c 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -88,6 +88,9 @@ public: void elementShowPollResults( not_null poll, FullMsgId context); + void elementOpenPhoto( + not_null photo, + 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 fe27ee04f..507c8d793 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -107,6 +107,11 @@ void SimpleElementDelegate::elementShowPollResults( FullMsgId context) { } +void SimpleElementDelegate::elementOpenPhoto( + not_null photo, + 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 cf7103c92..e56b1010a 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -60,6 +60,9 @@ public: virtual void elementShowPollResults( not_null poll, FullMsgId context) = 0; + virtual void elementOpenPhoto( + not_null photo, + FullMsgId context) = 0; virtual void elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) = 0; @@ -97,6 +100,9 @@ public: void elementShowPollResults( not_null poll, FullMsgId context) override; + void elementOpenPhoto( + not_null photo, + 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 a558c462f..8788cc780 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1300,6 +1300,12 @@ void ListWidget::elementShowPollResults( _controller->showPollResults(poll, context); } +void ListWidget::elementOpenPhoto( + not_null photo, + FullMsgId context) { + _controller->openPhoto(photo, context); +} + 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 debb2099c..56ae57d0d 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -234,6 +234,9 @@ public: void elementShowPollResults( not_null poll, FullMsgId context) override; + void elementOpenPhoto( + not_null photo, + FullMsgId context) override; void elementShowTooltip( const TextWithEntities &text, Fn hiddenCallback) override; diff --git a/Telegram/SourceFiles/history/view/media/history_view_file.cpp b/Telegram/SourceFiles/history/view/media/history_view_file.cpp index a32d63dc2..78dea0fb1 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_file.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_file.cpp @@ -39,7 +39,7 @@ void File::clickHandlerPressedChanged( } void File::setLinks( - FileClickHandlerPtr &&openl, + ClickHandlerPtr &&openl, FileClickHandlerPtr &&savel, FileClickHandlerPtr &&cancell) { _openl = std::move(openl); @@ -49,7 +49,6 @@ void File::setLinks( void File::refreshParentId(not_null realParent) { const auto contextId = realParent->fullId(); - _openl->setMessageId(contextId); _savel->setMessageId(contextId); _cancell->setMessageId(contextId); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_file.h b/Telegram/SourceFiles/history/view/media/history_view_file.h index 0e6574f1a..1a1542132 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_file.h +++ b/Telegram/SourceFiles/history/view/media/history_view_file.h @@ -13,7 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace HistoryView { -class File : public Media { +class File : public Media, public base::has_weak_ptr { public: File( not_null parent, @@ -44,10 +44,11 @@ protected: using FileClickHandlerPtr = std::shared_ptr; not_null _realParent; - FileClickHandlerPtr _openl, _savel, _cancell; + ClickHandlerPtr _openl; + FileClickHandlerPtr _savel, _cancell; void setLinks( - FileClickHandlerPtr &&openl, + ClickHandlerPtr &&openl, FileClickHandlerPtr &&savel, FileClickHandlerPtr &&cancell); void setDocumentLinks( diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp index e72f121d6..2095b9419 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -86,7 +86,9 @@ Photo::~Photo() { void Photo::create(FullMsgId contextId, PeerData *chat) { setLinks( - std::make_shared(_data, contextId, chat), + std::make_shared(_data, crl::guard(this, [=] { + showPhoto(); + })), std::make_shared(_data, contextId, chat), std::make_shared(_data, contextId, chat)); if ((_dataMedia = _data->activeMediaView())) { @@ -771,7 +773,7 @@ void Photo::playAnimation(bool autoplay) { if (_streamed && autoplay) { return; } else if (_streamed && videoAutoplayEnabled()) { - Core::App().showPhoto(_data, _parent->data()); + showPhoto(); return; } if (_streamed) { @@ -844,4 +846,10 @@ void Photo::parentTextUpdated() { history()->owner().requestViewResize(_parent); } +void Photo::showPhoto() { + _parent->delegate()->elementOpenPhoto( + _data, + _parent->data()->fullId()); +} + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.h b/Telegram/SourceFiles/history/view/media/history_view_photo.h index b0acad447..c127b438e 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.h +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.h @@ -102,6 +102,8 @@ protected: private: struct Streamed; + void showPhoto(); + void create(FullMsgId contextId, PeerData *chat = nullptr); void playAnimation(bool autoplay) override; diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index b0d43e532..b26d4ab9f 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -272,7 +272,7 @@ Photo::Photo( not_null photo) : ItemBase(delegate, parent) , _data(photo) -, _link(std::make_shared(photo, parent->fullId())) { +, _link(std::make_shared(photo, parent->fullId())) { if (_data->inlineThumbnailBytes().isEmpty() && (_data->hasExact(Data::PhotoSize::Small) || _data->hasExact(Data::PhotoSize::Thumbnail))) { @@ -1461,7 +1461,7 @@ Link::Link( } 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()); } else { diff --git a/Telegram/SourceFiles/ui/special_buttons.cpp b/Telegram/SourceFiles/ui/special_buttons.cpp index adb725d43..eaf659a61 100644 --- a/Telegram/SourceFiles/ui/special_buttons.cpp +++ b/Telegram/SourceFiles/ui/special_buttons.cpp @@ -293,8 +293,8 @@ void UserpicButton::openPeerPhoto() { return; } const auto photo = _peer->owner().photo(id); - if (photo->date) { - Core::App().showPhoto(photo, _peer); + if (photo->date && _controller) { + _controller->openPhoto(photo, _peer); } }