Add InputDialogId::are_equivalent.

GitOrigin-RevId: db383a715d619cb504bb8baa906bf1eae00e5e4d
This commit is contained in:
levlam 2020-05-28 03:29:12 +03:00
parent f80bd321b0
commit 26812a77f6
2 changed files with 22 additions and 0 deletions

View File

@ -109,6 +109,26 @@ tl_object_ptr<telegram_api::InputPeer> InputDialogId::get_input_peer() const {
}
}
bool InputDialogId::are_equivalent(const vector<InputDialogId> &lhs, const vector<InputDialogId> &rhs) {
auto lhs_it = lhs.begin();
auto rhs_it = rhs.begin();
while (lhs_it != lhs.end() && rhs_it != rhs.end()) {
while (lhs_it != lhs.end() && lhs_it->get_dialog_id().get_type() == DialogType::SecretChat) {
++lhs_it;
}
while (rhs_it != rhs.end() && rhs_it->get_dialog_id().get_type() == DialogType::SecretChat) {
++rhs_it;
}
if (lhs_it == lhs.end() || rhs_it == rhs.end()) {
break;
}
if (lhs_it->get_dialog_id() != rhs_it->get_dialog_id()) {
return false;
}
}
return lhs_it == lhs.end() && rhs_it == rhs.end();
}
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

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