cargo fmt/clippy
parent
bcdd81dc8c
commit
063d86af71
|
@ -14,7 +14,6 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use futures::future::{BoxFuture, Future, FutureExt};
|
use futures::future::{BoxFuture, Future, FutureExt};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::{TryFrom, TryInto};
|
||||||
use std::result::Result as StdResult;
|
use std::result::Result as StdResult;
|
||||||
use std::sync::atomic::{AtomicU64, Ordering};
|
use std::sync::atomic::{AtomicU64, Ordering};
|
||||||
|
|
|
@ -25,7 +25,7 @@ use crate::events::room::{
|
||||||
aliases::AliasesEvent,
|
aliases::AliasesEvent,
|
||||||
canonical_alias::CanonicalAliasEvent,
|
canonical_alias::CanonicalAliasEvent,
|
||||||
member::{MemberEvent, MembershipState},
|
member::{MemberEvent, MembershipState},
|
||||||
name::{NameEvent},
|
name::NameEvent,
|
||||||
};
|
};
|
||||||
use crate::events::EventResult;
|
use crate::events::EventResult;
|
||||||
use crate::identifiers::RoomAliasId;
|
use crate::identifiers::RoomAliasId;
|
||||||
|
@ -113,16 +113,20 @@ impl RoomName {
|
||||||
} else if !self.aliases.is_empty() {
|
} else if !self.aliases.is_empty() {
|
||||||
self.aliases[0].alias().to_string()
|
self.aliases[0].alias().to_string()
|
||||||
} else {
|
} else {
|
||||||
// TODO
|
// TODO
|
||||||
let mut names = members.values().flat_map(|m| m.display_name.clone()).take(3).collect::<Vec<_>>();
|
let mut names = members
|
||||||
|
.values()
|
||||||
|
.flat_map(|m| m.display_name.clone())
|
||||||
|
.take(3)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
if names.is_empty() {
|
if names.is_empty() {
|
||||||
// TODO implement the rest of matrix-js-sdk handling of room names
|
// TODO implement the rest of matrix-js-sdk handling of room names
|
||||||
format!("Room {}", room_id)
|
format!("Room {}", room_id)
|
||||||
} else {
|
} else {
|
||||||
// stabilize order
|
// stabilize order
|
||||||
names.sort();
|
names.sort();
|
||||||
names.join(", ").to_string()
|
names.join(", ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -362,13 +366,21 @@ impl Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn calculate_room_name(&self, room_id: &str) -> Option<String> {
|
pub(crate) fn calculate_room_name(&self, room_id: &str) -> Option<String> {
|
||||||
self.joined_rooms.get(room_id)
|
self.joined_rooms.get(room_id).and_then(|r| {
|
||||||
.and_then(|r| r.read().map(|r| r.room_name.calculate_name(room_id, &r.members)).ok())
|
r.read()
|
||||||
|
.map(|r| r.room_name.calculate_name(room_id, &r.members))
|
||||||
|
.ok()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn calculate_room_names(&self) -> Vec<String> {
|
pub(crate) fn calculate_room_names(&self) -> Vec<String> {
|
||||||
self.joined_rooms.iter()
|
self.joined_rooms
|
||||||
.flat_map(|(id, room)| room.read().map(|r| r.room_name.calculate_name(id, &r.members)).ok())
|
.iter()
|
||||||
|
.flat_map(|(id, room)| {
|
||||||
|
room.read()
|
||||||
|
.map(|r| r.room_name.calculate_name(id, &r.members))
|
||||||
|
.ok()
|
||||||
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,6 @@ fn sync() {
|
||||||
assert!(rt.block_on(client.sync_token()).is_some());
|
assert!(rt.block_on(client.sync_token()).is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn timeline() {
|
fn timeline() {
|
||||||
let mut rt = Runtime::new().unwrap();
|
let mut rt = Runtime::new().unwrap();
|
||||||
|
@ -88,7 +87,10 @@ fn timeline() {
|
||||||
let _response = rt.block_on(client.sync(sync_settings)).unwrap();
|
let _response = rt.block_on(client.sync(sync_settings)).unwrap();
|
||||||
|
|
||||||
assert_eq!(vec!["tutorial"], rt.block_on(client.get_room_names()));
|
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 ) });
|
// rt.block_on(async { println!("{:#?}", &client.base_client().await.joined_rooms ) });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue