From f269a15c230d28670014509b4b97f7d31de82cb8 Mon Sep 17 00:00:00 2001 From: Nyaaori <+@nyaaori.cat> Date: Sun, 27 Nov 2022 17:42:20 +0100 Subject: [PATCH] chore: code cleanup / cargo clippy --- src/config/mod.rs | 2 +- src/database/key_value/rooms/edus/presence.rs | 14 +++++++------- src/service/sending/mod.rs | 5 ++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 7ea551ef..43bd0179 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -268,7 +268,7 @@ fn default_turn_ttl() -> u64 { } fn default_presence_idle_timeout() -> u64 { - 1 * 60 + 60 } fn default_presence_offline_timeout() -> u64 { diff --git a/src/database/key_value/rooms/edus/presence.rs b/src/database/key_value/rooms/edus/presence.rs index b5e10e10..7a48559b 100644 --- a/src/database/key_value/rooms/edus/presence.rs +++ b/src/database/key_value/rooms/edus/presence.rs @@ -69,7 +69,7 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase { self.userid_presenceupdate.insert( user_id.as_bytes(), - &*PresenceUpdate { + &PresenceUpdate { count: services().globals.next_count()?, prev_timestamp: timestamp, curr_timestamp: timestamp, @@ -120,7 +120,7 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase { }; self.userid_presenceupdate - .insert(user_id.as_bytes(), &*new_presence.to_be_bytes())?; + .insert(user_id.as_bytes(), &new_presence.to_be_bytes())?; Ok(()) } @@ -188,7 +188,7 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase { .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) + utils::string_from_bytes(user_id_bytes) .expect("UserID bytes are a valid string"), ) .expect("UserID bytes from database are a valid UserID"); @@ -329,7 +329,7 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase { Some(user_id) }) { - match userid_presenceupdate.remove(&*user_id.as_bytes()) { + match userid_presenceupdate.remove(user_id.as_bytes()) { Ok(_) => (), Err(e) => { error!("An errord occured while removing a stale presence update: {e}") @@ -343,7 +343,7 @@ impl service::rooms::edus::presence::Data for KeyValueDatabase { .filter_map(|room_id| room_id.ok()) { match roomuserid_presenceevent - .remove(&*[room_id.as_bytes(), &[0xff], user_id.as_bytes()].concat()) + .remove(&[room_id.as_bytes(), &[0xff], user_id.as_bytes()].concat()) { Ok(_) => removed_events += 1, Err(e) => error!( @@ -380,13 +380,13 @@ fn parse_presence_event(bytes: &[u8], presence_timestamp: u64) -> Result PresenceState { let globals = &services().globals; - return if last_active_ago < globals.presence_idle_timeout() * 1000 { + if last_active_ago < globals.presence_idle_timeout() * 1000 { PresenceState::Online } else if last_active_ago < globals.presence_offline_timeout() * 1000 { PresenceState::Unavailable } else { PresenceState::Offline - }; + } } /// Translates the timestamp representing last_active_ago to a diff from now. diff --git a/src/service/sending/mod.rs b/src/service/sending/mod.rs index 374e6e3c..b809fd50 100644 --- a/src/service/sending/mod.rs +++ b/src/service/sending/mod.rs @@ -295,7 +295,10 @@ impl Service { user_id, presence: presence_event.content.presence, status_msg: presence_event.content.status_msg, - last_active_ago: presence_event.content.last_active_ago.unwrap_or(uint!(0)), + last_active_ago: presence_event + .content + .last_active_ago + .unwrap_or_else(|| uint!(0)), currently_active: presence_event.content.currently_active.unwrap_or(false), }) .collect();