From f9d02740aa3c6a66e52d339ae4b008beb91c05f4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 21 Feb 2020 17:03:03 +0400 Subject: [PATCH] Don't send same read request more than once. --- Telegram/SourceFiles/data/data_histories.cpp | 11 ++++++++++- Telegram/SourceFiles/data/data_histories.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/data/data_histories.cpp b/Telegram/SourceFiles/data/data_histories.cpp index 169615fdc..f2326b313 100644 --- a/Telegram/SourceFiles/data/data_histories.cpp +++ b/Telegram/SourceFiles/data/data_histories.cpp @@ -154,6 +154,11 @@ void Histories::readInboxTill( return; } auto &state = _states[history]; + if (state.readTillSent >= tillId) { + return; + } else { + state.readTillSent = 0; + } const auto wasReadTill = state.readTill; state.readTill = tillId; if (force || !stillUnread || !*stillUnread) { @@ -401,6 +406,7 @@ void Histories::sendReadRequests() { void Histories::sendReadRequest(not_null history, State &state) { const auto tillId = state.readTill; state.readWhen = kReadRequestSent; + state.readTillSent = tillId; sendRequest(history, RequestType::ReadInbox, [=](Fn finish) { const auto finished = [=] { const auto state = lookup(history); @@ -409,6 +415,8 @@ void Histories::sendReadRequest(not_null history, State &state) { if (history->unreadCountRefreshNeeded(tillId)) { requestDialogEntry(history); + } else if (state->readTillSent == tillId) { + state->readTillSent = 0; } if (state->readWhen == kReadRequestSent) { state->readWhen = 0; @@ -448,7 +456,8 @@ void Histories::checkEmptyState(not_null history) { return state.postponed.empty() && !state.postponedRequestEntry && state.sent.empty() - && (state.readTill == 0); + && (state.readTill == 0) + && (state.readTillSent == 0); }; const auto i = _states.find(history); if (i != end(_states) && empty(i->second)) { diff --git a/Telegram/SourceFiles/data/data_histories.h b/Telegram/SourceFiles/data/data_histories.h index 21e4efa5e..a6973d639 100644 --- a/Telegram/SourceFiles/data/data_histories.h +++ b/Telegram/SourceFiles/data/data_histories.h @@ -88,6 +88,7 @@ private: base::flat_map sent; crl::time readWhen = 0; MsgId readTill = 0; + MsgId readTillSent = 0; bool postponedRequestEntry = false; };