Implement MSC4185

This commit is contained in:
Lambda 2024-08-30 22:11:29 +00:00
parent f03b6cde29
commit f965bf2b6a
5 changed files with 72 additions and 6 deletions

View file

@ -147,7 +147,10 @@ xdg = "2.5.2"
nix = { version = "0.29", features = ["resource"] }
[features]
default = ["rocksdb", "sqlite", "systemd"]
# needed for ruma Request/Response derives
client = []
server = []
default = ["rocksdb", "sqlite", "systemd", "server"]
# Keep sorted
jemalloc = ["dep:tikv-jemallocator"]

View file

@ -6,6 +6,7 @@ mod config;
mod context;
mod device;
mod directory;
mod event_visibility;
mod filter;
mod keys;
mod media;
@ -40,6 +41,7 @@ pub(crate) use config::*;
pub(crate) use context::*;
pub(crate) use device::*;
pub(crate) use directory::*;
pub(crate) use event_visibility::*;
pub(crate) use filter::*;
pub(crate) use keys::*;
pub(crate) use media::*;

View 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,
)?,
}))
}

View file

@ -29,10 +29,10 @@ pub(crate) async fn get_supported_versions_route(
"v1.4".to_owned(),
"v1.5".to_owned(),
],
unstable_features: BTreeMap::from_iter([(
"org.matrix.e2e_cross_signing".to_owned(),
true,
)]),
unstable_features: BTreeMap::from_iter([
("org.matrix.e2e_cross_signing".to_owned(), true),
("org.matrix.msc4185".to_owned(), true),
]),
};
Ok(Ra(resp))

View file

@ -414,7 +414,8 @@ fn routes(config: &Config) -> Router {
.ruma_route(c2s::get_relating_events_with_rel_type_and_event_type_route)
.ruma_route(c2s::get_relating_events_with_rel_type_route)
.ruma_route(c2s::get_relating_events_route)
.ruma_route(c2s::get_hierarchy_route);
.ruma_route(c2s::get_hierarchy_route)
.ruma_route(c2s::can_user_see_event_route);
// Ruma doesn't have support for multiple paths for a single endpoint yet,
// and these routes share one Ruma request / response type pair with