Fix crash in Replies go-to-original button ripple.

This commit is contained in:
John Preston 2022-12-07 09:30:36 +04:00
parent 06ea927095
commit 8ec64f4167
2 changed files with 23 additions and 17 deletions

View file

@ -1589,6 +1589,7 @@ void Message::toggleCommentsButtonRipple(bool pressed) {
void Message::toggleRightActionRipple(bool pressed) { void Message::toggleRightActionRipple(bool pressed) {
Expects(_rightAction != nullptr); Expects(_rightAction != nullptr);
const auto size = rightActionSize(); const auto size = rightActionSize();
Assert(size != std::nullopt); Assert(size != std::nullopt);
@ -2007,7 +2008,7 @@ bool Message::getStateCommentsButton(
if (!_comments->link && data()->repliesAreComments()) { if (!_comments->link && data()->repliesAreComments()) {
_comments->link = createGoToCommentsLink(); _comments->link = createGoToCommentsLink();
} else if (!_comments->link && data()->externalReply()) { } else if (!_comments->link && data()->externalReply()) {
_comments->link = rightActionLink(); _comments->link = prepareRightActionLink();
} }
outResult->link = _comments->link; outResult->link = _comments->link;
_comments->lastPoint = point - QPoint(g.left(), g.top() + g.height()); _comments->lastPoint = point - QPoint(g.left(), g.top() + g.height());
@ -2989,9 +2990,7 @@ std::optional<QSize> Message::rightActionSize() const {
} }
void Message::applyRightActionLastPoint(QPoint p) const { void Message::applyRightActionLastPoint(QPoint p) const {
if (!_rightAction) { ensureRightAction();
_rightAction = std::make_unique<RightAction>();
}
_rightAction->lastPoint = std::move(p); _rightAction->lastPoint = std::move(p);
} }
@ -3038,9 +3037,7 @@ void Message::drawRightAction(
int left, int left,
int top, int top,
int outerWidth) const { int outerWidth) const {
if (!_rightAction) { ensureRightAction();
_rightAction = std::make_unique<RightAction>();
}
const auto size = rightActionSize(); const auto size = rightActionSize();
const auto st = context.st; const auto st = context.st;
@ -3104,18 +3101,26 @@ void Message::drawRightAction(
} }
ClickHandlerPtr Message::rightActionLink() const { ClickHandlerPtr Message::rightActionLink() const {
if (!_rightAction) { ensureRightAction();
_rightAction = std::make_unique<RightAction>(); if (!_rightAction->link) {
_rightAction->link = prepareRightActionLink();
} }
if (_rightAction->link) { return _rightAction->link;
return _rightAction->link; }
void Message::ensureRightAction() const {
if (_rightAction) {
return;
} }
Assert(rightActionSize().has_value());
_rightAction = std::make_unique<RightAction>();
}
ClickHandlerPtr Message::prepareRightActionLink() const {
if (isPinnedContext()) { if (isPinnedContext()) {
_rightAction->link = goToMessageClickHandler(data()); return goToMessageClickHandler(data());
return _rightAction->link;
} else if (displayRightActionComments()) { } else if (displayRightActionComments()) {
_rightAction->link = createGoToCommentsLink(); return createGoToCommentsLink();
return _rightAction->link;
} }
const auto sessionId = data()->history()->session().uniqueId(); const auto sessionId = data()->history()->session().uniqueId();
const auto owner = &data()->history()->owner(); const auto owner = &data()->history()->owner();
@ -3163,7 +3168,7 @@ ClickHandlerPtr Message::rightActionLink() const {
} }
}; };
}; };
_rightAction->link = std::make_shared<LambdaClickHandler>([=]( return std::make_shared<LambdaClickHandler>([=](
ClickContext context) { ClickContext context) {
const auto controller = ExtractController(context).value_or(nullptr); const auto controller = ExtractController(context).value_or(nullptr);
if (!controller) { if (!controller) {
@ -3186,7 +3191,6 @@ ClickHandlerPtr Message::rightActionLink() const {
} }
} }
}); });
return _rightAction->link;
} }
ClickHandlerPtr Message::fastReplyLink() const { ClickHandlerPtr Message::fastReplyLink() const {

View file

@ -273,7 +273,9 @@ private:
[[nodiscard]] bool displayFastShare() const; [[nodiscard]] bool displayFastShare() const;
[[nodiscard]] bool displayGoToOriginal() const; [[nodiscard]] bool displayGoToOriginal() const;
[[nodiscard]] ClickHandlerPtr fastReplyLink() const; [[nodiscard]] ClickHandlerPtr fastReplyLink() const;
[[nodiscard]] ClickHandlerPtr prepareRightActionLink() const;
void ensureRightAction() const;
void refreshTopicButton(); void refreshTopicButton();
void refreshInfoSkipBlock(); void refreshInfoSkipBlock();
[[nodiscard]] int plainMaxWidth() const; [[nodiscard]] int plainMaxWidth() const;