diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 95000dde6..17e480fbc 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -2675,6 +2675,10 @@ QString History::topPromotionMessage() const { return _topPromotedMessage; } +bool History::canHaveSponsoredMessages() const { + return isChannel(); +} + bool History::clearUnreadOnClientSide() const { if (!session().supportMode()) { return false; diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index 956be8a95..88b44b493 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -282,6 +282,8 @@ public: [[nodiscard]] bool topPromotionAboutShown() const; void markTopPromotionAboutShown(); + [[nodiscard]] bool canHaveSponsoredMessages() const; + MsgId minMsgId() const; MsgId maxMsgId() const; MsgId msgIdForRead() const; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index cad1f08de..13efe5da9 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -56,6 +56,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_chat_filters.h" #include "data/data_scheduled_messages.h" +#include "data/data_sponsored_messages.h" #include "data/data_file_origin.h" #include "data/data_histories.h" #include "data/data_group_call.h" @@ -109,6 +110,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/group_call_bar.h" #include "ui/chat/chat_theme.h" #include "ui/chat/chat_style.h" +#include "ui/chat/continuous_scroll.h" #include "ui/widgets/popup_menu.h" #include "ui/item_text_options.h" #include "ui/unread_badge.h" @@ -260,6 +262,14 @@ HistoryWidget::HistoryWidget( ) | rpl::start_with_next(crl::guard(_list, [=] { _list->onParentGeometryChanged(); }), lifetime()); + _scroll->addContentRequests( + ) | rpl::start_with_next([=] { + if (_history->loadedAtBottom() + && session().data().sponsoredMessages().append(_history)) { + _scroll->contentAdded(); + } + }, lifetime()); + _historyDown->addClickHandler([=] { historyDownClicked(); }); _unreadMentions->addClickHandler([=] { showNextUnreadMention(); }); _fieldBarCancel->addClickHandler([=] { cancelFieldAreaState(); }); @@ -1966,6 +1976,8 @@ void HistoryWidget::showHistory( } } return; + } else { + session().data().sponsoredMessages().clearItems(_history); } session().sendProgressManager().update( _history, @@ -2169,6 +2181,14 @@ void HistoryWidget::showHistory( } unreadCountUpdated(); // set _historyDown badge. showAboutTopPromotion(); + + { + const auto hasSponsored = _history->canHaveSponsoredMessages(); + _scroll->setTrackingContent(hasSponsored); + if (hasSponsored) { + session().data().sponsoredMessages().request(_history); + } + } } else { _chooseForReport = nullptr; refreshTopBarActiveChat(); @@ -2616,6 +2636,16 @@ void HistoryWidget::newItemAdded(not_null item) { || item->isScheduled()) { return; } + if (item->isSponsored()) { + if (const auto view = item->mainView()) { + view->resizeGetHeight(width()); + updateHistoryGeometry( + false, + true, + { ScrollChangeNoJumpToBottom, 0 }); + } + return; + } // If we get here in non-resized state we can't rely on results of // doWeReadServerHistory() and mark chat as read. diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 8bd0c68ea..c8d70ca77 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -80,6 +80,7 @@ namespace Toast { class Instance; } // namespace Toast class ChooseThemeController; +class ContinuousScroll; } // namespace Ui namespace Window { @@ -675,7 +676,7 @@ private: int _delayedShowAtRequest = 0; // Not real mtpRequestId. object_ptr _topBar; - object_ptr _scroll; + object_ptr _scroll; QPointer _list; History *_migrated = nullptr; History *_history = nullptr;