From cf481528531f9ce61a76e5bed49e56118cd16f0f Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 15 Sep 2020 18:30:12 +0300 Subject: [PATCH] Inject discussed message when no comments. --- .../SourceFiles/data/data_replies_list.cpp | 23 ++++++++++++++----- Telegram/SourceFiles/data/data_replies_list.h | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/data/data_replies_list.cpp b/Telegram/SourceFiles/data/data_replies_list.cpp index 6b892c163c..91131b703e 100644 --- a/Telegram/SourceFiles/data/data_replies_list.cpp +++ b/Telegram/SourceFiles/data/data_replies_list.cpp @@ -156,6 +156,18 @@ rpl::producer RepliesList::fullCount() const { return _fullCount.value() | rpl::filter_optional(); } +void RepliesList::injectRootMessage(not_null slice) { + if (slice->skippedBefore != 0) { + return; + } + if (const auto root = lookupRoot()) { + slice->ids.push_back(root->fullId()); + if (slice->fullCount) { + ++*slice->fullCount; + } + } +} + bool RepliesList::buildFromData(not_null viewer) { if (_list.empty() && _skippedBefore == 0 && _skippedAfter == 0) { viewer->slice.ids.clear(); @@ -163,6 +175,7 @@ bool RepliesList::buildFromData(not_null viewer) { = viewer->slice.skippedBefore = viewer->slice.skippedAfter = 0; + injectRootMessage(&viewer->slice); return true; } const auto around = [&] { @@ -205,14 +218,12 @@ bool RepliesList::buildFromData(not_null viewer) { for (auto j = i - useAfter, e = i + useBefore; j != e; ++j) { slice->ids.emplace_back(channelId, *j); } - if (slice->skippedBefore == 0) { - if (const auto root = lookupRoot()) { - slice->ids.push_back(root->fullId()); - } - } + slice->fullCount = _fullCount.current(); + + injectRootMessage(slice); + ranges::reverse(slice->ids); - slice->fullCount = _fullCount.current(); if (_skippedBefore != 0 && useBefore < viewer->limitBefore + 1) { loadBefore(); } diff --git a/Telegram/SourceFiles/data/data_replies_list.h b/Telegram/SourceFiles/data/data_replies_list.h index b9108a52e4..dedc9982c6 100644 --- a/Telegram/SourceFiles/data/data_replies_list.h +++ b/Telegram/SourceFiles/data/data_replies_list.h @@ -46,6 +46,7 @@ private: [[nodiscard]] bool applyUpdate( not_null viewer, const MessageUpdate &update); + void injectRootMessage(not_null slice); bool processMessagesIsEmpty(const MTPmessages_Messages &result); void loadAround(MsgId id); void loadBefore();