diff --git a/SplitSource.php b/SplitSource.php index d6fde5171..6a2f24f22 100644 --- a/SplitSource.php +++ b/SplitSource.php @@ -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', diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 25ac7d954..bf3725eaa 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -13591,7 +13591,7 @@ bool ContactsManager::is_user_bot(UserId user_id) const { return u != nullptr && !u->is_deleted && u->is_bot; } -Result ContactsManager::get_bot_data(UserId user_id) const { +Result 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; } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 1bac89767..d2e77a738 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -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 &&promise); static td_api::object_ptr 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> &&promise); + struct CanTransferOwnershipResult { + enum class Type : uint8 { Ok, PasswordNeeded, PasswordTooFresh, SessionTooFresh }; + Type type = Type::Ok; + int32 retry_after = 0; + }; void can_transfer_ownership(Promise &&promise); static td_api::object_ptr 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 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 &&promise); bool get_secret_chat_full(SecretChatId secret_chat_id, Promise &&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; diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 6cfc8b399..5f3ebeb95 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -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) { diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 31c6eb458..7e6fb934d 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -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(content)->poll_id)) { return Status::Error(400, "Non-anonymous polls can't be sent to channel chats"); } diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 4d5cf1b81..42617b6b9 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -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::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 MessagesManager::get_chat_type_object(Dialo auto channel_type = td_->contacts_manager_->get_channel_type(channel_id); return td_api::make_object( 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 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 &&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(); diff --git a/td/telegram/PrivacyManager.cpp b/td/telegram/PrivacyManager.cpp index 7f9618b9e..e7f255594 100644 --- a/td/telegram/PrivacyManager.cpp +++ b/td/telegram/PrivacyManager.cpp @@ -162,7 +162,7 @@ void PrivacyManager::UserPrivacySettingRule::set_chat_ids(const vector &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; } diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index ae3a78736..cf5de7ebe 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -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 &&promise); + enum class CheckStickerSetNameResult : uint8 { Ok, Invalid, Occupied }; void check_sticker_set_name(const string &name, Promise &&promise); static td_api::object_ptr get_check_sticker_set_name_result_object( diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 99e40620a..56bbcf6d0 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -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 result) mutable { + auto query_promise = PromiseCreator::lambda( + [promise = std::move(promise)](Result 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 result) mutable { + auto query_promise = PromiseCreator::lambda( + [promise = std::move(promise)](Result 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 result) mutable { + auto query_promise = PromiseCreator::lambda( + [promise = std::move(promise)](Result result) mutable { if (result.is_error()) { promise.set_error(result.move_as_error()); } else {