diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index c2777a525..93f43ac01 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -3652,7 +3652,7 @@ vector get_message_entities(const Td *td, } case secret_api::messageEntityCustomEmoji::ID: { auto entity = static_cast(secret_entity.get()); - if (is_premium || !td->stickers_manager_->is_premium_custom_emoji(entity->document_id_)) { + if (is_premium || !td->stickers_manager_->is_premium_custom_emoji(entity->document_id_, false)) { entities.emplace_back(MessageEntity::Type::CustomEmoji, entity->offset_, entity->length_, entity->document_id_); } @@ -4406,6 +4406,13 @@ vector> get_input_message_entities(co return {}; } +void remove_premium_custom_emoji_entities(const Td *td, vector &entities, bool remove_unknown) { + td::remove_if(entities, [&](const MessageEntity &entity) { + return entity.type == MessageEntity::Type::CustomEmoji && + td->stickers_manager_->is_premium_custom_emoji(entity.document_id, remove_unknown); + }); +} + void remove_unallowed_entities(const Td *td, FormattedText &text, DialogId dialog_id) { if (text.entities.empty()) { return; @@ -4432,11 +4439,7 @@ void remove_unallowed_entities(const Td *td, FormattedText &text, DialogId dialo } } 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); - }); + remove_premium_custom_emoji_entities(td, text.entities, false); } } diff --git a/td/telegram/MessageEntity.h b/td/telegram/MessageEntity.h index 263d699e4..01ddc6d42 100644 --- a/td/telegram/MessageEntity.h +++ b/td/telegram/MessageEntity.h @@ -151,6 +151,8 @@ 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_premium_custom_emoji_entities(const Td *td, vector &entities, bool remove_unknown); + 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); diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index c3e519e08..74e0eef59 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1692,16 +1692,15 @@ StickerType StickersManager::get_sticker_type(FileId file_id) const { return sticker->type; } -bool StickersManager::is_premium_custom_emoji(int64 custom_emoji_id) const { +bool StickersManager::is_premium_custom_emoji(int64 custom_emoji_id, bool default_result) const { auto it = custom_emoji_to_sticker_id_.find(custom_emoji_id); if (it == custom_emoji_to_sticker_id_.end()) { - // pretend that the unknown custom emoji isn't a premium - return false; + return default_result; } const Sticker *s = get_sticker(it->second); if (s == nullptr) { LOG(ERROR) << "Failed to find custom emoji sticker " << it->second; - return false; + return default_result; } return s->is_premium; } diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index b19521dee..0e8321baf 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -61,7 +61,7 @@ class StickersManager final : public Actor { StickerType get_sticker_type(FileId file_id) const; - bool is_premium_custom_emoji(int64 custom_emoji_id) const; + bool is_premium_custom_emoji(int64 custom_emoji_id, bool default_result) const; tl_object_ptr get_sticker_object(FileId file_id, bool for_animated_emoji = false, bool for_clicked_animated_emoji = false) const;