Support custom emoji in poll question and options.
This commit is contained in:
parent
db3f673deb
commit
7be2966e27
@ -350,12 +350,12 @@ closedVectorPath commands:vector<VectorPathCommand> = ClosedVectorPath;
|
|||||||
|
|
||||||
|
|
||||||
//@description Describes one answer option of a poll
|
//@description Describes one answer option of a poll
|
||||||
//@text Option text; 1-100 characters
|
//@text Option text; 1-100 characters. Only custom emoji entities are allowed
|
||||||
//@voter_count Number of voters for this option, available only for closed or voted polls
|
//@voter_count Number of voters for this option, available only for closed or voted polls
|
||||||
//@vote_percentage The percentage of votes for this option; 0-100
|
//@vote_percentage The percentage of votes for this option; 0-100
|
||||||
//@is_chosen True, if the option was chosen by the user
|
//@is_chosen True, if the option was chosen by the user
|
||||||
//@is_being_chosen True, if the option is being chosen by a pending setPollAnswer request
|
//@is_being_chosen True, if the option is being chosen by a pending setPollAnswer request
|
||||||
pollOption text:string voter_count:int32 vote_percentage:int32 is_chosen:Bool is_being_chosen:Bool = PollOption;
|
pollOption text:formattedText voter_count:int32 vote_percentage:int32 is_chosen:Bool is_being_chosen:Bool = PollOption;
|
||||||
|
|
||||||
|
|
||||||
//@class PollType @description Describes the type of poll
|
//@class PollType @description Describes the type of poll
|
||||||
@ -502,7 +502,7 @@ webApp short_name:string title:string description:string photo:photo animation:a
|
|||||||
|
|
||||||
//@description Describes a poll
|
//@description Describes a poll
|
||||||
//@id Unique poll identifier
|
//@id Unique poll identifier
|
||||||
//@question Poll question; 1-300 characters
|
//@question Poll question; 1-300 characters. Only custom emoji entities are allowed
|
||||||
//@options List of poll answer options
|
//@options List of poll answer options
|
||||||
//@total_voter_count Total number of voters, participating in the poll
|
//@total_voter_count Total number of voters, participating in the poll
|
||||||
//@recent_voter_ids Identifiers of recent voters, if the poll is non-anonymous
|
//@recent_voter_ids Identifiers of recent voters, if the poll is non-anonymous
|
||||||
@ -511,7 +511,7 @@ webApp short_name:string title:string description:string photo:photo animation:a
|
|||||||
//@open_period Amount of time the poll will be active after creation, in seconds
|
//@open_period Amount of time the poll will be active after creation, in seconds
|
||||||
//@close_date Point in time (Unix timestamp) when the poll will automatically be closed
|
//@close_date Point in time (Unix timestamp) when the poll will automatically be closed
|
||||||
//@is_closed True, if the poll is closed
|
//@is_closed True, if the poll is closed
|
||||||
poll id:int64 question:string options:vector<pollOption> total_voter_count:int32 recent_voter_ids:vector<MessageSender> is_anonymous:Bool type:PollType open_period:int32 close_date:int32 is_closed:Bool = Poll;
|
poll id:int64 question:formattedText options:vector<pollOption> total_voter_count:int32 recent_voter_ids:vector<MessageSender> is_anonymous:Bool type:PollType open_period:int32 close_date:int32 is_closed:Bool = Poll;
|
||||||
|
|
||||||
|
|
||||||
//@description Describes a chat background
|
//@description Describes a chat background
|
||||||
@ -3473,14 +3473,14 @@ inputMessageGame bot_user_id:int53 game_short_name: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 extended_media_content:InputMessageContent = 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 extended_media_content:InputMessageContent = InputMessageContent;
|
||||||
|
|
||||||
//@description A message with a poll. Polls can't be sent to secret chats. Polls can be sent only to a private chat with a bot
|
//@description A message with a poll. Polls can't be sent to secret chats. Polls can be sent only to a private chat with a bot
|
||||||
//@question Poll question; 1-255 characters (up to 300 characters for bots)
|
//@question Poll question; 1-255 characters (up to 300 characters for bots). Only custom emoji entities are allowed to be added and only by Premium users
|
||||||
//@options List of poll answer options, 2-10 strings 1-100 characters each
|
//@options List of poll answer options, 2-10 strings 1-100 characters each. Only custom emoji entities are allowed to be added and only by Premium users
|
||||||
//@is_anonymous True, if the poll voters are anonymous. Non-anonymous polls can't be sent or forwarded to channels
|
//@is_anonymous True, if the poll voters are anonymous. Non-anonymous polls can't be sent or forwarded to channels
|
||||||
//@type Type of the poll
|
//@type Type of the poll
|
||||||
//@open_period Amount of time the poll will be active after creation, in seconds; for bots only
|
//@open_period Amount of time the poll will be active after creation, in seconds; for bots only
|
||||||
//@close_date Point in time (Unix timestamp) when the poll will automatically be closed; for bots only
|
//@close_date Point in time (Unix timestamp) when the poll will automatically be closed; for bots only
|
||||||
//@is_closed True, if the poll needs to be sent already closed; for bots only
|
//@is_closed True, if the poll needs to be sent already closed; for bots only
|
||||||
inputMessagePoll question:string options:vector<string> is_anonymous:Bool type:PollType open_period:int32 close_date:int32 is_closed:Bool = InputMessageContent;
|
inputMessagePoll question:formattedText options:vector<formattedText> is_anonymous:Bool type:PollType open_period:int32 close_date:int32 is_closed:Bool = InputMessageContent;
|
||||||
|
|
||||||
//@description A message with a forwarded story. Stories can't be sent to secret chats. A story can be forwarded only if story.can_be_forwarded
|
//@description A message with a forwarded story. Stories can't be sent to secret chats. A story can be forwarded only if story.can_be_forwarded
|
||||||
//@story_sender_chat_id Identifier of the chat that posted the story
|
//@story_sender_chat_id Identifier of the chat that posted the story
|
||||||
|
@ -2801,13 +2801,9 @@ static Result<InputMessageContent> create_input_message_content(
|
|||||||
constexpr size_t MAX_POLL_OPTION_LENGTH = 100; // server-side limit
|
constexpr size_t MAX_POLL_OPTION_LENGTH = 100; // server-side limit
|
||||||
constexpr size_t MAX_POLL_OPTIONS = 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_)) {
|
TRY_RESULT(question,
|
||||||
return Status::Error(400, "Poll question must be encoded in UTF-8");
|
get_formatted_text(td, dialog_id, std::move(input_poll->question_), is_bot, false, true, false));
|
||||||
}
|
if (utf8_length(question.text) > MAX_POLL_QUESTION_LENGTH) {
|
||||||
if (input_poll->question_.empty()) {
|
|
||||||
return Status::Error(400, "Poll question must be non-empty");
|
|
||||||
}
|
|
||||||
if (utf8_length(input_poll->question_) > 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->options_.size() <= 1) {
|
if (input_poll->options_.size() <= 1) {
|
||||||
@ -2816,16 +2812,13 @@ static Result<InputMessageContent> create_input_message_content(
|
|||||||
if (input_poll->options_.size() > MAX_POLL_OPTIONS) {
|
if (input_poll->options_.size() > MAX_POLL_OPTIONS) {
|
||||||
return Status::Error(400, PSLICE() << "Poll can't have more than " << MAX_POLL_OPTIONS << " options");
|
return Status::Error(400, PSLICE() << "Poll can't have more than " << MAX_POLL_OPTIONS << " options");
|
||||||
}
|
}
|
||||||
for (auto &option : input_poll->options_) {
|
vector<FormattedText> options;
|
||||||
if (!clean_input_string(option)) {
|
for (auto &input_option : input_poll->options_) {
|
||||||
return Status::Error(400, "Poll options must be encoded in UTF-8");
|
TRY_RESULT(option, get_formatted_text(td, dialog_id, std::move(input_option), is_bot, false, true, false));
|
||||||
}
|
if (utf8_length(option.text) > MAX_POLL_OPTION_LENGTH) {
|
||||||
if (option.empty()) {
|
|
||||||
return Status::Error(400, "Poll options must be non-empty");
|
|
||||||
}
|
|
||||||
if (utf8_length(option) > MAX_POLL_OPTION_LENGTH) {
|
|
||||||
return Status::Error(400, PSLICE() << "Poll options length must not exceed " << MAX_POLL_OPTION_LENGTH);
|
return Status::Error(400, PSLICE() << "Poll options length must not exceed " << MAX_POLL_OPTION_LENGTH);
|
||||||
}
|
}
|
||||||
|
options.push_back(std::move(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool allow_multiple_answers = false;
|
bool allow_multiple_answers = false;
|
||||||
@ -2862,10 +2855,9 @@ static Result<InputMessageContent> create_input_message_content(
|
|||||||
close_date = 0;
|
close_date = 0;
|
||||||
}
|
}
|
||||||
bool is_closed = is_bot ? input_poll->is_closed_ : false;
|
bool is_closed = is_bot ? input_poll->is_closed_ : false;
|
||||||
content = make_unique<MessagePoll>(
|
content = make_unique<MessagePoll>(td->poll_manager_->create_poll(
|
||||||
td->poll_manager_->create_poll(std::move(input_poll->question_), std::move(input_poll->options_),
|
std::move(question), std::move(options), input_poll->is_anonymous_, allow_multiple_answers, is_quiz,
|
||||||
input_poll->is_anonymous_, allow_multiple_answers, is_quiz, correct_option_id,
|
correct_option_id, std::move(explanation), open_period, close_date, is_closed));
|
||||||
std::move(explanation), open_period, close_date, is_closed));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case td_api::inputMessageStory::ID: {
|
case td_api::inputMessageStory::ID: {
|
||||||
|
@ -4351,7 +4351,7 @@ Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool al
|
|||||||
entities.clear();
|
entities.clear();
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
return Status::Error(400, "Message must be non-empty");
|
return Status::Error(400, "Text must be non-empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
// re-fix entities if needed after removal of some characters
|
// re-fix entities if needed after removal of some characters
|
||||||
@ -4407,7 +4407,7 @@ Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool al
|
|||||||
LOG_CHECK(check_utf8(text)) << text;
|
LOG_CHECK(check_utf8(text)) << text;
|
||||||
|
|
||||||
if (!allow_empty && is_empty_string(text)) {
|
if (!allow_empty && is_empty_string(text)) {
|
||||||
return Status::Error(400, "Message must be non-empty");
|
return Status::Error(400, "Text must be non-empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr size_t LENGTH_LIMIT = 35000; // server side limit
|
constexpr size_t LENGTH_LIMIT = 35000; // server side limit
|
||||||
@ -4640,6 +4640,7 @@ vector<tl_object_ptr<telegram_api::MessageEntity>> get_input_message_entities(co
|
|||||||
make_tl_object<telegram_api::messageEntityTextUrl>(entity.offset, entity.length, entity.argument));
|
make_tl_object<telegram_api::messageEntityTextUrl>(entity.offset, entity.length, entity.argument));
|
||||||
break;
|
break;
|
||||||
case MessageEntity::Type::MentionName: {
|
case MessageEntity::Type::MentionName: {
|
||||||
|
CHECK(user_manager != nullptr);
|
||||||
auto input_user = user_manager->get_input_user_force(entity.user_id);
|
auto input_user = user_manager->get_input_user_force(entity.user_id);
|
||||||
result.push_back(make_tl_object<telegram_api::inputMessageEntityMentionName>(entity.offset, entity.length,
|
result.push_back(make_tl_object<telegram_api::inputMessageEntityMentionName>(entity.offset, entity.length,
|
||||||
std::move(input_user)));
|
std::move(input_user)));
|
||||||
|
@ -428,9 +428,13 @@ PollManager::Poll *PollManager::get_poll_force(PollId poll_id) {
|
|||||||
return get_poll_editable(poll_id);
|
return get_poll_editable(poll_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PollManager::remove_unallowed_entities(FormattedText &text) {
|
||||||
|
td::remove_if(text.entities, [](MessageEntity &entity) { return entity.type != MessageEntity::Type::CustomEmoji; });
|
||||||
|
}
|
||||||
|
|
||||||
td_api::object_ptr<td_api::pollOption> PollManager::get_poll_option_object(const PollOption &poll_option) {
|
td_api::object_ptr<td_api::pollOption> PollManager::get_poll_option_object(const PollOption &poll_option) {
|
||||||
return td_api::make_object<td_api::pollOption>(poll_option.text_, poll_option.voter_count_, 0, poll_option.is_chosen_,
|
return td_api::make_object<td_api::pollOption>(get_formatted_text_object(poll_option.text_, true, -1),
|
||||||
false);
|
poll_option.voter_count_, 0, poll_option.is_chosen_, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int32> PollManager::get_vote_percentage(const vector<int32> &voter_counts, int32 total_voter_count) {
|
vector<int32> PollManager::get_vote_percentage(const vector<int32> &voter_counts, int32 total_voter_count) {
|
||||||
@ -558,8 +562,8 @@ td_api::object_ptr<td_api::poll> PollManager::get_poll_object(PollId poll_id, co
|
|||||||
voter_count_diff = -1;
|
voter_count_diff = -1;
|
||||||
}
|
}
|
||||||
poll_options.push_back(td_api::make_object<td_api::pollOption>(
|
poll_options.push_back(td_api::make_object<td_api::pollOption>(
|
||||||
poll_option.text_, poll_option.voter_count_ - static_cast<int32>(poll_option.is_chosen_), 0, false,
|
get_formatted_text_object(poll_option.text_, true, -1),
|
||||||
is_being_chosen));
|
poll_option.voter_count_ - static_cast<int32>(poll_option.is_chosen_), 0, false, is_being_chosen));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -632,20 +636,24 @@ td_api::object_ptr<td_api::poll> PollManager::get_poll_object(PollId poll_id, co
|
|||||||
recent_voters.push_back(std::move(recent_voter));
|
recent_voters.push_back(std::move(recent_voter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return td_api::make_object<td_api::poll>(poll_id.get(), poll->question_, std::move(poll_options), total_voter_count,
|
return td_api::make_object<td_api::poll>(
|
||||||
std::move(recent_voters), poll->is_anonymous_, std::move(poll_type),
|
poll_id.get(), get_formatted_text_object(poll->question_, true, -1), std::move(poll_options), total_voter_count,
|
||||||
open_period, close_date, poll->is_closed_);
|
std::move(recent_voters), poll->is_anonymous_, std::move(poll_type), open_period, close_date, poll->is_closed_);
|
||||||
}
|
}
|
||||||
|
|
||||||
telegram_api::object_ptr<telegram_api::pollAnswer> PollManager::get_input_poll_option(const PollOption &poll_option) {
|
telegram_api::object_ptr<telegram_api::pollAnswer> PollManager::get_input_poll_option(const PollOption &poll_option) {
|
||||||
return telegram_api::make_object<telegram_api::pollAnswer>(
|
return telegram_api::make_object<telegram_api::pollAnswer>(
|
||||||
telegram_api::make_object<telegram_api::textWithEntities>(poll_option.text_, Auto()),
|
get_input_text_with_entities(nullptr, poll_option.text_, "get_input_poll_option"),
|
||||||
BufferSlice(poll_option.data_));
|
BufferSlice(poll_option.data_));
|
||||||
}
|
}
|
||||||
|
|
||||||
PollId PollManager::create_poll(string &&question, vector<string> &&options, bool is_anonymous,
|
PollId PollManager::create_poll(FormattedText &&question, vector<FormattedText> &&options, bool is_anonymous,
|
||||||
bool allow_multiple_answers, bool is_quiz, int32 correct_option_id,
|
bool allow_multiple_answers, bool is_quiz, int32 correct_option_id,
|
||||||
FormattedText &&explanation, int32 open_period, int32 close_date, bool is_closed) {
|
FormattedText &&explanation, int32 open_period, int32 close_date, bool is_closed) {
|
||||||
|
remove_unallowed_entities(question);
|
||||||
|
for (auto &option : options) {
|
||||||
|
remove_unallowed_entities(option);
|
||||||
|
}
|
||||||
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';
|
||||||
@ -794,10 +802,10 @@ string PollManager::get_poll_search_text(PollId poll_id) const {
|
|||||||
auto poll = get_poll(poll_id);
|
auto poll = get_poll(poll_id);
|
||||||
CHECK(poll != nullptr);
|
CHECK(poll != nullptr);
|
||||||
|
|
||||||
string result = poll->question_;
|
string result = poll->question_.text;
|
||||||
for (auto &option : poll->options_) {
|
for (auto &option : poll->options_) {
|
||||||
result += ' ';
|
result += ' ';
|
||||||
result += option.text_;
|
result += option.text_.text;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -1551,7 +1559,7 @@ tl_object_ptr<telegram_api::InputMedia> PollManager::get_input_media(PollId poll
|
|||||||
flags,
|
flags,
|
||||||
telegram_api::make_object<telegram_api::poll>(
|
telegram_api::make_object<telegram_api::poll>(
|
||||||
0, poll_flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
|
0, poll_flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
|
||||||
telegram_api::make_object<telegram_api::textWithEntities>(poll->question_, Auto()),
|
get_input_text_with_entities(nullptr, poll->question_, "get_input_media_poll"),
|
||||||
transform(poll->options_, get_input_poll_option), poll->open_period_, poll->close_date_),
|
transform(poll->options_, get_input_poll_option), poll->open_period_, poll->close_date_),
|
||||||
std::move(correct_answers), poll->explanation_.text,
|
std::move(correct_answers), poll->explanation_.text,
|
||||||
get_input_message_entities(td_->user_manager_.get(), poll->explanation_.entities, "get_input_media_poll"));
|
get_input_message_entities(td_->user_manager_.get(), poll->explanation_.entities, "get_input_media_poll"));
|
||||||
@ -1561,7 +1569,8 @@ vector<PollManager::PollOption> PollManager::get_poll_options(
|
|||||||
vector<telegram_api::object_ptr<telegram_api::pollAnswer>> &&poll_options) {
|
vector<telegram_api::object_ptr<telegram_api::pollAnswer>> &&poll_options) {
|
||||||
return transform(std::move(poll_options), [](telegram_api::object_ptr<telegram_api::pollAnswer> &&poll_option) {
|
return transform(std::move(poll_options), [](telegram_api::object_ptr<telegram_api::pollAnswer> &&poll_option) {
|
||||||
PollOption option;
|
PollOption option;
|
||||||
option.text_ = std::move(poll_option->text_->text_);
|
option.text_ = get_formatted_text(nullptr, std::move(poll_option->text_), false, true, true, "get_poll_options");
|
||||||
|
remove_unallowed_entities(option.text_);
|
||||||
option.data_ = poll_option->option_.as_slice().str();
|
option.data_ = poll_option->option_.as_slice().str();
|
||||||
return option;
|
return option;
|
||||||
});
|
});
|
||||||
@ -1638,13 +1647,14 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
|
|||||||
poll->options_ = get_poll_options(std::move(poll_server->answers_));
|
poll->options_ = get_poll_options(std::move(poll_server->answers_));
|
||||||
are_options_changed = true;
|
are_options_changed = true;
|
||||||
} else {
|
} else {
|
||||||
for (size_t i = 0; i < poll->options_.size(); i++) {
|
auto options = get_poll_options(std::move(poll_server->answers_));
|
||||||
if (poll->options_[i].text_ != poll_server->answers_[i]->text_->text_) {
|
for (size_t i = 0; i < options.size(); i++) {
|
||||||
poll->options_[i].text_ = std::move(poll_server->answers_[i]->text_->text_);
|
if (poll->options_[i].text_ != options[i].text_) {
|
||||||
|
poll->options_[i].text_ = std::move(options[i].text_);
|
||||||
is_changed = true;
|
is_changed = true;
|
||||||
}
|
}
|
||||||
if (poll->options_[i].data_ != poll_server->answers_[i]->option_.as_slice()) {
|
if (poll->options_[i].data_ != options[i].data_) {
|
||||||
poll->options_[i].data_ = poll_server->answers_[i]->option_.as_slice().str();
|
poll->options_[i].data_ = std::move(options[i].data_);
|
||||||
poll->options_[i].voter_count_ = 0;
|
poll->options_[i].voter_count_ = 0;
|
||||||
poll->options_[i].is_chosen_ = false;
|
poll->options_[i].is_chosen_ = false;
|
||||||
are_options_changed = true;
|
are_options_changed = true;
|
||||||
@ -1670,8 +1680,10 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
|
|||||||
}
|
}
|
||||||
is_changed = true;
|
is_changed = true;
|
||||||
}
|
}
|
||||||
if (poll->question_ != poll_server->question_->text_) {
|
auto question = get_formatted_text(nullptr, std::move(poll_server->question_), false, true, true, "on_get_poll");
|
||||||
poll->question_ = std::move(poll_server->question_->text_);
|
remove_unallowed_entities(question);
|
||||||
|
if (poll->question_ != question) {
|
||||||
|
poll->question_ = std::move(question);
|
||||||
is_changed = true;
|
is_changed = true;
|
||||||
}
|
}
|
||||||
poll_server_is_closed = (poll_server->flags_ & telegram_api::poll::CLOSED_MASK) != 0;
|
poll_server_is_closed = (poll_server->flags_ & telegram_api::poll::CLOSED_MASK) != 0;
|
||||||
|
@ -49,9 +49,9 @@ class PollManager final : public Actor {
|
|||||||
|
|
||||||
static bool is_local_poll_id(PollId poll_id);
|
static bool is_local_poll_id(PollId poll_id);
|
||||||
|
|
||||||
PollId create_poll(string &&question, vector<string> &&options, bool is_anonymous, bool allow_multiple_answers,
|
PollId create_poll(FormattedText &&question, vector<FormattedText> &&options, bool is_anonymous,
|
||||||
bool is_quiz, int32 correct_option_id, FormattedText &&explanation, int32 open_period,
|
bool allow_multiple_answers, bool is_quiz, int32 correct_option_id, FormattedText &&explanation,
|
||||||
int32 close_date, bool is_closed);
|
int32 open_period, int32 close_date, bool is_closed);
|
||||||
|
|
||||||
void register_poll(PollId poll_id, MessageFullId message_full_id, const char *source);
|
void register_poll(PollId poll_id, MessageFullId message_full_id, const char *source);
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ class PollManager final : public Actor {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
struct PollOption {
|
struct PollOption {
|
||||||
string text_;
|
FormattedText text_;
|
||||||
string data_;
|
string data_;
|
||||||
int32 voter_count_ = 0;
|
int32 voter_count_ = 0;
|
||||||
bool is_chosen_ = false;
|
bool is_chosen_ = false;
|
||||||
@ -115,7 +115,7 @@ class PollManager final : public Actor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Poll {
|
struct Poll {
|
||||||
string question_;
|
FormattedText question_;
|
||||||
vector<PollOption> options_;
|
vector<PollOption> options_;
|
||||||
vector<DialogId> recent_voter_dialog_ids_;
|
vector<DialogId> recent_voter_dialog_ids_;
|
||||||
vector<std::pair<ChannelId, MinChannel>> recent_voter_min_channels_;
|
vector<std::pair<ChannelId, MinChannel>> recent_voter_min_channels_;
|
||||||
@ -159,6 +159,8 @@ class PollManager final : public Actor {
|
|||||||
|
|
||||||
static void on_unload_poll_timeout_callback(void *poll_manager_ptr, int64 poll_id_int);
|
static void on_unload_poll_timeout_callback(void *poll_manager_ptr, int64 poll_id_int);
|
||||||
|
|
||||||
|
static void remove_unallowed_entities(FormattedText &text);
|
||||||
|
|
||||||
static td_api::object_ptr<td_api::pollOption> get_poll_option_object(const PollOption &poll_option);
|
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_option(const PollOption &poll_option);
|
static telegram_api::object_ptr<telegram_api::pollAnswer> get_input_poll_option(const PollOption &poll_option);
|
||||||
|
@ -20,25 +20,35 @@ namespace td {
|
|||||||
template <class StorerT>
|
template <class StorerT>
|
||||||
void PollManager::PollOption::store(StorerT &storer) const {
|
void PollManager::PollOption::store(StorerT &storer) const {
|
||||||
using ::td::store;
|
using ::td::store;
|
||||||
|
bool has_entities = !text_.entities.empty();
|
||||||
BEGIN_STORE_FLAGS();
|
BEGIN_STORE_FLAGS();
|
||||||
STORE_FLAG(is_chosen_);
|
STORE_FLAG(is_chosen_);
|
||||||
|
STORE_FLAG(has_entities);
|
||||||
END_STORE_FLAGS();
|
END_STORE_FLAGS();
|
||||||
|
|
||||||
store(text_, storer);
|
store(text_.text, storer);
|
||||||
store(data_, storer);
|
store(data_, storer);
|
||||||
store(voter_count_, storer);
|
store(voter_count_, storer);
|
||||||
|
if (has_entities) {
|
||||||
|
store(text_.entities, storer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ParserT>
|
template <class ParserT>
|
||||||
void PollManager::PollOption::parse(ParserT &parser) {
|
void PollManager::PollOption::parse(ParserT &parser) {
|
||||||
using ::td::parse;
|
using ::td::parse;
|
||||||
|
bool has_entities;
|
||||||
BEGIN_PARSE_FLAGS();
|
BEGIN_PARSE_FLAGS();
|
||||||
PARSE_FLAG(is_chosen_);
|
PARSE_FLAG(is_chosen_);
|
||||||
|
PARSE_FLAG(has_entities);
|
||||||
END_PARSE_FLAGS();
|
END_PARSE_FLAGS();
|
||||||
|
|
||||||
parse(text_, parser);
|
parse(text_.text, parser);
|
||||||
parse(data_, parser);
|
parse(data_, parser);
|
||||||
parse(voter_count_, parser);
|
parse(voter_count_, parser);
|
||||||
|
if (has_entities) {
|
||||||
|
parse(text_.entities, parser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class StorerT>
|
template <class StorerT>
|
||||||
@ -50,6 +60,7 @@ void PollManager::Poll::store(StorerT &storer) const {
|
|||||||
bool has_explanation = !explanation_.text.empty();
|
bool has_explanation = !explanation_.text.empty();
|
||||||
bool has_recent_voter_dialog_ids = !recent_voter_dialog_ids_.empty();
|
bool has_recent_voter_dialog_ids = !recent_voter_dialog_ids_.empty();
|
||||||
bool has_recent_voter_min_channels = !recent_voter_min_channels_.empty();
|
bool has_recent_voter_min_channels = !recent_voter_min_channels_.empty();
|
||||||
|
bool has_question_entities = !question_.entities.empty();
|
||||||
BEGIN_STORE_FLAGS();
|
BEGIN_STORE_FLAGS();
|
||||||
STORE_FLAG(is_closed_);
|
STORE_FLAG(is_closed_);
|
||||||
STORE_FLAG(is_public);
|
STORE_FLAG(is_public);
|
||||||
@ -62,9 +73,10 @@ void PollManager::Poll::store(StorerT &storer) const {
|
|||||||
STORE_FLAG(is_updated_after_close_);
|
STORE_FLAG(is_updated_after_close_);
|
||||||
STORE_FLAG(has_recent_voter_dialog_ids);
|
STORE_FLAG(has_recent_voter_dialog_ids);
|
||||||
STORE_FLAG(has_recent_voter_min_channels);
|
STORE_FLAG(has_recent_voter_min_channels);
|
||||||
|
STORE_FLAG(has_question_entities);
|
||||||
END_STORE_FLAGS();
|
END_STORE_FLAGS();
|
||||||
|
|
||||||
store(question_, storer);
|
store(question_.text, storer);
|
||||||
store(options_, storer);
|
store(options_, storer);
|
||||||
store(total_voter_count_, storer);
|
store(total_voter_count_, storer);
|
||||||
if (is_quiz_) {
|
if (is_quiz_) {
|
||||||
@ -85,6 +97,9 @@ void PollManager::Poll::store(StorerT &storer) const {
|
|||||||
if (has_recent_voter_min_channels) {
|
if (has_recent_voter_min_channels) {
|
||||||
store(recent_voter_min_channels_, storer);
|
store(recent_voter_min_channels_, storer);
|
||||||
}
|
}
|
||||||
|
if (has_question_entities) {
|
||||||
|
store(question_.entities, storer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ParserT>
|
template <class ParserT>
|
||||||
@ -97,6 +112,7 @@ void PollManager::Poll::parse(ParserT &parser) {
|
|||||||
bool has_explanation;
|
bool has_explanation;
|
||||||
bool has_recent_voter_dialog_ids;
|
bool has_recent_voter_dialog_ids;
|
||||||
bool has_recent_voter_min_channels;
|
bool has_recent_voter_min_channels;
|
||||||
|
bool has_question_entities;
|
||||||
BEGIN_PARSE_FLAGS();
|
BEGIN_PARSE_FLAGS();
|
||||||
PARSE_FLAG(is_closed_);
|
PARSE_FLAG(is_closed_);
|
||||||
PARSE_FLAG(is_public);
|
PARSE_FLAG(is_public);
|
||||||
@ -109,10 +125,11 @@ void PollManager::Poll::parse(ParserT &parser) {
|
|||||||
PARSE_FLAG(is_updated_after_close_);
|
PARSE_FLAG(is_updated_after_close_);
|
||||||
PARSE_FLAG(has_recent_voter_dialog_ids);
|
PARSE_FLAG(has_recent_voter_dialog_ids);
|
||||||
PARSE_FLAG(has_recent_voter_min_channels);
|
PARSE_FLAG(has_recent_voter_min_channels);
|
||||||
|
PARSE_FLAG(has_question_entities);
|
||||||
END_PARSE_FLAGS();
|
END_PARSE_FLAGS();
|
||||||
is_anonymous_ = !is_public;
|
is_anonymous_ = !is_public;
|
||||||
|
|
||||||
parse(question_, parser);
|
parse(question_.text, parser);
|
||||||
parse(options_, parser);
|
parse(options_, parser);
|
||||||
parse(total_voter_count_, parser);
|
parse(total_voter_count_, parser);
|
||||||
if (is_quiz_) {
|
if (is_quiz_) {
|
||||||
@ -141,6 +158,9 @@ void PollManager::Poll::parse(ParserT &parser) {
|
|||||||
if (has_recent_voter_min_channels) {
|
if (has_recent_voter_min_channels) {
|
||||||
parse(recent_voter_min_channels_, parser);
|
parse(recent_voter_min_channels_, parser);
|
||||||
}
|
}
|
||||||
|
if (has_question_entities) {
|
||||||
|
parse(question_.entities, parser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class StorerT>
|
template <class StorerT>
|
||||||
@ -152,6 +172,9 @@ void PollManager::store_poll(PollId poll_id, StorerT &storer) const {
|
|||||||
bool has_open_period = poll->open_period_ != 0;
|
bool has_open_period = poll->open_period_ != 0;
|
||||||
bool has_close_date = poll->close_date_ != 0;
|
bool has_close_date = poll->close_date_ != 0;
|
||||||
bool has_explanation = !poll->explanation_.text.empty();
|
bool has_explanation = !poll->explanation_.text.empty();
|
||||||
|
bool has_question_entities = !poll->question_.entities.empty();
|
||||||
|
bool has_option_entities =
|
||||||
|
td::any_of(poll->options_, [](const PollOption &option) { return !option.text_.entities.empty(); });
|
||||||
BEGIN_STORE_FLAGS();
|
BEGIN_STORE_FLAGS();
|
||||||
STORE_FLAG(poll->is_closed_);
|
STORE_FLAG(poll->is_closed_);
|
||||||
STORE_FLAG(poll->is_anonymous_);
|
STORE_FLAG(poll->is_anonymous_);
|
||||||
@ -160,9 +183,11 @@ void PollManager::store_poll(PollId poll_id, StorerT &storer) const {
|
|||||||
STORE_FLAG(has_open_period);
|
STORE_FLAG(has_open_period);
|
||||||
STORE_FLAG(has_close_date);
|
STORE_FLAG(has_close_date);
|
||||||
STORE_FLAG(has_explanation);
|
STORE_FLAG(has_explanation);
|
||||||
|
STORE_FLAG(has_question_entities);
|
||||||
|
STORE_FLAG(has_option_entities);
|
||||||
END_STORE_FLAGS();
|
END_STORE_FLAGS();
|
||||||
store(poll->question_, storer);
|
store(poll->question_.text, storer);
|
||||||
vector<string> options = transform(poll->options_, [](const PollOption &option) { return option.text_; });
|
vector<string> options = transform(poll->options_, [](const PollOption &option) { return option.text_.text; });
|
||||||
store(options, storer);
|
store(options, storer);
|
||||||
if (poll->is_quiz_) {
|
if (poll->is_quiz_) {
|
||||||
store(poll->correct_option_id_, storer);
|
store(poll->correct_option_id_, storer);
|
||||||
@ -176,6 +201,13 @@ void PollManager::store_poll(PollId poll_id, StorerT &storer) const {
|
|||||||
if (has_explanation) {
|
if (has_explanation) {
|
||||||
store(poll->explanation_, storer);
|
store(poll->explanation_, storer);
|
||||||
}
|
}
|
||||||
|
if (has_question_entities) {
|
||||||
|
store(poll->question_.entities, storer);
|
||||||
|
}
|
||||||
|
if (has_option_entities) {
|
||||||
|
auto option_entities = transform(poll->options_, [](const PollOption &option) { return option.text_.entities; });
|
||||||
|
store(option_entities, storer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,8 +217,8 @@ PollId PollManager::parse_poll(ParserT &parser) {
|
|||||||
td::parse(poll_id_int, parser);
|
td::parse(poll_id_int, 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;
|
FormattedText question;
|
||||||
vector<string> options;
|
vector<FormattedText> options;
|
||||||
FormattedText explanation;
|
FormattedText explanation;
|
||||||
int32 open_period = 0;
|
int32 open_period = 0;
|
||||||
int32 close_date = 0;
|
int32 close_date = 0;
|
||||||
@ -197,6 +229,8 @@ PollId PollManager::parse_poll(ParserT &parser) {
|
|||||||
bool has_open_period = false;
|
bool has_open_period = false;
|
||||||
bool has_close_date = false;
|
bool has_close_date = false;
|
||||||
bool has_explanation = false;
|
bool has_explanation = false;
|
||||||
|
bool has_question_entities = false;
|
||||||
|
bool has_option_entities = false;
|
||||||
int32 correct_option_id = -1;
|
int32 correct_option_id = -1;
|
||||||
|
|
||||||
if (parser.version() >= static_cast<int32>(Version::SupportPolls2_0)) {
|
if (parser.version() >= static_cast<int32>(Version::SupportPolls2_0)) {
|
||||||
@ -208,10 +242,13 @@ PollId PollManager::parse_poll(ParserT &parser) {
|
|||||||
PARSE_FLAG(has_open_period);
|
PARSE_FLAG(has_open_period);
|
||||||
PARSE_FLAG(has_close_date);
|
PARSE_FLAG(has_close_date);
|
||||||
PARSE_FLAG(has_explanation);
|
PARSE_FLAG(has_explanation);
|
||||||
|
PARSE_FLAG(has_question_entities);
|
||||||
|
PARSE_FLAG(has_option_entities);
|
||||||
END_PARSE_FLAGS();
|
END_PARSE_FLAGS();
|
||||||
}
|
}
|
||||||
parse(question, parser);
|
parse(question.text, parser);
|
||||||
parse(options, parser);
|
vector<string> option_texts;
|
||||||
|
parse(option_texts, parser);
|
||||||
if (is_quiz) {
|
if (is_quiz) {
|
||||||
parse(correct_option_id, parser);
|
parse(correct_option_id, parser);
|
||||||
if (correct_option_id < -1 || correct_option_id >= static_cast<int32>(options.size())) {
|
if (correct_option_id < -1 || correct_option_id >= static_cast<int32>(options.size())) {
|
||||||
@ -227,6 +264,19 @@ PollId PollManager::parse_poll(ParserT &parser) {
|
|||||||
if (has_explanation) {
|
if (has_explanation) {
|
||||||
parse(explanation, parser);
|
parse(explanation, parser);
|
||||||
}
|
}
|
||||||
|
if (has_question_entities) {
|
||||||
|
parse(question.entities, parser);
|
||||||
|
}
|
||||||
|
vector<vector<MessageEntity>> option_entities;
|
||||||
|
if (has_option_entities) {
|
||||||
|
parse(option_entities, parser);
|
||||||
|
CHECK(option_entities.size() == option_texts.size());
|
||||||
|
} else {
|
||||||
|
option_entities.resize(option_texts.size());
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < option_texts.size(); i++) {
|
||||||
|
options.push_back({std::move(option_texts[i]), std::move(option_entities[i])});
|
||||||
|
}
|
||||||
if (parser.get_error() != nullptr) {
|
if (parser.get_error() != nullptr) {
|
||||||
return PollId();
|
return PollId();
|
||||||
}
|
}
|
||||||
|
@ -1728,7 +1728,7 @@ class CliClient final : public Actor {
|
|||||||
static td_api::object_ptr<td_api::formattedText> as_formatted_text(
|
static td_api::object_ptr<td_api::formattedText> as_formatted_text(
|
||||||
const string &text, vector<td_api::object_ptr<td_api::textEntity>> entities = {}) {
|
const string &text, vector<td_api::object_ptr<td_api::textEntity>> entities = {}) {
|
||||||
if (entities.empty() && !text.empty()) {
|
if (entities.empty() && !text.empty()) {
|
||||||
Slice unused_reserved_characters("#+-={}.!");
|
Slice unused_reserved_characters("#+-={}.");
|
||||||
string new_text;
|
string new_text;
|
||||||
for (size_t i = 0; i < text.size(); i++) {
|
for (size_t i = 0; i < text.size(); i++) {
|
||||||
auto c = text[i];
|
auto c = text[i];
|
||||||
@ -5301,7 +5301,8 @@ class CliClient final : public Actor {
|
|||||||
ChatId chat_id;
|
ChatId chat_id;
|
||||||
string question;
|
string question;
|
||||||
get_args(args, chat_id, question, args);
|
get_args(args, chat_id, question, args);
|
||||||
auto options = autosplit_str(args);
|
vector<td_api::object_ptr<td_api::formattedText>> options =
|
||||||
|
transform(autosplit_str(args), [](const string &option) { return as_formatted_text(option); });
|
||||||
td_api::object_ptr<td_api::PollType> poll_type;
|
td_api::object_ptr<td_api::PollType> poll_type;
|
||||||
if (op == "squiz") {
|
if (op == "squiz") {
|
||||||
poll_type = td_api::make_object<td_api::pollTypeQuiz>(narrow_cast<int32>(options.size() - 1),
|
poll_type = td_api::make_object<td_api::pollTypeQuiz>(narrow_cast<int32>(options.size() - 1),
|
||||||
@ -5309,8 +5310,9 @@ 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), op != "spollp",
|
send_message(chat_id,
|
||||||
std::move(poll_type), 0, 0, false));
|
td_api::make_object<td_api::inputMessagePoll>(as_formatted_text(question), std::move(options),
|
||||||
|
op != "spollp", std::move(poll_type), 0, 0, false));
|
||||||
} else if (op == "sp") {
|
} else if (op == "sp") {
|
||||||
ChatId chat_id;
|
ChatId chat_id;
|
||||||
string photo;
|
string photo;
|
||||||
|
Loading…
Reference in New Issue
Block a user