From 9fca639f9b689a2a421ad3f4a785baf12b1c721a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 2 Aug 2022 13:38:30 +0200 Subject: [PATCH 1/2] feat(sdk): Add room::Common::add_event_handler --- crates/matrix-sdk/src/client/mod.rs | 4 ++++ crates/matrix-sdk/src/room/common.rs | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 0fa06b1d7..bff88ffa6 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -464,6 +464,10 @@ impl Client { /// [`add_event_handler`][Self::add_event_handler], except that the handler /// will only be called for events in the room with the specified ID. See /// that method for more details on event handler functions. + /// + /// `client.add_room_event_handler(room_id, hdl)` is equivalent to + /// `room.add_event_handler(hdl)`. Use whichever one is more convenient in + /// your use case. pub async fn add_room_event_handler( &self, room_id: &RoomId, diff --git a/crates/matrix-sdk/src/room/common.rs b/crates/matrix-sdk/src/room/common.rs index 8d4e600fe..9050862ba 100644 --- a/crates/matrix-sdk/src/room/common.rs +++ b/crates/matrix-sdk/src/room/common.rs @@ -1,4 +1,4 @@ -use std::{collections::BTreeMap, ops::Deref, sync::Arc}; +use std::{collections::BTreeMap, future::Future, ops::Deref, sync::Arc}; #[cfg(feature = "experimental-timeline")] use futures_core::stream::Stream; @@ -41,8 +41,10 @@ use ruma::{ serde::Raw, uint, EventId, MatrixToUri, MatrixUri, OwnedEventId, OwnedServerName, RoomId, UInt, UserId, }; +use serde::de::DeserializeOwned; use crate::{ + event_handler::{EventHandler, EventHandlerHandle, EventHandlerResult, SyncEvent}, media::{MediaFormat, MediaRequest}, room::RoomType, BaseRoom, Client, Error, HttpError, HttpResult, Result, RoomMember, @@ -231,6 +233,24 @@ impl Common { Ok(response) } + /// Register a handler for events of a specific type, within this room. + /// + /// This method works the same way as [`Client::add_event_handler`], except + /// that the handler will only be called for events within this room. See + /// that method for more details on event handler functions. + /// + /// `room.add_event_handler(hdl)` is equivalent to + /// `client.add_room_event_handler(room_id, hdl)`. Use whichever one is more + /// convenient in your use case. + pub async fn add_event_handler(&self, handler: H) -> EventHandlerHandle + where + Ev: SyncEvent + DeserializeOwned + Send + 'static, + H: EventHandler, + ::Output: EventHandlerResult, + { + self.client.add_room_event_handler(self.room_id(), handler).await + } + /// Get a stream for the timeline of this `Room` /// /// The first stream is forward in time and second stream is backward in From 38a71972e5931405aa9e4be4b6c677fdefe11e29 Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Tue, 2 Aug 2022 15:42:45 +0200 Subject: [PATCH 2/2] ci: add backend server for integration test with tarpaulin --- .github/workflows/coverage.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 0e30d443f..0f976e9ec 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -35,6 +35,18 @@ jobs: command: install args: cargo-tarpaulin + # set up backend for integration tests + - uses: actions/setup-python@v4 + with: + python-version: 3.8 + + - uses: gnunicorn/setup-matrix-synapse@main + with: + uploadLogs: true + httpPort: 8228 + disableRateLimiting: true + serverName: "matrix-sdk.rs" + - name: Run tarpaulin uses: actions-rs/cargo@v1 with: