diff --git a/td/telegram/DraftMessage.cpp b/td/telegram/DraftMessage.cpp index 7e1447dc7..d19989930 100644 --- a/td/telegram/DraftMessage.cpp +++ b/td/telegram/DraftMessage.cpp @@ -409,15 +409,9 @@ DraftMessage::DraftMessage(Td *td, telegram_api::object_ptrdate_; message_input_reply_to_ = MessageInputReplyTo(td, std::move(draft_message->reply_to_)); - auto entities = get_message_entities(td->user_manager_.get(), std::move(draft_message->entities_), "draftMessage"); - auto status = fix_formatted_text(draft_message->message_, entities, true, true, true, true, true); - if (status.is_error()) { - LOG(ERROR) << "Receive error " << status << " while parsing draft " << draft_message->message_; - if (!clean_input_string(draft_message->message_)) { - draft_message->message_.clear(); - } - entities = find_entities(draft_message->message_, false, true); - } + auto draft_text = + get_formatted_text(td->user_manager_.get(), std::move(draft_message->message_), + std::move(draft_message->entities_), true, true, true, true, true, "DraftMessage"); string web_page_url; bool force_small_media = false; bool force_large_media = false; @@ -434,9 +428,8 @@ DraftMessage::DraftMessage(Td *td, telegram_api::object_ptrforce_large_media_; } } - input_message_text_ = InputMessageText(FormattedText{std::move(draft_message->message_), std::move(entities)}, - std::move(web_page_url), draft_message->no_webpage_, force_small_media, - force_large_media, draft_message->invert_media_, false); + input_message_text_ = InputMessageText(std::move(draft_text), std::move(web_page_url), draft_message->no_webpage_, + force_small_media, force_large_media, draft_message->invert_media_, false); } Result> DraftMessage::get_draft_message( diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index 41361b75d..1ad6c2bf6 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -848,16 +848,8 @@ class GetDeepLinkInfoQuery final : public Td::ResultHandler { return promise_.set_value(nullptr); case telegram_api::help_deepLinkInfo::ID: { auto info = telegram_api::move_object_as(result); - auto entities = get_message_entities(nullptr, std::move(info->entities_), "GetDeepLinkInfoQuery"); - auto status = fix_formatted_text(info->message_, entities, true, true, true, true, true); - if (status.is_error()) { - LOG(ERROR) << "Receive error " << status << " while parsing deep link info " << info->message_; - if (!clean_input_string(info->message_)) { - info->message_.clear(); - } - entities = find_entities(info->message_, true, true); - } - FormattedText text{std::move(info->message_), std::move(entities)}; + auto text = get_formatted_text(nullptr, std::move(info->message_), std::move(info->entities_), true, true, true, + true, true, "GetDeepLinkInfoQuery"); return promise_.set_value( td_api::make_object(get_formatted_text_object(text, true, -1), info->update_app_)); } diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index f31bb3cff..7935475fb 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -2471,17 +2471,11 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id, switch (bot_inline_message->get_id()) { case telegram_api::botInlineMessageText::ID: { auto inline_message = move_tl_object_as(bot_inline_message); - auto entities = - get_message_entities(td->user_manager_.get(), std::move(inline_message->entities_), "botInlineMessageText"); - auto status = fix_formatted_text(inline_message->message_, entities, false, true, true, false, false); - if (status.is_error()) { - LOG(ERROR) << "Receive error " << status << " while parsing botInlineMessageText " << inline_message->message_; - break; - } - + auto text = get_formatted_text(td->user_manager_.get(), std::move(inline_message->message_), + std::move(inline_message->entities_), false, true, true, false, false, + "botInlineMessageText"); result.disable_web_page_preview = inline_message->no_webpage_; result.invert_media = inline_message->invert_media_; - FormattedText text{std::move(inline_message->message_), std::move(entities)}; WebPageId web_page_id; if (!result.disable_web_page_preview) { web_page_id = td->web_pages_manager_->get_web_page_by_url(get_first_url(text).str()); @@ -2497,18 +2491,10 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id, if (inline_message->manual_) { web_page_url = std::move(inline_message->url_); } - auto entities = get_message_entities(td->user_manager_.get(), std::move(inline_message->entities_), - "botInlineMessageMediaWebPage"); - auto status = - fix_formatted_text(inline_message->message_, entities, !web_page_url.empty(), true, true, false, false); - if (status.is_error()) { - LOG(ERROR) << "Receive error " << status << " while parsing botInlineMessageMediaWebPage " - << inline_message->message_; - break; - } - - FormattedText text{std::move(inline_message->message_), std::move(entities)}; - WebPageId web_page_id = + auto text = get_formatted_text(td->user_manager_.get(), std::move(inline_message->message_), + std::move(inline_message->entities_), !web_page_url.empty(), true, true, 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( std::move(text), web_page_id, inline_message->force_small_media_, inline_message->force_large_media_, diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index 364056b1b..33182bff6 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -3957,6 +3957,7 @@ FormattedText get_formatted_text(const UserManager *user_manager, string &&text, auto status = fix_formatted_text(text, entities, allow_empty, skip_new_entities, skip_bot_commands, skip_media_timestamps, skip_trim); if (status.is_error()) { + LOG(ERROR) << "Receive error " << status << " from " << source << " while parsing " << text; if (!clean_input_string(text)) { text.clear(); } diff --git a/td/telegram/MessageEntity.h b/td/telegram/MessageEntity.h index ffc138028..ad4f6a5f4 100644 --- a/td/telegram/MessageEntity.h +++ b/td/telegram/MessageEntity.h @@ -212,10 +212,6 @@ vector> get_input_message_entities(co vector> get_input_secret_message_entities( const vector &entities, int32 layer); -vector get_message_entities(const UserManager *user_manager, - vector> &&server_entities, - const char *source); - vector get_message_entities(Td *td, vector> &&secret_entities, bool is_premium, MultiPromiseActor &load_data_multipromise); diff --git a/td/telegram/MessageInputReplyTo.cpp b/td/telegram/MessageInputReplyTo.cpp index 4dd7245d8..b7a08647c 100644 --- a/td/telegram/MessageInputReplyTo.cpp +++ b/td/telegram/MessageInputReplyTo.cpp @@ -57,16 +57,9 @@ MessageInputReplyTo::MessageInputReplyTo(Td *td, dialog_id_ = dialog_id; if (!reply_to->quote_text_.empty()) { - auto entities = - get_message_entities(td->user_manager_.get(), std::move(reply_to->quote_entities_), "inputReplyToMessage"); - auto status = fix_formatted_text(reply_to->quote_text_, entities, true, true, true, true, false); - if (status.is_error()) { - if (!clean_input_string(reply_to->quote_text_)) { - reply_to->quote_text_.clear(); - } - entities.clear(); - } - quote_ = FormattedText{std::move(reply_to->quote_text_), std::move(entities)}; + quote_ = get_formatted_text(td->user_manager_.get(), std::move(reply_to->quote_text_), + std::move(reply_to->quote_entities_), true, true, true, true, false, + "inputReplyToMessage"); remove_unallowed_quote_entities(quote_); quote_position_ = max(0, reply_to->quote_offset_); } diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index db49f2cc3..7c1a47cf5 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -1812,16 +1812,9 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptruser_manager_.get(), std::move(poll_results->solution_entities_), source); - auto status = fix_formatted_text(poll_results->solution_, entities, true, true, true, true, false); - if (status.is_error()) { - if (!clean_input_string(poll_results->solution_)) { - poll_results->solution_.clear(); - } - entities = find_entities(poll_results->solution_, true, true); - } - FormattedText explanation{std::move(poll_results->solution_), std::move(entities)}; - + auto explanation = + get_formatted_text(td_->user_manager_.get(), std::move(poll_results->solution_), + std::move(poll_results->solution_entities_), true, true, true, 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) { diff --git a/td/telegram/RepliedMessageInfo.cpp b/td/telegram/RepliedMessageInfo.cpp index 52e111787..34347c518 100644 --- a/td/telegram/RepliedMessageInfo.cpp +++ b/td/telegram/RepliedMessageInfo.cpp @@ -117,18 +117,11 @@ RepliedMessageInfo::RepliedMessageInfo(Td *td, tl_object_ptrquote_text_.empty()) { is_quote_manual_ = reply_header->quote_; - auto entities = - get_message_entities(td->user_manager_.get(), std::move(reply_header->quote_entities_), "RepliedMessageInfo"); - auto status = fix_formatted_text(reply_header->quote_text_, entities, true, true, true, true, false); - if (status.is_error()) { - if (!clean_input_string(reply_header->quote_text_)) { - reply_header->quote_text_.clear(); - } - entities.clear(); - } - quote_ = FormattedText{std::move(reply_header->quote_text_), std::move(entities)}; - quote_position_ = max(0, reply_header->quote_offset_); + quote_ = get_formatted_text(td->user_manager_.get(), std::move(reply_header->quote_text_), + std::move(reply_header->quote_entities_), true, true, true, true, false, + "RepliedMessageInfo"); remove_unallowed_quote_entities(quote_); + quote_position_ = max(0, reply_header->quote_offset_); } } diff --git a/td/telegram/TermsOfService.cpp b/td/telegram/TermsOfService.cpp index afd410ab0..f93a5e446 100644 --- a/td/telegram/TermsOfService.cpp +++ b/td/telegram/TermsOfService.cpp @@ -95,18 +95,11 @@ TermsOfService::TermsOfService(telegram_api::object_ptrid_->data_); - auto entities = get_message_entities(nullptr, std::move(terms->entities_), "TermsOfService"); - auto status = fix_formatted_text(terms->text_, entities, true, true, true, true, false); - if (status.is_error()) { - if (!clean_input_string(terms->text_)) { - terms->text_.clear(); - } - entities = find_entities(terms->text_, true, true); - } - if (terms->text_.empty()) { + text_ = get_formatted_text(nullptr, std::move(terms->text_), std::move(terms->entities_), true, true, true, true, + false, "TermsOfService"); + if (text_.text.empty()) { id_.clear(); } - text_ = FormattedText{std::move(terms->text_), std::move(entities)}; min_user_age_ = terms->min_age_confirm_; show_popup_ = terms->popup_; }