Update signature of AppService::register_event_handler

It no longer requires a mutable `AppService` and can also be chained,
like `Client::register_event_handler`.
This commit is contained in:
Jonas Platte
2021-11-11 19:28:40 +01:00
parent 1651952903
commit df50d59de2
3 changed files with 4 additions and 4 deletions

View File

@@ -39,7 +39,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
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();

View File

@@ -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<Ev, Ctx, H>(&mut self, handler: H) -> Result<()>
pub async fn register_event_handler<Ev, Ctx, H>(&self, handler: H) -> Result<&Self>
where
Ev: SyncEvent + DeserializeOwned + Send + 'static,
H: EventHandler<Ev, Ctx>,
@@ -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

View File

@@ -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));