From 06940b281769d2495321b6939f8f8b3b9f932f08 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 22 Mar 2023 01:00:54 +0300 Subject: [PATCH] Add DialogFilter::get_chat_filter_object. --- td/telegram/DialogFilter.cpp | 20 +++++++++++++ td/telegram/DialogFilter.h | 2 ++ td/telegram/MessagesManager.cpp | 50 ++++++++++++++------------------- td/telegram/MessagesManager.h | 2 +- 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/td/telegram/DialogFilter.cpp b/td/telegram/DialogFilter.cpp index 708acf69a..3ddfff01b 100644 --- a/td/telegram/DialogFilter.cpp +++ b/td/telegram/DialogFilter.cpp @@ -326,6 +326,26 @@ telegram_api::object_ptr DialogFilter::get_input_dia InputDialogId::get_input_peers(excluded_dialog_ids)); } +td_api::object_ptr DialogFilter::get_chat_filter_object( + const vector &unknown_dialog_ids) const { + auto get_chat_ids = [unknown_dialog_ids](const vector &input_dialog_ids) { + vector chat_ids; + chat_ids.reserve(input_dialog_ids.size()); + for (auto &input_dialog_id : input_dialog_ids) { + auto dialog_id = input_dialog_id.get_dialog_id(); + if (!td::contains(unknown_dialog_ids, dialog_id)) { + chat_ids.push_back(dialog_id.get()); + } + } + return chat_ids; + }; + + return td_api::make_object(title, get_icon_name(), get_chat_ids(pinned_dialog_ids), + get_chat_ids(included_dialog_ids), get_chat_ids(excluded_dialog_ids), + exclude_muted, exclude_read, exclude_archived, include_contacts, + include_non_contacts, include_bots, include_groups, include_channels); +} + td_api::object_ptr DialogFilter::get_chat_filter_info_object() const { return td_api::make_object(dialog_filter_id.get(), title, get_chosen_or_default_icon_name()); } diff --git a/td/telegram/DialogFilter.h b/td/telegram/DialogFilter.h index b97b63188..e0cb76fee 100644 --- a/td/telegram/DialogFilter.h +++ b/td/telegram/DialogFilter.h @@ -78,6 +78,8 @@ class DialogFilter { telegram_api::object_ptr get_input_dialog_filter() const; + td_api::object_ptr get_chat_filter_object(const vector &unknown_dialog_ids) const; + td_api::object_ptr get_chat_filter_info_object() const; void for_each_dialog(std::function callback) const; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index ce0511cc8..4a81defc4 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -22135,39 +22135,31 @@ td_api::object_ptr MessagesManager::get_chat_filter_object(D return get_chat_filter_object(dialog_filter); } -td_api::object_ptr MessagesManager::get_chat_filter_object(const DialogFilter *filter) { - DialogFilterId dialog_filter_id = filter->get_dialog_filter_id(); - vector left_dialog_ids; - auto get_chat_ids = [this, dialog_filter_id, &left_dialog_ids](const vector &input_dialog_ids) { - vector chat_ids; - chat_ids.reserve(input_dialog_ids.size()); - for (auto &input_dialog_id : input_dialog_ids) { - auto dialog_id = input_dialog_id.get_dialog_id(); - const Dialog *d = get_dialog(dialog_id); - if (d != nullptr) { - if (d->order != DEFAULT_ORDER) { - chat_ids.push_back(dialog_id.get()); - } else { - LOG(INFO) << "Skip nonjoined " << dialog_id << " from " << dialog_filter_id; - left_dialog_ids.push_back(dialog_id); - } - } else { - LOG(ERROR) << "Can't find " << dialog_id << " from " << dialog_filter_id; - } - } - return chat_ids; - }; +td_api::object_ptr MessagesManager::get_chat_filter_object(const DialogFilter *dialog_filter) { + DialogFilterId dialog_filter_id = dialog_filter->get_dialog_filter_id(); - auto result = td_api::make_object( - filter->title, filter->get_icon_name(), get_chat_ids(filter->pinned_dialog_ids), - get_chat_ids(filter->included_dialog_ids), get_chat_ids(filter->excluded_dialog_ids), filter->exclude_muted, - filter->exclude_read, filter->exclude_archived, filter->include_contacts, filter->include_non_contacts, - filter->include_bots, filter->include_groups, filter->include_channels); + vector left_dialog_ids; + vector unknown_dialog_ids; + dialog_filter->for_each_dialog([&](const InputDialogId &input_dialog_id) { + auto dialog_id = input_dialog_id.get_dialog_id(); + const Dialog *d = get_dialog(dialog_id); + if (d != nullptr) { + if (d->order == DEFAULT_ORDER) { + LOG(INFO) << "Skip nonjoined " << dialog_id << " from " << dialog_filter_id; + unknown_dialog_ids.push_back(dialog_id); + left_dialog_ids.push_back(dialog_id); + } + } else { + LOG(ERROR) << "Can't find " << dialog_id << " from " << dialog_filter_id; + unknown_dialog_ids.push_back(dialog_id); + } + }); + + auto result = dialog_filter->get_chat_filter_object(unknown_dialog_ids); if (dialog_filter_id.is_valid()) { - delete_dialogs_from_filter(filter, std::move(left_dialog_ids), "get_chat_filter_object"); + delete_dialogs_from_filter(dialog_filter, std::move(left_dialog_ids), "get_chat_filter_object"); } - return result; } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 593c2548b..528efff3a 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2842,7 +2842,7 @@ class MessagesManager final : public Actor { void update_dialogs_hints(const Dialog *d); void update_dialogs_hints_rating(const Dialog *d); - td_api::object_ptr get_chat_filter_object(const DialogFilter *filter); + td_api::object_ptr get_chat_filter_object(const DialogFilter *dialog_filter); void load_dialog_filter_dialogs(DialogFilterId dialog_filter_id, vector &&input_dialog_ids, Promise &&promise);