Allow to add non-members as administrators in basic groups using setChatMemberStatus.
This commit is contained in:
parent
e212d1293d
commit
f2908bb7e5
@ -7108,11 +7108,9 @@ void ContactsManager::change_chat_participant_status(ChatId chat_id, UserId user
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto participant = get_chat_full_participant(chat_full, DialogId(user_id));
|
auto participant = get_chat_full_participant(chat_full, DialogId(user_id));
|
||||||
if (participant == nullptr) {
|
if (participant == nullptr && !status.is_administrator()) {
|
||||||
// the user isn't a member
|
// the user isn't a member, but needs to be added
|
||||||
if (!status.is_administrator()) {
|
return add_chat_participant(chat_id, user_id, 0, std::move(promise));
|
||||||
return add_chat_participant(chat_id, user_id, 0, std::move(promise));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!get_chat_permissions(c).can_promote_members()) {
|
if (!get_chat_permissions(c).can_promote_members()) {
|
||||||
@ -7120,16 +7118,35 @@ void ContactsManager::change_chat_participant_status(ChatId chat_id, UserId user
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user_id == get_my_id()) {
|
if (user_id == get_my_id()) {
|
||||||
return promise.set_error(Status::Error(3, "Can't change chat member status of self"));
|
return promise.set_error(Status::Error(3, "Can't promote or demote self"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (participant == nullptr) {
|
||||||
|
// the user must be added first
|
||||||
|
CHECK(status.is_administrator());
|
||||||
|
auto add_chat_participant_promise = PromiseCreator::lambda(
|
||||||
|
[actor_id = actor_id(this), chat_id, user_id, 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::send_edit_chat_admin_query, chat_id, user_id, true,
|
||||||
|
std::move(promise));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return add_chat_participant(chat_id, user_id, 0, std::move(add_chat_participant_promise));
|
||||||
|
}
|
||||||
|
|
||||||
|
send_edit_chat_admin_query(chat_id, user_id, status.is_administrator(), std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContactsManager::send_edit_chat_admin_query(ChatId chat_id, UserId user_id, bool is_administrator,
|
||||||
|
Promise<Unit> &&promise) {
|
||||||
auto input_user = get_input_user(user_id);
|
auto input_user = get_input_user(user_id);
|
||||||
if (input_user == nullptr) {
|
if (input_user == nullptr) {
|
||||||
return promise.set_error(Status::Error(3, "User not found"));
|
return promise.set_error(Status::Error(3, "User not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
td_->create_handler<EditChatAdminQuery>(std::move(promise))
|
td_->create_handler<EditChatAdminQuery>(std::move(promise))->send(chat_id, std::move(input_user), is_administrator);
|
||||||
->send(chat_id, std::move(input_user), status.is_administrator());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::can_transfer_ownership(Promise<CanTransferOwnershipResult> &&promise) {
|
void ContactsManager::can_transfer_ownership(Promise<CanTransferOwnershipResult> &&promise) {
|
||||||
|
@ -1488,6 +1488,8 @@ class ContactsManager final : public Actor {
|
|||||||
void change_channel_participant_status(ChannelId channel_id, DialogId participant_dialog_id,
|
void change_channel_participant_status(ChannelId channel_id, DialogId participant_dialog_id,
|
||||||
DialogParticipantStatus status, Promise<Unit> &&promise);
|
DialogParticipantStatus status, Promise<Unit> &&promise);
|
||||||
|
|
||||||
|
void send_edit_chat_admin_query(ChatId chat_id, UserId user_id, bool is_administrator, Promise<Unit> &&promise);
|
||||||
|
|
||||||
void delete_chat_participant(ChatId chat_id, UserId user_id, bool revoke_messages, Promise<Unit> &&promise);
|
void delete_chat_participant(ChatId chat_id, UserId user_id, bool revoke_messages, Promise<Unit> &&promise);
|
||||||
|
|
||||||
void search_chat_participants(ChatId chat_id, const string &query, int32 limit, DialogParticipantsFilter filter,
|
void search_chat_participants(ChatId chat_id, const string &query, int32 limit, DialogParticipantsFilter filter,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user