From df50d59de2f17aa419c8702dfe47f441f8300078 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 11 Nov 2021 19:28:40 +0100 Subject: [PATCH] Update signature of AppService::register_event_handler It no longer requires a mutable `AppService` and can also be chained, like `Client::register_event_handler`. --- crates/matrix-sdk-appservice/examples/appservice_autojoin.rs | 2 +- crates/matrix-sdk-appservice/src/lib.rs | 4 ++-- crates/matrix-sdk-appservice/tests/tests.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/matrix-sdk-appservice/examples/appservice_autojoin.rs b/crates/matrix-sdk-appservice/examples/appservice_autojoin.rs index fca04fa28..f52e11328 100644 --- a/crates/matrix-sdk-appservice/examples/appservice_autojoin.rs +++ b/crates/matrix-sdk-appservice/examples/appservice_autojoin.rs @@ -39,7 +39,7 @@ pub async fn main() -> Result<(), Box> { let server_name = "localhost"; let registration = AppServiceRegistration::try_from_yaml_file("./tests/registration.yaml")?; - let mut appservice = AppService::new(homeserver_url, server_name, registration).await?; + let appservice = AppService::new(homeserver_url, server_name, registration).await?; appservice .register_event_handler({ let appservice = appservice.clone(); diff --git a/crates/matrix-sdk-appservice/src/lib.rs b/crates/matrix-sdk-appservice/src/lib.rs index eda03217c..d2043e7d6 100644 --- a/crates/matrix-sdk-appservice/src/lib.rs +++ b/crates/matrix-sdk-appservice/src/lib.rs @@ -380,7 +380,7 @@ impl AppService { /// /// [`join` room `timeline` events]: https://spec.matrix.org/unstable/client-server-api/#get_matrixclientr0sync /// [MSC2409]: https://github.com/matrix-org/matrix-doc/pull/2409 - pub async fn register_event_handler(&mut self, handler: H) -> Result<()> + pub async fn register_event_handler(&self, handler: H) -> Result<&Self> where Ev: SyncEvent + DeserializeOwned + Send + 'static, H: EventHandler, @@ -389,7 +389,7 @@ impl AppService { let client = self.get_cached_client(None)?; client.register_event_handler(handler).await; - Ok(()) + Ok(self) } /// Register a responder for queries about the existence of a user with a diff --git a/crates/matrix-sdk-appservice/tests/tests.rs b/crates/matrix-sdk-appservice/tests/tests.rs index e732d96cb..40bf54e42 100644 --- a/crates/matrix-sdk-appservice/tests/tests.rs +++ b/crates/matrix-sdk-appservice/tests/tests.rs @@ -199,7 +199,7 @@ async fn test_no_access_token() -> Result<()> { #[async_test] async fn test_event_handler() -> Result<()> { - let mut appservice = appservice(None).await?; + let appservice = appservice(None).await?; #[allow(clippy::mutex_atomic)] let on_state_member = Arc::new(Mutex::new(false));