Allow creation and edit of invite links, requiring approval.

This commit is contained in:
levlam 2021-10-09 14:20:48 +03:00
parent 5d9a224386
commit 64d572bcbe
5 changed files with 41 additions and 29 deletions

View File

@ -4872,14 +4872,16 @@ replacePrimaryChatInviteLink chat_id:int53 = ChatInviteLink;
//@chat_id Chat identifier
//@expire_date Point in time (Unix timestamp) when the link will expire; pass 0 if never
//@member_limit The maximum number of chat members that can join the chat by the link simultaneously; 0-99999; pass 0 if not limited
createChatInviteLink chat_id:int53 expire_date:int32 member_limit:int32 = ChatInviteLink;
//@requires_approval True, if users joining the chat by the link need to be approved by chat administrators
createChatInviteLink chat_id:int53 expire_date:int32 member_limit:int32 requires_approval:Bool = ChatInviteLink;
//@description Edits a non-primary 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 The 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;
//@requires_approval True, if users joining the chat by the link need to be approved by chat administrators
editChatInviteLink chat_id:int53 invite_link:string expire_date:int32 member_limit:int32 requires_approval:Bool = 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

View File

@ -1610,7 +1610,7 @@ class ExportChatInviteQuery final : public Td::ResultHandler {
: promise_(std::move(promise)) {
}
void send(DialogId dialog_id, int32 expire_date, int32 usage_limit, bool is_permanent) {
void send(DialogId dialog_id, int32 expire_date, int32 usage_limit, bool requires_approval, bool is_permanent) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
@ -1624,6 +1624,9 @@ class ExportChatInviteQuery final : public Td::ResultHandler {
if (usage_limit > 0) {
flags |= telegram_api::messages_exportChatInvite::USAGE_LIMIT_MASK;
}
if (requires_approval) {
flags |= telegram_api::messages_exportChatInvite::REQUEST_NEEDED_MASK;
}
if (is_permanent) {
flags |= telegram_api::messages_exportChatInvite::LEGACY_REVOKE_PERMANENT_MASK;
}
@ -1669,7 +1672,8 @@ class EditChatInviteLinkQuery final : public Td::ResultHandler {
: promise_(std::move(promise)) {
}
void send(DialogId dialog_id, const string &invite_link, int32 expire_date, int32 usage_limit) {
void send(DialogId dialog_id, const string &invite_link, int32 expire_date, int32 usage_limit,
bool requires_approval) {
dialog_id_ = dialog_id;
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
@ -1677,9 +1681,11 @@ class EditChatInviteLinkQuery final : public Td::ResultHandler {
}
int32 flags = telegram_api::messages_editExportedChatInvite::EXPIRE_DATE_MASK |
telegram_api::messages_editExportedChatInvite::USAGE_LIMIT_MASK;
send_query(G()->net_query_creator().create(telegram_api::messages_editExportedChatInvite(
flags, false /*ignored*/, std::move(input_peer), invite_link, expire_date, usage_limit, false, string())));
telegram_api::messages_editExportedChatInvite::USAGE_LIMIT_MASK |
telegram_api::messages_editExportedChatInvite::REQUEST_NEEDED_MASK;
send_query(G()->net_query_creator().create(
telegram_api::messages_editExportedChatInvite(flags, false /*ignored*/, std::move(input_peer), invite_link,
expire_date, usage_limit, requires_approval, string())));
}
void on_result(uint64 id, BufferSlice packet) final {
@ -7268,31 +7274,31 @@ Status ContactsManager::can_manage_dialog_invite_links(DialogId dialog_id, bool
}
void ContactsManager::export_dialog_invite_link(DialogId dialog_id, int32 expire_date, int32 usage_limit,
bool is_permanent,
bool requires_approval, bool is_permanent,
Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise) {
get_me(PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, expire_date, usage_limit, is_permanent,
promise = std::move(promise)](Result<Unit> &&result) mutable {
get_me(PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, expire_date, usage_limit, requires_approval,
is_permanent, promise = std::move(promise)](Result<Unit> &&result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
send_closure(actor_id, &ContactsManager::export_dialog_invite_link_impl, dialog_id, expire_date, usage_limit,
is_permanent, std::move(promise));
requires_approval, is_permanent, std::move(promise));
}
}));
}
void ContactsManager::export_dialog_invite_link_impl(DialogId dialog_id, int32 expire_date, int32 usage_limit,
bool is_permanent,
bool requires_approval, bool is_permanent,
Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
TRY_STATUS_PROMISE(promise, can_manage_dialog_invite_links(dialog_id));
td_->create_handler<ExportChatInviteQuery>(std::move(promise))
->send(dialog_id, expire_date, usage_limit, is_permanent);
->send(dialog_id, expire_date, usage_limit, requires_approval, is_permanent);
}
void ContactsManager::edit_dialog_invite_link(DialogId dialog_id, const string &invite_link, int32 expire_date,
int32 usage_limit,
int32 usage_limit, bool requires_approval,
Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise) {
TRY_STATUS_PROMISE(promise, can_manage_dialog_invite_links(dialog_id));
@ -7301,7 +7307,7 @@ void ContactsManager::edit_dialog_invite_link(DialogId dialog_id, const string &
}
td_->create_handler<EditChatInviteLinkQuery>(std::move(promise))
->send(dialog_id, invite_link, expire_date, usage_limit);
->send(dialog_id, invite_link, expire_date, requires_approval, usage_limit);
}
void ContactsManager::get_dialog_invite_link(DialogId dialog_id, const string &invite_link,

View File

@ -382,11 +382,11 @@ class ContactsManager final : public Actor {
void transfer_dialog_ownership(DialogId dialog_id, UserId user_id, const string &password, Promise<Unit> &&promise);
void export_dialog_invite_link(DialogId dialog_id, int32 expire_date, int32 usage_limit, bool is_permanent,
Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise);
void export_dialog_invite_link(DialogId dialog_id, int32 expire_date, int32 usage_limit, bool requires_approval,
bool is_permanent, Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise);
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);
bool requires_approval, 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);
@ -1387,8 +1387,8 @@ class ContactsManager final : public Actor {
static bool is_channel_public(const Channel *c);
void export_dialog_invite_link_impl(DialogId dialog_id, int32 expire_date, int32 usage_limit, bool is_permanent,
Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise);
void export_dialog_invite_link_impl(DialogId dialog_id, int32 expire_date, int32 usage_limit, bool requires_approval,
bool is_permanent, Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise);
void remove_dialog_access_by_invite_link(DialogId dialog_id);

View File

@ -6285,20 +6285,20 @@ void Td::on_request(uint64 id, td_api::getChatAdministrators &request) {
void Td::on_request(uint64 id, const td_api::replacePrimaryChatInviteLink &request) {
CREATE_REQUEST_PROMISE();
contacts_manager_->export_dialog_invite_link(DialogId(request.chat_id_), 0, 0, true, std::move(promise));
contacts_manager_->export_dialog_invite_link(DialogId(request.chat_id_), 0, 0, false, true, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::createChatInviteLink &request) {
CREATE_REQUEST_PROMISE();
contacts_manager_->export_dialog_invite_link(DialogId(request.chat_id_), request.expire_date_, request.member_limit_,
false, std::move(promise));
request.requires_approval_, false, std::move(promise));
}
void Td::on_request(uint64 id, td_api::editChatInviteLink &request) {
CLEAN_INPUT_STRING(request.invite_link_);
CREATE_REQUEST_PROMISE();
contacts_manager_->edit_dialog_invite_link(DialogId(request.chat_id_), request.invite_link_, request.expire_date_,
request.member_limit_, std::move(promise));
request.member_limit_, request.requires_approval_, std::move(promise));
}
void Td::on_request(uint64 id, td_api::getChatInviteLink &request) {

View File

@ -2939,16 +2939,19 @@ class CliClient final : public Actor {
string chat_id;
int32 expire_date;
int32 member_limit;
get_args(args, chat_id, expire_date, member_limit);
send_request(td_api::make_object<td_api::createChatInviteLink>(as_chat_id(chat_id), expire_date, member_limit));
bool requires_approval;
get_args(args, chat_id, expire_date, member_limit, requires_approval);
send_request(td_api::make_object<td_api::createChatInviteLink>(as_chat_id(chat_id), expire_date, member_limit,
requires_approval));
} else if (op == "ecil") {
string chat_id;
string invite_link;
int32 expire_date;
int32 member_limit;
get_args(args, chat_id, invite_link, expire_date, member_limit);
send_request(
td_api::make_object<td_api::editChatInviteLink>(as_chat_id(chat_id), invite_link, expire_date, member_limit));
bool requires_approval;
get_args(args, chat_id, invite_link, expire_date, member_limit, requires_approval);
send_request(td_api::make_object<td_api::editChatInviteLink>(as_chat_id(chat_id), invite_link, expire_date,
member_limit, requires_approval));
} else if (op == "rcil") {
string chat_id;
string invite_link;
@ -2981,7 +2984,8 @@ class CliClient final : public Actor {
get_args(args, chat_id, invite_link, offset_user_id, offset_date, limit);
send_request(td_api::make_object<td_api::getChatInviteLinkMembers>(
as_chat_id(chat_id), invite_link,
td_api::make_object<td_api::chatInviteLinkMember>(as_user_id(offset_user_id), offset_date), as_limit(limit)));
td_api::make_object<td_api::chatInviteLinkMember>(as_user_id(offset_user_id), offset_date, 0),
as_limit(limit)));
} else if (op == "drcil") {
string chat_id;
string invite_link;