diff --git a/Telegram/SourceFiles/history/history_view_pull_to_next_channel.cpp b/Telegram/SourceFiles/history/history_view_pull_to_next_channel.cpp index 74b750b54f..e5e0fa1aa3 100644 --- a/Telegram/SourceFiles/history/history_view_pull_to_next_channel.cpp +++ b/Telegram/SourceFiles/history/history_view_pull_to_next_channel.cpp @@ -28,7 +28,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_shared_media.h" #include "support/support_preload.h" #include "ui/chat/chat_style.h" -#include "ui/chat/continuous_scroll.h" #include "ui/widgets/elastic_scroll.h" #include "ui/rect.h" #include "ui/rp_widget.h" @@ -568,7 +567,7 @@ void PullToNextChannel::HintOverlay::paintEvent(QPaintEvent *e) { PullToNextChannel::PullToNextChannel( not_null parent, - not_null scroll, + not_null scroll, not_null controller) : _parent(parent) , _scroll(scroll) diff --git a/Telegram/SourceFiles/history/history_view_pull_to_next_channel.h b/Telegram/SourceFiles/history/history_view_pull_to_next_channel.h index a598453026..bd316b8f68 100644 --- a/Telegram/SourceFiles/history/history_view_pull_to_next_channel.h +++ b/Telegram/SourceFiles/history/history_view_pull_to_next_channel.h @@ -16,7 +16,7 @@ class HistoryInner; namespace Ui { class RpWidget; -class ContinuousScroll; +class ElasticScroll; struct ElasticScrollPosition; enum class ElasticScrollMovement; } // namespace Ui @@ -31,7 +31,7 @@ class PullToNextChannel final { public: PullToNextChannel( not_null parent, - not_null scroll, + not_null scroll, not_null controller); ~PullToNextChannel(); @@ -58,7 +58,7 @@ private: void jumpTo(not_null history); const not_null _parent; - const not_null _scroll; + const not_null _scroll; const not_null _controller; const base::unique_qptr _indicator; const base::unique_qptr _hint; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 93bc0f920f..9b20ec7c09 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -176,7 +176,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/requests_bar.h" #include "ui/chat/chat_theme.h" #include "ui/chat/chat_style.h" -#include "ui/chat/continuous_scroll.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/elastic_scroll.h" #include "ui/widgets/popup_menu.h" @@ -381,37 +380,37 @@ HistoryWidget::HistoryWidget( handleScroll(); }, lifetime()); _scroll->setOverscrollTypes( - Ui::ElasticScroll::OverscrollType::None, + Ui::ElasticScroll::OverscrollType::Real, Ui::ElasticScroll::OverscrollType::Real); _scroll->setOverscrollBg(QColor(0, 0, 0, 0)); + _scroll->setOverscrollEdges( + [=] { return historyLoadedAtTop(); }, + [=] { return historyLoadedAtBottom(); }); _scroll->geometryChanged( ) | rpl::on_next(crl::guard(_list, [=] { _list->onParentGeometryChanged(); }), lifetime()); - _scroll->addContentRequests( - ) | rpl::on_next([=] { - if (_history && _history->loadedAtBottom()) { - using Result = Data::SponsoredMessages::AppendResult; - const auto tryToAppend = [=] { - const auto sponsored = &session().sponsoredMessages(); - const auto result = sponsored->append(_history); - if (result == Result::Appended) { - _scroll->contentAdded(); - } - return result; - }; - if (tryToAppend() == Result::MediaLoading - && !_historySponsoredPreloading) { - session().downloaderTaskFinished( - ) | rpl::on_next([=] { - if (tryToAppend() != Result::MediaLoading) { - _historySponsoredPreloading.destroy(); - } - }, _historySponsoredPreloading); - } + _scroll->setBottomContentRequest([=] { + if (!_history || !_history->loadedAtBottom()) { + return false; } - }, lifetime()); + using Result = Data::SponsoredMessages::AppendResult; + const auto tryToAppend = [=] { + return session().sponsoredMessages().append(_history); + }; + const auto result = tryToAppend(); + if (result == Result::MediaLoading + && !_historySponsoredPreloading) { + session().downloaderTaskFinished( + ) | rpl::on_next([=] { + if (tryToAppend() != Result::MediaLoading) { + _historySponsoredPreloading.destroy(); + } + }, _historySponsoredPreloading); + } + return (result == Result::Appended); + }); _fieldBarCancel->addClickHandler([=] { cancelFieldAreaState(); }); _send->addClickHandler([=] { sendButtonClicked(); }); @@ -3260,18 +3259,13 @@ void HistoryWidget::showHistory( showAboutTopPromotion(); if (!session().sponsoredMessages().isTopBarFor(_history)) { - _scroll->setTrackingContent(false); const auto checkState = [=] { using State = Data::SponsoredMessages::State; const auto state = session().sponsoredMessages().state( _history); _sponsoredMessagesStateKnown = (state != State::None); - if (state == State::AppendToEnd) { - _scroll->setTrackingContent( - session().sponsoredMessages().canHaveFor(_history)); - } else if (state == State::InjectToMiddle) { + if (state == State::InjectToMiddle) { injectSponsoredMessages(); - } else if (state == State::AppendToTopBar) { } }; const auto history = _history; diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 81fd282606..88e50685c4 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -83,7 +83,7 @@ class SendFilesWay; class SendAsButton; class SpoilerAnimation; class ChooseThemeController; -class ContinuousScroll; +class ElasticScroll; struct ChatPaintHighlight; class ChatStyle; template @@ -854,7 +854,7 @@ private: int _supportPreloadRequest = 0; // Not real mtpRequestId. object_ptr _topBar; - object_ptr _scroll; + object_ptr _scroll; QPointer _list; History *_migrated = nullptr; History *_history = nullptr; diff --git a/Telegram/SourceFiles/ui/chat/continuous_scroll.cpp b/Telegram/SourceFiles/ui/chat/continuous_scroll.cpp deleted file mode 100644 index 2bd8528d10..0000000000 --- a/Telegram/SourceFiles/ui/chat/continuous_scroll.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#include "ui/chat/continuous_scroll.h" - -#include -#include - -namespace Ui { - -ContinuousScroll::ContinuousScroll( - QWidget *parent, - const style::ScrollArea &st, - Qt::Orientation orientation) -: ElasticScroll(parent, st, orientation) { - setCustomWheelProcess([=](not_null e) { - if (_tracking - && !e->angleDelta().isNull() - && (e->angleDelta().y() < 0) - && (scrollTopMax() == scrollTop())) { - _addContentRequests.fire({}); - // Carry into freshly appended content, else swallow the over-scroll. - return !base::take(_contentAdded); - } - return false; - }); -} - -void ContinuousScroll::keyPressEvent(QKeyEvent *e) { - const auto key = e->key(); - if (_tracking - && (key == Qt::Key_Down || key == Qt::Key_PageDown) - && (scrollTopMax() == scrollTop())) { - _addContentRequests.fire({}); - base::take(_contentAdded); - } - ElasticScroll::keyPressEvent(e); -} - -void ContinuousScroll::setTrackingContent(bool value) { - _tracking = value; -} - -void ContinuousScroll::contentAdded() { - _contentAdded = true; -} - -rpl::producer<> ContinuousScroll::addContentRequests() const { - return _addContentRequests.events(); -} - -} // namespace Ui diff --git a/Telegram/SourceFiles/ui/chat/continuous_scroll.h b/Telegram/SourceFiles/ui/chat/continuous_scroll.h deleted file mode 100644 index 7f3c63495d..0000000000 --- a/Telegram/SourceFiles/ui/chat/continuous_scroll.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#pragma once - -#include "ui/widgets/elastic_scroll.h" - -namespace Ui { - -// This class is designed for seamless scrolling of -// on-demand augmented content. -class ContinuousScroll final : public ElasticScroll { -public: - ContinuousScroll( - QWidget *parent, - const style::ScrollArea &st = st::defaultScrollArea, - Qt::Orientation orientation = Qt::Vertical); - - void keyPressEvent(QKeyEvent *e) override; - - [[nodiscard]] rpl::producer<> addContentRequests() const; - void contentAdded(); - - void setTrackingContent(bool value); - -private: - bool _contentAdded = false; - bool _tracking = false; - - rpl::event_stream<> _addContentRequests; - -}; - -} // namespace Ui diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index 917c342c9e..0e24e68bad 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -398,8 +398,6 @@ PRIVATE ui/chat/chat_theme.h ui/chat/chats_filter_tag.cpp ui/chat/chats_filter_tag.h - ui/chat/continuous_scroll.cpp - ui/chat/continuous_scroll.h ui/chat/forward_options_box.cpp ui/chat/forward_options_box.h ui/chat/group_call_bar.cpp