Add DialogFilter::for_each_dialog.
This commit is contained in:
parent
b5fe088574
commit
51c4c1368b
@ -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());
|
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
|
// 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,
|
unique_ptr<DialogFilter> DialogFilter::merge_dialog_filter_changes(const DialogFilter *old_filter,
|
||||||
const DialogFilter *old_server_filter,
|
const DialogFilter *old_server_filter,
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
#include "td/utils/Status.h"
|
#include "td/utils/Status.h"
|
||||||
#include "td/utils/StringBuilder.h"
|
#include "td/utils/StringBuilder.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
class DialogFilter {
|
class DialogFilter {
|
||||||
@ -62,6 +64,8 @@ class DialogFilter {
|
|||||||
|
|
||||||
td_api::object_ptr<td_api::chatFilterInfo> get_chat_filter_info_object() const;
|
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
|
// 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,
|
static unique_ptr<DialogFilter> merge_dialog_filter_changes(const DialogFilter *old_filter,
|
||||||
const DialogFilter *old_server_filter,
|
const DialogFilter *old_server_filter,
|
||||||
|
@ -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) {
|
void MessagesManager::load_dialog_filter(const DialogFilter *filter, bool force, Promise<Unit> &&promise) {
|
||||||
CHECK(!td_->auth_manager_->is_bot());
|
CHECK(!td_->auth_manager_->is_bot());
|
||||||
vector<InputDialogId> needed_dialog_ids;
|
vector<InputDialogId> needed_dialog_ids;
|
||||||
for (auto input_dialog_ids :
|
filter->for_each_dialog([&](const InputDialogId &input_dialog_id) {
|
||||||
{&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())) {
|
if (!have_dialog(input_dialog_id.get_dialog_id())) {
|
||||||
needed_dialog_ids.push_back(input_dialog_id);
|
needed_dialog_ids.push_back(input_dialog_id);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
vector<InputDialogId> input_dialog_ids;
|
vector<InputDialogId> input_dialog_ids;
|
||||||
for (const auto &input_dialog_id : needed_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);
|
sort_input_dialog_ids(dialog_filter->included_dialog_ids);
|
||||||
|
|
||||||
FlatHashSet<DialogId, DialogIdHash> all_dialog_ids;
|
FlatHashSet<DialogId, DialogIdHash> all_dialog_ids;
|
||||||
for (auto input_dialog_ids :
|
dialog_filter->for_each_dialog([&](const InputDialogId &input_dialog_id) {
|
||||||
{&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();
|
auto dialog_id = input_dialog_id.get_dialog_id();
|
||||||
CHECK(dialog_id.is_valid());
|
CHECK(dialog_id.is_valid());
|
||||||
LOG_CHECK(all_dialog_ids.insert(dialog_id).second) << source << ' ' << dialog_id << ' ' << dialog_filter;
|
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,
|
Result<unique_ptr<DialogFilter>> MessagesManager::create_dialog_filter(DialogFilterId dialog_filter_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user