Add remove_premium_custom_emoji_entities.

This commit is contained in:
levlam 2022-07-27 23:36:44 +03:00
parent e601012e9f
commit 36c6b84ec8
4 changed files with 15 additions and 11 deletions

View File

@ -3652,7 +3652,7 @@ vector<MessageEntity> get_message_entities(const Td *td,
}
case secret_api::messageEntityCustomEmoji::ID: {
auto entity = static_cast<const secret_api::messageEntityCustomEmoji *>(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<tl_object_ptr<telegram_api::MessageEntity>> get_input_message_entities(co
return {};
}
void remove_premium_custom_emoji_entities(const Td *td, vector<MessageEntity> &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);
}
}

View File

@ -151,6 +151,8 @@ vector<tl_object_ptr<td_api::textEntity>> get_text_entities_object(const vector<
td_api::object_ptr<td_api::formattedText> 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<MessageEntity> &entities, bool remove_unknown);
void remove_unallowed_entities(const Td *td, FormattedText &text, DialogId dialog_id);
vector<MessageEntity> find_entities(Slice text, bool skip_bot_commands, bool skip_media_timestamps);

View File

@ -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;
}

View File

@ -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<td_api::sticker> get_sticker_object(FileId file_id, bool for_animated_emoji = false,
bool for_clicked_animated_emoji = false) const;