Improve error messages for invalid member_id parameters.
This commit is contained in:
parent
1a472ae415
commit
e649098194
@ -14521,15 +14521,26 @@ 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) {
|
||||
Result<DialogId> ContactsManager::get_participant_dialog_id(
|
||||
const td_api::object_ptr<td_api::MessageSender> &participant_id) {
|
||||
if (participant_id == nullptr) {
|
||||
return DialogId();
|
||||
return Status::Error(400, "Member identifier is not specified");
|
||||
}
|
||||
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_);
|
||||
case td_api::messageSenderUser::ID: {
|
||||
auto user_id = UserId(static_cast<const td_api::messageSenderUser *>(participant_id.get())->user_id_);
|
||||
if (!user_id.is_valid()) {
|
||||
return Status::Error(400, "Invalid user identifier specified");
|
||||
}
|
||||
return DialogId(user_id);
|
||||
}
|
||||
case td_api::messageSenderChat::ID: {
|
||||
auto dialog_id = DialogId(static_cast<const td_api::messageSenderChat *>(participant_id.get())->chat_id_);
|
||||
if (!dialog_id.is_valid()) {
|
||||
return Status::Error(400, "Invalid chat identifier specified");
|
||||
}
|
||||
return dialog_id;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return DialogId();
|
||||
@ -14583,9 +14594,12 @@ void ContactsManager::add_dialog_participants(DialogId dialog_id, const vector<U
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::set_dialog_participant_status(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
void ContactsManager::set_dialog_participant_status(DialogId dialog_id,
|
||||
const tl_object_ptr<td_api::MessageSender> &participant_id,
|
||||
const tl_object_ptr<td_api::ChatMemberStatus> &chat_member_status,
|
||||
Promise<Unit> &&promise) {
|
||||
TRY_RESULT_PROMISE(promise, participant_dialog_id, get_participant_dialog_id(participant_id));
|
||||
|
||||
auto status = get_dialog_participant_status(chat_member_status);
|
||||
if (!td_->messages_manager_->have_dialog_force(dialog_id, "set_dialog_participant_status")) {
|
||||
return promise.set_error(Status::Error(3, "Chat not found"));
|
||||
@ -14615,8 +14629,11 @@ void ContactsManager::set_dialog_participant_status(DialogId dialog_id, DialogId
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::ban_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
void ContactsManager::ban_dialog_participant(DialogId dialog_id,
|
||||
const tl_object_ptr<td_api::MessageSender> &participant_id,
|
||||
int32 banned_until_date, bool revoke_messages, Promise<Unit> &&promise) {
|
||||
TRY_RESULT_PROMISE(promise, participant_dialog_id, get_participant_dialog_id(participant_id));
|
||||
|
||||
if (!td_->messages_manager_->have_dialog_force(dialog_id, "ban_dialog_participant")) {
|
||||
return promise.set_error(Status::Error(3, "Chat not found"));
|
||||
}
|
||||
@ -14641,8 +14658,17 @@ void ContactsManager::ban_dialog_participant(DialogId dialog_id, DialogId partic
|
||||
}
|
||||
}
|
||||
|
||||
DialogParticipant ContactsManager::get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
DialogParticipant ContactsManager::get_dialog_participant(DialogId dialog_id,
|
||||
const tl_object_ptr<td_api::MessageSender> &participant_id,
|
||||
int64 &random_id, bool force, Promise<Unit> &&promise) {
|
||||
// TODO TRY_RESULT_PROMISE(promise, participant_dialog_id, get_participant_dialog_id(participant_id));
|
||||
auto r_participant_dialog_id = get_participant_dialog_id(participant_id);
|
||||
if (r_participant_dialog_id.is_error()) {
|
||||
promise.set_error(r_participant_dialog_id.move_as_error());
|
||||
return {};
|
||||
}
|
||||
auto participant_dialog_id = r_participant_dialog_id.move_as_ok();
|
||||
|
||||
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")) {
|
||||
@ -14650,11 +14676,6 @@ DialogParticipant ContactsManager::get_dialog_participant(DialogId dialog_id, Di
|
||||
return DialogParticipant();
|
||||
}
|
||||
|
||||
if (!participant_dialog_id.is_valid()) {
|
||||
promise.set_error(Status::Error(3, "Invalid member identifier specified"));
|
||||
return DialogParticipant();
|
||||
}
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
if (participant_dialog_id == DialogId(get_my_id())) {
|
||||
|
@ -509,20 +509,19 @@ class ContactsManager final : 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);
|
||||
|
||||
void set_dialog_participant_status(DialogId dialog_id, DialogId participant_dialog_id,
|
||||
void set_dialog_participant_status(DialogId dialog_id, const tl_object_ptr<td_api::MessageSender> &participant_id,
|
||||
const tl_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 ban_dialog_participant(DialogId dialog_id, const tl_object_ptr<td_api::MessageSender> &participant_id,
|
||||
int32 banned_until_date, bool revoke_messages, Promise<Unit> &&promise);
|
||||
|
||||
DialogParticipant get_dialog_participant(DialogId dialog_id, DialogId participant_dialog_id, int64 &random_id,
|
||||
DialogParticipant get_dialog_participant(DialogId dialog_id,
|
||||
const tl_object_ptr<td_api::MessageSender> &participant_id, int64 &random_id,
|
||||
bool force, Promise<Unit> &&promise);
|
||||
|
||||
void search_dialog_participants(DialogId dialog_id, const string &query, int32 limit, DialogParticipantsFilter filter,
|
||||
@ -1387,6 +1386,8 @@ class ContactsManager final : public Actor {
|
||||
|
||||
bool update_permanent_invite_link(DialogInviteLink &invite_link, DialogInviteLink new_invite_link);
|
||||
|
||||
static Result<DialogId> get_participant_dialog_id(const td_api::object_ptr<td_api::MessageSender> &participant_id);
|
||||
|
||||
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, Promise<Unit> &&promise,
|
||||
|
@ -1945,30 +1945,32 @@ class UpgradeGroupChatToSupergroupChatRequest final : public RequestActor<> {
|
||||
|
||||
class GetChatMemberRequest final : public RequestActor<> {
|
||||
DialogId dialog_id_;
|
||||
DialogId participant_dialog_id_;
|
||||
tl_object_ptr<td_api::MessageSender> participant_id_;
|
||||
int64 random_id_;
|
||||
|
||||
DialogParticipant dialog_participant_;
|
||||
|
||||
void do_run(Promise<Unit> &&promise) final {
|
||||
dialog_participant_ = td->contacts_manager_->get_dialog_participant(dialog_id_, participant_dialog_id_, random_id_,
|
||||
dialog_participant_ = td->contacts_manager_->get_dialog_participant(dialog_id_, participant_id_, random_id_,
|
||||
get_tries() < 3, std::move(promise));
|
||||
}
|
||||
|
||||
void do_send_result() final {
|
||||
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_))) {
|
||||
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 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, DialogId participant_dialog_id)
|
||||
GetChatMemberRequest(ActorShared<Td> td, uint64 request_id, int64 dialog_id,
|
||||
tl_object_ptr<td_api::MessageSender> participant_id)
|
||||
: RequestActor(std::move(td), request_id)
|
||||
, dialog_id_(dialog_id)
|
||||
, participant_dialog_id_(participant_dialog_id)
|
||||
, participant_id_(std::move(participant_id))
|
||||
, random_id_(0) {
|
||||
set_tries(3);
|
||||
}
|
||||
@ -6435,8 +6437,9 @@ 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, DialogId(contacts_manager_->get_my_id()),
|
||||
std::move(new_status), std::move(promise));
|
||||
contacts_manager_->set_dialog_participant_status(
|
||||
dialog_id, td_api::make_object<td_api::messageSenderUser>(contacts_manager_->get_my_id().get()),
|
||||
std::move(new_status), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::addChatMember &request) {
|
||||
@ -6455,15 +6458,13 @@ void Td::on_request(uint64 id, const td_api::addChatMembers &request) {
|
||||
|
||||
void Td::on_request(uint64 id, td_api::setChatMemberStatus &request) {
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
contacts_manager_->set_dialog_participant_status(DialogId(request.chat_id_),
|
||||
ContactsManager::get_participant_dialog_id(request.member_id_),
|
||||
contacts_manager_->set_dialog_participant_status(DialogId(request.chat_id_), std::move(request.member_id_),
|
||||
request.status_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::banChatMember &request) {
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
contacts_manager_->ban_dialog_participant(DialogId(request.chat_id_),
|
||||
ContactsManager::get_participant_dialog_id(request.member_id_),
|
||||
contacts_manager_->ban_dialog_participant(DialogId(request.chat_id_), std::move(request.member_id_),
|
||||
request.banned_until_date_, request.revoke_messages_, std::move(promise));
|
||||
}
|
||||
|
||||
@ -6490,8 +6491,7 @@ 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_,
|
||||
ContactsManager::get_participant_dialog_id(request.member_id_));
|
||||
CREATE_REQUEST(GetChatMemberRequest, request.chat_id_, std::move(request.member_id_));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::searchChatMembers &request) {
|
||||
|
Loading…
Reference in New Issue
Block a user