fix: send devicekeyupdate users in /sync

merge-requests/22/head
timokoesters 4 years ago
parent f0aed35ecf
commit 42ae433b25
No known key found for this signature in database
GPG Key ID: 356E705610F626D5

@ -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<get_media_config::Response> {
#[options("/<_segments..>")]
pub fn options_route(
_segments: rocket::http::uri::Segments<'_>,
) -> MatrixResult<create_message_event::Response> {
MatrixResult(Err(Error {
kind: ErrorKind::NotFound,
message: "".to_owned(),
status_code: http::StatusCode::OK,
}))
) -> MatrixResult<send_event_to_device::Response> {
MatrixResult(Ok(send_event_to_device::Response))
}

@ -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 {

@ -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<Item = Result<UserId>> {
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,

Loading…
Cancel
Save