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:
parent
972babbc79
commit
3c26166fb5
3 changed files with 10 additions and 25 deletions
|
@ -149,15 +149,7 @@ pub async fn sync_events_route(
|
|||
device_list_updates.extend(
|
||||
db.rooms
|
||||
.room_members(&room_id)
|
||||
.filter_map(|user_id| {
|
||||
Some(
|
||||
UserId::try_from(user_id.ok()?.clone())
|
||||
.map_err(|_| {
|
||||
Error::bad_database("Invalid member event state key in db.")
|
||||
})
|
||||
.ok()?,
|
||||
)
|
||||
})
|
||||
.filter_map(|user_id| Some(user_id.ok()?))
|
||||
.filter(|user_id| {
|
||||
// Don't send key updates from the sender to the sender
|
||||
sender_id != user_id
|
||||
|
@ -491,9 +483,7 @@ pub async fn sync_events_route(
|
|||
}
|
||||
|
||||
for user_id in left_encrypted_users {
|
||||
// If the user doesn't share an encrypted room with the target anymore, we need to tell
|
||||
// them
|
||||
if db
|
||||
let user_target_encrypted = db
|
||||
.rooms
|
||||
.get_shared_rooms(vec![sender_id.clone(), user_id.clone()])
|
||||
.filter_map(|r| r.ok())
|
||||
|
@ -505,8 +495,10 @@ pub async fn sync_events_route(
|
|||
.is_some(),
|
||||
)
|
||||
})
|
||||
.all(|encrypted| !encrypted)
|
||||
{
|
||||
.all(|encrypted| !encrypted);
|
||||
// If the user doesn't share an encrypted room with the target anymore, we need to tell
|
||||
// them
|
||||
if user_target_encrypted {
|
||||
device_list_left.insert(user_id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,23 +75,23 @@ impl StateStore for Rooms {
|
|||
.map_err(|e| e.to_string())?
|
||||
.ok_or_else(|| "PDU via room_id and event_id not found in the db.".to_owned())?;
|
||||
|
||||
utils::deserialize(
|
||||
serde_json::from_slice(
|
||||
&self
|
||||
.pduid_pdu
|
||||
.get(pid)
|
||||
.map_err(|e| e.to_string())?
|
||||
.ok_or_else(|| "PDU via pduid not found in db.".to_owned())?,
|
||||
)
|
||||
.map_err(|e| e.to_string())
|
||||
.and_then(|pdu: StateEvent| {
|
||||
// conduit's PDU's always contain a room_id but some
|
||||
// of ruma's do not so this must be an Option
|
||||
if pdu.room_id() == Some(room_id) {
|
||||
Ok(pdu)
|
||||
} else {
|
||||
Err(Error::bad_database("Found PDU for incorrect room in db."))
|
||||
Err("Found PDU for incorrect room in db.".into())
|
||||
}
|
||||
})
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1207,8 +1207,7 @@ impl Rooms {
|
|||
let roomid_index = key
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, &b)| b == 0xff)
|
||||
.nth(0)
|
||||
.find(|(_, &b)| b == 0xff)
|
||||
.ok_or_else(|| Error::bad_database("Invalid userroomid_joined in db."))?
|
||||
.0
|
||||
+ 1; // +1 because the room id starts AFTER the separator
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use crate::Error;
|
||||
use argon2::{Config, Variant};
|
||||
use cmp::Ordering;
|
||||
use rand::prelude::*;
|
||||
|
@ -91,8 +90,3 @@ pub fn common_elements(
|
|||
.all(|b| b)
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, T: serde::Deserialize<'de>>(val: &'de sled::IVec) -> Result<T, Error> {
|
||||
serde_json::from_slice::<T>(val.as_ref())
|
||||
.map_err(|_| Error::bad_database("Found invalid bytes as PDU in db."))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue