Skip to content

Commit

Permalink
Add DialogFilter::for_each_dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Mar 21, 2023
1 parent b5fe088 commit 51c4c13
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
8 changes: 8 additions & 0 deletions td/telegram/DialogFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions td/telegram/DialogFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "td/utils/Status.h"
#include "td/utils/StringBuilder.h"

#include <functional>

namespace td {

class DialogFilter {
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 9 additions & 15 deletions td/telegram/MessagesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 51c4c13

Please sign in to comment.