Add new flags to basicGroupFullInfo.

This commit is contained in:
levlam 2022-12-20 11:17:51 +03:00
parent 983cb965cf
commit 0fe8023cdc
3 changed files with 46 additions and 10 deletions

View File

@ -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 //@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 //@creator_user_id User identifier of the creator of the group; 0 if unknown
//@members Group members //@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 //@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 //@bot_commands List of commands of bots in the group
basicGroupFullInfo photo:chatPhoto description:string creator_user_id:int53 members:vector<chatMember> invite_link:chatInviteLink bot_commands:vector<botCommands> = BasicGroupFullInfo; basicGroupFullInfo photo:chatPhoto description:string creator_user_id:int53 members:vector<chatMember> can_hide_members:Bool can_toggle_aggressive_anti_spam:Bool invite_link:chatInviteLink bot_commands:vector<botCommands> = 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: //@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:

View File

@ -7475,6 +7475,20 @@ void ContactsManager::toggle_channel_is_all_history_available(ChannelId channel_
td_->create_handler<TogglePrehistoryHiddenQuery>(std::move(promise))->send(channel_id, is_all_history_available); td_->create_handler<TogglePrehistoryHiddenQuery>(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 { Status ContactsManager::can_hide_channel_participants(ChannelId channel_id, const ChannelFull *channel_full) const {
auto c = get_channel(channel_id); auto c = get_channel(channel_id);
if (c == nullptr) { 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")) { 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::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(); return Status::OK();
} }
@ -7522,7 +7550,6 @@ Status ContactsManager::can_toggle_channel_aggressive_anti_spam(ChannelId channe
"aggressive_anti_spam_supergroup_member_count_min")) { "aggressive_anti_spam_supergroup_member_count_min")) {
return Status::Error(400, "The supergroup is too small"); return Status::Error(400, "The supergroup is too small");
} }
return Status::OK(); return Status::OK();
} }
@ -11666,7 +11693,7 @@ void ContactsManager::update_chat_full(ChatFull *chat_full, ChatId chat_id, cons
send_closure( send_closure(
G()->td(), &Td::send_update, G()->td(), &Td::send_update,
make_tl_object<td_api::updateBasicGroupFullInfo>(get_basic_group_id_object(chat_id, "update_chat_full"), make_tl_object<td_api::updateBasicGroupFullInfo>(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; chat_full->need_send_update = false;
} }
if (chat_full->need_save_to_database) { if (chat_full->need_save_to_database) {
@ -18011,20 +18038,22 @@ tl_object_ptr<td_api::basicGroup> ContactsManager::get_basic_group_object_const(
} }
tl_object_ptr<td_api::basicGroupFullInfo> ContactsManager::get_basic_group_full_info_object(ChatId chat_id) const { tl_object_ptr<td_api::basicGroupFullInfo> 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<td_api::basicGroupFullInfo> ContactsManager::get_basic_group_full_info_object( tl_object_ptr<td_api::basicGroupFullInfo> ContactsManager::get_basic_group_full_info_object(
const ChatFull *chat_full) const { ChatId chat_id, const ChatFull *chat_full) const {
CHECK(chat_full != nullptr); CHECK(chat_full != nullptr);
auto bot_commands = transform(chat_full->bot_commands, [td = td_](const BotCommands &commands) { auto bot_commands = transform(chat_full->bot_commands, [td = td_](const BotCommands &commands) {
return commands.get_bot_commands_object(td); 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<td_api::basicGroupFullInfo>( return make_tl_object<td_api::basicGroupFullInfo>(
get_chat_photo_object(td_->file_manager_.get(), chat_full->photo), chat_full->description, get_chat_photo_object(td_->file_manager_.get(), chat_full->photo), chat_full->description,
get_user_id_object(chat_full->creator_user_id, "basicGroupFullInfo"), get_user_id_object(chat_full->creator_user_id, "basicGroupFullInfo"), std::move(members),
transform(chat_full->participants, can_hide_chat_participants(chat_id).is_ok(), can_toggle_chat_aggressive_anti_spam(chat_id).is_ok(),
[this](const DialogParticipant &chat_participant) { return get_chat_member_object(chat_participant); }),
chat_full->invite_link.get_chat_invite_link_object(this), std::move(bot_commands)); chat_full->invite_link.get_chat_invite_link_object(this), std::move(bot_commands));
} }
@ -18323,7 +18352,7 @@ void ContactsManager::get_current_state(vector<td_api::object_ptr<td_api::Update
}); });
chats_full_.foreach([&](const ChatId &chat_id, const unique_ptr<ChatFull> &chat_full) { chats_full_.foreach([&](const ChatId &chat_id, const unique_ptr<ChatFull> &chat_full) {
updates.push_back(td_api::make_object<td_api::updateBasicGroupFullInfo>( updates.push_back(td_api::make_object<td_api::updateBasicGroupFullInfo>(
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())));
}); });
} }

View File

@ -1674,14 +1674,19 @@ class ContactsManager final : public Actor {
tl_object_ptr<td_api::basicGroup> get_basic_group_object_const(ChatId chat_id, const Chat *c) const; tl_object_ptr<td_api::basicGroup> get_basic_group_object_const(ChatId chat_id, const Chat *c) const;
tl_object_ptr<td_api::basicGroupFullInfo> get_basic_group_full_info_object(const ChatFull *chat_full) const; tl_object_ptr<td_api::basicGroupFullInfo> get_basic_group_full_info_object(ChatId chat_id,
const ChatFull *chat_full) const;
td_api::object_ptr<td_api::updateSupergroup> get_update_unknown_supergroup_object(ChannelId channel_id) const; td_api::object_ptr<td_api::updateSupergroup> get_update_unknown_supergroup_object(ChannelId channel_id) const;
static tl_object_ptr<td_api::supergroup> get_supergroup_object(ChannelId channel_id, const Channel *c); static tl_object_ptr<td_api::supergroup> 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_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; Status can_toggle_channel_aggressive_anti_spam(ChannelId channel_id, const ChannelFull *channel_full) const;
tl_object_ptr<td_api::supergroupFullInfo> get_supergroup_full_info_object(ChannelId channel_id, tl_object_ptr<td_api::supergroupFullInfo> get_supergroup_full_info_object(ChannelId channel_id,