Improve parameters name.
This commit is contained in:
parent
2fad9afd49
commit
f18d1455cf
@ -7808,53 +7808,53 @@ void ContactsManager::set_channel_participant_status(ChannelId channel_id, Dialo
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::set_channel_participant_status_impl(ChannelId channel_id, DialogId participant_dialog_id,
|
void ContactsManager::set_channel_participant_status_impl(ChannelId channel_id, DialogId participant_dialog_id,
|
||||||
DialogParticipantStatus status,
|
DialogParticipantStatus new_status,
|
||||||
DialogParticipantStatus old_status, Promise<Unit> &&promise) {
|
DialogParticipantStatus old_status, Promise<Unit> &&promise) {
|
||||||
if (old_status == status && !old_status.is_creator()) {
|
if (old_status == new_status && !old_status.is_creator()) {
|
||||||
return promise.set_value(Unit());
|
return promise.set_value(Unit());
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(INFO) << "Change status of " << participant_dialog_id << " in " << channel_id << " from " << old_status << " to "
|
LOG(INFO) << "Change status of " << participant_dialog_id << " in " << channel_id << " from " << old_status << " to "
|
||||||
<< status;
|
<< new_status;
|
||||||
bool need_add = false;
|
bool need_add = false;
|
||||||
bool need_promote = false;
|
bool need_promote = false;
|
||||||
bool need_restrict = false;
|
bool need_restrict = false;
|
||||||
if (status.is_creator() || old_status.is_creator()) {
|
if (new_status.is_creator() || old_status.is_creator()) {
|
||||||
if (!old_status.is_creator()) {
|
if (!old_status.is_creator()) {
|
||||||
return promise.set_error(Status::Error(400, "Can't add another owner to the chat"));
|
return promise.set_error(Status::Error(400, "Can't add another owner to the chat"));
|
||||||
}
|
}
|
||||||
if (!status.is_creator()) {
|
if (!new_status.is_creator()) {
|
||||||
return promise.set_error(Status::Error(400, "Can't remove chat owner"));
|
return promise.set_error(Status::Error(400, "Can't remove chat owner"));
|
||||||
}
|
}
|
||||||
auto user_id = get_my_id();
|
auto user_id = get_my_id();
|
||||||
if (participant_dialog_id != DialogId(user_id)) {
|
if (participant_dialog_id != DialogId(user_id)) {
|
||||||
return promise.set_error(Status::Error(400, "Not enough rights to edit chat owner rights"));
|
return promise.set_error(Status::Error(400, "Not enough rights to edit chat owner rights"));
|
||||||
}
|
}
|
||||||
if (status.is_member() == old_status.is_member()) {
|
if (new_status.is_member() == old_status.is_member()) {
|
||||||
// change rank and is_anonymous
|
// change rank and is_anonymous
|
||||||
auto r_input_user = get_input_user(user_id);
|
auto r_input_user = get_input_user(user_id);
|
||||||
CHECK(r_input_user.is_ok());
|
CHECK(r_input_user.is_ok());
|
||||||
td_->create_handler<EditChannelAdminQuery>(std::move(promise))
|
td_->create_handler<EditChannelAdminQuery>(std::move(promise))
|
||||||
->send(channel_id, user_id, r_input_user.move_as_ok(), status);
|
->send(channel_id, user_id, r_input_user.move_as_ok(), new_status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (status.is_member()) {
|
if (new_status.is_member()) {
|
||||||
// creator not member -> creator member
|
// creator not member -> creator member
|
||||||
need_add = true;
|
need_add = true;
|
||||||
} else {
|
} else {
|
||||||
// creator member -> creator not member
|
// creator member -> creator not member
|
||||||
need_restrict = true;
|
need_restrict = true;
|
||||||
}
|
}
|
||||||
} else if (status.is_administrator()) {
|
} else if (new_status.is_administrator()) {
|
||||||
need_promote = true;
|
need_promote = true;
|
||||||
} else if (!status.is_member() || status.is_restricted()) {
|
} else if (!new_status.is_member() || new_status.is_restricted()) {
|
||||||
if (status.is_member() && !old_status.is_member()) {
|
if (new_status.is_member() && !old_status.is_member()) {
|
||||||
// TODO there is no way in server API to invite someone and change restrictions
|
// TODO there is no way in server API to invite someone and change restrictions
|
||||||
// we need to first add user and change restrictions again after that
|
// we need to first add user and change restrictions again after that
|
||||||
// but if restrictions aren't changed, then adding is enough
|
// but if restrictions aren't changed, then adding is enough
|
||||||
auto copy_old_status = old_status;
|
auto copy_old_status = old_status;
|
||||||
copy_old_status.set_is_member(true);
|
copy_old_status.set_is_member(true);
|
||||||
if (copy_old_status == status) {
|
if (copy_old_status == new_status) {
|
||||||
need_add = true;
|
need_add = true;
|
||||||
} else {
|
} else {
|
||||||
need_restrict = true;
|
need_restrict = true;
|
||||||
@ -7878,10 +7878,10 @@ void ContactsManager::set_channel_participant_status_impl(ChannelId channel_id,
|
|||||||
if (participant_dialog_id.get_type() != DialogType::User) {
|
if (participant_dialog_id.get_type() != DialogType::User) {
|
||||||
return promise.set_error(Status::Error(400, "Can't promote chats to chat administrators"));
|
return promise.set_error(Status::Error(400, "Can't promote chats to chat administrators"));
|
||||||
}
|
}
|
||||||
return promote_channel_participant(channel_id, participant_dialog_id.get_user_id(), status, old_status,
|
return promote_channel_participant(channel_id, participant_dialog_id.get_user_id(), new_status, old_status,
|
||||||
std::move(promise));
|
std::move(promise));
|
||||||
} else if (need_restrict) {
|
} else if (need_restrict) {
|
||||||
return restrict_channel_participant(channel_id, participant_dialog_id, std::move(status), std::move(old_status),
|
return restrict_channel_participant(channel_id, participant_dialog_id, std::move(new_status), std::move(old_status),
|
||||||
std::move(promise));
|
std::move(promise));
|
||||||
} else {
|
} else {
|
||||||
CHECK(need_add);
|
CHECK(need_add);
|
||||||
@ -7893,17 +7893,17 @@ void ContactsManager::set_channel_participant_status_impl(ChannelId channel_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::promote_channel_participant(ChannelId channel_id, UserId user_id,
|
void ContactsManager::promote_channel_participant(ChannelId channel_id, UserId user_id,
|
||||||
const DialogParticipantStatus &status,
|
const DialogParticipantStatus &new_status,
|
||||||
const DialogParticipantStatus &old_status, Promise<Unit> &&promise) {
|
const DialogParticipantStatus &old_status, Promise<Unit> &&promise) {
|
||||||
LOG(INFO) << "Promote " << user_id << " in " << channel_id << " from " << old_status << " to " << status;
|
LOG(INFO) << "Promote " << user_id << " in " << channel_id << " from " << old_status << " to " << new_status;
|
||||||
const Channel *c = get_channel(channel_id);
|
const Channel *c = get_channel(channel_id);
|
||||||
CHECK(c != nullptr);
|
CHECK(c != nullptr);
|
||||||
|
|
||||||
if (user_id == get_my_id()) {
|
if (user_id == get_my_id()) {
|
||||||
if (status.is_administrator()) {
|
if (new_status.is_administrator()) {
|
||||||
return promise.set_error(Status::Error(400, "Can't promote self"));
|
return promise.set_error(Status::Error(400, "Can't promote self"));
|
||||||
}
|
}
|
||||||
CHECK(status.is_member());
|
CHECK(new_status.is_member());
|
||||||
// allow to demote self. TODO is it allowed server-side?
|
// allow to demote self. TODO is it allowed server-side?
|
||||||
} else {
|
} else {
|
||||||
if (!get_channel_permissions(c).can_promote_members()) {
|
if (!get_channel_permissions(c).can_promote_members()) {
|
||||||
@ -7911,14 +7911,14 @@ void ContactsManager::promote_channel_participant(ChannelId channel_id, UserId u
|
|||||||
}
|
}
|
||||||
|
|
||||||
CHECK(!old_status.is_creator());
|
CHECK(!old_status.is_creator());
|
||||||
CHECK(!status.is_creator());
|
CHECK(!new_status.is_creator());
|
||||||
}
|
}
|
||||||
|
|
||||||
TRY_RESULT_PROMISE(promise, input_user, get_input_user(user_id));
|
TRY_RESULT_PROMISE(promise, input_user, get_input_user(user_id));
|
||||||
|
|
||||||
speculative_add_channel_user(channel_id, user_id, status, old_status);
|
speculative_add_channel_user(channel_id, user_id, new_status, old_status);
|
||||||
td_->create_handler<EditChannelAdminQuery>(std::move(promise))
|
td_->create_handler<EditChannelAdminQuery>(std::move(promise))
|
||||||
->send(channel_id, user_id, std::move(input_user), status);
|
->send(channel_id, user_id, std::move(input_user), new_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::set_chat_participant_status(ChatId chat_id, UserId user_id, DialogParticipantStatus status,
|
void ContactsManager::set_chat_participant_status(ChatId chat_id, UserId user_id, DialogParticipantStatus status,
|
||||||
@ -8396,19 +8396,19 @@ void ContactsManager::delete_chat_participant(ChatId chat_id, UserId user_id, bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::restrict_channel_participant(ChannelId channel_id, DialogId participant_dialog_id,
|
void ContactsManager::restrict_channel_participant(ChannelId channel_id, DialogId participant_dialog_id,
|
||||||
DialogParticipantStatus &&status,
|
DialogParticipantStatus &&new_status,
|
||||||
DialogParticipantStatus &&old_status, Promise<Unit> &&promise) {
|
DialogParticipantStatus &&old_status, Promise<Unit> &&promise) {
|
||||||
TRY_STATUS_PROMISE(promise, G()->close_status());
|
TRY_STATUS_PROMISE(promise, G()->close_status());
|
||||||
|
|
||||||
LOG(INFO) << "Restrict " << participant_dialog_id << " in " << channel_id << " from " << old_status << " to "
|
LOG(INFO) << "Restrict " << participant_dialog_id << " in " << channel_id << " from " << old_status << " to "
|
||||||
<< status;
|
<< new_status;
|
||||||
const Channel *c = get_channel(channel_id);
|
const Channel *c = get_channel(channel_id);
|
||||||
if (c == nullptr) {
|
if (c == nullptr) {
|
||||||
return promise.set_error(Status::Error(400, "Chat info not found"));
|
return promise.set_error(Status::Error(400, "Chat info not found"));
|
||||||
}
|
}
|
||||||
if (!c->status.is_member() && !c->status.is_creator()) {
|
if (!c->status.is_member() && !c->status.is_creator()) {
|
||||||
if (participant_dialog_id == DialogId(get_my_id())) {
|
if (participant_dialog_id == DialogId(get_my_id())) {
|
||||||
if (status.is_member()) {
|
if (new_status.is_member()) {
|
||||||
return promise.set_error(Status::Error(400, "Can't unrestrict self"));
|
return promise.set_error(Status::Error(400, "Can't unrestrict self"));
|
||||||
}
|
}
|
||||||
return promise.set_value(Unit());
|
return promise.set_value(Unit());
|
||||||
@ -8422,15 +8422,15 @@ void ContactsManager::restrict_channel_participant(ChannelId channel_id, DialogI
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (participant_dialog_id == DialogId(get_my_id())) {
|
if (participant_dialog_id == DialogId(get_my_id())) {
|
||||||
if (status.is_restricted() || status.is_banned()) {
|
if (new_status.is_restricted() || new_status.is_banned()) {
|
||||||
return promise.set_error(Status::Error(400, "Can't restrict self"));
|
return promise.set_error(Status::Error(400, "Can't restrict self"));
|
||||||
}
|
}
|
||||||
if (status.is_member()) {
|
if (new_status.is_member()) {
|
||||||
return promise.set_error(Status::Error(400, "Can't unrestrict self"));
|
return promise.set_error(Status::Error(400, "Can't unrestrict self"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// leave the channel
|
// leave the channel
|
||||||
speculative_add_channel_user(channel_id, participant_dialog_id.get_user_id(), status, c->status);
|
speculative_add_channel_user(channel_id, participant_dialog_id.get_user_id(), new_status, c->status);
|
||||||
td_->create_handler<LeaveChannelQuery>(std::move(promise))->send(channel_id);
|
td_->create_handler<LeaveChannelQuery>(std::move(promise))->send(channel_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -8440,7 +8440,7 @@ void ContactsManager::restrict_channel_participant(ChannelId channel_id, DialogI
|
|||||||
// ok;
|
// ok;
|
||||||
break;
|
break;
|
||||||
case DialogType::Channel:
|
case DialogType::Channel:
|
||||||
if (status.is_administrator() || status.is_member() || status.is_restricted()) {
|
if (new_status.is_administrator() || new_status.is_member() || new_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;
|
||||||
@ -8449,16 +8449,16 @@ void ContactsManager::restrict_channel_participant(ChannelId channel_id, DialogI
|
|||||||
}
|
}
|
||||||
|
|
||||||
CHECK(!old_status.is_creator());
|
CHECK(!old_status.is_creator());
|
||||||
CHECK(!status.is_creator());
|
CHECK(!new_status.is_creator());
|
||||||
|
|
||||||
if (!get_channel_permissions(c).can_restrict_members()) {
|
if (!get_channel_permissions(c).can_restrict_members()) {
|
||||||
return promise.set_error(Status::Error(400, "Not enough rights to restrict/unrestrict chat member"));
|
return promise.set_error(Status::Error(400, "Not enough rights to restrict/unrestrict chat member"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (old_status.is_member() && !status.is_member() && !status.is_banned()) {
|
if (old_status.is_member() && !new_status.is_member() && !new_status.is_banned()) {
|
||||||
// we can't make participant Left without kicking it first
|
// we can't make participant Left without kicking it first
|
||||||
auto on_result_promise = PromiseCreator::lambda([actor_id = actor_id(this), channel_id, participant_dialog_id,
|
auto on_result_promise = PromiseCreator::lambda([actor_id = actor_id(this), channel_id, participant_dialog_id,
|
||||||
status = std::move(status),
|
new_status = std::move(new_status),
|
||||||
promise = std::move(promise)](Result<> result) mutable {
|
promise = std::move(promise)](Result<> result) mutable {
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
return promise.set_error(result.move_as_error());
|
return promise.set_error(result.move_as_error());
|
||||||
@ -8466,27 +8466,27 @@ void ContactsManager::restrict_channel_participant(ChannelId channel_id, DialogI
|
|||||||
|
|
||||||
create_actor<SleepActor>(
|
create_actor<SleepActor>(
|
||||||
"RestrictChannelParticipantSleepActor", 1.0,
|
"RestrictChannelParticipantSleepActor", 1.0,
|
||||||
PromiseCreator::lambda([actor_id, channel_id, participant_dialog_id, status = std::move(status),
|
PromiseCreator::lambda([actor_id, channel_id, participant_dialog_id, new_status = std::move(new_status),
|
||||||
promise = std::move(promise)](Result<> result) mutable {
|
promise = std::move(promise)](Result<> result) mutable {
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
return promise.set_error(result.move_as_error());
|
return promise.set_error(result.move_as_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
send_closure(actor_id, &ContactsManager::restrict_channel_participant, channel_id, participant_dialog_id,
|
send_closure(actor_id, &ContactsManager::restrict_channel_participant, channel_id, participant_dialog_id,
|
||||||
std::move(status), DialogParticipantStatus::Banned(0), std::move(promise));
|
std::move(new_status), DialogParticipantStatus::Banned(0), std::move(promise));
|
||||||
}))
|
}))
|
||||||
.release();
|
.release();
|
||||||
});
|
});
|
||||||
|
|
||||||
promise = std::move(on_result_promise);
|
promise = std::move(on_result_promise);
|
||||||
status = DialogParticipantStatus::Banned(G()->unix_time() + 60);
|
new_status = DialogParticipantStatus::Banned(G()->unix_time() + 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (participant_dialog_id.get_type() == DialogType::User) {
|
if (participant_dialog_id.get_type() == DialogType::User) {
|
||||||
speculative_add_channel_user(channel_id, participant_dialog_id.get_user_id(), status, old_status);
|
speculative_add_channel_user(channel_id, participant_dialog_id.get_user_id(), new_status, old_status);
|
||||||
}
|
}
|
||||||
td_->create_handler<EditChannelBannedQuery>(std::move(promise))
|
td_->create_handler<EditChannelBannedQuery>(std::move(promise))
|
||||||
->send(channel_id, participant_dialog_id, std::move(input_peer), status);
|
->send(channel_id, participant_dialog_id, std::move(input_peer), new_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::on_set_channel_participant_status(ChannelId channel_id, DialogId participant_dialog_id,
|
void ContactsManager::on_set_channel_participant_status(ChannelId channel_id, DialogId participant_dialog_id,
|
||||||
|
@ -1691,14 +1691,14 @@ class ContactsManager final : public Actor {
|
|||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
void set_channel_participant_status_impl(ChannelId channel_id, DialogId participant_dialog_id,
|
void set_channel_participant_status_impl(ChannelId channel_id, DialogId participant_dialog_id,
|
||||||
DialogParticipantStatus status, DialogParticipantStatus old_status,
|
DialogParticipantStatus new_status, DialogParticipantStatus old_status,
|
||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
void promote_channel_participant(ChannelId channel_id, UserId user_id, const DialogParticipantStatus &status,
|
void promote_channel_participant(ChannelId channel_id, UserId user_id, const DialogParticipantStatus &new_status,
|
||||||
const DialogParticipantStatus &old_status, Promise<Unit> &&promise);
|
const DialogParticipantStatus &old_status, Promise<Unit> &&promise);
|
||||||
|
|
||||||
void restrict_channel_participant(ChannelId channel_id, DialogId participant_dialog_id,
|
void restrict_channel_participant(ChannelId channel_id, DialogId participant_dialog_id,
|
||||||
DialogParticipantStatus &&status, DialogParticipantStatus &&old_status,
|
DialogParticipantStatus &&new_status, DialogParticipantStatus &&old_status,
|
||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
void transfer_channel_ownership(ChannelId channel_id, UserId user_id,
|
void transfer_channel_ownership(ChannelId channel_id, UserId user_id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user