From 477fe509b52539c3be098fd98e23ef43e7056e66 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 4 Nov 2022 17:23:43 +0300 Subject: [PATCH] Fix adding of a chat list to beginning. --- td/telegram/MessagesManager.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 4ca87654d..424858f3b 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -17721,7 +17721,7 @@ void MessagesManager::on_get_dialog_filters(Result> new_server_dialog_filters; - LOG(INFO) << "Receive " << filters.size() << " chat filters from server"; + LOG(INFO) << "Receive chat filters from server: " << to_string(filters); std::unordered_set new_dialog_filter_ids; int32 server_main_dialog_list_position = -1; int32 position = 0; @@ -19769,7 +19769,20 @@ void MessagesManager::on_update_dialog_filter(unique_ptr dialog_fi } if (!is_edited) { - server_dialog_filters_.push_back(std::move(dialog_filter)); + bool at_beginning = false; + for (const auto &recommended_dialog_filter : recommended_dialog_filters_) { + if (DialogFilter::are_similar(*recommended_dialog_filter.dialog_filter, *dialog_filter)) { + at_beginning = true; + } + } + if (at_beginning) { + server_dialog_filters_.insert(server_dialog_filters_.begin(), std::move(dialog_filter)); + } else { + server_dialog_filters_.push_back(std::move(dialog_filter)); + } + if (at_beginning && main_dialog_list_position_ != 0) { + main_dialog_list_position_++; + } } save_dialog_filters(); }