diff --git a/Telegram/SourceFiles/history/history_item_helpers.cpp b/Telegram/SourceFiles/history/history_item_helpers.cpp index c972558aa..c4971b2df 100644 --- a/Telegram/SourceFiles/history/history_item_helpers.cpp +++ b/Telegram/SourceFiles/history/history_item_helpers.cpp @@ -35,6 +35,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "base/unixtime.h" #include "core/application.h" +#include "core/click_handler_types.h" // ClickHandlerContext. +#include "settings/settings_premium.h" // Settings::ShowPremium. #include "ui/text/format_values.h" #include "ui/text/text_utilities.h" #include "ui/text/text_entity.h" @@ -330,6 +332,15 @@ ClickHandlerPtr JumpToStoryClickHandler( }); } +ClickHandlerPtr HideSponsoredClickHandler() { + return std::make_shared([=](ClickContext context) { + const auto my = context.other.value(); + if (const auto controller = my.sessionWindow.get()) { + Settings::ShowPremium(controller, "no_ads"); + } + }); +} + MessageFlags FlagsFromMTP( MsgId id, MTPDmessage::Flags flags, diff --git a/Telegram/SourceFiles/history/history_item_helpers.h b/Telegram/SourceFiles/history/history_item_helpers.h index a39c4b0e2..855f1b653 100644 --- a/Telegram/SourceFiles/history/history_item_helpers.h +++ b/Telegram/SourceFiles/history/history_item_helpers.h @@ -136,6 +136,7 @@ struct SendingErrorRequest { ClickHandlerPtr JumpToStoryClickHandler( not_null peer, StoryId storyId); +[[nodiscard]] ClickHandlerPtr HideSponsoredClickHandler(); [[nodiscard]] not_null GenerateJoinedMessage( not_null history, diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index c7b0dc7c4..ef46a4d10 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1191,7 +1191,9 @@ void Message::draw(Painter &p, const PaintContext &context) const { 0, st::historyFastShareBottom); const auto fastShareLeft = g.left() + g.width() + st::historyFastShareLeft; - const auto fastShareTop = g.top() + g.height() - fastShareSkip - size->height(); + const auto fastShareTop = data()->isSponsored() + ? g.top() + fastShareSkip + : g.top() + g.height() - fastShareSkip - size->height(); drawRightAction(p, context, fastShareLeft, fastShareTop, width()); } @@ -2209,7 +2211,9 @@ TextState Message::textState( 0, st::historyFastShareBottom); const auto fastShareLeft = g.left() + g.width() + st::historyFastShareLeft; - const auto fastShareTop = g.top() + g.height() - fastShareSkip - size->height(); + const auto fastShareTop = data()->isSponsored() + ? g.top() + fastShareSkip + : g.top() + g.height() - fastShareSkip - size->height(); if (QRect( fastShareLeft, fastShareTop, @@ -3343,7 +3347,9 @@ std::optional Message::rightActionSize() const { st::historyFastShareSize + st::historyFastShareBottom + st::semiboldFont->height) : QSize(st::historyFastShareSize, st::historyFastShareSize); } - return (displayFastShare() || displayGoToOriginal()) + return data()->isSponsored() + ? QSize(st::historyFastCloseSize, st::historyFastCloseSize) + : (displayFastShare() || displayGoToOriginal()) ? QSize(st::historyFastShareSize, st::historyFastShareSize) : std::optional(); } @@ -3447,7 +3453,9 @@ void Message::drawRightAction( views->repliesSmall.textWidth); } } else { - const auto &icon = (displayFastShare() && !isPinnedContext()) + const auto &icon = data()->isSponsored() + ? st->historyFastCloseIcon() + : (displayFastShare() && !isPinnedContext()) ? st->historyFastShareIcon() : st->historyGoToOriginalIcon(); icon.paintInCenter(p, { left, top, size->width(), size->height() }); @@ -3475,7 +3483,9 @@ void Message::ensureRightAction() const { } ClickHandlerPtr Message::prepareRightActionLink() const { - if (isPinnedContext()) { + if (data()->isSponsored()) { + return HideSponsoredClickHandler(); + } else if (isPinnedContext()) { return JumpToMessageClickHandler(data()); } else if (displayRightActionComments()) { return createGoToCommentsLink(); diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index 43ea6aa4b..2385895f5 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -559,6 +559,8 @@ historyFastShareBottom: 5px; historyFastShareIcon: icon {{ "fast_share", msgServiceFg }}; historyGoToOriginalIcon: icon {{ "fast_to_original", msgServiceFg, point(1px, 0px) }}; historyFastCommentsIcon: icon {{ "fast_comments", msgServiceFg }}; +historyFastCloseSize: 30px; +historyFastCloseIcon: icon {{ "box_button_close", msgServiceFg }}; historyFastTranscribeIcon: icon {{ "chat/voice_to_text", msgServiceFg }}; historySavedFont: font(semibold 14px); diff --git a/Telegram/SourceFiles/ui/chat/chat_style.cpp b/Telegram/SourceFiles/ui/chat/chat_style.cpp index 206eb523d..a5187ecbc 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.cpp +++ b/Telegram/SourceFiles/ui/chat/chat_style.cpp @@ -190,6 +190,7 @@ ChatStyle::ChatStyle(rpl::producer colorIndices) { make(_historyFastShareIcon, st::historyFastShareIcon); make(_historyFastTranscribeIcon, st::historyFastTranscribeIcon); make(_historyGoToOriginalIcon, st::historyGoToOriginalIcon); + make(_historyFastCloseIcon, st::historyFastCloseIcon); make(_historyMapPoint, st::historyMapPoint); make(_historyMapPointInner, st::historyMapPointInner); make(_youtubeIcon, st::youtubeIcon); diff --git a/Telegram/SourceFiles/ui/chat/chat_style.h b/Telegram/SourceFiles/ui/chat/chat_style.h index 85102db6a..12c049582 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.h +++ b/Telegram/SourceFiles/ui/chat/chat_style.h @@ -388,6 +388,9 @@ public: [[nodiscard]] const style::icon &historyGoToOriginalIcon() const { return _historyGoToOriginalIcon; } + [[nodiscard]] const style::icon &historyFastCloseIcon() const { + return _historyFastCloseIcon; + } [[nodiscard]] const style::icon &historyMapPoint() const { return _historyMapPoint; } @@ -512,6 +515,7 @@ private: style::icon _historyFastShareIcon = { Qt::Uninitialized }; style::icon _historyFastTranscribeIcon = { Qt::Uninitialized }; style::icon _historyGoToOriginalIcon = { Qt::Uninitialized }; + style::icon _historyFastCloseIcon = { Qt::Uninitialized }; style::icon _historyMapPoint = { Qt::Uninitialized }; style::icon _historyMapPointInner = { Qt::Uninitialized }; style::icon _youtubeIcon = { Qt::Uninitialized };