Add separate createChatSubscriptionInviteLink.

This commit is contained in:
levlam 2024-08-13 23:56:59 +03:00
parent 357e59a781
commit 8cefcc6ac7
6 changed files with 41 additions and 14 deletions

View File

@ -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 //@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 //@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 //@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. createChatInviteLink chat_id:int53 name:string expiration_date:int32 member_limit:int32 creates_join_request:Bool = ChatInviteLink;
//-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 //@description Creates a new subscription invite link for a channel chat. Requires can_invite_users right in the chat
createChatInviteLink chat_id:int53 name:string expiration_date:int32 member_limit:int32 creates_join_request:Bool subscription_pricing:starSubscriptionPricing = ChatInviteLink; //@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. //@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 //-If the link creates a subscription, then expiration_date, member_limit and creates_join_request must not be used

View File

@ -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, void DialogInviteLinkManager::export_dialog_invite_link(DialogId dialog_id, string title, int32 expire_date,
int32 usage_limit, bool creates_join_request, int32 usage_limit, bool creates_join_request,
StarSubscriptionPricing subscription_pricing, bool is_permanent, StarSubscriptionPricing subscription_pricing,
bool is_subscription, bool is_permanent,
Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise) { Promise<td_api::object_ptr<td_api::chatInviteLink>> &&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( 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, [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<Unit> &&result) mutable { subscription_pricing, is_permanent, promise = std::move(promise)](Result<Unit> &&result) mutable {

View File

@ -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, void export_dialog_invite_link(DialogId dialog_id, string title, int32 expire_date, int32 usage_limit,
bool creates_join_request, StarSubscriptionPricing subscription_pricing, bool creates_join_request, StarSubscriptionPricing subscription_pricing,
bool is_permanent, Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise); bool is_subscription, bool is_permanent,
Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise);
void edit_dialog_invite_link(DialogId dialog_id, const string &link, string title, int32 expire_date, void edit_dialog_invite_link(DialogId dialog_id, const string &link, string title, int32 expire_date,
int32 usage_limit, bool creates_join_request, int32 usage_limit, bool creates_join_request,

View File

@ -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) { void Td::on_request(uint64 id, const td_api::replacePrimaryChatInviteLink &request) {
CREATE_REQUEST_PROMISE(); CREATE_REQUEST_PROMISE();
dialog_invite_link_manager_->export_dialog_invite_link(DialogId(request.chat_id_), string(), 0, 0, false, {}, true, dialog_invite_link_manager_->export_dialog_invite_link(DialogId(request.chat_id_), string(), 0, 0, false,
std::move(promise)); StarSubscriptionPricing(), false, true, std::move(promise));
} }
void Td::on_request(uint64 id, td_api::createChatInviteLink &request) { 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(); CREATE_REQUEST_PROMISE();
dialog_invite_link_manager_->export_dialog_invite_link( dialog_invite_link_manager_->export_dialog_invite_link(
DialogId(request.chat_id_), std::move(request.name_), request.expiration_date_, request.member_limit_, 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, request.creates_join_request_, StarSubscriptionPricing(), false, false, std::move(promise));
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) { void Td::on_request(uint64 id, td_api::editChatInviteLink &request) {

View File

@ -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::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::editChatInviteLink &request);
void on_request(uint64 id, td_api::getChatInviteLink &request); void on_request(uint64 id, td_api::getChatInviteLink &request);

View File

@ -4376,12 +4376,17 @@ class CliClient final : public Actor {
int32 expiration_date; int32 expiration_date;
int32 member_limit; int32 member_limit;
bool creates_join_request; bool creates_join_request;
get_args(args, chat_id, name, expiration_date, member_limit, creates_join_request);
send_request(td_api::make_object<td_api::createChatInviteLink>(chat_id, name, expiration_date, member_limit,
creates_join_request));
} else if (op == "ccsil") {
ChatId chat_id;
string name;
int32 period; int32 period;
int64 star_count; int64 star_count;
get_args(args, chat_id, name, expiration_date, member_limit, creates_join_request, period, star_count); get_args(args, chat_id, name, period, star_count);
send_request(td_api::make_object<td_api::createChatInviteLink>( send_request(td_api::make_object<td_api::createChatSubscriptionInviteLink>(
chat_id, name, expiration_date, member_limit, creates_join_request, chat_id, name, td_api::make_object<td_api::starSubscriptionPricing>(period, star_count)));
star_count == 0 ? nullptr : td_api::make_object<td_api::starSubscriptionPricing>(period, star_count)));
} else if (op == "ecil") { } else if (op == "ecil") {
ChatId chat_id; ChatId chat_id;
string invite_link; string invite_link;