diff --git a/src/client_server.rs b/src/client_server.rs index f34dc60..f1a9dbe 100644 --- a/src/client_server.rs +++ b/src/client_server.rs @@ -44,7 +44,7 @@ use ruma::{ push::{get_pushers, get_pushrules_all, set_pushrule, set_pushrule_enabled}, read_marker::set_read_marker, redact::redact_event, - room::{self, create_room}, + room::{self, create_room, get_room_event}, session::{get_login_types, login, logout, logout_all}, state::{ create_state_event_for_empty_key, create_state_event_for_key, get_state_events, @@ -2059,6 +2059,35 @@ pub fn get_protocols_route() -> ConduitResult { .into()) } +#[get( + "/_matrix/client/r0/rooms/<_room_id>/event/<_event_id>", + data = "" +)] +pub fn get_room_event_route( + db: State<'_, Database>, + body: Ruma, + _room_id: String, + _event_id: String, +) -> ConduitResult { + let user_id = body.user_id.as_ref().expect("user is authenticated"); + + if !db.rooms.is_joined(user_id, &body.room_id)? { + return Err(Error::BadRequest( + ErrorKind::Forbidden, + "You don't have permission to view this room.", + )); + } + + Ok(get_room_event::Response { + event: db + .rooms + .get_pdu(&body.event_id)? + .ok_or(Error::BadRequest(ErrorKind::NotFound, "Event not found."))? + .to_room_event(), + } + .into()) +} + #[put( "/_matrix/client/r0/rooms/<_room_id>/send/<_event_type>/<_txn_id>", data = "" diff --git a/src/main.rs b/src/main.rs index 47b840f..f406a17 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,6 +36,7 @@ fn setup_rocket() -> rocket::Rocket { client_server::get_pushrules_all_route, client_server::set_pushrule_route, client_server::set_pushrule_enabled_route, + client_server::get_room_event_route, client_server::get_filter_route, client_server::create_filter_route, client_server::set_global_account_data_route,