Add CHECKs in register_poll/unregister_poll.

GitOrigin-RevId: 5e87cf053b6b174dd20070a8a1b1d45874080ec7
This commit is contained in:
levlam 2019-02-25 19:12:35 +03:00
parent 2c2866b5fc
commit 35d3be72f3

View File

@ -366,7 +366,8 @@ PollId PollManager::create_poll(string &&question, vector<string> &&options) {
void PollManager::register_poll(PollId poll_id, FullMessageId full_message_id) {
CHECK(have_poll(poll_id));
LOG(INFO) << "Register " << poll_id << " from " << full_message_id;
poll_messages_[poll_id].insert(full_message_id);
bool is_inserted = poll_messages_[poll_id].insert(full_message_id).second;
CHECK(is_inserted);
if (!td_->auth_manager_->is_bot() && !is_local_poll_id(poll_id) && !get_poll_is_closed(poll_id)) {
update_poll_timeout_.add_timeout_in(poll_id.get(), 0);
}
@ -376,7 +377,8 @@ void PollManager::unregister_poll(PollId poll_id, FullMessageId full_message_id)
CHECK(have_poll(poll_id));
LOG(INFO) << "Unregister " << poll_id << " from " << full_message_id;
auto &message_ids = poll_messages_[poll_id];
message_ids.erase(full_message_id);
auto is_deleted = message_ids.erase(full_message_id);
CHECK(is_deleted);
if (message_ids.empty()) {
poll_messages_.erase(poll_id);
update_poll_timeout_.cancel_timeout(poll_id.get());