mirror of https://github.com/procxx/kepka.git
Don't send same read request more than once.
This commit is contained in:
parent
ec7a2dce2f
commit
f9d02740aa
|
@ -154,6 +154,11 @@ void Histories::readInboxTill(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto &state = _states[history];
|
auto &state = _states[history];
|
||||||
|
if (state.readTillSent >= tillId) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
state.readTillSent = 0;
|
||||||
|
}
|
||||||
const auto wasReadTill = state.readTill;
|
const auto wasReadTill = state.readTill;
|
||||||
state.readTill = tillId;
|
state.readTill = tillId;
|
||||||
if (force || !stillUnread || !*stillUnread) {
|
if (force || !stillUnread || !*stillUnread) {
|
||||||
|
@ -401,6 +406,7 @@ void Histories::sendReadRequests() {
|
||||||
void Histories::sendReadRequest(not_null<History*> history, State &state) {
|
void Histories::sendReadRequest(not_null<History*> history, State &state) {
|
||||||
const auto tillId = state.readTill;
|
const auto tillId = state.readTill;
|
||||||
state.readWhen = kReadRequestSent;
|
state.readWhen = kReadRequestSent;
|
||||||
|
state.readTillSent = tillId;
|
||||||
sendRequest(history, RequestType::ReadInbox, [=](Fn<void()> finish) {
|
sendRequest(history, RequestType::ReadInbox, [=](Fn<void()> finish) {
|
||||||
const auto finished = [=] {
|
const auto finished = [=] {
|
||||||
const auto state = lookup(history);
|
const auto state = lookup(history);
|
||||||
|
@ -409,6 +415,8 @@ void Histories::sendReadRequest(not_null<History*> history, State &state) {
|
||||||
|
|
||||||
if (history->unreadCountRefreshNeeded(tillId)) {
|
if (history->unreadCountRefreshNeeded(tillId)) {
|
||||||
requestDialogEntry(history);
|
requestDialogEntry(history);
|
||||||
|
} else if (state->readTillSent == tillId) {
|
||||||
|
state->readTillSent = 0;
|
||||||
}
|
}
|
||||||
if (state->readWhen == kReadRequestSent) {
|
if (state->readWhen == kReadRequestSent) {
|
||||||
state->readWhen = 0;
|
state->readWhen = 0;
|
||||||
|
@ -448,7 +456,8 @@ void Histories::checkEmptyState(not_null<History*> history) {
|
||||||
return state.postponed.empty()
|
return state.postponed.empty()
|
||||||
&& !state.postponedRequestEntry
|
&& !state.postponedRequestEntry
|
||||||
&& state.sent.empty()
|
&& state.sent.empty()
|
||||||
&& (state.readTill == 0);
|
&& (state.readTill == 0)
|
||||||
|
&& (state.readTillSent == 0);
|
||||||
};
|
};
|
||||||
const auto i = _states.find(history);
|
const auto i = _states.find(history);
|
||||||
if (i != end(_states) && empty(i->second)) {
|
if (i != end(_states) && empty(i->second)) {
|
||||||
|
|
|
@ -88,6 +88,7 @@ private:
|
||||||
base::flat_map<int, SentRequest> sent;
|
base::flat_map<int, SentRequest> sent;
|
||||||
crl::time readWhen = 0;
|
crl::time readWhen = 0;
|
||||||
MsgId readTill = 0;
|
MsgId readTill = 0;
|
||||||
|
MsgId readTillSent = 0;
|
||||||
bool postponedRequestEntry = false;
|
bool postponedRequestEntry = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue