From ac95df0213d538acfc70edfef664916b91c78821 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 10 Mar 2019 10:57:15 +0300 Subject: [PATCH] Ignore possibly outdated poll results. GitOrigin-RevId: 3d4c8b4a429ba3933ca2e22f08aaefc62a3b1691 --- td/telegram/PollManager.cpp | 20 +++++++++++++++----- td/telegram/PollManager.h | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index 5b9dbcd05..d7ddd54cc 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -683,6 +683,8 @@ void PollManager::stop_poll(PollId poll_id, FullMessageId full_message_id, Promi return; } + ++current_generation_; + poll->is_closed = true; notify_on_poll_update(poll_id); save_poll(poll, poll_id); @@ -753,14 +755,15 @@ void PollManager::on_update_poll_timeout(PollId poll_id) { auto full_message_id = *it->second.begin(); LOG(INFO) << "Fetching results of " << poll_id << " from " << full_message_id; - auto query_promise = PromiseCreator::lambda( - [poll_id, actor_id = actor_id(this)](Result> &&result) { - send_closure(actor_id, &PollManager::on_get_poll_results, poll_id, std::move(result)); - }); + auto query_promise = PromiseCreator::lambda([poll_id, generation = current_generation_, actor_id = actor_id(this)]( + Result> &&result) { + send_closure(actor_id, &PollManager::on_get_poll_results, poll_id, generation, std::move(result)); + }); td_->create_handler(std::move(query_promise))->send(poll_id, full_message_id); } -void PollManager::on_get_poll_results(PollId poll_id, Result> result) { +void PollManager::on_get_poll_results(PollId poll_id, uint64 generation, + Result> result) { if (result.is_error()) { if (!get_poll_is_closed(poll_id) && !td_->auth_manager_->is_bot()) { auto timeout = get_polling_timeout(); @@ -769,6 +772,13 @@ void PollManager::on_get_poll_results(PollId poll_id, Resultauth_manager_->is_bot()) { + update_poll_timeout_.set_timeout_in(poll_id.get(), 0.0); + } + return; + } td_->updates_manager_->on_get_updates(result.move_as_ok()); } diff --git a/td/telegram/PollManager.h b/td/telegram/PollManager.h index d61e081c9..3bb6148a7 100644 --- a/td/telegram/PollManager.h +++ b/td/telegram/PollManager.h @@ -137,7 +137,7 @@ class PollManager : public Actor { Poll *get_poll_force(PollId poll_id); - void on_get_poll_results(PollId poll_id, Result> result); + void on_get_poll_results(PollId poll_id, uint64 generation, Result> result); void do_set_poll_answer(PollId poll_id, FullMessageId full_message_id, vector &&options, uint64 logevent_id, Promise &&promise);