From 29e30d2d00c6c6c04147f04753dba63b6402ce39 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 5 Nov 2022 19:07:20 +0400 Subject: [PATCH] Version 4.3: Fix rounding with inline keyboard markup. --- .../history/view/history_view_message.cpp | 31 +++++++++++-------- .../history/view/history_view_message.h | 2 ++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index d37c05b5c..ae90a0bc1 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -485,13 +485,15 @@ auto Message::takeReactionAnimations() } QSize Message::performCountOptimalSize() { + const auto item = message(); + const auto markup = item->inlineReplyMarkup(); validateText(); + validateInlineKeyboard(markup); updateViewButtonExistence(); updateMediaInBubbleState(); refreshRightBadge(); refreshInfoSkipBlock(); - const auto item = message(); const auto media = this->media(); auto maxWidth = 0; @@ -642,18 +644,10 @@ QSize Message::performCountOptimalSize() { maxWidth = st::msgMinWidth; minHeight = 0; } - if (const auto markup = item->inlineReplyMarkup()) { - if (!markup->inlineKeyboard && !markup->hiddenBy(item->media())) { - markup->inlineKeyboard = std::make_unique( - item, - std::make_unique(st::msgBotKbButton)); - } - - // if we have a text bubble we can resize it to fit the keyboard - // but if we have only media we don't do that - if (hasVisibleText() && markup->inlineKeyboard) { - accumulate_max(maxWidth, markup->inlineKeyboard->naturalWidth()); - } + // if we have a text bubble we can resize it to fit the keyboard + // but if we have only media we don't do that + if (markup && markup->inlineKeyboard && hasVisibleText()) { + accumulate_max(maxWidth, markup->inlineKeyboard->naturalWidth()); } return QSize(maxWidth, minHeight); } @@ -2414,6 +2408,17 @@ void Message::refreshReactions() { } } +void Message::validateInlineKeyboard(HistoryMessageReplyMarkup *markup) { + if (!markup + || markup->inlineKeyboard + || markup->hiddenBy(data()->media())) { + return; + } + markup->inlineKeyboard = std::make_unique( + data(), + std::make_unique(st::msgBotKbButton)); +} + void Message::validateFromNameText(PeerData *from) const { if (!from) { if (_fromNameStatus) { diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index 72b066e07..aac1e775a 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class HistoryMessage; struct HistoryMessageEdited; struct HistoryMessageForwarded; +struct HistoryMessageReplyMarkup; namespace Data { struct ReactionId; @@ -256,6 +257,7 @@ private: [[nodiscard]] int plainMaxWidth() const; [[nodiscard]] int monospaceMaxWidth() const; + void validateInlineKeyboard(HistoryMessageReplyMarkup *markup); void updateViewButtonExistence(); [[nodiscard]] int viewButtonHeight() const;