Force reload results on auto-closed quiz.

This commit is contained in:
John Preston 2020-04-13 12:27:53 +04:00
parent b34d5b8306
commit 5dcb232b77
2 changed files with 11 additions and 7 deletions

View File

@ -48,6 +48,7 @@ bool PollData::closeByTimer() {
return false;
}
_flags |= Flag::Closed;
_lastResultsUpdate = -1; // Force reload results.
++version;
return true;
}
@ -105,7 +106,7 @@ bool PollData::applyChanges(const MTPDpoll &poll) {
bool PollData::applyResults(const MTPPollResults &results) {
return results.match([&](const MTPDpollResults &results) {
lastResultsUpdate = crl::now();
_lastResultsUpdate = crl::now();
const auto newTotalVoters =
results.vtotal_voters().value_or(totalVoters);
@ -158,13 +159,16 @@ bool PollData::applyResults(const MTPPollResults &results) {
});
}
void PollData::checkResultsReload(not_null<HistoryItem*> item, crl::time now) {
if (lastResultsUpdate && lastResultsUpdate + kShortPollTimeout > now) {
void PollData::checkResultsReload(
not_null<HistoryItem*> item,
crl::time now) {
if (_lastResultsUpdate > 0
&& _lastResultsUpdate + kShortPollTimeout > now) {
return;
} else if (closed()) {
} else if (closed() && _lastResultsUpdate >= 0) {
return;
}
lastResultsUpdate = now;
_lastResultsUpdate = now;
_owner->session().api().reloadPollResults(item);
}

View File

@ -62,7 +62,6 @@ struct PollData {
std::vector<PollAnswer> answers;
std::vector<not_null<UserData*>> recentVoters;
std::vector<QByteArray> sendingVotes;
crl::time lastResultsUpdate = 0;
TextWithEntities solution;
TimeId closePeriod = 0;
TimeId closeDate = 0;
@ -76,8 +75,9 @@ private:
const MTPPollAnswerVoters &result,
bool isMinResults);
not_null<Data::Session*> _owner;
const not_null<Data::Session*> _owner;
Flags _flags = Flags();
crl::time _lastResultsUpdate = 0; // < 0 means force reload.
};