From 6c56fad180fb42c1bbe17449611b2802fff767d6 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 18 Jun 2021 07:22:47 +0300 Subject: [PATCH] Fixed updating of parent id for file click handlers. Fixed #16447. --- .../data/data_file_click_handler.cpp | 20 ++++----- .../data/data_file_click_handler.h | 12 ++++-- .../view/media/history_view_document.cpp | 4 +- .../history/view/media/history_view_file.cpp | 10 +++-- .../history/view/media/history_view_file.h | 5 +-- .../history/view/media/history_view_photo.cpp | 15 ++++--- .../history/view/media/history_view_photo.h | 2 +- .../view/media/history_view_sticker.cpp | 9 ++-- .../media/view/media_view_overlay_widget.cpp | 4 +- .../SourceFiles/overview/overview_layout.cpp | 42 +++++++++++-------- 10 files changed, 66 insertions(+), 57 deletions(-) diff --git a/Telegram/SourceFiles/data/data_file_click_handler.cpp b/Telegram/SourceFiles/data/data_file_click_handler.cpp index bae51c79e..a128d943f 100644 --- a/Telegram/SourceFiles/data/data_file_click_handler.cpp +++ b/Telegram/SourceFiles/data/data_file_click_handler.cpp @@ -62,15 +62,15 @@ DocumentClickHandler::DocumentClickHandler( DocumentOpenClickHandler::DocumentOpenClickHandler( not_null document, - Fn &&callback) -: DocumentClickHandler(document) + Fn &&callback, + FullMsgId context) +: DocumentClickHandler(document, context) , _handler(std::move(callback)) { + Expects(_handler != nullptr); } void DocumentOpenClickHandler::onClickImpl() const { - if (_handler) { - _handler(); - } + _handler(context()); } void DocumentSaveClickHandler::Save( @@ -170,15 +170,15 @@ PeerData *PhotoClickHandler::peer() const { PhotoOpenClickHandler::PhotoOpenClickHandler( not_null photo, - Fn &&callback) -: PhotoClickHandler(photo) + Fn &&callback, + FullMsgId context) +: PhotoClickHandler(photo, context) , _handler(std::move(callback)) { + Expects(_handler != nullptr); } void PhotoOpenClickHandler::onClickImpl() const { - if (_handler) { - _handler(); - } + _handler(context()); } void PhotoSaveClickHandler::onClickImpl() const { diff --git a/Telegram/SourceFiles/data/data_file_click_handler.h b/Telegram/SourceFiles/data/data_file_click_handler.h index 7d1f7ff81..33b410e3d 100644 --- a/Telegram/SourceFiles/data/data_file_click_handler.h +++ b/Telegram/SourceFiles/data/data_file_click_handler.h @@ -74,13 +74,14 @@ class DocumentOpenClickHandler : public DocumentClickHandler { public: DocumentOpenClickHandler( not_null document, - Fn &&callback); + Fn &&callback, + FullMsgId context = FullMsgId()); protected: void onClickImpl() const override; private: - Fn _handler; + const Fn _handler; }; @@ -148,13 +149,16 @@ private: class PhotoOpenClickHandler : public PhotoClickHandler { public: - PhotoOpenClickHandler(not_null photo, Fn &&callback); + PhotoOpenClickHandler( + not_null photo, + Fn &&callback, + FullMsgId context = FullMsgId()); protected: void onClickImpl() const override; private: - Fn _handler; + const Fn _handler; }; diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index 52b5f2a28..46774f047 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -221,7 +221,9 @@ void Document::createComponents(bool caption) { _realParent->fullId()); } if (const auto voice = Get()) { - voice->_seekl = std::make_shared(_data, [] {}); + voice->_seekl = std::make_shared( + _data, + [](FullMsgId) {}); } } diff --git a/Telegram/SourceFiles/history/view/media/history_view_file.cpp b/Telegram/SourceFiles/history/view/media/history_view_file.cpp index 4ea0ec3c1..21a583f94 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_file.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_file.cpp @@ -48,7 +48,7 @@ void File::clickHandlerPressedChanged( } void File::setLinks( - ClickHandlerPtr &&openl, + FileClickHandlerPtr &&openl, FileClickHandlerPtr &&savel, FileClickHandlerPtr &&cancell) { _openl = std::move(openl); @@ -58,6 +58,7 @@ void File::setLinks( void File::refreshParentId(not_null realParent) { const auto contextId = realParent->fullId(); + _openl->setMessageId(contextId); _savel->setMessageId(contextId); _cancell->setMessageId(contextId); } @@ -114,9 +115,10 @@ void File::setDocumentLinks( setLinks( std::make_shared( document, - crl::guard(this, [=] { - _parent->delegate()->elementOpenDocument(document, context); - })), + crl::guard(this, [=](FullMsgId id) { + _parent->delegate()->elementOpenDocument(document, id); + }), + context), std::make_shared(document, context), std::make_shared(document, context)); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_file.h b/Telegram/SourceFiles/history/view/media/history_view_file.h index ef097254b..a425d7305 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_file.h +++ b/Telegram/SourceFiles/history/view/media/history_view_file.h @@ -44,11 +44,10 @@ protected: using FileClickHandlerPtr = std::shared_ptr; not_null _realParent; - ClickHandlerPtr _openl; - FileClickHandlerPtr _savel, _cancell; + FileClickHandlerPtr _openl, _savel, _cancell; void setLinks( - ClickHandlerPtr &&openl, + FileClickHandlerPtr &&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 db755a43f..a73889646 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -87,9 +87,10 @@ Photo::~Photo() { void Photo::create(FullMsgId contextId, PeerData *chat) { setLinks( - std::make_shared(_data, crl::guard(this, [=] { - showPhoto(); - })), + std::make_shared( + _data, + crl::guard(this, [=](FullMsgId id) { showPhoto(id); }), + contextId), std::make_shared(_data, contextId, chat), std::make_shared(_data, contextId, chat)); if ((_dataMedia = _data->activeMediaView())) { @@ -774,7 +775,7 @@ void Photo::playAnimation(bool autoplay) { if (_streamed && autoplay) { return; } else if (_streamed && videoAutoplayEnabled()) { - showPhoto(); + showPhoto(_parent->data()->fullId()); return; } if (_streamed) { @@ -847,10 +848,8 @@ void Photo::parentTextUpdated() { history()->owner().requestViewResize(_parent); } -void Photo::showPhoto() { - _parent->delegate()->elementOpenPhoto( - _data, - _parent->data()->fullId()); +void Photo::showPhoto(FullMsgId id) { + _parent->delegate()->elementOpenPhoto(_data, id); } } // 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 c127b438e..04dc9726b 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.h +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.h @@ -102,7 +102,7 @@ protected: private: struct Streamed; - void showPhoto(); + void showPhoto(FullMsgId id); void create(FullMsgId contextId, PeerData *chat = nullptr); diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index bea40fe9c..c6982bfdc 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -287,11 +287,10 @@ void Sticker::refreshLink() { // .webp image and we allow to open it in media viewer. _link = std::make_shared( _data, - crl::guard(this, [=] { - _parent->delegate()->elementOpenDocument( - _data, - _parent->data()->fullId()); - })); + crl::guard(this, [=](FullMsgId id) { + _parent->delegate()->elementOpenDocument(_data, id); + }), + _parent->data()->fullId()); } } diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 6f2b894d9..5e36d6039 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -2276,9 +2276,7 @@ void OverlayWidget::show(OpenRequest request) { } clearControlsState(); - if (contextPeer) { - _firstOpenedPeerPhoto = true; - } + _firstOpenedPeerPhoto = (contextPeer != nullptr); assignMediaPointer(photo); displayPhoto(photo, contextPeer ? nullptr : contextItem); diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 5c0961987..2a70527b4 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -188,9 +188,10 @@ void RadialProgressItem::setDocumentLinks( setLinks( std::make_shared( document, - crl::guard(this, [=] { - delegate()->openDocument(document, context); - })), + crl::guard(this, [=](FullMsgId id) { + delegate()->openDocument(document, id); + }), + context), std::make_shared(document, context), std::make_shared(document, context)); } @@ -277,9 +278,10 @@ Photo::Photo( not_null photo) : ItemBase(delegate, parent) , _data(photo) -, _link(std::make_shared(photo, crl::guard(this, [=] { - delegate->openPhoto(photo, parent->fullId()); -}))) { +, _link(std::make_shared( + photo, + crl::guard(this, [=](FullMsgId id) { delegate->openPhoto(photo, id); }), + parent->fullId())) { if (_data->inlineThumbnailBytes().isEmpty() && (_data->hasExact(Data::PhotoSize::Small) || _data->hasExact(Data::PhotoSize::Thumbnail))) { @@ -602,9 +604,10 @@ Voice::Voice( , _data(voice) , _namel(std::make_shared( _data, - crl::guard(this, [=] { - delegate->openDocument(_data, parent->fullId()); - }))) + crl::guard(this, [=](FullMsgId id) { + delegate->openDocument(_data, id); + }), + parent->fullId())) , _st(st) { AddComponents(Info::Bit()); @@ -913,9 +916,10 @@ Document::Document( , _msgl(goToMessageClickHandler(parent)) , _namel(std::make_shared( _data, - crl::guard(this, [=] { - delegate->openDocument(_data, parent->fullId()); - }))) + crl::guard(this, [=](FullMsgId id) { + delegate->openDocument(_data, id); + }), + parent->fullId())) , _st(st) , _date(langDateTime(base::unixtime::parse(_data->date))) , _datew(st::normalFont->width(_date)) @@ -1469,9 +1473,10 @@ Link::Link( if (_page->document) { _photol = std::make_shared( _page->document, - crl::guard(this, [=] { - delegate->openDocument(_page->document, parent->fullId()); - })); + crl::guard(this, [=](FullMsgId id) { + delegate->openDocument(_page->document, id); + }), + parent->fullId()); } else if (_page->photo) { if (_page->type == WebPageType::Profile || _page->type == WebPageType::Video) { _photol = createHandler(_page->url); @@ -1480,9 +1485,10 @@ Link::Link( || _page->siteName == qstr("Facebook")) { _photol = std::make_shared( _page->photo, - crl::guard(this, [=] { - delegate->openPhoto(_page->photo, parent->fullId()); - })); + crl::guard(this, [=](FullMsgId id) { + delegate->openPhoto(_page->photo, id); + }), + parent->fullId()); } else { _photol = createHandler(_page->url); }