Skip to content
Snippets Groups Projects
Commit 3c26166f authored by Timo's avatar Timo Committed by Devin Ragotzy
Browse files

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
parent 972babbc
No related branches found
No related tags found
No related merge requests found
...@@ -149,15 +149,7 @@ pub async fn sync_events_route( ...@@ -149,15 +149,7 @@ pub async fn sync_events_route(
device_list_updates.extend( device_list_updates.extend(
db.rooms db.rooms
.room_members(&room_id) .room_members(&room_id)
.filter_map(|user_id| { .filter_map(|user_id| Some(user_id.ok()?))
Some(
UserId::try_from(user_id.ok()?.clone())
.map_err(|_| {
Error::bad_database("Invalid member event state key in db.")
})
.ok()?,
)
})
.filter(|user_id| { .filter(|user_id| {
// Don't send key updates from the sender to the sender // Don't send key updates from the sender to the sender
sender_id != user_id sender_id != user_id
...@@ -491,9 +483,7 @@ pub async fn sync_events_route( ...@@ -491,9 +483,7 @@ pub async fn sync_events_route(
} }
for user_id in left_encrypted_users { for user_id in left_encrypted_users {
// If the user doesn't share an encrypted room with the target anymore, we need to tell let user_target_encrypted = db
// them
if db
.rooms .rooms
.get_shared_rooms(vec![sender_id.clone(), user_id.clone()]) .get_shared_rooms(vec![sender_id.clone(), user_id.clone()])
.filter_map(|r| r.ok()) .filter_map(|r| r.ok())
...@@ -505,8 +495,10 @@ pub async fn sync_events_route( ...@@ -505,8 +495,10 @@ pub async fn sync_events_route(
.is_some(), .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); device_list_left.insert(user_id);
} }
} }
......
...@@ -75,23 +75,23 @@ fn get_event(&self, room_id: &RoomId, event_id: &EventId) -> StdResult<StateEven ...@@ -75,23 +75,23 @@ fn get_event(&self, room_id: &RoomId, event_id: &EventId) -> StdResult<StateEven
.map_err(|e| e.to_string())? .map_err(|e| e.to_string())?
.ok_or_else(|| "PDU via room_id and event_id not found in the db.".to_owned())?; .ok_or_else(|| "PDU via room_id and event_id not found in the db.".to_owned())?;
utils::deserialize( serde_json::from_slice(
&self &self
.pduid_pdu .pduid_pdu
.get(pid) .get(pid)
.map_err(|e| e.to_string())? .map_err(|e| e.to_string())?
.ok_or_else(|| "PDU via pduid not found in db.".to_owned())?, .ok_or_else(|| "PDU via pduid not found in db.".to_owned())?,
) )
.map_err(|e| e.to_string())
.and_then(|pdu: StateEvent| { .and_then(|pdu: StateEvent| {
// conduit's PDU's always contain a room_id but some // conduit's PDU's always contain a room_id but some
// of ruma's do not so this must be an Option // of ruma's do not so this must be an Option
if pdu.room_id() == Some(room_id) { if pdu.room_id() == Some(room_id) {
Ok(pdu) Ok(pdu)
} else { } 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 @@ pub fn get_shared_rooms<'a>( ...@@ -1207,8 +1207,7 @@ pub fn get_shared_rooms<'a>(
let roomid_index = key let roomid_index = key
.iter() .iter()
.enumerate() .enumerate()
.filter(|(_, &b)| b == 0xff) .find(|(_, &b)| b == 0xff)
.nth(0)
.ok_or_else(|| Error::bad_database("Invalid userroomid_joined in db."))? .ok_or_else(|| Error::bad_database("Invalid userroomid_joined in db."))?
.0 .0
+ 1; // +1 because the room id starts AFTER the separator + 1; // +1 because the room id starts AFTER the separator
......
use crate::Error;
use argon2::{Config, Variant}; use argon2::{Config, Variant};
use cmp::Ordering; use cmp::Ordering;
use rand::prelude::*; use rand::prelude::*;
...@@ -91,8 +90,3 @@ pub fn common_elements( ...@@ -91,8 +90,3 @@ pub fn common_elements(
.all(|b| b) .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."))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment