Add editChatInviteLink method.
This commit is contained in:
parent
0b7ce1c647
commit
87a2423f5a
@ -4349,17 +4349,25 @@ readFilePart file_id:int32 offset:int32 count:int32 = FilePart;
|
||||
deleteFile file_id:int32 = Ok;
|
||||
|
||||
|
||||
//@description Generates a new invite link for a chat. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right
|
||||
//@description Creates a new invite link for a chat. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right
|
||||
//@chat_id Chat identifier
|
||||
//@expire_date Point in time (Unix timestamp) when the link will expire; pass 0 if never
|
||||
//@usage_limit Maximum number of times the link can be used; pass 0 if not limited
|
||||
generateChatInviteLink chat_id:int53 expire_date:int32 usage_limit:int32 = ChatInviteLink;
|
||||
createChatInviteLink chat_id:int53 expire_date:int32 usage_limit:int32 = ChatInviteLink;
|
||||
|
||||
//@description Checks the validity of an invite link for a chat and returns information about the corresponding chat @invite_link Invite link to be checked; should begin with "https://t.me/joinchat/", "https://telegram.me/joinchat/", or "https://telegram.dog/joinchat/"
|
||||
//@description Edits an invite link for a chat. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right
|
||||
//@chat_id Chat identifier
|
||||
//@invite_link Invite link to be edited; must begin with "https://t.me/joinchat/", "https://telegram.me/joinchat/", or "https://telegram.dog/joinchat/"
|
||||
//@expire_date Point in time (Unix timestamp) when the link will expire; pass 0 if never
|
||||
//@usage_limit Maximum number of times the link can be used; pass 0 if not limited
|
||||
//@is_revoked True, if the link is revoked
|
||||
editChatInviteLink chat_id:int53 invite_link:string expire_date:int32 usage_limit:int32 is_revoked:Bool = ChatInviteLink;
|
||||
|
||||
//@description Checks the validity of an invite link for a chat and returns information about the corresponding chat @invite_link Invite link to be checked; must begin with "https://t.me/joinchat/", "https://telegram.me/joinchat/", or "https://telegram.dog/joinchat/"
|
||||
checkChatInviteLink invite_link:string = ChatInviteLinkInfo;
|
||||
|
||||
//@description Uses an invite link to add the current user to the chat if possible. The new member will not be added until the chat state has been synchronized with the server
|
||||
//@invite_link Invite link to import; should begin with "https://t.me/joinchat/", "https://telegram.me/joinchat/", or "https://telegram.dog/joinchat/"
|
||||
//@invite_link Invite link to import; must begin with "https://t.me/joinchat/", "https://telegram.me/joinchat/", or "https://telegram.dog/joinchat/"
|
||||
joinChatByInviteLink invite_link:string = Chat;
|
||||
|
||||
|
||||
|
Binary file not shown.
@ -1594,6 +1594,72 @@ class ExportChatInviteLinkQuery : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class EditChatInviteLinkQuery : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::chatInviteLink>> promise_;
|
||||
DialogId dialog_id_;
|
||||
|
||||
public:
|
||||
explicit EditChatInviteLinkQuery(Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(DialogId dialog_id, const string &invite_link, int32 expire_date, int32 usage_limit, bool is_revoked) {
|
||||
dialog_id_ = dialog_id;
|
||||
auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(0, Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
|
||||
int32 flags = 0;
|
||||
if (expire_date > 0) {
|
||||
flags |= telegram_api::messages_editExportedChatInvite::EXPIRE_DATE_MASK;
|
||||
}
|
||||
if (usage_limit > 0) {
|
||||
flags |= telegram_api::messages_editExportedChatInvite::USAGE_LIMIT_MASK;
|
||||
}
|
||||
if (is_revoked) {
|
||||
flags |= telegram_api::messages_editExportedChatInvite::REVOKED_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)));
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) override {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_editExportedChatInvite>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(id, result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto result = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for ExportChatInviteQuery: " << to_string(result);
|
||||
|
||||
td->contacts_manager_->on_get_users(std::move(result->users_), "EditChatInviteLinkQuery");
|
||||
|
||||
auto recent_importers = std::move(result->recent_importers_);
|
||||
auto ptr = std::move(result->invite_);
|
||||
int32 expire_date = 0;
|
||||
if ((ptr->flags_ & telegram_api::chatInviteExported::EXPIRE_DATE_MASK) != 0) {
|
||||
expire_date = ptr->expire_date_;
|
||||
}
|
||||
int32 usage_limit = 0;
|
||||
if ((ptr->flags_ & telegram_api::chatInviteExported::USAGE_LIMIT_MASK) != 0) {
|
||||
usage_limit = ptr->usage_limit_;
|
||||
}
|
||||
int32 usage_count = 0;
|
||||
if ((ptr->flags_ & telegram_api::chatInviteExported::USAGE_MASK) != 0) {
|
||||
usage_count = ptr->usage_;
|
||||
}
|
||||
auto invite_link = td_api::make_object<td_api::chatInviteLink>(
|
||||
ptr->link_, ptr->admin_id_, ptr->date_, expire_date, usage_limit, usage_count, ptr->expired_, ptr->revoked_);
|
||||
promise_.set_value(std::move(invite_link));
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) override {
|
||||
promise_.set_error(std::move(status));
|
||||
td->updates_manager_->get_difference("EditChatInviteLinkQuery");
|
||||
}
|
||||
};
|
||||
|
||||
class CheckDialogInviteLinkQuery : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
string invite_link_;
|
||||
@ -6480,56 +6546,77 @@ void ContactsManager::transfer_channel_ownership(
|
||||
->send(channel_id, user_id, std::move(input_check_password));
|
||||
}
|
||||
|
||||
void ContactsManager::export_dialog_invite_link(DialogId dialog_id, int32 expire_date, int32 usage_limit,
|
||||
Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise) {
|
||||
LOG(INFO) << "Receive ExportDialogInviteLink request for " << dialog_id;
|
||||
Status ContactsManager::can_manage_dialog_invite_links(DialogId dialog_id) {
|
||||
if (!td_->messages_manager_->have_dialog_force(dialog_id)) {
|
||||
return promise.set_error(Status::Error(3, "Chat not found"));
|
||||
return Status::Error(3, "Chat not found");
|
||||
}
|
||||
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
return promise.set_error(Status::Error(3, "Can't invite members to a private chat"));
|
||||
return Status::Error(3, "Can't invite members to a private chat");
|
||||
case DialogType::Chat: {
|
||||
const Chat *c = get_chat(dialog_id.get_chat_id());
|
||||
if (c == nullptr) {
|
||||
return promise.set_error(Status::Error(3, "Chat info not found"));
|
||||
return Status::Error(3, "Chat info not found");
|
||||
}
|
||||
if (!c->is_active) {
|
||||
return promise.set_error(Status::Error(3, "Chat is deactivated"));
|
||||
return Status::Error(3, "Chat is deactivated");
|
||||
}
|
||||
if (!get_chat_status(c).is_administrator() || !get_chat_status(c).can_invite_users()) {
|
||||
return promise.set_error(Status::Error(3, "Not enough rights to export chat invite link"));
|
||||
return Status::Error(3, "Not enough rights to manage chat invite link");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DialogType::Channel: {
|
||||
const Channel *c = get_channel(dialog_id.get_channel_id());
|
||||
if (c == nullptr) {
|
||||
return promise.set_error(Status::Error(3, "Chat info not found"));
|
||||
return Status::Error(3, "Chat info not found");
|
||||
}
|
||||
if (!get_channel_status(c).is_administrator() || !get_channel_status(c).can_invite_users()) {
|
||||
return promise.set_error(Status::Error(3, "Not enough rights to export chat invite link"));
|
||||
return Status::Error(3, "Not enough rights to manage chat invite link");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DialogType::SecretChat:
|
||||
return promise.set_error(Status::Error(3, "Can't invite members to a secret chat"));
|
||||
return Status::Error(3, "Can't invite members to a secret chat");
|
||||
case DialogType::None:
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
void ContactsManager::export_dialog_invite_link(DialogId dialog_id, int32 expire_date, int32 usage_limit,
|
||||
Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise) {
|
||||
LOG(INFO) << "Receive CreateDialogInviteLink request for " << dialog_id;
|
||||
|
||||
TRY_STATUS_PROMISE(promise, can_manage_dialog_invite_links(dialog_id));
|
||||
|
||||
td_->create_handler<ExportChatInviteLinkQuery>(std::move(promise))->send(dialog_id, expire_date, usage_limit);
|
||||
}
|
||||
|
||||
void ContactsManager::edit_dialog_invite_link(DialogId dialog_id, const string &invite_link, int32 expire_date,
|
||||
int32 usage_limit, bool is_revoked,
|
||||
Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise) {
|
||||
LOG(INFO) << "Receive EditDialogInviteLink request for link " << invite_link << " in " << dialog_id;
|
||||
|
||||
TRY_STATUS_PROMISE(promise, can_manage_dialog_invite_links(dialog_id));
|
||||
|
||||
if (!is_valid_invite_link(invite_link)) {
|
||||
return promise.set_error(Status::Error(400, "Wrong invite link"));
|
||||
}
|
||||
|
||||
td_->create_handler<EditChatInviteLinkQuery>(std::move(promise))
|
||||
->send(dialog_id, invite_link, expire_date, usage_limit, is_revoked);
|
||||
}
|
||||
|
||||
void ContactsManager::check_dialog_invite_link(const string &invite_link, Promise<Unit> &&promise) const {
|
||||
if (invite_link_infos_.count(invite_link) > 0) {
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
|
||||
if (!is_valid_invite_link(invite_link)) {
|
||||
return promise.set_error(Status::Error(3, "Wrong invite link"));
|
||||
return promise.set_error(Status::Error(400, "Wrong invite link"));
|
||||
}
|
||||
|
||||
td_->create_handler<CheckDialogInviteLinkQuery>(std::move(promise))->send(invite_link);
|
||||
@ -6537,7 +6624,7 @@ void ContactsManager::check_dialog_invite_link(const string &invite_link, Promis
|
||||
|
||||
void ContactsManager::import_dialog_invite_link(const string &invite_link, Promise<DialogId> &&promise) {
|
||||
if (!is_valid_invite_link(invite_link)) {
|
||||
return promise.set_error(Status::Error(3, "Wrong invite link"));
|
||||
return promise.set_error(Status::Error(400, "Wrong invite link"));
|
||||
}
|
||||
|
||||
td_->create_handler<ImportDialogInviteLinkQuery>(std::move(promise))->send(invite_link);
|
||||
|
@ -391,6 +391,9 @@ class ContactsManager : public Actor {
|
||||
void export_dialog_invite_link(DialogId dialog_id, int32 expire_date, int32 usage_limit,
|
||||
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 is_revoked, Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise);
|
||||
|
||||
void check_dialog_invite_link(const string &invite_link, Promise<Unit> &&promise) const;
|
||||
|
||||
void import_dialog_invite_link(const string &invite_link, Promise<DialogId> &&promise);
|
||||
@ -1343,6 +1346,8 @@ class ContactsManager : public Actor {
|
||||
|
||||
void remove_dialog_access_by_invite_link(DialogId dialog_id);
|
||||
|
||||
Status can_manage_dialog_invite_links(DialogId dialog_id);
|
||||
|
||||
static bool is_valid_invite_link(const string &invite_link);
|
||||
|
||||
bool update_invite_link(string &invite_link, tl_object_ptr<telegram_api::chatInviteExported> &&exported_chat_invite);
|
||||
|
@ -6275,12 +6275,19 @@ void Td::on_request(uint64 id, td_api::getChatAdministrators &request) {
|
||||
CREATE_REQUEST(GetChatAdministratorsRequest, request.chat_id_);
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::generateChatInviteLink &request) {
|
||||
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.usage_limit_,
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::editChatInviteLink &request) {
|
||||
CREATE_REQUEST_PROMISE();
|
||||
CLEAN_INPUT_STRING(request.invite_link_);
|
||||
contacts_manager_->edit_dialog_invite_link(DialogId(request.chat_id_), request.invite_link_, request.expire_date_,
|
||||
request.usage_limit_, request.is_revoked_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::checkChatInviteLink &request) {
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.invite_link_);
|
||||
|
@ -786,7 +786,9 @@ class Td final : public NetQueryCallback {
|
||||
|
||||
void on_request(uint64 id, td_api::getChatAdministrators &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::generateChatInviteLink &request);
|
||||
void on_request(uint64 id, const td_api::createChatInviteLink &request);
|
||||
|
||||
void on_request(uint64 id, td_api::editChatInviteLink &request);
|
||||
|
||||
void on_request(uint64 id, td_api::checkChatInviteLink &request);
|
||||
|
||||
|
@ -2687,7 +2687,16 @@ class CliClient final : public Actor {
|
||||
int32 expire_date;
|
||||
int32 usage_limit;
|
||||
get_args(args, chat_id, expire_date, usage_limit);
|
||||
send_request(td_api::make_object<td_api::generateChatInviteLink>(as_chat_id(chat_id), expire_date, usage_limit));
|
||||
send_request(td_api::make_object<td_api::createChatInviteLink>(as_chat_id(chat_id), expire_date, usage_limit));
|
||||
} else if (op == "ecil") {
|
||||
string chat_id;
|
||||
string invite_link;
|
||||
int32 expire_date;
|
||||
int32 usage_limit;
|
||||
bool is_revoked;
|
||||
get_args(args, chat_id, invite_link, expire_date, usage_limit, is_revoked);
|
||||
send_request(td_api::make_object<td_api::editChatInviteLink>(as_chat_id(chat_id), invite_link, expire_date,
|
||||
usage_limit, is_revoked));
|
||||
} else if (op == "ccil") {
|
||||
send_request(td_api::make_object<td_api::checkChatInviteLink>(args));
|
||||
} else if (op == "jcbil") {
|
||||
|
Loading…
Reference in New Issue
Block a user