Files
continuwuity/src/api/client/room/event.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
2.1 KiB
Rust
Raw Normal View History

2024-11-06 18:27:40 +00:00
use axum::extract::State;
2025-06-04 00:11:09 +01:00
use conduwuit::{Err, Event, Result, debug_warn, err};
2024-11-06 18:27:40 +00:00
use ruma::api::client::room::get_room_event;
use crate::{Ruma, client::is_ignored_pdu};
2024-11-06 18:27:40 +00:00
/// # `GET /_matrix/client/r0/rooms/{roomId}/event/{eventId}`
///
/// Gets a single event.
pub(crate) async fn get_room_event_route(
2025-02-06 10:23:17 +00:00
State(ref services): State<crate::State>,
ref body: Ruma<get_room_event::v3::Request>,
2024-11-06 18:27:40 +00:00
) -> Result<get_room_event::v3::Response> {
let sender_user = body.identity.expect_sender_user()?;
2025-02-06 10:23:17 +00:00
let event_id = &body.event_id;
let room_id = &body.room_id;
let mut event = match services.rooms.timeline.get_pdu(event_id).await {
| Ok(event) => event,
2026-09-22 00:11:38 +01:00
| Err(e) if e.is_not_found() => {
// Only fetch over federation for users who could see the event.
2026-09-22 00:11:38 +01:00
let (joined, world_readable) = tokio::join!(
services.rooms.state_cache.is_joined(sender_user, room_id),
services.rooms.state_accessor.is_world_readable(room_id)
);
if !joined && !world_readable {
return Err!(Request(NotFound("Event {} not found.", event_id)));
}
services
.rooms
.timeline
.get_remote_pdu(room_id, event_id)
.await
.map_err(|_| err!(Request(NotFound("Event {} not found.", event_id))))?
},
2026-09-22 00:11:38 +01:00
| Err(e) => return Err(e),
};
// NOTE: checked after fetching, as visibility of an unknown event cannot
// be determined (user_can_see_event returns true for those).
let visible = services
.rooms
.state_accessor
.user_can_see_event(sender_user, room_id, event_id)
.await;
if !visible || is_ignored_pdu(services, &event, sender_user).await? {
return Err!(Request(Forbidden("You don't have permission to view this event.")));
}
2025-06-04 00:11:09 +01:00
if let Err(e) = services
.rooms
.pdu_metadata
.add_bundled_aggregations_to_pdu(sender_user, &mut event)
2025-06-04 00:11:09 +01:00
.await
{
debug_warn!("Failed to add bundled aggregations to event: {e}");
}
let ctx = services
.rooms
.timeline
.get_unsigned_context(&event, Some(sender_user))
.await;
2026-09-21 03:15:46 +01:00
event.set_unsigned(ctx.user_id, ctx.membership, ctx.prev_content, ctx.redacted_because)?;
2026-04-10 12:52:42 -04:00
Ok(get_room_event::v3::Response::new(event.into_format()))
2024-11-06 18:27:40 +00:00
}