Support adding basic group members through setChatMemberStatus.

This commit is contained in:
levlam 2021-09-23 18:39:13 +03:00
parent b0b25b53b0
commit d032ca2ab2
2 changed files with 35 additions and 9 deletions

View File

@ -4673,7 +4673,7 @@ addChatMember chat_id:int53 user_id:int53 forward_limit:int32 = Ok;
//@chat_id Chat identifier @user_ids Identifiers of the users to be added to the chat. The maximum number of added users is 20 for supergroups and 100 for channels
addChatMembers chat_id:int53 user_ids:vector<int53> = Ok;
//@description Changes the status of a chat member, needs appropriate privileges. This function is currently not suitable for adding new members to the chat and transferring chat ownership; instead, use addChatMember or transferChatOwnership
//@description Changes the status of a chat member, needs appropriate privileges. This function is currently not suitable for transferring chat ownership; use transferChatOwnership instead. Use addChatMember or banChatMember if you need to pass some additional parameters
//@chat_id Chat identifier @member_id Member identifier. Chats can be only banned and unbanned in supergroups and channels @status The new status of the member in the chat
setChatMemberStatus chat_id:int53 member_id:MessageSender status:ChatMemberStatus = Ok;

View File

@ -7077,10 +7077,43 @@ void ContactsManager::change_chat_participant_status(ChatId chat_id, UserId user
if (!status.is_member()) {
return delete_chat_participant(chat_id, user_id, false, std::move(promise));
}
if (status.is_creator()) {
return promise.set_error(Status::Error(400, "Can't change owner in basic group chats"));
}
if (status.is_restricted()) {
return promise.set_error(Status::Error(400, "Can't restrict users in basic group chats"));
}
auto c = get_chat(chat_id);
if (c == nullptr) {
return promise.set_error(Status::Error(6, "Chat info not found"));
return promise.set_error(Status::Error(400, "Chat info not found"));
}
if (!c->is_active) {
return promise.set_error(Status::Error(400, "Chat is deactivated"));
}
auto chat_full = get_chat_full(chat_id);
if (chat_full == nullptr) {
auto load_chat_full_promise =
PromiseCreator::lambda([actor_id = actor_id(this), chat_id, user_id, status = std::move(status),
promise = std::move(promise)](Result<Unit> &&result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
send_closure(actor_id, &ContactsManager::change_chat_participant_status, chat_id, user_id, status,
std::move(promise));
}
});
load_chat_full(chat_id, false, std::move(load_chat_full_promise), "change_chat_participant_status");
return;
}
auto participant = get_chat_full_participant(chat_full, DialogId(user_id));
if (participant == nullptr) {
// the user isn't a member
if (!status.is_administrator()) {
return add_chat_participant(chat_id, user_id, 0, std::move(promise));
}
}
if (!get_chat_permissions(c).can_promote_members()) {
@ -7096,13 +7129,6 @@ void ContactsManager::change_chat_participant_status(ChatId chat_id, UserId user
return promise.set_error(Status::Error(3, "User not found"));
}
if (status.is_creator()) {
return promise.set_error(Status::Error(3, "Can't add creator to the group chat"));
}
if (status.is_restricted()) {
return promise.set_error(Status::Error(3, "Can't restrict users in a basic group chat"));
}
td_->create_handler<EditChatAdminQuery>(std::move(promise))
->send(chat_id, std::move(input_user), status.is_administrator());
}