Improve field name.

This commit is contained in:
levlam 2023-02-11 22:37:43 +03:00
parent ebe93d7e4f
commit 896de65c3e
3 changed files with 22 additions and 22 deletions

View File

@ -3734,11 +3734,11 @@ telegram_api::object_ptr<telegram_api::textWithEntities> get_input_text_with_ent
FormattedText get_formatted_text(const ContactsManager *contacts_manager, FormattedText get_formatted_text(const ContactsManager *contacts_manager,
telegram_api::object_ptr<telegram_api::textWithEntities> text_with_entities, telegram_api::object_ptr<telegram_api::textWithEntities> text_with_entities,
bool allow_empty, bool skip_new_entities, bool skip_bot_commands, bool allow_empty, bool skip_new_entities, bool skip_bot_commands,
bool skip_media_timestamps, bool for_draft, const char *source) { bool skip_media_timestamps, bool skip_trim, const char *source) {
CHECK(text_with_entities != nullptr); CHECK(text_with_entities != nullptr);
auto entities = get_message_entities(contacts_manager, std::move(text_with_entities->entities_), source); auto entities = get_message_entities(contacts_manager, std::move(text_with_entities->entities_), source);
auto status = fix_formatted_text(text_with_entities->text_, entities, allow_empty, skip_new_entities, auto status = fix_formatted_text(text_with_entities->text_, entities, allow_empty, skip_new_entities,
skip_bot_commands, skip_media_timestamps, for_draft); skip_bot_commands, skip_media_timestamps, skip_trim);
if (status.is_error()) { if (status.is_error()) {
if (!clean_input_string(text_with_entities->text_)) { if (!clean_input_string(text_with_entities->text_)) {
text_with_entities->text_.clear(); text_with_entities->text_.clear();
@ -4154,7 +4154,7 @@ static void merge_new_entities(vector<MessageEntity> &entities, vector<MessageEn
} }
Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool allow_empty, bool skip_new_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) { bool skip_bot_commands, bool skip_media_timestamps, bool skip_trim) {
string result; string result;
if (entities.empty()) { if (entities.empty()) {
// fast path // fast path
@ -4202,7 +4202,7 @@ Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool al
// some splittable entities may be needed to be concatenated // some splittable entities may be needed to be concatenated
fix_entities(entities); fix_entities(entities);
if (for_draft) { if (skip_trim) {
text = std::move(result); text = std::move(result);
} else { } else {
// rtrim // rtrim
@ -4330,7 +4330,7 @@ td_api::object_ptr<td_api::formattedText> extract_input_caption(
Result<FormattedText> get_formatted_text(const Td *td, DialogId dialog_id, Result<FormattedText> get_formatted_text(const Td *td, DialogId dialog_id,
td_api::object_ptr<td_api::formattedText> &&text, bool is_bot, td_api::object_ptr<td_api::formattedText> &&text, bool is_bot,
bool allow_empty, bool skip_media_timestamps, bool for_draft) { bool allow_empty, bool skip_media_timestamps, bool skip_trim) {
if (text == nullptr) { if (text == nullptr) {
if (allow_empty) { if (allow_empty) {
return FormattedText(); return FormattedText();
@ -4343,13 +4343,13 @@ Result<FormattedText> get_formatted_text(const Td *td, DialogId dialog_id,
auto need_skip_bot_commands = need_always_skip_bot_commands(td->contacts_manager_.get(), dialog_id, is_bot); auto need_skip_bot_commands = need_always_skip_bot_commands(td->contacts_manager_.get(), dialog_id, is_bot);
bool parse_markdown = td->option_manager_->get_option_boolean("always_parse_markdown"); bool parse_markdown = td->option_manager_->get_option_boolean("always_parse_markdown");
TRY_STATUS(fix_formatted_text(text->text_, entities, allow_empty, parse_markdown, need_skip_bot_commands, TRY_STATUS(fix_formatted_text(text->text_, entities, allow_empty, parse_markdown, need_skip_bot_commands,
is_bot || skip_media_timestamps || parse_markdown, for_draft)); is_bot || skip_media_timestamps || parse_markdown, skip_trim));
FormattedText result{std::move(text->text_), std::move(entities)}; FormattedText result{std::move(text->text_), std::move(entities)};
if (parse_markdown) { if (parse_markdown) {
result = parse_markdown_v3(std::move(result)); result = parse_markdown_v3(std::move(result));
fix_formatted_text(result.text, result.entities, allow_empty, false, need_skip_bot_commands, fix_formatted_text(result.text, result.entities, allow_empty, false, need_skip_bot_commands,
is_bot || skip_media_timestamps, for_draft) is_bot || skip_media_timestamps, skip_trim)
.ensure(); .ensure();
} }
remove_unallowed_entities(td, result, dialog_id); remove_unallowed_entities(td, result, dialog_id);

View File

@ -220,11 +220,11 @@ telegram_api::object_ptr<telegram_api::textWithEntities> get_input_text_with_ent
FormattedText get_formatted_text(const ContactsManager *contacts_manager, FormattedText get_formatted_text(const ContactsManager *contacts_manager,
telegram_api::object_ptr<telegram_api::textWithEntities> text_with_entities, telegram_api::object_ptr<telegram_api::textWithEntities> text_with_entities,
bool allow_empty, bool skip_new_entities, bool skip_bot_commands, bool allow_empty, bool skip_new_entities, bool skip_bot_commands,
bool skip_media_timestamps, bool for_draft, const char *source); bool skip_media_timestamps, bool skip_trim, const char *source);
// like clean_input_string but also validates entities // like clean_input_string but also validates entities
Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool allow_empty, bool skip_new_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; bool skip_bot_commands, bool skip_media_timestamps, bool skip_trim) TD_WARN_UNUSED_RESULT;
FormattedText get_message_text(const ContactsManager *contacts_manager, string message_text, FormattedText get_message_text(const ContactsManager *contacts_manager, string message_text,
vector<tl_object_ptr<telegram_api::MessageEntity>> &&server_entities, vector<tl_object_ptr<telegram_api::MessageEntity>> &&server_entities,
@ -236,7 +236,7 @@ td_api::object_ptr<td_api::formattedText> extract_input_caption(
Result<FormattedText> get_formatted_text(const Td *td, DialogId dialog_id, Result<FormattedText> get_formatted_text(const Td *td, DialogId dialog_id,
td_api::object_ptr<td_api::formattedText> &&text, bool is_bot, td_api::object_ptr<td_api::formattedText> &&text, bool is_bot,
bool allow_empty, bool skip_media_timestamps, bool for_draft); bool allow_empty, bool skip_media_timestamps, bool skip_trim);
void add_formatted_text_dependencies(Dependencies &dependencies, const FormattedText *text); void add_formatted_text_dependencies(Dependencies &dependencies, const FormattedText *text);

View File

@ -725,16 +725,16 @@ static void check_fix_formatted_text(td::string str, td::vector<td::MessageEntit
const td::string &expected_str, const td::string &expected_str,
const td::vector<td::MessageEntity> &expected_entities, bool allow_empty = true, const td::vector<td::MessageEntity> &expected_entities, bool allow_empty = true,
bool skip_new_entities = false, bool skip_bot_commands = false, bool skip_new_entities = false, bool skip_bot_commands = false,
bool for_draft = true) { bool skip_trim = true) {
ASSERT_TRUE(td::fix_formatted_text(str, entities, allow_empty, skip_new_entities, skip_bot_commands, true, for_draft) ASSERT_TRUE(td::fix_formatted_text(str, entities, allow_empty, skip_new_entities, skip_bot_commands, true, skip_trim)
.is_ok()); .is_ok());
ASSERT_STREQ(expected_str, str); ASSERT_STREQ(expected_str, str);
ASSERT_EQ(expected_entities, entities); ASSERT_EQ(expected_entities, entities);
} }
static void check_fix_formatted_text(td::string str, td::vector<td::MessageEntity> entities, bool allow_empty, static void check_fix_formatted_text(td::string str, td::vector<td::MessageEntity> entities, bool allow_empty,
bool skip_new_entities, bool skip_bot_commands, bool for_draft) { bool skip_new_entities, bool skip_bot_commands, bool skip_trim) {
ASSERT_TRUE(td::fix_formatted_text(str, entities, allow_empty, skip_new_entities, skip_bot_commands, true, for_draft) ASSERT_TRUE(td::fix_formatted_text(str, entities, allow_empty, skip_new_entities, skip_bot_commands, true, skip_trim)
.is_error()); .is_error());
} }
@ -815,9 +815,9 @@ TEST(MessageEntities, fix_formatted_text) {
} }
str = " /test @abaca #ORD $ABC telegram.org "; str = " /test @abaca #ORD $ABC telegram.org ";
for (auto for_draft : {false, true}) { for (auto skip_trim : {false, true}) {
td::int32 shift = for_draft ? 2 : 0; td::int32 shift = skip_trim ? 2 : 0;
td::string expected_str = for_draft ? str : str.substr(2, str.size() - 3); td::string expected_str = skip_trim ? str : str.substr(2, str.size() - 3);
for (auto skip_new_entities : {false, true}) { for (auto skip_new_entities : {false, true}) {
for (auto skip_bot_commands : {false, true}) { for (auto skip_bot_commands : {false, true}) {
@ -833,9 +833,9 @@ TEST(MessageEntities, fix_formatted_text) {
} }
check_fix_formatted_text(str, {}, expected_str, entities, true, skip_new_entities, skip_bot_commands, check_fix_formatted_text(str, {}, expected_str, entities, true, skip_new_entities, skip_bot_commands,
for_draft); skip_trim);
check_fix_formatted_text(str, {}, expected_str, entities, false, skip_new_entities, skip_bot_commands, check_fix_formatted_text(str, {}, expected_str, entities, false, skip_new_entities, skip_bot_commands,
for_draft); skip_trim);
} }
} }
} }
@ -846,8 +846,8 @@ TEST(MessageEntities, fix_formatted_text) {
for (td::int32 offset = 0; static_cast<size_t>(offset + length) <= str.size(); offset++) { for (td::int32 offset = 0; static_cast<size_t>(offset + length) <= str.size(); offset++) {
for (auto type : {td::MessageEntity::Type::Bold, td::MessageEntity::Type::Url, td::MessageEntity::Type::TextUrl, for (auto type : {td::MessageEntity::Type::Bold, td::MessageEntity::Type::Url, td::MessageEntity::Type::TextUrl,
td::MessageEntity::Type::MentionName}) { td::MessageEntity::Type::MentionName}) {
for (auto for_draft : {false, true}) { for (auto skip_trim : {false, true}) {
fixed_str = for_draft ? "aba \n caba " : "aba \n caba"; fixed_str = skip_trim ? "aba \n caba " : "aba \n caba";
auto fixed_length = offset <= 4 && offset + length >= 5 ? length - 1 : length; auto fixed_length = offset <= 4 && offset + length >= 5 ? length - 1 : length;
auto fixed_offset = offset >= 5 ? offset - 1 : offset; auto fixed_offset = offset >= 5 ? offset - 1 : offset;
if (static_cast<size_t>(fixed_offset) >= fixed_str.size()) { if (static_cast<size_t>(fixed_offset) >= fixed_str.size()) {
@ -885,7 +885,7 @@ TEST(MessageEntities, fix_formatted_text) {
} }
} }
} }
check_fix_formatted_text(str, entities, fixed_str, fixed_entities, true, false, false, for_draft); check_fix_formatted_text(str, entities, fixed_str, fixed_entities, true, false, false, skip_trim);
} }
} }
} }