From 656a6412907db5dade026954699a241fe62b69c2 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 22 Dec 2020 01:51:20 +0300 Subject: [PATCH] Fix sending response to setPollAnser. --- td/telegram/PollManager.cpp | 40 ++++++++++++++++++++-------------- td/telegram/PollManager.h | 2 ++ td/telegram/UpdatesManager.cpp | 2 +- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index db9340335..2385c5b0e 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -844,26 +844,34 @@ void PollManager::on_set_poll_answer(PollId poll_id, uint64 generation, poll->was_saved = false; } if (result.is_ok()) { - td_->updates_manager_->on_get_updates(result.move_as_ok(), Promise()); - - for (auto &promise : promises) { - promise.set_value(Unit()); - } + td_->updates_manager_->on_get_updates( + result.move_as_ok(), PromiseCreator::lambda([actor_id = actor_id(this), poll_id, + promises = std::move(promises)](Result &&result) mutable { + send_closure(actor_id, &PollManager::on_set_poll_answer_finished, poll_id, Unit(), std::move(promises)); + })); } else { - for (auto &promise : promises) { - promise.set_error(result.error().clone()); + on_set_poll_answer_finished(poll_id, result.move_as_error(), std::move(promises)); + } +} + +void PollManager::on_set_poll_answer_finished(PollId poll_id, Result &&result, vector> &&promises) { + if (!G()->close_flag()) { + auto poll = get_poll(poll_id); + if (poll != nullptr && !poll->was_saved) { + // no updates was sent during updates processing, so send them + // poll wasn't changed, so there is no reason to actually save it + if (!(poll->is_closed && poll->is_updated_after_close)) { + LOG(INFO) << "Schedule updating of " << poll_id << " soon"; + update_poll_timeout_.set_timeout_in(poll_id.get(), 0.0); + } + + notify_on_poll_update(poll_id); + poll->was_saved = true; } } - if (poll != nullptr && !poll->was_saved) { - // no updates was sent during updates processing, so send them - // poll wasn't changed, so there is no reason to actually save it - if (!(poll->is_closed && poll->is_updated_after_close)) { - LOG(INFO) << "Schedule updating of " << poll_id << " soon"; - update_poll_timeout_.set_timeout_in(poll_id.get(), 0.0); - } - notify_on_poll_update(poll_id); - poll->was_saved = true; + for (auto &promise : promises) { + promise.set_result(result.clone()); } } diff --git a/td/telegram/PollManager.h b/td/telegram/PollManager.h index 6d8c63ff7..3af448a92 100644 --- a/td/telegram/PollManager.h +++ b/td/telegram/PollManager.h @@ -186,6 +186,8 @@ class PollManager : public Actor { void on_set_poll_answer(PollId poll_id, uint64 generation, Result> &&result); + void on_set_poll_answer_finished(PollId poll_id, Result &&result, vector> &&promises); + void invalidate_poll_voters(const Poll *poll, PollId poll_id); void invalidate_poll_option_voters(const Poll *poll, PollId poll_id, size_t option_index); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 812cadc27..f9dbc3e22 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1258,7 +1258,7 @@ void UpdatesManager::on_pending_updates(vector