Move set_dialog_participant_status and similar methods to DialogParticipantManager.
This commit is contained in:
parent
50b5a6e9bf
commit
9660a7f2b1
@ -17388,85 +17388,6 @@ std::pair<int32, vector<DialogId>> ContactsManager::search_among_dialogs(const v
|
||||
return {narrow_cast<int32>(result.first), transform(result.second, [](int64 key) { return DialogId(key); })};
|
||||
}
|
||||
|
||||
void ContactsManager::add_dialog_participant(DialogId dialog_id, UserId user_id, int32 forward_limit,
|
||||
Promise<Unit> &&promise) {
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "add_dialog_participant")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
return promise.set_error(Status::Error(400, "Can't add members to a private chat"));
|
||||
case DialogType::Chat:
|
||||
return add_chat_participant(dialog_id.get_chat_id(), user_id, forward_limit, std::move(promise));
|
||||
case DialogType::Channel:
|
||||
return add_channel_participant(dialog_id.get_channel_id(), user_id, DialogParticipantStatus::Left(),
|
||||
std::move(promise));
|
||||
case DialogType::SecretChat:
|
||||
return promise.set_error(Status::Error(400, "Can't add members to a secret chat"));
|
||||
case DialogType::None:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::add_dialog_participants(DialogId dialog_id, const vector<UserId> &user_ids,
|
||||
Promise<Unit> &&promise) {
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "add_dialog_participants")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
return promise.set_error(Status::Error(400, "Can't add members to a private chat"));
|
||||
case DialogType::Chat:
|
||||
if (user_ids.size() == 1) {
|
||||
return add_chat_participant(dialog_id.get_chat_id(), user_ids[0], 0, std::move(promise));
|
||||
}
|
||||
return promise.set_error(Status::Error(400, "Can't add many members at once to a basic group chat"));
|
||||
case DialogType::Channel:
|
||||
return add_channel_participants(dialog_id.get_channel_id(), user_ids, std::move(promise));
|
||||
case DialogType::SecretChat:
|
||||
return promise.set_error(Status::Error(400, "Can't add members to a secret chat"));
|
||||
case DialogType::None:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::set_dialog_participant_status(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
td_api::object_ptr<td_api::ChatMemberStatus> &&chat_member_status,
|
||||
Promise<Unit> &&promise) {
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "set_dialog_participant_status")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
return promise.set_error(Status::Error(400, "Chat member status can't be changed in private chats"));
|
||||
case DialogType::Chat: {
|
||||
auto status = get_dialog_participant_status(chat_member_status, ChannelType::Unknown);
|
||||
if (participant_dialog_id.get_type() != DialogType::User) {
|
||||
if (status == DialogParticipantStatus::Left()) {
|
||||
return promise.set_value(Unit());
|
||||
} else {
|
||||
return promise.set_error(Status::Error(400, "Chats can't be members of basic groups"));
|
||||
}
|
||||
}
|
||||
return set_chat_participant_status(dialog_id.get_chat_id(), participant_dialog_id.get_user_id(), status,
|
||||
std::move(promise));
|
||||
}
|
||||
case DialogType::Channel:
|
||||
return set_channel_participant_status(dialog_id.get_channel_id(), participant_dialog_id,
|
||||
std::move(chat_member_status), std::move(promise));
|
||||
case DialogType::SecretChat:
|
||||
return promise.set_error(Status::Error(400, "Chat member status can't be changed in secret chats"));
|
||||
case DialogType::None:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::leave_dialog(DialogId dialog_id, Promise<Unit> &&promise) {
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "leave_dialog")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
@ -17493,34 +17414,6 @@ void ContactsManager::leave_dialog(DialogId dialog_id, Promise<Unit> &&promise)
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::ban_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
int32 banned_until_date, bool revoke_messages, Promise<Unit> &&promise) {
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "ban_dialog_participant")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
return promise.set_error(Status::Error(400, "Can't ban members in private chats"));
|
||||
case DialogType::Chat:
|
||||
if (participant_dialog_id.get_type() != DialogType::User) {
|
||||
return promise.set_error(Status::Error(400, "Can't ban chats in basic groups"));
|
||||
}
|
||||
return delete_chat_participant(dialog_id.get_chat_id(), participant_dialog_id.get_user_id(), revoke_messages,
|
||||
std::move(promise));
|
||||
case DialogType::Channel:
|
||||
// must use td_api::chatMemberStatusBanned to properly fix banned_until_date
|
||||
return set_channel_participant_status(dialog_id.get_channel_id(), participant_dialog_id,
|
||||
td_api::make_object<td_api::chatMemberStatusBanned>(banned_until_date),
|
||||
std::move(promise));
|
||||
case DialogType::SecretChat:
|
||||
return promise.set_error(Status::Error(400, "Can't ban members in secret chats"));
|
||||
case DialogType::None:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
DialogParticipants ContactsManager::search_private_chat_participants(UserId my_user_id, UserId peer_user_id,
|
||||
const string &query, int32 limit,
|
||||
DialogParticipantFilter filter) const {
|
||||
|
@ -647,19 +647,24 @@ class ContactsManager final : public Actor {
|
||||
int32 get_channel_slow_mode_delay(ChannelId channel_id, const char *source);
|
||||
bool get_channel_effective_has_hidden_participants(ChannelId channel_id, const char *source);
|
||||
|
||||
void add_dialog_participant(DialogId dialog_id, UserId user_id, int32 forward_limit, Promise<Unit> &&promise);
|
||||
void add_chat_participant(ChatId chat_id, UserId user_id, int32 forward_limit, Promise<Unit> &&promise);
|
||||
|
||||
void add_dialog_participants(DialogId dialog_id, const vector<UserId> &user_ids, Promise<Unit> &&promise);
|
||||
void add_channel_participant(ChannelId channel_id, UserId user_id, const DialogParticipantStatus &old_status,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void set_dialog_participant_status(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
td_api::object_ptr<td_api::ChatMemberStatus> &&chat_member_status,
|
||||
Promise<Unit> &&promise);
|
||||
void add_channel_participants(ChannelId channel_id, const vector<UserId> &user_ids, Promise<Unit> &&promise);
|
||||
|
||||
void set_chat_participant_status(ChatId chat_id, UserId user_id, DialogParticipantStatus status,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void set_channel_participant_status(ChannelId channel_id, DialogId participant_dialog_id,
|
||||
td_api::object_ptr<td_api::ChatMemberStatus> &&chat_member_status,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void delete_chat_participant(ChatId chat_id, UserId user_id, bool revoke_messages, Promise<Unit> &&promise);
|
||||
|
||||
void leave_dialog(DialogId dialog_id, Promise<Unit> &&promise);
|
||||
|
||||
void ban_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id, int32 banned_until_date,
|
||||
bool revoke_messages, Promise<Unit> &&promise);
|
||||
|
||||
void get_chat_participant(ChatId chat_id, UserId user_id, Promise<DialogParticipant> &&promise);
|
||||
|
||||
void search_dialog_participants(DialogId dialog_id, const string &query, int32 limit, DialogParticipantFilter filter,
|
||||
@ -1713,13 +1718,6 @@ class ContactsManager final : public Actor {
|
||||
|
||||
bool update_permanent_invite_link(DialogInviteLink &invite_link, DialogInviteLink new_invite_link);
|
||||
|
||||
void add_chat_participant(ChatId chat_id, UserId user_id, int32 forward_limit, Promise<Unit> &&promise);
|
||||
|
||||
void add_channel_participant(ChannelId channel_id, UserId user_id, const DialogParticipantStatus &old_status,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void add_channel_participants(ChannelId channel_id, const vector<UserId> &user_ids, Promise<Unit> &&promise);
|
||||
|
||||
vector<BotCommands> get_bot_commands(vector<tl_object_ptr<telegram_api::botInfo>> &&bot_infos,
|
||||
const vector<DialogParticipant> *participants);
|
||||
|
||||
@ -1807,8 +1805,6 @@ class ContactsManager final : public Actor {
|
||||
|
||||
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 search_chat_participants(ChatId chat_id, const string &query, int32 limit, DialogParticipantFilter filter,
|
||||
Promise<DialogParticipants> &&promise);
|
||||
|
||||
@ -1820,13 +1816,6 @@ class ContactsManager final : public Actor {
|
||||
tl_object_ptr<telegram_api::channels_channelParticipants> &&channel_participants,
|
||||
Promise<DialogParticipants> &&promise);
|
||||
|
||||
void set_chat_participant_status(ChatId chat_id, UserId user_id, DialogParticipantStatus status,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void set_channel_participant_status(ChannelId channel_id, DialogId participant_dialog_id,
|
||||
td_api::object_ptr<td_api::ChatMemberStatus> &&chat_member_status,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void set_channel_participant_status_impl(ChannelId channel_id, DialogId participant_dialog_id,
|
||||
DialogParticipantStatus new_status, DialogParticipantStatus old_status,
|
||||
Promise<Unit> &&promise);
|
||||
|
@ -1131,6 +1131,116 @@ void DialogParticipantManager::finish_get_channel_participant(ChannelId channel_
|
||||
promise.set_value(std::move(dialog_participant));
|
||||
}
|
||||
|
||||
void DialogParticipantManager::add_dialog_participant(DialogId dialog_id, UserId user_id, int32 forward_limit,
|
||||
Promise<Unit> &&promise) {
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "add_dialog_participant")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
return promise.set_error(Status::Error(400, "Can't add members to a private chat"));
|
||||
case DialogType::Chat:
|
||||
return td_->contacts_manager_->add_chat_participant(dialog_id.get_chat_id(), user_id, forward_limit,
|
||||
std::move(promise));
|
||||
case DialogType::Channel:
|
||||
return td_->contacts_manager_->add_channel_participant(dialog_id.get_channel_id(), user_id,
|
||||
DialogParticipantStatus::Left(), std::move(promise));
|
||||
case DialogType::SecretChat:
|
||||
return promise.set_error(Status::Error(400, "Can't add members to a secret chat"));
|
||||
case DialogType::None:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void DialogParticipantManager::add_dialog_participants(DialogId dialog_id, const vector<UserId> &user_ids,
|
||||
Promise<Unit> &&promise) {
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "add_dialog_participants")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
return promise.set_error(Status::Error(400, "Can't add members to a private chat"));
|
||||
case DialogType::Chat:
|
||||
if (user_ids.size() == 1) {
|
||||
return td_->contacts_manager_->add_chat_participant(dialog_id.get_chat_id(), user_ids[0], 0,
|
||||
std::move(promise));
|
||||
}
|
||||
return promise.set_error(Status::Error(400, "Can't add many members at once to a basic group chat"));
|
||||
case DialogType::Channel:
|
||||
return td_->contacts_manager_->add_channel_participants(dialog_id.get_channel_id(), user_ids, std::move(promise));
|
||||
case DialogType::SecretChat:
|
||||
return promise.set_error(Status::Error(400, "Can't add members to a secret chat"));
|
||||
case DialogType::None:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void DialogParticipantManager::set_dialog_participant_status(
|
||||
DialogId dialog_id, DialogId participant_dialog_id,
|
||||
td_api::object_ptr<td_api::ChatMemberStatus> &&chat_member_status, Promise<Unit> &&promise) {
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "set_dialog_participant_status")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
return promise.set_error(Status::Error(400, "Chat member status can't be changed in private chats"));
|
||||
case DialogType::Chat: {
|
||||
auto status = get_dialog_participant_status(chat_member_status, ChannelType::Unknown);
|
||||
if (participant_dialog_id.get_type() != DialogType::User) {
|
||||
if (status == DialogParticipantStatus::Left()) {
|
||||
return promise.set_value(Unit());
|
||||
} else {
|
||||
return promise.set_error(Status::Error(400, "Chats can't be members of basic groups"));
|
||||
}
|
||||
}
|
||||
return td_->contacts_manager_->set_chat_participant_status(
|
||||
dialog_id.get_chat_id(), participant_dialog_id.get_user_id(), status, std::move(promise));
|
||||
}
|
||||
case DialogType::Channel:
|
||||
return td_->contacts_manager_->set_channel_participant_status(dialog_id.get_channel_id(), participant_dialog_id,
|
||||
std::move(chat_member_status), std::move(promise));
|
||||
case DialogType::SecretChat:
|
||||
return promise.set_error(Status::Error(400, "Chat member status can't be changed in secret chats"));
|
||||
case DialogType::None:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void DialogParticipantManager::ban_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
int32 banned_until_date, bool revoke_messages,
|
||||
Promise<Unit> &&promise) {
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "ban_dialog_participant")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
return promise.set_error(Status::Error(400, "Can't ban members in private chats"));
|
||||
case DialogType::Chat:
|
||||
if (participant_dialog_id.get_type() != DialogType::User) {
|
||||
return promise.set_error(Status::Error(400, "Can't ban chats in basic groups"));
|
||||
}
|
||||
return td_->contacts_manager_->delete_chat_participant(
|
||||
dialog_id.get_chat_id(), participant_dialog_id.get_user_id(), revoke_messages, std::move(promise));
|
||||
case DialogType::Channel:
|
||||
// must use td_api::chatMemberStatusBanned to properly fix banned_until_date
|
||||
return td_->contacts_manager_->set_channel_participant_status(
|
||||
dialog_id.get_channel_id(), participant_dialog_id,
|
||||
td_api::make_object<td_api::chatMemberStatusBanned>(banned_until_date), std::move(promise));
|
||||
case DialogType::SecretChat:
|
||||
return promise.set_error(Status::Error(400, "Can't ban members in secret chats"));
|
||||
case DialogType::None:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void DialogParticipantManager::on_set_channel_participant_status(ChannelId channel_id, DialogId participant_dialog_id,
|
||||
DialogParticipantStatus status) {
|
||||
if (G()->close_flag() || participant_dialog_id == td_->dialog_manager_->get_my_dialog_id()) {
|
||||
|
@ -85,6 +85,17 @@ class DialogParticipantManager final : public Actor {
|
||||
void get_channel_participant(ChannelId channel_id, DialogId participant_dialog_id,
|
||||
Promise<DialogParticipant> &&promise);
|
||||
|
||||
void add_dialog_participant(DialogId dialog_id, UserId user_id, int32 forward_limit, Promise<Unit> &&promise);
|
||||
|
||||
void add_dialog_participants(DialogId dialog_id, const vector<UserId> &user_ids, Promise<Unit> &&promise);
|
||||
|
||||
void set_dialog_participant_status(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
td_api::object_ptr<td_api::ChatMemberStatus> &&chat_member_status,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void ban_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id, int32 banned_until_date,
|
||||
bool revoke_messages, Promise<Unit> &&promise);
|
||||
|
||||
void on_set_channel_participant_status(ChannelId channel_id, DialogId participant_dialog_id,
|
||||
DialogParticipantStatus status);
|
||||
|
||||
|
@ -6910,8 +6910,8 @@ void Td::on_request(uint64 id, const td_api::unpinAllMessageThreadMessages &requ
|
||||
void Td::on_request(uint64 id, const td_api::joinChat &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
contacts_manager_->add_dialog_participant(DialogId(request.chat_id_), contacts_manager_->get_my_id(), 0,
|
||||
std::move(promise));
|
||||
dialog_participant_manager_->add_dialog_participant(DialogId(request.chat_id_), contacts_manager_->get_my_id(), 0,
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::leaveChat &request) {
|
||||
@ -6929,38 +6929,39 @@ void Td::on_request(uint64 id, const td_api::leaveChat &request) {
|
||||
td_api::make_object<td_api::chatMemberStatusCreator>(status.get_rank(), status.is_anonymous(), false);
|
||||
}
|
||||
}
|
||||
contacts_manager_->set_dialog_participant_status(dialog_id, dialog_manager_->get_my_dialog_id(),
|
||||
std::move(new_status), std::move(promise));
|
||||
dialog_participant_manager_->set_dialog_participant_status(dialog_id, dialog_manager_->get_my_dialog_id(),
|
||||
std::move(new_status), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::addChatMember &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
contacts_manager_->add_dialog_participant(DialogId(request.chat_id_), UserId(request.user_id_),
|
||||
request.forward_limit_, std::move(promise));
|
||||
dialog_participant_manager_->add_dialog_participant(DialogId(request.chat_id_), UserId(request.user_id_),
|
||||
request.forward_limit_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::addChatMembers &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
contacts_manager_->add_dialog_participants(DialogId(request.chat_id_), UserId::get_user_ids(request.user_ids_),
|
||||
std::move(promise));
|
||||
dialog_participant_manager_->add_dialog_participants(DialogId(request.chat_id_),
|
||||
UserId::get_user_ids(request.user_ids_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::setChatMemberStatus &request) {
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
TRY_RESULT_PROMISE(promise, participant_dialog_id,
|
||||
get_message_sender_dialog_id(this, request.member_id_, false, false));
|
||||
contacts_manager_->set_dialog_participant_status(DialogId(request.chat_id_), participant_dialog_id,
|
||||
std::move(request.status_), std::move(promise));
|
||||
dialog_participant_manager_->set_dialog_participant_status(DialogId(request.chat_id_), participant_dialog_id,
|
||||
std::move(request.status_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::banChatMember &request) {
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
TRY_RESULT_PROMISE(promise, participant_dialog_id,
|
||||
get_message_sender_dialog_id(this, request.member_id_, false, false));
|
||||
contacts_manager_->ban_dialog_participant(DialogId(request.chat_id_), participant_dialog_id,
|
||||
request.banned_until_date_, request.revoke_messages_, std::move(promise));
|
||||
dialog_participant_manager_->ban_dialog_participant(DialogId(request.chat_id_), participant_dialog_id,
|
||||
request.banned_until_date_, request.revoke_messages_,
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::canTransferOwnership &request) {
|
||||
|
Loading…
Reference in New Issue
Block a user