Add functions for conversion between FormattedText and textWithEntities.
This commit is contained in:
parent
8c43a7c0bb
commit
3121757b32
@ -3725,6 +3725,27 @@ vector<MessageEntity> get_message_entities(Td *td, vector<tl_object_ptr<secret_a
|
||||
return entities;
|
||||
}
|
||||
|
||||
telegram_api::object_ptr<telegram_api::textWithEntities> get_input_text_with_entities(
|
||||
const ContactsManager *contacts_manager, const FormattedText &text, const char *source) {
|
||||
return telegram_api::make_object<telegram_api::textWithEntities>(
|
||||
text.text, get_input_message_entities(contacts_manager, text.entities, source));
|
||||
}
|
||||
|
||||
FormattedText get_formatted_text(const ContactsManager *contacts_manager,
|
||||
telegram_api::object_ptr<telegram_api::textWithEntities> 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<string> clean_input_string_with_entities(const string &text, vector<MessageEntity> &entities) {
|
||||
|
@ -201,6 +201,13 @@ vector<MessageEntity> get_message_entities(const ContactsManager *contacts_manag
|
||||
vector<MessageEntity> get_message_entities(Td *td, vector<tl_object_ptr<secret_api::MessageEntity>> &&secret_entities,
|
||||
bool is_premium, MultiPromiseActor &load_data_multipromise);
|
||||
|
||||
telegram_api::object_ptr<telegram_api::textWithEntities> 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<telegram_api::textWithEntities> text_with_entities,
|
||||
const char *source);
|
||||
|
||||
// like clean_input_string but also validates entities
|
||||
Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool allow_empty, bool skip_new_entities,
|
||||
bool skip_bot_commands, bool skip_media_timestamps, bool for_draft) TD_WARN_UNUSED_RESULT;
|
||||
|
Loading…
Reference in New Issue
Block a user