diff --git a/Telegram/SourceFiles/data/data_types.h b/Telegram/SourceFiles/data/data_types.h index ab72828a3..31c976859 100644 --- a/Telegram/SourceFiles/data/data_types.h +++ b/Telegram/SourceFiles/data/data_types.h @@ -311,6 +311,8 @@ enum class MessageFlag : uint64 { DisplayFromChecked = (1ULL << 40), ShowSimilarChannels = (1ULL << 41), + + Sponsored = (1ULL << 42), }; inline constexpr bool is_flag_type(MessageFlag) { return true; } using MessageFlags = base::flags; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 4765fffb7..19727944c 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -853,8 +853,6 @@ bool HistoryInner::canHaveFromUserpics() const { && !_peer->isRepliesChat() && !_isChatWide) { return false; - } else if (_canHaveFromUserpicsSponsored) { - return true; } else if (_peer->isChannel() && !_peer->isMegagroup()) { return false; } @@ -4049,10 +4047,6 @@ void HistoryInner::clearChooseReportReason() { _chooseForReportReason = std::nullopt; } -void HistoryInner::setCanHaveFromUserpicsSponsored(bool value) { - _canHaveFromUserpicsSponsored = value; -} - auto HistoryInner::viewByItem(const HistoryItem *item) const -> Element* { return !item ? nullptr diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index b57420eac..dcc8dc4b5 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -183,8 +183,6 @@ public: void setChooseReportReason(Ui::ReportReason reason); void clearChooseReportReason(); - void setCanHaveFromUserpicsSponsored(bool value); - // -1 if should not be visible, -2 if bad history() [[nodiscard]] int itemTop(const HistoryItem *item) const; [[nodiscard]] int itemTop(const Element *view) const; @@ -490,7 +488,6 @@ private: bool _pressWasInactive = false; bool _recountedAfterPendingResizedItems = false; bool _useCornerReaction = false; - bool _canHaveFromUserpicsSponsored = false; bool _acceptsHorizontalScroll = false; bool _horizontalScrollLocked = false; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 32cae6df1..8b3e7ea30 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -731,7 +731,6 @@ HistoryItem::HistoryItem( webpage, MediaWebPageFlag::Sponsored); _media = std::move(webpageMedia); - setSponsoredFrom(from); } HistoryItem::HistoryItem( @@ -1181,10 +1180,6 @@ HistoryItem *HistoryItem::lookupDiscussionPostOriginal() const { PeerData *HistoryItem::computeDisplayFrom() const { if (const auto sender = discussionPostOriginalSender()) { return sender; - } else if (const auto sponsored = Get()) { - if (sponsored->sender) { - return nullptr; - } } else if (const auto forwarded = Get()) { if (_history->peer->isSelf() || _history->peer->isRepliesChat() @@ -1492,7 +1487,7 @@ bool HistoryItem::isScheduled() const { } bool HistoryItem::isSponsored() const { - return Has(); + return _flags & MessageFlag::Sponsored; } bool HistoryItem::skipNotification() const { @@ -2486,9 +2481,7 @@ PeerData *HistoryItem::originalSender() const { } const HiddenSenderInfo *HistoryItem::hiddenSenderInfo() const { - if (const auto sponsored = Get()) { - return sponsored->sender.get(); - } else if (const auto forwarded = Get()) { + if (const auto forwarded = Get()) { return forwarded->hiddenSenderInfo.get(); } return nullptr; @@ -3100,8 +3093,6 @@ ItemPreview HistoryItem::toPreview(ToPreviewOptions options) const { const auto sender = [&]() -> std::optional { if (options.hideSender || isPost() || isEmpty()) { return {}; - } else if (const auto sponsored = Get()) { - return sponsored->sender->name; } else if (!_history->peer->isUser()) { if (const auto from = displayFrom()) { return fromSender(from); @@ -3349,36 +3340,6 @@ TextWithEntities HistoryItem::withLocalEntities( return textWithEntities; } -void HistoryItem::setSponsoredFrom(const Data::SponsoredFrom &from) { - AddComponents(HistoryMessageSponsored::Bit()); - const auto sponsored = Get(); - sponsored->sender = std::make_unique( - from.title, - false, - from.peer ? from.peer->colorIndex() : std::optional()); - sponsored->recommended = from.isRecommended; - sponsored->isForceUserpicDisplay = from.isForceUserpicDisplay; - if (from.userpic.location.valid()) { - sponsored->sender->customUserpic.set( - &_history->session(), - from.userpic); - } - - sponsored->externalLink = from.externalLink; - using Type = HistoryMessageSponsored::Type; - sponsored->type = (!from.externalLink.isEmpty()) - ? Type::ExternalLink - : from.isExactPost - ? Type::Post - : from.isBot - ? Type::Bot - : from.isBroadcast - ? Type::Broadcast - : (from.peer && from.peer->isUser()) - ? Type::User - : Type::Group; -} - void HistoryItem::createComponentsHelper( MessageFlags flags, FullReplyTo replyTo, diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 50141aa93..9839a6d08 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -615,8 +615,6 @@ private: // It should show the receipt for the payed invoice. Still let mobile apps do that. void replaceBuyWithReceiptInMarkup(); - void setSponsoredFrom(const Data::SponsoredFrom &from); - [[nodiscard]] PreparedServiceText preparePinnedText(); [[nodiscard]] PreparedServiceText prepareGameScoreText(); [[nodiscard]] PreparedServiceText preparePaymentSentText(); diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 9275cf1b9..0cce4e499 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -140,22 +140,6 @@ struct HistoryMessageForwarded : public RuntimeComponent { - enum class Type : uchar { - User, - Group, - Broadcast, - Post, - Bot, - ExternalLink, - }; - std::unique_ptr sender; - Type type = Type::User; - bool recommended = false; - bool isForceUserpicDisplay = false; - QString externalLink; -}; - class ReplyToMessagePointer final { public: ReplyToMessagePointer(HistoryItem *item = nullptr) : _data(item) { diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 3084637ea..4cf3f03c8 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -294,9 +294,6 @@ HistoryWidget::HistoryWidget( if (_history && _history->loadedAtBottom() && session().data().sponsoredMessages().append(_history)) { - if (_list) { - _list->setCanHaveFromUserpicsSponsored(true); - } _scroll->contentAdded(); } }, lifetime()); @@ -2347,9 +2344,6 @@ void HistoryWidget::showHistory( _scroll->setTrackingContent( sponsored.canHaveFor(_history)); } else if (state == State::InjectToMiddle) { - if (_list) { - _list->setCanHaveFromUserpicsSponsored(true); - } injectSponsoredMessages(); } }); diff --git a/Telegram/SourceFiles/history/view/history_view_view_button.cpp b/Telegram/SourceFiles/history/view/history_view_view_button.cpp index 90a0152ba..0780e4ddf 100644 --- a/Telegram/SourceFiles/history/view/history_view_view_button.cpp +++ b/Telegram/SourceFiles/history/view/history_view_view_button.cpp @@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_item_components.h" #include "history/view/history_view_cursor_state.h" -#include "history/view/history_view_sponsored_click_handler.h" #include "lang/lang_keys.h" #include "ui/effects/ripple_animation.h" #include "ui/painter.h" @@ -22,24 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace HistoryView { namespace { -using SponsoredType = HistoryMessageSponsored::Type; - -inline auto SponsoredPhrase(SponsoredType type) { - const auto phrase = [&] { - switch (type) { - case SponsoredType::User: return tr::lng_view_button_user; - case SponsoredType::Group: return tr::lng_view_button_group; - case SponsoredType::Broadcast: return tr::lng_view_button_channel; - case SponsoredType::Post: return tr::lng_view_button_message; - case SponsoredType::Bot: return tr::lng_view_button_bot; - case SponsoredType::ExternalLink: - return tr::lng_view_button_external_link; - } - Unexpected("SponsoredType in SponsoredPhrase."); - }(); - return Ui::Text::Upper(phrase(tr::now)); -} - [[nodiscard]] ClickHandlerPtr MakeMediaButtonClickHandler( not_null media) { const auto giveaway = media->giveaway(); @@ -70,10 +51,6 @@ inline auto SponsoredPhrase(SponsoredType type) { } // namespace struct ViewButton::Inner { - Inner( - not_null sponsored, - uint8 colorIndex, - Fn updateCallback); Inner( not_null media, uint8 colorIndex, @@ -98,18 +75,6 @@ bool ViewButton::MediaHasViewButton(not_null media) { return (media->giveaway() != nullptr); } -ViewButton::Inner::Inner( - not_null sponsored, - uint8 colorIndex, - Fn updateCallback) -: margins(st::historyViewButtonMargins) -, link(SponsoredLink(sponsored->externalLink)) -, updateCallback(std::move(updateCallback)) -, colorIndex(colorIndex) -, externalLink((sponsored->type == SponsoredType::ExternalLink) ? 1 : 0) -, text(st::historyViewButtonTextStyle, SponsoredPhrase(sponsored->type)) { -} - ViewButton::Inner::Inner( not_null media, uint8 colorIndex, @@ -141,16 +106,6 @@ void ViewButton::Inner::toggleRipple(bool pressed) { } } -ViewButton::ViewButton( - not_null sponsored, - uint8 colorIndex, - Fn updateCallback) -: _inner(std::make_unique( - sponsored, - colorIndex, - std::move(updateCallback))) { -} - ViewButton::ViewButton( not_null media, uint8 colorIndex, diff --git a/Telegram/SourceFiles/history/view/history_view_view_button.h b/Telegram/SourceFiles/history/view/history_view_view_button.h index 262f00dc0..e6a3744d4 100644 --- a/Telegram/SourceFiles/history/view/history_view_view_button.h +++ b/Telegram/SourceFiles/history/view/history_view_view_button.h @@ -9,8 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/chat_style.h" -struct HistoryMessageSponsored; - namespace Data { class Media; } // namespace Data @@ -23,10 +21,6 @@ struct TextState; class ViewButton { public: - ViewButton( - not_null sponsored, - uint8 colorIndex, - Fn updateCallback); ViewButton( not_null media, uint8 colorIndex,