Move some classes inside corresponding managers.

This commit is contained in:
levlam 2021-06-18 03:06:20 +03:00
parent ed7a7e5eaf
commit 9440925711
9 changed files with 52 additions and 53 deletions

View File

@ -280,7 +280,7 @@ function split_file($file, $chunks, $undo) {
'auth_manager[_(-][^.]|AuthManager' => 'AuthManager',
'background_manager[_(-][^.]|BackgroundManager' => "BackgroundManager",
'ConfigShared|shared_config[(]' => 'ConfigShared',
'contacts_manager[_(-][^.]|ContactsManager([^ ;.]| [^*])|BotData|ChannelType|CheckDialogUsernameResult|CanTransferOwnershipResult' => 'ContactsManager',
'contacts_manager[_(-][^.]|ContactsManager([^ ;.]| [^*])' => 'ContactsManager',
'country_info_manager[_(-][^.]|CountryInfoManager' => 'CountryInfoManager',
'documents_manager[_(-][^.]|DocumentsManager' => "DocumentsManager",
'file_reference_manager[_(-][^.]|FileReferenceManager|file_references[)]' => 'FileReferenceManager',
@ -300,7 +300,7 @@ function split_file($file, $chunks, $undo) {
'PublicDialogType|get_public_dialog_type' => 'PublicDialogType',
'SecretChatActor' => 'SecretChatActor',
'secret_chats_manager[_(-][^.]|SecretChatsManager' => 'SecretChatsManager',
'stickers_manager[_(-][^.]|StickersManager|CheckStickerSetNameResult' => 'StickersManager',
'stickers_manager[_(-][^.]|StickersManager' => 'StickersManager',
'[>](td_db[(][)]|get_td_db_impl[(])|TdDb[^A-Za-z]' => 'TdDb',
'TopDialogCategory|get_top_dialog_category' => 'TopDialogCategory',
'top_dialog_manager[_(-][^.]|TopDialogManager' => 'TopDialogManager',

View File

@ -13591,7 +13591,7 @@ bool ContactsManager::is_user_bot(UserId user_id) const {
return u != nullptr && !u->is_deleted && u->is_bot;
}
Result<BotData> ContactsManager::get_bot_data(UserId user_id) const {
Result<ContactsManager::BotData> ContactsManager::get_bot_data(UserId user_id) const {
auto p = users_.find(user_id);
if (p == users_.end()) {
return Status::Error(5, "Bot not found");
@ -14229,7 +14229,7 @@ bool ContactsManager::is_channel_public(const Channel *c) {
return c != nullptr && (!c->username.empty() || c->has_location);
}
ChannelType ContactsManager::get_channel_type(ChannelId channel_id) const {
ContactsManager::ChannelType ContactsManager::get_channel_type(ChannelId channel_id) const {
auto c = get_channel(channel_id);
if (c == nullptr) {
return ChannelType::Unknown;
@ -14237,7 +14237,7 @@ ChannelType ContactsManager::get_channel_type(ChannelId channel_id) const {
return get_channel_type(c);
}
ChannelType ContactsManager::get_channel_type(const Channel *c) {
ContactsManager::ChannelType ContactsManager::get_channel_type(const Channel *c) {
if (c->is_megagroup) {
return ChannelType::Megagroup;
}

View File

@ -55,29 +55,8 @@ namespace td {
struct BinlogEvent;
class DialogInviteLink;
class DialogLocation;
class Td;
struct BotData {
string username;
bool can_join_groups;
bool can_read_all_group_messages;
bool is_inline;
bool need_location;
};
enum class ChannelType : uint8 { Broadcast, Megagroup, Unknown };
enum class CheckDialogUsernameResult : uint8 { Ok, Invalid, Occupied, PublicDialogsTooMuch, PublicGroupsUnavailable };
struct CanTransferOwnershipResult {
enum class Type : uint8 { Ok, PasswordNeeded, PasswordTooFresh, SessionTooFresh };
Type type = Type::Ok;
int32 retry_after = 0;
};
class ContactsManager : public Actor {
public:
ContactsManager(Td *td, ActorShared<> parent);
@ -284,6 +263,8 @@ class ContactsManager : public Actor {
void invalidate_user_full(UserId user_id);
enum class CheckDialogUsernameResult : uint8 { Ok, Invalid, Occupied, PublicDialogsTooMuch, PublicGroupsUnavailable };
void check_dialog_username(DialogId dialog_id, const string &username, Promise<CheckDialogUsernameResult> &&promise);
static td_api::object_ptr<td_api::CheckChatUsernameResult> get_check_chat_username_result_object(
@ -387,6 +368,11 @@ class ContactsManager : public Actor {
void load_statistics_graph(DialogId dialog_id, const string &token, int64 x,
Promise<td_api::object_ptr<td_api::StatisticalGraph>> &&promise);
struct CanTransferOwnershipResult {
enum class Type : uint8 { Ok, PasswordNeeded, PasswordTooFresh, SessionTooFresh };
Type type = Type::Ok;
int32 retry_after = 0;
};
void can_transfer_ownership(Promise<CanTransferOwnershipResult> &&promise);
static td_api::object_ptr<td_api::CanTransferOwnershipResult> get_can_transfer_ownership_result_object(
@ -444,6 +430,14 @@ class ContactsManager : public Actor {
bool is_user_support(UserId user_id) const;
bool is_user_bot(UserId user_id) const;
struct BotData {
string username;
bool can_join_groups;
bool can_read_all_group_messages;
bool is_inline;
bool need_location;
};
Result<BotData> get_bot_data(UserId user_id) const TD_WARN_UNUSED_RESULT;
bool is_user_online(UserId user_id, int32 tolerance = 0) const;
@ -502,6 +496,8 @@ class ContactsManager : public Actor {
bool get_secret_chat(SecretChatId secret_chat_id, bool force, Promise<Unit> &&promise);
bool get_secret_chat_full(SecretChatId secret_chat_id, Promise<Unit> &&promise);
enum class ChannelType : uint8 { Broadcast, Megagroup, Unknown };
ChannelType get_channel_type(ChannelId channel_id) const;
int32 get_channel_date(ChannelId channel_id) const;
DialogParticipantStatus get_channel_status(ChannelId channel_id) const;

View File

@ -1264,7 +1264,8 @@ void InlineQueriesManager::on_get_inline_query_results(DialogId dialog_id, UserI
break;
}
if (dialog_type == DialogType::Channel &&
td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) == ChannelType::Broadcast) {
td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) ==
ContactsManager::ChannelType::Broadcast) {
continue;
}
if (dialog_type == DialogType::SecretChat) {

View File

@ -2484,8 +2484,8 @@ Status can_send_message_content(DialogId dialog_id, const MessageContent *conten
}
break;
case MessageContentType::Game:
if (dialog_type == DialogType::Channel &&
td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) == ChannelType::Broadcast) {
if (dialog_type == DialogType::Channel && td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) ==
ContactsManager::ChannelType::Broadcast) {
// return Status::Error(400, "Games can't be sent to channel chats");
}
if (dialog_type == DialogType::SecretChat) {
@ -2523,7 +2523,8 @@ Status can_send_message_content(DialogId dialog_id, const MessageContent *conten
return Status::Error(400, "Not enough rights to send polls to the chat");
}
if (dialog_type == DialogType::Channel &&
td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) == ChannelType::Broadcast &&
td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) ==
ContactsManager::ChannelType::Broadcast &&
!td->poll_manager_->get_poll_is_anonymous(static_cast<const MessagePoll *>(content)->poll_id)) {
return Status::Error(400, "Non-anonymous polls can't be sent to channel chats");
}

View File

@ -2152,7 +2152,8 @@ class SearchMessagesQuery : public Td::ResultHandler {
} else if (top_thread_message_id.is_valid() && query.empty() && !sender_dialog_id.is_valid() &&
filter == MessageSearchFilter::Empty) {
handle_errors_ = dialog_id.get_type() != DialogType::Channel ||
td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) != ChannelType::Broadcast;
td->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) !=
ContactsManager::ChannelType::Broadcast;
send_query(G()->net_query_creator().create(telegram_api::messages_getReplies(
std::move(input_peer), top_thread_message_id.get_server_message_id().get(),
from_message_id.get_server_message_id().get(), 0, offset, limit, std::numeric_limits<int32>::max(), 0, 0)));
@ -10731,7 +10732,7 @@ void MessagesManager::delete_dialog_messages_from_user(DialogId dialog_id, UserI
case DialogType::Channel: {
channel_id = dialog_id.get_channel_id();
auto channel_type = td_->contacts_manager_->get_channel_type(channel_id);
if (channel_type != ChannelType::Megagroup) {
if (channel_type != ContactsManager::ChannelType::Megagroup) {
return promise.set_error(Status::Error(3, "The method is available only for supergroup chats"));
}
channel_status = td_->contacts_manager_->get_channel_permissions(channel_id);
@ -19589,7 +19590,7 @@ td_api::object_ptr<td_api::ChatType> MessagesManager::get_chat_type_object(Dialo
auto channel_type = td_->contacts_manager_->get_channel_type(channel_id);
return td_api::make_object<td_api::chatTypeSupergroup>(
td_->contacts_manager_->get_supergroup_id_object(channel_id, "chatTypeSupergroup"),
channel_type != ChannelType::Megagroup);
channel_type != ContactsManager::ChannelType::Megagroup);
}
case DialogType::SecretChat: {
auto secret_chat_id = dialog_id.get_secret_chat_id();
@ -22819,13 +22820,13 @@ Status MessagesManager::can_send_message(DialogId dialog_id) const {
auto channel_status = td_->contacts_manager_->get_channel_permissions(channel_id);
switch (channel_type) {
case ChannelType::Unknown:
case ChannelType::Megagroup:
case ContactsManager::ChannelType::Unknown:
case ContactsManager::ChannelType::Megagroup:
if (!channel_status.can_send_messages()) {
return Status::Error(400, "Have no rights to send a message");
}
break;
case ChannelType::Broadcast: {
case ContactsManager::ChannelType::Broadcast: {
if (!channel_status.can_post_messages()) {
return Status::Error(400, "Need administrator rights in the channel chat");
}
@ -23988,14 +23989,14 @@ Result<MessageId> MessagesManager::send_bot_start_message(UserId bot_user_id, Di
return Status::Error(3, "Can't access the chat");
}
switch (td_->contacts_manager_->get_channel_type(channel_id)) {
case ChannelType::Megagroup:
case ContactsManager::ChannelType::Megagroup:
if (!bot_data.can_join_groups) {
return Status::Error(5, "The bot can't join groups");
}
break;
case ChannelType::Broadcast:
case ContactsManager::ChannelType::Broadcast:
return Status::Error(3, "Bots can't be invited to channel chats. Add them as administrators instead");
case ChannelType::Unknown:
case ContactsManager::ChannelType::Unknown:
default:
UNREACHABLE();
}
@ -24443,7 +24444,8 @@ bool MessagesManager::is_broadcast_channel(DialogId dialog_id) const {
return false;
}
return td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) == ChannelType::Broadcast;
return td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id()) ==
ContactsManager::ChannelType::Broadcast;
}
bool MessagesManager::is_deleted_secret_chat(const Dialog *d) const {
@ -33479,7 +33481,7 @@ MessagesManager::Dialog *MessagesManager::add_new_dialog(unique_ptr<Dialog> &&d,
break;
case DialogType::Channel: {
auto channel_type = td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id());
if (channel_type == ChannelType::Broadcast) {
if (channel_type == ContactsManager::ChannelType::Broadcast) {
d->last_read_outbox_message_id = MessageId::max();
d->is_last_read_outbox_message_id_inited = true;
}
@ -35731,13 +35733,13 @@ void MessagesManager::update_top_dialogs(DialogId dialog_id, const Message *m) {
break;
case DialogType::Channel:
switch (td_->contacts_manager_->get_channel_type(dialog_id.get_channel_id())) {
case ChannelType::Broadcast:
case ContactsManager::ChannelType::Broadcast:
category = TopDialogCategory::Channel;
break;
case ChannelType::Megagroup:
case ContactsManager::ChannelType::Megagroup:
category = TopDialogCategory::Group;
break;
case ChannelType::Unknown:
case ContactsManager::ChannelType::Unknown:
break;
default:
UNREACHABLE();

View File

@ -162,7 +162,7 @@ void PrivacyManager::UserPrivacySettingRule::set_chat_ids(const vector<int64> &d
break;
case DialogType::Channel: {
auto channel_id = dialog_id.get_channel_id();
if (td->contacts_manager_->get_channel_type(channel_id) != ChannelType::Megagroup) {
if (td->contacts_manager_->get_channel_type(channel_id) != ContactsManager::ChannelType::Megagroup) {
LOG(ERROR) << "Ignore broadcast " << channel_id;
break;
}

View File

@ -38,8 +38,6 @@ namespace td {
class Td;
enum class CheckStickerSetNameResult : uint8 { Ok, Invalid, Occupied };
class StickersManager : public Actor {
public:
static constexpr int64 GREAT_MINDS_SET_ID = 1842540969984001;
@ -169,6 +167,7 @@ class StickersManager : public Actor {
void get_suggested_sticker_set_name(string short_name, Promise<string> &&promise);
enum class CheckStickerSetNameResult : uint8 { Ok, Invalid, Occupied };
void check_sticker_set_name(const string &name, Promise<CheckStickerSetNameResult> &&promise);
static td_api::object_ptr<td_api::CheckStickerSetNameResult> get_check_sticker_set_name_result_object(

View File

@ -5410,8 +5410,8 @@ void Td::on_request(uint64 id, td_api::checkChatUsername &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.username_);
CREATE_REQUEST_PROMISE();
auto query_promise =
PromiseCreator::lambda([promise = std::move(promise)](Result<CheckDialogUsernameResult> result) mutable {
auto query_promise = PromiseCreator::lambda(
[promise = std::move(promise)](Result<ContactsManager::CheckDialogUsernameResult> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
@ -6439,8 +6439,8 @@ void Td::on_request(uint64 id, const td_api::banChatMember &request) {
void Td::on_request(uint64 id, const td_api::canTransferOwnership &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
auto query_promise =
PromiseCreator::lambda([promise = std::move(promise)](Result<CanTransferOwnershipResult> result) mutable {
auto query_promise = PromiseCreator::lambda(
[promise = std::move(promise)](Result<ContactsManager::CanTransferOwnershipResult> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
@ -7047,8 +7047,8 @@ void Td::on_request(uint64 id, td_api::getSuggestedStickerSetName &request) {
void Td::on_request(uint64 id, td_api::checkStickerSetName &request) {
CLEAN_INPUT_STRING(request.name_);
CREATE_REQUEST_PROMISE();
auto query_promise =
PromiseCreator::lambda([promise = std::move(promise)](Result<CheckStickerSetNameResult> result) mutable {
auto query_promise = PromiseCreator::lambda(
[promise = std::move(promise)](Result<StickersManager::CheckStickerSetNameResult> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {