fix-try 1

This commit is contained in:
holger krekel
2019-09-08 18:40:58 +02:00
parent b32f3f71ad
commit 87c8c5a363

View File

@@ -1711,31 +1711,29 @@ fn search_chat_ids_by_contact_ids(
params![], params![],
|row| Ok((row.get::<_, u32>(0)?, row.get::<_, u32>(1)?)), |row| Ok((row.get::<_, u32>(0)?, row.get::<_, u32>(1)?)),
|rows| { |rows| {
let mut last_chat_id = 0; let mut chat2contacts = HashMap<u32, Vec<u32>>::new();
let mut matches = 0;
let mut mismatches = 0;
for row in rows { for row in rows {
let (chat_id, contact_id) = row?; let (chat_id, contact_id) = row?;
if chat_id != last_chat_id { let mut contacts: Vec<u32>;
if matches == contact_ids.len() && mismatches == 0 { contacts = match chat2contacts.get(chat_id) {
chat_ids.push(last_chat_id); Some(c) => c,
None => {
l = Vec<u32>::default();
chat2contacts.insert(chat_id, l);
l
} }
last_chat_id = chat_id;
matches = 0;
mismatches = 0;
} }
if contact_id == contact_ids[matches] { contacts.push(contact_id);
matches += 1; }
} else { for (&chat_id, &contacts) in chat2contacts.iter_mut() {
mismatches += 1; contacts.retain(|x| {
contact_ids.contains(x)
});
if contacts.len() == contact_ids.len() {
chat_ids.push(chat_id)
} }
} }
Ok(())
if matches == contact_ids.len() && mismatches == 0 {
chat_ids.push(last_chat_id);
}
Ok(())
} }
).unwrap(); // TODO: better error handling ).unwrap(); // TODO: better error handling