2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Support poll closing by date.

This commit is contained in:
John Preston
2020-04-07 16:10:34 +04:00
parent 6882093ed1
commit 3cb76fb80b
4 changed files with 53 additions and 3 deletions

View File

@@ -191,6 +191,7 @@ Session::Session(not_null<Main::Session*> session)
, _sendActionsAnimation([=](crl::time now) {
return sendActionsAnimationCallback(now);
})
, _pollsClosingTimer([=] { checkPollsClosings(); })
, _unmuteByFinishedTimer([=] { unmuteByFinished(); })
, _groups(this)
, _chatsFilters(std::make_unique<ChatFilters>(this))
@@ -2877,6 +2878,10 @@ not_null<PollData*> Session::processPoll(const MTPPoll &data) {
if (changed) {
notifyPollUpdateDelayed(result);
}
if (result->closeDate > 0 && !result->closed()) {
_pollsClosings.emplace(result->closeDate, result);
checkPollsClosings();
}
return result;
});
}
@@ -2890,6 +2895,29 @@ not_null<PollData*> Session::processPoll(const MTPDmessageMediaPoll &data) {
return result;
}
void Session::checkPollsClosings() {
const auto now = base::unixtime::now();
auto closest = 0;
for (auto i = _pollsClosings.begin(); i != _pollsClosings.end();) {
if (i->first <= now) {
if (i->second->closeByTimer()) {
notifyPollUpdateDelayed(i->second);
}
i = _pollsClosings.erase(i);
} else {
if (!closest) {
closest = i->first;
}
++i;
}
}
if (closest) {
_pollsClosingTimer.callOnce((closest - now) * crl::time(1000));
} else {
_pollsClosingTimer.cancel();
}
}
void Session::applyUpdate(const MTPDupdateMessagePoll &update) {
const auto updated = [&] {
const auto poll = update.vpoll();