de-global services() from api
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
463f1a1287
commit
8b6018d77d
61 changed files with 1485 additions and 1320 deletions
|
@ -1,3 +1,4 @@
|
|||
use axum::extract::State;
|
||||
use ruma::api::{
|
||||
client::error::ErrorKind,
|
||||
federation::{
|
||||
|
@ -9,13 +10,15 @@ use ruma::api::{
|
|||
use crate::{
|
||||
client::{claim_keys_helper, get_keys_helper},
|
||||
service::user_is_local,
|
||||
services, Error, Result, Ruma,
|
||||
Error, Result, Ruma,
|
||||
};
|
||||
|
||||
/// # `GET /_matrix/federation/v1/user/devices/{userId}`
|
||||
///
|
||||
/// Gets information on all devices of the user.
|
||||
pub(crate) async fn get_devices_route(body: Ruma<get_devices::v1::Request>) -> Result<get_devices::v1::Response> {
|
||||
pub(crate) async fn get_devices_route(
|
||||
State(services): State<crate::State>, body: Ruma<get_devices::v1::Request>,
|
||||
) -> Result<get_devices::v1::Response> {
|
||||
if !user_is_local(&body.user_id) {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::InvalidParam,
|
||||
|
@ -27,25 +30,25 @@ pub(crate) async fn get_devices_route(body: Ruma<get_devices::v1::Request>) -> R
|
|||
|
||||
Ok(get_devices::v1::Response {
|
||||
user_id: body.user_id.clone(),
|
||||
stream_id: services()
|
||||
stream_id: services
|
||||
.users
|
||||
.get_devicelist_version(&body.user_id)?
|
||||
.unwrap_or(0)
|
||||
.try_into()
|
||||
.expect("version will not grow that large"),
|
||||
devices: services()
|
||||
devices: services
|
||||
.users
|
||||
.all_devices_metadata(&body.user_id)
|
||||
.filter_map(Result::ok)
|
||||
.filter_map(|metadata| {
|
||||
let device_id_string = metadata.device_id.as_str().to_owned();
|
||||
let device_display_name = if services().globals.allow_device_name_federation() {
|
||||
let device_display_name = if services.globals.allow_device_name_federation() {
|
||||
metadata.display_name
|
||||
} else {
|
||||
Some(device_id_string)
|
||||
};
|
||||
Some(UserDevice {
|
||||
keys: services()
|
||||
keys: services
|
||||
.users
|
||||
.get_device_keys(&body.user_id, &metadata.device_id)
|
||||
.ok()??,
|
||||
|
@ -54,10 +57,10 @@ pub(crate) async fn get_devices_route(body: Ruma<get_devices::v1::Request>) -> R
|
|||
})
|
||||
})
|
||||
.collect(),
|
||||
master_key: services()
|
||||
master_key: services
|
||||
.users
|
||||
.get_master_key(None, &body.user_id, &|u| u.server_name() == origin)?,
|
||||
self_signing_key: services()
|
||||
self_signing_key: services
|
||||
.users
|
||||
.get_self_signing_key(None, &body.user_id, &|u| u.server_name() == origin)?,
|
||||
})
|
||||
|
@ -66,7 +69,9 @@ pub(crate) async fn get_devices_route(body: Ruma<get_devices::v1::Request>) -> R
|
|||
/// # `POST /_matrix/federation/v1/user/keys/query`
|
||||
///
|
||||
/// Gets devices and identity keys for the given users.
|
||||
pub(crate) async fn get_keys_route(body: Ruma<get_keys::v1::Request>) -> Result<get_keys::v1::Response> {
|
||||
pub(crate) async fn get_keys_route(
|
||||
State(services): State<crate::State>, body: Ruma<get_keys::v1::Request>,
|
||||
) -> Result<get_keys::v1::Response> {
|
||||
if body.device_keys.iter().any(|(u, _)| !user_is_local(u)) {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::InvalidParam,
|
||||
|
@ -75,10 +80,11 @@ pub(crate) async fn get_keys_route(body: Ruma<get_keys::v1::Request>) -> Result<
|
|||
}
|
||||
|
||||
let result = get_keys_helper(
|
||||
services,
|
||||
None,
|
||||
&body.device_keys,
|
||||
|u| Some(u.server_name()) == body.origin.as_deref(),
|
||||
services().globals.allow_device_name_federation(),
|
||||
services.globals.allow_device_name_federation(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
@ -92,7 +98,9 @@ pub(crate) async fn get_keys_route(body: Ruma<get_keys::v1::Request>) -> Result<
|
|||
/// # `POST /_matrix/federation/v1/user/keys/claim`
|
||||
///
|
||||
/// Claims one-time keys.
|
||||
pub(crate) async fn claim_keys_route(body: Ruma<claim_keys::v1::Request>) -> Result<claim_keys::v1::Response> {
|
||||
pub(crate) async fn claim_keys_route(
|
||||
State(services): State<crate::State>, body: Ruma<claim_keys::v1::Request>,
|
||||
) -> Result<claim_keys::v1::Response> {
|
||||
if body.one_time_keys.iter().any(|(u, _)| !user_is_local(u)) {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::InvalidParam,
|
||||
|
@ -100,7 +108,7 @@ pub(crate) async fn claim_keys_route(body: Ruma<claim_keys::v1::Request>) -> Res
|
|||
));
|
||||
}
|
||||
|
||||
let result = claim_keys_helper(&body.one_time_keys).await?;
|
||||
let result = claim_keys_helper(services, &body.one_time_keys).await?;
|
||||
|
||||
Ok(claim_keys::v1::Response {
|
||||
one_time_keys: result.one_time_keys,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue