New polls support fixes.
GitOrigin-RevId: f5421227029a8ae1f9284882e6f6221617002925
This commit is contained in:
parent
6d15cc7bf0
commit
da4694bc81
@ -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
|
//@description A regular poll @allow_multiple_answers True, if multiple answer options can be chosen simultaneously
|
||||||
pollTypeRegular allow_multiple_answers:Bool = PollType;
|
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;
|
pollTypeQuiz correct_option_id:int32 = PollType;
|
||||||
|
|
||||||
|
|
||||||
|
@ -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;
|
td_api::object_ptr<td_api::PollType> poll_type;
|
||||||
if (poll->is_quiz) {
|
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 {
|
} else {
|
||||||
poll_type = td_api::make_object<td_api::pollTypeRegular>(poll->allow_multiple_answers);
|
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>(
|
return telegram_api::make_object<telegram_api::inputMediaPoll>(
|
||||||
flags,
|
flags,
|
||||||
telegram_api::make_object<telegram_api::poll>(0, flags, false /*ignored*/, false /*ignored*/, false /*ignored*/,
|
telegram_api::make_object<telegram_api::poll>(0, poll_flags, false /*ignored*/, false /*ignored*/,
|
||||||
false /*ignored*/, poll->question,
|
false /*ignored*/, false /*ignored*/, poll->question,
|
||||||
transform(poll->options, get_input_poll_option)),
|
transform(poll->options, get_input_poll_option)),
|
||||||
std::move(correct_answers));
|
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++) {
|
for (size_t i = 0; i < poll_results->results_.size(); i++) {
|
||||||
auto &poll_result = poll_results->results_[i];
|
auto &poll_result = poll_results->results_[i];
|
||||||
Slice data = poll_result->option_.as_slice();
|
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];
|
auto &option = poll->options[option_index];
|
||||||
if (option.data != data) {
|
if (option.data != data) {
|
||||||
continue;
|
continue;
|
||||||
@ -1280,16 +1281,12 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (poll->is_quiz) {
|
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) {
|
if (poll->correct_option_id != correct_option_id) {
|
||||||
poll->correct_option_id = correct_option_id;
|
poll->correct_option_id = correct_option_id;
|
||||||
is_changed = true;
|
is_changed = true;
|
||||||
}
|
}
|
||||||
} else if (correct_option_id != -1) {
|
} 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;
|
vector<UserId> recent_voter_user_ids;
|
||||||
for (auto &user_id_int : poll_results->recent_voters_) {
|
for (auto &user_id_int : poll_results->recent_voters_) {
|
||||||
|
@ -82,7 +82,7 @@ void PollManager::Poll::parse(ParserT &parser) {
|
|||||||
parse(total_voter_count, parser);
|
parse(total_voter_count, parser);
|
||||||
if (is_quiz) {
|
if (is_quiz) {
|
||||||
parse(correct_option_id, parser);
|
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");
|
parser.set_error("Wrong correct_option_id");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ PollId PollManager::parse_poll(ParserT &parser) {
|
|||||||
parse(options, parser);
|
parse(options, parser);
|
||||||
if (is_quiz) {
|
if (is_quiz) {
|
||||||
parse(correct_option_id, parser);
|
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");
|
parser.set_error("Wrong correct_option_id");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3194,7 +3194,7 @@ class CliClient final : public Actor {
|
|||||||
|
|
||||||
send_message(chat_id, td_api::make_object<td_api::inputMessageLocation>(as_location(latitude, longitude),
|
send_message(chat_id, td_api::make_object<td_api::inputMessageLocation>(as_location(latitude, longitude),
|
||||||
to_integer<int32>(period)));
|
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 chat_id;
|
||||||
string question;
|
string question;
|
||||||
std::tie(chat_id, args) = split(args);
|
std::tie(chat_id, args) = split(args);
|
||||||
@ -3207,7 +3207,7 @@ class CliClient final : public Actor {
|
|||||||
} else {
|
} else {
|
||||||
poll_type = td_api::make_object<td_api::pollTypeRegular>(op == "spollm");
|
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)));
|
std::move(poll_type)));
|
||||||
} else if (op == "sp" || op == "spcaption" || op == "spttl") {
|
} else if (op == "sp" || op == "spcaption" || op == "spttl") {
|
||||||
string chat_id;
|
string chat_id;
|
||||||
|
Reference in New Issue
Block a user