1
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-04-01 23:00:58 +00:00

Don't send same read request more than once.

This commit is contained in:
John Preston 2020-02-21 17:03:03 +04:00
parent ec7a2dce2f
commit f9d02740aa
2 changed files with 11 additions and 1 deletions
Telegram/SourceFiles/data

View File

@ -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*> history, State &state) {
const auto tillId = state.readTill;
state.readWhen = kReadRequestSent;
state.readTillSent = tillId;
sendRequest(history, RequestType::ReadInbox, [=](Fn<void()> finish) {
const auto finished = [=] {
const auto state = lookup(history);
@ -409,6 +415,8 @@ void Histories::sendReadRequest(not_null<History*> 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*> 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)) {

View File

@ -88,6 +88,7 @@ private:
base::flat_map<int, SentRequest> sent;
crl::time readWhen = 0;
MsgId readTill = 0;
MsgId readTillSent = 0;
bool postponedRequestEntry = false;
};