From 32d93e265121402b9f467bf773c86c2e56774ef9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 19 Feb 2020 16:40:01 +0400 Subject: [PATCH] Fix several read requests together. --- Telegram/SourceFiles/data/data_histories.cpp | 14 +++++++++++--- Telegram/SourceFiles/history/history.cpp | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/data/data_histories.cpp b/Telegram/SourceFiles/data/data_histories.cpp index 9c8dc7d826..27aef7d020 100644 --- a/Telegram/SourceFiles/data/data_histories.cpp +++ b/Telegram/SourceFiles/data/data_histories.cpp @@ -117,13 +117,13 @@ void Histories::readInboxTill(not_null 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, 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(); }; diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index c7be764d90..247b9893da 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -1667,7 +1667,7 @@ bool History::unreadCountRefreshNeeded(MsgId readTillId) const { } std::optional History::countStillUnreadLocal(MsgId readTillId) const { - if (isEmpty()) { + if (isEmpty() || !folderKnown()) { return std::nullopt; } if (_inboxReadBefore) {