fix: send devicekeyupdate users in /sync
This commit is contained in:
parent
f0aed35ecf
commit
42ae433b25
3 changed files with 28 additions and 8 deletions
|
@ -714,7 +714,7 @@ pub fn upload_keys_route(
|
||||||
|
|
||||||
if let Some(device_keys) = &body.device_keys {
|
if let Some(device_keys) = &body.device_keys {
|
||||||
db.users
|
db.users
|
||||||
.add_device_keys(user_id, device_id, device_keys)
|
.add_device_keys(user_id, device_id, device_keys, &db.globals)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1640,7 +1640,18 @@ pub fn sync_route(
|
||||||
.map(|(_, v)| v)
|
.map(|(_, v)| v)
|
||||||
.collect(),
|
.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(),
|
device_one_time_keys_count: Default::default(),
|
||||||
to_device: sync_events::ToDevice {
|
to_device: sync_events::ToDevice {
|
||||||
events: db
|
events: db
|
||||||
|
@ -1762,10 +1773,6 @@ pub fn get_media_config_route() -> MatrixResult<get_media_config::Response> {
|
||||||
#[options("/<_segments..>")]
|
#[options("/<_segments..>")]
|
||||||
pub fn options_route(
|
pub fn options_route(
|
||||||
_segments: rocket::http::uri::Segments<'_>,
|
_segments: rocket::http::uri::Segments<'_>,
|
||||||
) -> MatrixResult<create_message_event::Response> {
|
) -> MatrixResult<send_event_to_device::Response> {
|
||||||
MatrixResult(Err(Error {
|
MatrixResult(Ok(send_event_to_device::Response))
|
||||||
kind: ErrorKind::NotFound,
|
|
||||||
message: "".to_owned(),
|
|
||||||
status_code: http::StatusCode::OK,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@ impl Database {
|
||||||
token_userdeviceid: db.open_tree("token_userdeviceid").unwrap(),
|
token_userdeviceid: db.open_tree("token_userdeviceid").unwrap(),
|
||||||
onetimekeyid_onetimekeys: db.open_tree("onetimekeyid_onetimekeys").unwrap(),
|
onetimekeyid_onetimekeys: db.open_tree("onetimekeyid_onetimekeys").unwrap(),
|
||||||
userdeviceid_devicekeys: db.open_tree("userdeviceid_devicekeys").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(),
|
todeviceid_events: db.open_tree("todeviceid_events").unwrap(),
|
||||||
},
|
},
|
||||||
rooms: rooms::Rooms {
|
rooms: rooms::Rooms {
|
||||||
|
|
|
@ -15,6 +15,7 @@ pub struct Users {
|
||||||
|
|
||||||
pub(super) onetimekeyid_onetimekeys: sled::Tree, // OneTimeKeyId = UserId + AlgorithmAndDeviceId
|
pub(super) onetimekeyid_onetimekeys: sled::Tree, // OneTimeKeyId = UserId + AlgorithmAndDeviceId
|
||||||
pub(super) userdeviceid_devicekeys: sled::Tree,
|
pub(super) userdeviceid_devicekeys: sled::Tree,
|
||||||
|
pub(super) devicekeychangeid_userid: sled::Tree, // DeviceKeyChangeId = Count
|
||||||
|
|
||||||
pub(super) todeviceid_events: sled::Tree, // ToDeviceId = UserId + DeviceId + Count
|
pub(super) todeviceid_events: sled::Tree, // ToDeviceId = UserId + DeviceId + Count
|
||||||
}
|
}
|
||||||
|
@ -259,6 +260,7 @@ impl Users {
|
||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
device_id: &DeviceId,
|
device_id: &DeviceId,
|
||||||
device_keys: &DeviceKeys,
|
device_keys: &DeviceKeys,
|
||||||
|
globals: &super::globals::Globals,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
let mut userdeviceid = user_id.to_string().as_bytes().to_vec();
|
||||||
userdeviceid.push(0xff);
|
userdeviceid.push(0xff);
|
||||||
|
@ -267,6 +269,9 @@ impl Users {
|
||||||
self.userdeviceid_devicekeys
|
self.userdeviceid_devicekeys
|
||||||
.insert(&userdeviceid, &*serde_json::to_string(&device_keys)?)?;
|
.insert(&userdeviceid, &*serde_json::to_string(&device_keys)?)?;
|
||||||
|
|
||||||
|
self.devicekeychangeid_userid
|
||||||
|
.insert(globals.next_count()?.to_be_bytes(), &*user_id.to_string())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,6 +290,13 @@ impl Users {
|
||||||
.map(|bytes| Ok(serde_json::from_slice(&bytes?)?))
|
.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(
|
pub fn all_device_keys(
|
||||||
&self,
|
&self,
|
||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
|
|
Loading…
Reference in a new issue