New polls support fixes.

GitOrigin-RevId: f5421227029a8ae1f9284882e6f6221617002925
This commit is contained in:
levlam 2020-01-14 01:51:03 +03:00
parent 6d15cc7bf0
commit da4694bc81
4 changed files with 11 additions and 14 deletions

View File

@ -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;

View File

@ -528,7 +528,8 @@ td_api::object_ptr<td_api::poll> PollManager::get_poll_object(PollId poll_id, co
}
td_api::object_ptr<td_api::PollType> poll_type;
if (poll->is_quiz) {
poll_type = td_api::make_object<td_api::pollTypeQuiz>(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<td_api::pollTypeQuiz>(correct_option_id);
} else {
poll_type = td_api::make_object<td_api::pollTypeRegular>(poll->allow_multiple_answers);
}
@ -1113,8 +1114,8 @@ tl_object_ptr<telegram_api::InputMedia> PollManager::get_input_media(PollId poll
}
return telegram_api::make_object<telegram_api::inputMediaPoll>(
flags,
telegram_api::make_object<telegram_api::poll>(0, flags, false /*ignored*/, false /*ignored*/, false /*ignored*/,
false /*ignored*/, poll->question,
telegram_api::make_object<telegram_api::poll>(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_ptr<telegram_api::poll
for (size_t i = 0; i < poll_results->results_.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_ptr<telegram_api::poll
}
}
if (poll->is_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<UserId> recent_voter_user_ids;
for (auto &user_id_int : poll_results->recent_voters_) {

View File

@ -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<int32>(options.size())) {
if (correct_option_id < -1 || correct_option_id >= static_cast<int32>(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<int32>(options.size())) {
if (correct_option_id < -1 || correct_option_id >= static_cast<int32>(options.size())) {
parser.set_error("Wrong correct_option_id");
}
}

View File

@ -3194,7 +3194,7 @@ class CliClient final : public Actor {
send_message(chat_id, td_api::make_object<td_api::inputMessageLocation>(as_location(latitude, longitude),
to_integer<int32>(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<td_api::pollTypeRegular>(op == "spollm");
}
send_message(chat_id, td_api::make_object<td_api::inputMessagePoll>(question, std::move(options), true,
send_message(chat_id, td_api::make_object<td_api::inputMessagePoll>(question, std::move(options), op != "spollp",
std::move(poll_type)));
} else if (op == "sp" || op == "spcaption" || op == "spttl") {
string chat_id;