improvement: device list works better

The only situation that isn't working yet is sending `left` events for
users when the sender leaves the room
This commit is contained in:
Timo 2020-08-21 21:22:59 +02:00
parent f23fb32e95
commit 4323cf5fec
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
5 changed files with 246 additions and 151 deletions

View file

@ -1,5 +1,6 @@
use argon2::{Config, Variant};
use rand::prelude::*;
use sled::IVec;
use std::{
convert::TryInto,
time::{SystemTime, UNIX_EPOCH},
@ -59,3 +60,29 @@ pub fn calculate_hash(password: &str) -> Result<String, argon2::Error> {
let salt = random_string(32);
argon2::hash_encoded(password.as_bytes(), salt.as_bytes(), &hashing_config)
}
pub fn common_elements(
mut iterators: impl Iterator<Item = impl Iterator<Item = IVec>>,
) -> Option<impl Iterator<Item = IVec>> {
let first_iterator = iterators.next()?;
let mut other_iterators = iterators.map(|i| i.peekable()).collect::<Vec<_>>();
Some(first_iterator.filter(move |target| {
other_iterators
.iter_mut()
.map(|it| {
while let Some(element) = it.peek() {
if element > target {
return false;
} else if element == target {
return true;
} else {
it.next();
}
}
false
})
.all(|b| b)
}))
}