From 773912f586fe8e67e0715d9105f8d8e146e18068 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 20 Jul 2021 12:13:32 +0300 Subject: [PATCH] Apply local / server comment updates together. --- .../SourceFiles/data/data_replies_list.cpp | 29 ++++--------------- .../history/history_inner_widget.cpp | 14 ++++----- .../SourceFiles/history/history_widget.cpp | 6 +++- .../history/view/history_view_list_widget.cpp | 14 +++++++-- .../history/view/history_view_list_widget.h | 4 +-- 5 files changed, 30 insertions(+), 37 deletions(-) diff --git a/Telegram/SourceFiles/data/data_replies_list.cpp b/Telegram/SourceFiles/data/data_replies_list.cpp index 7870cecb7..7ae7dea4a 100644 --- a/Telegram/SourceFiles/data/data_replies_list.cpp +++ b/Telegram/SourceFiles/data/data_replies_list.cpp @@ -44,7 +44,6 @@ struct RepliesList::Viewer { int limitAfter = 0; int injectedForRoot = 0; base::has_weak_ptr guard; - bool stale = true; bool scheduled = false; }; @@ -65,23 +64,6 @@ rpl::producer RepliesList::source( MessagePosition aroundId, int limitBefore, int limitAfter) { - return rpl::combine( - sourceFromServer(aroundId, limitBefore, limitAfter), - _history->session().changes().historyFlagsValue( - _history, - Data::HistoryUpdate::Flag::LocalMessages) - ) | rpl::filter([=](const MessagesSlice &data, const auto &) { - return (data.fullCount.value_or(0) >= 0); - }) | rpl::map([=](MessagesSlice &&server, const auto &) { - appendLocalMessages(server); - return std::move(server); - }); -} - -rpl::producer RepliesList::sourceFromServer( - MessagePosition aroundId, - int limitBefore, - int limitAfter) { const auto around = aroundId.fullId.msg; return [=](auto consumer) { auto lifetime = rpl::lifetime(); @@ -89,15 +71,11 @@ rpl::producer RepliesList::sourceFromServer( const auto push = [=] { viewer->scheduled = false; if (buildFromData(viewer)) { - viewer->stale = false; + appendLocalMessages(viewer->slice); consumer.put_next_copy(viewer->slice); } }; const auto pushDelayed = [=] { - if (!viewer->stale) { - viewer->stale = true; - consumer.put_next_copy(MessagesSlice{ .fullCount = -1 }); - } if (!viewer->scheduled) { viewer->scheduled = true; crl::on_main(&viewer->guard, push); @@ -115,6 +93,11 @@ rpl::producer RepliesList::sourceFromServer( return applyUpdate(viewer, update); }) | rpl::start_with_next(pushDelayed, lifetime); + _history->session().changes().historyUpdates( + _history, + Data::HistoryUpdate::Flag::LocalMessages + ) | rpl::start_with_next(pushDelayed, lifetime); + _partLoaded.events( ) | rpl::start_with_next(pushDelayed, lifetime); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 42337c014..f2e1511ac 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2377,16 +2377,14 @@ void HistoryInner::changeItemsRevealHeight(int revealHeight) { if (_revealHeight == revealHeight) { return; } - const auto old = std::exchange(_revealHeight, revealHeight); - resize(_scroll->width(), height() + old - _revealHeight); - if (!_revealHeight) { - mouseActionUpdate(QCursor::pos()); - } + _revealHeight = revealHeight; + updateSize(); } void HistoryInner::updateSize() { - int visibleHeight = _scroll->height(); - int newHistoryPaddingTop = qMax(visibleHeight - historyHeight() - st::historyPaddingBottom, 0); + const auto visibleHeight = _scroll->height(); + const auto itemsHeight = historyHeight() - _revealHeight; + int newHistoryPaddingTop = qMax(visibleHeight - itemsHeight - st::historyPaddingBottom, 0); if (_botAbout && !_botAbout->info->text.isEmpty()) { accumulate_max(newHistoryPaddingTop, st::msgMargin.top() + st::msgMargin.bottom() + st::msgPadding.top() + st::msgPadding.bottom() + st::msgNameFont->height + st::botDescSkip + _botAbout->height); } @@ -2408,7 +2406,7 @@ void HistoryInner::updateSize() { _historyPaddingTop = newHistoryPaddingTop; - int newHeight = _historyPaddingTop + historyHeight() + st::historyPaddingBottom - _revealHeight; + int newHeight = _historyPaddingTop + itemsHeight + st::historyPaddingBottom; if (width() != _scroll->width() || height() != newHeight) { resize(_scroll->width(), newHeight); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index a0b39cbc8..cf0f7f510 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -4895,6 +4895,10 @@ void HistoryWidget::revealItemsCallback() { if (_itemsRevealHeight != height) { const auto wasScrollTop = _scroll->scrollTop(); const auto wasAtBottom = (wasScrollTop == _scroll->scrollTopMax()); + if (!wasAtBottom) { + height = 0; + _itemRevealAnimations.clear(); + } _itemsRevealHeight = height; _list->changeItemsRevealHeight(_itemsRevealHeight); @@ -4920,7 +4924,7 @@ void HistoryWidget::startItemRevealAnimations() { [=] { revealItemsCallback(); }, 0., 1., - HistoryView::kItemRevealDuration, + HistoryView::ListWidget::kItemRevealDuration, anim::easeOutCirc); } } diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 294b66f70..f5947c697 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -75,6 +75,8 @@ ListWidget::MouseState::MouseState( , pointState(pointState) { } +const crl::time ListWidget::kItemRevealDuration = crl::time(150); + template void ListWidget::enumerateItems(Method method) { constexpr auto TopToBottom = (direction == EnumItemsDirection::TopToBottom); @@ -1455,7 +1457,12 @@ void ListWidget::revealItemsCallback() { } } if (_itemsRevealHeight != revealHeight) { - saveScrollState(); + updateVisibleTopItem(); + if (_visibleTopItem) { + // We're not at the bottom. + revealHeight = 0; + _itemRevealAnimations.clear(); + } const auto old = std::exchange(_itemsRevealHeight, revealHeight); const auto delta = old - _itemsRevealHeight; _itemsHeight += delta; @@ -1463,12 +1470,13 @@ void ListWidget::revealItemsCallback() { ? (_minHeight - _itemsHeight - st::historyPaddingBottom) : 0; const auto wasHeight = height(); - const auto nowHeight = std::min(_minHeight, wasHeight + delta); + const auto nowHeight = std::max(_minHeight, wasHeight + delta); if (wasHeight != nowHeight) { resize(width(), nowHeight); } update(); - restoreScrollState(); + restoreScrollPosition(); + updateVisibleTopItem(); if (!_itemsRevealHeight) { mouseActionUpdate(QCursor::pos()); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index a46041f58..67c256cde 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -143,8 +143,6 @@ private: }; -inline constexpr auto kItemRevealDuration = crl::time(150); - class ListWidget final : public Ui::RpWidget , public ElementDelegate @@ -156,6 +154,8 @@ public: not_null controller, not_null delegate); + static const crl::time kItemRevealDuration; + [[nodiscard]] Main::Session &session() const; [[nodiscard]] not_null controller() const; [[nodiscard]] not_null delegate() const;