mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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 limitAfter = 0;
|
||||||
int injectedForRoot = 0;
|
int injectedForRoot = 0;
|
||||||
base::has_weak_ptr guard;
|
base::has_weak_ptr guard;
|
||||||
bool stale = true;
|
|
||||||
bool scheduled = false;
|
bool scheduled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,23 +64,6 @@ rpl::producer<MessagesSlice> RepliesList::source(
|
||||||
MessagePosition aroundId,
|
MessagePosition aroundId,
|
||||||
int limitBefore,
|
int limitBefore,
|
||||||
int limitAfter) {
|
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;
|
const auto around = aroundId.fullId.msg;
|
||||||
return [=](auto consumer) {
|
return [=](auto consumer) {
|
||||||
auto lifetime = rpl::lifetime();
|
auto lifetime = rpl::lifetime();
|
||||||
|
@ -89,15 +71,11 @@ rpl::producer<MessagesSlice> RepliesList::sourceFromServer(
|
||||||
const auto push = [=] {
|
const auto push = [=] {
|
||||||
viewer->scheduled = false;
|
viewer->scheduled = false;
|
||||||
if (buildFromData(viewer)) {
|
if (buildFromData(viewer)) {
|
||||||
viewer->stale = false;
|
appendLocalMessages(viewer->slice);
|
||||||
consumer.put_next_copy(viewer->slice);
|
consumer.put_next_copy(viewer->slice);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const auto pushDelayed = [=] {
|
const auto pushDelayed = [=] {
|
||||||
if (!viewer->stale) {
|
|
||||||
viewer->stale = true;
|
|
||||||
consumer.put_next_copy(MessagesSlice{ .fullCount = -1 });
|
|
||||||
}
|
|
||||||
if (!viewer->scheduled) {
|
if (!viewer->scheduled) {
|
||||||
viewer->scheduled = true;
|
viewer->scheduled = true;
|
||||||
crl::on_main(&viewer->guard, push);
|
crl::on_main(&viewer->guard, push);
|
||||||
|
@ -115,6 +93,11 @@ rpl::producer<MessagesSlice> RepliesList::sourceFromServer(
|
||||||
return applyUpdate(viewer, update);
|
return applyUpdate(viewer, update);
|
||||||
}) | rpl::start_with_next(pushDelayed, lifetime);
|
}) | rpl::start_with_next(pushDelayed, lifetime);
|
||||||
|
|
||||||
|
_history->session().changes().historyUpdates(
|
||||||
|
_history,
|
||||||
|
Data::HistoryUpdate::Flag::LocalMessages
|
||||||
|
) | rpl::start_with_next(pushDelayed, lifetime);
|
||||||
|
|
||||||
_partLoaded.events(
|
_partLoaded.events(
|
||||||
) | rpl::start_with_next(pushDelayed, lifetime);
|
) | rpl::start_with_next(pushDelayed, lifetime);
|
||||||
|
|
||||||
|
|
|
@ -2377,16 +2377,14 @@ void HistoryInner::changeItemsRevealHeight(int revealHeight) {
|
||||||
if (_revealHeight == revealHeight) {
|
if (_revealHeight == revealHeight) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto old = std::exchange(_revealHeight, revealHeight);
|
_revealHeight = revealHeight;
|
||||||
resize(_scroll->width(), height() + old - _revealHeight);
|
updateSize();
|
||||||
if (!_revealHeight) {
|
|
||||||
mouseActionUpdate(QCursor::pos());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryInner::updateSize() {
|
void HistoryInner::updateSize() {
|
||||||
int visibleHeight = _scroll->height();
|
const auto visibleHeight = _scroll->height();
|
||||||
int newHistoryPaddingTop = qMax(visibleHeight - historyHeight() - st::historyPaddingBottom, 0);
|
const auto itemsHeight = historyHeight() - _revealHeight;
|
||||||
|
int newHistoryPaddingTop = qMax(visibleHeight - itemsHeight - st::historyPaddingBottom, 0);
|
||||||
if (_botAbout && !_botAbout->info->text.isEmpty()) {
|
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);
|
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;
|
_historyPaddingTop = newHistoryPaddingTop;
|
||||||
|
|
||||||
int newHeight = _historyPaddingTop + historyHeight() + st::historyPaddingBottom - _revealHeight;
|
int newHeight = _historyPaddingTop + itemsHeight + st::historyPaddingBottom;
|
||||||
if (width() != _scroll->width() || height() != newHeight) {
|
if (width() != _scroll->width() || height() != newHeight) {
|
||||||
resize(_scroll->width(), newHeight);
|
resize(_scroll->width(), newHeight);
|
||||||
|
|
||||||
|
|
|
@ -4895,6 +4895,10 @@ void HistoryWidget::revealItemsCallback() {
|
||||||
if (_itemsRevealHeight != height) {
|
if (_itemsRevealHeight != height) {
|
||||||
const auto wasScrollTop = _scroll->scrollTop();
|
const auto wasScrollTop = _scroll->scrollTop();
|
||||||
const auto wasAtBottom = (wasScrollTop == _scroll->scrollTopMax());
|
const auto wasAtBottom = (wasScrollTop == _scroll->scrollTopMax());
|
||||||
|
if (!wasAtBottom) {
|
||||||
|
height = 0;
|
||||||
|
_itemRevealAnimations.clear();
|
||||||
|
}
|
||||||
|
|
||||||
_itemsRevealHeight = height;
|
_itemsRevealHeight = height;
|
||||||
_list->changeItemsRevealHeight(_itemsRevealHeight);
|
_list->changeItemsRevealHeight(_itemsRevealHeight);
|
||||||
|
@ -4920,7 +4924,7 @@ void HistoryWidget::startItemRevealAnimations() {
|
||||||
[=] { revealItemsCallback(); },
|
[=] { revealItemsCallback(); },
|
||||||
0.,
|
0.,
|
||||||
1.,
|
1.,
|
||||||
HistoryView::kItemRevealDuration,
|
HistoryView::ListWidget::kItemRevealDuration,
|
||||||
anim::easeOutCirc);
|
anim::easeOutCirc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,8 @@ ListWidget::MouseState::MouseState(
|
||||||
, pointState(pointState) {
|
, pointState(pointState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const crl::time ListWidget::kItemRevealDuration = crl::time(150);
|
||||||
|
|
||||||
template <ListWidget::EnumItemsDirection direction, typename Method>
|
template <ListWidget::EnumItemsDirection direction, typename Method>
|
||||||
void ListWidget::enumerateItems(Method method) {
|
void ListWidget::enumerateItems(Method method) {
|
||||||
constexpr auto TopToBottom = (direction == EnumItemsDirection::TopToBottom);
|
constexpr auto TopToBottom = (direction == EnumItemsDirection::TopToBottom);
|
||||||
|
@ -1455,7 +1457,12 @@ void ListWidget::revealItemsCallback() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_itemsRevealHeight != revealHeight) {
|
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 old = std::exchange(_itemsRevealHeight, revealHeight);
|
||||||
const auto delta = old - _itemsRevealHeight;
|
const auto delta = old - _itemsRevealHeight;
|
||||||
_itemsHeight += delta;
|
_itemsHeight += delta;
|
||||||
|
@ -1463,12 +1470,13 @@ void ListWidget::revealItemsCallback() {
|
||||||
? (_minHeight - _itemsHeight - st::historyPaddingBottom)
|
? (_minHeight - _itemsHeight - st::historyPaddingBottom)
|
||||||
: 0;
|
: 0;
|
||||||
const auto wasHeight = height();
|
const auto wasHeight = height();
|
||||||
const auto nowHeight = std::min(_minHeight, wasHeight + delta);
|
const auto nowHeight = std::max(_minHeight, wasHeight + delta);
|
||||||
if (wasHeight != nowHeight) {
|
if (wasHeight != nowHeight) {
|
||||||
resize(width(), nowHeight);
|
resize(width(), nowHeight);
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
restoreScrollState();
|
restoreScrollPosition();
|
||||||
|
updateVisibleTopItem();
|
||||||
|
|
||||||
if (!_itemsRevealHeight) {
|
if (!_itemsRevealHeight) {
|
||||||
mouseActionUpdate(QCursor::pos());
|
mouseActionUpdate(QCursor::pos());
|
||||||
|
|
|
@ -143,8 +143,6 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline constexpr auto kItemRevealDuration = crl::time(150);
|
|
||||||
|
|
||||||
class ListWidget final
|
class ListWidget final
|
||||||
: public Ui::RpWidget
|
: public Ui::RpWidget
|
||||||
, public ElementDelegate
|
, public ElementDelegate
|
||||||
|
@ -156,6 +154,8 @@ public:
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
not_null<ListDelegate*> delegate);
|
not_null<ListDelegate*> delegate);
|
||||||
|
|
||||||
|
static const crl::time kItemRevealDuration;
|
||||||
|
|
||||||
[[nodiscard]] Main::Session &session() const;
|
[[nodiscard]] Main::Session &session() const;
|
||||||
[[nodiscard]] not_null<Window::SessionController*> controller() const;
|
[[nodiscard]] not_null<Window::SessionController*> controller() const;
|
||||||
[[nodiscard]] not_null<ListDelegate*> delegate() const;
|
[[nodiscard]] not_null<ListDelegate*> delegate() const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue