diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index db9ca1013..78749983c 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -3725,6 +3725,27 @@ vector get_message_entities(Td *td, vector get_input_text_with_entities( + const ContactsManager *contacts_manager, const FormattedText &text, const char *source) { + return telegram_api::make_object( + text.text, get_input_message_entities(contacts_manager, text.entities, source)); +} + +FormattedText get_formatted_text(const ContactsManager *contacts_manager, + telegram_api::object_ptr text_with_entities, + const char *source) { + CHECK(text_with_entities != nullptr); + auto entities = get_message_entities(contacts_manager, std::move(text_with_entities->entities_), source); + auto status = fix_formatted_text(text_with_entities->text_, entities, true, true, true, true, false); + if (status.is_error()) { + if (!clean_input_string(text_with_entities->text_)) { + text_with_entities->text_.clear(); + } + entities = find_entities(text_with_entities->text_, true, true); + } + return {std::move(text_with_entities->text_), std::move(entities)}; +} + // like clean_input_string but also fixes entities // entities must be sorted, can be nested, but must not intersect each other static Result clean_input_string_with_entities(const string &text, vector &entities) { diff --git a/td/telegram/MessageEntity.h b/td/telegram/MessageEntity.h index c392ab2cc..f45070c01 100644 --- a/td/telegram/MessageEntity.h +++ b/td/telegram/MessageEntity.h @@ -201,6 +201,13 @@ vector get_message_entities(const ContactsManager *contacts_manag vector get_message_entities(Td *td, vector> &&secret_entities, bool is_premium, MultiPromiseActor &load_data_multipromise); +telegram_api::object_ptr get_input_text_with_entities( + const ContactsManager *contacts_manager, const FormattedText &text, const char *source); + +FormattedText get_formatted_text(const ContactsManager *contacts_manager, + telegram_api::object_ptr text_with_entities, + const char *source); + // like clean_input_string but also validates entities Status fix_formatted_text(string &text, vector &entities, bool allow_empty, bool skip_new_entities, bool skip_bot_commands, bool skip_media_timestamps, bool for_draft) TD_WARN_UNUSED_RESULT;