Don't check received from server strings for emptiness.

This commit is contained in:
levlam 2024-05-04 23:12:26 +03:00
parent 4e085215b3
commit b1044c9348
9 changed files with 22 additions and 24 deletions

View File

@ -409,7 +409,7 @@ DraftMessage::DraftMessage(Td *td, telegram_api::object_ptr<telegram_api::draftM
date_ = draft_message->date_;
message_input_reply_to_ = MessageInputReplyTo(td, std::move(draft_message->reply_to_));
auto draft_text = get_formatted_text(td->user_manager_.get(), std::move(draft_message->message_),
std::move(draft_message->entities_), true, true, true, "DraftMessage");
std::move(draft_message->entities_), true, true, "DraftMessage");
string web_page_url;
bool force_small_media = false;
bool force_large_media = false;

View File

@ -848,7 +848,7 @@ class GetDeepLinkInfoQuery final : public Td::ResultHandler {
return promise_.set_value(nullptr);
case telegram_api::help_deepLinkInfo::ID: {
auto info = telegram_api::move_object_as<telegram_api::help_deepLinkInfo>(result);
auto text = get_formatted_text(nullptr, std::move(info->message_), std::move(info->entities_), true, true, true,
auto text = get_formatted_text(nullptr, std::move(info->message_), std::move(info->entities_), true, true,
"GetDeepLinkInfoQuery");
return promise_.set_value(
td_api::make_object<td_api::deepLinkInfo>(get_formatted_text_object(text, true, -1), info->update_app_));

View File

@ -2472,7 +2472,7 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
case telegram_api::botInlineMessageText::ID: {
auto inline_message = move_tl_object_as<telegram_api::botInlineMessageText>(bot_inline_message);
auto text = get_formatted_text(td->user_manager_.get(), std::move(inline_message->message_),
std::move(inline_message->entities_), false, false, false, "botInlineMessageText");
std::move(inline_message->entities_), false, false, "botInlineMessageText");
result.disable_web_page_preview = inline_message->no_webpage_;
result.invert_media = inline_message->invert_media_;
WebPageId web_page_id;
@ -2490,9 +2490,9 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
if (inline_message->manual_) {
web_page_url = std::move(inline_message->url_);
}
auto text = get_formatted_text(td->user_manager_.get(), std::move(inline_message->message_),
std::move(inline_message->entities_), !web_page_url.empty(), false, false,
"botInlineMessageMediaWebPage");
auto text =
get_formatted_text(td->user_manager_.get(), std::move(inline_message->message_),
std::move(inline_message->entities_), false, false, "botInlineMessageMediaWebPage");
auto web_page_id =
td->web_pages_manager_->get_web_page_by_url(web_page_url.empty() ? get_first_url(text).str() : web_page_url);
result.message_content = td::make_unique<MessageText>(

View File

@ -3933,9 +3933,9 @@ telegram_api::object_ptr<telegram_api::textWithEntities> get_input_text_with_ent
FormattedText get_formatted_text(const UserManager *user_manager, string &&text,
vector<telegram_api::object_ptr<telegram_api::MessageEntity>> &&server_entities,
bool allow_empty, bool skip_media_timestamps, bool skip_trim, const char *source) {
bool skip_media_timestamps, bool skip_trim, const char *source) {
auto entities = get_message_entities(user_manager, std::move(server_entities), source);
auto status = fix_formatted_text(text, entities, allow_empty, true, true, skip_media_timestamps, skip_trim);
auto status = fix_formatted_text(text, entities, true, true, true, skip_media_timestamps, skip_trim);
if (status.is_error()) {
LOG(ERROR) << "Receive error " << status << " from " << source << " while parsing \"" << text << "\"("
<< hex_encode(text) << ')';
@ -3949,11 +3949,10 @@ FormattedText get_formatted_text(const UserManager *user_manager, string &&text,
FormattedText get_formatted_text(const UserManager *user_manager,
telegram_api::object_ptr<telegram_api::textWithEntities> text_with_entities,
bool allow_empty, bool skip_media_timestamps, bool skip_trim, const char *source) {
bool skip_media_timestamps, bool skip_trim, const char *source) {
CHECK(text_with_entities != nullptr);
return get_formatted_text(user_manager, std::move(text_with_entities->text_),
std::move(text_with_entities->entities_), allow_empty, skip_media_timestamps, skip_trim,
source);
std::move(text_with_entities->entities_), skip_media_timestamps, skip_trim, source);
}
// like clean_input_string but also fixes entities

View File

@ -217,11 +217,11 @@ telegram_api::object_ptr<telegram_api::textWithEntities> get_input_text_with_ent
FormattedText get_formatted_text(const UserManager *user_manager, string &&text,
vector<telegram_api::object_ptr<telegram_api::MessageEntity>> &&server_entities,
bool allow_empty, bool skip_media_timestamps, bool skip_trim, const char *source);
bool skip_media_timestamps, bool skip_trim, const char *source);
FormattedText get_formatted_text(const UserManager *user_manager,
telegram_api::object_ptr<telegram_api::textWithEntities> text_with_entities,
bool allow_empty, bool skip_media_timestamps, bool skip_trim, const char *source);
bool skip_media_timestamps, bool skip_trim, const char *source);
void fix_entities(vector<MessageEntity> &entities);

View File

@ -28,9 +28,8 @@ MessageQuote::MessageQuote(Td *td,
if (input_reply_to_message->quote_text_.empty()) {
return;
}
text_ =
get_formatted_text(td->user_manager_.get(), std::move(input_reply_to_message->quote_text_),
std::move(input_reply_to_message->quote_entities_), true, true, false, "inputReplyToMessage");
text_ = get_formatted_text(td->user_manager_.get(), std::move(input_reply_to_message->quote_text_),
std::move(input_reply_to_message->quote_entities_), true, false, "inputReplyToMessage");
remove_unallowed_quote_entities(text_);
position_ = max(0, input_reply_to_message->quote_offset_);
}
@ -41,7 +40,7 @@ MessageQuote::MessageQuote(Td *td, telegram_api::object_ptr<telegram_api::messag
return;
}
text_ = get_formatted_text(td->user_manager_.get(), std::move(reply_header->quote_text_),
std::move(reply_header->quote_entities_), true, true, false, "messageReplyHeader");
std::move(reply_header->quote_entities_), true, false, "messageReplyHeader");
remove_unallowed_quote_entities(text_);
position_ = max(0, reply_header->quote_offset_);
is_manual_ = reply_header->quote_;

View File

@ -1575,7 +1575,7 @@ vector<PollManager::PollOption> PollManager::get_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) {
PollOption option;
option.text_ = get_formatted_text(nullptr, std::move(poll_option->text_), false, true, true, "get_poll_options");
option.text_ = get_formatted_text(nullptr, std::move(poll_option->text_), true, true, "get_poll_options");
remove_unallowed_entities(option.text_);
option.data_ = poll_option->option_.as_slice().str();
return option;
@ -1686,7 +1686,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
}
is_changed = true;
}
auto question = get_formatted_text(nullptr, std::move(poll_server->question_), false, true, true, "on_get_poll");
auto question = get_formatted_text(nullptr, std::move(poll_server->question_), true, true, "on_get_poll");
remove_unallowed_entities(question);
if (poll->question_ != question) {
poll->question_ = std::move(question);
@ -1833,7 +1833,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
}
auto explanation = get_formatted_text(td_->user_manager_.get(), std::move(poll_results->solution_),
std::move(poll_results->solution_entities_), true, true, false, source);
std::move(poll_results->solution_entities_), true, false, source);
if (poll->is_quiz_) {
if (poll->correct_option_id_ != correct_option_id) {
if (correct_option_id == -1 && poll->correct_option_id_ != -1) {

View File

@ -94,8 +94,8 @@ TermsOfService::TermsOfService(telegram_api::object_ptr<telegram_api::help_terms
}
id_ = std::move(terms->id_->data_);
text_ = get_formatted_text(nullptr, std::move(terms->text_), std::move(terms->entities_), true, true, false,
"TermsOfService");
text_ =
get_formatted_text(nullptr, std::move(terms->text_), std::move(terms->entities_), true, false, "TermsOfService");
if (text_.text.empty()) {
id_.clear();
}

View File

@ -119,8 +119,8 @@ void TranslationManager::on_get_translated_texts(vector<telegram_api::object_ptr
if (texts.size() != 1u) {
return promise.set_error(Status::Error(500, "Receive invalid number of results"));
}
auto formatted_text = get_formatted_text(td_->user_manager_.get(), std::move(texts[0]), true,
max_media_timestamp == -1, true, "on_get_translated_texts");
auto formatted_text = get_formatted_text(td_->user_manager_.get(), std::move(texts[0]), max_media_timestamp == -1,
true, "on_get_translated_texts");
promise.set_value(get_formatted_text_object(formatted_text, skip_bot_commands, max_media_timestamp));
}