diff --git a/td/telegram/InputMessageText.cpp b/td/telegram/InputMessageText.cpp index b26576fa7..2afda69ee 100644 --- a/td/telegram/InputMessageText.cpp +++ b/td/telegram/InputMessageText.cpp @@ -53,7 +53,7 @@ Result process_input_message_text(const Td *td, DialogId dialo is_bot || for_draft, for_draft) .ensure(); } - remove_unallowed_entities(td->stickers_manager_.get(), result.text, dialog_id.get_type() == DialogType::SecretChat); + remove_unallowed_entities(td, result.text, dialog_id); return std::move(result); } diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 97a136768..e70191e07 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -4663,7 +4663,7 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const case MessageContentType::Text: { auto result = make_unique(*static_cast(content)); if (type == MessageContentDupType::Copy || type == MessageContentDupType::ServerCopy) { - remove_unallowed_entities(td->stickers_manager_.get(), result->text, to_secret); + remove_unallowed_entities(td, result->text, dialog_id); } return result; } diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index 199145f22..fee706470 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -13,6 +13,7 @@ #include "td/telegram/misc.h" #include "td/telegram/SecretChatLayer.h" #include "td/telegram/StickersManager.h" +#include "td/telegram/Td.h" #include "td/utils/algorithm.h" #include "td/utils/format.h" @@ -211,20 +212,6 @@ td_api::object_ptr get_formatted_text_object(const Format text.text, get_text_entities_object(text.entities, skip_bot_commands, max_media_timestamp)); } -void remove_unallowed_entities(const StickersManager *stickers_manager, FormattedText &text, bool to_secret) { - if (to_secret) { - td::remove_if(text.entities, [](const MessageEntity &entity) { - return entity.type == MessageEntity::Type::Spoiler || entity.type == MessageEntity::Type::CustomEmoji; - }); - } else if (!G()->shared_config().get_option_boolean("is_premium")) { - // remove premium custom emoji - td::remove_if(text.entities, [stickers_manager](const MessageEntity &entity) { - return entity.type == MessageEntity::Type::CustomEmoji && - stickers_manager->is_premium_custom_emoji(entity.document_id); - }); - } -} - static bool is_word_character(uint32 code) { switch (get_unicode_simple_category(code)) { case UnicodeSimpleCategory::Letter: @@ -4392,4 +4379,36 @@ vector> get_input_message_entities(co return {}; } +void remove_unallowed_entities(const Td *td, FormattedText &text, DialogId dialog_id) { + if (text.entities.empty()) { + return; + } + + if (dialog_id.get_type() == DialogType::SecretChat) { + auto layer = td->contacts_manager_->get_secret_chat_layer(dialog_id.get_secret_chat_id()); + td::remove_if(text.entities, [layer](const MessageEntity &entity) { + if (layer < static_cast(SecretChatLayer::NewEntities) && + (entity.type == MessageEntity::Type::Underline || entity.type == MessageEntity::Type::Strikethrough || + entity.type == MessageEntity::Type::BlockQuote)) { + return true; + } + if (entity.type == MessageEntity::Type::Spoiler || entity.type == MessageEntity::Type::CustomEmoji) { + return true; + } + return false; + }); + + if (layer < static_cast(SecretChatLayer::NewEntities)) { + sort_entities(text.entities); + remove_intersecting_entities(text.entities); + } + } else if (!G()->shared_config().get_option_boolean("is_premium")) { + // remove premium custom emoji + td::remove_if(text.entities, [td](const MessageEntity &entity) { + return entity.type == MessageEntity::Type::CustomEmoji && + td->stickers_manager_->is_premium_custom_emoji(entity.document_id); + }); + } +} + } // namespace td diff --git a/td/telegram/MessageEntity.h b/td/telegram/MessageEntity.h index b5feeb779..d7d71ac6e 100644 --- a/td/telegram/MessageEntity.h +++ b/td/telegram/MessageEntity.h @@ -24,7 +24,7 @@ namespace td { class ContactsManager; class Dependencies; -class StickersManager; +class Td; class MessageEntity { public: @@ -151,7 +151,7 @@ vector> get_text_entities_object(const vector< td_api::object_ptr get_formatted_text_object(const FormattedText &text, bool skip_bot_commands, int32 max_media_timestamp); -void remove_unallowed_entities(const StickersManager *stickers_manager, FormattedText &text, bool to_secret); +void remove_unallowed_entities(const Td *td, FormattedText &text, DialogId dialog_id); vector find_entities(Slice text, bool skip_bot_commands, bool skip_media_timestamps);