Fix several read requests together.

This commit is contained in:
John Preston 2020-02-19 16:40:01 +04:00
parent 9cccea9a87
commit 32d93e2651
2 changed files with 12 additions and 4 deletions

View File

@ -117,13 +117,13 @@ void Histories::readInboxTill(not_null<History*> history, MsgId tillId) {
return;
}
auto &state = _states[history];
const auto wasWaiting = (state.readTill != 0);
const auto wasReadTill = state.readTill;
state.readTill = tillId;
if (!stillUnread) {
state.readWhen = 0;
sendReadRequests();
return;
} else if (!wasWaiting) {
} else if (!wasReadTill) {
state.readWhen = crl::now() + kReadRequestTimeout;
if (!_readRequestsTimer.isActive()) {
_readRequestsTimer.callOnce(kReadRequestTimeout);
@ -158,6 +158,8 @@ void Histories::sendReadRequests() {
}
if (next.has_value()) {
_readRequestsTimer.callOnce(*next - now);
} else {
_readRequestsTimer.cancel();
}
}
@ -168,12 +170,18 @@ void Histories::sendReadRequest(not_null<History*> history, State &state) {
const auto finished = [=] {
const auto state = lookup(history);
Assert(state != nullptr);
Assert(state->readTill >= tillId);
if (history->unreadCountRefreshNeeded(tillId)) {
session().api().requestDialogEntry(history);
}
if (state->readWhen == kReadRequestSent) {
state->readWhen = 0;
state->readTill = 0;
if (state->readTill == tillId) {
state->readTill = 0;
} else {
sendReadRequests();
}
}
done();
};

View File

@ -1667,7 +1667,7 @@ bool History::unreadCountRefreshNeeded(MsgId readTillId) const {
}
std::optional<int> History::countStillUnreadLocal(MsgId readTillId) const {
if (isEmpty()) {
if (isEmpty() || !folderKnown()) {
return std::nullopt;
}
if (_inboxReadBefore) {