Add ContactsManager::get_participant_dialog_id.

This commit is contained in:
levlam 2021-03-26 03:17:30 +03:00
parent ffc847dbf5
commit f28af4ab20
3 changed files with 29 additions and 30 deletions

View File

@ -14451,6 +14451,21 @@ 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); })};
}
DialogId ContactsManager::get_participant_dialog_id(const td_api::object_ptr<td_api::MessageSender> &participant_id) {
if (participant_id == nullptr) {
return DialogId();
}
switch (participant_id->get_id()) {
case td_api::messageSenderUser::ID:
return DialogId(UserId(static_cast<const td_api::messageSenderUser *>(participant_id.get())->user_id_));
case td_api::messageSenderChat::ID:
return DialogId(static_cast<const td_api::messageSenderChat *>(participant_id.get())->chat_id_);
default:
UNREACHABLE();
return DialogId();
}
}
void ContactsManager::add_dialog_participant(DialogId dialog_id, UserId user_id, int32 forward_limit,
Promise<Unit> &&promise) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "add_dialog_participant")) {
@ -14543,32 +14558,15 @@ void ContactsManager::ban_dialog_participant(DialogId dialog_id, UserId user_id,
}
}
DialogParticipant ContactsManager::get_dialog_participant(DialogId dialog_id,
const td_api::object_ptr<td_api::MessageSender> &member_id,
DialogParticipant ContactsManager::get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
int64 &random_id, bool force, Promise<Unit> &&promise) {
LOG(INFO) << "Receive GetChatMember request to get " << to_string(member_id) << " in " << dialog_id
LOG(INFO) << "Receive GetChatMember request to get " << participant_dialog_id << " in " << dialog_id
<< " with random_id " << random_id;
if (!td_->messages_manager_->have_dialog_force(dialog_id, "get_dialog_participant")) {
promise.set_error(Status::Error(3, "Chat not found"));
return DialogParticipant();
}
if (member_id == nullptr) {
promise.set_error(Status::Error(3, "Member must be non-empty"));
return DialogParticipant();
}
DialogId participant_dialog_id;
switch (member_id->get_id()) {
case td_api::messageSenderUser::ID:
participant_dialog_id =
DialogId(UserId(static_cast<const td_api::messageSenderUser *>(member_id.get())->user_id_));
break;
case td_api::messageSenderChat::ID:
participant_dialog_id = DialogId(static_cast<const td_api::messageSenderChat *>(member_id.get())->chat_id_);
break;
default:
UNREACHABLE();
}
if (!participant_dialog_id.is_valid()) {
promise.set_error(Status::Error(3, "Invalid member identifier specified"));
return DialogParticipant();

View File

@ -514,6 +514,8 @@ class ContactsManager : public Actor {
ChannelId get_channel_linked_channel_id(ChannelId channel_id);
int32 get_channel_slow_mode_delay(ChannelId channel_id);
static DialogId get_participant_dialog_id(const td_api::object_ptr<td_api::MessageSender> &participant_id);
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);
@ -525,8 +527,7 @@ class ContactsManager : public Actor {
void ban_dialog_participant(DialogId dialog_id, UserId user_id, int32 banned_until_date, bool revoke_messages,
Promise<Unit> &&promise);
DialogParticipant get_dialog_participant(DialogId dialog_id,
const td_api::object_ptr<td_api::MessageSender> &member_id, int64 &random_id,
DialogParticipant get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id, int64 &random_id,
bool force, Promise<Unit> &&promise);
void search_dialog_participants(DialogId dialog_id, const string &query, int32 limit, DialogParticipantsFilter filter,

View File

@ -1940,31 +1940,30 @@ class UpgradeGroupChatToSupergroupChatRequest : public RequestActor<> {
class GetChatMemberRequest : public RequestActor<> {
DialogId dialog_id_;
td_api::object_ptr<td_api::MessageSender> member_id_;
DialogId participant_dialog_id_;
int64 random_id_;
DialogParticipant dialog_participant_;
void do_run(Promise<Unit> &&promise) override {
dialog_participant_ = td->contacts_manager_->get_dialog_participant(dialog_id_, member_id_, random_id_,
dialog_participant_ = td->contacts_manager_->get_dialog_participant(dialog_id_, participant_dialog_id_, random_id_,
get_tries() < 3, std::move(promise));
}
void do_send_result() override {
auto dialog_id = dialog_participant_.dialog_id;
if ((dialog_id.get_type() == DialogType::User && !td->contacts_manager_->have_user(dialog_id.get_user_id())) ||
!td->messages_manager_->have_dialog(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 send_error(Status::Error(3, "Member not found"));
}
send_result(td->contacts_manager_->get_chat_member_object(dialog_participant_));
}
public:
GetChatMemberRequest(ActorShared<Td> td, uint64 request_id, int64 dialog_id,
td_api::object_ptr<td_api::MessageSender> &&member_id)
GetChatMemberRequest(ActorShared<Td> td, uint64 request_id, int64 dialog_id, DialogId participant_dialog_id)
: RequestActor(std::move(td), request_id)
, dialog_id_(dialog_id)
, member_id_(std::move(member_id))
, participant_dialog_id_(participant_dialog_id)
, random_id_(0) {
set_tries(3);
}
@ -6377,7 +6376,8 @@ void Td::on_request(uint64 id, td_api::transferChatOwnership &request) {
}
void Td::on_request(uint64 id, td_api::getChatMember &request) {
CREATE_REQUEST(GetChatMemberRequest, request.chat_id_, std::move(request.member_id_));
CREATE_REQUEST(GetChatMemberRequest, request.chat_id_,
ContactsManager::get_participant_dialog_id(request.member_id_));
}
void Td::on_request(uint64 id, td_api::searchChatMembers &request) {