From f3f95a73d0d667afa213f01553e5294a1b30e502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Wed, 7 Apr 2021 15:56:57 +0200 Subject: [PATCH] improvement: /event route --- src/main.rs | 1 + src/server_server.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/main.rs b/src/main.rs index f523abbd..4ccc0251 100644 --- a/src/main.rs +++ b/src/main.rs @@ -164,6 +164,7 @@ fn setup_rocket() -> (rocket::Rocket, Config) { server_server::get_public_rooms_route, server_server::get_public_rooms_filtered_route, server_server::send_transaction_message_route, + server_server::get_event_route, server_server::get_missing_events_route, server_server::get_room_state_ids_route, server_server::get_profile_information_route, diff --git a/src/server_server.rs b/src/server_server.rs index 421b4f81..84cfe618 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -1388,6 +1388,34 @@ pub(crate) fn append_incoming_pdu( Ok(()) } +#[cfg_attr( + feature = "conduit_bin", + get("/_matrix/federation/v1/event/<_>", data = "") +)] +#[tracing::instrument(skip(db, body))] +pub fn get_event_route<'a>( + db: State<'a, Database>, + body: Ruma>, +) -> ConduitResult { + if !db.globals.allow_federation() { + return Err(Error::bad_config("Federation is disabled.")); + } + + Ok(get_event::v1::Response { + origin: db.globals.server_name().to_owned(), + origin_server_ts: SystemTime::now(), + pdu: PduEvent::convert_to_outgoing_federation_event( + serde_json::from_value( + db.rooms + .get_pdu_json(&body.event_id)? + .ok_or(Error::BadRequest(ErrorKind::NotFound, "Event not found."))?, + ) + .map_err(|_| Error::bad_database("Invalid pdu in database."))?, + ), + } + .into()) +} + #[cfg_attr( feature = "conduit_bin", post("/_matrix/federation/v1/get_missing_events/<_>", data = "")