Add supergroupFullInfo.can_toggle_aggressive_anti_spam.

This commit is contained in:
levlam 2022-12-19 13:59:09 +03:00
parent 8a2598869c
commit f2d8575828
4 changed files with 43 additions and 21 deletions

View File

@ -876,6 +876,7 @@ supergroup id:int53 usernames:usernames date:int32 status:ChatMemberStatus membe
//@can_set_sticker_set True, if the supergroup sticker set can be changed
//@can_set_location True, if the supergroup location can be changed
//@can_get_statistics True, if the supergroup or channel statistics are available
//@can_toggle_aggressive_anti_spam True, if aggressive anti-spam checks can be enabled or disabled in the supergroup
//@is_all_history_available True, if new chat members will have access to old messages. In public, discussion, of forum groups and all channels, old messages are always available,
//-so this option affects only private non-forum supergroups without a linked chat. The value of this field is only available for chat administrators
//@is_aggressive_anti_spam_enabled True, if aggressive anti-spam checks are enabled in the supergroup. The value of this field is only available for chat administrators
@ -885,7 +886,7 @@ supergroup id:int53 usernames:usernames date:int32 status:ChatMemberStatus membe
//@bot_commands List of commands of bots in the group
//@upgraded_from_basic_group_id Identifier of the basic group from which supergroup was upgraded; 0 if none
//@upgraded_from_max_message_id Identifier of the last message in the basic group from which supergroup was upgraded; 0 if none
supergroupFullInfo photo:chatPhoto description:string member_count:int32 administrator_count:int32 restricted_count:int32 banned_count:int32 linked_chat_id:int53 slow_mode_delay:int32 slow_mode_delay_expires_in:double can_get_members:Bool can_set_username:Bool can_set_sticker_set:Bool can_set_location:Bool can_get_statistics:Bool is_all_history_available:Bool is_aggressive_anti_spam_enabled:Bool sticker_set_id:int64 location:chatLocation invite_link:chatInviteLink bot_commands:vector<botCommands> upgraded_from_basic_group_id:int53 upgraded_from_max_message_id:int53 = SupergroupFullInfo;
supergroupFullInfo photo:chatPhoto description:string member_count:int32 administrator_count:int32 restricted_count:int32 banned_count:int32 linked_chat_id:int53 slow_mode_delay:int32 slow_mode_delay_expires_in:double can_get_members:Bool can_set_username:Bool can_set_sticker_set:Bool can_set_location:Bool can_get_statistics:Bool can_toggle_aggressive_anti_spam:Bool is_all_history_available:Bool is_aggressive_anti_spam_enabled:Bool sticker_set_id:int64 location:chatLocation invite_link:chatInviteLink bot_commands:vector<botCommands> upgraded_from_basic_group_id:int53 upgraded_from_max_message_id:int53 = SupergroupFullInfo;
//@class SecretChatState @description Describes the current secret chat state
@ -7302,7 +7303,7 @@ toggleSupergroupJoinByRequest supergroup_id:int53 join_by_request:Bool = Ok;
//@description Toggles whether the message history of a supergroup is available to new members; requires can_change_info administrator right @supergroup_id The identifier of the supergroup @is_all_history_available The new value of is_all_history_available
toggleSupergroupIsAllHistoryAvailable supergroup_id:int53 is_all_history_available:Bool = Ok;
//@description Toggles whether aggressive anti-spam checks are enabled in the supergroup; requires can_delete_messages administrator right. Can be called only if the supergroup has at least getOption("aggressive_anti_spam_supergroup_member_count_min") members
//@description Toggles whether aggressive anti-spam checks are enabled in the supergroup. Can be called only if supergroupFullInfo.can_toggle_aggressive_anti_spam == true
//@supergroup_id The identifier of the supergroup, which isn't a broadcast group
//@is_aggressive_anti_spam_enabled The new value of is_aggressive_anti_spam_enabled
toggleSupergroupIsAggressiveAntiSpamEnabled supergroup_id:int53 is_aggressive_anti_spam_enabled:Bool = Ok;

View File

@ -7473,23 +7473,40 @@ void ContactsManager::toggle_channel_is_all_history_available(ChannelId channel_
td_->create_handler<TogglePrehistoryHiddenQuery>(std::move(promise))->send(channel_id, is_all_history_available);
}
Status ContactsManager::can_toggle_channel_aggressive_anti_spam(ChannelId channel_id,
const ChannelFull *channel_full) const {
auto c = get_channel(channel_id);
if (c == nullptr) {
return Status::Error(400, "Supergroup not found");
}
if (!get_channel_permissions(c).can_delete_messages()) {
return Status::Error(400, "Not enough rights to enable aggressive anti-spam checks");
}
if (get_channel_type(c) != ChannelType::Megagroup) {
return Status::Error(400, "Aggressive anti-spam checks can be enabled in supergroups only");
}
if (c->is_gigagroup) {
return Status::Error(400, "Aggressive anti-spam checks can't be enabled in broadcast supergroups");
}
if (channel_full != nullptr && channel_full->is_aggressive_anti_spam_enabled) {
return Status::OK();
}
if (c->has_location || begins_with(c->usernames.get_editable_username(), "translation_")) {
return Status::OK();
}
if (c->participant_count > 0 && c->participant_count < td_->option_manager_->get_option_integer(
"aggressive_anti_spam_supergroup_member_count_min")) {
return Status::Error(400, "The supergroup is too small");
}
return Status::OK();
}
void ContactsManager::toggle_channel_is_aggressive_anti_spam_enabled(ChannelId channel_id,
bool is_aggressive_anti_spam_enabled,
Promise<Unit> &&promise) {
auto c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(400, "Supergroup not found"));
}
if (!get_channel_permissions(c).can_delete_messages()) {
return promise.set_error(Status::Error(400, "Not enough rights to enable aggressive anti-spam checks"));
}
if (get_channel_type(c) != ChannelType::Megagroup) {
return promise.set_error(Status::Error(400, "Aggressive anti-spam checks can be enabled in supergroups only"));
}
if (c->is_gigagroup) {
return promise.set_error(
Status::Error(400, "Aggressive anti-spam checks can't be enabled in broadcast supergroups"));
}
auto channel_full = get_channel_full_force(channel_id, true, "toggle_channel_is_aggressive_anti_spam_enabled");
TRY_STATUS_PROMISE(promise, can_toggle_channel_aggressive_anti_spam(channel_id, channel_full));
td_->create_handler<ToggleAntiSpamQuery>(std::move(promise))->send(channel_id, is_aggressive_anti_spam_enabled);
}
@ -18026,9 +18043,10 @@ tl_object_ptr<td_api::supergroupFullInfo> ContactsManager::get_supergroup_full_i
channel_full->banned_count, DialogId(channel_full->linked_channel_id).get(), channel_full->slow_mode_delay,
slow_mode_delay_expires_in, channel_full->can_get_participants, channel_full->can_set_username,
channel_full->can_set_sticker_set, channel_full->can_set_location, channel_full->can_view_statistics,
channel_full->is_all_history_available, channel_full->is_aggressive_anti_spam_enabled,
channel_full->sticker_set_id.get(), channel_full->location.get_chat_location_object(),
channel_full->invite_link.get_chat_invite_link_object(this), std::move(bot_commands),
can_toggle_channel_aggressive_anti_spam(channel_id, channel_full).is_ok(), channel_full->is_all_history_available,
channel_full->is_aggressive_anti_spam_enabled, channel_full->sticker_set_id.get(),
channel_full->location.get_chat_location_object(), channel_full->invite_link.get_chat_invite_link_object(this),
std::move(bot_commands),
get_basic_group_id_object(channel_full->migrated_from_chat_id, "get_supergroup_full_info_object"),
channel_full->migrated_from_max_message_id.get());
}

View File

@ -1005,7 +1005,7 @@ class ContactsManager final : public Actor {
bool can_view_statistics = false;
bool is_can_view_statistics_inited = false;
bool is_all_history_available = true;
bool is_aggressive_anti_spam_enabled = true;
bool is_aggressive_anti_spam_enabled = false;
bool can_be_deleted = false;
bool is_slow_mode_next_send_date_changed = true;
@ -1677,6 +1677,8 @@ class ContactsManager final : public Actor {
static tl_object_ptr<td_api::supergroup> get_supergroup_object(ChannelId channel_id, const Channel *c);
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,
const ChannelFull *channel_full) const;

View File

@ -245,7 +245,8 @@ bool OptionManager::is_internal_option(Slice name) {
switch (name[0]) {
case 'a':
return name == "about_length_limit_default" || name == "about_length_limit_premium" ||
name == "animated_emoji_zoom" || name == "animation_search_emojis" || name == "animation_search_provider";
name == "aggressive_anti_spam_supergroup_member_count_min" || name == "animated_emoji_zoom" ||
name == "animation_search_emojis" || name == "animation_search_provider";
case 'b':
return name == "base_language_pack_version";
case 'c':