From 5512700b7704e5ffb0f1733ab9e2873bf41006a5 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 1 Dec 2021 23:31:10 +0300 Subject: [PATCH] Immediately reload *Full after invalidation in opened chats. --- td/telegram/ContactsManager.cpp | 22 ++++++++++++++-------- td/telegram/ContactsManager.h | 2 +- td/telegram/MessagesManager.cpp | 7 +++++++ td/telegram/MessagesManager.h | 2 ++ td/telegram/UpdatesManager.cpp | 2 +- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 312695f6a..faf731e7a 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -8012,11 +8012,15 @@ void ContactsManager::on_update_phone_number_privacy() { void ContactsManager::invalidate_user_full(UserId user_id) { auto user_full = get_user_full_force(user_id); - if (user_full != nullptr && !user_full->is_expired()) { - user_full->expires_at = 0.0; - user_full->need_save_to_database = true; + if (user_full != nullptr) { + td_->messages_manager_->on_dialog_info_full_invalidated(DialogId(user_id)); - update_user_full(user_full, user_id, "invalidate_user_full"); + if (!user_full->is_expired()) { + user_full->expires_at = 0.0; + user_full->need_save_to_database = true; + + update_user_full(user_full, user_id, "invalidate_user_full"); + } } } @@ -9591,7 +9595,7 @@ void ContactsManager::on_load_channel_full_from_database(ChannelId channel_id, s if (invalidated_channels_full_.erase(channel_id) > 0 || (!c->is_slow_mode_enabled && channel_full->slow_mode_delay != 0)) { - do_invalidate_channel_full(channel_full, !c->is_slow_mode_enabled); + do_invalidate_channel_full(channel_full, channel_id, !c->is_slow_mode_enabled); } td_->group_call_manager_->on_update_dialog_about(DialogId(channel_id), channel_full->description, false); @@ -12162,15 +12166,17 @@ void ContactsManager::invalidate_channel_full(ChannelId channel_id, bool need_dr LOG(INFO) << "Invalidate supergroup full for " << channel_id; auto channel_full = get_channel_full(channel_id, true, "invalidate_channel_full"); // must not load ChannelFull if (channel_full != nullptr) { - do_invalidate_channel_full(channel_full, need_drop_slow_mode_delay); + do_invalidate_channel_full(channel_full, channel_id, need_drop_slow_mode_delay); update_channel_full(channel_full, channel_id, "invalidate_channel_full"); } else { invalidated_channels_full_.insert(channel_id); } } -void ContactsManager::do_invalidate_channel_full(ChannelFull *channel_full, bool need_drop_slow_mode_delay) { +void ContactsManager::do_invalidate_channel_full(ChannelFull *channel_full, ChannelId channel_id, + bool need_drop_slow_mode_delay) { CHECK(channel_full != nullptr); + td_->messages_manager_->on_dialog_info_full_invalidated(DialogId(channel_id)); if (channel_full->expires_at >= Time::now()) { channel_full->expires_at = 0.0; channel_full->need_save_to_database = true; @@ -13195,7 +13201,7 @@ void ContactsManager::on_channel_status_changed(const Channel *c, ChannelId chan auto channel_full = get_channel_full(channel_id, true, "on_channel_status_changed"); if (channel_full != nullptr) { // otherwise invite_link will be dropped when the channel is loaded on_update_channel_full_invite_link(channel_full, nullptr); - do_invalidate_channel_full(channel_full, !c->is_slow_mode_enabled); + do_invalidate_channel_full(channel_full, channel_id, !c->is_slow_mode_enabled); update_channel_full(channel_full, channel_id, "on_channel_status_changed"); } } else { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 88592427a..485c087b9 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1269,7 +1269,7 @@ class ContactsManager final : public Actor { void drop_channel_photos(ChannelId channel_id, bool is_empty, bool drop_channel_full_photo, const char *source); - static void do_invalidate_channel_full(ChannelFull *channel_full, bool need_drop_slow_mode_delay); + void do_invalidate_channel_full(ChannelFull *channel_full, ChannelId channel_id, bool need_drop_slow_mode_delay); void update_user_online_member_count(User *u); void update_chat_online_member_count(const ChatFull *chat_full, ChatId chat_id, bool is_from_server); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 3e7cae8bb..14cb71b20 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -17589,6 +17589,13 @@ void MessagesManager::reload_dialog_info_full(DialogId dialog_id) { } } +void MessagesManager::on_dialog_info_full_invalidated(DialogId dialog_id) { + Dialog *d = get_dialog(dialog_id); + if (d != nullptr && d->is_opened) { + reload_dialog_info_full(dialog_id); + } +} + MessageId MessagesManager::get_dialog_pinned_message(DialogId dialog_id, Promise &&promise) { Dialog *d = get_dialog_force(dialog_id, "get_dialog_pinned_message"); if (d == nullptr) { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index e0d9cfbcd..af8dc759c 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -524,6 +524,8 @@ class MessagesManager final : public Actor { void reload_dialog_info_full(DialogId dialog_id); + void on_dialog_info_full_invalidated(DialogId dialog_id); + bool load_dialog(DialogId dialog_id, int left_tries, Promise &&promise); void load_dialogs(vector dialog_ids, Promise> &&promise); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 829c6105b..0f28b717f 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -2513,7 +2513,7 @@ void UpdatesManager::on_update(tl_object_ptr update, Promise &&promise) { - // nothing to do + td_->messages_manager_->on_dialog_info_full_invalidated(DialogId(ChatId(update->chat_id_))); promise.set_value(Unit()); }