improvement: /event route
This commit is contained in:
parent
d0cdbe2e2b
commit
f3f95a73d0
2 changed files with 29 additions and 0 deletions
|
@ -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,
|
||||
|
|
|
@ -1388,6 +1388,34 @@ pub(crate) fn append_incoming_pdu(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "conduit_bin",
|
||||
get("/_matrix/federation/v1/event/<_>", data = "<body>")
|
||||
)]
|
||||
#[tracing::instrument(skip(db, body))]
|
||||
pub fn get_event_route<'a>(
|
||||
db: State<'a, Database>,
|
||||
body: Ruma<get_event::v1::Request<'_>>,
|
||||
) -> ConduitResult<get_event::v1::Response> {
|
||||
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 = "<body>")
|
||||
|
|
Loading…
Reference in a new issue