feat: respect history visibility

This commit is contained in:
Timo Kösters 2023-02-22 15:49:55 +01:00
parent 2a16a5e967
commit 10fa686c77
No known key found for this signature in database
GPG key ID: 0B25E636FBA7E4CB
8 changed files with 166 additions and 98 deletions

View file

@ -425,24 +425,25 @@ pub async fn get_room_event_route(
) -> Result<get_room_event::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
if !services()
let event = services()
.rooms
.state_cache
.is_joined(sender_user, &body.room_id)?
{
.timeline
.get_pdu(&body.event_id)?
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Event not found."))?;
if !services().rooms.state_accessor.user_can_see_event(
sender_user,
&event.room_id,
&body.event_id,
)? {
return Err(Error::BadRequest(
ErrorKind::Forbidden,
"You don't have permission to view this room.",
"You don't have permission to view this event.",
));
}
Ok(get_room_event::v3::Response {
event: services()
.rooms
.timeline
.get_pdu(&body.event_id)?
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Event not found."))?
.to_room_event(),
event: event.to_room_event(),
})
}