Add InputDialogId::contains.

GitOrigin-RevId: 89fa1ee325cfebfb02e0aa3f93e658442fc4898a
This commit is contained in:
levlam 2020-05-31 00:26:22 +03:00
parent c7e65e8cc6
commit 1462d1ff3c
3 changed files with 17 additions and 14 deletions

View File

@ -131,6 +131,15 @@ bool InputDialogId::are_equivalent(const vector<InputDialogId> &lhs, const vecto
return lhs_it == lhs.end() && rhs_it == rhs.end();
}
bool InputDialogId::contains(const vector<InputDialogId> &input_dialog_ids, DialogId dialog_id) {
for (auto &input_dialog_id : input_dialog_ids) {
if (input_dialog_id.get_dialog_id() == dialog_id) {
return true;
}
}
return false;
}
vector<DialogId> InputDialogId::get_dialog_ids(const vector<InputDialogId> &input_dialog_ids) {
return transform(input_dialog_ids, [](InputDialogId input_dialog_id) { return input_dialog_id.get_dialog_id(); });
}

View File

@ -42,6 +42,8 @@ class InputDialogId {
static bool are_equivalent(const vector<InputDialogId> &lhs, const vector<InputDialogId> &rhs);
static bool contains(const vector<InputDialogId> &input_dialog_ids, DialogId dialog_id);
bool operator==(const InputDialogId &other) const {
return dialog_id == other.dialog_id && access_hash == other.access_hash;
}

View File

@ -31071,34 +31071,26 @@ bool MessagesManager::need_dialog_in_filter(const Dialog *d, const DialogFilter
CHECK(filter != nullptr);
CHECK(d->order != DEFAULT_ORDER);
auto matches = [](const vector<InputDialogId> input_dialog_ids, DialogId dialog_id) {
for (auto &input_dialog_id : input_dialog_ids) {
if (input_dialog_id.get_dialog_id() == dialog_id) {
return true;
}
}
return false;
};
if (matches(filter->pinned_dialog_ids, d->dialog_id)) {
if (InputDialogId::contains(filter->pinned_dialog_ids, d->dialog_id)) {
return true;
}
if (matches(filter->included_dialog_ids, d->dialog_id)) {
if (InputDialogId::contains(filter->included_dialog_ids, d->dialog_id)) {
return true;
}
if (matches(filter->excluded_dialog_ids, d->dialog_id)) {
if (InputDialogId::contains(filter->excluded_dialog_ids, d->dialog_id)) {
return false;
}
if (d->dialog_id.get_type() == DialogType::SecretChat) {
auto user_id = td_->contacts_manager_->get_secret_chat_user_id(d->dialog_id.get_secret_chat_id());
if (user_id.is_valid()) {
auto dialog_id = DialogId(user_id);
if (matches(filter->pinned_dialog_ids, dialog_id)) {
if (InputDialogId::contains(filter->pinned_dialog_ids, dialog_id)) {
return true;
}
if (matches(filter->included_dialog_ids, dialog_id)) {
if (InputDialogId::contains(filter->included_dialog_ids, dialog_id)) {
return true;
}
if (matches(filter->excluded_dialog_ids, dialog_id)) {
if (InputDialogId::contains(filter->excluded_dialog_ids, dialog_id)) {
return false;
}
}