From e72346cb6fd2f7b08a93387df8dc14c0469b1746 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 19 Feb 2020 04:14:58 +0300 Subject: [PATCH] Make repair_channel_server_unread_count persistent. GitOrigin-RevId: f99be75116f3e5bbfa2224d74723ec4fa5feaa91 --- td/telegram/MessagesManager.cpp | 15 ++++++++++++++- td/telegram/MessagesManager.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 67b8ea70e..c6c3b199c 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -4347,6 +4347,7 @@ void MessagesManager::Dialog::store(StorerT &storer) const { STORE_FLAG(can_report_location); STORE_FLAG(has_scheduled_server_messages); STORE_FLAG(has_scheduled_database_messages); + STORE_FLAG(need_repair_channel_server_unread_count); END_STORE_FLAGS(); } @@ -4507,6 +4508,7 @@ void MessagesManager::Dialog::parse(ParserT &parser) { PARSE_FLAG(can_report_location); PARSE_FLAG(has_scheduled_server_messages); PARSE_FLAG(has_scheduled_database_messages); + PARSE_FLAG(need_repair_channel_server_unread_count); END_PARSE_FLAGS(); } else { is_folder_id_inited = false; @@ -9495,9 +9497,12 @@ void MessagesManager::repair_channel_server_unread_count(Dialog *d) { // there is no unread count in left channels return; } + if (!d->need_repair_channel_server_unread_count) { + d->need_repair_channel_server_unread_count = true; + on_dialog_updated(d->dialog_id, "repair_channel_server_unread_count"); + } LOG(INFO) << "Reload ChannelFull for " << d->dialog_id << " to repair unread message counts"; - // TODO logevent? td_->contacts_manager_->get_channel_full(d->dialog_id.get_channel_id(), Promise()); } @@ -9511,6 +9516,11 @@ void MessagesManager::read_history_inbox(DialogId dialog_id, MessageId max_messa Dialog *d = get_dialog_force(dialog_id); if (d != nullptr) { + if (d->need_repair_channel_server_unread_count) { + d->need_repair_channel_server_unread_count = false; + on_dialog_updated(dialog_id, "read_history_inbox"); + } + // there can be updateReadHistoryInbox up to message 0, if messages where read and then all messages where deleted if (!max_message_id.is_valid() && max_message_id != MessageId()) { LOG(ERROR) << "Receive read inbox update in " << dialog_id << " up to " << max_message_id << " from " << source; @@ -27868,6 +27878,9 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr &&last_datab CHECK(dialog_type != DialogType::SecretChat); repair_server_unread_count(dialog_id, d->server_unread_count); } + if (d->need_repair_channel_server_unread_count) { + repair_channel_server_unread_count(d); + } update_dialog_pos(d, false, "fix_new_dialog 7", true, is_loaded_from_database); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index def6058c3..35b49ff7f 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1104,6 +1104,7 @@ class MessagesManager : public Actor { bool is_pinned_message_id_inited = false; bool is_folder_id_inited = false; bool need_repair_server_unread_count = false; + bool need_repair_channel_server_unread_count = false; bool is_marked_as_unread = false; bool last_sent_has_scheduled_messages = false; bool has_scheduled_server_messages = false;