diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index aa5efa4d..b92cec92 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -216,7 +216,7 @@ pollOption text:string voter_count:int32 vote_percentage:int32 is_chosen:Bool is //@description A regular poll @allow_multiple_answers True, if multiple answer options can be chosen simultaneously pollTypeRegular allow_multiple_answers:Bool = PollType; -//@description A quiz, which has exactly one correct answer option and can be answered only once @correct_option_id 0-based identifier of the correct answer option +//@description A quiz, which has exactly one correct answer option and can be answered only once @correct_option_id 0-based identifier of the correct answer option; -1 for a yet unanswered quiz pollTypeQuiz correct_option_id:int32 = PollType; diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index ff792681..df4240b3 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -528,7 +528,8 @@ td_api::object_ptr PollManager::get_poll_object(PollId poll_id, co } td_api::object_ptr poll_type; if (poll->is_quiz) { - poll_type = td_api::make_object(poll->correct_option_id); + auto correct_option_id = is_local_poll_id(poll_id) ? -1 : poll->correct_option_id; + poll_type = td_api::make_object(correct_option_id); } else { poll_type = td_api::make_object(poll->allow_multiple_answers); } @@ -1113,8 +1114,8 @@ tl_object_ptr PollManager::get_input_media(PollId poll } return telegram_api::make_object( flags, - telegram_api::make_object(0, flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, - false /*ignored*/, poll->question, + telegram_api::make_object(0, poll_flags, false /*ignored*/, false /*ignored*/, + false /*ignored*/, false /*ignored*/, poll->question, transform(poll->options, get_input_poll_option)), std::move(correct_answers)); } @@ -1223,7 +1224,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptrresults_.size(); i++) { auto &poll_result = poll_results->results_[i]; Slice data = poll_result->option_.as_slice(); - for (size_t option_index = 0; option_index < poll->options.size(); i++) { + for (size_t option_index = 0; option_index < poll->options.size(); option_index++) { auto &option = poll->options[option_index]; if (option.data != data) { continue; @@ -1280,16 +1281,12 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptris_quiz) { - if (correct_option_id == -1) { - LOG(ERROR) << "Have no correct option in quiz " << poll_id; - correct_option_id = 0; - } if (poll->correct_option_id != correct_option_id) { poll->correct_option_id = correct_option_id; is_changed = true; } } else if (correct_option_id != -1) { - LOG(ERROR) << "Receive correct option " << correct_option_id << " in quiz " << poll_id; + LOG(ERROR) << "Receive correct option " << correct_option_id << " in non-quiz " << poll_id; } vector recent_voter_user_ids; for (auto &user_id_int : poll_results->recent_voters_) { diff --git a/td/telegram/PollManager.hpp b/td/telegram/PollManager.hpp index e6e78e05..0cda4b19 100644 --- a/td/telegram/PollManager.hpp +++ b/td/telegram/PollManager.hpp @@ -82,7 +82,7 @@ void PollManager::Poll::parse(ParserT &parser) { parse(total_voter_count, parser); if (is_quiz) { parse(correct_option_id, parser); - if (correct_option_id < 0 || correct_option_id >= static_cast(options.size())) { + if (correct_option_id < -1 || correct_option_id >= static_cast(options.size())) { parser.set_error("Wrong correct_option_id"); } } @@ -138,7 +138,7 @@ PollId PollManager::parse_poll(ParserT &parser) { parse(options, parser); if (is_quiz) { parse(correct_option_id, parser); - if (correct_option_id < 0 || correct_option_id >= static_cast(options.size())) { + if (correct_option_id < -1 || correct_option_id >= static_cast(options.size())) { parser.set_error("Wrong correct_option_id"); } } diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 59ca18a4..fb30dce5 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3194,7 +3194,7 @@ class CliClient final : public Actor { send_message(chat_id, td_api::make_object(as_location(latitude, longitude), to_integer(period))); - } else if (op == "spoll" || op == "spollm" || op == "squiz") { + } else if (op == "spoll" || op == "spollm" || op == "spollp" || op == "squiz") { string chat_id; string question; std::tie(chat_id, args) = split(args); @@ -3207,7 +3207,7 @@ class CliClient final : public Actor { } else { poll_type = td_api::make_object(op == "spollm"); } - send_message(chat_id, td_api::make_object(question, std::move(options), true, + send_message(chat_id, td_api::make_object(question, std::move(options), op != "spollp", std::move(poll_type))); } else if (op == "sp" || op == "spcaption" || op == "spttl") { string chat_id;