1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-08-11 17:50:59 +00:00

feat(devices): update the device last seen timestamp on usage

This commit is contained in:
Matthias Ahouansou 2024-04-19 17:47:21 +01:00
parent a1886a1396
commit 09e1713c30
No known key found for this signature in database
11 changed files with 170 additions and 31 deletions

View file

@ -17,8 +17,8 @@ pub async fn get_devices_route(
let devices: Vec<device::Device> = services()
.users
.all_devices_metadata(sender_user)
.filter_map(|r| r.ok()) // Filter out buggy devices
.all_user_devices_metadata(sender_user)
.await
.collect();
Ok(get_devices::v3::Response { devices })

View file

@ -71,6 +71,17 @@ pub async fn sync_events_route(
) -> Result<sync_events::v3::Response, RumaResponse<UiaaResponse>> {
let sender_user = body.sender_user.expect("user is authenticated");
let sender_device = body.sender_device.expect("user is authenticated");
let cloned_sender_user = sender_user.clone();
let cloned_sender_device = sender_device.clone();
// No need to block sync on device last-seen update
tokio::spawn(async move {
services()
.users
.update_device_last_seen(cloned_sender_user, cloned_sender_device)
.await;
});
let body = body.body;
let mut rx = match services()
@ -1274,6 +1285,17 @@ pub async fn sync_events_v5_route(
) -> Result<sync_events::v5::Response, RumaResponse<UiaaResponse>> {
let sender_user = body.sender_user.expect("user is authenticated");
let sender_device = body.sender_device.expect("user is authenticated");
let cloned_sender_user = sender_user.clone();
let cloned_sender_device = sender_device.clone();
// No need to block sync on device last-seen update
tokio::spawn(async move {
services()
.users
.update_device_last_seen(cloned_sender_user, cloned_sender_device)
.await;
});
let mut body = body.body;
// Setup watchers, so if there's no response, we can wait for them
let watcher = services().globals.watch(&sender_user, &sender_device);

View file

@ -89,7 +89,7 @@ where
if let Some(reg_info) = services().appservice.find_from_token(token).await {
Token::Appservice(Box::new(reg_info.clone()))
} else if let Some((user_id, device_id)) = services().users.find_from_token(token)? {
Token::User((user_id, OwnedDeviceId::from(device_id)))
Token::User((user_id, device_id))
} else {
Token::Invalid
}

View file

@ -2351,8 +2351,8 @@ pub async fn get_devices_route(
.expect("version will not grow that large"),
devices: services()
.users
.all_devices_metadata(&body.user_id)
.filter_map(|r| r.ok())
.all_user_devices_metadata(&body.user_id)
.await
.filter_map(|metadata| {
Some(UserDevice {
keys: services()