diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 42940e5a5..35be56ae3 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1589,6 +1589,7 @@ void Message::toggleCommentsButtonRipple(bool pressed) { void Message::toggleRightActionRipple(bool pressed) { Expects(_rightAction != nullptr); + const auto size = rightActionSize(); Assert(size != std::nullopt); @@ -2007,7 +2008,7 @@ bool Message::getStateCommentsButton( if (!_comments->link && data()->repliesAreComments()) { _comments->link = createGoToCommentsLink(); } else if (!_comments->link && data()->externalReply()) { - _comments->link = rightActionLink(); + _comments->link = prepareRightActionLink(); } outResult->link = _comments->link; _comments->lastPoint = point - QPoint(g.left(), g.top() + g.height()); @@ -2989,9 +2990,7 @@ std::optional Message::rightActionSize() const { } void Message::applyRightActionLastPoint(QPoint p) const { - if (!_rightAction) { - _rightAction = std::make_unique(); - } + ensureRightAction(); _rightAction->lastPoint = std::move(p); } @@ -3038,9 +3037,7 @@ void Message::drawRightAction( int left, int top, int outerWidth) const { - if (!_rightAction) { - _rightAction = std::make_unique(); - } + ensureRightAction(); const auto size = rightActionSize(); const auto st = context.st; @@ -3104,18 +3101,26 @@ void Message::drawRightAction( } ClickHandlerPtr Message::rightActionLink() const { - if (!_rightAction) { - _rightAction = std::make_unique(); + ensureRightAction(); + 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(); +} + +ClickHandlerPtr Message::prepareRightActionLink() const { if (isPinnedContext()) { - _rightAction->link = goToMessageClickHandler(data()); - return _rightAction->link; + return goToMessageClickHandler(data()); } else if (displayRightActionComments()) { - _rightAction->link = createGoToCommentsLink(); - return _rightAction->link; + return createGoToCommentsLink(); } const auto sessionId = data()->history()->session().uniqueId(); const auto owner = &data()->history()->owner(); @@ -3163,7 +3168,7 @@ ClickHandlerPtr Message::rightActionLink() const { } }; }; - _rightAction->link = std::make_shared([=]( + return std::make_shared([=]( ClickContext context) { const auto controller = ExtractController(context).value_or(nullptr); if (!controller) { @@ -3186,7 +3191,6 @@ ClickHandlerPtr Message::rightActionLink() const { } } }); - return _rightAction->link; } ClickHandlerPtr Message::fastReplyLink() const { diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index f2c769386..b81bac754 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -273,7 +273,9 @@ private: [[nodiscard]] bool displayFastShare() const; [[nodiscard]] bool displayGoToOriginal() const; [[nodiscard]] ClickHandlerPtr fastReplyLink() const; + [[nodiscard]] ClickHandlerPtr prepareRightActionLink() const; + void ensureRightAction() const; void refreshTopicButton(); void refreshInfoSkipBlock(); [[nodiscard]] int plainMaxWidth() const;