style(presence): code cleanup

This commit is contained in:
Jakub Kubík 2022-11-22 18:37:04 +01:00
parent 2eb5907d95
commit 502526789d
No known key found for this signature in database
GPG key ID: D3A0D5D60F3A173F
2 changed files with 14 additions and 30 deletions

View file

@ -79,11 +79,6 @@ pub async fn get_presence_route(
presence: presence.content.presence,
})
} else {
Ok(get_presence::v3::Response {
status_msg: None,
currently_active: None,
last_active_ago: None,
presence: PresenceState::Offline,
})
Ok(get_presence::v3::Response::new(PresenceState::Offline))
}
}

View file

@ -185,31 +185,20 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase {
Ok(Box::new(
self.roomuserid_presenceevent
.scan_prefix(room_id.as_bytes().to_vec())
.filter_map(|(roomuserid_bytes, presence_bytes)| {
let user_id_bytes =
roomuserid_bytes.split(|byte| *byte == 0xff as u8).last()?;
Some((
UserId::parse(
utils::string_from_bytes(&user_id_bytes)
.expect("UserID bytes are a valid string"),
)
.expect("UserID bytes from database are a valid UserID")
.to_owned(),
presence_bytes,
))
})
.filter_map(
move |(user_id, presence_bytes)| -> Option<(OwnedUserId, PresenceEvent)> {
let timestamp = user_timestamp.get(&user_id)?;
.filter_map(move |(roomuserid_bytes, presence_bytes)| {
let user_id_bytes = roomuserid_bytes.split(|byte| *byte == 0xff).last()?;
let user_id: OwnedUserId = UserId::parse(
utils::string_from_bytes(&user_id_bytes)
.expect("UserID bytes are a valid string"),
)
.expect("UserID bytes from database are a valid UserID");
Some((
user_id,
parse_presence_event(&presence_bytes, *timestamp).expect(
"PresenceEvent bytes from database are a valid PresenceEvent",
),
))
},
),
let timestamp = user_timestamp.get(&user_id)?;
let presence_event = parse_presence_event(&presence_bytes, *timestamp)
.expect("PresenceEvent bytes from database are a valid PresenceEvent");
Some((user_id, presence_event))
}),
))
}