Add DialogFilter::get_chat_filter_object.

This commit is contained in:
levlam 2023-03-22 01:00:54 +03:00
parent 0c22f267c2
commit 06940b2817
4 changed files with 44 additions and 30 deletions

View File

@ -326,6 +326,26 @@ telegram_api::object_ptr<telegram_api::DialogFilter> DialogFilter::get_input_dia
InputDialogId::get_input_peers(excluded_dialog_ids));
}
td_api::object_ptr<td_api::chatFilter> DialogFilter::get_chat_filter_object(
const vector<DialogId> &unknown_dialog_ids) const {
auto get_chat_ids = [unknown_dialog_ids](const vector<InputDialogId> &input_dialog_ids) {
vector<int64> 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<td_api::chatFilter>(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<td_api::chatFilterInfo> DialogFilter::get_chat_filter_info_object() const {
return td_api::make_object<td_api::chatFilterInfo>(dialog_filter_id.get(), title, get_chosen_or_default_icon_name());
}

View File

@ -78,6 +78,8 @@ class DialogFilter {
telegram_api::object_ptr<telegram_api::DialogFilter> get_input_dialog_filter() const;
td_api::object_ptr<td_api::chatFilter> get_chat_filter_object(const vector<DialogId> &unknown_dialog_ids) 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;

View File

@ -22135,39 +22135,31 @@ td_api::object_ptr<td_api::chatFilter> MessagesManager::get_chat_filter_object(D
return get_chat_filter_object(dialog_filter);
}
td_api::object_ptr<td_api::chatFilter> MessagesManager::get_chat_filter_object(const DialogFilter *filter) {
DialogFilterId dialog_filter_id = filter->get_dialog_filter_id();
vector<DialogId> left_dialog_ids;
auto get_chat_ids = [this, dialog_filter_id, &left_dialog_ids](const vector<InputDialogId> &input_dialog_ids) {
vector<int64> 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<td_api::chatFilter> 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<td_api::chatFilter>(
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<DialogId> left_dialog_ids;
vector<DialogId> 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;
}

View File

@ -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<td_api::chatFilter> get_chat_filter_object(const DialogFilter *filter);
td_api::object_ptr<td_api::chatFilter> get_chat_filter_object(const DialogFilter *dialog_filter);
void load_dialog_filter_dialogs(DialogFilterId dialog_filter_id, vector<InputDialogId> &&input_dialog_ids,
Promise<Unit> &&promise);