From d4a2c4a1519e346b456de5b01e1a09d26aedea0e Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 23 Sep 2022 11:59:46 +0400 Subject: [PATCH] Fix crash in caption spoiler opening. --- .../history_view_spoiler_click_handler.cpp | 56 +++++-------------- Telegram/lib_ui | 2 +- 2 files changed, 16 insertions(+), 42 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_spoiler_click_handler.cpp b/Telegram/SourceFiles/history/view/history_view_spoiler_click_handler.cpp index e151a4ca9b..a230b55849 100644 --- a/Telegram/SourceFiles/history/view/history_view_spoiler_click_handler.cpp +++ b/Telegram/SourceFiles/history/view/history_view_spoiler_click_handler.cpp @@ -15,52 +15,26 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/weak_ptr.h" namespace HistoryView { -namespace { - -class AnimatedSpoilerClickHandler final : public ClickHandler { -public: - AnimatedSpoilerClickHandler( - not_null view, - Ui::Text::String &text); - - void onClick(ClickContext context) const override; - -private: - base::weak_ptr _weak; - Ui::Text::String &_text; - -}; - -AnimatedSpoilerClickHandler::AnimatedSpoilerClickHandler( - not_null view, - Ui::Text::String &text) -: _weak(view) -, _text(text) { -} - -void AnimatedSpoilerClickHandler::onClick(ClickContext context) const { - const auto button = context.button; - const auto view = _weak.get(); - if (button != Qt::LeftButton || !view) { - return; - } - const auto my = context.other.value(); - if (const auto d = my.elementDelegate ? my.elementDelegate() : nullptr) { - _text.setSpoilerRevealed(true, anim::type::normal); - if (const auto controller = my.sessionWindow.get()) { - controller->session().data().registerShownSpoiler(view); - } - } -} - -} // namespace void FillTextWithAnimatedSpoilers( not_null view, Ui::Text::String &text) { if (text.hasSpoilers()) { - text.setSpoilerLink( - std::make_shared(view, text)); + text.setSpoilerLinkFilter([weak = base::make_weak(view.get())]( + const ClickContext &context) { + const auto my = context.other.value(); + const auto button = context.button; + const auto view = weak.get(); + if (button != Qt::LeftButton || !view || !my.elementDelegate) { + return false; + } else if (const auto d = my.elementDelegate()) { + if (const auto controller = my.sessionWindow.get()) { + controller->session().data().registerShownSpoiler(view); + } + return true; + } + return false; + }); } } diff --git a/Telegram/lib_ui b/Telegram/lib_ui index d57bf79ce0..0f77143905 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit d57bf79ce0862fda1093d9b9acfeff94c80a96f8 +Subproject commit 0f7714390552c4071ccdf3b1c34f8cd33f759b4d