From d246318a5c436a39b9b6bae6c6066ea28a1a959b Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 26 Jan 2021 23:59:09 +0300 Subject: [PATCH] Update permanent invite link after replacing. --- td/telegram/ContactsManager.cpp | 39 ++++++++++++++++++++++++++++----- td/telegram/ContactsManager.h | 5 +++-- td/telegram/DialogInviteLink.h | 4 ++++ 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 493807ad6..a86a5ce94 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -1618,6 +1618,9 @@ class ExportChatInviteLinkQuery : public Td::ResultHandler { if (invite_link.get_administrator_user_id() != td->contacts_manager_->get_my_id()) { return on_error(id, Status::Error(500, "Receive invalid invite link creator")); } + if (invite_link.is_permanent()) { + td->contacts_manager_->on_get_permanent_dialog_invite_link(dialog_id_, invite_link); + } promise_.set_value(invite_link.get_chat_invite_link_object(td->contacts_manager_.get())); } @@ -11855,10 +11858,38 @@ void ContactsManager::on_update_channel_full_photo(ChannelFull *channel_full, Ch } } +void ContactsManager::on_get_permanent_dialog_invite_link(DialogId dialog_id, const DialogInviteLink &invite_link) { + switch (dialog_id.get_type()) { + case DialogType::Chat: { + auto chat_id = dialog_id.get_chat_id(); + auto chat_full = get_chat_full_force(chat_id, "on_get_permanent_dialog_invite_link"); + if (chat_full != nullptr && update_permanent_invite_link(chat_full->invite_link, invite_link)) { + chat_full->is_changed = true; + update_chat_full(chat_full, chat_id); + } + break; + } + case DialogType::Channel: { + auto channel_id = dialog_id.get_channel_id(); + auto channel_full = get_channel_full_force(channel_id, "on_get_permanent_dialog_invite_link"); + if (channel_full != nullptr && update_permanent_invite_link(channel_full->invite_link, invite_link)) { + channel_full->is_changed = true; + update_channel_full(channel_full, channel_id); + } + break; + } + case DialogType::User: + case DialogType::SecretChat: + case DialogType::None: + default: + UNREACHABLE(); + } +} + void ContactsManager::on_update_chat_full_invite_link(ChatFull *chat_full, tl_object_ptr &&invite_link) { CHECK(chat_full != nullptr); - if (update_permanent_invite_link(chat_full->invite_link, std::move(invite_link))) { + if (update_permanent_invite_link(chat_full->invite_link, DialogInviteLink(std::move(invite_link)))) { chat_full->is_changed = true; } } @@ -11866,7 +11897,7 @@ void ContactsManager::on_update_chat_full_invite_link(ChatFull *chat_full, void ContactsManager::on_update_channel_full_invite_link( ChannelFull *channel_full, tl_object_ptr &&invite_link) { CHECK(channel_full != nullptr); - if (update_permanent_invite_link(channel_full->invite_link, std::move(invite_link))) { + if (update_permanent_invite_link(channel_full->invite_link, DialogInviteLink(std::move(invite_link)))) { channel_full->is_changed = true; } } @@ -12174,9 +12205,7 @@ void ContactsManager::remove_dialog_access_by_invite_link(DialogId dialog_id) { invite_link_info_expire_timeout_.cancel_timeout(dialog_id.get()); } -bool ContactsManager::update_permanent_invite_link( - DialogInviteLink &invite_link, tl_object_ptr &&exported_chat_invite) { - DialogInviteLink new_invite_link(std::move(exported_chat_invite)); +bool ContactsManager::update_permanent_invite_link(DialogInviteLink &invite_link, DialogInviteLink new_invite_link) { if (new_invite_link != invite_link) { if (invite_link.is_valid() && invite_link.get_invite_link() != new_invite_link.get_invite_link()) { // old link was invalidated diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 59dbc0397..bbb784818 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -226,6 +226,8 @@ class ContactsManager : public Actor { bool on_get_channel_error(ChannelId channel_id, const Status &status, const string &source); + void on_get_permanent_dialog_invite_link(DialogId dialog_id, const DialogInviteLink &invite_link); + void on_get_dialog_invite_link_info(const string &invite_link, tl_object_ptr &&chat_invite_ptr, Promise &&promise); @@ -1049,8 +1051,7 @@ class ContactsManager : public Actor { Status can_manage_dialog_invite_links(DialogId dialog_id); - bool update_permanent_invite_link(DialogInviteLink &invite_link, - tl_object_ptr &&exported_chat_invite); + bool update_permanent_invite_link(DialogInviteLink &invite_link, DialogInviteLink new_invite_link); const DialogParticipant *get_chat_participant(ChatId chat_id, UserId user_id) const; diff --git a/td/telegram/DialogInviteLink.h b/td/telegram/DialogInviteLink.h index 4a7146330..8eb8f1c6f 100644 --- a/td/telegram/DialogInviteLink.h +++ b/td/telegram/DialogInviteLink.h @@ -51,6 +51,10 @@ class DialogInviteLink { return !invite_link_.empty() && administrator_user_id_.is_valid() && date_ > 0; } + bool is_permanent() const { + return is_permanent_; + } + bool is_expired() const; int32 get_expire_time() const;