Allow to create and edit chat invite links with title.
This commit is contained in:
parent
8d458f3038
commit
97243b53e4
@ -4902,18 +4902,20 @@ replacePrimaryChatInviteLink chat_id:int53 = ChatInviteLink;
|
||||
|
||||
//@description Creates a new invite link for a chat. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right in the chat
|
||||
//@chat_id Chat identifier
|
||||
//@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
|
||||
createChatInviteLink chat_id:int53 expire_date:int32 member_limit:int32 requires_approval:Bool = ChatInviteLink;
|
||||
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
|
||||
//@chat_id Chat identifier
|
||||
//@invite_link Invite link to be edited
|
||||
//@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
|
||||
editChatInviteLink chat_id:int53 invite_link:string expire_date:int32 member_limit:int32 requires_approval:Bool = ChatInviteLink;
|
||||
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
|
||||
//@chat_id Chat identifier
|
||||
|
@ -1610,7 +1610,8 @@ class ExportChatInviteQuery final : public Td::ResultHandler {
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(DialogId dialog_id, int32 expire_date, int32 usage_limit, bool requires_approval, bool is_permanent) {
|
||||
void send(DialogId dialog_id, const string &title, 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) {
|
||||
@ -1630,9 +1631,12 @@ class ExportChatInviteQuery final : public Td::ResultHandler {
|
||||
if (is_permanent) {
|
||||
flags |= telegram_api::messages_exportChatInvite::LEGACY_REVOKE_PERMANENT_MASK;
|
||||
}
|
||||
if (!title.empty()) {
|
||||
flags |= telegram_api::messages_exportChatInvite::TITLE_MASK;
|
||||
}
|
||||
|
||||
send_query(G()->net_query_creator().create(telegram_api::messages_exportChatInvite(
|
||||
flags, false /*ignored*/, false /*ignored*/, std::move(input_peer), expire_date, usage_limit, string())));
|
||||
flags, false /*ignored*/, false /*ignored*/, std::move(input_peer), expire_date, usage_limit, title)));
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) final {
|
||||
@ -1672,7 +1676,7 @@ 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, const string &title, 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);
|
||||
@ -1682,10 +1686,11 @@ class EditChatInviteLinkQuery final : public Td::ResultHandler {
|
||||
|
||||
int32 flags = telegram_api::messages_editExportedChatInvite::EXPIRE_DATE_MASK |
|
||||
telegram_api::messages_editExportedChatInvite::USAGE_LIMIT_MASK |
|
||||
telegram_api::messages_editExportedChatInvite::REQUEST_NEEDED_MASK;
|
||||
telegram_api::messages_editExportedChatInvite::REQUEST_NEEDED_MASK |
|
||||
telegram_api::messages_editExportedChatInvite::TITLE_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())));
|
||||
expire_date, usage_limit, requires_approval, title)));
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) final {
|
||||
@ -7432,32 +7437,34 @@ Status ContactsManager::can_manage_dialog_invite_links(DialogId dialog_id, bool
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
void ContactsManager::export_dialog_invite_link(DialogId dialog_id, int32 expire_date, int32 usage_limit,
|
||||
void ContactsManager::export_dialog_invite_link(DialogId dialog_id, string title, int32 expire_date, int32 usage_limit,
|
||||
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, requires_approval,
|
||||
is_permanent, promise = std::move(promise)](Result<Unit> &&result) mutable {
|
||||
get_me(PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, title = std::move(title), 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,
|
||||
requires_approval, is_permanent, std::move(promise));
|
||||
send_closure(actor_id, &ContactsManager::export_dialog_invite_link_impl, dialog_id, std::move(title), expire_date,
|
||||
usage_limit, requires_approval, is_permanent, std::move(promise));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void ContactsManager::export_dialog_invite_link_impl(DialogId dialog_id, int32 expire_date, int32 usage_limit,
|
||||
bool requires_approval, bool is_permanent,
|
||||
void ContactsManager::export_dialog_invite_link_impl(DialogId dialog_id, string title, int32 expire_date,
|
||||
int32 usage_limit, 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));
|
||||
|
||||
auto new_title = clean_name(std::move(title), MAX_INVITE_LINK_TITLE_LENGTH);
|
||||
td_->create_handler<ExportChatInviteQuery>(std::move(promise))
|
||||
->send(dialog_id, expire_date, usage_limit, requires_approval, is_permanent);
|
||||
->send(dialog_id, new_title, 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, bool requires_approval,
|
||||
void ContactsManager::edit_dialog_invite_link(DialogId dialog_id, const string &invite_link, string title,
|
||||
int32 expire_date, 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));
|
||||
|
||||
@ -7465,8 +7472,9 @@ void ContactsManager::edit_dialog_invite_link(DialogId dialog_id, const string &
|
||||
return promise.set_error(Status::Error(400, "Invite link must be non-empty"));
|
||||
}
|
||||
|
||||
auto new_title = clean_name(std::move(title), MAX_INVITE_LINK_TITLE_LENGTH);
|
||||
td_->create_handler<EditChatInviteLinkQuery>(std::move(promise))
|
||||
->send(dialog_id, invite_link, expire_date, requires_approval, usage_limit);
|
||||
->send(dialog_id, invite_link, new_title, expire_date, requires_approval, usage_limit);
|
||||
}
|
||||
|
||||
void ContactsManager::get_dialog_invite_link(DialogId dialog_id, const string &invite_link,
|
||||
|
@ -384,11 +384,13 @@ 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 requires_approval,
|
||||
bool is_permanent, Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise);
|
||||
void export_dialog_invite_link(DialogId dialog_id, string title, 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,
|
||||
bool requires_approval, 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,
|
||||
int32 usage_limit, 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);
|
||||
@ -982,6 +984,7 @@ class ContactsManager final : public Actor {
|
||||
static constexpr size_t MAX_NAME_LENGTH = 64; // server side limit for first/last name
|
||||
static constexpr size_t MAX_DESCRIPTION_LENGTH = 255; // server side limit for chat/channel description
|
||||
static constexpr size_t MAX_BIO_LENGTH = 70; // server side limit
|
||||
static constexpr size_t MAX_INVITE_LINK_TITLE_LENGTH = 32; // server side limit
|
||||
static constexpr int32 MAX_GET_CHANNEL_PARTICIPANTS = 200; // server side limit
|
||||
|
||||
static constexpr int32 CHANNEL_PARTICIPANT_CACHE_TIME = 1800; // some reasonable limit
|
||||
@ -1400,8 +1403,9 @@ 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 requires_approval,
|
||||
bool is_permanent, Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise);
|
||||
void export_dialog_invite_link_impl(DialogId dialog_id, string title, 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);
|
||||
|
||||
|
@ -6304,20 +6304,25 @@ 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, false, true, std::move(promise));
|
||||
contacts_manager_->export_dialog_invite_link(DialogId(request.chat_id_), string(), 0, 0, false, true,
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::createChatInviteLink &request) {
|
||||
void Td::on_request(uint64 id, td_api::createChatInviteLink &request) {
|
||||
CLEAN_INPUT_STRING(request.title_);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
contacts_manager_->export_dialog_invite_link(DialogId(request.chat_id_), request.expire_date_, request.member_limit_,
|
||||
request.requires_approval_, false, std::move(promise));
|
||||
contacts_manager_->export_dialog_invite_link(DialogId(request.chat_id_), std::move(request.title_),
|
||||
request.expire_date_, request.member_limit_, request.requires_approval_,
|
||||
false, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::editChatInviteLink &request) {
|
||||
CLEAN_INPUT_STRING(request.title_);
|
||||
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_, request.requires_approval_, std::move(promise));
|
||||
contacts_manager_->edit_dialog_invite_link(DialogId(request.chat_id_), request.invite_link_,
|
||||
std::move(request.title_), request.expire_date_, request.member_limit_,
|
||||
request.requires_approval_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getChatInviteLink &request) {
|
||||
|
@ -862,7 +862,7 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, const td_api::replacePrimaryChatInviteLink &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::createChatInviteLink &request);
|
||||
void on_request(uint64 id, td_api::createChatInviteLink &request);
|
||||
|
||||
void on_request(uint64 id, td_api::editChatInviteLink &request);
|
||||
|
||||
|
@ -2947,20 +2947,22 @@ class CliClient final : public Actor {
|
||||
send_request(td_api::make_object<td_api::replacePrimaryChatInviteLink>(as_chat_id(chat_id)));
|
||||
} else if (op == "ccilt") {
|
||||
string chat_id;
|
||||
string title;
|
||||
int32 expire_date;
|
||||
int32 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));
|
||||
get_args(args, chat_id, title, expire_date, member_limit, requires_approval);
|
||||
send_request(td_api::make_object<td_api::createChatInviteLink>(as_chat_id(chat_id), title, expire_date,
|
||||
member_limit, requires_approval));
|
||||
} else if (op == "ecil") {
|
||||
string chat_id;
|
||||
string invite_link;
|
||||
string title;
|
||||
int32 expire_date;
|
||||
int32 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,
|
||||
get_args(args, chat_id, invite_link, title, expire_date, member_limit, requires_approval);
|
||||
send_request(td_api::make_object<td_api::editChatInviteLink>(as_chat_id(chat_id), invite_link, title, expire_date,
|
||||
member_limit, requires_approval));
|
||||
} else if (op == "rcil") {
|
||||
string chat_id;
|
||||
|
Loading…
Reference in New Issue
Block a user