Add td_api::getChatInviteLink.

This commit is contained in:
levlam 2021-02-24 22:25:10 +03:00
parent 37adbece28
commit 1e7795354d
7 changed files with 80 additions and 1 deletions

View File

@ -4482,6 +4482,11 @@ createChatInviteLink chat_id:int53 expire_date:int32 member_limit:int32 = ChatIn
//@member_limit Maximum number of chat members that can join the chat by the link simultaneously; 0-99999; pass 0 if not limited
editChatInviteLink chat_id:int53 invite_link:string expire_date:int32 member_limit:int32 = ChatInviteLink;
//@description Returns information about an invite link. Requires administrator privileges and can_invite_users right in the chat to get own links and owner privileges to get other links
//@chat_id Chat identifier
//@invite_link Invite link to get
getChatInviteLink chat_id:int53 invite_link:string = ChatInviteLink;
//@description Returns list of chat administrators with number of their invite links. Requires owner privileges in the chat @chat_id Chat identifier
getChatInviteLinkCounts chat_id:int53 = ChatInviteLinkCounts;

Binary file not shown.

View File

@ -1751,6 +1751,56 @@ class EditChatInviteLinkQuery : public Td::ResultHandler {
}
};
class GetExportedChatInviteQuery : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::chatInviteLink>> promise_;
DialogId dialog_id_;
public:
explicit GetExportedChatInviteQuery(Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise)
: promise_(std::move(promise)) {
}
void send(DialogId dialog_id, const string &invite_link) {
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"));
}
send_query(G()->net_query_creator().create(
telegram_api::messages_getExportedChatInvite(std::move(input_peer), invite_link)));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::messages_getExportedChatInvite>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
if (result_ptr.ok()->get_id() != telegram_api::messages_exportedChatInvite::ID) {
LOG(ERROR) << "Receive result for GetExportedChatInviteQuery: " << to_string(result_ptr.ok());
return on_error(id, Status::Error(500, "Receive unexpected response"));
}
auto result = move_tl_object_as<telegram_api::messages_exportedChatInvite>(result_ptr.ok_ref());
LOG(INFO) << "Receive result for GetExportedChatInviteQuery: " << to_string(result);
td->contacts_manager_->on_get_users(std::move(result->users_), "GetExportedChatInviteQuery");
DialogInviteLink invite_link(std::move(result->invite_));
if (!invite_link.is_valid()) {
LOG(ERROR) << "Receive invalid invite link in " << dialog_id_;
return on_error(id, Status::Error(500, "Receive invalid invite link"));
}
promise_.set_value(invite_link.get_chat_invite_link_object(td->contacts_manager_.get()));
}
void on_error(uint64 id, Status status) override {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetExportedChatInviteQuery");
promise_.set_error(std::move(status));
}
};
class GetExportedChatInvitesQuery : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::chatInviteLinks>> promise_;
DialogId dialog_id_;
@ -7115,6 +7165,13 @@ void ContactsManager::edit_dialog_invite_link(DialogId dialog_id, const string &
->send(dialog_id, invite_link, expire_date, usage_limit);
}
void ContactsManager::get_dialog_invite_link(DialogId dialog_id, const string &invite_link,
Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise) {
TRY_STATUS_PROMISE(promise, can_manage_dialog_invite_links(dialog_id, false));
td_->create_handler<GetExportedChatInviteQuery>(std::move(promise))->send(dialog_id, invite_link);
}
void ContactsManager::get_dialog_invite_link_counts(
DialogId dialog_id, Promise<td_api::object_ptr<td_api::chatInviteLinkCounts>> &&promise) {
TRY_STATUS_PROMISE(promise, can_manage_dialog_invite_links(dialog_id, true));

View File

@ -397,6 +397,9 @@ class ContactsManager : public Actor {
void edit_dialog_invite_link(DialogId dialog_id, const string &link, int32 expire_date, int32 usage_limit,
Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise);
void get_dialog_invite_link(DialogId dialog_id, const string &invite_link,
Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise);
void get_dialog_invite_link_counts(DialogId dialog_id,
Promise<td_api::object_ptr<td_api::chatInviteLinkCounts>> &&promise);

View File

@ -6331,6 +6331,13 @@ void Td::on_request(uint64 id, td_api::editChatInviteLink &request) {
request.member_limit_, std::move(promise));
}
void Td::on_request(uint64 id, td_api::getChatInviteLink &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.invite_link_);
CREATE_REQUEST_PROMISE();
contacts_manager_->get_dialog_invite_link(DialogId(request.chat_id_), request.invite_link_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getChatInviteLinkCounts &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();

View File

@ -800,6 +800,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::editChatInviteLink &request);
void on_request(uint64 id, td_api::getChatInviteLink &request);
void on_request(uint64 id, const td_api::getChatInviteLinkCounts &request);
void on_request(uint64 id, td_api::getChatInviteLinks &request);

View File

@ -2744,7 +2744,12 @@ class CliClient final : public Actor {
} else if (op == "gcilc") {
string chat_id = args;
send_request(td_api::make_object<td_api::getChatInviteLinkCounts>(as_chat_id(chat_id)));
} else if (op == "gcil" || op == "gcilr") {
} else if (op == "gcil") {
string chat_id;
string invite_link;
get_args(args, chat_id, invite_link);
send_request(td_api::make_object<td_api::getChatInviteLink>(as_chat_id(chat_id), invite_link));
} else if (op == "gcils" || op == "gcilr") {
string chat_id;
string administrator_user_id;
int32 offset_date;