From 469071e105781181356d41b98541ea36160156f8 Mon Sep 17 00:00:00 2001 From: the0 Date: Sat, 11 Jul 2020 14:08:37 +0200 Subject: [PATCH] feat: implement /event (#144) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge branch 'master' into event-route Event: Implement /event Co-authored-by: the0 Reviewed-on: https://git.koesters.xyz/timo/conduit/pulls/144 Reviewed-by: Timo Kösters --- src/client_server.rs | 31 ++++++++++++++++++++++++++++++- src/main.rs | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) 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,