mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-19 08:41:24 +01:00
Implement MSC4185
This commit is contained in:
parent
f03b6cde29
commit
f965bf2b6a
5 changed files with 72 additions and 6 deletions
60
src/api/client_server/event_visibility.rs
Normal file
60
src/api/client_server/event_visibility.rs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
//! 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,
|
||||
)?,
|
||||
}))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue