cargo fmt/clippy

This commit is contained in:
Devin R 2020-03-27 17:23:49 -04:00
parent a29ae2a62e
commit 82f8af4c08
3 changed files with 25 additions and 12 deletions

View file

@ -14,7 +14,6 @@
// limitations under the License.
use futures::future::{BoxFuture, Future, FutureExt};
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex, RwLock as SyncLock};

View file

@ -21,7 +21,7 @@ use crate::events::room::{
aliases::AliasesEvent,
canonical_alias::CanonicalAliasEvent,
member::{MemberEvent, MembershipState},
name::{NameEvent},
name::NameEvent,
};
use crate::events::EventResult;
use crate::identifiers::RoomAliasId;
@ -109,16 +109,20 @@ impl RoomName {
} else if !self.aliases.is_empty() {
self.aliases[0].alias().to_string()
} else {
// TODO
let mut names = members.values().flat_map(|m| m.display_name.clone()).take(3).collect::<Vec<_>>();
// TODO
let mut names = members
.values()
.flat_map(|m| m.display_name.clone())
.take(3)
.collect::<Vec<_>>();
if names.is_empty() {
// TODO implement the rest of matrix-js-sdk handling of room names
format!("Room {}", room_id)
} else {
// stabilize order
names.sort();
names.join(", ").to_string()
names.join(", ")
}
}
}
@ -353,13 +357,21 @@ impl Client {
}
pub(crate) fn calculate_room_name(&self, room_id: &str) -> Option<String> {
self.joined_rooms.get(room_id)
.and_then(|r| r.read().map(|r| r.room_name.calculate_name(room_id, &r.members)).ok())
self.joined_rooms.get(room_id).and_then(|r| {
r.read()
.map(|r| r.room_name.calculate_name(room_id, &r.members))
.ok()
})
}
pub(crate) fn calculate_room_names(&self) -> Vec<String> {
self.joined_rooms.iter()
.flat_map(|(id, room)| room.read().map(|r| r.room_name.calculate_name(id, &r.members)).ok())
self.joined_rooms
.iter()
.flat_map(|(id, room)| {
room.read()
.map(|r| r.room_name.calculate_name(id, &r.members))
.ok()
})
.collect()
}

View file

@ -59,7 +59,6 @@ fn sync() {
assert!(rt.block_on(client.sync_token()).is_some());
}
#[test]
fn timeline() {
let mut rt = Runtime::new().unwrap();
@ -87,7 +86,10 @@ fn timeline() {
let _response = rt.block_on(client.sync(sync_settings)).unwrap();
assert_eq!(vec!["tutorial"], rt.block_on(client.get_room_names()));
assert_eq!(Some("tutorial".into()), rt.block_on(client.get_room_name("!SVkFJHzfwvuaIEawgC:localhost")));
assert_eq!(
Some("tutorial".into()),
rt.block_on(client.get_room_name("!SVkFJHzfwvuaIEawgC:localhost"))
);
// rt.block_on(async { println!("{:#?}", &client.base_client().await.joined_rooms ) });
}