Fix possible crash in view button click handler.

This commit is contained in:
John Preston 2022-02-01 15:49:22 +03:00
parent b415b293cf
commit 18bf48bf90
1 changed files with 14 additions and 10 deletions

View File

@ -73,6 +73,19 @@ inline auto WebPageToPhrase(not_null<WebPageData*> webpage) {
: QString());
}
[[nodiscard]] ClickHandlerPtr MakeWebPageClickHandler(
not_null<Data::Media*> media) {
Expects(media->webpage() != nullptr);
const auto url = media->webpage()->url;
return std::make_shared<LambdaClickHandler>([=](ClickContext context) {
const auto my = context.other.value<ClickHandlerContext>();
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<Data::Media*> media,
Fn<void()> updateCallback)
: margins(st::historyViewButtonMargins)
, link(std::make_shared<LambdaClickHandler>([=](ClickContext context) {
const auto my = context.other.value<ClickHandlerContext>();
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())) {