Merge remote-tracking branch 'origin/main' into ben-getting-started-example

This commit is contained in:
Benjamin Kampmann
2022-08-03 11:39:50 +02:00
3 changed files with 37 additions and 1 deletions
+12
View File
@@ -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:
+4
View File
@@ -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<Ev, Ctx, H>(
&self,
room_id: &RoomId,
+21 -1
View File
@@ -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<Ev, Ctx, H>(&self, handler: H) -> EventHandlerHandle
where
Ev: SyncEvent + DeserializeOwned + Send + 'static,
H: EventHandler<Ev, Ctx>,
<H::Future as Future>::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