Improve banning of channels.

This commit is contained in:
levlam 2021-11-29 21:59:16 +03:00
parent c21796ec3a
commit b8d20ca6bb

View File

@ -6851,16 +6851,25 @@ void ContactsManager::set_channel_participant_status(ChannelId channel_id, Dialo
return promise.set_error(Status::Error(400, "Chat info not found")); return promise.set_error(Status::Error(400, "Chat info not found"));
} }
auto input_peer = td_->messages_manager_->get_input_peer(participant_dialog_id, AccessRights::Read);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(400, "Member not found"));
}
if (participant_dialog_id == DialogId(get_my_id())) { if (participant_dialog_id == DialogId(get_my_id())) {
// fast path is needed, because get_channel_status may return Creator, while GetChannelParticipantQuery returning Left // fast path is needed, because get_channel_status may return Creator, while GetChannelParticipantQuery returning Left
return set_channel_participant_status_impl(channel_id, participant_dialog_id, std::move(status), return set_channel_participant_status_impl(channel_id, participant_dialog_id, std::move(status),
get_channel_status(c), std::move(promise)); get_channel_status(c), std::move(promise));
} }
if (participant_dialog_id.get_type() != DialogType::User) {
if (status.is_administrator() || status.is_member() || status.is_restricted()) {
return promise.set_error(Status::Error(400, "Other chats can be only banned or unbanned"));
}
// always pretend that old_status is different
return restrict_channel_participant(
channel_id, participant_dialog_id, std::move(status),
status.is_banned() ? DialogParticipantStatus::Left() : DialogParticipantStatus::Banned(0), std::move(promise));
}
auto input_peer = td_->messages_manager_->get_input_peer(participant_dialog_id, AccessRights::Read);
if (input_peer == nullptr) {
return promise.set_error(Status::Error(400, "Member not found"));
}
auto on_result_promise = auto on_result_promise =
PromiseCreator::lambda([actor_id = actor_id(this), channel_id, participant_dialog_id, status, PromiseCreator::lambda([actor_id = actor_id(this), channel_id, participant_dialog_id, status,
@ -7507,7 +7516,7 @@ void ContactsManager::restrict_channel_participant(ChannelId channel_id, DialogI
// ok; // ok;
break; break;
case DialogType::Channel: case DialogType::Channel:
if (!status.is_banned() && !status.is_left()) { if (status.is_administrator() || status.is_member() || status.is_restricted()) {
return promise.set_error(Status::Error(400, "Other chats can be only banned or unbanned")); return promise.set_error(Status::Error(400, "Other chats can be only banned or unbanned"));
} }
break; break;