From e2432d476e6fef8bbb5e74ca63ead5e1059362ca Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 8 Sep 2021 23:33:08 +0200 Subject: [PATCH] Add Client::register_notification_handler It had been planned but forgotten. --- matrix_sdk/src/client.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index 58ef9683..ac55fafa 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -979,6 +979,23 @@ impl Client { self } + /// Register a handler for a notification. + /// + /// Similar to `.register_event_handler`, but only allows functions or + /// closures with exactly the three arguments `Notification`, `room::Room`, + /// `Client` for now. + pub async fn register_notification_handler(&self, handler: H) -> &Self + where + H: Fn(Notification, room::Room, Client) -> Fut + Send + Sync + 'static, + Fut: Future + Send + 'static, + { + self.notification_handlers.write().await.push(Box::new( + move |notification, room, client| (handler)(notification, room, client).boxed(), + )); + + self + } + /// Get all the rooms the client knows about. /// /// This will return the list of joined, invited, and left rooms.