fix slice match room_aliases

This commit is contained in:
Devin R 2020-03-27 20:17:06 -04:00
parent 3df15b72eb
commit c2022180ad
3 changed files with 9 additions and 4 deletions

View file

@ -263,10 +263,10 @@ impl AsyncClient {
#[doc(hidden)]
/// Access to the underlying `BaseClient`. Used for testing and debugging so far.
pub async fn base_client(&self) -> RwLockReadGuard<'_, BaseClient> {
self.base_client.read().await
pub fn base_client(&self) -> Arc<RwLock<BaseClient>> {
Arc::clone(&self.base_client)
}
/// Calculate the room name from a `RoomId`, returning a string.
pub async fn get_room_name(&self, room_id: &str) -> Option<String> {
self.base_client.read().await.calculate_room_name(room_id)

View file

@ -199,6 +199,7 @@ impl Room {
}
/// Handle a room.member updating the room state if necessary.
///
/// Returns true if the joined member list changed, false otherwise.
pub fn handle_membership(&mut self, event: &MemberEvent) -> bool {
match event.content.membership {
@ -229,15 +230,18 @@ impl Room {
}
/// Handle a room.aliases event, updating the room state if necessary.
///
/// Returns true if the room name changed, false otherwise.
pub fn handle_room_aliases(&mut self, event: &AliasesEvent) -> bool {
match event.content.aliases.as_slice() {
[alias] => self.room_aliases(alias),
[alias, ..] => self.room_aliases(alias),
_ => false,
}
}
/// Handle a room.canonical_alias event, updating the room state if necessary.
///
/// Returns true if the room name changed, false otherwise.
pub fn handle_canonical(&mut self, event: &CanonicalAliasEvent) -> bool {
match &event.content.alias {
@ -247,6 +251,7 @@ impl Room {
}
/// Handle a room.name event, updating the room state if necessary.
///
/// Returns true if the room name changed, false otherwise.
pub fn handle_room_name(&mut self, event: &NameEvent) -> bool {
match event.content.name() {

View file

@ -91,5 +91,5 @@ fn timeline() {
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().read().await.joined_rooms ) });
}