From e556ed04a05f05c3584f89fcd4904604b6cd3f16 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 17 Oct 2023 01:25:58 +0300 Subject: [PATCH] Add ContactsManager::can_use_premium_custom_emoji. --- td/telegram/ContactsManager.cpp | 11 +++++++++++ td/telegram/ContactsManager.h | 2 ++ td/telegram/MessageEntity.cpp | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index d4b96640c..bb740aeb0 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -5931,6 +5931,17 @@ FolderId ContactsManager::get_secret_chat_initial_folder_id(SecretChatId secret_ return c->initial_folder_id; } +bool ContactsManager::can_use_premium_custom_emoji() const { + if (td_->option_manager_->get_option_boolean("is_premium")) { + return true; + } + if (!td_->auth_manager_->is_bot()) { + return false; + } + const User *u = get_user(get_my_id()); + return u == nullptr || u->usernames.get_active_usernames().size() > (u->usernames.has_editable_username() ? 1u : 0u); +} + UserId ContactsManager::get_my_id() const { LOG_IF(ERROR, !my_id_.is_valid()) << "Wrong or unknown my ID returned"; return my_id_; diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 467f70f15..ad44ec97e 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -290,6 +290,8 @@ class ContactsManager final : public Actor { void unregister_message_channels(MessageFullId message_full_id, vector channel_ids); + bool can_use_premium_custom_emoji() const; + UserId get_my_id() const; void set_my_online_status(bool is_online, bool send_update, bool is_local); diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index 15e5009d1..f78ec477d 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -4531,8 +4531,8 @@ void remove_unallowed_entities(const Td *td, FormattedText &text, DialogId dialo remove_intersecting_entities(text.entities); } } - if (!td->option_manager_->get_option_boolean("is_premium") && - dialog_id != DialogId(td->contacts_manager_->get_my_id())) { + if (dialog_id != DialogId(td->contacts_manager_->get_my_id()) && + !td->contacts_manager_->can_use_premium_custom_emoji()) { remove_premium_custom_emoji_entities(td, text.entities, false); } }