2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Fix opening Replies section on unread bar.

This commit is contained in:
John Preston
2020-10-02 19:26:04 +03:00
parent 8d70a62ee8
commit 4b6d74dd9b
7 changed files with 45 additions and 10 deletions

View File

@@ -479,9 +479,15 @@ void MessagesSliceBuilder::requestMessagesCount() {
MessagesSlice MessagesSliceBuilder::snapshot() const {
auto result = MessagesSlice();
result.ids.reserve(_ids.size());
auto nearestToAround = std::optional<FullMsgId>();
for (const auto &position : _ids) {
result.ids.push_back(position.fullId);
if (!nearestToAround && position >= _key) {
nearestToAround = position.fullId;
}
}
result.nearestToAround = nearestToAround.value_or(
_ids.empty() ? FullMsgId() : _ids.back().fullId);
result.skippedBefore = _skippedBefore;
result.skippedAfter = _skippedAfter;
result.fullCount = _fullCount;

View File

@@ -93,10 +93,10 @@ constexpr auto UnreadMessagePosition = MessagePosition(
struct MessagesSlice {
std::vector<FullMsgId> ids;
FullMsgId nearestToAround;
std::optional<int> skippedBefore;
std::optional<int> skippedAfter;
std::optional<int> fullCount;
};
struct MessagesQuery {
@@ -112,7 +112,6 @@ struct MessagesQuery {
MessagePosition aroundId;
int limitBefore = 0;
int limitAfter = 0;
};
struct MessagesResult {

View File

@@ -227,6 +227,7 @@ void RepliesList::injectRootDivider(
bool RepliesList::buildFromData(not_null<Viewer*> viewer) {
if (_list.empty() && _skippedBefore == 0 && _skippedAfter == 0) {
viewer->slice.ids.clear();
viewer->slice.nearestToAround = FullMsgId();
viewer->slice.fullCount
= viewer->slice.skippedBefore
= viewer->slice.skippedAfter
@@ -268,10 +269,20 @@ bool RepliesList::buildFromData(not_null<Viewer*> viewer) {
const auto channelId = _history->channelId();
slice->ids.clear();
auto nearestToAround = std::optional<MsgId>();
slice->ids.reserve(useAfter + useBefore);
for (auto j = i - useAfter, e = i + useBefore; j != e; ++j) {
if (!nearestToAround && *j < around) {
nearestToAround = (j == i - useAfter)
? *j
: *(j - 1);
}
slice->ids.emplace_back(channelId, *j);
}
slice->nearestToAround = FullMsgId(
channelId,
nearestToAround.value_or(
slice->ids.empty() ? 0 : slice->ids.back().msg));
slice->fullCount = _fullCount.current();
injectRootMessageAndReverse(slice);