Add td_api::getChatInviteLinkCounts.

This commit is contained in:
levlam 2021-02-02 19:23:45 +03:00
parent 0cdb0388ee
commit f2f68aa3b3
7 changed files with 108 additions and 23 deletions

View File

@ -559,6 +559,12 @@ chatInviteLink invite_link:string administrator_user_id:int32 date:int32 edit_da
//@description Contains a list of chat invite links @total_count Approximate total count of chat invite links found @invite_links List of invite links
chatInviteLinks total_count:int32 invite_links:vector<chatInviteLink> = ChatInviteLinks;
//@description Describes a chat administrator with a number of active chat invite links @user_id Administrator's user identifier @invite_link_count Number of active invite links
chatInviteLinkCount user_id:int32 invite_link_count:int32 = ChatInviteLinkCount;
//@description Contains a list of chat invite link counts @invite_link_counts List of invite linkcounts
chatInviteLinkCounts invite_link_counts:vector<chatInviteLinkCount> = ChatInviteLinkCounts;
//@description Describes a chat member joined a chat by an invite link @user_id User identifier @joined_chat_date Point in time (Unix timestamp) when the user joined the chat
chatInviteLinkMember user_id:int32 joined_chat_date:int32 = ChatInviteLinkMember;
@ -4425,35 +4431,38 @@ replacePermanentChatInviteLink chat_id:int53 = ChatInviteLink;
//@member_limit Maximum number of chat members that can join the chat by the link simultaneously; 0-100000; pass 0 if not limited
createChatInviteLink chat_id:int53 expire_date:int32 member_limit:int32 = ChatInviteLink;
//@description Edits a non-permanent invite link for a chat. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right in the chat
//@description Edits a non-permanent invite link for a chat. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right in the chat for own links and owner privileges for other links
//@chat_id Chat identifier
//@invite_link Invite link to be edited
//@expire_date Point in time (Unix timestamp) when the link will expire; pass 0 if never
//@member_limit Maximum number of chat members that can join the chat by the link simultaneously; 0-100000; pass 0 if not limited
editChatInviteLink chat_id:int53 invite_link:string expire_date:int32 member_limit:int32 = ChatInviteLink;
//@description Returns invite links for a chat created by specified administrator. Requires administrator privileges and can_invite_users right in the chat
//@description Returns list of chat administrators with number of active invite links. Requires owner privileges in the chat @chat_id Chat identifier
getChatInviteLinkCounts chat_id:int53 = ChatInviteLinkCounts;
//@description Returns invite links for a chat created by specified administrator. 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
//@administrator_user_id User identifier of a chat administrator
//@administrator_user_id User identifier of a chat administrator. Must be an identifier of the current user for non-owner
//@is_revoked Pass true if revoked links needs to be returned instead of active or expired
//@offset_date Creation date of an invite link starting after which to return invite links; use 0 to get results from the beginning
//@offset_invite_link Invite link starting after which to return invite links; use empty string to get results from the beginning
//@limit Maximum number of invite links to return
getChatInviteLinks chat_id:int53 administrator_user_id:int32 is_revoked:Bool offset_date:int32 offset_invite_link:string limit:int32 = ChatInviteLinks;
//@description Returns chat members joined a chat by an invite link. Requires administrator privileges and can_invite_users right in the chat @chat_id Chat identifier @invite_link Invite link for which to return chat members
//@description Returns chat members joined a chat by an invite link. Requires administrator privileges and can_invite_users right in the chat for own links and owner privileges for other links @chat_id Chat identifier @invite_link Invite link for which to return chat members
//@offset_member A chat member from which to return next chat members; use null to get results from the beginning @limit Maximum number of chat members to return
getChatInviteLinkMembers chat_id:int53 invite_link:string offset_member:chatInviteLinkMember limit:int32 = ChatInviteLinkMembers;
//@description Revokes a non-permanent invite link for a chat. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right in the chat
//@description Revokes a non-permanent invite link for a chat. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right in the chat for own links and owner privileges for other links
//@chat_id Chat identifier
//@invite_link Invite link to be revoked
revokeChatInviteLink chat_id:int53 invite_link:string = ChatInviteLink;
//@description Deletes revoked chat invite links. Requires administrator privileges and can_invite_users right in the chat @chat_id Chat identifier @invite_link Invite link to revoke
//@description Deletes revoked chat invite links. Requires administrator privileges and can_invite_users right in the chat for own links and owner privileges for other links @chat_id Chat identifier @invite_link Invite link to revoke
deleteRevokedChatInviteLink chat_id:int53 invite_link:string = Ok;
//@description Deletes all revoked chat invite links. Requires administrator privileges and can_invite_users right in the chat @chat_id Chat identifier
//@description Deletes all revoked chat invite links. Requires administrator privileges and can_invite_users right in the chat for own links and owner privileges for other links @chat_id Chat identifier
deleteAllRevokedChatInviteLinks chat_id:int53 = Ok;
//@description Checks the validity of an invite link for a chat and returns information about the corresponding chat @invite_link Invite link to be checked; must begin with "https://t.me/joinchat/", "https://telegram.me/joinchat/", or "https://telegram.dog/joinchat/"

Binary file not shown.

View File

@ -1578,7 +1578,7 @@ class ExportChatInviteLinkQuery : public Td::ResultHandler {
void send(DialogId dialog_id, int32 expire_date, int32 usage_limit, bool is_permanent) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
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"));
}
@ -1637,7 +1637,7 @@ class EditChatInviteLinkQuery : public Td::ResultHandler {
void send(DialogId dialog_id, const string &invite_link, int32 expire_date, int32 usage_limit, bool is_revoked) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
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"));
}
@ -1687,7 +1687,7 @@ class GetExportedChatInvitesQuery : public Td::ResultHandler {
void send(DialogId dialog_id, UserId administrator_user_id, bool is_revoked, int32 offset_date,
const string &offset_invite_link, int32 limit) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
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"));
}
@ -1743,6 +1743,55 @@ class GetExportedChatInvitesQuery : public Td::ResultHandler {
}
};
class GetChatAdminWithInvitesQuery : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::chatInviteLinkCounts>> promise_;
DialogId dialog_id_;
public:
explicit GetChatAdminWithInvitesQuery(Promise<td_api::object_ptr<td_api::chatInviteLinkCounts>> &&promise)
: promise_(std::move(promise)) {
}
void send(DialogId dialog_id) {
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_getAdminsWithInvites(std::move(input_peer))));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::messages_getAdminsWithInvites>(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 GetChatAdminWithInvitesQuery: " << to_string(result);
td->contacts_manager_->on_get_users(std::move(result->users_), "GetChatAdminWithInvitesQuery");
vector<td_api::object_ptr<td_api::chatInviteLinkCount>> invite_link_counts;
for (auto &admin : result->admins_) {
UserId user_id(admin->admin_id_);
if (!user_id.is_valid()) {
LOG(ERROR) << "Receive invalid invite link creator " << user_id << " in " << dialog_id_;
continue;
}
invite_link_counts.push_back(td_api::make_object<td_api::chatInviteLinkCount>(
td->contacts_manager_->get_user_id_object(user_id, "chatInviteLinkCount"), admin->invites_count_));
}
promise_.set_value(td_api::make_object<td_api::chatInviteLinkCounts>(std::move(invite_link_counts)));
}
void on_error(uint64 id, Status status) override {
td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetChatAdminWithInvitesQuery");
promise_.set_error(std::move(status));
}
};
class GetChatInviteImportersQuery : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::chatInviteLinkMembers>> promise_;
DialogId dialog_id_;
@ -1754,7 +1803,7 @@ class GetChatInviteImportersQuery : public Td::ResultHandler {
void send(DialogId dialog_id, const string &invite_link, int32 offset_date, UserId offset_user_id, int32 limit) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
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"));
}
@ -1814,7 +1863,7 @@ class DeleteExportedChatInviteQuery : public Td::ResultHandler {
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::Read);
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"));
}
@ -1848,7 +1897,7 @@ class DeleteRevokedExportedChatInvitesQuery : public Td::ResultHandler {
void send(DialogId dialog_id) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
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"));
}
@ -6809,7 +6858,7 @@ void ContactsManager::transfer_channel_ownership(
->send(channel_id, user_id, std::move(input_check_password));
}
Status ContactsManager::can_manage_dialog_invite_links(DialogId dialog_id) {
Status ContactsManager::can_manage_dialog_invite_links(DialogId dialog_id, bool creator_only) {
if (!td_->messages_manager_->have_dialog_force(dialog_id)) {
return Status::Error(3, "Chat not found");
}
@ -6825,7 +6874,9 @@ Status ContactsManager::can_manage_dialog_invite_links(DialogId dialog_id) {
if (!c->is_active) {
return Status::Error(3, "Chat is deactivated");
}
if (!get_chat_status(c).is_administrator() || !get_chat_status(c).can_invite_users()) {
auto status = get_chat_status(c);
bool have_rights = creator_only ? status.is_creator() : status.is_administrator() && status.can_invite_users();
if (!have_rights) {
return Status::Error(3, "Not enough rights to manage chat invite link");
}
break;
@ -6835,7 +6886,9 @@ Status ContactsManager::can_manage_dialog_invite_links(DialogId dialog_id) {
if (c == nullptr) {
return Status::Error(3, "Chat info not found");
}
if (!get_channel_status(c).is_administrator() || !get_channel_status(c).can_invite_users()) {
auto status = get_channel_status(c);
bool have_rights = creator_only ? status.is_creator() : status.is_administrator() && status.can_invite_users();
if (!have_rights) {
return Status::Error(3, "Not enough rights to manage chat invite link");
}
break;
@ -6889,10 +6942,17 @@ void ContactsManager::edit_dialog_invite_link(DialogId dialog_id, const string &
->send(dialog_id, invite_link, expire_date, usage_limit, is_revoked);
}
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));
td_->create_handler<GetChatAdminWithInvitesQuery>(std::move(promise))->send(dialog_id);
}
void ContactsManager::get_dialog_invite_links(DialogId dialog_id, UserId administrator_user_id, bool is_revoked,
int32 offset_date, const string &offset_invite_link, int32 limit,
Promise<td_api::object_ptr<td_api::chatInviteLinks>> &&promise) {
TRY_STATUS_PROMISE(promise, can_manage_dialog_invite_links(dialog_id));
TRY_STATUS_PROMISE(promise, can_manage_dialog_invite_links(dialog_id, administrator_user_id != get_my_id()));
if (!have_input_user(administrator_user_id)) {
return promise.set_error(Status::Error(400, "Administrator user not found"));

View File

@ -389,6 +389,9 @@ class ContactsManager : public Actor {
void edit_dialog_invite_link(DialogId dialog_id, const string &link, int32 expire_date, int32 usage_limit,
bool is_revoked, 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);
void get_dialog_invite_links(DialogId dialog_id, UserId administrator_user_id, bool is_revoked, int32 offset_date,
const string &offset_invite_link, int32 limit,
Promise<td_api::object_ptr<td_api::chatInviteLinks>> &&promise);
@ -1371,7 +1374,7 @@ class ContactsManager : public Actor {
void remove_dialog_access_by_invite_link(DialogId dialog_id);
Status can_manage_dialog_invite_links(DialogId dialog_id);
Status can_manage_dialog_invite_links(DialogId dialog_id, bool creator_only = false);
bool update_permanent_invite_link(DialogInviteLink &invite_link, DialogInviteLink new_invite_link);

View File

@ -6322,14 +6322,14 @@ void Td::on_request(uint64 id, td_api::editChatInviteLink &request) {
request.member_limit_, false, std::move(promise));
}
void Td::on_request(uint64 id, td_api::revokeChatInviteLink &request) {
CLEAN_INPUT_STRING(request.invite_link_);
void Td::on_request(uint64 id, const td_api::getChatInviteLinkCounts &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
contacts_manager_->edit_dialog_invite_link(DialogId(request.chat_id_), request.invite_link_, 0, 0, true,
std::move(promise));
contacts_manager_->get_dialog_invite_link_counts(DialogId(request.chat_id_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::getChatInviteLinks &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.offset_invite_link_);
CREATE_REQUEST_PROMISE();
contacts_manager_->get_dialog_invite_links(DialogId(request.chat_id_), UserId(request.administrator_user_id_),
@ -6338,6 +6338,7 @@ void Td::on_request(uint64 id, td_api::getChatInviteLinks &request) {
}
void Td::on_request(uint64 id, td_api::getChatInviteLinkMembers &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.invite_link_);
CREATE_REQUEST_PROMISE();
contacts_manager_->get_dialog_invite_link_users(DialogId(request.chat_id_), request.invite_link_,
@ -6345,6 +6346,13 @@ void Td::on_request(uint64 id, td_api::getChatInviteLinkMembers &request) {
std::move(promise));
}
void Td::on_request(uint64 id, td_api::revokeChatInviteLink &request) {
CLEAN_INPUT_STRING(request.invite_link_);
CREATE_REQUEST_PROMISE();
contacts_manager_->edit_dialog_invite_link(DialogId(request.chat_id_), request.invite_link_, 0, 0, true,
std::move(promise));
}
void Td::on_request(uint64 id, td_api::deleteRevokedChatInviteLink &request) {
CLEAN_INPUT_STRING(request.invite_link_);
CREATE_OK_REQUEST_PROMISE();

View File

@ -798,12 +798,14 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::editChatInviteLink &request);
void on_request(uint64 id, td_api::revokeChatInviteLink &request);
void on_request(uint64 id, const td_api::getChatInviteLinkCounts &request);
void on_request(uint64 id, td_api::getChatInviteLinks &request);
void on_request(uint64 id, td_api::getChatInviteLinkMembers &request);
void on_request(uint64 id, td_api::revokeChatInviteLink &request);
void on_request(uint64 id, td_api::deleteRevokedChatInviteLink &request);
void on_request(uint64 id, const td_api::deleteAllRevokedChatInviteLinks &request);

View File

@ -2715,6 +2715,9 @@ class CliClient final : public Actor {
string invite_link;
get_args(args, chat_id, invite_link);
send_request(td_api::make_object<td_api::revokeChatInviteLink>(as_chat_id(chat_id), invite_link));
} 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") {
string chat_id;
string administrator_user_id;