From 03311836af967b27c8637f86d7bfb24cc8378752 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 26 Dec 2019 05:21:09 +0300 Subject: [PATCH] Add DialogList.in_memory_total_count_. GitOrigin-RevId: ab418de72778dc9a51761a5acbcf1fadc2116197 --- td/telegram/MessagesManager.cpp | 10 +++++++++- td/telegram/MessagesManager.h | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 82e6491c..d77a11e1 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -9584,7 +9584,7 @@ void MessagesManager::recalc_unread_count(FolderId folder_id) { int32 dialog_muted_count = 0; int32 dialog_marked_count = 0; int32 dialog_muted_marked_count = 0; - for (auto &dialog_date : list.ordered_server_dialogs_) { + for (const auto &dialog_date : list.ordered_server_dialogs_) { auto dialog_id = dialog_date.get_dialog_id(); Dialog *d = get_dialog(dialog_id); CHECK(d != nullptr); @@ -27988,6 +27988,14 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen bool is_removed_from_folder = new_order == DEFAULT_ORDER; bool is_added_to_folder = d->order == DEFAULT_ORDER; + if (is_removed_from_folder) { + list.in_memory_total_count_--; + } else if (is_added_to_folder) { + list.in_memory_total_count_++; + } + CHECK(static_cast(list.ordered_dialogs_.size()) <= list.in_memory_total_count_); + CHECK(static_cast(list.in_memory_total_count_) <= list.ordered_server_dialogs_.size()); + if (!is_loaded_from_database && had_unread_counter != has_unread_counter && !td_->auth_manager_->is_bot()) { auto unread_count = d->server_unread_count + d->local_unread_count; const char *change_source = had_unread_counter ? "on_dialog_leave" : "on_dialog_join"; diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 73468fd5..07cdf6a3 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1213,9 +1213,10 @@ class MessagesManager : public Actor { int32 unread_dialog_muted_count_ = 0; int32 unread_dialog_marked_count_ = 0; int32 unread_dialog_muted_marked_count_ = 0; + int32 in_memory_total_count_ = 0; - std::set ordered_dialogs_; - std::set ordered_server_dialogs_; + std::set ordered_dialogs_; // all dialogs with date <= last_dialog_date_ + std::set ordered_server_dialogs_; // all known dialogs, including with default order // date of last dialog in the dialog list // last_dialog_date_ == min(last_server_dialog_date_, last_secret_chat_dialog_date_)