diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index c7a6f9e8e..97102e32f 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -674,6 +674,10 @@ void PollManager::unregister_poll(PollId poll_id, FullMessageId full_message_id, auto &message_ids = other_poll_messages_[poll_id]; auto is_deleted = message_ids.erase(full_message_id) > 0; LOG_CHECK(is_deleted) << source << ' ' << poll_id << ' ' << full_message_id; + if (is_local_poll_id(poll_id)) { + CHECK(message_ids.empty()); + forget_local_poll(poll_id); + } if (message_ids.empty()) { other_poll_messages_.erase(poll_id); @@ -685,6 +689,10 @@ void PollManager::unregister_poll(PollId poll_id, FullMessageId full_message_id, auto &message_ids = server_poll_messages_[poll_id]; auto is_deleted = message_ids.erase(full_message_id) > 0; LOG_CHECK(is_deleted) << source << ' ' << poll_id << ' ' << full_message_id; + if (is_local_poll_id(poll_id)) { + CHECK(message_ids.empty()); + forget_local_poll(poll_id); + } if (message_ids.empty()) { server_poll_messages_.erase(poll_id); update_poll_timeout_.cancel_timeout(poll_id.get()); @@ -1308,6 +1316,18 @@ void PollManager::on_unload_poll_timeout(PollId poll_id) { unload_poll_timeout_.cancel_timeout(poll_id.get()); } +void PollManager::forget_local_poll(PollId poll_id) { + CHECK(is_local_poll_id(poll_id)); + + LOG(INFO) << "Forget " << poll_id; + + auto is_deleted = polls_.erase(poll_id) > 0; + CHECK(is_deleted); + + CHECK(poll_voters_.count(poll_id) == 0); + CHECK(loaded_from_database_polls_.count(poll_id) == 0); +} + void PollManager::on_get_poll_results(PollId poll_id, uint64 generation, Result> result) { auto poll = get_poll(poll_id); diff --git a/td/telegram/PollManager.h b/td/telegram/PollManager.h index e0f733dbb..59f3e0a03 100644 --- a/td/telegram/PollManager.h +++ b/td/telegram/PollManager.h @@ -213,6 +213,8 @@ class PollManager final : public Actor { void do_stop_poll(PollId poll_id, FullMessageId full_message_id, unique_ptr &&reply_markup, uint64 log_event_id, Promise &&promise); + void forget_local_poll(PollId poll_id); + MultiTimeout update_poll_timeout_{"UpdatePollTimeout"}; MultiTimeout close_poll_timeout_{"ClosePollTimeout"}; MultiTimeout unload_poll_timeout_{"UnloadPollTimeout"};