diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d42a89c9b..19728606b 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -10130,10 +10130,14 @@ replacePrimaryChatInviteLink chat_id:int53 = ChatInviteLink; //@expiration_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 via the link simultaneously; 0-99999; pass 0 if not limited //@creates_join_request Pass true if users joining the chat via the link need to be approved by chat administrators. In this case, member_limit must be 0 -//@subscription_pricing Information about subscription plan that will be applied to the users joining the chat via the link; for channel chats only; pass null if the link doesn't require subscription. -//-Subscription period must be 2592000 in production environment, and 60 or 300 if Telegram test environment is used. If non-null, then expiration_date, member_limit and creates_join_request -//-must not be used -createChatInviteLink chat_id:int53 name:string expiration_date:int32 member_limit:int32 creates_join_request:Bool subscription_pricing:starSubscriptionPricing = ChatInviteLink; +createChatInviteLink chat_id:int53 name:string expiration_date:int32 member_limit:int32 creates_join_request:Bool = ChatInviteLink; + +//@description Creates a new subscription invite link for a channel chat. Requires can_invite_users right in the chat +//@chat_id Chat identifier +//@name Invite link name; 0-32 characters +//@subscription_pricing Information about subscription plan that will be applied to the users joining the chat via the link. +//-Subscription period must be 2592000 in production environment, and 60 or 300 if Telegram test environment is used +createChatSubscriptionInviteLink chat_id:int53 name:string subscription_pricing:starSubscriptionPricing = ChatInviteLink; //@description Edits a non-primary invite link for a chat. Available for basic groups, supergroups, and channels. //-If the link creates a subscription, then expiration_date, member_limit and creates_join_request must not be used diff --git a/td/telegram/DialogInviteLinkManager.cpp b/td/telegram/DialogInviteLinkManager.cpp index 09e13646d..ba2900f22 100644 --- a/td/telegram/DialogInviteLinkManager.cpp +++ b/td/telegram/DialogInviteLinkManager.cpp @@ -977,8 +977,16 @@ void DialogInviteLinkManager::on_get_permanent_dialog_invite_link(DialogId dialo void DialogInviteLinkManager::export_dialog_invite_link(DialogId dialog_id, string title, int32 expire_date, int32 usage_limit, bool creates_join_request, - StarSubscriptionPricing subscription_pricing, bool is_permanent, + StarSubscriptionPricing subscription_pricing, + bool is_subscription, bool is_permanent, Promise> &&promise) { + if (is_subscription) { + if (subscription_pricing.is_empty()) { + return promise.set_error(Status::Error(400, "Invalid subscription pricing specified")); + } + } else { + CHECK(subscription_pricing.is_empty()); + } td_->user_manager_->get_me(PromiseCreator::lambda( [actor_id = actor_id(this), dialog_id, title = std::move(title), expire_date, usage_limit, creates_join_request, subscription_pricing, is_permanent, promise = std::move(promise)](Result &&result) mutable { diff --git a/td/telegram/DialogInviteLinkManager.h b/td/telegram/DialogInviteLinkManager.h index 6a588aeba..0aadff7f9 100644 --- a/td/telegram/DialogInviteLinkManager.h +++ b/td/telegram/DialogInviteLinkManager.h @@ -57,7 +57,8 @@ class DialogInviteLinkManager final : public Actor { void export_dialog_invite_link(DialogId dialog_id, string title, int32 expire_date, int32 usage_limit, bool creates_join_request, StarSubscriptionPricing subscription_pricing, - bool is_permanent, Promise> &&promise); + bool is_subscription, bool is_permanent, + Promise> &&promise); void edit_dialog_invite_link(DialogId dialog_id, const string &link, string title, int32 expire_date, int32 usage_limit, bool creates_join_request, diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 0d4a8a483..ff06ab6ff 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6778,8 +6778,8 @@ void Td::on_request(uint64 id, const td_api::getChatAdministrators &request) { void Td::on_request(uint64 id, const td_api::replacePrimaryChatInviteLink &request) { CREATE_REQUEST_PROMISE(); - dialog_invite_link_manager_->export_dialog_invite_link(DialogId(request.chat_id_), string(), 0, 0, false, {}, true, - std::move(promise)); + dialog_invite_link_manager_->export_dialog_invite_link(DialogId(request.chat_id_), string(), 0, 0, false, + StarSubscriptionPricing(), false, true, std::move(promise)); } void Td::on_request(uint64 id, td_api::createChatInviteLink &request) { @@ -6787,8 +6787,15 @@ void Td::on_request(uint64 id, td_api::createChatInviteLink &request) { CREATE_REQUEST_PROMISE(); dialog_invite_link_manager_->export_dialog_invite_link( DialogId(request.chat_id_), std::move(request.name_), request.expiration_date_, request.member_limit_, - request.creates_join_request_, StarSubscriptionPricing(std::move(request.subscription_pricing_)), false, - std::move(promise)); + request.creates_join_request_, StarSubscriptionPricing(), false, false, std::move(promise)); +} + +void Td::on_request(uint64 id, td_api::createChatSubscriptionInviteLink &request) { + CLEAN_INPUT_STRING(request.name_); + CREATE_REQUEST_PROMISE(); + dialog_invite_link_manager_->export_dialog_invite_link( + DialogId(request.chat_id_), std::move(request.name_), 0, 0, false, + StarSubscriptionPricing(std::move(request.subscription_pricing_)), true, false, std::move(promise)); } void Td::on_request(uint64 id, td_api::editChatInviteLink &request) { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 460c4e16f..1d824d3d7 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1276,6 +1276,8 @@ class Td final : public Actor { void on_request(uint64 id, td_api::createChatInviteLink &request); + void on_request(uint64 id, td_api::createChatSubscriptionInviteLink &request); + void on_request(uint64 id, td_api::editChatInviteLink &request); void on_request(uint64 id, td_api::getChatInviteLink &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 81cf61650..526750eed 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4376,12 +4376,17 @@ class CliClient final : public Actor { int32 expiration_date; int32 member_limit; bool creates_join_request; + get_args(args, chat_id, name, expiration_date, member_limit, creates_join_request); + send_request(td_api::make_object(chat_id, name, expiration_date, member_limit, + creates_join_request)); + } else if (op == "ccsil") { + ChatId chat_id; + string name; int32 period; int64 star_count; - get_args(args, chat_id, name, expiration_date, member_limit, creates_join_request, period, star_count); - send_request(td_api::make_object( - chat_id, name, expiration_date, member_limit, creates_join_request, - star_count == 0 ? nullptr : td_api::make_object(period, star_count))); + get_args(args, chat_id, name, period, star_count); + send_request(td_api::make_object( + chat_id, name, td_api::make_object(period, star_count))); } else if (op == "ecil") { ChatId chat_id; string invite_link;