diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index 08d1b74d4..92538f057 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -3734,11 +3734,11 @@ telegram_api::object_ptr get_input_text_with_ent FormattedText get_formatted_text(const ContactsManager *contacts_manager, telegram_api::object_ptr text_with_entities, 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); 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, - skip_bot_commands, skip_media_timestamps, for_draft); + 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(); @@ -4154,7 +4154,7 @@ static void merge_new_entities(vector &entities, vector &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; if (entities.empty()) { // fast path @@ -4202,7 +4202,7 @@ Status fix_formatted_text(string &text, vector &entities, bool al // some splittable entities may be needed to be concatenated fix_entities(entities); - if (for_draft) { + if (skip_trim) { text = std::move(result); } else { // rtrim @@ -4330,7 +4330,7 @@ td_api::object_ptr extract_input_caption( Result get_formatted_text(const Td *td, DialogId dialog_id, td_api::object_ptr &&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 (allow_empty) { return FormattedText(); @@ -4343,13 +4343,13 @@ Result 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); 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, - 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)}; if (parse_markdown) { result = parse_markdown_v3(std::move(result)); 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(); } remove_unallowed_entities(td, result, dialog_id); diff --git a/td/telegram/MessageEntity.h b/td/telegram/MessageEntity.h index c0cad3967..b8305a2d6 100644 --- a/td/telegram/MessageEntity.h +++ b/td/telegram/MessageEntity.h @@ -220,11 +220,11 @@ telegram_api::object_ptr get_input_text_with_ent FormattedText get_formatted_text(const ContactsManager *contacts_manager, telegram_api::object_ptr text_with_entities, 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 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; + 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, vector> &&server_entities, @@ -236,7 +236,7 @@ td_api::object_ptr extract_input_caption( Result get_formatted_text(const Td *td, DialogId dialog_id, td_api::object_ptr &&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); diff --git a/test/message_entities.cpp b/test/message_entities.cpp index ff9735392..378e76b23 100644 --- a/test/message_entities.cpp +++ b/test/message_entities.cpp @@ -725,16 +725,16 @@ static void check_fix_formatted_text(td::string str, td::vector &expected_entities, bool allow_empty = true, bool skip_new_entities = false, bool skip_bot_commands = false, - bool for_draft = true) { - ASSERT_TRUE(td::fix_formatted_text(str, entities, allow_empty, skip_new_entities, skip_bot_commands, true, for_draft) + bool skip_trim = true) { + ASSERT_TRUE(td::fix_formatted_text(str, entities, allow_empty, skip_new_entities, skip_bot_commands, true, skip_trim) .is_ok()); ASSERT_STREQ(expected_str, str); ASSERT_EQ(expected_entities, entities); } static void check_fix_formatted_text(td::string str, td::vector entities, bool allow_empty, - bool skip_new_entities, bool skip_bot_commands, bool for_draft) { - ASSERT_TRUE(td::fix_formatted_text(str, entities, allow_empty, skip_new_entities, skip_bot_commands, true, 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, skip_trim) .is_error()); } @@ -815,9 +815,9 @@ TEST(MessageEntities, fix_formatted_text) { } str = " /test @abaca #ORD $ABC telegram.org "; - for (auto for_draft : {false, true}) { - td::int32 shift = for_draft ? 2 : 0; - td::string expected_str = for_draft ? str : str.substr(2, str.size() - 3); + for (auto skip_trim : {false, true}) { + td::int32 shift = skip_trim ? 2 : 0; + td::string expected_str = skip_trim ? str : str.substr(2, str.size() - 3); for (auto skip_new_entities : {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, - for_draft); + skip_trim); 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(offset + length) <= str.size(); offset++) { for (auto type : {td::MessageEntity::Type::Bold, td::MessageEntity::Type::Url, td::MessageEntity::Type::TextUrl, td::MessageEntity::Type::MentionName}) { - for (auto for_draft : {false, true}) { - fixed_str = for_draft ? "aba \n caba " : "aba \n caba"; + for (auto skip_trim : {false, true}) { + fixed_str = skip_trim ? "aba \n caba " : "aba \n caba"; auto fixed_length = offset <= 4 && offset + length >= 5 ? length - 1 : length; auto fixed_offset = offset >= 5 ? offset - 1 : offset; if (static_cast(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); } } }