Update layer 123. Support new generateChatInviteLink.

This commit is contained in:
levlam 2021-01-12 17:05:25 +03:00
parent 70b4838a21
commit 0b7ce1c647
10 changed files with 116 additions and 250 deletions

View File

@ -884,8 +884,11 @@ chatNearby chat_id:int53 distance:int32 = ChatNearby;
chatsNearby users_nearby:vector<chatNearby> supergroups_nearby:vector<chatNearby> = ChatsNearby;
//@description Contains a chat invite link @invite_link Chat invite link
chatInviteLink invite_link:string = ChatInviteLink;
//@description Contains a chat invite link @invite_link Chat invite link @administrator_user_id User identifier of an administrator created the link
//@date Point in time (Unix timestamp) when the link was created @expire_date Point in time (Unix timestamp) when the link will expire; 0 if never
//@usage_limit Maximum number of times the link can be used; 0 if not limited @usage_count Number of times the link has already been used
//@is_expired True, if the link is already expired @is_revoked True, if the link was revoked
chatInviteLink invite_link:string administrator_user_id:int32 date:int32 expire_date:int32 usage_limit:int32 usage_count:int32 is_expired:Bool is_revoked:Bool = ChatInviteLink;
//@description Contains information about a chat invite link
//@chat_id Chat identifier of the invite link; 0 if the user has no access to the chat before joining
@ -4346,8 +4349,11 @@ readFilePart file_id:int32 offset:int32 count:int32 = FilePart;
deleteFile file_id:int32 = Ok;
//@description Generates a new invite link for a chat; the previously generated link is revoked. Available for basic groups, supergroups, and channels. Requires administrator privileges and can_invite_users right @chat_id Chat identifier
generateChatInviteLink chat_id:int53 = ChatInviteLink;
//@description Generates 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;
//@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/"
checkChatInviteLink invite_link:string = ChatInviteLinkInfo;

Binary file not shown.

View File

@ -114,8 +114,8 @@ chatForbidden#7328bdb id:int title:string = Chat;
channel#d31a961e flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true has_geo:flags.21?true slowmode_enabled:flags.22?true call_active:flags.23?true call_not_empty:flags.24?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?Vector<RestrictionReason> admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int = Chat;
channelForbidden#289da732 flags:# broadcast:flags.5?true megagroup:flags.8?true id:int access_hash:long title:string until_date:flags.16?int = Chat;
chatFull#dc8c181 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:int about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:flags.3?Vector<BotInfo> pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall = ChatFull;
channelFull#ef3a6acd flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true id:int about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:Vector<BotInfo> migrated_from_chat_id:flags.4?int migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?int location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall = ChatFull;
chatFull#f3474af6 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:int about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector<BotInfo> pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall = ChatFull;
channelFull#7a7de4f7 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true id:int about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector<BotInfo> migrated_from_chat_id:flags.4?int migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?int location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall = ChatFull;
chatParticipant#c8d7493e user_id:int inviter_id:int date:int = ChatParticipant;
chatParticipantCreator#da13538a user_id:int = ChatParticipant;
@ -522,8 +522,7 @@ auth.passwordRecovery#137948a5 email_pattern:string = auth.PasswordRecovery;
receivedNotifyMessage#a384b779 id:int flags:int = ReceivedNotifyMessage;
chatInviteEmpty#69df3769 = ExportedChatInvite;
chatInviteExported#fc2e05bc link:string = ExportedChatInvite;
chatInviteExported#a9a847ea flags:# revoked:flags.0?true expired:flags.4?true permanent:flags.5?true link:string admin_id:int date:int expire_date:flags.1?int usage_limit:flags.2?int usage:flags.3?int = ExportedChatInvite;
chatInviteAlready#5a686d7c chat:Chat = ChatInvite;
chatInvite#dfc2f58e flags:# channel:flags.0?true broadcast:flags.1?true public:flags.2?true megagroup:flags.3?true title:string photo:Photo participants_count:int participants:flags.4?Vector<User> = ChatInvite;
@ -1194,6 +1193,14 @@ inlineQueryPeerTypeChat#d766c50a = InlineQueryPeerType;
inlineQueryPeerTypeMegagroup#5ec4be43 = InlineQueryPeerType;
inlineQueryPeerTypeBroadcast#6334ee9a = InlineQueryPeerType;
chatInviteImporter#1e3e6680 user_id:int date:int = ChatInviteImporter;
messages.exportedChatInvites#bdc62dcc count:int invites:Vector<ExportedChatInvite> users:Vector<User> = messages.ExportedChatInvites;
messages.exportedChatInvite#1871be50 invite:ExportedChatInvite users:Vector<User> = messages.ExportedChatInvite;
messages.chatInviteImporters#81b6b00a count:int importers:Vector<ChatInviteImporter> users:Vector<User> = messages.ChatInviteImporters;
---functions---
invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
@ -1353,7 +1360,7 @@ messages.readMessageContents#36a73f77 id:Vector<int> = messages.AffectedMessages
messages.getStickers#43d4f2c emoticon:string hash:int = messages.Stickers;
messages.getAllStickers#1c9618b1 hash:int = messages.AllStickers;
messages.getWebPagePreview#8b68b0cc flags:# message:string entities:flags.3?Vector<MessageEntity> = MessageMedia;
messages.exportChatInvite#df7534c peer:InputPeer = ExportedChatInvite;
messages.exportChatInvite#14b9bcd7 flags:# legacy_revoke_permanent:flags.2?true peer:InputPeer expire_date:flags.0?int usage_limit:flags.1?int = ExportedChatInvite;
messages.checkChatInvite#3eadb1bb hash:string = ChatInvite;
messages.importChatInvite#6c50051c hash:string = Updates;
messages.getStickerSet#2619a90e stickerset:InputStickerSet = messages.StickerSet;
@ -1443,6 +1450,9 @@ messages.getReplies#24b581ba peer:InputPeer msg_id:int offset_id:int offset_date
messages.getDiscussionMessage#446972fd peer:InputPeer msg_id:int = messages.DiscussionMessage;
messages.readDiscussion#f731a9f4 peer:InputPeer msg_id:int read_max_id:int = Bool;
messages.unpinAllMessages#f025bc8b peer:InputPeer = messages.AffectedHistory;
messages.getExportedChatInvites#6d9cae03 flags:# peer:InputPeer admin_id:flags.0?InputUser offset_link:flags.2?string limit:int = messages.ExportedChatInvites;
messages.editExportedChatInvite#2e4ffbe flags:# revoked:flags.2?true peer:InputPeer link:string expire_date:flags.0?int usage_limit:flags.1?int = messages.ExportedChatInvite;
messages.getChatInviteImporters#26fb7289 peer:InputPeer link:string offset_date:int offset_user:InputUser limit:int = messages.ChatInviteImporters;
updates.getState#edd4882a = updates.State;
updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference;

Binary file not shown.

View File

@ -1536,20 +1536,30 @@ class EditChatAdminQuery : public Td::ResultHandler {
};
class ExportChatInviteLinkQuery : public Td::ResultHandler {
Promise<Unit> promise_;
ChatId chat_id_;
Promise<td_api::object_ptr<td_api::chatInviteLink>> promise_;
DialogId dialog_id_;
public:
explicit ExportChatInviteLinkQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
explicit ExportChatInviteLinkQuery(Promise<td_api::object_ptr<td_api::chatInviteLink>> &&promise)
: promise_(std::move(promise)) {
}
void send(ChatId chat_id) {
chat_id_ = chat_id;
auto input_peer = td->messages_manager_->get_input_peer(DialogId(chat_id), AccessRights::Read);
void send(DialogId dialog_id, int32 expire_date, int32 usage_limit) {
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"));
}
send_query(G()->net_query_creator().create(telegram_api::messages_exportChatInvite(std::move(input_peer))));
int32 flags = 0;
if (expire_date > 0) {
flags |= telegram_api::messages_exportChatInvite::EXPIRE_DATE_MASK;
}
if (usage_limit > 0) {
flags |= telegram_api::messages_exportChatInvite::USAGE_LIMIT_MASK;
}
send_query(G()->net_query_creator().create(telegram_api::messages_exportChatInvite(
flags, false /*ignored*/, std::move(input_peer), expire_date, usage_limit)));
}
void on_result(uint64 id, BufferSlice packet) override {
@ -1561,8 +1571,21 @@ class ExportChatInviteLinkQuery : public Td::ResultHandler {
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for ExportChatInviteQuery: " << to_string(ptr);
td->contacts_manager_->on_get_chat_invite_link(chat_id_, std::move(ptr));
promise_.set_value(Unit());
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 {
@ -1571,43 +1594,6 @@ class ExportChatInviteLinkQuery : public Td::ResultHandler {
}
};
class ExportChannelInviteLinkQuery : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId channel_id_;
public:
explicit ExportChannelInviteLinkQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(ChannelId channel_id) {
channel_id_ = channel_id;
auto input_peer = td->messages_manager_->get_input_peer(DialogId(channel_id), AccessRights::Read);
if (input_peer == nullptr) {
return on_error(0, Status::Error(400, "Can't access the chat"));
}
send_query(G()->net_query_creator().create(telegram_api::messages_exportChatInvite(std::move(input_peer))));
}
void on_result(uint64 id, BufferSlice packet) override {
auto result_ptr = fetch_result<telegram_api::messages_exportChatInvite>(packet);
if (result_ptr.is_error()) {
return on_error(id, result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for ExportChannelInviteQuery: " << to_string(ptr);
td->contacts_manager_->on_get_channel_invite_link(channel_id_, std::move(ptr));
promise_.set_value(Unit());
}
void on_error(uint64 id, Status status) override {
td->contacts_manager_->on_get_channel_error(channel_id_, status, "ExportChannelInviteLinkQuery");
promise_.set_error(std::move(status));
td->updates_manager_->get_difference("ExportChannelInviteLinkQuery");
}
};
class CheckDialogInviteLinkQuery : public Td::ResultHandler {
Promise<Unit> promise_;
string invite_link_;
@ -6494,33 +6480,47 @@ void ContactsManager::transfer_channel_ownership(
->send(channel_id, user_id, std::move(input_check_password));
}
void ContactsManager::export_chat_invite_link(ChatId chat_id, Promise<Unit> &&promise) {
const Chat *c = get_chat(chat_id);
if (c == nullptr) {
return promise.set_error(Status::Error(3, "Chat info not found"));
}
if (!c->is_active) {
return promise.set_error(Status::Error(3, "Chat is deactivated"));
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;
if (!td_->messages_manager_->have_dialog_force(dialog_id)) {
return promise.set_error(Status::Error(3, "Chat not found"));
}
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"));
switch (dialog_id.get_type()) {
case DialogType::User:
return promise.set_error(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"));
}
if (!c->is_active) {
return promise.set_error(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"));
}
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"));
}
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"));
}
break;
}
case DialogType::SecretChat:
return promise.set_error(Status::Error(3, "Can't invite members to a secret chat"));
case DialogType::None:
default:
UNREACHABLE();
}
td_->create_handler<ExportChatInviteLinkQuery>(std::move(promise))->send(chat_id);
}
void ContactsManager::export_channel_invite_link(ChannelId channel_id, Promise<Unit> &&promise) {
const Channel *c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(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"));
}
td_->create_handler<ExportChannelInviteLinkQuery>(std::move(promise))->send(channel_id);
td_->create_handler<ExportChatInviteLinkQuery>(std::move(promise))->send(dialog_id, expire_date, usage_limit);
}
void ContactsManager::check_dialog_invite_link(const string &invite_link, Promise<Unit> &&promise) const {
@ -6543,25 +6543,6 @@ void ContactsManager::import_dialog_invite_link(const string &invite_link, Promi
td_->create_handler<ImportDialogInviteLinkQuery>(std::move(promise))->send(invite_link);
}
string ContactsManager::get_chat_invite_link(ChatId chat_id) const {
auto chat_full = get_chat_full(chat_id);
if (chat_full == nullptr) {
auto it = dialog_invite_links_.find(DialogId(chat_id));
return it == dialog_invite_links_.end() ? string() : it->second;
}
return chat_full->invite_link;
}
string ContactsManager::get_channel_invite_link(
ChannelId channel_id) { // should be non-const to update ChannelFull cache
auto channel_full = get_channel_full(channel_id, "get_channel_invite_link");
if (channel_full == nullptr) {
auto it = dialog_invite_links_.find(DialogId(channel_id));
return it == dialog_invite_links_.end() ? string() : it->second;
}
return channel_full->invite_link;
}
void ContactsManager::delete_chat_participant(ChatId chat_id, UserId user_id, Promise<Unit> &&promise) {
const Chat *c = get_chat(chat_id);
if (c == nullptr) {
@ -11017,11 +10998,6 @@ void ContactsManager::invalidate_channel_full(ChannelId channel_id, bool need_dr
}
if (need_drop_invite_link) {
remove_dialog_access_by_invite_link(DialogId(channel_id));
auto it = dialog_invite_links_.find(DialogId(channel_id));
if (it != dialog_invite_links_.end()) {
invalidate_invite_link_info(it->second);
}
}
}
@ -11099,52 +11075,18 @@ void ContactsManager::on_update_channel_full_photo(ChannelFull *channel_full, Ch
}
}
void ContactsManager::on_get_chat_invite_link(ChatId chat_id,
tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link_ptr) {
CHECK(chat_id.is_valid());
if (!have_chat_force(chat_id)) {
LOG(ERROR) << chat_id << " not found";
return;
}
auto chat_full = get_chat_full_force(chat_id, "on_get_chat_invite_link");
if (chat_full == nullptr) {
update_invite_link(dialog_invite_links_[DialogId(chat_id)], std::move(invite_link_ptr));
return;
}
on_update_chat_full_invite_link(chat_full, std::move(invite_link_ptr));
update_chat_full(chat_full, chat_id);
}
void ContactsManager::on_update_chat_full_invite_link(
ChatFull *chat_full, tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link_ptr) {
void ContactsManager::on_update_chat_full_invite_link(ChatFull *chat_full,
tl_object_ptr<telegram_api::chatInviteExported> &&invite_link) {
CHECK(chat_full != nullptr);
if (update_invite_link(chat_full->invite_link, std::move(invite_link_ptr))) {
if (update_invite_link(chat_full->invite_link, std::move(invite_link))) {
chat_full->is_changed = true;
}
}
void ContactsManager::on_get_channel_invite_link(ChannelId channel_id,
tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link_ptr) {
CHECK(channel_id.is_valid());
if (!have_channel(channel_id)) {
LOG(ERROR) << channel_id << " not found";
return;
}
auto channel_full = get_channel_full_force(channel_id, "on_get_channel_invite_link");
if (channel_full == nullptr) {
update_invite_link(dialog_invite_links_[DialogId(channel_id)], std::move(invite_link_ptr));
return;
}
on_update_channel_full_invite_link(channel_full, std::move(invite_link_ptr));
update_channel_full(channel_full, channel_id);
}
void ContactsManager::on_update_channel_full_invite_link(
ChannelFull *channel_full, tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link_ptr) {
ChannelFull *channel_full, tl_object_ptr<telegram_api::chatInviteExported> &&invite_link) {
CHECK(channel_full != nullptr);
if (update_invite_link(channel_full->invite_link, std::move(invite_link_ptr))) {
if (update_invite_link(channel_full->invite_link, std::move(invite_link))) {
channel_full->is_changed = true;
}
}
@ -11387,13 +11329,6 @@ void ContactsManager::on_get_dialog_invite_link_info(const string &invite_link,
invite_link_info_expire_timeout_.set_timeout_in(dialog_id.get(), expires_in);
}
}
if (chat_id.is_valid()) {
on_get_chat_invite_link(chat_id, make_tl_object<telegram_api::chatInviteExported>(invite_link));
}
if (channel_id.is_valid()) {
on_get_channel_invite_link(channel_id, make_tl_object<telegram_api::chatInviteExported>(invite_link));
}
break;
}
case telegram_api::chatInvite::ID: {
@ -11486,21 +11421,10 @@ Slice ContactsManager::get_dialog_invite_link_hash(const string &invite_link) {
}
bool ContactsManager::update_invite_link(string &invite_link,
tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link_ptr) {
tl_object_ptr<telegram_api::chatInviteExported> &&exported_chat_invite) {
string new_invite_link;
if (invite_link_ptr != nullptr) {
switch (invite_link_ptr->get_id()) {
case telegram_api::chatInviteEmpty::ID:
// link is empty
break;
case telegram_api::chatInviteExported::ID: {
auto chat_invite_exported = move_tl_object_as<telegram_api::chatInviteExported>(invite_link_ptr);
new_invite_link = std::move(chat_invite_exported->link_);
break;
}
default:
UNREACHABLE();
}
if (exported_chat_invite != nullptr) {
new_invite_link = std::move(exported_chat_invite->link_);
}
if (new_invite_link != invite_link) {
@ -11723,7 +11647,6 @@ void ContactsManager::on_update_chat_delete_user(ChatId chat_id, UserId user_id,
void ContactsManager::on_update_chat_status(Chat *c, ChatId chat_id, DialogParticipantStatus status) {
if (c->status != status) {
LOG(INFO) << "Update " << chat_id << " status from " << c->status << " to " << status;
bool need_drop_invite_link = c->status.is_left() != status.is_left();
bool need_reload_group_call = c->status.can_manage_calls() != status.can_manage_calls();
c->status = status;
@ -11736,12 +11659,6 @@ void ContactsManager::on_update_chat_status(Chat *c, ChatId chat_id, DialogParti
drop_chat_full(chat_id);
}
if (need_drop_invite_link) {
auto it = dialog_invite_links_.find(DialogId(chat_id));
if (it != dialog_invite_links_.end()) {
invalidate_invite_link_info(it->second);
}
}
if (need_reload_group_call) {
send_closure_later(G()->messages_manager(), &MessagesManager::on_update_dialog_group_call_rights,
DialogId(chat_id));
@ -12015,11 +11932,6 @@ void ContactsManager::drop_chat_full(ChatId chat_id) {
ChatFull *chat_full = get_chat_full_force(chat_id, "drop_chat_full");
if (chat_full == nullptr) {
drop_chat_photos(chat_id, false, false, "drop_chat_full");
auto it = dialog_invite_links_.find(DialogId(chat_id));
if (it != dialog_invite_links_.end()) {
invalidate_invite_link_info(it->second);
}
return;
}

View File

@ -222,11 +222,6 @@ class ContactsManager : public Actor {
static Slice get_dialog_invite_link_hash(const string &invite_link);
void on_get_chat_invite_link(ChatId chat_id, tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link_ptr);
void on_get_channel_invite_link(ChannelId channel_id,
tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link_ptr);
void on_get_dialog_invite_link_info(const string &invite_link,
tl_object_ptr<telegram_api::ChatInvite> &&chat_invite_ptr,
Promise<Unit> &&promise);
@ -393,18 +388,13 @@ class ContactsManager : public Actor {
void transfer_dialog_ownership(DialogId dialog_id, UserId user_id, const string &password, Promise<Unit> &&promise);
void export_chat_invite_link(ChatId chat_id, Promise<Unit> &&promise);
void export_channel_invite_link(ChannelId channel_id, Promise<Unit> &&promise);
void export_dialog_invite_link(DialogId dialog_id, int32 expire_date, int32 usage_limit,
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);
string get_chat_invite_link(ChatId chat_id) const;
string get_channel_invite_link(ChannelId channel_id);
ChannelId migrate_chat_to_megagroup(ChatId chat_id, Promise<Unit> &promise);
vector<DialogId> get_created_public_dialogs(PublicDialogType type, Promise<Unit> &&promise);
@ -1035,6 +1025,7 @@ class ContactsManager : public Actor {
static constexpr int32 CHANNEL_FULL_FLAG_CAN_VIEW_STATISTICS = 1 << 20;
static constexpr int32 CHANNEL_FULL_FLAG_HAS_ACTIVE_GROUP_CALL = 1 << 21;
static constexpr int32 CHANNEL_FULL_FLAG_IS_BLOCKED = 1 << 22;
static constexpr int32 CHANNEL_FULL_FLAG_HAS_EXPORTED_INVITE = 1 << 23;
static constexpr int32 CHAT_INVITE_FLAG_IS_CHANNEL = 1 << 0;
static constexpr int32 CHAT_INVITE_FLAG_IS_BROADCAST = 1 << 1;
@ -1176,7 +1167,7 @@ class ContactsManager : public Actor {
void on_update_chat_full_participants(ChatFull *chat_full, ChatId chat_id, vector<DialogParticipant> participants,
int32 version, bool from_update);
void on_update_chat_full_invite_link(ChatFull *chat_full,
tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link_ptr);
tl_object_ptr<telegram_api::chatInviteExported> &&invite_link);
void on_update_channel_photo(Channel *c, ChannelId channel_id,
tl_object_ptr<telegram_api::ChatPhoto> &&chat_photo_ptr);
@ -1189,7 +1180,7 @@ class ContactsManager : public Actor {
void on_update_channel_full_photo(ChannelFull *channel_full, ChannelId channel_id, Photo photo);
void on_update_channel_full_invite_link(ChannelFull *channel_full,
tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link_ptr);
tl_object_ptr<telegram_api::chatInviteExported> &&invite_link);
void on_update_channel_full_linked_channel_id(ChannelFull *channel_full, ChannelId channel_id,
ChannelId linked_channel_id);
void on_update_channel_full_location(ChannelFull *channel_full, ChannelId channel_id, const DialogLocation &location);
@ -1354,7 +1345,7 @@ class ContactsManager : public Actor {
static bool is_valid_invite_link(const string &invite_link);
bool update_invite_link(string &invite_link, tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link_ptr);
bool update_invite_link(string &invite_link, tl_object_ptr<telegram_api::chatInviteExported> &&exported_chat_invite);
const DialogParticipant *get_chat_participant(ChatId chat_id, UserId user_id) const;
@ -1511,7 +1502,6 @@ class ContactsManager : public Actor {
std::unordered_set<string> invite_links;
int32 accessible_before = 0;
};
std::unordered_map<DialogId, string, DialogIdHash> dialog_invite_links_; // in-memory cache for invite links
std::unordered_map<string, unique_ptr<InviteLinkInfo>> invite_link_infos_;
std::unordered_map<DialogId, DialogAccessByInviteLink, DialogIdHash> dialog_access_by_invite_link_;

View File

@ -30414,43 +30414,6 @@ vector<DialogAdministrator> MessagesManager::get_dialog_administrators(DialogId
return {};
}
void MessagesManager::export_dialog_invite_link(DialogId dialog_id, Promise<Unit> &&promise) {
LOG(INFO) << "Receive ExportDialogInviteLink request for " << dialog_id;
if (!have_dialog_force(dialog_id)) {
return promise.set_error(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"));
case DialogType::Chat:
return td_->contacts_manager_->export_chat_invite_link(dialog_id.get_chat_id(), std::move(promise));
case DialogType::Channel:
return td_->contacts_manager_->export_channel_invite_link(dialog_id.get_channel_id(), std::move(promise));
case DialogType::SecretChat:
return promise.set_error(Status::Error(3, "Can't invite members to a secret chat"));
case DialogType::None:
default:
UNREACHABLE();
}
}
string MessagesManager::get_dialog_invite_link(DialogId dialog_id) {
switch (dialog_id.get_type()) {
case DialogType::Chat:
return td_->contacts_manager_->get_chat_invite_link(dialog_id.get_chat_id());
case DialogType::Channel:
return td_->contacts_manager_->get_channel_invite_link(dialog_id.get_channel_id());
case DialogType::User:
case DialogType::SecretChat:
case DialogType::None:
return string();
default:
UNREACHABLE();
return string();
}
}
tl_object_ptr<telegram_api::channelAdminLogEventsFilter> MessagesManager::get_channel_admin_log_events_filter(
const tl_object_ptr<td_api::chatEventLogFilters> &filters) {
if (filters == nullptr) {

View File

@ -482,10 +482,6 @@ class MessagesManager : public Actor {
vector<DialogAdministrator> get_dialog_administrators(DialogId dialog_id, int left_tries, Promise<Unit> &&promise);
void export_dialog_invite_link(DialogId dialog_id, Promise<Unit> &&promise);
string get_dialog_invite_link(DialogId dialog_id);
void get_dialog_info_full(DialogId dialog_id, Promise<Unit> &&promise);
int64 get_dialog_event_log(DialogId dialog_id, const string &query, int64 from_event_id, int32 limit,

View File

@ -1985,23 +1985,6 @@ class GetChatAdministratorsRequest : public RequestActor<> {
}
};
class GenerateChatInviteLinkRequest : public RequestOnceActor {
DialogId dialog_id_;
void do_run(Promise<Unit> &&promise) override {
td->messages_manager_->export_dialog_invite_link(dialog_id_, std::move(promise));
}
void do_send_result() override {
send_result(make_tl_object<td_api::chatInviteLink>(td->messages_manager_->get_dialog_invite_link(dialog_id_)));
}
public:
GenerateChatInviteLinkRequest(ActorShared<Td> td, uint64 request_id, int64 dialog_id)
: RequestOnceActor(std::move(td), request_id), dialog_id_(dialog_id) {
}
};
class CheckChatInviteLinkRequest : public RequestActor<> {
string invite_link_;
@ -6293,7 +6276,9 @@ void Td::on_request(uint64 id, td_api::getChatAdministrators &request) {
}
void Td::on_request(uint64 id, const td_api::generateChatInviteLink &request) {
CREATE_REQUEST(GenerateChatInviteLinkRequest, request.chat_id_);
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::checkChatInviteLink &request) {

View File

@ -2683,7 +2683,11 @@ class CliClient final : public Actor {
} else if (op == "dgc") {
send_request(td_api::make_object<td_api::discardGroupCall>(as_group_call_id(args)));
} else if (op == "gcil") {
send_request(td_api::make_object<td_api::generateChatInviteLink>(as_chat_id(args)));
string chat_id;
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));
} else if (op == "ccil") {
send_request(td_api::make_object<td_api::checkChatInviteLink>(args));
} else if (op == "jcbil") {