From d732789cacda23d5ff936c885f451e42e0f82a5b Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 2 Nov 2021 17:21:36 +0300 Subject: [PATCH] Disallow member_limit for links requiring administrator approval. --- td/generate/scheme/td_api.tl | 8 ++++---- td/telegram/ContactsManager.cpp | 8 ++++++++ td/telegram/DialogInviteLink.cpp | 4 ++++ td/telegram/DialogInviteLink.h | 3 +++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 5f3b2b23e..5462d5984 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -569,10 +569,10 @@ supergroupMembersFilterBots = SupergroupMembersFilter; //@date Point in time (Unix timestamp) when the link was created //@edit_date Point in time (Unix timestamp) when the link was last edited; 0 if never or unknown //@expire_date Point in time (Unix timestamp) when the link will expire; 0 if never -//@member_limit The maximum number of members, which can join the chat using the link simultaneously; 0 if not limited +//@member_limit The maximum number of members, which can join the chat using the link simultaneously; 0 if not limited. Always 0 if the link requires approval //@member_count Number of chat members, which joined the chat using the link //@pending_join_request_count Number of pending join requests, created using this link -//@requires_approval True, if users joining the chat by the link need to be approved by chat administrators +//@requires_approval True, if users joining the chat by the link need to be approved by chat administrators. If true, total number of joining members will be unlimited //@is_primary True, if the link is primary. Primary invite link can't have title, expire date or usage limit. There is exactly one primary invite link for each administrator with can_invite_users right at a given time //@is_revoked True, if the link was revoked chatInviteLink invite_link:string title:string creator_user_id:int53 date:int32 edit_date:int32 expire_date:int32 member_limit:int32 member_count:int32 pending_join_request_count:int32 requires_approval:Bool is_primary:Bool is_revoked:Bool = ChatInviteLink; @@ -4933,7 +4933,7 @@ replacePrimaryChatInviteLink chat_id:int53 = ChatInviteLink; //@title Invite link title; 0-32 characters //@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 -//@requires_approval True, if users joining the chat by the link need to be approved by chat administrators +//@requires_approval True, if users joining the chat by the link need to be approved by chat administrators. If true, member_limit must not be specified createChatInviteLink chat_id:int53 title:string 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 @@ -4942,7 +4942,7 @@ createChatInviteLink chat_id:int53 title:string expire_date:int32 member_limit:i //@title Invite link title; 0-32 characters //@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 -//@requires_approval True, if users joining the chat by the link need to be approved by chat administrators +//@requires_approval True, if users joining the chat by the link need to be approved by chat administrators. If true, member_limit must not be specified editChatInviteLink chat_id:int53 invite_link:string title: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 diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 19c9afe36..a7433639f 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -7459,6 +7459,10 @@ void ContactsManager::export_dialog_invite_link_impl(DialogId dialog_id, string Promise> &&promise) { TRY_STATUS_PROMISE(promise, G()->close_status()); TRY_STATUS_PROMISE(promise, can_manage_dialog_invite_links(dialog_id)); + if (requires_approval && usage_limit > 0) { + return promise.set_error( + Status::Error(400, "Member limit can't be specified for links requiring administrator approval")); + } auto new_title = clean_name(std::move(title), MAX_INVITE_LINK_TITLE_LENGTH); td_->create_handler(std::move(promise)) @@ -7469,6 +7473,10 @@ void ContactsManager::edit_dialog_invite_link(DialogId dialog_id, const string & int32 expire_date, int32 usage_limit, bool requires_approval, Promise> &&promise) { TRY_STATUS_PROMISE(promise, can_manage_dialog_invite_links(dialog_id)); + if (requires_approval && usage_limit > 0) { + return promise.set_error( + Status::Error(400, "Member limit can't be specified for links requiring administrator approval")); + } if (invite_link.empty()) { return promise.set_error(Status::Error(400, "Invite link must be non-empty")); diff --git a/td/telegram/DialogInviteLink.cpp b/td/telegram/DialogInviteLink.cpp index 3cc8e2324..6ab4ba74c 100644 --- a/td/telegram/DialogInviteLink.cpp +++ b/td/telegram/DialogInviteLink.cpp @@ -71,6 +71,10 @@ DialogInviteLink::DialogInviteLink(tl_object_ptr 0) { + LOG(ERROR) << "Receive wrong permanent " << *this; + usage_limit_ = 0; + } } bool DialogInviteLink::is_valid_invite_link(Slice invite_link) { diff --git a/td/telegram/DialogInviteLink.h b/td/telegram/DialogInviteLink.h index accfdd396..5d020f421 100644 --- a/td/telegram/DialogInviteLink.h +++ b/td/telegram/DialogInviteLink.h @@ -146,6 +146,9 @@ class DialogInviteLink { if (has_title) { parse(title_, parser); } + if (requires_approval_) { + usage_limit_ = 0; + } } };