diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 2cbcf336a..f61c2420f 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -832,9 +832,11 @@ basicGroup id:int53 member_count:int32 status:ChatMemberStatus is_active:Bool up //@param_description Group description. Updated only after the basic group is opened //@creator_user_id User identifier of the creator of the group; 0 if unknown //@members Group members +//@can_hide_members True, if non-administrators and non-bots can be hidden in responses to getSupergroupMembers and searchChatMembers for non-administrators after upgrading the basic group to a supergroup +//@can_toggle_aggressive_anti_spam True, if aggressive anti-spam checks can be enabled or disabled in the supergroup after upgrading the basic group to a supergroup //@invite_link Primary invite link for this group; may be null. For chat administrators with can_invite_users right only. Updated only after the basic group is opened //@bot_commands List of commands of bots in the group -basicGroupFullInfo photo:chatPhoto description:string creator_user_id:int53 members:vector invite_link:chatInviteLink bot_commands:vector = BasicGroupFullInfo; +basicGroupFullInfo photo:chatPhoto description:string creator_user_id:int53 members:vector can_hide_members:Bool can_toggle_aggressive_anti_spam:Bool invite_link:chatInviteLink bot_commands:vector = BasicGroupFullInfo; //@description Represents a supergroup or channel with zero or more members (subscribers in the case of channels). From the point of view of the system, a channel is a special kind of a supergroup: diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index b34646930..dd8ddc6c9 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -7475,6 +7475,20 @@ void ContactsManager::toggle_channel_is_all_history_available(ChannelId channel_ td_->create_handler(std::move(promise))->send(channel_id, is_all_history_available); } +Status ContactsManager::can_hide_chat_participants(ChatId chat_id) const { + auto c = get_chat(chat_id); + if (c == nullptr) { + return Status::Error(400, "Basic group not found"); + } + if (!get_chat_permissions(c).is_creator()) { + return Status::Error(400, "Not enough rights to hide group members"); + } + if (c->participant_count < td_->option_manager_->get_option_integer("hidden_members_group_size_min")) { + return Status::Error(400, "The basic group is too small"); + } + return Status::OK(); +} + Status ContactsManager::can_hide_channel_participants(ChannelId channel_id, const ChannelFull *channel_full) const { auto c = get_channel(channel_id); if (c == nullptr) { @@ -7493,7 +7507,21 @@ Status ContactsManager::can_hide_channel_participants(ChannelId channel_id, cons c->participant_count < td_->option_manager_->get_option_integer("hidden_members_group_size_min")) { return Status::Error(400, "The supergroup is too small"); } + return Status::OK(); +} +Status ContactsManager::can_toggle_chat_aggressive_anti_spam(ChatId chat_id) const { + auto c = get_chat(chat_id); + if (c == nullptr) { + return Status::Error(400, "Basic group not found"); + } + if (!get_chat_permissions(c).is_creator()) { + return Status::Error(400, "Not enough rights to enable aggressive anti-spam checks"); + } + if (c->participant_count < + td_->option_manager_->get_option_integer("aggressive_anti_spam_supergroup_member_count_min")) { + return Status::Error(400, "The basic group is too small"); + } return Status::OK(); } @@ -7522,7 +7550,6 @@ Status ContactsManager::can_toggle_channel_aggressive_anti_spam(ChannelId channe "aggressive_anti_spam_supergroup_member_count_min")) { return Status::Error(400, "The supergroup is too small"); } - return Status::OK(); } @@ -11666,7 +11693,7 @@ void ContactsManager::update_chat_full(ChatFull *chat_full, ChatId chat_id, cons send_closure( G()->td(), &Td::send_update, make_tl_object(get_basic_group_id_object(chat_id, "update_chat_full"), - get_basic_group_full_info_object(chat_full))); + get_basic_group_full_info_object(chat_id, chat_full))); chat_full->need_send_update = false; } if (chat_full->need_save_to_database) { @@ -18011,20 +18038,22 @@ tl_object_ptr ContactsManager::get_basic_group_object_const( } tl_object_ptr ContactsManager::get_basic_group_full_info_object(ChatId chat_id) const { - return get_basic_group_full_info_object(get_chat_full(chat_id)); + return get_basic_group_full_info_object(chat_id, get_chat_full(chat_id)); } tl_object_ptr ContactsManager::get_basic_group_full_info_object( - const ChatFull *chat_full) const { + ChatId chat_id, const ChatFull *chat_full) const { CHECK(chat_full != nullptr); auto bot_commands = transform(chat_full->bot_commands, [td = td_](const BotCommands &commands) { return commands.get_bot_commands_object(td); }); + auto members = transform(chat_full->participants, [this](const DialogParticipant &chat_participant) { + return get_chat_member_object(chat_participant); + }); return make_tl_object( get_chat_photo_object(td_->file_manager_.get(), chat_full->photo), chat_full->description, - get_user_id_object(chat_full->creator_user_id, "basicGroupFullInfo"), - transform(chat_full->participants, - [this](const DialogParticipant &chat_participant) { return get_chat_member_object(chat_participant); }), + get_user_id_object(chat_full->creator_user_id, "basicGroupFullInfo"), std::move(members), + can_hide_chat_participants(chat_id).is_ok(), can_toggle_chat_aggressive_anti_spam(chat_id).is_ok(), chat_full->invite_link.get_chat_invite_link_object(this), std::move(bot_commands)); } @@ -18323,7 +18352,7 @@ void ContactsManager::get_current_state(vector &chat_full) { updates.push_back(td_api::make_object( - chat_id.get(), get_basic_group_full_info_object(chat_full.get()))); + chat_id.get(), get_basic_group_full_info_object(chat_id, chat_full.get()))); }); } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 8354fddd1..26c0d8bd8 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1674,14 +1674,19 @@ class ContactsManager final : public Actor { tl_object_ptr get_basic_group_object_const(ChatId chat_id, const Chat *c) const; - tl_object_ptr get_basic_group_full_info_object(const ChatFull *chat_full) const; + tl_object_ptr get_basic_group_full_info_object(ChatId chat_id, + const ChatFull *chat_full) const; td_api::object_ptr get_update_unknown_supergroup_object(ChannelId channel_id) const; static tl_object_ptr get_supergroup_object(ChannelId channel_id, const Channel *c); + Status can_hide_chat_participants(ChatId chat_id) const; + Status can_hide_channel_participants(ChannelId channel_id, const ChannelFull *channel_full) const; + Status can_toggle_chat_aggressive_anti_spam(ChatId chat_id) const; + Status can_toggle_channel_aggressive_anti_spam(ChannelId channel_id, const ChannelFull *channel_full) const; tl_object_ptr get_supergroup_full_info_object(ChannelId channel_id,