Fix handling errors to setPollAnswer.

GitOrigin-RevId: 686a76db9a69d7c19bda0c07d294ce9a448d09d4
This commit is contained in:
levlam 2020-04-04 02:44:25 +03:00
parent 1cb2141fee
commit 1e4c1f16b9
2 changed files with 17 additions and 0 deletions

View File

@ -314,6 +314,7 @@ string PollManager::get_poll_database_key(PollId poll_id) {
void PollManager::save_poll(const Poll *poll, PollId poll_id) { void PollManager::save_poll(const Poll *poll, PollId poll_id) {
CHECK(!is_local_poll_id(poll_id)); CHECK(!is_local_poll_id(poll_id));
poll->was_saved = true;
if (!G()->parameters().use_message_db) { if (!G()->parameters().use_message_db) {
return; return;
@ -788,6 +789,10 @@ void PollManager::on_set_poll_answer(PollId poll_id, uint64 generation,
auto promises = std::move(pending_answer.promises_); auto promises = std::move(pending_answer.promises_);
pending_answers_.erase(it); pending_answers_.erase(it);
auto poll = get_poll(poll_id);
if (poll != nullptr) {
poll->was_saved = false;
}
if (result.is_ok()) { if (result.is_ok()) {
td_->updates_manager_->on_get_updates(result.move_as_ok()); td_->updates_manager_->on_get_updates(result.move_as_ok());
@ -799,6 +804,17 @@ void PollManager::on_set_poll_answer(PollId poll_id, uint64 generation,
promise.set_error(result.error().clone()); promise.set_error(result.error().clone());
} }
} }
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) {
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;
}
} }
void PollManager::invalidate_poll_voters(const Poll *poll, PollId poll_id) { void PollManager::invalidate_poll_voters(const Poll *poll, PollId poll_id) {

View File

@ -112,6 +112,7 @@ class PollManager : public Actor {
bool allow_multiple_answers = false; bool allow_multiple_answers = false;
bool is_quiz = false; bool is_quiz = false;
bool is_closed = false; bool is_closed = false;
mutable bool was_saved = false;
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const; void store(StorerT &storer) const;