1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-07-27 10:18:30 +00:00
continuwuity/src/api/server/event.rs
strawberry 0317cc8cc5
rename conduit to conduwuit finally
Signed-off-by: strawberry <strawberry@puppygock.gay>
2024-12-14 22:24:45 -05:00

48 lines
1.2 KiB
Rust

use axum::extract::State;
use conduwuit::{err, Result};
use ruma::{api::federation::event::get_event, MilliSecondsSinceUnixEpoch, RoomId};
use super::AccessCheck;
use crate::Ruma;
/// # `GET /_matrix/federation/v1/event/{eventId}`
///
/// Retrieves a single event from the server.
///
/// - Only works if a user of this server is currently invited or joined the
/// room
pub(crate) async fn get_event_route(
State(services): State<crate::State>, body: Ruma<get_event::v1::Request>,
) -> Result<get_event::v1::Response> {
let event = services
.rooms
.timeline
.get_pdu_json(&body.event_id)
.await
.map_err(|_| err!(Request(NotFound("Event not found."))))?;
let room_id: &RoomId = event
.get("room_id")
.and_then(|val| val.as_str())
.ok_or_else(|| err!(Database("Invalid event in database.")))?
.try_into()
.map_err(|_| err!(Database("Invalid room_id in event in database.")))?;
AccessCheck {
services: &services,
origin: body.origin(),
room_id,
event_id: Some(&body.event_id),
}
.check()
.await?;
Ok(get_event::v1::Response {
origin: services.globals.server_name().to_owned(),
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
pdu: services
.sending
.convert_to_outgoing_federation_event(event)
.await,
})
}