Move can_use_premium_custom_emoji to DialogManager.

This commit is contained in:
levlam 2024-03-10 03:15:01 +03:00
parent 919a1d8329
commit 1fba0f0c84
5 changed files with 39 additions and 24 deletions

View File

@ -5078,6 +5078,14 @@ bool ContactsManager::can_poll_channel_active_stories(ChannelId channel_id) cons
return need_poll_channel_active_stories(c, channel_id) && Time::now() >= c->max_active_story_id_next_reload_time;
}
bool ContactsManager::can_use_premium_custom_emoji_in_channel(ChannelId channel_id) const {
if (!is_megagroup_channel(channel_id)) {
return false;
}
auto channel_full = get_channel_full_const(channel_id);
return channel_full == nullptr || channel_full->emoji_sticker_set_id.is_valid();
}
string ContactsManager::get_user_private_forward_name(UserId user_id) {
auto user_full = get_user_full_force(user_id, "get_user_private_forward_name");
if (user_full != nullptr) {
@ -5202,6 +5210,14 @@ string ContactsManager::get_channel_editable_username(ChannelId channel_id) cons
return c->usernames.get_editable_username();
}
bool ContactsManager::has_user_fragment_username(UserId user_id) const {
auto u = get_user(user_id);
if (u == nullptr) {
return false;
}
return u->usernames.get_active_usernames().size() > (u->usernames.has_editable_username() ? 1u : 0u);
}
UserId ContactsManager::get_secret_chat_user_id(SecretChatId secret_chat_id) const {
auto c = get_secret_chat(secret_chat_id);
if (c == nullptr) {
@ -5242,26 +5258,6 @@ FolderId ContactsManager::get_secret_chat_initial_folder_id(SecretChatId secret_
return c->initial_folder_id;
}
bool ContactsManager::can_use_premium_custom_emoji(DialogId dialog_id) const {
if (td_->option_manager_->get_option_boolean("is_premium")) {
return true;
}
if (dialog_id.get_type() == DialogType::Channel) {
auto channel_id = dialog_id.get_channel_id();
if (!td_->auth_manager_->is_bot() && is_megagroup_channel(channel_id)) {
auto channel_full = get_channel_full_const(channel_id);
if (channel_full == nullptr || channel_full->emoji_sticker_set_id.is_valid()) {
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_;

View File

@ -172,6 +172,8 @@ class ContactsManager final : public Actor {
bool can_poll_user_active_stories(UserId user_id) const;
bool can_poll_channel_active_stories(ChannelId channel_id) const;
bool can_use_premium_custom_emoji_in_channel(ChannelId channel_id) const;
string get_user_private_forward_name(UserId user_id);
bool get_user_voice_messages_forbidden(UserId user_id) const;
@ -188,6 +190,8 @@ class ContactsManager final : public Actor {
string get_channel_first_username(ChannelId channel_id) const;
string get_channel_editable_username(ChannelId channel_id) const;
bool has_user_fragment_username(UserId user_id) const;
int32 get_secret_chat_date(SecretChatId secret_chat_id) const;
int32 get_secret_chat_ttl(SecretChatId secret_chat_id) const;
UserId get_secret_chat_user_id(SecretChatId secret_chat_id) const;
@ -333,8 +337,6 @@ class ContactsManager final : public Actor {
void unregister_message_channels(MessageFullId message_full_id, vector<ChannelId> channel_ids);
bool can_use_premium_custom_emoji(DialogId dialog_id) const;
UserId get_my_id() const;
void set_my_online_status(bool is_online, bool send_update, bool is_local);

View File

@ -17,6 +17,7 @@
#include "td/telegram/Global.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/misc.h"
#include "td/telegram/OptionManager.h"
#include "td/telegram/ReportReason.h"
#include "td/telegram/SecretChatId.h"
#include "td/telegram/SecretChatsManager.h"
@ -1772,6 +1773,21 @@ Status DialogManager::can_pin_messages(DialogId dialog_id) const {
return Status::OK();
}
bool DialogManager::can_use_premium_custom_emoji_in_dialog(DialogId dialog_id) const {
if (!td_->auth_manager_->is_bot()) {
if (dialog_id == get_my_dialog_id() || td_->option_manager_->get_option_boolean("is_premium")) {
return true;
}
if (dialog_id.get_type() == DialogType::Channel &&
td_->contacts_manager_->can_use_premium_custom_emoji_in_channel(dialog_id.get_channel_id())) {
return true;
}
return false;
}
auto user_id = td_->contacts_manager_->get_my_id();
return !td_->contacts_manager_->have_user(user_id) || td_->contacts_manager_->has_user_fragment_username(user_id);
}
bool DialogManager::is_dialog_removed_from_dialog_list(DialogId dialog_id) const {
switch (dialog_id.get_type()) {
case DialogType::User:

View File

@ -174,6 +174,8 @@ class DialogManager final : public Actor {
Status can_pin_messages(DialogId dialog_id) const;
bool can_use_premium_custom_emoji_in_dialog(DialogId dialog_id) const;
bool is_dialog_removed_from_dialog_list(DialogId dialog_id) const;
void upload_dialog_photo(DialogId dialog_id, FileId file_id, bool is_animation, double main_frame_timestamp,

View File

@ -4731,8 +4731,7 @@ void remove_unallowed_entities(const Td *td, FormattedText &text, DialogId dialo
remove_intersecting_entities(text.entities);
}
}
if (dialog_id != td->dialog_manager_->get_my_dialog_id() &&
!td->contacts_manager_->can_use_premium_custom_emoji(dialog_id)) {
if (!td->dialog_manager_->can_use_premium_custom_emoji_in_dialog(dialog_id)) {
remove_premium_custom_emoji_entities(td, text.entities, false);
}
}