diff --git a/Cargo.toml b/Cargo.toml index ceaa9d53..145d117c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ serde = "1.0.106" serde_json = "1.0.51" # Ruma dependencies -js_int = "0.1.4" +js_int = "0.1.5" ruma-api = "0.16.0-rc.2" ruma-client-api = { version = "0.8.0-rc.5" } ruma-events = { version = "0.21.0-beta.1" } diff --git a/src/base_client.rs b/src/base_client.rs index 1fa0315c..83c76585 100644 --- a/src/base_client.rs +++ b/src/base_client.rs @@ -223,7 +223,7 @@ impl Client { pub(crate) async fn calculate_room_names(&self) -> Vec { let mut res = Vec::new(); - for (_id, room) in &self.joined_rooms { + for room in self.joined_rooms.values() { let room = room.read().await; res.push(room.room_name.calculate_name(&room.members)) } diff --git a/src/models/room.rs b/src/models/room.rs index 05178f4c..8700eb03 100644 --- a/src/models/room.rs +++ b/src/models/room.rs @@ -147,13 +147,13 @@ impl RoomName { } else if !self.aliases.is_empty() && !self.aliases[0].alias().is_empty() { self.aliases[0].alias().trim().to_string() } else { - let joined = self.joined_member_count.unwrap_or(UInt::min_value()); - let invited = self.invited_member_count.unwrap_or(UInt::min_value()); + let joined = self.joined_member_count.unwrap_or(UInt::MIN); + let invited = self.invited_member_count.unwrap_or(UInt::MIN); let heroes = UInt::new(self.heroes.len() as u64).unwrap(); let one = UInt::new(1).unwrap(); - let invited_joined = if invited + joined == UInt::min_value() { - UInt::min_value() + let invited_joined = if invited + joined == UInt::MIN { + UInt::MIN } else { invited + joined - one }; @@ -166,8 +166,7 @@ impl RoomName { .map(|mem| { mem.display_name .clone() - .unwrap_or(mem.user_id.localpart().to_string()) - .to_string() + .unwrap_or_else(|| mem.user_id.localpart().to_string()) }) .collect::>(); // stabilize ordering @@ -180,7 +179,7 @@ impl RoomName { .map(|mem| { mem.display_name .clone() - .unwrap_or(mem.user_id.localpart().to_string()) + .unwrap_or_else(|| mem.user_id.localpart().to_string()) }) .collect::>(); names.sort(); diff --git a/src/request_builder.rs b/src/request_builder.rs index a9893321..4ff56930 100644 --- a/src/request_builder.rs +++ b/src/request_builder.rs @@ -327,17 +327,15 @@ mod test { .invite_3pid(vec![]) .is_direct(true) .power_level_override(PowerLevelsEventContent { - ban: Int::max_value(), + ban: Int::MAX, events: BTreeMap::default(), - events_default: Int::min_value(), - invite: Int::min_value(), - kick: Int::min_value(), - redact: Int::max_value(), - state_default: Int::min_value(), - users_default: Int::min_value(), - notifications: NotificationPowerLevels { - room: Int::min_value(), - }, + events_default: Int::MIN, + invite: Int::MIN, + kick: Int::MIN, + redact: Int::MAX, + state_default: Int::MIN, + users_default: Int::MIN, + notifications: NotificationPowerLevels { room: Int::MIN }, users: BTreeMap::default(), }) .preset(RoomPreset::PrivateChat) diff --git a/src/test_builder.rs b/src/test_builder.rs index db0f616a..b6badf5e 100644 --- a/src/test_builder.rs +++ b/src/test_builder.rs @@ -96,7 +96,7 @@ impl EventBuilder { variant: fn(Ev) -> Event, ) -> Self { let val = fs::read_to_string(path.as_ref()) - .expect(&format!("file not found {:?}", path.as_ref())); + .unwrap_or_else(|_| panic!("file not found {:?}", path.as_ref())); let event = serde_json::from_str::>(&val) .unwrap() .deserialize() @@ -112,7 +112,7 @@ impl EventBuilder { variant: fn(Ev) -> Event, ) -> Self { let val = fs::read_to_string(path.as_ref()) - .expect(&format!("file not found {:?}", path.as_ref())); + .unwrap_or_else(|_| panic!("file not found {:?}", path.as_ref())); let event = serde_json::from_str::>(&val) .unwrap() .deserialize() @@ -128,7 +128,7 @@ impl EventBuilder { variant: fn(Ev) -> RoomEvent, ) -> Self { let val = fs::read_to_string(path.as_ref()) - .expect(&format!("file not found {:?}", path.as_ref())); + .unwrap_or_else(|_| panic!("file not found {:?}", path.as_ref())); let event = serde_json::from_str::>(&val) .unwrap() .deserialize() @@ -144,7 +144,7 @@ impl EventBuilder { variant: fn(Ev) -> StateEvent, ) -> Self { let val = fs::read_to_string(path.as_ref()) - .expect(&format!("file not found {:?}", path.as_ref())); + .unwrap_or_else(|_| panic!("file not found {:?}", path.as_ref())); let event = serde_json::from_str::>(&val) .unwrap() .deserialize() @@ -156,7 +156,7 @@ impl EventBuilder { /// Add a presence event to the presence events `Vec`. pub fn add_presence_event_from_file>(mut self, path: P) -> Self { let val = fs::read_to_string(path.as_ref()) - .expect(&format!("file not found {:?}", path.as_ref())); + .unwrap_or_else(|_| panic!("file not found {:?}", path.as_ref())); let event = serde_json::from_str::>(&val) .unwrap() .deserialize() @@ -174,7 +174,7 @@ impl EventBuilder { P: AsRef, { let body = fs::read_to_string(path.as_ref()) - .expect(&format!("file not found {:?}", path.as_ref())); + .unwrap_or_else(|_| panic!("file not found {:?}", path.as_ref())); let mock = Some( mock(method, matcher) .with_status(200) @@ -367,12 +367,8 @@ impl ClientTestRunner { } for event in &self.room_events { - cli.receive_joined_timeline_event( - room_id, - &mut EventJson::from(event.clone()), - &mut false, - ) - .await; + cli.receive_joined_timeline_event(room_id, &mut EventJson::from(event), &mut false) + .await; } for event in &self.presence_events { cli.receive_presence_event(room_id, event).await;