mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 16:21:24 +01:00
60 lines
1.5 KiB
Rust
60 lines
1.5 KiB
Rust
//! Implementation of [MSC4185](https://github.com/matrix-org/matrix-spec-proposals/pull/4185)
|
|
|
|
use ruma::{
|
|
api::{request, response, Metadata},
|
|
metadata, OwnedEventId, OwnedRoomId, OwnedUserId,
|
|
};
|
|
|
|
use crate::{services, Ar, Ra, Result};
|
|
|
|
const METADATA: Metadata = metadata! {
|
|
method: GET,
|
|
rate_limited: true,
|
|
authentication: AccessToken,
|
|
|
|
history: {
|
|
unstable => "/_matrix/client/unstable/net.tadzik/can_user_see_event/:room_id/:user_id/:event_id",
|
|
},
|
|
};
|
|
|
|
#[request]
|
|
#[allow(clippy::struct_field_names)]
|
|
pub(crate) struct Request {
|
|
#[ruma_api(path)]
|
|
pub(crate) room_id: OwnedRoomId,
|
|
|
|
#[ruma_api(path)]
|
|
pub(crate) user_id: OwnedUserId,
|
|
|
|
#[ruma_api(path)]
|
|
pub(crate) event_id: OwnedEventId,
|
|
}
|
|
|
|
#[response]
|
|
pub(crate) struct Response {
|
|
#[ruma_api(body)]
|
|
pub(crate) is_visible: bool,
|
|
}
|
|
|
|
pub(crate) async fn can_user_see_event_route(
|
|
body: Ar<Request>,
|
|
) -> Result<Ra<Response>> {
|
|
let Ok(true) = services().rooms.state_accessor.user_can_see_event(
|
|
body.sender_user.as_ref().expect("user is authenticated"),
|
|
&body.room_id,
|
|
&body.event_id,
|
|
) else {
|
|
return Err(crate::Error::BadRequest(
|
|
ruma::api::client::error::ErrorKind::Unauthorized,
|
|
"event is not visible to requesting user",
|
|
));
|
|
};
|
|
|
|
Ok(Ra(Response {
|
|
is_visible: services().rooms.state_accessor.user_can_see_event(
|
|
&body.user_id,
|
|
&body.room_id,
|
|
&body.event_id,
|
|
)?,
|
|
}))
|
|
}
|