diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 7aebfa46e..9382813b6 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -84,17 +84,6 @@ void HistoryMessageVia::resize(int32 availw) const { } } -HistoryMessageSponsored::HistoryMessageSponsored() { - text.setText( - st::msgDateTextStyle, - tr::lng_sponsored(tr::now), - Ui::NameTextOptions()); -} - -int HistoryMessageSponsored::maxWidth() const { - return text.maxWidth(); -} - HiddenSenderInfo::HiddenSenderInfo(const QString &name, bool external) : name(name) , colorPeerId(Data::FakePeerIdForJustName(name)) diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 776134533..bf0ed95f6 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -68,15 +68,6 @@ struct HistoryMessageEdited : public RuntimeComponent { - HistoryMessageSponsored(); - int maxWidth() const; - - Ui::Text::String text; -}; - struct HiddenSenderInfo { HiddenSenderInfo(const QString &name, bool external); diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 6eed91676..757bdeb87 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -433,7 +433,6 @@ struct HistoryMessage::CreateConfig { HistoryMessageMarkupData markup; HistoryMessageRepliesData replies; bool imported = false; - bool sponsored = false; // For messages created from existing messages (forwarded). const HistoryMessageReplyMarkup *inlineMarkup = nullptr; @@ -787,9 +786,6 @@ void HistoryMessage::createComponentsHelper( config.markup = std::move(markup); if (flags & MessageFlag::HasPostAuthor) config.author = postAuthor; if (flags & MessageFlag::HasViews) config.viewsCount = 1; - if (flags & MessageFlag::IsSponsored) { - config.sponsored = true; - } createComponents(std::move(config)); } @@ -1095,9 +1091,6 @@ void HistoryMessage::createComponents(CreateConfig &&config) { if (config.editDate != TimeId(0)) { mask |= HistoryMessageEdited::Bit(); } - if (config.sponsored) { - mask |= HistoryMessageSponsored::Bit(); - } if (config.originalDate != 0) { mask |= HistoryMessageForwarded::Bit(); } diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp index 128ce3724..e8beb806b 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp @@ -242,7 +242,9 @@ void BottomInfo::layoutDateText() { const auto name = _authorElided ? st::msgDateFont->elided(author, maxWidth - afterAuthorWidth) : author; - const auto full = name + date; + const auto full = (_data.flags & Data::Flag::Sponsored) + ? tr::lng_sponsored(tr::now) + : name + date; _authorEditedDate.setText( st::msgDateTextStyle, full, @@ -336,6 +338,9 @@ BottomInfo::Data BottomInfoDataFromMessage(not_null message) { if (message->context() == Context::Replies) { result.flags |= Flag::RepliesContext; } + if (item->isSponsored()) { + result.flags |= Flag::Sponsored; + } if (const auto msgsigned = item->Get()) { if (!msgsigned->isAnonymousRank) { result.author = msgsigned->author; diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.h b/Telegram/SourceFiles/history/view/history_view_bottom_info.h index 4750aec32..5c8ab24fa 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.h +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.h @@ -29,6 +29,7 @@ public: OutLayout = 0x02, Sending = 0x04, RepliesContext = 0x08, + Sponsored = 0x10, //Unread, // We don't want to pass and update it in Date for now. }; friend inline constexpr bool is_flag_type(Flag) { return true; }; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 2e1ef5d0a..1568ee571 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -606,16 +606,21 @@ void Message::draw(Painter &p, const PaintContext &context) const { auto inner = g; paintCommentsButton(p, inner, context); + const auto needDrawInfo = needInfoDisplay(); auto trect = inner.marginsRemoved(st::msgPadding); if (_viewButton) { + const auto belowInfo = _viewButton->belowMessageInfo(); + const auto infoHeight = _bottomInfo.size().height(); + const auto heightMargins = QMargins(0, 0, 0, infoHeight); _viewButton->draw( p, - _viewButton->countRect(inner), + _viewButton->countRect(belowInfo + ? inner + : inner - heightMargins), context); - // Inner should contain _viewButton height, because info is - // painted below the _viewButton. - // - // inner.setHeight(inner.height() - _viewButton->height()); + if (belowInfo) { + inner.setHeight(inner.height() - _viewButton->height()); + } trect.setHeight(trect.height() - _viewButton->height()); if (mediaDisplayed) { trect.setHeight(trect.height() - st::mediaInBubbleSkip); @@ -636,7 +641,6 @@ void Message::draw(Painter &p, const PaintContext &context) const { if (entry) { trect.setHeight(trect.height() - entry->height()); } - const auto needDrawInfo = needInfoDisplay(); if (needDrawInfo) { trect.setHeight(trect.height() - (_bottomInfo.size().height() - st::msgDateFont->height)); } @@ -680,10 +684,10 @@ void Message::draw(Painter &p, const PaintContext &context) const { inner.top() + inner.height(), 2 * inner.left() + inner.width(), InfoDisplayType::Default); - if (g != inner) { + if (_comments) { const auto o = p.opacity(); p.setOpacity(0.3); - p.fillRect(inner.left(), inner.top() + inner.height() - st::lineWidth, inner.width(), st::lineWidth, stm->msgDateFg); + p.fillRect(g.left(), g.top() + g.height() - st::historyCommentsButtonHeight - st::lineWidth, g.width(), st::lineWidth, stm->msgDateFg); p.setOpacity(o); } } @@ -1213,12 +1217,21 @@ TextState Message::textState( if (getStateCommentsButton(point, bubble, &result)) { return result; } - if (_viewButton - && _viewButton->getState( - point, - _viewButton->countRect(bubble), - &result)) { - return result; + if (_viewButton) { + const auto belowInfo = _viewButton->belowMessageInfo(); + const auto infoHeight = _bottomInfo.size().height(); + const auto heightMargins = QMargins(0, 0, 0, infoHeight); + if (_viewButton->getState( + point, + _viewButton->countRect(belowInfo + ? bubble + : bubble - heightMargins), + &result)) { + return result; + } + if (belowInfo) { + bubble -= heightMargins; + } } auto trect = bubble.marginsRemoved(st::msgPadding); @@ -2625,16 +2638,6 @@ TimeId Message::displayedEditDate() const { return TimeId(0); } -const HistoryMessageSponsored *Message::displayedSponsorBadge() const { - // Ignore media while sponsored messages are text only. - // if (const auto media = this->media()) { - // if (media->overrideEditedDate()) { - // return media->displayedEditBadge(); - // } - // } - return message()->Get(); -} - HistoryMessageEdited *Message::displayedEditBadge() { if (const auto media = this->media()) { if (media->overrideEditedDate()) { diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index 0c00cb5dd..d538e9449 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class HistoryMessage; struct HistoryMessageEdited; -struct HistoryMessageSponsored; struct HistoryMessageForwarded; namespace HistoryView { @@ -54,8 +53,8 @@ public: not_null message() const; - const HistoryMessageEdited *displayedEditBadge() const; - HistoryMessageEdited *displayedEditBadge(); + [[nodiscard]] const HistoryMessageEdited *displayedEditBadge() const; + [[nodiscard]] HistoryMessageEdited *displayedEditBadge(); int marginTop() const override; int marginBottom() const override; @@ -210,8 +209,6 @@ private: [[nodiscard]] bool displayFastShare() const; [[nodiscard]] bool displayGoToOriginal() const; [[nodiscard]] ClickHandlerPtr fastReplyLink() const; - [[nodiscard]] auto displayedSponsorBadge() const - -> const HistoryMessageSponsored*; [[nodiscard]] bool displayPinIcon() const; void initTime() const; diff --git a/Telegram/SourceFiles/history/view/history_view_view_button.cpp b/Telegram/SourceFiles/history/view/history_view_view_button.cpp index 7bfed5f54..96cb8b494 100644 --- a/Telegram/SourceFiles/history/view/history_view_view_button.cpp +++ b/Telegram/SourceFiles/history/view/history_view_view_button.cpp @@ -82,7 +82,7 @@ struct ViewButton::Inner { const style::margins &margins; const ClickHandlerPtr link; const Fn updateCallback; - bool underDate = true; + bool belowInfo = true; int lastWidth = 0; QPoint lastPoint; std::unique_ptr ripple; @@ -143,7 +143,7 @@ ViewButton::Inner::Inner( } })) , updateCallback(std::move(updateCallback)) -, underDate(false) +, belowInfo(false) , text(st::historyViewButtonTextStyle, WebPageToPhrase(media->webpage())) { } @@ -187,6 +187,10 @@ int ViewButton::height() const { return st::historyViewButtonHeight; } +bool ViewButton::belowMessageInfo() const { + return _inner->belowInfo; +} + void ViewButton::draw( Painter &p, const QRect &r, @@ -252,10 +256,9 @@ bool ViewButton::getState( } QRect ViewButton::countRect(const QRect &r) const { - const auto dateHeight = (_inner->underDate ? 0 : st::msgDateFont->height); return QRect( r.left(), - r.top() + r.height() - height() - dateHeight, + r.top() + r.height() - height(), r.width(), height()) - _inner->margins; } diff --git a/Telegram/SourceFiles/history/view/history_view_view_button.h b/Telegram/SourceFiles/history/view/history_view_view_button.h index 3c9514a8c..f49ae2ab2 100644 --- a/Telegram/SourceFiles/history/view/history_view_view_button.h +++ b/Telegram/SourceFiles/history/view/history_view_view_button.h @@ -31,6 +31,7 @@ public: not_null webpage); [[nodiscard]] int height() const; + [[nodiscard]] bool belowMessageInfo() const; void draw( Painter &p,