diff --git a/src/client_server.rs b/src/client_server.rs index 054a0bc..ab70b31 100644 --- a/src/client_server.rs +++ b/src/client_server.rs @@ -714,7 +714,7 @@ pub fn upload_keys_route( if let Some(device_keys) = &body.device_keys { db.users - .add_device_keys(user_id, device_id, device_keys) + .add_device_keys(user_id, device_id, device_keys, &db.globals) .unwrap(); } @@ -1640,7 +1640,18 @@ pub fn sync_route( .map(|(_, v)| v) .collect(), }, - device_lists: Default::default(), + device_lists: if since != 0 { + Some(sync_events::DeviceLists { + changed: db + .users + .device_keys_changed(since) + .map(|u| u.unwrap().to_string()) + .collect(), // TODO: use userids when ruma changes + left: Vec::new(), // TODO + }) + } else { + None // TODO: left + }, device_one_time_keys_count: Default::default(), to_device: sync_events::ToDevice { events: db @@ -1762,10 +1773,6 @@ pub fn get_media_config_route() -> MatrixResult { #[options("/<_segments..>")] pub fn options_route( _segments: rocket::http::uri::Segments<'_>, -) -> MatrixResult { - MatrixResult(Err(Error { - kind: ErrorKind::NotFound, - message: "".to_owned(), - status_code: http::StatusCode::OK, - })) +) -> MatrixResult { + MatrixResult(Ok(send_event_to_device::Response)) } diff --git a/src/database.rs b/src/database.rs index 4cdad87..77ea2f9 100644 --- a/src/database.rs +++ b/src/database.rs @@ -61,6 +61,7 @@ impl Database { token_userdeviceid: db.open_tree("token_userdeviceid").unwrap(), onetimekeyid_onetimekeys: db.open_tree("onetimekeyid_onetimekeys").unwrap(), userdeviceid_devicekeys: db.open_tree("userdeviceid_devicekeys").unwrap(), + devicekeychangeid_userid: db.open_tree("devicekeychangeid_userid").unwrap(), todeviceid_events: db.open_tree("todeviceid_events").unwrap(), }, rooms: rooms::Rooms { diff --git a/src/database/users.rs b/src/database/users.rs index ced5fe1..1b56066 100644 --- a/src/database/users.rs +++ b/src/database/users.rs @@ -15,6 +15,7 @@ pub struct Users { pub(super) onetimekeyid_onetimekeys: sled::Tree, // OneTimeKeyId = UserId + AlgorithmAndDeviceId pub(super) userdeviceid_devicekeys: sled::Tree, + pub(super) devicekeychangeid_userid: sled::Tree, // DeviceKeyChangeId = Count pub(super) todeviceid_events: sled::Tree, // ToDeviceId = UserId + DeviceId + Count } @@ -259,6 +260,7 @@ impl Users { user_id: &UserId, device_id: &DeviceId, device_keys: &DeviceKeys, + globals: &super::globals::Globals, ) -> Result<()> { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); userdeviceid.push(0xff); @@ -267,6 +269,9 @@ impl Users { self.userdeviceid_devicekeys .insert(&userdeviceid, &*serde_json::to_string(&device_keys)?)?; + self.devicekeychangeid_userid + .insert(globals.next_count()?.to_be_bytes(), &*user_id.to_string())?; + Ok(()) } @@ -285,6 +290,13 @@ impl Users { .map(|bytes| Ok(serde_json::from_slice(&bytes?)?)) } + pub fn device_keys_changed(&self, since: u64) -> impl Iterator> { + self.devicekeychangeid_userid + .range(since.to_be_bytes()..) + .values() + .map(|bytes| Ok(UserId::try_from(utils::string_from_bytes(&bytes?)?)?)) + } + pub fn all_device_keys( &self, user_id: &UserId,