Unread counters don't differ in/out messages in threads.
This commit is contained in:
parent
ec0380b250
commit
ef3ed760b1
|
@ -799,20 +799,9 @@ std::optional<int> RepliesList::computeUnreadCountLocally(
|
||||||
const auto fullLoaded = backLoaded && frontLoaded;
|
const auto fullLoaded = backLoaded && frontLoaded;
|
||||||
const auto allUnread = (readTillId == _rootId)
|
const auto allUnread = (readTillId == _rootId)
|
||||||
|| (fullLoaded && _list.empty());
|
|| (fullLoaded && _list.empty());
|
||||||
const auto countIncoming = [&](auto from, auto till) {
|
|
||||||
auto &owner = _history->owner();
|
|
||||||
const auto peerId = _history->peer->id;
|
|
||||||
auto count = 0;
|
|
||||||
for (auto i = from; i != till; ++i) {
|
|
||||||
if (!owner.message(peerId, *i)->out()) {
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
};
|
|
||||||
if (allUnread && fullLoaded) {
|
if (allUnread && fullLoaded) {
|
||||||
// Should not happen too often unless the list is empty.
|
// Should not happen too often unless the list is empty.
|
||||||
return countIncoming(begin(_list), end(_list));
|
return int(_list.size());
|
||||||
} else if (frontLoaded && !_list.empty() && readTillId >= _list.front()) {
|
} else if (frontLoaded && !_list.empty() && readTillId >= _list.front()) {
|
||||||
// Always "count by local data" if read till the end.
|
// Always "count by local data" if read till the end.
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -821,9 +810,8 @@ std::optional<int> RepliesList::computeUnreadCountLocally(
|
||||||
return wasUnreadCountAfter;
|
return wasUnreadCountAfter;
|
||||||
} else if (frontLoaded && !_list.empty() && readTillId >= _list.back()) {
|
} else if (frontLoaded && !_list.empty() && readTillId >= _list.back()) {
|
||||||
// And count by local data if it is available and read-till changed.
|
// And count by local data if it is available and read-till changed.
|
||||||
return countIncoming(
|
return int(ranges::lower_bound(_list, readTillId, std::greater<>())
|
||||||
begin(_list),
|
- begin(_list));
|
||||||
ranges::lower_bound(_list, readTillId, std::greater<>()));
|
|
||||||
} else if (_list.empty()) {
|
} else if (_list.empty()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
} else if (wasUnreadCountAfter.has_value()
|
} else if (wasUnreadCountAfter.has_value()
|
||||||
|
@ -839,7 +827,7 @@ std::optional<int> RepliesList::computeUnreadCountLocally(
|
||||||
end(_list),
|
end(_list),
|
||||||
wasReadTillId,
|
wasReadTillId,
|
||||||
std::greater<>());
|
std::greater<>());
|
||||||
return std::max(int(*wasUnreadCountAfter - (till - from)), 0);
|
return std::max(*wasUnreadCountAfter - int(till - from), 0);
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue