From c2022180aded4e1a51fd7147dcb44a4c78e281cc 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 ba8e90cb..a76ef571 100644 --- a/src/async_client.rs +++ b/src/async_client.rs @@ -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> { + 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 54f60b0a..6fce1abf 100644 --- a/src/base_client.rs +++ b/src/base_client.rs @@ -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() { diff --git a/tests/async_client_tests.rs b/tests/async_client_tests.rs index 0f4b425b..ecf9c2a1 100644 --- a/tests/async_client_tests.rs +++ b/tests/async_client_tests.rs @@ -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 ) }); }