Gated history overscroll on load, removed ContinuousScroll.

This commit is contained in:
23rd
2026-07-07 16:19:13 +03:00
committed by John Preston
parent 0004582780
commit d5608c021a
7 changed files with 30 additions and 133 deletions
@@ -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<Ui::RpWidget*> parent,
not_null<Ui::ContinuousScroll*> scroll,
not_null<Ui::ElasticScroll*> scroll,
not_null<Window::SessionController*> controller)
: _parent(parent)
, _scroll(scroll)
@@ -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<Ui::RpWidget*> parent,
not_null<Ui::ContinuousScroll*> scroll,
not_null<Ui::ElasticScroll*> scroll,
not_null<Window::SessionController*> controller);
~PullToNextChannel();
@@ -58,7 +58,7 @@ private:
void jumpTo(not_null<History*> history);
const not_null<Ui::RpWidget*> _parent;
const not_null<Ui::ContinuousScroll*> _scroll;
const not_null<Ui::ElasticScroll*> _scroll;
const not_null<Window::SessionController*> _controller;
const base::unique_qptr<Indicator> _indicator;
const base::unique_qptr<HintOverlay> _hint;
+24 -30
View File
@@ -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;
@@ -83,7 +83,7 @@ class SendFilesWay;
class SendAsButton;
class SpoilerAnimation;
class ChooseThemeController;
class ContinuousScroll;
class ElasticScroll;
struct ChatPaintHighlight;
class ChatStyle;
template <typename Widget>
@@ -854,7 +854,7 @@ private:
int _supportPreloadRequest = 0; // Not real mtpRequestId.
object_ptr<HistoryView::TopBarWidget> _topBar;
object_ptr<Ui::ContinuousScroll> _scroll;
object_ptr<Ui::ElasticScroll> _scroll;
QPointer<HistoryInner> _list;
History *_migrated = nullptr;
History *_history = nullptr;
@@ -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 <QWheelEvent>
#include <QKeyEvent>
namespace Ui {
ContinuousScroll::ContinuousScroll(
QWidget *parent,
const style::ScrollArea &st,
Qt::Orientation orientation)
: ElasticScroll(parent, st, orientation) {
setCustomWheelProcess([=](not_null<QWheelEvent*> 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
@@ -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
-2
View File
@@ -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