Reload poll data each 30 seconds without update.

This commit is contained in:
John Preston
2018-12-24 21:03:53 +04:00
parent b6a3bb4080
commit 6f176803d4
6 changed files with 40 additions and 0 deletions
+16
View File
@@ -7,8 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "data/data_poll.h"
#include "apiwrap.h"
#include "auth_session.h"
namespace {
constexpr auto kShortPollTimeout = 30 * TimeMs(1000);
const PollAnswer *AnswerByOption(
const std::vector<PollAnswer> &list,
const QByteArray &option) {
@@ -85,10 +90,21 @@ bool PollData::applyResults(const MTPPollResults &results) {
}
}
totalVoters = newTotalVoters;
lastResultsUpdate = getms();
return changed;
});
}
void PollData::checkResultsReload(not_null<HistoryItem*> item, TimeMs now) {
if (lastResultsUpdate && lastResultsUpdate + kShortPollTimeout > now) {
return;
} else if (closed) {
return;
}
lastResultsUpdate = now;
Auth().api().reloadPollResults(item);
}
PollAnswer *PollData::answerByOption(const QByteArray &option) {
return AnswerByOption(answers, option);
}