Move get_dialog_participant to DialogParticipantManager.
This commit is contained in:
parent
f1a4579e67
commit
f8565154a1
@ -17690,77 +17690,6 @@ void ContactsManager::ban_dialog_participant(DialogId dialog_id, DialogId partic
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
Promise<td_api::object_ptr<td_api::chatMember>> &&promise) {
|
||||
auto new_promise = PromiseCreator::lambda(
|
||||
[actor_id = actor_id(this), promise = std::move(promise)](Result<DialogParticipant> &&result) mutable {
|
||||
TRY_RESULT_PROMISE(promise, dialog_participant, std::move(result));
|
||||
send_closure(actor_id, &ContactsManager::finish_get_dialog_participant, std::move(dialog_participant),
|
||||
std::move(promise));
|
||||
});
|
||||
do_get_dialog_participant(dialog_id, participant_dialog_id, std::move(new_promise));
|
||||
}
|
||||
|
||||
void ContactsManager::finish_get_dialog_participant(DialogParticipant &&dialog_participant,
|
||||
Promise<td_api::object_ptr<td_api::chatMember>> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, G()->close_status());
|
||||
|
||||
auto participant_dialog_id = dialog_participant.dialog_id_;
|
||||
bool is_user = participant_dialog_id.get_type() == DialogType::User;
|
||||
if ((is_user && !have_user(participant_dialog_id.get_user_id())) ||
|
||||
(!is_user && !td_->messages_manager_->have_dialog(participant_dialog_id))) {
|
||||
return promise.set_error(Status::Error(400, "Member not found"));
|
||||
}
|
||||
|
||||
promise.set_value(get_chat_member_object(dialog_participant, "finish_get_dialog_participant"));
|
||||
}
|
||||
|
||||
void ContactsManager::do_get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
Promise<DialogParticipant> &&promise) {
|
||||
LOG(INFO) << "Receive GetChatMember request to get " << participant_dialog_id << " in " << dialog_id;
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "do_get_dialog_participant")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User: {
|
||||
auto my_user_id = get_my_id();
|
||||
auto peer_user_id = dialog_id.get_user_id();
|
||||
if (participant_dialog_id == DialogId(my_user_id)) {
|
||||
return promise.set_value(DialogParticipant::private_member(my_user_id, peer_user_id));
|
||||
}
|
||||
if (participant_dialog_id == dialog_id) {
|
||||
return promise.set_value(DialogParticipant::private_member(peer_user_id, my_user_id));
|
||||
}
|
||||
|
||||
return promise.set_error(Status::Error(400, "Member not found"));
|
||||
}
|
||||
case DialogType::Chat:
|
||||
if (participant_dialog_id.get_type() != DialogType::User) {
|
||||
return promise.set_value(DialogParticipant::left(participant_dialog_id));
|
||||
}
|
||||
return get_chat_participant(dialog_id.get_chat_id(), participant_dialog_id.get_user_id(), std::move(promise));
|
||||
case DialogType::Channel:
|
||||
return get_channel_participant(dialog_id.get_channel_id(), participant_dialog_id, std::move(promise));
|
||||
case DialogType::SecretChat: {
|
||||
auto my_user_id = get_my_id();
|
||||
auto peer_user_id = get_secret_chat_user_id(dialog_id.get_secret_chat_id());
|
||||
if (participant_dialog_id == DialogId(my_user_id)) {
|
||||
return promise.set_value(DialogParticipant::private_member(my_user_id, peer_user_id));
|
||||
}
|
||||
if (peer_user_id.is_valid() && participant_dialog_id == DialogId(peer_user_id)) {
|
||||
return promise.set_value(DialogParticipant::private_member(peer_user_id, my_user_id));
|
||||
}
|
||||
|
||||
return promise.set_error(Status::Error(400, "Member not found"));
|
||||
}
|
||||
case DialogType::None:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return promise.set_error(Status::Error(500, "Wrong chat type"));
|
||||
}
|
||||
}
|
||||
|
||||
DialogParticipants ContactsManager::search_private_chat_participants(UserId my_user_id, UserId peer_user_id,
|
||||
const string &query, int32 limit,
|
||||
DialogParticipantFilter filter) const {
|
||||
|
@ -670,8 +670,10 @@ class ContactsManager final : public Actor {
|
||||
void on_set_channel_participant_status(ChannelId channel_id, DialogId participant_dialog_id,
|
||||
DialogParticipantStatus status);
|
||||
|
||||
void get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
Promise<td_api::object_ptr<td_api::chatMember>> &&promise);
|
||||
void get_chat_participant(ChatId chat_id, UserId user_id, Promise<DialogParticipant> &&promise);
|
||||
|
||||
void get_channel_participant(ChannelId channel_id, DialogId participant_dialog_id,
|
||||
Promise<DialogParticipant> &&promise);
|
||||
|
||||
void search_dialog_participants(DialogId dialog_id, const string &query, int32 limit, DialogParticipantFilter filter,
|
||||
Promise<DialogParticipants> &&promise);
|
||||
@ -1745,19 +1747,8 @@ class ContactsManager final : public Actor {
|
||||
DialogParticipants search_private_chat_participants(UserId my_user_id, UserId peer_user_id, const string &query,
|
||||
int32 limit, DialogParticipantFilter filter) const;
|
||||
|
||||
void do_get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
Promise<DialogParticipant> &&promise);
|
||||
|
||||
void finish_get_dialog_participant(DialogParticipant &&dialog_participant,
|
||||
Promise<td_api::object_ptr<td_api::chatMember>> &&promise);
|
||||
|
||||
void get_chat_participant(ChatId chat_id, UserId user_id, Promise<DialogParticipant> &&promise);
|
||||
|
||||
void finish_get_chat_participant(ChatId chat_id, UserId user_id, Promise<DialogParticipant> &&promise);
|
||||
|
||||
void get_channel_participant(ChannelId channel_id, DialogId participant_dialog_id,
|
||||
Promise<DialogParticipant> &&promise);
|
||||
|
||||
void finish_get_channel_participant(ChannelId channel_id, DialogParticipant &&dialog_participant,
|
||||
Promise<DialogParticipant> &&promise);
|
||||
|
||||
|
@ -955,4 +955,78 @@ void DialogParticipantManager::on_update_chat_invite_requester(DialogId dialog_i
|
||||
invite_link.get_chat_invite_link_object(td_->contacts_manager_.get())));
|
||||
}
|
||||
|
||||
void DialogParticipantManager::get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
Promise<td_api::object_ptr<td_api::chatMember>> &&promise) {
|
||||
auto new_promise = PromiseCreator::lambda(
|
||||
[actor_id = actor_id(this), promise = std::move(promise)](Result<DialogParticipant> &&result) mutable {
|
||||
TRY_RESULT_PROMISE(promise, dialog_participant, std::move(result));
|
||||
send_closure(actor_id, &DialogParticipantManager::finish_get_dialog_participant, std::move(dialog_participant),
|
||||
std::move(promise));
|
||||
});
|
||||
do_get_dialog_participant(dialog_id, participant_dialog_id, std::move(new_promise));
|
||||
}
|
||||
|
||||
void DialogParticipantManager::finish_get_dialog_participant(
|
||||
DialogParticipant &&dialog_participant, Promise<td_api::object_ptr<td_api::chatMember>> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, G()->close_status());
|
||||
|
||||
auto participant_dialog_id = dialog_participant.dialog_id_;
|
||||
bool is_user = participant_dialog_id.get_type() == DialogType::User;
|
||||
if ((is_user && !td_->contacts_manager_->have_user(participant_dialog_id.get_user_id())) ||
|
||||
(!is_user && !td_->messages_manager_->have_dialog(participant_dialog_id))) {
|
||||
return promise.set_error(Status::Error(400, "Member not found"));
|
||||
}
|
||||
|
||||
promise.set_value(
|
||||
td_->contacts_manager_->get_chat_member_object(dialog_participant, "finish_get_dialog_participant"));
|
||||
}
|
||||
|
||||
void DialogParticipantManager::do_get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
Promise<DialogParticipant> &&promise) {
|
||||
LOG(INFO) << "Receive getChatMember request to get " << participant_dialog_id << " in " << dialog_id;
|
||||
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "do_get_dialog_participant")) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User: {
|
||||
auto my_user_id = td_->contacts_manager_->get_my_id();
|
||||
auto peer_user_id = dialog_id.get_user_id();
|
||||
if (participant_dialog_id == DialogId(my_user_id)) {
|
||||
return promise.set_value(DialogParticipant::private_member(my_user_id, peer_user_id));
|
||||
}
|
||||
if (participant_dialog_id == dialog_id) {
|
||||
return promise.set_value(DialogParticipant::private_member(peer_user_id, my_user_id));
|
||||
}
|
||||
|
||||
return promise.set_error(Status::Error(400, "Member not found"));
|
||||
}
|
||||
case DialogType::Chat:
|
||||
if (participant_dialog_id.get_type() != DialogType::User) {
|
||||
return promise.set_value(DialogParticipant::left(participant_dialog_id));
|
||||
}
|
||||
return td_->contacts_manager_->get_chat_participant(dialog_id.get_chat_id(), participant_dialog_id.get_user_id(),
|
||||
std::move(promise));
|
||||
case DialogType::Channel:
|
||||
return td_->contacts_manager_->get_channel_participant(dialog_id.get_channel_id(), participant_dialog_id,
|
||||
std::move(promise));
|
||||
case DialogType::SecretChat: {
|
||||
auto my_user_id = td_->contacts_manager_->get_my_id();
|
||||
auto peer_user_id = td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id());
|
||||
if (participant_dialog_id == DialogId(my_user_id)) {
|
||||
return promise.set_value(DialogParticipant::private_member(my_user_id, peer_user_id));
|
||||
}
|
||||
if (peer_user_id.is_valid() && participant_dialog_id == DialogId(peer_user_id)) {
|
||||
return promise.set_value(DialogParticipant::private_member(peer_user_id, my_user_id));
|
||||
}
|
||||
|
||||
return promise.set_error(Status::Error(400, "Member not found"));
|
||||
}
|
||||
case DialogType::None:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -79,6 +79,9 @@ class DialogParticipantManager final : public Actor {
|
||||
void on_update_chat_invite_requester(DialogId dialog_id, UserId user_id, string about, int32 date,
|
||||
DialogInviteLink invite_link);
|
||||
|
||||
void get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
Promise<td_api::object_ptr<td_api::chatMember>> &&promise);
|
||||
|
||||
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
||||
|
||||
private:
|
||||
@ -118,6 +121,12 @@ class DialogParticipantManager final : public Actor {
|
||||
const DialogParticipant &old_dialog_participant,
|
||||
const DialogParticipant &new_dialog_participant);
|
||||
|
||||
void do_get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
Promise<DialogParticipant> &&promise);
|
||||
|
||||
void finish_get_dialog_participant(DialogParticipant &&dialog_participant,
|
||||
Promise<td_api::object_ptr<td_api::chatMember>> &&promise);
|
||||
|
||||
struct OnlineMemberCountInfo {
|
||||
int32 online_member_count = 0;
|
||||
double update_time = 0;
|
||||
|
@ -6989,7 +6989,8 @@ void Td::on_request(uint64 id, const td_api::getChatMember &request) {
|
||||
CREATE_REQUEST_PROMISE();
|
||||
TRY_RESULT_PROMISE(promise, participant_dialog_id,
|
||||
get_message_sender_dialog_id(this, request.member_id_, false, false));
|
||||
contacts_manager_->get_dialog_participant(DialogId(request.chat_id_), participant_dialog_id, std::move(promise));
|
||||
dialog_participant_manager_->get_dialog_participant(DialogId(request.chat_id_), participant_dialog_id,
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::searchChatMembers &request) {
|
||||
|
Loading…
Reference in New Issue
Block a user