Add get_formatted_text(string, vector<MessageEntity>).

This commit is contained in:
levlam 2024-04-23 19:23:02 +03:00
parent 2424d681c9
commit e9beb42444
2 changed files with 24 additions and 10 deletions

View File

@ -3949,21 +3949,30 @@ telegram_api::object_ptr<telegram_api::textWithEntities> get_input_text_with_ent
text.text, get_input_message_entities(user_manager, text.entities, source));
}
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_new_entities, bool skip_bot_commands,
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, skip_new_entities, skip_bot_commands,
skip_media_timestamps, skip_trim);
if (status.is_error()) {
if (!clean_input_string(text)) {
text.clear();
}
entities = find_entities(text, skip_bot_commands, skip_media_timestamps);
}
return {std::move(text), std::move(entities)};
}
FormattedText get_formatted_text(const UserManager *user_manager,
telegram_api::object_ptr<telegram_api::textWithEntities> text_with_entities,
bool allow_empty, bool skip_new_entities, bool skip_bot_commands,
bool skip_media_timestamps, bool skip_trim, const char *source) {
CHECK(text_with_entities != nullptr);
auto entities = get_message_entities(user_manager, std::move(text_with_entities->entities_), source);
auto status = fix_formatted_text(text_with_entities->text_, entities, allow_empty, skip_new_entities,
skip_bot_commands, skip_media_timestamps, skip_trim);
if (status.is_error()) {
if (!clean_input_string(text_with_entities->text_)) {
text_with_entities->text_.clear();
}
entities = find_entities(text_with_entities->text_, skip_bot_commands, skip_media_timestamps);
}
return {std::move(text_with_entities->text_), std::move(entities)};
return get_formatted_text(user_manager, std::move(text_with_entities->text_),
std::move(text_with_entities->entities_), allow_empty, skip_new_entities, skip_bot_commands,
skip_media_timestamps, skip_trim, source);
}
// like clean_input_string but also fixes entities

View File

@ -223,6 +223,11 @@ telegram_api::object_ptr<telegram_api::textWithEntities> get_input_text_with_ent
const FormattedText &text,
const char *source);
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_new_entities, bool skip_bot_commands,
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_new_entities, bool skip_bot_commands,