diff --git a/Telegram/SourceFiles/history/view/history_view_view_button.cpp b/Telegram/SourceFiles/history/view/history_view_view_button.cpp index 7d722b8692..f7471c31a9 100644 --- a/Telegram/SourceFiles/history/view/history_view_view_button.cpp +++ b/Telegram/SourceFiles/history/view/history_view_view_button.cpp @@ -73,6 +73,19 @@ inline auto WebPageToPhrase(not_null webpage) { : QString()); } +[[nodiscard]] ClickHandlerPtr MakeWebPageClickHandler( + not_null media) { + Expects(media->webpage() != nullptr); + + const auto url = media->webpage()->url; + return std::make_shared([=](ClickContext context) { + const auto my = context.other.value(); + if (const auto controller = my.sessionWindow.get()) { + HiddenUrlClickHandler::Open(url, context.other); + } + }); +} + } // namespace struct ViewButton::Inner { @@ -146,16 +159,7 @@ ViewButton::Inner::Inner( not_null media, Fn updateCallback) : margins(st::historyViewButtonMargins) -, link(std::make_shared([=](ClickContext context) { - const auto my = context.other.value(); - if (const auto controller = my.sessionWindow.get()) { - const auto webpage = media->webpage(); - if (!webpage) { - return; - } - HiddenUrlClickHandler::Open(webpage->url, context.other); - } -})) +, link(MakeWebPageClickHandler(media)) , updateCallback(std::move(updateCallback)) , belowInfo(false) , text(st::historyViewButtonTextStyle, WebPageToPhrase(media->webpage())) {