Add DialogFilter::for_each_dialog.

This commit is contained in:
levlam 2023-03-21 16:12:47 +03:00
parent b5fe088574
commit 51c4c1368b
3 changed files with 21 additions and 15 deletions

View File

@ -256,6 +256,14 @@ td_api::object_ptr<td_api::chatFilterInfo> DialogFilter::get_chat_filter_info_ob
return td_api::make_object<td_api::chatFilterInfo>(dialog_filter_id.get(), title, get_chosen_or_default_icon_name());
}
void DialogFilter::for_each_dialog(std::function<void(const InputDialogId &)> callback) const {
for (auto input_dialog_ids : {&pinned_dialog_ids, &excluded_dialog_ids, &included_dialog_ids}) {
for (const auto &input_dialog_id : *input_dialog_ids) {
callback(input_dialog_id);
}
}
}
// merges changes from old_server_filter to new_server_filter in old_filter
unique_ptr<DialogFilter> DialogFilter::merge_dialog_filter_changes(const DialogFilter *old_filter,
const DialogFilter *old_server_filter,

View File

@ -16,6 +16,8 @@
#include "td/utils/Status.h"
#include "td/utils/StringBuilder.h"
#include <functional>
namespace td {
class DialogFilter {
@ -62,6 +64,8 @@ class DialogFilter {
td_api::object_ptr<td_api::chatFilterInfo> get_chat_filter_info_object() const;
void for_each_dialog(std::function<void(const InputDialogId &)> callback) const;
// merges changes from old_server_filter to new_server_filter in old_filter
static unique_ptr<DialogFilter> merge_dialog_filter_changes(const DialogFilter *old_filter,
const DialogFilter *old_server_filter,

View File

@ -17055,14 +17055,11 @@ void MessagesManager::load_dialog_filter(DialogFilterId dialog_filter_id, bool f
void MessagesManager::load_dialog_filter(const DialogFilter *filter, bool force, Promise<Unit> &&promise) {
CHECK(!td_->auth_manager_->is_bot());
vector<InputDialogId> needed_dialog_ids;
for (auto input_dialog_ids :
{&filter->pinned_dialog_ids, &filter->excluded_dialog_ids, &filter->included_dialog_ids}) {
for (const auto &input_dialog_id : *input_dialog_ids) {
if (!have_dialog(input_dialog_id.get_dialog_id())) {
needed_dialog_ids.push_back(input_dialog_id);
}
filter->for_each_dialog([&](const InputDialogId &input_dialog_id) {
if (!have_dialog(input_dialog_id.get_dialog_id())) {
needed_dialog_ids.push_back(input_dialog_id);
}
}
});
vector<InputDialogId> input_dialog_ids;
for (const auto &input_dialog_id : needed_dialog_ids) {
@ -19673,14 +19670,11 @@ void MessagesManager::sort_dialog_filter_input_dialog_ids(DialogFilter *dialog_f
sort_input_dialog_ids(dialog_filter->included_dialog_ids);
FlatHashSet<DialogId, DialogIdHash> all_dialog_ids;
for (auto input_dialog_ids :
{&dialog_filter->pinned_dialog_ids, &dialog_filter->excluded_dialog_ids, &dialog_filter->included_dialog_ids}) {
for (const auto &input_dialog_id : *input_dialog_ids) {
auto dialog_id = input_dialog_id.get_dialog_id();
CHECK(dialog_id.is_valid());
LOG_CHECK(all_dialog_ids.insert(dialog_id).second) << source << ' ' << dialog_id << ' ' << dialog_filter;
}
}
dialog_filter->for_each_dialog([&](const InputDialogId &input_dialog_id) {
auto dialog_id = input_dialog_id.get_dialog_id();
CHECK(dialog_id.is_valid());
LOG_CHECK(all_dialog_ids.insert(dialog_id).second) << source << ' ' << dialog_id << ' ' << dialog_filter;
});
}
Result<unique_ptr<DialogFilter>> MessagesManager::create_dialog_filter(DialogFilterId dialog_filter_id,