Rename poll answers to options.

GitOrigin-RevId: bcb2b9f6b29b58a3460df18773148eb426935664
This commit is contained in:
levlam 2019-02-21 03:52:58 +03:00
parent d6dd0a0bb9
commit d22dfb2a0c
8 changed files with 79 additions and 71 deletions

View File

@ -192,8 +192,8 @@ maskPointChin = MaskPoint;
maskPosition point:MaskPoint x_shift:double y_shift:double scale:double = MaskPosition; maskPosition point:MaskPoint x_shift:double y_shift:double scale:double = MaskPosition;
//@description Describes one answer of a poll @text Answer text, 1-100 characters @voter_count Number of voters for this answer @is_chosen True, if the answer was chosen by the user //@description Describes one answer option of a poll @text Option text, 1-100 characters @voter_count Number of voters for this option @is_chosen True, if the option was chosen by the user
pollAnswer text:string voter_count:int32 is_chosen:Bool = PollAnswer; pollOption text:string voter_count:int32 is_chosen:Bool = PollOption;
//@description Describes an animation file. The animation must be encoded in GIF or MPEG4 format @duration Duration of the animation, in seconds; as defined by the sender @width Width of the animation @height Height of the animation //@description Describes an animation file. The animation must be encoded in GIF or MPEG4 format @duration Duration of the animation, in seconds; as defined by the sender @width Width of the animation @height Height of the animation
@ -241,8 +241,8 @@ venue location:location title:string address:string provider:string id:string ty
//@param_description Game description @photo Game photo @animation Game animation; may be null //@param_description Game description @photo Game photo @animation Game animation; may be null
game id:int64 short_name:string title:string text:formattedText description:string photo:photo animation:animation = Game; game id:int64 short_name:string title:string text:formattedText description:string photo:photo animation:animation = Game;
//@description Describes a poll @question Poll question, 1-255 characters @answers List of poll answers @total_voter_count Total number of voters, participating in the poll @is_closed True, if the poll is closed //@description Describes a poll @question Poll question, 1-255 characters @options List of poll answer options @total_voter_count Total number of voters, participating in the poll @is_closed True, if the poll is closed
poll question:string answers:vector<pollAnswer> total_voter_count:int32 is_closed:Bool = Poll; poll question:string options:vector<pollOption> total_voter_count:int32 is_closed:Bool = Poll;
//@description Describes a user profile photo @id Photo identifier; 0 for an empty photo. Can be used to find a photo in a list of userProfilePhotos //@description Describes a user profile photo @id Photo identifier; 0 for an empty photo. Can be used to find a photo in a list of userProfilePhotos
@ -1402,8 +1402,8 @@ inputMessageGame bot_user_id:int32 game_short_name:string = InputMessageContent;
//@payload The invoice payload @provider_token Payment provider token @provider_data JSON-encoded data about the invoice, which will be shared with the payment provider @start_parameter Unique invoice bot start_parameter for the generation of this invoice //@payload The invoice payload @provider_token Payment provider token @provider_data JSON-encoded data about the invoice, which will be shared with the payment provider @start_parameter Unique invoice bot start_parameter for the generation of this invoice
inputMessageInvoice invoice:invoice title:string description:string photo_url:string photo_size:int32 photo_width:int32 photo_height:int32 payload:bytes provider_token:string provider_data:string start_parameter:string = InputMessageContent; inputMessageInvoice invoice:invoice title:string description:string photo_url:string photo_size:int32 photo_width:int32 photo_height:int32 payload:bytes provider_token:string provider_data:string start_parameter:string = InputMessageContent;
//@description A message with a poll @question Poll question, 1-255 characters @answers List of poll answers, 1-10 strings 1-100 characters each //@description A message with a poll @question Poll question, 1-255 characters @options List of poll answer options, 1-10 strings 1-100 characters each
inputMessagePoll question:string answers:vector<string> = InputMessageContent; inputMessagePoll question:string options:vector<string> = InputMessageContent;
//@description A forwarded message @from_chat_id Identifier for the chat this forwarded message came from @message_id Identifier of the message to forward @in_game_share True, if a game message should be shared within a launched game; applies only to game messages //@description A forwarded message @from_chat_id Identifier for the chat this forwarded message came from @message_id Identifier of the message to forward @in_game_share True, if a game message should be shared within a launched game; applies only to game messages
inputMessageForwarded from_chat_id:int53 message_id:int53 in_game_share:Bool = InputMessageContent; inputMessageForwarded from_chat_id:int53 message_id:int53 in_game_share:Bool = InputMessageContent;
@ -2930,7 +2930,7 @@ answerShippingQuery shipping_query_id:int64 shipping_options:vector<shippingOpti
answerPreCheckoutQuery pre_checkout_query_id:int64 error_message:string = Ok; answerPreCheckoutQuery pre_checkout_query_id:int64 error_message:string = Ok;
//@description Updates the game score of the specified user in the game; for bots only @chat_id The chat to which the message with the game @message_id Identifier of the message @edit_message True, if the message should be edited @user_id User identifier @score The new score //@description Updates the game score of the specified user in the game; for bots only @chat_id The chat to which the message with the game belongs @message_id Identifier of the message @edit_message True, if the message should be edited @user_id User identifier @score The new score
//@force Pass true to update the score even if it decreases. If the score is 0, the user will be deleted from the high score table //@force Pass true to update the score even if it decreases. If the score is 0, the user will be deleted from the high score table
setGameScore chat_id:int53 message_id:int53 edit_message:Bool user_id:int32 score:int32 force:Bool = Message; setGameScore chat_id:int53 message_id:int53 edit_message:Bool user_id:int32 score:int32 force:Bool = Message;

Binary file not shown.

View File

@ -1747,8 +1747,8 @@ static Result<InputMessageContent> create_input_message_content(
} }
case td_api::inputMessagePoll::ID: { case td_api::inputMessagePoll::ID: {
constexpr size_t MAX_POLL_QUESTION_LENGTH = 255; // server-side limit constexpr size_t MAX_POLL_QUESTION_LENGTH = 255; // server-side limit
constexpr size_t MAX_POLL_ANSWER_LENGTH = 100; // server-side limit constexpr size_t MAX_POLL_OPTION_LENGTH = 100; // server-side limit
constexpr size_t MAX_POLL_ANSWERS = 10; // server-side limit constexpr size_t MAX_POLL_OPTIONS = 10; // server-side limit
auto input_poll = static_cast<td_api::inputMessagePoll *>(input_message_content.get()); auto input_poll = static_cast<td_api::inputMessagePoll *>(input_message_content.get());
if (!clean_input_string(input_poll->question_)) { if (!clean_input_string(input_poll->question_)) {
return Status::Error(400, "Poll question must be encoded in UTF-8"); return Status::Error(400, "Poll question must be encoded in UTF-8");
@ -1759,26 +1759,26 @@ static Result<InputMessageContent> create_input_message_content(
if (input_poll->question_.size() > MAX_POLL_QUESTION_LENGTH) { if (input_poll->question_.size() > MAX_POLL_QUESTION_LENGTH) {
return Status::Error(400, PSLICE() << "Poll question length must not exceed " << MAX_POLL_QUESTION_LENGTH); return Status::Error(400, PSLICE() << "Poll question length must not exceed " << MAX_POLL_QUESTION_LENGTH);
} }
if (input_poll->answers_.empty()) { if (input_poll->options_.empty()) {
return Status::Error(400, "Poll must have at least 1 answer"); return Status::Error(400, "Poll must have at least 1 option");
} }
if (input_poll->answers_.size() > MAX_POLL_ANSWERS) { if (input_poll->options_.size() > MAX_POLL_OPTIONS) {
return Status::Error(400, PSLICE() << "Poll can't have more than " << MAX_POLL_QUESTION_LENGTH << " answers"); return Status::Error(400, PSLICE() << "Poll can't have more than " << MAX_POLL_OPTIONS << " option");
} }
for (auto &answer : input_poll->answers_) { for (auto &option : input_poll->options_) {
if (!clean_input_string(answer)) { if (!clean_input_string(option)) {
return Status::Error(400, "Poll answers must be encoded in UTF-8"); return Status::Error(400, "Poll options must be encoded in UTF-8");
} }
if (answer.empty()) { if (option.empty()) {
return Status::Error(400, "Poll answers must be non-empty"); return Status::Error(400, "Poll options must be non-empty");
} }
if (answer.size() > MAX_POLL_ANSWER_LENGTH) { if (option.size() > MAX_POLL_OPTION_LENGTH) {
return Status::Error(400, PSLICE() << "Poll answers length must not exceed " << MAX_POLL_ANSWER_LENGTH); return Status::Error(400, PSLICE() << "Poll options length must not exceed " << MAX_POLL_OPTION_LENGTH);
} }
} }
content = make_unique<MessagePoll>( content = make_unique<MessagePoll>(
td->poll_manager_->create_poll(std::move(input_poll->question_), std::move(input_poll->answers_))); td->poll_manager_->create_poll(std::move(input_poll->question_), std::move(input_poll->options_)));
break; break;
} }
default: default:

View File

@ -123,30 +123,30 @@ PollManager::Poll *PollManager::get_poll_force(PollId poll_id) {
return get_poll_editable(poll_id); return get_poll_editable(poll_id);
} }
td_api::object_ptr<td_api::pollAnswer> PollManager::get_poll_answer_object(const PollAnswer &poll_answer) { td_api::object_ptr<td_api::pollOption> PollManager::get_poll_option_object(const PollOption &poll_option) {
return td_api::make_object<td_api::pollAnswer>(poll_answer.text, poll_answer.voter_count, poll_answer.is_chosen); return td_api::make_object<td_api::pollOption>(poll_option.text, poll_option.voter_count, poll_option.is_chosen);
} }
td_api::object_ptr<td_api::poll> PollManager::get_poll_object(PollId poll_id) const { td_api::object_ptr<td_api::poll> PollManager::get_poll_object(PollId poll_id) const {
auto poll = get_poll(poll_id); auto poll = get_poll(poll_id);
CHECK(poll != nullptr); CHECK(poll != nullptr);
return td_api::make_object<td_api::poll>(poll->question, transform(poll->answers, get_poll_answer_object), return td_api::make_object<td_api::poll>(poll->question, transform(poll->options, get_poll_option_object),
poll->total_voter_count, poll->is_closed); poll->total_voter_count, poll->is_closed);
} }
telegram_api::object_ptr<telegram_api::pollAnswer> PollManager::get_input_poll_answer(const PollAnswer &poll_answer) { telegram_api::object_ptr<telegram_api::pollAnswer> PollManager::get_input_poll_option(const PollOption &poll_option) {
return telegram_api::make_object<telegram_api::pollAnswer>(poll_answer.text, BufferSlice(poll_answer.data)); return telegram_api::make_object<telegram_api::pollAnswer>(poll_option.text, BufferSlice(poll_option.data));
} }
PollId PollManager::create_poll(string &&question, vector<string> &&answers) { PollId PollManager::create_poll(string &&question, vector<string> &&options) {
auto poll = make_unique<Poll>(); auto poll = make_unique<Poll>();
poll->question = std::move(question); poll->question = std::move(question);
int pos = 0; int pos = 0;
for (auto &answer_text : answers) { for (auto &option_text : options) {
PollAnswer answer; PollOption option;
answer.text = std::move(answer_text); option.text = std::move(option_text);
answer.data = to_string(pos++); option.data = to_string(pos++);
poll->answers.push_back(std::move(answer)); poll->options.push_back(std::move(option));
} }
PollId poll_id(--current_local_poll_id_); PollId poll_id(--current_local_poll_id_);
@ -185,16 +185,16 @@ tl_object_ptr<telegram_api::InputMedia> PollManager::get_input_media(PollId poll
auto poll = get_poll(poll_id); auto poll = get_poll(poll_id);
CHECK(poll != nullptr); CHECK(poll != nullptr);
return telegram_api::make_object<telegram_api::inputMediaPoll>(telegram_api::make_object<telegram_api::poll>( return telegram_api::make_object<telegram_api::inputMediaPoll>(telegram_api::make_object<telegram_api::poll>(
0, 0, false /* ignored */, poll->question, transform(poll->answers, get_input_poll_answer))); 0, 0, false /* ignored */, poll->question, transform(poll->options, get_input_poll_option)));
} }
vector<PollManager::PollAnswer> PollManager::get_poll_answers( vector<PollManager::PollOption> PollManager::get_poll_options(
vector<tl_object_ptr<telegram_api::pollAnswer>> &&poll_answers) { vector<tl_object_ptr<telegram_api::pollAnswer>> &&poll_options) {
return transform(std::move(poll_answers), [](tl_object_ptr<telegram_api::pollAnswer> &&poll_answer) { return transform(std::move(poll_options), [](tl_object_ptr<telegram_api::pollAnswer> &&poll_option) {
PollAnswer answer; PollOption option;
answer.text = std::move(poll_answer->text_); option.text = std::move(poll_option->text_);
answer.data = poll_answer->option_.as_slice().str(); option.data = poll_option->option_.as_slice().str();
return answer; return option;
}); });
} }
@ -232,19 +232,19 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
poll->question = std::move(poll_server->question_); poll->question = std::move(poll_server->question_);
is_changed = true; is_changed = true;
} }
if (poll->answers.size() != poll_server->answers_.size()) { if (poll->options.size() != poll_server->answers_.size()) {
poll->answers = get_poll_answers(std::move(poll_server->answers_)); poll->options = get_poll_options(std::move(poll_server->answers_));
is_changed = true; is_changed = true;
} else { } else {
for (size_t i = 0; i < poll->answers.size(); i++) { for (size_t i = 0; i < poll->options.size(); i++) {
if (poll->answers[i].text != poll_server->answers_[i]->text_) { if (poll->options[i].text != poll_server->answers_[i]->text_) {
poll->answers[i].text = std::move(poll_server->answers_[i]->text_); poll->options[i].text = std::move(poll_server->answers_[i]->text_);
is_changed = true; is_changed = true;
} }
if (poll->answers[i].data != poll_server->answers_[i]->option_.as_slice()) { if (poll->options[i].data != poll_server->answers_[i]->option_.as_slice()) {
poll->answers[i].data = poll_server->answers_[i]->option_.as_slice().str(); poll->options[i].data = poll_server->answers_[i]->option_.as_slice().str();
poll->answers[i].voter_count = 0; poll->options[i].voter_count = 0;
poll->answers[i].is_chosen = false; poll->options[i].is_chosen = false;
is_changed = true; is_changed = true;
} }
} }
@ -265,19 +265,19 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
} }
for (auto &poll_result : poll_results->results_) { for (auto &poll_result : poll_results->results_) {
Slice data = poll_result->option_.as_slice(); Slice data = poll_result->option_.as_slice();
for (auto &answer : poll->answers) { for (auto &option : poll->options) {
if (answer.data != data) { if (option.data != data) {
continue; continue;
} }
if (!is_min) { if (!is_min) {
bool is_chosen = (poll_result->flags_ & telegram_api::pollAnswerVoters::CHOSEN_MASK) != 0; bool is_chosen = (poll_result->flags_ & telegram_api::pollAnswerVoters::CHOSEN_MASK) != 0;
if (is_chosen != answer.is_chosen) { if (is_chosen != option.is_chosen) {
answer.is_chosen = is_chosen; option.is_chosen = is_chosen;
is_changed = true; is_changed = true;
} }
} }
if (poll_result->voters_ != answer.voter_count) { if (poll_result->voters_ != option.voter_count) {
answer.voter_count = poll_result->voters_; option.voter_count = poll_result->voters_;
is_changed = true; is_changed = true;
} }
} }

View File

@ -33,7 +33,7 @@ class PollManager : public Actor {
PollManager &operator=(PollManager &&) = delete; PollManager &operator=(PollManager &&) = delete;
~PollManager() override; ~PollManager() override;
PollId create_poll(string &&question, vector<string> &&answers); PollId create_poll(string &&question, vector<string> &&options);
void register_poll(PollId poll_id, FullMessageId full_message_id); void register_poll(PollId poll_id, FullMessageId full_message_id);
@ -55,7 +55,7 @@ class PollManager : public Actor {
PollId parse_poll(ParserT &parser); PollId parse_poll(ParserT &parser);
private: private:
struct PollAnswer { struct PollOption {
string text; string text;
string data; string data;
int32 voter_count = 0; int32 voter_count = 0;
@ -69,7 +69,7 @@ class PollManager : public Actor {
struct Poll { struct Poll {
string question; string question;
vector<PollAnswer> answers; vector<PollOption> options;
int32 total_voter_count = 0; int32 total_voter_count = 0;
bool is_closed = false; bool is_closed = false;
@ -83,11 +83,11 @@ class PollManager : public Actor {
static bool is_local_poll_id(PollId poll_id); static bool is_local_poll_id(PollId poll_id);
static td_api::object_ptr<td_api::pollAnswer> get_poll_answer_object(const PollAnswer &poll_answer); static td_api::object_ptr<td_api::pollOption> get_poll_option_object(const PollOption &poll_option);
static telegram_api::object_ptr<telegram_api::pollAnswer> get_input_poll_answer(const PollAnswer &poll_answer); static telegram_api::object_ptr<telegram_api::pollAnswer> get_input_poll_option(const PollOption &poll_option);
static vector<PollAnswer> get_poll_answers(vector<tl_object_ptr<telegram_api::pollAnswer>> &&poll_answers); static vector<PollOption> get_poll_options(vector<tl_object_ptr<telegram_api::pollAnswer>> &&poll_options);
bool have_poll(PollId poll_id) const; bool have_poll(PollId poll_id) const;

View File

@ -15,7 +15,7 @@
namespace td { namespace td {
template <class StorerT> template <class StorerT>
void PollManager::PollAnswer::store(StorerT &storer) const { void PollManager::PollOption::store(StorerT &storer) const {
using ::td::store; using ::td::store;
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(is_chosen); STORE_FLAG(is_chosen);
@ -27,7 +27,7 @@ void PollManager::PollAnswer::store(StorerT &storer) const {
} }
template <class ParserT> template <class ParserT>
void PollManager::PollAnswer::parse(ParserT &parser) { void PollManager::PollOption::parse(ParserT &parser) {
using ::td::parse; using ::td::parse;
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_chosen); PARSE_FLAG(is_chosen);
@ -46,7 +46,7 @@ void PollManager::Poll::store(StorerT &storer) const {
END_STORE_FLAGS(); END_STORE_FLAGS();
store(question, storer); store(question, storer);
store(answers, storer); store(options, storer);
store(total_voter_count, storer); store(total_voter_count, storer);
} }
@ -58,7 +58,7 @@ void PollManager::Poll::parse(ParserT &parser) {
END_PARSE_FLAGS(); END_PARSE_FLAGS();
parse(question, parser); parse(question, parser);
parse(answers, parser); parse(options, parser);
parse(total_voter_count, parser); parse(total_voter_count, parser);
} }
@ -69,8 +69,8 @@ void PollManager::store_poll(PollId poll_id, StorerT &storer) const {
auto poll = get_poll(poll_id); auto poll = get_poll(poll_id);
CHECK(poll != nullptr); CHECK(poll != nullptr);
store(poll->question, storer); store(poll->question, storer);
vector<string> answers = transform(poll->answers, [](const PollAnswer &answer) { return answer.text; }); vector<string> options = transform(poll->options, [](const PollOption &option) { return option.text; });
store(answers, storer); store(options, storer);
} }
} }
@ -81,10 +81,10 @@ PollId PollManager::parse_poll(ParserT &parser) {
PollId poll_id(poll_id_int); PollId poll_id(poll_id_int);
if (is_local_poll_id(poll_id)) { if (is_local_poll_id(poll_id)) {
string question; string question;
vector<string> answers; vector<string> options;
parse(question, parser); parse(question, parser);
parse(answers, parser); parse(options, parser);
return create_poll(std::move(question), std::move(answers)); return create_poll(std::move(question), std::move(options));
} }
auto poll = get_poll_force(poll_id); auto poll = get_poll_force(poll_id);

View File

@ -6540,7 +6540,13 @@ void Td::on_request(uint64 id, td_api::setOption &request) {
return send_error_raw(id, 3, "Option can't be set"); return send_error_raw(id, 3, "Option can't be set");
} }
/*
void Td::on_request(uint64 id, td_api::setPollAnswers &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
messages_manager_->set_poll_answers({DialogId(request.chat_id_), MessageId(request.message_id_)}, std::move(request.option_ids_));
}
*/
void Td::on_request(uint64 id, td_api::getInlineQueryResults &request) { void Td::on_request(uint64 id, td_api::getInlineQueryResults &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CLEAN_INPUT_STRING(request.query_); CLEAN_INPUT_STRING(request.query_);

View File

@ -830,6 +830,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::setOption &request); void on_request(uint64 id, td_api::setOption &request);
// void on_request(uint64 id, td_api::setPollAnswers &request);
void on_request(uint64 id, td_api::getInlineQueryResults &request); void on_request(uint64 id, td_api::getInlineQueryResults &request);
void on_request(uint64 id, td_api::answerInlineQuery &request); void on_request(uint64 id, td_api::answerInlineQuery &request);