From 0b46b93bc8b704afc7c7f7876ab293b4bef9f485 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 7 Jun 2020 23:22:33 +0300 Subject: [PATCH] Add MessagesManager::do_update_list_last_dialog_date. GitOrigin-RevId: 337bcc66893ef8c47224d77d5ab54d841936c836 --- td/telegram/MessagesManager.cpp | 20 ++++++++++++-------- td/telegram/MessagesManager.h | 2 ++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index e433c9e41..62138e6fe 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -30840,10 +30840,11 @@ void MessagesManager::update_list_last_pinned_dialog_date(DialogList &list, bool } } -void MessagesManager::update_list_last_dialog_date(DialogList &list, bool only_update) { +// must not call get_dialog_filter +bool MessagesManager::do_update_list_last_dialog_date(DialogList &list, const vector &folder_ids) const { CHECK(!td_->auth_manager_->is_bot()); auto new_last_dialog_date = list.last_pinned_dialog_date_; - for (auto folder_id : get_dialog_list_folder_ids(list)) { + for (auto folder_id : folder_ids) { const auto &folder = *get_dialog_folder(folder_id); if (folder.folder_last_dialog_date_ < new_last_dialog_date) { new_last_dialog_date = folder.folder_last_dialog_date_; @@ -30851,7 +30852,6 @@ void MessagesManager::update_list_last_dialog_date(DialogList &list, bool only_u } if (list.list_last_dialog_date_ != new_last_dialog_date) { - auto old_dialog_total_count = get_dialog_total_count(list); auto old_last_dialog_date = list.list_last_dialog_date_; LOG(INFO) << "Update last dialog date in " << list.dialog_list_id << " from " << old_last_dialog_date << " to " << new_last_dialog_date; @@ -30862,11 +30862,15 @@ void MessagesManager::update_list_last_dialog_date(DialogList &list, bool only_u << get_dialog_folder(FolderId::archive())->folder_last_dialog_date_ << " " << list.load_list_queries_.size() << " " << list.pinned_dialogs_; list.list_last_dialog_date_ = new_last_dialog_date; + return true; + } + return false; +} - if (only_update) { - return; - } - +void MessagesManager::update_list_last_dialog_date(DialogList &list, bool only_update) { + auto old_dialog_total_count = get_dialog_total_count(list); + auto old_last_dialog_date = list.list_last_dialog_date_; + if (do_update_list_last_dialog_date(list, get_dialog_list_folder_ids(list)) && !only_update) { for (auto it = std::upper_bound(list.pinned_dialogs_.begin(), list.pinned_dialogs_.end(), old_last_dialog_date); it != list.pinned_dialogs_.end() && *it <= list.list_last_dialog_date_; ++it) { auto dialog_id = it->get_dialog_id(); @@ -30875,7 +30879,7 @@ void MessagesManager::update_list_last_dialog_date(DialogList &list, bool only_u send_update_chat_position(list.dialog_list_id, d, "update_list_last_dialog_date"); } - bool is_list_further_loaded = new_last_dialog_date == MAX_DIALOG_DATE; + bool is_list_further_loaded = list.list_last_dialog_date_ == MAX_DIALOG_DATE; for (auto folder_id : get_dialog_list_folder_ids(list)) { const auto &folder = *get_dialog_folder(folder_id); for (auto it = folder.ordered_dialogs_.upper_bound(old_last_dialog_date); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index b8ba44139..d5ccf69ec 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2547,6 +2547,8 @@ class MessagesManager : public Actor { void update_list_last_pinned_dialog_date(DialogList &list, bool only_update = false); + bool do_update_list_last_dialog_date(DialogList &list, const vector &folder_ids) const; + void update_list_last_dialog_date(DialogList &list, bool only_update = false); void load_notification_settings();