Add approve/declineCjatJoinRequest.

This commit is contained in:
levlam 2021-10-13 23:10:47 +03:00
parent 1a7f4b4d3e
commit 0a9f6b1c91
6 changed files with 85 additions and 0 deletions

View File

@ -4942,6 +4942,12 @@ joinChatByInviteLink invite_link:string = Chat;
//@limit The maximum number of chat join requests to return
getChatJoinRequests chat_id:int53 invite_link:string query:string offset_request:chatJoinRequest limit:int32 = ChatJoinRequests;
//@description Approves pending join request in a chat @chat_id Chat identifier @user_id Identifier of the user, which request will be approved
approveChatJoinRequest chat_id:int53 user_id:int53 = Ok;
//@description Declines pending join request in a chat @chat_id Chat identifier @user_id Identifier of the user, which request will be declined
declineChatJoinRequest chat_id:int53 user_id:int53 = Ok;
//@description Creates a new call @user_id Identifier of the user to be called @protocol Description of the call protocols supported by the application @is_video True, if a video call needs to be created
createCall user_id:int53 protocol:callProtocol is_video:Bool = CallId;

View File

@ -2023,6 +2023,51 @@ class GetChatJoinRequestsQuery final : public Td::ResultHandler {
}
};
class HideChatJoinRequestQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
DialogId dialog_id_;
public:
explicit HideChatJoinRequestQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(DialogId dialog_id, UserId user_id, bool is_approved) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
return on_error(0, Status::Error(400, "Can't access the chat"));
}
auto input_user = td->contacts_manager_->get_input_user(user_id);
if (input_user == nullptr) {
return on_error(0, Status::Error(400, "Can't find user"));
}
int32 flags = 0;
if (is_approved) {
flags |= telegram_api::messages_hideChatJoinRequest::APPROVED_MASK;
}
send_query(G()->net_query_creator().create(telegram_api::messages_hideChatJoinRequest(
flags, false /*ignored*/, std::move(input_peer), std::move(input_user))));
}
void on_result(uint64 id, BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_hideChatJoinRequest>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
auto result = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for HideChatJoinRequestQuery: " << to_string(result);
td->updates_manager_->on_get_updates(std::move(result), std::move(promise_));
}
void on_error(uint64 id, Status status) final {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "HideChatJoinRequestQuery");
promise_.set_error(std::move(status));
}
};
class RevokeChatInviteLinkQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::chatInviteLinks>> promise_;
DialogId dialog_id_;
@ -7503,6 +7548,12 @@ void ContactsManager::get_dialog_join_requests(DialogId dialog_id, const string
->send(dialog_id, invite_link, query, offset_date, offset_user_id, limit);
}
void ContactsManager::process_dialog_join_requests(DialogId dialog_id, UserId user_id, bool is_approved,
Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, can_manage_dialog_invite_links(dialog_id));
td_->create_handler<HideChatJoinRequestQuery>(std::move(promise))->send(dialog_id, user_id, is_approved);
}
void ContactsManager::revoke_dialog_invite_link(DialogId dialog_id, const string &invite_link,
Promise<td_api::object_ptr<td_api::chatInviteLinks>> &&promise) {
TRY_STATUS_PROMISE(promise, can_manage_dialog_invite_links(dialog_id));

View File

@ -408,6 +408,8 @@ class ContactsManager final : public Actor {
td_api::object_ptr<td_api::chatJoinRequest> offset_request, int32 limit,
Promise<td_api::object_ptr<td_api::chatJoinRequests>> &&promise);
void process_dialog_join_requests(DialogId dialog_id, UserId user_id, bool is_approved, Promise<Unit> &&promise);
void revoke_dialog_invite_link(DialogId dialog_id, const string &link,
Promise<td_api::object_ptr<td_api::chatInviteLinks>> &&promise);

View File

@ -6341,6 +6341,18 @@ void Td::on_request(uint64 id, td_api::getChatJoinRequests &request) {
std::move(request.offset_request_), request.limit_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::approveChatJoinRequest &request) {
CREATE_OK_REQUEST_PROMISE();
contacts_manager_->process_dialog_join_requests(DialogId(request.chat_id_), UserId(request.user_id_), true,
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::declineChatJoinRequest &request) {
CREATE_OK_REQUEST_PROMISE();
contacts_manager_->process_dialog_join_requests(DialogId(request.chat_id_), UserId(request.user_id_), false,
std::move(promise));
}
void Td::on_request(uint64 id, td_api::revokeChatInviteLink &request) {
CLEAN_INPUT_STRING(request.invite_link_);
CREATE_REQUEST_PROMISE();

View File

@ -872,6 +872,10 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::getChatJoinRequests &request);
void on_request(uint64 id, const td_api::approveChatJoinRequest &request);
void on_request(uint64 id, const td_api::declineChatJoinRequest &request);
void on_request(uint64 id, td_api::revokeChatInviteLink &request);
void on_request(uint64 id, td_api::deleteRevokedChatInviteLink &request);

View File

@ -2998,6 +2998,16 @@ class CliClient final : public Actor {
as_chat_id(chat_id), invite_link, query,
td_api::make_object<td_api::chatJoinRequest>(as_user_id(offset_user_id), offset_date, string()),
as_limit(limit)));
} else if (op == "acjr") {
string chat_id;
string user_id;
get_args(args, chat_id, user_id);
send_request(td_api::make_object<td_api::approveChatJoinRequest>(as_chat_id(chat_id), as_user_id(user_id)));
} else if (op == "dcjr") {
string chat_id;
string user_id;
get_args(args, chat_id, user_id);
send_request(td_api::make_object<td_api::declineChatJoinRequest>(as_chat_id(chat_id), as_user_id(user_id)));
} else if (op == "drcil") {
string chat_id;
string invite_link;