From b5edaf4c23f8993bed230ce75a5bd57d4e04b3b9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 21 Dec 2021 11:59:27 +0000 Subject: [PATCH] Fix layout of reactions in files / contacts. --- .../history/view/history_view_bottom_info.cpp | 14 +++++++++++--- .../history/view/history_view_bottom_info.h | 1 + .../history/view/history_view_element.cpp | 4 ++++ .../history/view/history_view_element.h | 1 + .../history/view/history_view_message.cpp | 17 +++++++++++++++-- .../history/view/history_view_message.h | 1 + .../history/view/media/history_view_contact.cpp | 7 +------ .../view/media/history_view_document.cpp | 8 +------- 8 files changed, 35 insertions(+), 18 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp index fa7f77d7c..2d8e8164a 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp @@ -91,6 +91,14 @@ int BottomInfo::firstLineWidth() const { return maxWidth() - _reactionsMaxWidth; } +bool BottomInfo::isWide() const { + return (_data.flags & Data::Flag::Edited) + || !_data.author.isEmpty() + || !_views.isEmpty() + || !_replies.isEmpty() + || !_reactions.empty(); +} + TextState BottomInfo::textState( not_null item, QPoint position) const { @@ -273,9 +281,9 @@ void BottomInfo::layoutDateText() { : QString(); const auto author = _data.author; const auto prefix = author.isEmpty() ? qsl(", ") : QString(); - const auto date = _data.date.toString(cTimeFormat()); + const auto date = edited + _data.date.toString(cTimeFormat()); _dateWidth = st::msgDateFont->width(date); - const auto afterAuthor = prefix + edited + date; + const auto afterAuthor = prefix + date; const auto afterAuthorWidth = st::msgDateFont->width(afterAuthor); const auto authorWidth = st::msgDateFont->width(author); const auto maxWidth = st::maxSignatureSize; @@ -286,7 +294,7 @@ void BottomInfo::layoutDateText() { : author; const auto full = (_data.flags & Data::Flag::Sponsored) ? tr::lng_sponsored(tr::now) - : name + date; + : name.isEmpty() ? date : (name + afterAuthor); _authorEditedDate.setText( st::msgDateTextStyle, full, diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.h b/Telegram/SourceFiles/history/view/history_view_bottom_info.h index 573b52710..71b37c182 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.h +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.h @@ -52,6 +52,7 @@ public: void update(Data &&data, int availableWidth); [[nodiscard]] int firstLineWidth() const; + [[nodiscard]] bool isWide() const; [[nodiscard]] TextState textState( not_null item, QPoint position) const; diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index b6eff7288..df770e01e 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -475,6 +475,10 @@ int Element::bottomInfoFirstLineWidth() const { return 0; } +bool Element::bottomInfoIsWide() const { + return false; +} + bool Element::isHiddenByGroup() const { return _flags & Flag::HiddenByGroup; } diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 76b84a5b4..a985df302 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -272,6 +272,7 @@ public: QString skipBlock() const; virtual int infoWidth() const; virtual int bottomInfoFirstLineWidth() const; + virtual bool bottomInfoIsWide() const; bool isHiddenByGroup() const; virtual bool isHidden() const; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index be8cfc430..02044b139 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -364,7 +364,10 @@ QSize Message::performCountOptimalSize() { (st::msgPadding.left() + _reactions->maxWidth() + st::msgPadding.right()))); - minHeight += st::mediaInBubbleSkip + _reactions->minHeight(); + if (!mediaDisplayed) { + minHeight += st::mediaInBubbleSkip; + } + minHeight += _reactions->minHeight(); } if (!mediaOnBottom) { minHeight += st::msgPadding.bottom(); @@ -1904,6 +1907,13 @@ int Message::bottomInfoFirstLineWidth() const { return _bottomInfo.firstLineWidth(); } +bool Message::bottomInfoIsWide() const { + if (_reactions && embedReactionsInBubble()) { + return false; + } + return _bottomInfo.isWide(); +} + bool Message::isSignedAuthorElided() const { return _bottomInfo.isSignedAuthorElided(); } @@ -2661,7 +2671,10 @@ int Message::resizeContentGetHeight(int newWidth) { newHeight += entry->resizeGetHeight(contentWidth); } if (reactionsInBubble) { - newHeight += st::mediaInBubbleSkip + _reactions->height(); + if (!mediaDisplayed) { + newHeight += st::mediaInBubbleSkip; + } + newHeight += _reactions->height(); } } diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index 80b72bf53..18f0e4f6a 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -123,6 +123,7 @@ public: const ClickHandlerPtr &handler) const override; [[nodiscard]] int infoWidth() const override; [[nodiscard]] int bottomInfoFirstLineWidth() const override; + [[nodiscard]] bool bottomInfoIsWide() const override; [[nodiscard]] bool isSignedAuthorElided() const override; void itemDataChanged() override; diff --git a/Telegram/SourceFiles/history/view/media/history_view_contact.cpp b/Telegram/SourceFiles/history/view/media/history_view_contact.cpp index b73cf8628..3222bf47a 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_contact.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_contact.cpp @@ -148,12 +148,7 @@ QSize Contact::countOptimalSize() { accumulate_max(maxWidth, tleft + _name.maxWidth() + tright); accumulate_min(maxWidth, st::msgMaxWidth); auto minHeight = st.padding.top() + st.thumbSize + st.padding.bottom(); - const auto msgsigned = item->Get(); - const auto views = item->Get(); - if ((msgsigned && !msgsigned->isAnonymousRank) - || (views - && (views->views.count >= 0 || views->replies.count > 0)) - || !item->reactions().empty()) { + if (_parent->bottomInfoIsWide()) { minHeight += st::msgDateFont->height - st::msgDateDelta.y(); } if (!isBubbleTop()) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index b1467248d..bd1353dd3 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -268,13 +268,7 @@ QSize Document::countOptimalSize() { } auto minHeight = st.padding.top() + st.thumbSize + st.padding.bottom(); - const auto msgsigned = item->Get(); - const auto views = item->Get(); - if (!captioned && ((msgsigned && !msgsigned->isAnonymousRank) - || (views - && (views->views.count >= 0 || views->replies.count > 0)) - || !item->reactions().empty() - || _parent->displayEditedBadge())) { + if (!captioned && _parent->bottomInfoIsWide()) { minHeight += st::msgDateFont->height - st::msgDateDelta.y(); } if (!isBubbleTop()) {