From 7062bdb484880e499eb080e768f2db6a9a9950e8 Mon Sep 17 00:00:00 2001 From: Devin R Date: Fri, 27 Mar 2020 20:17:06 -0400 Subject: [PATCH] fix slice match room_aliases --- src/async_client.rs | 6 +++--- src/base_client.rs | 5 +++++ tests/async_client_tests.rs | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/async_client.rs b/src/async_client.rs index 811af61c..7996c4c9 100644 --- a/src/async_client.rs +++ b/src/async_client.rs @@ -262,10 +262,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> { + 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 { self.base_client.read().await.calculate_room_name(room_id) diff --git a/src/base_client.rs b/src/base_client.rs index 6c1a23e2..d5d7b74f 100644 --- a/src/base_client.rs +++ b/src/base_client.rs @@ -203,6 +203,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 { @@ -233,15 +234,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 { @@ -251,6 +255,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() { diff --git a/tests/async_client_tests.rs b/tests/async_client_tests.rs index 6584f0c0..670a43da 100644 --- a/tests/async_client_tests.rs +++ b/tests/async_client_tests.rs @@ -92,5 +92,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 ) }); }