diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 8f6bbc49a..6873d88cb 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -4330,8 +4330,8 @@ unique_ptr get_message_content(Td *td, FormattedText message, } case telegram_api::messageMediaPoll::ID: { auto media_poll = move_tl_object_as(media); - auto poll_id = - td->poll_manager_->on_get_poll(PollId(), std::move(media_poll->poll_), std::move(media_poll->results_)); + auto poll_id = td->poll_manager_->on_get_poll(PollId(), std::move(media_poll->poll_), + std::move(media_poll->results_), "messageMediaPoll"); if (!poll_id.is_valid()) { break; } diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index f0e18be73..b7a774d4b 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -1425,38 +1425,41 @@ vector PollManager::get_poll_options( } PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr &&poll_server, - tl_object_ptr &&poll_results) { + tl_object_ptr &&poll_results, const char *source) { bool is_bot = td_->auth_manager_->is_bot(); bool need_update_poll = poll_id.is_valid() && is_bot; if (!poll_id.is_valid() && poll_server != nullptr) { poll_id = PollId(poll_server->id_); } if (!poll_id.is_valid() || is_local_poll_id(poll_id)) { - LOG(ERROR) << "Receive " << poll_id << " from server: " << oneline(to_string(poll_server)) << " " + LOG(ERROR) << "Receive " << poll_id << " from " << source << ": " << oneline(to_string(poll_server)) << " " << oneline(to_string(poll_results)); return PollId(); } if (poll_server != nullptr && poll_server->id_ != poll_id.get()) { - LOG(ERROR) << "Receive poll " << poll_server->id_ << " instead of " << poll_id; + LOG(ERROR) << "Receive poll " << poll_server->id_ << " instead of " << poll_id << " from " << source; return PollId(); } constexpr size_t MAX_POLL_OPTIONS = 10; // server-side limit if (poll_server != nullptr && (poll_server->answers_.size() <= 1 || poll_server->answers_.size() > 10 * MAX_POLL_OPTIONS)) { - LOG(ERROR) << "Receive " << poll_id << " with wrong number of answers: " << to_string(poll_server); + LOG(ERROR) << "Receive " << poll_id << " from " << source + << " with wrong number of answers: " << to_string(poll_server); return PollId(); } if (poll_server != nullptr) { FlatHashSet option_data; for (auto &answer : poll_server->answers_) { if (answer->option_.empty()) { - LOG(ERROR) << "Receive " << poll_id << " with an empty option data: " << to_string(poll_server); + LOG(ERROR) << "Receive " << poll_id << " from " << source + << " with an empty option data: " << to_string(poll_server); return PollId(); } option_data.insert(answer->option_.as_slice()); } if (option_data.size() != poll_server->answers_.size()) { - LOG(ERROR) << "Receive " << poll_id << " with duplicate options: " << to_string(poll_server); + LOG(ERROR) << "Receive " << poll_id << " from " << source + << " with duplicate options: " << to_string(poll_server); return PollId(); } } @@ -1574,7 +1577,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptrflags_ & telegram_api::poll::MULTIPLE_CHOICE_MASK) != 0; bool is_quiz = (poll_server->flags_ & telegram_api::poll::QUIZ_MASK) != 0; if (is_quiz && allow_multiple_answers) { - LOG(ERROR) << "Receive quiz " << poll_id << " allowing multiple answers"; + LOG(ERROR) << "Receive quiz " << poll_id << " from " << source << " allowing multiple answers"; allow_multiple_answers = false; } if (allow_multiple_answers != poll->allow_multiple_answers) { @@ -1593,7 +1596,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptrtotal_voters_ != poll->total_voter_count) { poll->total_voter_count = poll_results->total_voters_; if (poll->total_voter_count < 0) { - LOG(ERROR) << "Receive " << poll->total_voter_count << " voters in " << poll_id; + LOG(ERROR) << "Receive " << poll->total_voter_count << " voters in " << poll_id << " from " << source; poll->total_voter_count = 0; } is_changed = true; @@ -1617,7 +1620,8 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptrcorrect_; if (is_correct) { if (correct_option_id != -1) { - LOG(ERROR) << "Receive more than 1 correct answers " << correct_option_id << " and " << option_index; + LOG(ERROR) << "Receive more than 1 correct answers " << correct_option_id << " and " << option_index + << " in " << poll_id << " from " << source; } correct_option_id = static_cast(option_index); } @@ -1626,21 +1630,23 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptrvoters_ < 0) { - LOG(ERROR) << "Receive " << poll_result->voters_ << " voters for an option in " << poll_id; + LOG(ERROR) << "Receive " << poll_result->voters_ << " voters for an option in " << poll_id << " from " + << source; poll_result->voters_ = 0; } if (option.is_chosen && poll_result->voters_ == 0) { - LOG(ERROR) << "Receive 0 voters for the chosen option in " << poll_id; + LOG(ERROR) << "Receive 0 voters for the chosen option in " << poll_id << " from " << source; poll_result->voters_ = 1; } if (poll_result->voters_ > poll->total_voter_count) { LOG(ERROR) << "Have only " << poll->total_voter_count << " poll voters, but there are " << poll_result->voters_ - << " voters for an option in " << poll_id; + << " voters for an option in " << poll_id << " from " << source; poll->total_voter_count = poll_result->voters_; } auto max_voter_count = std::numeric_limits::max() / narrow_cast(poll->options.size()) - 2; if (poll_result->voters_ > max_voter_count) { - LOG(ERROR) << "Have too many " << poll_result->voters_ << " poll voters for an option in " << poll_id; + LOG(ERROR) << "Have too many " << poll_result->voters_ << " poll voters for an option in " << poll_id + << " from " << source; poll_result->voters_ = max_voter_count; } if (poll_result->voters_ != option.voter_count) { @@ -1657,13 +1663,13 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptrtotal_voter_count > max_total_voter_count && max_total_voter_count != 0) { LOG(ERROR) << "Have only " << max_total_voter_count << " total poll voters, but there are " - << poll->total_voter_count << " voters in " << poll_id; + << poll->total_voter_count << " voters in " << poll_id << " from " << source; poll->total_voter_count = max_total_voter_count; } } auto entities = - get_message_entities(td_->contacts_manager_.get(), std::move(poll_results->solution_entities_), "on_get_poll"); + get_message_entities(td_->contacts_manager_.get(), std::move(poll_results->solution_entities_), source); auto status = fix_formatted_text(poll_results->solution_, entities, true, true, true, true, false); if (status.is_error()) { if (!clean_input_string(poll_results->solution_)) { @@ -1677,7 +1683,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptrcorrect_option_id != correct_option_id) { if (correct_option_id == -1 && poll->correct_option_id != -1) { LOG(ERROR) << "Can't change correct option of " << poll_id << " from " << poll->correct_option_id << " to " - << correct_option_id; + << correct_option_id << " from " << source; } else { poll->correct_option_id = correct_option_id; is_changed = true; @@ -1685,7 +1691,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptrexplanation != explanation && (!is_min || poll_server_is_closed)) { if (explanation.text.empty() && !poll->explanation.text.empty()) { - LOG(ERROR) << "Can't change known " << poll_id << " explanation to empty"; + LOG(ERROR) << "Can't change known " << poll_id << " explanation to empty from " << source ; } else { poll->explanation = std::move(explanation); is_changed = true; @@ -1693,10 +1699,10 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptris_anonymous && !recent_voter_user_ids.empty()) { - LOG(ERROR) << "Receive anonymous " << poll_id << " with recent voters " << recent_voter_user_ids; + LOG(ERROR) << "Receive anonymous " << poll_id << " with recent voters " << recent_voter_user_ids << " from " + << source; recent_voter_user_ids.clear(); } if (recent_voter_user_ids != poll->recent_voter_user_ids) { diff --git a/td/telegram/PollManager.h b/td/telegram/PollManager.h index 84ae3589e..e0f733dbb 100644 --- a/td/telegram/PollManager.h +++ b/td/telegram/PollManager.h @@ -77,7 +77,7 @@ class PollManager final : public Actor { tl_object_ptr get_input_media(PollId poll_id) const; PollId on_get_poll(PollId poll_id, tl_object_ptr &&poll_server, - tl_object_ptr &&poll_results); + tl_object_ptr &&poll_results, const char *source); void on_get_poll_vote(PollId poll_id, UserId user_id, vector &&options); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index fe91bf802..06e459965 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -3344,7 +3344,8 @@ void UpdatesManager::on_update(tl_object_ptr } void UpdatesManager::on_update(tl_object_ptr update, Promise &&promise) { - td_->poll_manager_->on_get_poll(PollId(update->poll_id_), std::move(update->poll_), std::move(update->results_)); + td_->poll_manager_->on_get_poll(PollId(update->poll_id_), std::move(update->poll_), std::move(update->results_), + "updateMessagePoll"); promise.set_value(Unit()); }