mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 15:43:55 +02:00
Fix possible crash in view button click handler.
This commit is contained in:
parent
b415b293cf
commit
18bf48bf90
1 changed files with 14 additions and 10 deletions
|
@ -73,6 +73,19 @@ inline auto WebPageToPhrase(not_null<WebPageData*> webpage) {
|
||||||
: QString());
|
: 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
|
} // namespace
|
||||||
|
|
||||||
struct ViewButton::Inner {
|
struct ViewButton::Inner {
|
||||||
|
@ -146,16 +159,7 @@ ViewButton::Inner::Inner(
|
||||||
not_null<Data::Media*> media,
|
not_null<Data::Media*> media,
|
||||||
Fn<void()> updateCallback)
|
Fn<void()> updateCallback)
|
||||||
: margins(st::historyViewButtonMargins)
|
: margins(st::historyViewButtonMargins)
|
||||||
, link(std::make_shared<LambdaClickHandler>([=](ClickContext context) {
|
, link(MakeWebPageClickHandler(media))
|
||||||
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);
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
, updateCallback(std::move(updateCallback))
|
, updateCallback(std::move(updateCallback))
|
||||||
, belowInfo(false)
|
, belowInfo(false)
|
||||||
, text(st::historyViewButtonTextStyle, WebPageToPhrase(media->webpage())) {
|
, text(st::historyViewButtonTextStyle, WebPageToPhrase(media->webpage())) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue