mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Apply local / server comment updates together.
This commit is contained in:
parent
c789349b24
commit
773912f586
5 changed files with 30 additions and 37 deletions
|
@ -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<MessagesSlice> 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<MessagesSlice> 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<MessagesSlice> 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<MessagesSlice> 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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,6 +75,8 @@ ListWidget::MouseState::MouseState(
|
|||
, pointState(pointState) {
|
||||
}
|
||||
|
||||
const crl::time ListWidget::kItemRevealDuration = crl::time(150);
|
||||
|
||||
template <ListWidget::EnumItemsDirection direction, typename Method>
|
||||
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());
|
||||
|
|
|
@ -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<Window::SessionController*> controller,
|
||||
not_null<ListDelegate*> delegate);
|
||||
|
||||
static const crl::time kItemRevealDuration;
|
||||
|
||||
[[nodiscard]] Main::Session &session() const;
|
||||
[[nodiscard]] not_null<Window::SessionController*> controller() const;
|
||||
[[nodiscard]] not_null<ListDelegate*> delegate() const;
|
||||
|
|
Loading…
Add table
Reference in a new issue