mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +01:00
don't automatically wrap in RumaResponse
This allows us to use the `ruma_route` convenience function even when we need to add our own hacks into the responses, thus making us less reliant on Ruma.
This commit is contained in:
parent
87ac0e2a38
commit
230ebd3884
35 changed files with 438 additions and 405 deletions
|
|
@ -19,7 +19,9 @@ use ruma::{
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
|
use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
|
||||||
use crate::{api::client_server, services, utils, Error, Result, Ruma};
|
use crate::{
|
||||||
|
api::client_server, services, utils, Error, Result, Ruma, RumaResponse,
|
||||||
|
};
|
||||||
|
|
||||||
const RANDOM_USER_ID_LENGTH: usize = 10;
|
const RANDOM_USER_ID_LENGTH: usize = 10;
|
||||||
|
|
||||||
|
|
@ -36,7 +38,7 @@ const RANDOM_USER_ID_LENGTH: usize = 10;
|
||||||
/// invalid when trying to register
|
/// invalid when trying to register
|
||||||
pub(crate) async fn get_register_available_route(
|
pub(crate) async fn get_register_available_route(
|
||||||
body: Ruma<get_username_availability::v3::Request>,
|
body: Ruma<get_username_availability::v3::Request>,
|
||||||
) -> Result<get_username_availability::v3::Response> {
|
) -> Result<RumaResponse<get_username_availability::v3::Response>> {
|
||||||
// Validate user id
|
// Validate user id
|
||||||
let user_id = UserId::parse_with_server_name(
|
let user_id = UserId::parse_with_server_name(
|
||||||
body.username.to_lowercase(),
|
body.username.to_lowercase(),
|
||||||
|
|
@ -63,9 +65,9 @@ pub(crate) async fn get_register_available_route(
|
||||||
// TODO add check for appservice namespaces
|
// TODO add check for appservice namespaces
|
||||||
|
|
||||||
// If no if check is true we have an username that's available to be used.
|
// If no if check is true we have an username that's available to be used.
|
||||||
Ok(get_username_availability::v3::Response {
|
Ok(RumaResponse(get_username_availability::v3::Response {
|
||||||
available: true,
|
available: true,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/register`
|
/// # `POST /_matrix/client/r0/register`
|
||||||
|
|
@ -88,7 +90,7 @@ pub(crate) async fn get_register_available_route(
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub(crate) async fn register_route(
|
pub(crate) async fn register_route(
|
||||||
body: Ruma<register::v3::Request>,
|
body: Ruma<register::v3::Request>,
|
||||||
) -> Result<register::v3::Response> {
|
) -> Result<RumaResponse<register::v3::Response>> {
|
||||||
if !services().globals.allow_registration()
|
if !services().globals.allow_registration()
|
||||||
&& body.appservice_info.is_none()
|
&& body.appservice_info.is_none()
|
||||||
{
|
{
|
||||||
|
|
@ -248,13 +250,13 @@ pub(crate) async fn register_route(
|
||||||
|
|
||||||
// Inhibit login does not work for guests
|
// Inhibit login does not work for guests
|
||||||
if !is_guest && body.inhibit_login {
|
if !is_guest && body.inhibit_login {
|
||||||
return Ok(register::v3::Response {
|
return Ok(RumaResponse(register::v3::Response {
|
||||||
access_token: None,
|
access_token: None,
|
||||||
user_id,
|
user_id,
|
||||||
device_id: None,
|
device_id: None,
|
||||||
refresh_token: None,
|
refresh_token: None,
|
||||||
expires_in: None,
|
expires_in: None,
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate new device id if the user didn't specify one
|
// Generate new device id if the user didn't specify one
|
||||||
|
|
@ -300,13 +302,13 @@ pub(crate) async fn register_route(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(register::v3::Response {
|
Ok(RumaResponse(register::v3::Response {
|
||||||
access_token: Some(token),
|
access_token: Some(token),
|
||||||
user_id,
|
user_id,
|
||||||
device_id: Some(device_id),
|
device_id: Some(device_id),
|
||||||
refresh_token: None,
|
refresh_token: None,
|
||||||
expires_in: None,
|
expires_in: None,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/account/password`
|
/// # `POST /_matrix/client/r0/account/password`
|
||||||
|
|
@ -328,7 +330,7 @@ pub(crate) async fn register_route(
|
||||||
/// - Triggers device list updates
|
/// - Triggers device list updates
|
||||||
pub(crate) async fn change_password_route(
|
pub(crate) async fn change_password_route(
|
||||||
body: Ruma<change_password::v3::Request>,
|
body: Ruma<change_password::v3::Request>,
|
||||||
) -> Result<change_password::v3::Response> {
|
) -> Result<RumaResponse<change_password::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let sender_device =
|
let sender_device =
|
||||||
body.sender_device.as_ref().expect("user is authenticated");
|
body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
@ -381,7 +383,7 @@ pub(crate) async fn change_password_route(
|
||||||
format!("User {sender_user} changed their password."),
|
format!("User {sender_user} changed their password."),
|
||||||
));
|
));
|
||||||
|
|
||||||
Ok(change_password::v3::Response {})
|
Ok(RumaResponse(change_password::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET _matrix/client/r0/account/whoami`
|
/// # `GET _matrix/client/r0/account/whoami`
|
||||||
|
|
@ -391,16 +393,16 @@ pub(crate) async fn change_password_route(
|
||||||
/// Note: Also works for Application Services
|
/// Note: Also works for Application Services
|
||||||
pub(crate) async fn whoami_route(
|
pub(crate) async fn whoami_route(
|
||||||
body: Ruma<whoami::v3::Request>,
|
body: Ruma<whoami::v3::Request>,
|
||||||
) -> Result<whoami::v3::Response> {
|
) -> Result<RumaResponse<whoami::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let device_id = body.sender_device.as_ref().cloned();
|
let device_id = body.sender_device.as_ref().cloned();
|
||||||
|
|
||||||
Ok(whoami::v3::Response {
|
Ok(RumaResponse(whoami::v3::Response {
|
||||||
user_id: sender_user.clone(),
|
user_id: sender_user.clone(),
|
||||||
device_id,
|
device_id,
|
||||||
is_guest: services().users.is_deactivated(sender_user)?
|
is_guest: services().users.is_deactivated(sender_user)?
|
||||||
&& body.appservice_info.is_none(),
|
&& body.appservice_info.is_none(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/account/deactivate`
|
/// # `POST /_matrix/client/r0/account/deactivate`
|
||||||
|
|
@ -416,7 +418,7 @@ pub(crate) async fn whoami_route(
|
||||||
/// - Removes ability to log in again
|
/// - Removes ability to log in again
|
||||||
pub(crate) async fn deactivate_route(
|
pub(crate) async fn deactivate_route(
|
||||||
body: Ruma<deactivate::v3::Request>,
|
body: Ruma<deactivate::v3::Request>,
|
||||||
) -> Result<deactivate::v3::Response> {
|
) -> Result<RumaResponse<deactivate::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let sender_device =
|
let sender_device =
|
||||||
body.sender_device.as_ref().expect("user is authenticated");
|
body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
@ -461,9 +463,9 @@ pub(crate) async fn deactivate_route(
|
||||||
format!("User {sender_user} deactivated their account."),
|
format!("User {sender_user} deactivated their account."),
|
||||||
));
|
));
|
||||||
|
|
||||||
Ok(deactivate::v3::Response {
|
Ok(RumaResponse(deactivate::v3::Response {
|
||||||
id_server_unbind_result: ThirdPartyIdRemovalStatus::NoSupport,
|
id_server_unbind_result: ThirdPartyIdRemovalStatus::NoSupport,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET _matrix/client/v3/account/3pid`
|
/// # `GET _matrix/client/v3/account/3pid`
|
||||||
|
|
@ -473,11 +475,11 @@ pub(crate) async fn deactivate_route(
|
||||||
/// - Currently always returns empty list
|
/// - Currently always returns empty list
|
||||||
pub(crate) async fn third_party_route(
|
pub(crate) async fn third_party_route(
|
||||||
body: Ruma<get_3pids::v3::Request>,
|
body: Ruma<get_3pids::v3::Request>,
|
||||||
) -> Result<get_3pids::v3::Response> {
|
) -> Result<RumaResponse<get_3pids::v3::Response>> {
|
||||||
let _sender_user =
|
let _sender_user =
|
||||||
body.sender_user.as_ref().expect("user is authenticated");
|
body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
Ok(get_3pids::v3::Response::new(Vec::new()))
|
Ok(RumaResponse(get_3pids::v3::Response::new(Vec::new())))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/v3/account/3pid/email/requestToken`
|
/// # `POST /_matrix/client/v3/account/3pid/email/requestToken`
|
||||||
|
|
@ -489,7 +491,8 @@ pub(crate) async fn third_party_route(
|
||||||
/// as a contact option.
|
/// as a contact option.
|
||||||
pub(crate) async fn request_3pid_management_token_via_email_route(
|
pub(crate) async fn request_3pid_management_token_via_email_route(
|
||||||
_body: Ruma<request_3pid_management_token_via_email::v3::Request>,
|
_body: Ruma<request_3pid_management_token_via_email::v3::Request>,
|
||||||
) -> Result<request_3pid_management_token_via_email::v3::Response> {
|
) -> Result<RumaResponse<request_3pid_management_token_via_email::v3::Response>>
|
||||||
|
{
|
||||||
Err(Error::BadRequest(
|
Err(Error::BadRequest(
|
||||||
ErrorKind::ThreepidDenied,
|
ErrorKind::ThreepidDenied,
|
||||||
"Third party identifier is not allowed",
|
"Third party identifier is not allowed",
|
||||||
|
|
@ -503,9 +506,12 @@ pub(crate) async fn request_3pid_management_token_via_email_route(
|
||||||
///
|
///
|
||||||
/// - 403 signals that The homeserver does not allow the third party identifier
|
/// - 403 signals that The homeserver does not allow the third party identifier
|
||||||
/// as a contact option.
|
/// as a contact option.
|
||||||
|
#[rustfmt::skip]
|
||||||
pub(crate) async fn request_3pid_management_token_via_msisdn_route(
|
pub(crate) async fn request_3pid_management_token_via_msisdn_route(
|
||||||
_body: Ruma<request_3pid_management_token_via_msisdn::v3::Request>,
|
_body: Ruma<request_3pid_management_token_via_msisdn::v3::Request>,
|
||||||
) -> Result<request_3pid_management_token_via_msisdn::v3::Response> {
|
)
|
||||||
|
-> Result<RumaResponse<request_3pid_management_token_via_msisdn::v3::Response>>
|
||||||
|
{
|
||||||
Err(Error::BadRequest(
|
Err(Error::BadRequest(
|
||||||
ErrorKind::ThreepidDenied,
|
ErrorKind::ThreepidDenied,
|
||||||
"Third party identifier is not allowed",
|
"Third party identifier is not allowed",
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,14 @@ use ruma::{
|
||||||
OwnedRoomAliasId,
|
OwnedRoomAliasId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{services, Error, Result, Ruma};
|
use crate::{services, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/directory/room/{roomAlias}`
|
/// # `PUT /_matrix/client/r0/directory/room/{roomAlias}`
|
||||||
///
|
///
|
||||||
/// Creates a new room alias on this server.
|
/// Creates a new room alias on this server.
|
||||||
pub(crate) async fn create_alias_route(
|
pub(crate) async fn create_alias_route(
|
||||||
body: Ruma<create_alias::v3::Request>,
|
body: Ruma<create_alias::v3::Request>,
|
||||||
) -> Result<create_alias::v3::Response> {
|
) -> Result<RumaResponse<create_alias::v3::Response>> {
|
||||||
if body.room_alias.server_name() != services().globals.server_name() {
|
if body.room_alias.server_name() != services().globals.server_name() {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::InvalidParam,
|
ErrorKind::InvalidParam,
|
||||||
|
|
@ -46,7 +46,7 @@ pub(crate) async fn create_alias_route(
|
||||||
|
|
||||||
services().rooms.alias.set_alias(&body.room_alias, &body.room_id)?;
|
services().rooms.alias.set_alias(&body.room_alias, &body.room_id)?;
|
||||||
|
|
||||||
Ok(create_alias::v3::Response::new())
|
Ok(RumaResponse(create_alias::v3::Response::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/directory/room/{roomAlias}`
|
/// # `DELETE /_matrix/client/r0/directory/room/{roomAlias}`
|
||||||
|
|
@ -57,7 +57,7 @@ pub(crate) async fn create_alias_route(
|
||||||
/// - TODO: Update canonical alias event
|
/// - TODO: Update canonical alias event
|
||||||
pub(crate) async fn delete_alias_route(
|
pub(crate) async fn delete_alias_route(
|
||||||
body: Ruma<delete_alias::v3::Request>,
|
body: Ruma<delete_alias::v3::Request>,
|
||||||
) -> Result<delete_alias::v3::Response> {
|
) -> Result<RumaResponse<delete_alias::v3::Response>> {
|
||||||
if body.room_alias.server_name() != services().globals.server_name() {
|
if body.room_alias.server_name() != services().globals.server_name() {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::InvalidParam,
|
ErrorKind::InvalidParam,
|
||||||
|
|
@ -83,7 +83,7 @@ pub(crate) async fn delete_alias_route(
|
||||||
|
|
||||||
// TODO: update alt_aliases?
|
// TODO: update alt_aliases?
|
||||||
|
|
||||||
Ok(delete_alias::v3::Response::new())
|
Ok(RumaResponse(delete_alias::v3::Response::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/directory/room/{roomAlias}`
|
/// # `GET /_matrix/client/r0/directory/room/{roomAlias}`
|
||||||
|
|
@ -93,8 +93,8 @@ pub(crate) async fn delete_alias_route(
|
||||||
/// - TODO: Suggest more servers to join via
|
/// - TODO: Suggest more servers to join via
|
||||||
pub(crate) async fn get_alias_route(
|
pub(crate) async fn get_alias_route(
|
||||||
body: Ruma<get_alias::v3::Request>,
|
body: Ruma<get_alias::v3::Request>,
|
||||||
) -> Result<get_alias::v3::Response> {
|
) -> Result<RumaResponse<get_alias::v3::Response>> {
|
||||||
get_alias_helper(body.body.room_alias).await
|
get_alias_helper(body.body.room_alias).await.map(RumaResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_alias_helper(
|
pub(crate) async fn get_alias_helper(
|
||||||
|
|
|
||||||
|
|
@ -9,21 +9,21 @@ use ruma::api::client::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{services, Error, Result, Ruma};
|
use crate::{services, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/room_keys/version`
|
/// # `POST /_matrix/client/r0/room_keys/version`
|
||||||
///
|
///
|
||||||
/// Creates a new backup.
|
/// Creates a new backup.
|
||||||
pub(crate) async fn create_backup_version_route(
|
pub(crate) async fn create_backup_version_route(
|
||||||
body: Ruma<create_backup_version::v3::Request>,
|
body: Ruma<create_backup_version::v3::Request>,
|
||||||
) -> Result<create_backup_version::v3::Response> {
|
) -> Result<RumaResponse<create_backup_version::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let version =
|
let version =
|
||||||
services().key_backups.create_backup(sender_user, &body.algorithm)?;
|
services().key_backups.create_backup(sender_user, &body.algorithm)?;
|
||||||
|
|
||||||
Ok(create_backup_version::v3::Response {
|
Ok(RumaResponse(create_backup_version::v3::Response {
|
||||||
version,
|
version,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/version/{version}`
|
/// # `PUT /_matrix/client/r0/room_keys/version/{version}`
|
||||||
|
|
@ -32,7 +32,7 @@ pub(crate) async fn create_backup_version_route(
|
||||||
/// modified.
|
/// modified.
|
||||||
pub(crate) async fn update_backup_version_route(
|
pub(crate) async fn update_backup_version_route(
|
||||||
body: Ruma<update_backup_version::v3::Request>,
|
body: Ruma<update_backup_version::v3::Request>,
|
||||||
) -> Result<update_backup_version::v3::Response> {
|
) -> Result<RumaResponse<update_backup_version::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
services().key_backups.update_backup(
|
services().key_backups.update_backup(
|
||||||
sender_user,
|
sender_user,
|
||||||
|
|
@ -40,7 +40,7 @@ pub(crate) async fn update_backup_version_route(
|
||||||
&body.algorithm,
|
&body.algorithm,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(update_backup_version::v3::Response {})
|
Ok(RumaResponse(update_backup_version::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/version`
|
/// # `GET /_matrix/client/r0/room_keys/version`
|
||||||
|
|
@ -48,7 +48,7 @@ pub(crate) async fn update_backup_version_route(
|
||||||
/// Get information about the latest backup version.
|
/// Get information about the latest backup version.
|
||||||
pub(crate) async fn get_latest_backup_info_route(
|
pub(crate) async fn get_latest_backup_info_route(
|
||||||
body: Ruma<get_latest_backup_info::v3::Request>,
|
body: Ruma<get_latest_backup_info::v3::Request>,
|
||||||
) -> Result<get_latest_backup_info::v3::Response> {
|
) -> Result<RumaResponse<get_latest_backup_info::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let (version, algorithm) = services()
|
let (version, algorithm) = services()
|
||||||
|
|
@ -59,7 +59,7 @@ pub(crate) async fn get_latest_backup_info_route(
|
||||||
"Key backup does not exist.",
|
"Key backup does not exist.",
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
Ok(get_latest_backup_info::v3::Response {
|
Ok(RumaResponse(get_latest_backup_info::v3::Response {
|
||||||
algorithm,
|
algorithm,
|
||||||
count: services()
|
count: services()
|
||||||
.key_backups
|
.key_backups
|
||||||
|
|
@ -68,7 +68,7 @@ pub(crate) async fn get_latest_backup_info_route(
|
||||||
.expect("count should fit in UInt"),
|
.expect("count should fit in UInt"),
|
||||||
etag: services().key_backups.get_etag(sender_user, &version)?,
|
etag: services().key_backups.get_etag(sender_user, &version)?,
|
||||||
version,
|
version,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/version`
|
/// # `GET /_matrix/client/r0/room_keys/version`
|
||||||
|
|
@ -76,7 +76,7 @@ pub(crate) async fn get_latest_backup_info_route(
|
||||||
/// Get information about an existing backup.
|
/// Get information about an existing backup.
|
||||||
pub(crate) async fn get_backup_info_route(
|
pub(crate) async fn get_backup_info_route(
|
||||||
body: Ruma<get_backup_info::v3::Request>,
|
body: Ruma<get_backup_info::v3::Request>,
|
||||||
) -> Result<get_backup_info::v3::Response> {
|
) -> Result<RumaResponse<get_backup_info::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let algorithm = services()
|
let algorithm = services()
|
||||||
.key_backups
|
.key_backups
|
||||||
|
|
@ -86,7 +86,7 @@ pub(crate) async fn get_backup_info_route(
|
||||||
"Key backup does not exist.",
|
"Key backup does not exist.",
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
Ok(get_backup_info::v3::Response {
|
Ok(RumaResponse(get_backup_info::v3::Response {
|
||||||
algorithm,
|
algorithm,
|
||||||
count: services()
|
count: services()
|
||||||
.key_backups
|
.key_backups
|
||||||
|
|
@ -95,7 +95,7 @@ pub(crate) async fn get_backup_info_route(
|
||||||
.expect("count should fit in UInt"),
|
.expect("count should fit in UInt"),
|
||||||
etag: services().key_backups.get_etag(sender_user, &body.version)?,
|
etag: services().key_backups.get_etag(sender_user, &body.version)?,
|
||||||
version: body.version.clone(),
|
version: body.version.clone(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/version/{version}`
|
/// # `DELETE /_matrix/client/r0/room_keys/version/{version}`
|
||||||
|
|
@ -106,12 +106,12 @@ pub(crate) async fn get_backup_info_route(
|
||||||
/// to the backup
|
/// to the backup
|
||||||
pub(crate) async fn delete_backup_version_route(
|
pub(crate) async fn delete_backup_version_route(
|
||||||
body: Ruma<delete_backup_version::v3::Request>,
|
body: Ruma<delete_backup_version::v3::Request>,
|
||||||
) -> Result<delete_backup_version::v3::Response> {
|
) -> Result<RumaResponse<delete_backup_version::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
services().key_backups.delete_backup(sender_user, &body.version)?;
|
services().key_backups.delete_backup(sender_user, &body.version)?;
|
||||||
|
|
||||||
Ok(delete_backup_version::v3::Response {})
|
Ok(RumaResponse(delete_backup_version::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/keys`
|
/// # `PUT /_matrix/client/r0/room_keys/keys`
|
||||||
|
|
@ -124,7 +124,7 @@ pub(crate) async fn delete_backup_version_route(
|
||||||
/// - Returns the new number of keys in this backup and the etag
|
/// - Returns the new number of keys in this backup and the etag
|
||||||
pub(crate) async fn add_backup_keys_route(
|
pub(crate) async fn add_backup_keys_route(
|
||||||
body: Ruma<add_backup_keys::v3::Request>,
|
body: Ruma<add_backup_keys::v3::Request>,
|
||||||
) -> Result<add_backup_keys::v3::Response> {
|
) -> Result<RumaResponse<add_backup_keys::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if Some(&body.version)
|
if Some(&body.version)
|
||||||
|
|
@ -152,14 +152,14 @@ pub(crate) async fn add_backup_keys_route(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(add_backup_keys::v3::Response {
|
Ok(RumaResponse(add_backup_keys::v3::Response {
|
||||||
count: services()
|
count: services()
|
||||||
.key_backups
|
.key_backups
|
||||||
.count_keys(sender_user, &body.version)?
|
.count_keys(sender_user, &body.version)?
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("count should fit in UInt"),
|
.expect("count should fit in UInt"),
|
||||||
etag: services().key_backups.get_etag(sender_user, &body.version)?,
|
etag: services().key_backups.get_etag(sender_user, &body.version)?,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}`
|
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}`
|
||||||
|
|
@ -172,7 +172,7 @@ pub(crate) async fn add_backup_keys_route(
|
||||||
/// - Returns the new number of keys in this backup and the etag
|
/// - Returns the new number of keys in this backup and the etag
|
||||||
pub(crate) async fn add_backup_keys_for_room_route(
|
pub(crate) async fn add_backup_keys_for_room_route(
|
||||||
body: Ruma<add_backup_keys_for_room::v3::Request>,
|
body: Ruma<add_backup_keys_for_room::v3::Request>,
|
||||||
) -> Result<add_backup_keys_for_room::v3::Response> {
|
) -> Result<RumaResponse<add_backup_keys_for_room::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if Some(&body.version)
|
if Some(&body.version)
|
||||||
|
|
@ -198,14 +198,14 @@ pub(crate) async fn add_backup_keys_for_room_route(
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(add_backup_keys_for_room::v3::Response {
|
Ok(RumaResponse(add_backup_keys_for_room::v3::Response {
|
||||||
count: services()
|
count: services()
|
||||||
.key_backups
|
.key_backups
|
||||||
.count_keys(sender_user, &body.version)?
|
.count_keys(sender_user, &body.version)?
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("count should fit in UInt"),
|
.expect("count should fit in UInt"),
|
||||||
etag: services().key_backups.get_etag(sender_user, &body.version)?,
|
etag: services().key_backups.get_etag(sender_user, &body.version)?,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
||||||
|
|
@ -218,7 +218,7 @@ pub(crate) async fn add_backup_keys_for_room_route(
|
||||||
/// - Returns the new number of keys in this backup and the etag
|
/// - Returns the new number of keys in this backup and the etag
|
||||||
pub(crate) async fn add_backup_keys_for_session_route(
|
pub(crate) async fn add_backup_keys_for_session_route(
|
||||||
body: Ruma<add_backup_keys_for_session::v3::Request>,
|
body: Ruma<add_backup_keys_for_session::v3::Request>,
|
||||||
) -> Result<add_backup_keys_for_session::v3::Response> {
|
) -> Result<RumaResponse<add_backup_keys_for_session::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if Some(&body.version)
|
if Some(&body.version)
|
||||||
|
|
@ -242,14 +242,14 @@ pub(crate) async fn add_backup_keys_for_session_route(
|
||||||
&body.session_data,
|
&body.session_data,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(add_backup_keys_for_session::v3::Response {
|
Ok(RumaResponse(add_backup_keys_for_session::v3::Response {
|
||||||
count: services()
|
count: services()
|
||||||
.key_backups
|
.key_backups
|
||||||
.count_keys(sender_user, &body.version)?
|
.count_keys(sender_user, &body.version)?
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("count should fit in UInt"),
|
.expect("count should fit in UInt"),
|
||||||
etag: services().key_backups.get_etag(sender_user, &body.version)?,
|
etag: services().key_backups.get_etag(sender_user, &body.version)?,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/keys`
|
/// # `GET /_matrix/client/r0/room_keys/keys`
|
||||||
|
|
@ -257,14 +257,14 @@ pub(crate) async fn add_backup_keys_for_session_route(
|
||||||
/// Retrieves all keys from the backup.
|
/// Retrieves all keys from the backup.
|
||||||
pub(crate) async fn get_backup_keys_route(
|
pub(crate) async fn get_backup_keys_route(
|
||||||
body: Ruma<get_backup_keys::v3::Request>,
|
body: Ruma<get_backup_keys::v3::Request>,
|
||||||
) -> Result<get_backup_keys::v3::Response> {
|
) -> Result<RumaResponse<get_backup_keys::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let rooms = services().key_backups.get_all(sender_user, &body.version)?;
|
let rooms = services().key_backups.get_all(sender_user, &body.version)?;
|
||||||
|
|
||||||
Ok(get_backup_keys::v3::Response {
|
Ok(RumaResponse(get_backup_keys::v3::Response {
|
||||||
rooms,
|
rooms,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}`
|
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}`
|
||||||
|
|
@ -272,7 +272,7 @@ pub(crate) async fn get_backup_keys_route(
|
||||||
/// Retrieves all keys from the backup for a given room.
|
/// Retrieves all keys from the backup for a given room.
|
||||||
pub(crate) async fn get_backup_keys_for_room_route(
|
pub(crate) async fn get_backup_keys_for_room_route(
|
||||||
body: Ruma<get_backup_keys_for_room::v3::Request>,
|
body: Ruma<get_backup_keys_for_room::v3::Request>,
|
||||||
) -> Result<get_backup_keys_for_room::v3::Response> {
|
) -> Result<RumaResponse<get_backup_keys_for_room::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let sessions = services().key_backups.get_room(
|
let sessions = services().key_backups.get_room(
|
||||||
|
|
@ -281,9 +281,9 @@ pub(crate) async fn get_backup_keys_for_room_route(
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(get_backup_keys_for_room::v3::Response {
|
Ok(RumaResponse(get_backup_keys_for_room::v3::Response {
|
||||||
sessions,
|
sessions,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
||||||
|
|
@ -291,7 +291,7 @@ pub(crate) async fn get_backup_keys_for_room_route(
|
||||||
/// Retrieves a key from the backup.
|
/// Retrieves a key from the backup.
|
||||||
pub(crate) async fn get_backup_keys_for_session_route(
|
pub(crate) async fn get_backup_keys_for_session_route(
|
||||||
body: Ruma<get_backup_keys_for_session::v3::Request>,
|
body: Ruma<get_backup_keys_for_session::v3::Request>,
|
||||||
) -> Result<get_backup_keys_for_session::v3::Response> {
|
) -> Result<RumaResponse<get_backup_keys_for_session::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let key_data = services()
|
let key_data = services()
|
||||||
|
|
@ -307,9 +307,9 @@ pub(crate) async fn get_backup_keys_for_session_route(
|
||||||
"Backup key not found for this user's session.",
|
"Backup key not found for this user's session.",
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
Ok(get_backup_keys_for_session::v3::Response {
|
Ok(RumaResponse(get_backup_keys_for_session::v3::Response {
|
||||||
key_data,
|
key_data,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/keys`
|
/// # `DELETE /_matrix/client/r0/room_keys/keys`
|
||||||
|
|
@ -317,19 +317,19 @@ pub(crate) async fn get_backup_keys_for_session_route(
|
||||||
/// Delete the keys from the backup.
|
/// Delete the keys from the backup.
|
||||||
pub(crate) async fn delete_backup_keys_route(
|
pub(crate) async fn delete_backup_keys_route(
|
||||||
body: Ruma<delete_backup_keys::v3::Request>,
|
body: Ruma<delete_backup_keys::v3::Request>,
|
||||||
) -> Result<delete_backup_keys::v3::Response> {
|
) -> Result<RumaResponse<delete_backup_keys::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
services().key_backups.delete_all_keys(sender_user, &body.version)?;
|
services().key_backups.delete_all_keys(sender_user, &body.version)?;
|
||||||
|
|
||||||
Ok(delete_backup_keys::v3::Response {
|
Ok(RumaResponse(delete_backup_keys::v3::Response {
|
||||||
count: services()
|
count: services()
|
||||||
.key_backups
|
.key_backups
|
||||||
.count_keys(sender_user, &body.version)?
|
.count_keys(sender_user, &body.version)?
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("count should fit in UInt"),
|
.expect("count should fit in UInt"),
|
||||||
etag: services().key_backups.get_etag(sender_user, &body.version)?,
|
etag: services().key_backups.get_etag(sender_user, &body.version)?,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}`
|
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}`
|
||||||
|
|
@ -337,7 +337,7 @@ pub(crate) async fn delete_backup_keys_route(
|
||||||
/// Delete the keys from the backup for a given room.
|
/// Delete the keys from the backup for a given room.
|
||||||
pub(crate) async fn delete_backup_keys_for_room_route(
|
pub(crate) async fn delete_backup_keys_for_room_route(
|
||||||
body: Ruma<delete_backup_keys_for_room::v3::Request>,
|
body: Ruma<delete_backup_keys_for_room::v3::Request>,
|
||||||
) -> Result<delete_backup_keys_for_room::v3::Response> {
|
) -> Result<RumaResponse<delete_backup_keys_for_room::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
services().key_backups.delete_room_keys(
|
services().key_backups.delete_room_keys(
|
||||||
|
|
@ -346,14 +346,14 @@ pub(crate) async fn delete_backup_keys_for_room_route(
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(delete_backup_keys_for_room::v3::Response {
|
Ok(RumaResponse(delete_backup_keys_for_room::v3::Response {
|
||||||
count: services()
|
count: services()
|
||||||
.key_backups
|
.key_backups
|
||||||
.count_keys(sender_user, &body.version)?
|
.count_keys(sender_user, &body.version)?
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("count should fit in UInt"),
|
.expect("count should fit in UInt"),
|
||||||
etag: services().key_backups.get_etag(sender_user, &body.version)?,
|
etag: services().key_backups.get_etag(sender_user, &body.version)?,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
||||||
|
|
@ -361,7 +361,7 @@ pub(crate) async fn delete_backup_keys_for_room_route(
|
||||||
/// Delete a key from the backup.
|
/// Delete a key from the backup.
|
||||||
pub(crate) async fn delete_backup_keys_for_session_route(
|
pub(crate) async fn delete_backup_keys_for_session_route(
|
||||||
body: Ruma<delete_backup_keys_for_session::v3::Request>,
|
body: Ruma<delete_backup_keys_for_session::v3::Request>,
|
||||||
) -> Result<delete_backup_keys_for_session::v3::Response> {
|
) -> Result<RumaResponse<delete_backup_keys_for_session::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
services().key_backups.delete_room_key(
|
services().key_backups.delete_room_key(
|
||||||
|
|
@ -371,12 +371,12 @@ pub(crate) async fn delete_backup_keys_for_session_route(
|
||||||
&body.session_id,
|
&body.session_id,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(delete_backup_keys_for_session::v3::Response {
|
Ok(RumaResponse(delete_backup_keys_for_session::v3::Response {
|
||||||
count: services()
|
count: services()
|
||||||
.key_backups
|
.key_backups
|
||||||
.count_keys(sender_user, &body.version)?
|
.count_keys(sender_user, &body.version)?
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("count should fit in UInt"),
|
.expect("count should fit in UInt"),
|
||||||
etag: services().key_backups.get_etag(sender_user, &body.version)?,
|
etag: services().key_backups.get_etag(sender_user, &body.version)?,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use ruma::api::client::discovery::get_capabilities::{
|
||||||
self, Capabilities, RoomVersionStability, RoomVersionsCapability,
|
self, Capabilities, RoomVersionStability, RoomVersionsCapability,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{services, Result, Ruma};
|
use crate::{services, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/capabilities`
|
/// # `GET /_matrix/client/r0/capabilities`
|
||||||
///
|
///
|
||||||
|
|
@ -12,7 +12,7 @@ use crate::{services, Result, Ruma};
|
||||||
/// of this server.
|
/// of this server.
|
||||||
pub(crate) async fn get_capabilities_route(
|
pub(crate) async fn get_capabilities_route(
|
||||||
_body: Ruma<get_capabilities::v3::Request>,
|
_body: Ruma<get_capabilities::v3::Request>,
|
||||||
) -> Result<get_capabilities::v3::Response> {
|
) -> Result<RumaResponse<get_capabilities::v3::Response>> {
|
||||||
let mut available = BTreeMap::new();
|
let mut available = BTreeMap::new();
|
||||||
for room_version in &services().globals.unstable_room_versions {
|
for room_version in &services().globals.unstable_room_versions {
|
||||||
available.insert(room_version.clone(), RoomVersionStability::Unstable);
|
available.insert(room_version.clone(), RoomVersionStability::Unstable);
|
||||||
|
|
@ -27,7 +27,7 @@ pub(crate) async fn get_capabilities_route(
|
||||||
available,
|
available,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_capabilities::v3::Response {
|
Ok(RumaResponse(get_capabilities::v3::Response {
|
||||||
capabilities,
|
capabilities,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,14 @@ use ruma::{
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::{json, value::RawValue as RawJsonValue};
|
use serde_json::{json, value::RawValue as RawJsonValue};
|
||||||
|
|
||||||
use crate::{services, Error, Result, Ruma};
|
use crate::{services, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/user/{userId}/account_data/{type}`
|
/// # `PUT /_matrix/client/r0/user/{userId}/account_data/{type}`
|
||||||
///
|
///
|
||||||
/// Sets some account data for the sender user.
|
/// Sets some account data for the sender user.
|
||||||
pub(crate) async fn set_global_account_data_route(
|
pub(crate) async fn set_global_account_data_route(
|
||||||
body: Ruma<set_global_account_data::v3::Request>,
|
body: Ruma<set_global_account_data::v3::Request>,
|
||||||
) -> Result<set_global_account_data::v3::Response> {
|
) -> Result<RumaResponse<set_global_account_data::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let data: serde_json::Value = serde_json::from_str(body.data.json().get())
|
let data: serde_json::Value = serde_json::from_str(body.data.json().get())
|
||||||
|
|
@ -41,7 +41,7 @@ pub(crate) async fn set_global_account_data_route(
|
||||||
}),
|
}),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(set_global_account_data::v3::Response {})
|
Ok(RumaResponse(set_global_account_data::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
||||||
|
|
@ -49,7 +49,7 @@ pub(crate) async fn set_global_account_data_route(
|
||||||
/// Sets some room account data for the sender user.
|
/// Sets some room account data for the sender user.
|
||||||
pub(crate) async fn set_room_account_data_route(
|
pub(crate) async fn set_room_account_data_route(
|
||||||
body: Ruma<set_room_account_data::v3::Request>,
|
body: Ruma<set_room_account_data::v3::Request>,
|
||||||
) -> Result<set_room_account_data::v3::Response> {
|
) -> Result<RumaResponse<set_room_account_data::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let data: serde_json::Value = serde_json::from_str(body.data.json().get())
|
let data: serde_json::Value = serde_json::from_str(body.data.json().get())
|
||||||
|
|
@ -69,7 +69,7 @@ pub(crate) async fn set_room_account_data_route(
|
||||||
}),
|
}),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(set_room_account_data::v3::Response {})
|
Ok(RumaResponse(set_room_account_data::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/user/{userId}/account_data/{type}`
|
/// # `GET /_matrix/client/r0/user/{userId}/account_data/{type}`
|
||||||
|
|
@ -77,7 +77,7 @@ pub(crate) async fn set_room_account_data_route(
|
||||||
/// Gets some account data for the sender user.
|
/// Gets some account data for the sender user.
|
||||||
pub(crate) async fn get_global_account_data_route(
|
pub(crate) async fn get_global_account_data_route(
|
||||||
body: Ruma<get_global_account_data::v3::Request>,
|
body: Ruma<get_global_account_data::v3::Request>,
|
||||||
) -> Result<get_global_account_data::v3::Response> {
|
) -> Result<RumaResponse<get_global_account_data::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let event: Box<RawJsonValue> = services()
|
let event: Box<RawJsonValue> = services()
|
||||||
|
|
@ -92,9 +92,9 @@ pub(crate) async fn get_global_account_data_route(
|
||||||
})?
|
})?
|
||||||
.content;
|
.content;
|
||||||
|
|
||||||
Ok(get_global_account_data::v3::Response {
|
Ok(RumaResponse(get_global_account_data::v3::Response {
|
||||||
account_data,
|
account_data,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
/// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
||||||
|
|
@ -102,7 +102,7 @@ pub(crate) async fn get_global_account_data_route(
|
||||||
/// Gets some room account data for the sender user.
|
/// Gets some room account data for the sender user.
|
||||||
pub(crate) async fn get_room_account_data_route(
|
pub(crate) async fn get_room_account_data_route(
|
||||||
body: Ruma<get_room_account_data::v3::Request>,
|
body: Ruma<get_room_account_data::v3::Request>,
|
||||||
) -> Result<get_room_account_data::v3::Response> {
|
) -> Result<RumaResponse<get_room_account_data::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let event: Box<RawJsonValue> = services()
|
let event: Box<RawJsonValue> = services()
|
||||||
|
|
@ -117,9 +117,9 @@ pub(crate) async fn get_room_account_data_route(
|
||||||
})?
|
})?
|
||||||
.content;
|
.content;
|
||||||
|
|
||||||
Ok(get_room_account_data::v3::Response {
|
Ok(RumaResponse(get_room_account_data::v3::Response {
|
||||||
account_data,
|
account_data,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use ruma::{
|
||||||
};
|
};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
use crate::{services, Error, Result, Ruma};
|
use crate::{services, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomId}/context`
|
/// # `GET /_matrix/client/r0/rooms/{roomId}/context`
|
||||||
///
|
///
|
||||||
|
|
@ -21,7 +21,7 @@ use crate::{services, Error, Result, Ruma};
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub(crate) async fn get_context_route(
|
pub(crate) async fn get_context_route(
|
||||||
body: Ruma<get_context::v3::Request>,
|
body: Ruma<get_context::v3::Request>,
|
||||||
) -> Result<get_context::v3::Response> {
|
) -> Result<RumaResponse<get_context::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let sender_device =
|
let sender_device =
|
||||||
body.sender_device.as_ref().expect("user is authenticated");
|
body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
@ -187,5 +187,5 @@ pub(crate) async fn get_context_route(
|
||||||
state,
|
state,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(resp)
|
Ok(RumaResponse(resp))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,14 @@ use ruma::api::client::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::SESSION_ID_LENGTH;
|
use super::SESSION_ID_LENGTH;
|
||||||
use crate::{services, utils, Error, Result, Ruma};
|
use crate::{services, utils, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/devices`
|
/// # `GET /_matrix/client/r0/devices`
|
||||||
///
|
///
|
||||||
/// Get metadata on all devices of the sender user.
|
/// Get metadata on all devices of the sender user.
|
||||||
pub(crate) async fn get_devices_route(
|
pub(crate) async fn get_devices_route(
|
||||||
body: Ruma<get_devices::v3::Request>,
|
body: Ruma<get_devices::v3::Request>,
|
||||||
) -> Result<get_devices::v3::Response> {
|
) -> Result<RumaResponse<get_devices::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let devices: Vec<device::Device> = services()
|
let devices: Vec<device::Device> = services()
|
||||||
|
|
@ -24,9 +24,9 @@ pub(crate) async fn get_devices_route(
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(get_devices::v3::Response {
|
Ok(RumaResponse(get_devices::v3::Response {
|
||||||
devices,
|
devices,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/devices/{deviceId}`
|
/// # `GET /_matrix/client/r0/devices/{deviceId}`
|
||||||
|
|
@ -34,7 +34,7 @@ pub(crate) async fn get_devices_route(
|
||||||
/// Get metadata on a single device of the sender user.
|
/// Get metadata on a single device of the sender user.
|
||||||
pub(crate) async fn get_device_route(
|
pub(crate) async fn get_device_route(
|
||||||
body: Ruma<get_device::v3::Request>,
|
body: Ruma<get_device::v3::Request>,
|
||||||
) -> Result<get_device::v3::Response> {
|
) -> Result<RumaResponse<get_device::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let device = services()
|
let device = services()
|
||||||
|
|
@ -42,9 +42,9 @@ pub(crate) async fn get_device_route(
|
||||||
.get_device_metadata(sender_user, &body.body.device_id)?
|
.get_device_metadata(sender_user, &body.body.device_id)?
|
||||||
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Device not found."))?;
|
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Device not found."))?;
|
||||||
|
|
||||||
Ok(get_device::v3::Response {
|
Ok(RumaResponse(get_device::v3::Response {
|
||||||
device,
|
device,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/devices/{deviceId}`
|
/// # `PUT /_matrix/client/r0/devices/{deviceId}`
|
||||||
|
|
@ -52,7 +52,7 @@ pub(crate) async fn get_device_route(
|
||||||
/// Updates the metadata on a given device of the sender user.
|
/// Updates the metadata on a given device of the sender user.
|
||||||
pub(crate) async fn update_device_route(
|
pub(crate) async fn update_device_route(
|
||||||
body: Ruma<update_device::v3::Request>,
|
body: Ruma<update_device::v3::Request>,
|
||||||
) -> Result<update_device::v3::Response> {
|
) -> Result<RumaResponse<update_device::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let mut device = services()
|
let mut device = services()
|
||||||
|
|
@ -68,7 +68,7 @@ pub(crate) async fn update_device_route(
|
||||||
&device,
|
&device,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(update_device::v3::Response {})
|
Ok(RumaResponse(update_device::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/devices/{deviceId}`
|
/// # `DELETE /_matrix/client/r0/devices/{deviceId}`
|
||||||
|
|
@ -83,7 +83,7 @@ pub(crate) async fn update_device_route(
|
||||||
/// - Triggers device list updates
|
/// - Triggers device list updates
|
||||||
pub(crate) async fn delete_device_route(
|
pub(crate) async fn delete_device_route(
|
||||||
body: Ruma<delete_device::v3::Request>,
|
body: Ruma<delete_device::v3::Request>,
|
||||||
) -> Result<delete_device::v3::Response> {
|
) -> Result<RumaResponse<delete_device::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let sender_device =
|
let sender_device =
|
||||||
body.sender_device.as_ref().expect("user is authenticated");
|
body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
@ -120,7 +120,7 @@ pub(crate) async fn delete_device_route(
|
||||||
|
|
||||||
services().users.remove_device(sender_user, &body.device_id)?;
|
services().users.remove_device(sender_user, &body.device_id)?;
|
||||||
|
|
||||||
Ok(delete_device::v3::Response {})
|
Ok(RumaResponse(delete_device::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/devices/{deviceId}`
|
/// # `PUT /_matrix/client/r0/devices/{deviceId}`
|
||||||
|
|
@ -137,7 +137,7 @@ pub(crate) async fn delete_device_route(
|
||||||
/// - Triggers device list updates
|
/// - Triggers device list updates
|
||||||
pub(crate) async fn delete_devices_route(
|
pub(crate) async fn delete_devices_route(
|
||||||
body: Ruma<delete_devices::v3::Request>,
|
body: Ruma<delete_devices::v3::Request>,
|
||||||
) -> Result<delete_devices::v3::Response> {
|
) -> Result<RumaResponse<delete_devices::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let sender_device =
|
let sender_device =
|
||||||
body.sender_device.as_ref().expect("user is authenticated");
|
body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
@ -176,5 +176,5 @@ pub(crate) async fn delete_devices_route(
|
||||||
services().users.remove_device(sender_user, device_id)?;
|
services().users.remove_device(sender_user, device_id)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(delete_devices::v3::Response {})
|
Ok(RumaResponse(delete_devices::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ use ruma::{
|
||||||
};
|
};
|
||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
|
|
||||||
use crate::{services, Error, Result, Ruma};
|
use crate::{services, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/publicRooms`
|
/// # `POST /_matrix/client/r0/publicRooms`
|
||||||
///
|
///
|
||||||
|
|
@ -38,7 +38,7 @@ use crate::{services, Error, Result, Ruma};
|
||||||
/// - Rooms are ordered by the number of joined members
|
/// - Rooms are ordered by the number of joined members
|
||||||
pub(crate) async fn get_public_rooms_filtered_route(
|
pub(crate) async fn get_public_rooms_filtered_route(
|
||||||
body: Ruma<get_public_rooms_filtered::v3::Request>,
|
body: Ruma<get_public_rooms_filtered::v3::Request>,
|
||||||
) -> Result<get_public_rooms_filtered::v3::Response> {
|
) -> Result<RumaResponse<get_public_rooms_filtered::v3::Response>> {
|
||||||
get_public_rooms_filtered_helper(
|
get_public_rooms_filtered_helper(
|
||||||
body.server.as_deref(),
|
body.server.as_deref(),
|
||||||
body.limit,
|
body.limit,
|
||||||
|
|
@ -47,6 +47,7 @@ pub(crate) async fn get_public_rooms_filtered_route(
|
||||||
&body.room_network,
|
&body.room_network,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
.map(RumaResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/publicRooms`
|
/// # `GET /_matrix/client/r0/publicRooms`
|
||||||
|
|
@ -56,7 +57,7 @@ pub(crate) async fn get_public_rooms_filtered_route(
|
||||||
/// - Rooms are ordered by the number of joined members
|
/// - Rooms are ordered by the number of joined members
|
||||||
pub(crate) async fn get_public_rooms_route(
|
pub(crate) async fn get_public_rooms_route(
|
||||||
body: Ruma<get_public_rooms::v3::Request>,
|
body: Ruma<get_public_rooms::v3::Request>,
|
||||||
) -> Result<get_public_rooms::v3::Response> {
|
) -> Result<RumaResponse<get_public_rooms::v3::Response>> {
|
||||||
let response = get_public_rooms_filtered_helper(
|
let response = get_public_rooms_filtered_helper(
|
||||||
body.server.as_deref(),
|
body.server.as_deref(),
|
||||||
body.limit,
|
body.limit,
|
||||||
|
|
@ -66,12 +67,12 @@ pub(crate) async fn get_public_rooms_route(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(get_public_rooms::v3::Response {
|
Ok(RumaResponse(get_public_rooms::v3::Response {
|
||||||
chunk: response.chunk,
|
chunk: response.chunk,
|
||||||
prev_batch: response.prev_batch,
|
prev_batch: response.prev_batch,
|
||||||
next_batch: response.next_batch,
|
next_batch: response.next_batch,
|
||||||
total_room_count_estimate: response.total_room_count_estimate,
|
total_room_count_estimate: response.total_room_count_estimate,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/directory/list/room/{roomId}`
|
/// # `PUT /_matrix/client/r0/directory/list/room/{roomId}`
|
||||||
|
|
@ -81,7 +82,7 @@ pub(crate) async fn get_public_rooms_route(
|
||||||
/// - TODO: Access control checks
|
/// - TODO: Access control checks
|
||||||
pub(crate) async fn set_room_visibility_route(
|
pub(crate) async fn set_room_visibility_route(
|
||||||
body: Ruma<set_room_visibility::v3::Request>,
|
body: Ruma<set_room_visibility::v3::Request>,
|
||||||
) -> Result<set_room_visibility::v3::Response> {
|
) -> Result<RumaResponse<set_room_visibility::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if !services().rooms.metadata.exists(&body.room_id)? {
|
if !services().rooms.metadata.exists(&body.room_id)? {
|
||||||
|
|
@ -105,7 +106,7 @@ pub(crate) async fn set_room_visibility_route(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(set_room_visibility::v3::Response {})
|
Ok(RumaResponse(set_room_visibility::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/directory/list/room/{roomId}`
|
/// # `GET /_matrix/client/r0/directory/list/room/{roomId}`
|
||||||
|
|
@ -113,13 +114,13 @@ pub(crate) async fn set_room_visibility_route(
|
||||||
/// Gets the visibility of a given room in the room directory.
|
/// Gets the visibility of a given room in the room directory.
|
||||||
pub(crate) async fn get_room_visibility_route(
|
pub(crate) async fn get_room_visibility_route(
|
||||||
body: Ruma<get_room_visibility::v3::Request>,
|
body: Ruma<get_room_visibility::v3::Request>,
|
||||||
) -> Result<get_room_visibility::v3::Response> {
|
) -> Result<RumaResponse<get_room_visibility::v3::Response>> {
|
||||||
if !services().rooms.metadata.exists(&body.room_id)? {
|
if !services().rooms.metadata.exists(&body.room_id)? {
|
||||||
// Return 404 if the room doesn't exist
|
// Return 404 if the room doesn't exist
|
||||||
return Err(Error::BadRequest(ErrorKind::NotFound, "Room not found"));
|
return Err(Error::BadRequest(ErrorKind::NotFound, "Room not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_room_visibility::v3::Response {
|
Ok(RumaResponse(get_room_visibility::v3::Response {
|
||||||
visibility: if services()
|
visibility: if services()
|
||||||
.rooms
|
.rooms
|
||||||
.directory
|
.directory
|
||||||
|
|
@ -129,7 +130,7 @@ pub(crate) async fn get_room_visibility_route(
|
||||||
} else {
|
} else {
|
||||||
room::Visibility::Private
|
room::Visibility::Private
|
||||||
},
|
},
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use ruma::api::client::{
|
||||||
filter::{create_filter, get_filter},
|
filter::{create_filter, get_filter},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{services, Error, Result, Ruma};
|
use crate::{services, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/user/{userId}/filter/{filterId}`
|
/// # `GET /_matrix/client/r0/user/{userId}/filter/{filterId}`
|
||||||
///
|
///
|
||||||
|
|
@ -12,7 +12,7 @@ use crate::{services, Error, Result, Ruma};
|
||||||
/// - A user can only access their own filters
|
/// - A user can only access their own filters
|
||||||
pub(crate) async fn get_filter_route(
|
pub(crate) async fn get_filter_route(
|
||||||
body: Ruma<get_filter::v3::Request>,
|
body: Ruma<get_filter::v3::Request>,
|
||||||
) -> Result<get_filter::v3::Response> {
|
) -> Result<RumaResponse<get_filter::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let Some(filter) =
|
let Some(filter) =
|
||||||
services().users.get_filter(sender_user, &body.filter_id)?
|
services().users.get_filter(sender_user, &body.filter_id)?
|
||||||
|
|
@ -23,7 +23,7 @@ pub(crate) async fn get_filter_route(
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_filter::v3::Response::new(filter))
|
Ok(RumaResponse(get_filter::v3::Response::new(filter)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/user/{userId}/filter`
|
/// # `PUT /_matrix/client/r0/user/{userId}/filter`
|
||||||
|
|
@ -31,9 +31,9 @@ pub(crate) async fn get_filter_route(
|
||||||
/// Creates a new filter to be used by other endpoints.
|
/// Creates a new filter to be used by other endpoints.
|
||||||
pub(crate) async fn create_filter_route(
|
pub(crate) async fn create_filter_route(
|
||||||
body: Ruma<create_filter::v3::Request>,
|
body: Ruma<create_filter::v3::Request>,
|
||||||
) -> Result<create_filter::v3::Response> {
|
) -> Result<RumaResponse<create_filter::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
Ok(create_filter::v3::Response::new(
|
Ok(RumaResponse(create_filter::v3::Response::new(
|
||||||
services().users.create_filter(sender_user, &body.filter)?,
|
services().users.create_filter(sender_user, &body.filter)?,
|
||||||
))
|
)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ use serde_json::json;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use super::SESSION_ID_LENGTH;
|
use super::SESSION_ID_LENGTH;
|
||||||
use crate::{services, utils, Error, Result, Ruma};
|
use crate::{services, utils, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/upload`
|
/// # `POST /_matrix/client/r0/keys/upload`
|
||||||
///
|
///
|
||||||
|
|
@ -34,7 +34,7 @@ use crate::{services, utils, Error, Result, Ruma};
|
||||||
/// existing keys?)
|
/// existing keys?)
|
||||||
pub(crate) async fn upload_keys_route(
|
pub(crate) async fn upload_keys_route(
|
||||||
body: Ruma<upload_keys::v3::Request>,
|
body: Ruma<upload_keys::v3::Request>,
|
||||||
) -> Result<upload_keys::v3::Response> {
|
) -> Result<RumaResponse<upload_keys::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let sender_device =
|
let sender_device =
|
||||||
body.sender_device.as_ref().expect("user is authenticated");
|
body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
@ -64,11 +64,11 @@ pub(crate) async fn upload_keys_route(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(upload_keys::v3::Response {
|
Ok(RumaResponse(upload_keys::v3::Response {
|
||||||
one_time_key_counts: services()
|
one_time_key_counts: services()
|
||||||
.users
|
.users
|
||||||
.count_one_time_keys(sender_user, sender_device)?,
|
.count_one_time_keys(sender_user, sender_device)?,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/query`
|
/// # `POST /_matrix/client/r0/keys/query`
|
||||||
|
|
@ -81,7 +81,7 @@ pub(crate) async fn upload_keys_route(
|
||||||
/// allowed to see
|
/// allowed to see
|
||||||
pub(crate) async fn get_keys_route(
|
pub(crate) async fn get_keys_route(
|
||||||
body: Ruma<get_keys::v3::Request>,
|
body: Ruma<get_keys::v3::Request>,
|
||||||
) -> Result<get_keys::v3::Response> {
|
) -> Result<RumaResponse<get_keys::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let response = get_keys_helper(Some(sender_user), &body.device_keys, |u| {
|
let response = get_keys_helper(Some(sender_user), &body.device_keys, |u| {
|
||||||
|
|
@ -89,7 +89,7 @@ pub(crate) async fn get_keys_route(
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(response)
|
Ok(RumaResponse(response))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/claim`
|
/// # `POST /_matrix/client/r0/keys/claim`
|
||||||
|
|
@ -97,10 +97,10 @@ pub(crate) async fn get_keys_route(
|
||||||
/// Claims one-time keys
|
/// Claims one-time keys
|
||||||
pub(crate) async fn claim_keys_route(
|
pub(crate) async fn claim_keys_route(
|
||||||
body: Ruma<claim_keys::v3::Request>,
|
body: Ruma<claim_keys::v3::Request>,
|
||||||
) -> Result<claim_keys::v3::Response> {
|
) -> Result<RumaResponse<claim_keys::v3::Response>> {
|
||||||
let response = claim_keys_helper(&body.one_time_keys).await?;
|
let response = claim_keys_helper(&body.one_time_keys).await?;
|
||||||
|
|
||||||
Ok(response)
|
Ok(RumaResponse(response))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/device_signing/upload`
|
/// # `POST /_matrix/client/r0/keys/device_signing/upload`
|
||||||
|
|
@ -110,7 +110,7 @@ pub(crate) async fn claim_keys_route(
|
||||||
/// - Requires UIAA to verify password
|
/// - Requires UIAA to verify password
|
||||||
pub(crate) async fn upload_signing_keys_route(
|
pub(crate) async fn upload_signing_keys_route(
|
||||||
body: Ruma<upload_signing_keys::v3::Request>,
|
body: Ruma<upload_signing_keys::v3::Request>,
|
||||||
) -> Result<upload_signing_keys::v3::Response> {
|
) -> Result<RumaResponse<upload_signing_keys::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let sender_device =
|
let sender_device =
|
||||||
body.sender_device.as_ref().expect("user is authenticated");
|
body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
@ -156,7 +156,7 @@ pub(crate) async fn upload_signing_keys_route(
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(upload_signing_keys::v3::Response {})
|
Ok(RumaResponse(upload_signing_keys::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/signatures/upload`
|
/// # `POST /_matrix/client/r0/keys/signatures/upload`
|
||||||
|
|
@ -164,7 +164,7 @@ pub(crate) async fn upload_signing_keys_route(
|
||||||
/// Uploads end-to-end key signatures from the sender user.
|
/// Uploads end-to-end key signatures from the sender user.
|
||||||
pub(crate) async fn upload_signatures_route(
|
pub(crate) async fn upload_signatures_route(
|
||||||
body: Ruma<upload_signatures::v3::Request>,
|
body: Ruma<upload_signatures::v3::Request>,
|
||||||
) -> Result<upload_signatures::v3::Response> {
|
) -> Result<RumaResponse<upload_signatures::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
for (user_id, keys) in &body.signed_keys {
|
for (user_id, keys) in &body.signed_keys {
|
||||||
|
|
@ -213,10 +213,10 @@ pub(crate) async fn upload_signatures_route(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(upload_signatures::v3::Response {
|
Ok(RumaResponse(upload_signatures::v3::Response {
|
||||||
// TODO: integrate
|
// TODO: integrate
|
||||||
failures: BTreeMap::new(),
|
failures: BTreeMap::new(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/changes`
|
/// # `POST /_matrix/client/r0/keys/changes`
|
||||||
|
|
@ -227,7 +227,7 @@ pub(crate) async fn upload_signatures_route(
|
||||||
/// - TODO: left users
|
/// - TODO: left users
|
||||||
pub(crate) async fn get_key_changes_route(
|
pub(crate) async fn get_key_changes_route(
|
||||||
body: Ruma<get_key_changes::v3::Request>,
|
body: Ruma<get_key_changes::v3::Request>,
|
||||||
) -> Result<get_key_changes::v3::Response> {
|
) -> Result<RumaResponse<get_key_changes::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let mut device_list_updates = HashSet::new();
|
let mut device_list_updates = HashSet::new();
|
||||||
|
|
@ -277,11 +277,11 @@ pub(crate) async fn get_key_changes_route(
|
||||||
.filter_map(Result::ok),
|
.filter_map(Result::ok),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Ok(get_key_changes::v3::Response {
|
Ok(RumaResponse(get_key_changes::v3::Response {
|
||||||
changed: device_list_updates.into_iter().collect(),
|
changed: device_list_updates.into_iter().collect(),
|
||||||
// TODO
|
// TODO
|
||||||
left: Vec::new(),
|
left: Vec::new(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,10 @@ use ruma::api::client::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{service::media::FileMeta, services, utils, Error, Result, Ruma};
|
use crate::{
|
||||||
|
service::media::FileMeta, services, utils, Error, Result, Ruma,
|
||||||
|
RumaResponse,
|
||||||
|
};
|
||||||
|
|
||||||
const MXC_LENGTH: usize = 32;
|
const MXC_LENGTH: usize = 32;
|
||||||
|
|
||||||
|
|
@ -17,10 +20,10 @@ const MXC_LENGTH: usize = 32;
|
||||||
/// Returns max upload size.
|
/// Returns max upload size.
|
||||||
pub(crate) async fn get_media_config_route(
|
pub(crate) async fn get_media_config_route(
|
||||||
_body: Ruma<get_media_config::v3::Request>,
|
_body: Ruma<get_media_config::v3::Request>,
|
||||||
) -> Result<get_media_config::v3::Response> {
|
) -> Result<RumaResponse<get_media_config::v3::Response>> {
|
||||||
Ok(get_media_config::v3::Response {
|
Ok(RumaResponse(get_media_config::v3::Response {
|
||||||
upload_size: services().globals.max_request_size().into(),
|
upload_size: services().globals.max_request_size().into(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/media/r0/upload`
|
/// # `POST /_matrix/media/r0/upload`
|
||||||
|
|
@ -31,7 +34,7 @@ pub(crate) async fn get_media_config_route(
|
||||||
/// - Media will be saved in the media/ directory
|
/// - Media will be saved in the media/ directory
|
||||||
pub(crate) async fn create_content_route(
|
pub(crate) async fn create_content_route(
|
||||||
body: Ruma<create_content::v3::Request>,
|
body: Ruma<create_content::v3::Request>,
|
||||||
) -> Result<create_content::v3::Response> {
|
) -> Result<RumaResponse<create_content::v3::Response>> {
|
||||||
let mxc = format!(
|
let mxc = format!(
|
||||||
"mxc://{}/{}",
|
"mxc://{}/{}",
|
||||||
services().globals.server_name(),
|
services().globals.server_name(),
|
||||||
|
|
@ -51,10 +54,10 @@ pub(crate) async fn create_content_route(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(create_content::v3::Response {
|
Ok(RumaResponse(create_content::v3::Response {
|
||||||
content_uri: mxc.into(),
|
content_uri: mxc.into(),
|
||||||
blurhash: None,
|
blurhash: None,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_remote_content(
|
pub(crate) async fn get_remote_content(
|
||||||
|
|
@ -96,7 +99,7 @@ pub(crate) async fn get_remote_content(
|
||||||
/// - Only allows federation if `allow_remote` is true
|
/// - Only allows federation if `allow_remote` is true
|
||||||
pub(crate) async fn get_content_route(
|
pub(crate) async fn get_content_route(
|
||||||
body: Ruma<get_content::v3::Request>,
|
body: Ruma<get_content::v3::Request>,
|
||||||
) -> Result<get_content::v3::Response> {
|
) -> Result<RumaResponse<get_content::v3::Response>> {
|
||||||
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
|
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
|
||||||
|
|
||||||
if let Some(FileMeta {
|
if let Some(FileMeta {
|
||||||
|
|
@ -105,19 +108,19 @@ pub(crate) async fn get_content_route(
|
||||||
file,
|
file,
|
||||||
}) = services().media.get(mxc.clone()).await?
|
}) = services().media.get(mxc.clone()).await?
|
||||||
{
|
{
|
||||||
Ok(get_content::v3::Response {
|
Ok(RumaResponse(get_content::v3::Response {
|
||||||
file,
|
file,
|
||||||
content_type,
|
content_type,
|
||||||
content_disposition,
|
content_disposition,
|
||||||
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
||||||
})
|
}))
|
||||||
} else if &*body.server_name != services().globals.server_name()
|
} else if &*body.server_name != services().globals.server_name()
|
||||||
&& body.allow_remote
|
&& body.allow_remote
|
||||||
{
|
{
|
||||||
let remote_content_response =
|
let remote_content_response =
|
||||||
get_remote_content(&mxc, &body.server_name, body.media_id.clone())
|
get_remote_content(&mxc, &body.server_name, body.media_id.clone())
|
||||||
.await?;
|
.await?;
|
||||||
Ok(remote_content_response)
|
Ok(RumaResponse(remote_content_response))
|
||||||
} else {
|
} else {
|
||||||
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
|
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
|
||||||
}
|
}
|
||||||
|
|
@ -130,7 +133,7 @@ pub(crate) async fn get_content_route(
|
||||||
/// - Only allows federation if `allow_remote` is true
|
/// - Only allows federation if `allow_remote` is true
|
||||||
pub(crate) async fn get_content_as_filename_route(
|
pub(crate) async fn get_content_as_filename_route(
|
||||||
body: Ruma<get_content_as_filename::v3::Request>,
|
body: Ruma<get_content_as_filename::v3::Request>,
|
||||||
) -> Result<get_content_as_filename::v3::Response> {
|
) -> Result<RumaResponse<get_content_as_filename::v3::Response>> {
|
||||||
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
|
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
|
||||||
|
|
||||||
if let Some(FileMeta {
|
if let Some(FileMeta {
|
||||||
|
|
@ -139,7 +142,7 @@ pub(crate) async fn get_content_as_filename_route(
|
||||||
..
|
..
|
||||||
}) = services().media.get(mxc.clone()).await?
|
}) = services().media.get(mxc.clone()).await?
|
||||||
{
|
{
|
||||||
Ok(get_content_as_filename::v3::Response {
|
Ok(RumaResponse(get_content_as_filename::v3::Response {
|
||||||
file,
|
file,
|
||||||
content_type,
|
content_type,
|
||||||
content_disposition: Some(format!(
|
content_disposition: Some(format!(
|
||||||
|
|
@ -147,7 +150,7 @@ pub(crate) async fn get_content_as_filename_route(
|
||||||
body.filename
|
body.filename
|
||||||
)),
|
)),
|
||||||
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
||||||
})
|
}))
|
||||||
} else if &*body.server_name != services().globals.server_name()
|
} else if &*body.server_name != services().globals.server_name()
|
||||||
&& body.allow_remote
|
&& body.allow_remote
|
||||||
{
|
{
|
||||||
|
|
@ -155,7 +158,7 @@ pub(crate) async fn get_content_as_filename_route(
|
||||||
get_remote_content(&mxc, &body.server_name, body.media_id.clone())
|
get_remote_content(&mxc, &body.server_name, body.media_id.clone())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(get_content_as_filename::v3::Response {
|
Ok(RumaResponse(get_content_as_filename::v3::Response {
|
||||||
content_disposition: Some(format!(
|
content_disposition: Some(format!(
|
||||||
"inline: filename={}",
|
"inline: filename={}",
|
||||||
body.filename
|
body.filename
|
||||||
|
|
@ -163,7 +166,7 @@ pub(crate) async fn get_content_as_filename_route(
|
||||||
content_type: remote_content_response.content_type,
|
content_type: remote_content_response.content_type,
|
||||||
file: remote_content_response.file,
|
file: remote_content_response.file,
|
||||||
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
||||||
})
|
}))
|
||||||
} else {
|
} else {
|
||||||
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
|
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +179,7 @@ pub(crate) async fn get_content_as_filename_route(
|
||||||
/// - Only allows federation if `allow_remote` is true
|
/// - Only allows federation if `allow_remote` is true
|
||||||
pub(crate) async fn get_content_thumbnail_route(
|
pub(crate) async fn get_content_thumbnail_route(
|
||||||
body: Ruma<get_content_thumbnail::v3::Request>,
|
body: Ruma<get_content_thumbnail::v3::Request>,
|
||||||
) -> Result<get_content_thumbnail::v3::Response> {
|
) -> Result<RumaResponse<get_content_thumbnail::v3::Response>> {
|
||||||
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
|
let mxc = format!("mxc://{}/{}", body.server_name, body.media_id);
|
||||||
|
|
||||||
if let Some(FileMeta {
|
if let Some(FileMeta {
|
||||||
|
|
@ -196,11 +199,11 @@ pub(crate) async fn get_content_thumbnail_route(
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
Ok(get_content_thumbnail::v3::Response {
|
Ok(RumaResponse(get_content_thumbnail::v3::Response {
|
||||||
file,
|
file,
|
||||||
content_type,
|
content_type,
|
||||||
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
||||||
})
|
}))
|
||||||
} else if &*body.server_name != services().globals.server_name()
|
} else if &*body.server_name != services().globals.server_name()
|
||||||
&& body.allow_remote
|
&& body.allow_remote
|
||||||
{
|
{
|
||||||
|
|
@ -233,7 +236,7 @@ pub(crate) async fn get_content_thumbnail_route(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(get_thumbnail_response)
|
Ok(RumaResponse(get_thumbnail_response))
|
||||||
} else {
|
} else {
|
||||||
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
|
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ use tracing::{debug, error, info, warn};
|
||||||
use super::get_alias_helper;
|
use super::get_alias_helper;
|
||||||
use crate::{
|
use crate::{
|
||||||
service::pdu::{gen_event_id_canonical_json, PduBuilder},
|
service::pdu::{gen_event_id_canonical_json, PduBuilder},
|
||||||
services, utils, Error, PduEvent, Result, Ruma,
|
services, utils, Error, PduEvent, Result, Ruma, RumaResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/join`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/join`
|
||||||
|
|
@ -49,7 +49,7 @@ use crate::{
|
||||||
/// federation
|
/// federation
|
||||||
pub(crate) async fn join_room_by_id_route(
|
pub(crate) async fn join_room_by_id_route(
|
||||||
body: Ruma<join_room_by_id::v3::Request>,
|
body: Ruma<join_room_by_id::v3::Request>,
|
||||||
) -> Result<join_room_by_id::v3::Response> {
|
) -> Result<RumaResponse<join_room_by_id::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
// There is no body.server_name for /roomId/join
|
// There is no body.server_name for /roomId/join
|
||||||
|
|
@ -83,6 +83,7 @@ pub(crate) async fn join_room_by_id_route(
|
||||||
body.third_party_signed.as_ref(),
|
body.third_party_signed.as_ref(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
.map(RumaResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/join/{roomIdOrAlias}`
|
/// # `POST /_matrix/client/r0/join/{roomIdOrAlias}`
|
||||||
|
|
@ -95,7 +96,7 @@ pub(crate) async fn join_room_by_id_route(
|
||||||
/// federation
|
/// federation
|
||||||
pub(crate) async fn join_room_by_id_or_alias_route(
|
pub(crate) async fn join_room_by_id_or_alias_route(
|
||||||
body: Ruma<join_room_by_id_or_alias::v3::Request>,
|
body: Ruma<join_room_by_id_or_alias::v3::Request>,
|
||||||
) -> Result<join_room_by_id_or_alias::v3::Response> {
|
) -> Result<RumaResponse<join_room_by_id_or_alias::v3::Response>> {
|
||||||
let sender_user =
|
let sender_user =
|
||||||
body.sender_user.as_deref().expect("user is authenticated");
|
body.sender_user.as_deref().expect("user is authenticated");
|
||||||
let body = body.body;
|
let body = body.body;
|
||||||
|
|
@ -147,9 +148,9 @@ pub(crate) async fn join_room_by_id_or_alias_route(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(join_room_by_id_or_alias::v3::Response {
|
Ok(RumaResponse(join_room_by_id_or_alias::v3::Response {
|
||||||
room_id: join_room_response.room_id,
|
room_id: join_room_response.room_id,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/leave`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/leave`
|
||||||
|
|
@ -159,12 +160,12 @@ pub(crate) async fn join_room_by_id_or_alias_route(
|
||||||
/// - This should always work if the user is currently joined.
|
/// - This should always work if the user is currently joined.
|
||||||
pub(crate) async fn leave_room_route(
|
pub(crate) async fn leave_room_route(
|
||||||
body: Ruma<leave_room::v3::Request>,
|
body: Ruma<leave_room::v3::Request>,
|
||||||
) -> Result<leave_room::v3::Response> {
|
) -> Result<RumaResponse<leave_room::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
leave_room(sender_user, &body.room_id, body.reason.clone()).await?;
|
leave_room(sender_user, &body.room_id, body.reason.clone()).await?;
|
||||||
|
|
||||||
Ok(leave_room::v3::Response::new())
|
Ok(RumaResponse(leave_room::v3::Response::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/invite`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/invite`
|
||||||
|
|
@ -172,7 +173,7 @@ pub(crate) async fn leave_room_route(
|
||||||
/// Tries to send an invite event into the room.
|
/// Tries to send an invite event into the room.
|
||||||
pub(crate) async fn invite_user_route(
|
pub(crate) async fn invite_user_route(
|
||||||
body: Ruma<invite_user::v3::Request>,
|
body: Ruma<invite_user::v3::Request>,
|
||||||
) -> Result<invite_user::v3::Response> {
|
) -> Result<RumaResponse<invite_user::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if let invite_user::v3::InvitationRecipient::UserId {
|
if let invite_user::v3::InvitationRecipient::UserId {
|
||||||
|
|
@ -187,7 +188,7 @@ pub(crate) async fn invite_user_route(
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(invite_user::v3::Response {})
|
Ok(RumaResponse(invite_user::v3::Response {}))
|
||||||
} else {
|
} else {
|
||||||
Err(Error::BadRequest(ErrorKind::NotFound, "User not found."))
|
Err(Error::BadRequest(ErrorKind::NotFound, "User not found."))
|
||||||
}
|
}
|
||||||
|
|
@ -198,13 +199,13 @@ pub(crate) async fn invite_user_route(
|
||||||
/// Tries to send a kick event into the room.
|
/// Tries to send a kick event into the room.
|
||||||
pub(crate) async fn kick_user_route(
|
pub(crate) async fn kick_user_route(
|
||||||
body: Ruma<kick_user::v3::Request>,
|
body: Ruma<kick_user::v3::Request>,
|
||||||
) -> Result<kick_user::v3::Response> {
|
) -> Result<RumaResponse<kick_user::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if let Ok(true) =
|
if let Ok(true) =
|
||||||
services().rooms.state_cache.is_left(sender_user, &body.room_id)
|
services().rooms.state_cache.is_left(sender_user, &body.room_id)
|
||||||
{
|
{
|
||||||
return Ok(kick_user::v3::Response {});
|
return Ok(RumaResponse(kick_user::v3::Response {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut event: RoomMemberEventContent = serde_json::from_str(
|
let mut event: RoomMemberEventContent = serde_json::from_str(
|
||||||
|
|
@ -259,7 +260,7 @@ pub(crate) async fn kick_user_route(
|
||||||
|
|
||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
|
|
||||||
Ok(kick_user::v3::Response::new())
|
Ok(RumaResponse(kick_user::v3::Response::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/ban`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/ban`
|
||||||
|
|
@ -267,14 +268,14 @@ pub(crate) async fn kick_user_route(
|
||||||
/// Tries to send a ban event into the room.
|
/// Tries to send a ban event into the room.
|
||||||
pub(crate) async fn ban_user_route(
|
pub(crate) async fn ban_user_route(
|
||||||
body: Ruma<ban_user::v3::Request>,
|
body: Ruma<ban_user::v3::Request>,
|
||||||
) -> Result<ban_user::v3::Response> {
|
) -> Result<RumaResponse<ban_user::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if let Ok(Some(membership_event)) =
|
if let Ok(Some(membership_event)) =
|
||||||
services().rooms.state_accessor.get_member(&body.room_id, sender_user)
|
services().rooms.state_accessor.get_member(&body.room_id, sender_user)
|
||||||
{
|
{
|
||||||
if membership_event.membership == MembershipState::Ban {
|
if membership_event.membership == MembershipState::Ban {
|
||||||
return Ok(ban_user::v3::Response {});
|
return Ok(RumaResponse(ban_user::v3::Response {}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -343,7 +344,7 @@ pub(crate) async fn ban_user_route(
|
||||||
|
|
||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
|
|
||||||
Ok(ban_user::v3::Response::new())
|
Ok(RumaResponse(ban_user::v3::Response::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/unban`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/unban`
|
||||||
|
|
@ -351,14 +352,14 @@ pub(crate) async fn ban_user_route(
|
||||||
/// Tries to send an unban event into the room.
|
/// Tries to send an unban event into the room.
|
||||||
pub(crate) async fn unban_user_route(
|
pub(crate) async fn unban_user_route(
|
||||||
body: Ruma<unban_user::v3::Request>,
|
body: Ruma<unban_user::v3::Request>,
|
||||||
) -> Result<unban_user::v3::Response> {
|
) -> Result<RumaResponse<unban_user::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if let Ok(Some(membership_event)) =
|
if let Ok(Some(membership_event)) =
|
||||||
services().rooms.state_accessor.get_member(&body.room_id, sender_user)
|
services().rooms.state_accessor.get_member(&body.room_id, sender_user)
|
||||||
{
|
{
|
||||||
if membership_event.membership != MembershipState::Ban {
|
if membership_event.membership != MembershipState::Ban {
|
||||||
return Ok(unban_user::v3::Response {});
|
return Ok(RumaResponse(unban_user::v3::Response {}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -414,7 +415,7 @@ pub(crate) async fn unban_user_route(
|
||||||
|
|
||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
|
|
||||||
Ok(unban_user::v3::Response::new())
|
Ok(RumaResponse(unban_user::v3::Response::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/forget`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/forget`
|
||||||
|
|
@ -428,12 +429,12 @@ pub(crate) async fn unban_user_route(
|
||||||
/// forgotten, so this has to be called from every device
|
/// forgotten, so this has to be called from every device
|
||||||
pub(crate) async fn forget_room_route(
|
pub(crate) async fn forget_room_route(
|
||||||
body: Ruma<forget_room::v3::Request>,
|
body: Ruma<forget_room::v3::Request>,
|
||||||
) -> Result<forget_room::v3::Response> {
|
) -> Result<RumaResponse<forget_room::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
services().rooms.state_cache.forget(&body.room_id, sender_user)?;
|
services().rooms.state_cache.forget(&body.room_id, sender_user)?;
|
||||||
|
|
||||||
Ok(forget_room::v3::Response::new())
|
Ok(RumaResponse(forget_room::v3::Response::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/joined_rooms`
|
/// # `POST /_matrix/client/r0/joined_rooms`
|
||||||
|
|
@ -441,17 +442,17 @@ pub(crate) async fn forget_room_route(
|
||||||
/// Lists all rooms the user has joined.
|
/// Lists all rooms the user has joined.
|
||||||
pub(crate) async fn joined_rooms_route(
|
pub(crate) async fn joined_rooms_route(
|
||||||
body: Ruma<joined_rooms::v3::Request>,
|
body: Ruma<joined_rooms::v3::Request>,
|
||||||
) -> Result<joined_rooms::v3::Response> {
|
) -> Result<RumaResponse<joined_rooms::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
Ok(joined_rooms::v3::Response {
|
Ok(RumaResponse(joined_rooms::v3::Response {
|
||||||
joined_rooms: services()
|
joined_rooms: services()
|
||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.rooms_joined(sender_user)
|
.rooms_joined(sender_user)
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
.collect(),
|
.collect(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/members`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/members`
|
||||||
|
|
@ -462,7 +463,7 @@ pub(crate) async fn joined_rooms_route(
|
||||||
/// - Only works if the user is currently joined
|
/// - Only works if the user is currently joined
|
||||||
pub(crate) async fn get_member_events_route(
|
pub(crate) async fn get_member_events_route(
|
||||||
body: Ruma<get_member_events::v3::Request>,
|
body: Ruma<get_member_events::v3::Request>,
|
||||||
) -> Result<get_member_events::v3::Response> {
|
) -> Result<RumaResponse<get_member_events::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if !services()
|
if !services()
|
||||||
|
|
@ -476,7 +477,7 @@ pub(crate) async fn get_member_events_route(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_member_events::v3::Response {
|
Ok(RumaResponse(get_member_events::v3::Response {
|
||||||
chunk: services()
|
chunk: services()
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
|
|
@ -486,7 +487,7 @@ pub(crate) async fn get_member_events_route(
|
||||||
.filter(|(key, _)| key.0 == StateEventType::RoomMember)
|
.filter(|(key, _)| key.0 == StateEventType::RoomMember)
|
||||||
.map(|(_, pdu)| pdu.to_member_event())
|
.map(|(_, pdu)| pdu.to_member_event())
|
||||||
.collect(),
|
.collect(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/joined_members`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/joined_members`
|
||||||
|
|
@ -497,7 +498,7 @@ pub(crate) async fn get_member_events_route(
|
||||||
/// - TODO: An appservice just needs a puppet joined
|
/// - TODO: An appservice just needs a puppet joined
|
||||||
pub(crate) async fn joined_members_route(
|
pub(crate) async fn joined_members_route(
|
||||||
body: Ruma<joined_members::v3::Request>,
|
body: Ruma<joined_members::v3::Request>,
|
||||||
) -> Result<joined_members::v3::Response> {
|
) -> Result<RumaResponse<joined_members::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if !services()
|
if !services()
|
||||||
|
|
@ -530,9 +531,9 @@ pub(crate) async fn joined_members_route(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(joined_members::v3::Response {
|
Ok(RumaResponse(joined_members::v3::Response {
|
||||||
joined,
|
joined,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use ruma::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
service::{pdu::PduBuilder, rooms::timeline::PduCount},
|
service::{pdu::PduBuilder, rooms::timeline::PduCount},
|
||||||
services, utils, Error, Result, Ruma,
|
services, utils, Error, Result, Ruma, RumaResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}`
|
/// # `PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}`
|
||||||
|
|
@ -28,7 +28,7 @@ use crate::{
|
||||||
/// allowed
|
/// allowed
|
||||||
pub(crate) async fn send_message_event_route(
|
pub(crate) async fn send_message_event_route(
|
||||||
body: Ruma<send_message_event::v3::Request>,
|
body: Ruma<send_message_event::v3::Request>,
|
||||||
) -> Result<send_message_event::v3::Response> {
|
) -> Result<RumaResponse<send_message_event::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let sender_device = body.sender_device.as_deref();
|
let sender_device = body.sender_device.as_deref();
|
||||||
|
|
||||||
|
|
@ -77,9 +77,9 @@ pub(crate) async fn send_message_event_route(
|
||||||
.map_err(|_| {
|
.map_err(|_| {
|
||||||
Error::bad_database("Invalid event id in txnid data.")
|
Error::bad_database("Invalid event id in txnid data.")
|
||||||
})?;
|
})?;
|
||||||
return Ok(send_message_event::v3::Response {
|
return Ok(RumaResponse(send_message_event::v3::Response {
|
||||||
event_id,
|
event_id,
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut unsigned = BTreeMap::new();
|
let mut unsigned = BTreeMap::new();
|
||||||
|
|
@ -118,7 +118,9 @@ pub(crate) async fn send_message_event_route(
|
||||||
|
|
||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
|
|
||||||
Ok(send_message_event::v3::Response::new((*event_id).to_owned()))
|
Ok(RumaResponse(send_message_event::v3::Response::new(
|
||||||
|
(*event_id).to_owned(),
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomId}/messages`
|
/// # `GET /_matrix/client/r0/rooms/{roomId}/messages`
|
||||||
|
|
@ -131,7 +133,7 @@ pub(crate) async fn send_message_event_route(
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub(crate) async fn get_message_events_route(
|
pub(crate) async fn get_message_events_route(
|
||||||
body: Ruma<get_message_events::v3::Request>,
|
body: Ruma<get_message_events::v3::Request>,
|
||||||
) -> Result<get_message_events::v3::Response> {
|
) -> Result<RumaResponse<get_message_events::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let sender_device =
|
let sender_device =
|
||||||
body.sender_device.as_ref().expect("user is authenticated");
|
body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
@ -308,5 +310,5 @@ pub(crate) async fn get_message_events_route(
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Ok(resp)
|
Ok(RumaResponse(resp))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,9 @@ use ruma::{
|
||||||
use serde_json::value::to_raw_value;
|
use serde_json::value::to_raw_value;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
use crate::{service::pdu::PduBuilder, services, Error, Result, Ruma};
|
use crate::{
|
||||||
|
service::pdu::PduBuilder, services, Error, Result, Ruma, RumaResponse,
|
||||||
|
};
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/profile/{userId}/displayname`
|
/// # `PUT /_matrix/client/r0/profile/{userId}/displayname`
|
||||||
///
|
///
|
||||||
|
|
@ -27,7 +29,7 @@ use crate::{service::pdu::PduBuilder, services, Error, Result, Ruma};
|
||||||
/// - Also makes sure other users receive the update using presence EDUs
|
/// - Also makes sure other users receive the update using presence EDUs
|
||||||
pub(crate) async fn set_displayname_route(
|
pub(crate) async fn set_displayname_route(
|
||||||
body: Ruma<set_display_name::v3::Request>,
|
body: Ruma<set_display_name::v3::Request>,
|
||||||
) -> Result<set_display_name::v3::Response> {
|
) -> Result<RumaResponse<set_display_name::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
services().users.set_displayname(sender_user, body.displayname.clone())?;
|
services().users.set_displayname(sender_user, body.displayname.clone())?;
|
||||||
|
|
@ -107,7 +109,7 @@ pub(crate) async fn set_displayname_route(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(set_display_name::v3::Response {})
|
Ok(RumaResponse(set_display_name::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/profile/{userId}/displayname`
|
/// # `GET /_matrix/client/r0/profile/{userId}/displayname`
|
||||||
|
|
@ -117,7 +119,7 @@ pub(crate) async fn set_displayname_route(
|
||||||
/// - If user is on another server: Fetches displayname over federation
|
/// - If user is on another server: Fetches displayname over federation
|
||||||
pub(crate) async fn get_displayname_route(
|
pub(crate) async fn get_displayname_route(
|
||||||
body: Ruma<get_display_name::v3::Request>,
|
body: Ruma<get_display_name::v3::Request>,
|
||||||
) -> Result<get_display_name::v3::Response> {
|
) -> Result<RumaResponse<get_display_name::v3::Response>> {
|
||||||
if body.user_id.server_name() != services().globals.server_name() {
|
if body.user_id.server_name() != services().globals.server_name() {
|
||||||
let response = services()
|
let response = services()
|
||||||
.sending
|
.sending
|
||||||
|
|
@ -130,14 +132,14 @@ pub(crate) async fn get_displayname_route(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Ok(get_display_name::v3::Response {
|
return Ok(RumaResponse(get_display_name::v3::Response {
|
||||||
displayname: response.displayname,
|
displayname: response.displayname,
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_display_name::v3::Response {
|
Ok(RumaResponse(get_display_name::v3::Response {
|
||||||
displayname: services().users.displayname(&body.user_id)?,
|
displayname: services().users.displayname(&body.user_id)?,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/profile/{userId}/avatar_url`
|
/// # `PUT /_matrix/client/r0/profile/{userId}/avatar_url`
|
||||||
|
|
@ -147,7 +149,7 @@ pub(crate) async fn get_displayname_route(
|
||||||
/// - Also makes sure other users receive the update using presence EDUs
|
/// - Also makes sure other users receive the update using presence EDUs
|
||||||
pub(crate) async fn set_avatar_url_route(
|
pub(crate) async fn set_avatar_url_route(
|
||||||
body: Ruma<set_avatar_url::v3::Request>,
|
body: Ruma<set_avatar_url::v3::Request>,
|
||||||
) -> Result<set_avatar_url::v3::Response> {
|
) -> Result<RumaResponse<set_avatar_url::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
services().users.set_avatar_url(sender_user, body.avatar_url.clone())?;
|
services().users.set_avatar_url(sender_user, body.avatar_url.clone())?;
|
||||||
|
|
@ -229,7 +231,7 @@ pub(crate) async fn set_avatar_url_route(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(set_avatar_url::v3::Response {})
|
Ok(RumaResponse(set_avatar_url::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/profile/{userId}/avatar_url`
|
/// # `GET /_matrix/client/r0/profile/{userId}/avatar_url`
|
||||||
|
|
@ -240,7 +242,7 @@ pub(crate) async fn set_avatar_url_route(
|
||||||
/// federation
|
/// federation
|
||||||
pub(crate) async fn get_avatar_url_route(
|
pub(crate) async fn get_avatar_url_route(
|
||||||
body: Ruma<get_avatar_url::v3::Request>,
|
body: Ruma<get_avatar_url::v3::Request>,
|
||||||
) -> Result<get_avatar_url::v3::Response> {
|
) -> Result<RumaResponse<get_avatar_url::v3::Response>> {
|
||||||
if body.user_id.server_name() != services().globals.server_name() {
|
if body.user_id.server_name() != services().globals.server_name() {
|
||||||
let response = services()
|
let response = services()
|
||||||
.sending
|
.sending
|
||||||
|
|
@ -253,16 +255,16 @@ pub(crate) async fn get_avatar_url_route(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Ok(get_avatar_url::v3::Response {
|
return Ok(RumaResponse(get_avatar_url::v3::Response {
|
||||||
avatar_url: response.avatar_url,
|
avatar_url: response.avatar_url,
|
||||||
blurhash: response.blurhash,
|
blurhash: response.blurhash,
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_avatar_url::v3::Response {
|
Ok(RumaResponse(get_avatar_url::v3::Response {
|
||||||
avatar_url: services().users.avatar_url(&body.user_id)?,
|
avatar_url: services().users.avatar_url(&body.user_id)?,
|
||||||
blurhash: services().users.blurhash(&body.user_id)?,
|
blurhash: services().users.blurhash(&body.user_id)?,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/profile/{userId}`
|
/// # `GET /_matrix/client/r0/profile/{userId}`
|
||||||
|
|
@ -272,7 +274,7 @@ pub(crate) async fn get_avatar_url_route(
|
||||||
/// - If user is on another server: Fetches profile over federation
|
/// - If user is on another server: Fetches profile over federation
|
||||||
pub(crate) async fn get_profile_route(
|
pub(crate) async fn get_profile_route(
|
||||||
body: Ruma<get_profile::v3::Request>,
|
body: Ruma<get_profile::v3::Request>,
|
||||||
) -> Result<get_profile::v3::Response> {
|
) -> Result<RumaResponse<get_profile::v3::Response>> {
|
||||||
if body.user_id.server_name() != services().globals.server_name() {
|
if body.user_id.server_name() != services().globals.server_name() {
|
||||||
let response = services()
|
let response = services()
|
||||||
.sending
|
.sending
|
||||||
|
|
@ -285,11 +287,11 @@ pub(crate) async fn get_profile_route(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Ok(get_profile::v3::Response {
|
return Ok(RumaResponse(get_profile::v3::Response {
|
||||||
displayname: response.displayname,
|
displayname: response.displayname,
|
||||||
avatar_url: response.avatar_url,
|
avatar_url: response.avatar_url,
|
||||||
blurhash: response.blurhash,
|
blurhash: response.blurhash,
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !services().users.exists(&body.user_id)? {
|
if !services().users.exists(&body.user_id)? {
|
||||||
|
|
@ -300,9 +302,9 @@ pub(crate) async fn get_profile_route(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_profile::v3::Response {
|
Ok(RumaResponse(get_profile::v3::Response {
|
||||||
avatar_url: services().users.avatar_url(&body.user_id)?,
|
avatar_url: services().users.avatar_url(&body.user_id)?,
|
||||||
blurhash: services().users.blurhash(&body.user_id)?,
|
blurhash: services().users.blurhash(&body.user_id)?,
|
||||||
displayname: services().users.displayname(&body.user_id)?,
|
displayname: services().users.displayname(&body.user_id)?,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,14 @@ use ruma::{
|
||||||
push::{AnyPushRuleRef, InsertPushRuleError, RemovePushRuleError},
|
push::{AnyPushRuleRef, InsertPushRuleError, RemovePushRuleError},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{services, Error, Result, Ruma};
|
use crate::{services, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules`
|
/// # `GET /_matrix/client/r0/pushrules`
|
||||||
///
|
///
|
||||||
/// Retrieves the push rules event for this user.
|
/// Retrieves the push rules event for this user.
|
||||||
pub(crate) async fn get_pushrules_all_route(
|
pub(crate) async fn get_pushrules_all_route(
|
||||||
body: Ruma<get_pushrules_all::v3::Request>,
|
body: Ruma<get_pushrules_all::v3::Request>,
|
||||||
) -> Result<get_pushrules_all::v3::Response> {
|
) -> Result<RumaResponse<get_pushrules_all::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let event = services()
|
let event = services()
|
||||||
|
|
@ -37,9 +37,9 @@ pub(crate) async fn get_pushrules_all_route(
|
||||||
.map_err(|_| Error::bad_database("Invalid account data event in db."))?
|
.map_err(|_| Error::bad_database("Invalid account data event in db."))?
|
||||||
.content;
|
.content;
|
||||||
|
|
||||||
Ok(get_pushrules_all::v3::Response {
|
Ok(RumaResponse(get_pushrules_all::v3::Response {
|
||||||
global: account_data.global,
|
global: account_data.global,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
|
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
|
||||||
|
|
@ -47,7 +47,7 @@ pub(crate) async fn get_pushrules_all_route(
|
||||||
/// Retrieves a single specified push rule for this user.
|
/// Retrieves a single specified push rule for this user.
|
||||||
pub(crate) async fn get_pushrule_route(
|
pub(crate) async fn get_pushrule_route(
|
||||||
body: Ruma<get_pushrule::v3::Request>,
|
body: Ruma<get_pushrule::v3::Request>,
|
||||||
) -> Result<get_pushrule::v3::Response> {
|
) -> Result<RumaResponse<get_pushrule::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let event = services()
|
let event = services()
|
||||||
|
|
@ -72,9 +72,9 @@ pub(crate) async fn get_pushrule_route(
|
||||||
.map(Into::into);
|
.map(Into::into);
|
||||||
|
|
||||||
if let Some(rule) = rule {
|
if let Some(rule) = rule {
|
||||||
Ok(get_pushrule::v3::Response {
|
Ok(RumaResponse(get_pushrule::v3::Response {
|
||||||
rule,
|
rule,
|
||||||
})
|
}))
|
||||||
} else {
|
} else {
|
||||||
Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found."))
|
Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found."))
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +85,7 @@ pub(crate) async fn get_pushrule_route(
|
||||||
/// Creates a single specified push rule for this user.
|
/// Creates a single specified push rule for this user.
|
||||||
pub(crate) async fn set_pushrule_route(
|
pub(crate) async fn set_pushrule_route(
|
||||||
body: Ruma<set_pushrule::v3::Request>,
|
body: Ruma<set_pushrule::v3::Request>,
|
||||||
) -> Result<set_pushrule::v3::Response> {
|
) -> Result<RumaResponse<set_pushrule::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let body = body.body;
|
let body = body.body;
|
||||||
|
|
||||||
|
|
@ -157,7 +157,7 @@ pub(crate) async fn set_pushrule_route(
|
||||||
.expect("to json value always works"),
|
.expect("to json value always works"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(set_pushrule::v3::Response {})
|
Ok(RumaResponse(set_pushrule::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions`
|
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions`
|
||||||
|
|
@ -165,7 +165,7 @@ pub(crate) async fn set_pushrule_route(
|
||||||
/// Gets the actions of a single specified push rule for this user.
|
/// Gets the actions of a single specified push rule for this user.
|
||||||
pub(crate) async fn get_pushrule_actions_route(
|
pub(crate) async fn get_pushrule_actions_route(
|
||||||
body: Ruma<get_pushrule_actions::v3::Request>,
|
body: Ruma<get_pushrule_actions::v3::Request>,
|
||||||
) -> Result<get_pushrule_actions::v3::Response> {
|
) -> Result<RumaResponse<get_pushrule_actions::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if body.scope != RuleScope::Global {
|
if body.scope != RuleScope::Global {
|
||||||
|
|
@ -200,9 +200,9 @@ pub(crate) async fn get_pushrule_actions_route(
|
||||||
"Push rule not found.",
|
"Push rule not found.",
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
Ok(get_pushrule_actions::v3::Response {
|
Ok(RumaResponse(get_pushrule_actions::v3::Response {
|
||||||
actions,
|
actions,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions`
|
/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions`
|
||||||
|
|
@ -210,7 +210,7 @@ pub(crate) async fn get_pushrule_actions_route(
|
||||||
/// Sets the actions of a single specified push rule for this user.
|
/// Sets the actions of a single specified push rule for this user.
|
||||||
pub(crate) async fn set_pushrule_actions_route(
|
pub(crate) async fn set_pushrule_actions_route(
|
||||||
body: Ruma<set_pushrule_actions::v3::Request>,
|
body: Ruma<set_pushrule_actions::v3::Request>,
|
||||||
) -> Result<set_pushrule_actions::v3::Response> {
|
) -> Result<RumaResponse<set_pushrule_actions::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if body.scope != RuleScope::Global {
|
if body.scope != RuleScope::Global {
|
||||||
|
|
@ -257,7 +257,7 @@ pub(crate) async fn set_pushrule_actions_route(
|
||||||
.expect("to json value always works"),
|
.expect("to json value always works"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(set_pushrule_actions::v3::Response {})
|
Ok(RumaResponse(set_pushrule_actions::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled`
|
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled`
|
||||||
|
|
@ -265,7 +265,7 @@ pub(crate) async fn set_pushrule_actions_route(
|
||||||
/// Gets the enabled status of a single specified push rule for this user.
|
/// Gets the enabled status of a single specified push rule for this user.
|
||||||
pub(crate) async fn get_pushrule_enabled_route(
|
pub(crate) async fn get_pushrule_enabled_route(
|
||||||
body: Ruma<get_pushrule_enabled::v3::Request>,
|
body: Ruma<get_pushrule_enabled::v3::Request>,
|
||||||
) -> Result<get_pushrule_enabled::v3::Response> {
|
) -> Result<RumaResponse<get_pushrule_enabled::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if body.scope != RuleScope::Global {
|
if body.scope != RuleScope::Global {
|
||||||
|
|
@ -301,9 +301,9 @@ pub(crate) async fn get_pushrule_enabled_route(
|
||||||
"Push rule not found.",
|
"Push rule not found.",
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
Ok(get_pushrule_enabled::v3::Response {
|
Ok(RumaResponse(get_pushrule_enabled::v3::Response {
|
||||||
enabled,
|
enabled,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled`
|
/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled`
|
||||||
|
|
@ -311,7 +311,7 @@ pub(crate) async fn get_pushrule_enabled_route(
|
||||||
/// Sets the enabled status of a single specified push rule for this user.
|
/// Sets the enabled status of a single specified push rule for this user.
|
||||||
pub(crate) async fn set_pushrule_enabled_route(
|
pub(crate) async fn set_pushrule_enabled_route(
|
||||||
body: Ruma<set_pushrule_enabled::v3::Request>,
|
body: Ruma<set_pushrule_enabled::v3::Request>,
|
||||||
) -> Result<set_pushrule_enabled::v3::Response> {
|
) -> Result<RumaResponse<set_pushrule_enabled::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if body.scope != RuleScope::Global {
|
if body.scope != RuleScope::Global {
|
||||||
|
|
@ -358,7 +358,7 @@ pub(crate) async fn set_pushrule_enabled_route(
|
||||||
.expect("to json value always works"),
|
.expect("to json value always works"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(set_pushrule_enabled::v3::Response {})
|
Ok(RumaResponse(set_pushrule_enabled::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
|
/// # `DELETE /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
|
||||||
|
|
@ -366,7 +366,7 @@ pub(crate) async fn set_pushrule_enabled_route(
|
||||||
/// Deletes a single specified push rule for this user.
|
/// Deletes a single specified push rule for this user.
|
||||||
pub(crate) async fn delete_pushrule_route(
|
pub(crate) async fn delete_pushrule_route(
|
||||||
body: Ruma<delete_pushrule::v3::Request>,
|
body: Ruma<delete_pushrule::v3::Request>,
|
||||||
) -> Result<delete_pushrule::v3::Response> {
|
) -> Result<RumaResponse<delete_pushrule::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if body.scope != RuleScope::Global {
|
if body.scope != RuleScope::Global {
|
||||||
|
|
@ -418,7 +418,7 @@ pub(crate) async fn delete_pushrule_route(
|
||||||
.expect("to json value always works"),
|
.expect("to json value always works"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(delete_pushrule::v3::Response {})
|
Ok(RumaResponse(delete_pushrule::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushers`
|
/// # `GET /_matrix/client/r0/pushers`
|
||||||
|
|
@ -426,12 +426,12 @@ pub(crate) async fn delete_pushrule_route(
|
||||||
/// Gets all currently active pushers for the sender user.
|
/// Gets all currently active pushers for the sender user.
|
||||||
pub(crate) async fn get_pushers_route(
|
pub(crate) async fn get_pushers_route(
|
||||||
body: Ruma<get_pushers::v3::Request>,
|
body: Ruma<get_pushers::v3::Request>,
|
||||||
) -> Result<get_pushers::v3::Response> {
|
) -> Result<RumaResponse<get_pushers::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
Ok(get_pushers::v3::Response {
|
Ok(RumaResponse(get_pushers::v3::Response {
|
||||||
pushers: services().pusher.get_pushers(sender_user)?,
|
pushers: services().pusher.get_pushers(sender_user)?,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/pushers/set`
|
/// # `POST /_matrix/client/r0/pushers/set`
|
||||||
|
|
@ -441,10 +441,10 @@ pub(crate) async fn get_pushers_route(
|
||||||
/// - TODO: Handle `append`
|
/// - TODO: Handle `append`
|
||||||
pub(crate) async fn set_pushers_route(
|
pub(crate) async fn set_pushers_route(
|
||||||
body: Ruma<set_pusher::v3::Request>,
|
body: Ruma<set_pusher::v3::Request>,
|
||||||
) -> Result<set_pusher::v3::Response> {
|
) -> Result<RumaResponse<set_pusher::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
services().pusher.set_pusher(sender_user, body.action.clone())?;
|
services().pusher.set_pusher(sender_user, body.action.clone())?;
|
||||||
|
|
||||||
Ok(set_pusher::v3::Response::default())
|
Ok(RumaResponse(set_pusher::v3::Response::default()))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ use ruma::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
service::rooms::timeline::PduCount, services, Error, Result, Ruma,
|
service::rooms::timeline::PduCount, services, Error, Result, Ruma,
|
||||||
|
RumaResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/read_markers`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/read_markers`
|
||||||
|
|
@ -24,7 +25,7 @@ use crate::{
|
||||||
/// EDU
|
/// EDU
|
||||||
pub(crate) async fn set_read_marker_route(
|
pub(crate) async fn set_read_marker_route(
|
||||||
body: Ruma<set_read_marker::v3::Request>,
|
body: Ruma<set_read_marker::v3::Request>,
|
||||||
) -> Result<set_read_marker::v3::Response> {
|
) -> Result<RumaResponse<set_read_marker::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if let Some(fully_read) = &body.fully_read {
|
if let Some(fully_read) = &body.fully_read {
|
||||||
|
|
@ -97,7 +98,7 @@ pub(crate) async fn set_read_marker_route(
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(set_read_marker::v3::Response {})
|
Ok(RumaResponse(set_read_marker::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}`
|
||||||
|
|
@ -105,7 +106,7 @@ pub(crate) async fn set_read_marker_route(
|
||||||
/// Sets private read marker and public read receipt EDU.
|
/// Sets private read marker and public read receipt EDU.
|
||||||
pub(crate) async fn create_receipt_route(
|
pub(crate) async fn create_receipt_route(
|
||||||
body: Ruma<create_receipt::v3::Request>,
|
body: Ruma<create_receipt::v3::Request>,
|
||||||
) -> Result<create_receipt::v3::Response> {
|
) -> Result<RumaResponse<create_receipt::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if matches!(
|
if matches!(
|
||||||
|
|
@ -187,5 +188,5 @@ pub(crate) async fn create_receipt_route(
|
||||||
_ => return Err(Error::bad_database("Unsupported receipt type")),
|
_ => return Err(Error::bad_database("Unsupported receipt type")),
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(create_receipt::v3::Response {})
|
Ok(RumaResponse(create_receipt::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use ruma::{
|
||||||
};
|
};
|
||||||
use serde_json::value::to_raw_value;
|
use serde_json::value::to_raw_value;
|
||||||
|
|
||||||
use crate::{service::pdu::PduBuilder, services, Result, Ruma};
|
use crate::{service::pdu::PduBuilder, services, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}`
|
/// # `PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}`
|
||||||
///
|
///
|
||||||
|
|
@ -15,7 +15,7 @@ use crate::{service::pdu::PduBuilder, services, Result, Ruma};
|
||||||
/// - TODO: Handle txn id
|
/// - TODO: Handle txn id
|
||||||
pub(crate) async fn redact_event_route(
|
pub(crate) async fn redact_event_route(
|
||||||
body: Ruma<redact_event::v3::Request>,
|
body: Ruma<redact_event::v3::Request>,
|
||||||
) -> Result<redact_event::v3::Response> {
|
) -> Result<RumaResponse<redact_event::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let body = body.body;
|
let body = body.body;
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ pub(crate) async fn redact_event_route(
|
||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
|
|
||||||
let event_id = (*event_id).to_owned();
|
let event_id = (*event_id).to_owned();
|
||||||
Ok(redact_event::v3::Response {
|
Ok(RumaResponse(redact_event::v3::Response {
|
||||||
event_id,
|
event_id,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,18 @@ use ruma::{
|
||||||
uint,
|
uint,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{service::rooms::timeline::PduCount, services, Result, Ruma};
|
use crate::{
|
||||||
|
service::rooms::timeline::PduCount, services, Result, Ruma, RumaResponse,
|
||||||
|
};
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}`
|
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}`
|
||||||
pub(crate) async fn get_relating_events_with_rel_type_and_event_type_route(
|
pub(crate) async fn get_relating_events_with_rel_type_and_event_type_route(
|
||||||
body: Ruma<get_relating_events_with_rel_type_and_event_type::v1::Request>,
|
body: Ruma<get_relating_events_with_rel_type_and_event_type::v1::Request>,
|
||||||
) -> Result<get_relating_events_with_rel_type_and_event_type::v1::Response> {
|
) -> Result<
|
||||||
|
RumaResponse<
|
||||||
|
get_relating_events_with_rel_type_and_event_type::v1::Response,
|
||||||
|
>,
|
||||||
|
> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let from = match body.from.clone() {
|
let from = match body.from.clone() {
|
||||||
|
|
@ -44,17 +50,19 @@ pub(crate) async fn get_relating_events_with_rel_type_and_event_type_route(
|
||||||
limit,
|
limit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(get_relating_events_with_rel_type_and_event_type::v1::Response {
|
Ok(RumaResponse(
|
||||||
|
get_relating_events_with_rel_type_and_event_type::v1::Response {
|
||||||
chunk: res.chunk,
|
chunk: res.chunk,
|
||||||
next_batch: res.next_batch,
|
next_batch: res.next_batch,
|
||||||
prev_batch: res.prev_batch,
|
prev_batch: res.prev_batch,
|
||||||
})
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}`
|
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}/{relType}`
|
||||||
pub(crate) async fn get_relating_events_with_rel_type_route(
|
pub(crate) async fn get_relating_events_with_rel_type_route(
|
||||||
body: Ruma<get_relating_events_with_rel_type::v1::Request>,
|
body: Ruma<get_relating_events_with_rel_type::v1::Request>,
|
||||||
) -> Result<get_relating_events_with_rel_type::v1::Response> {
|
) -> Result<RumaResponse<get_relating_events_with_rel_type::v1::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let from = match body.from.clone() {
|
let from = match body.from.clone() {
|
||||||
|
|
@ -87,17 +95,17 @@ pub(crate) async fn get_relating_events_with_rel_type_route(
|
||||||
limit,
|
limit,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(get_relating_events_with_rel_type::v1::Response {
|
Ok(RumaResponse(get_relating_events_with_rel_type::v1::Response {
|
||||||
chunk: res.chunk,
|
chunk: res.chunk,
|
||||||
next_batch: res.next_batch,
|
next_batch: res.next_batch,
|
||||||
prev_batch: res.prev_batch,
|
prev_batch: res.prev_batch,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}`
|
/// # `GET /_matrix/client/r0/rooms/{roomId}/relations/{eventId}`
|
||||||
pub(crate) async fn get_relating_events_route(
|
pub(crate) async fn get_relating_events_route(
|
||||||
body: Ruma<get_relating_events::v1::Request>,
|
body: Ruma<get_relating_events::v1::Request>,
|
||||||
) -> Result<get_relating_events::v1::Response> {
|
) -> Result<RumaResponse<get_relating_events::v1::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let from = match body.from.clone() {
|
let from = match body.from.clone() {
|
||||||
|
|
@ -119,7 +127,10 @@ pub(crate) async fn get_relating_events_route(
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("0-100 should fit in usize");
|
.expect("0-100 should fit in usize");
|
||||||
|
|
||||||
services().rooms.pdu_metadata.paginate_relations_with_filter(
|
services()
|
||||||
|
.rooms
|
||||||
|
.pdu_metadata
|
||||||
|
.paginate_relations_with_filter(
|
||||||
sender_user,
|
sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&body.event_id,
|
&body.event_id,
|
||||||
|
|
@ -129,4 +140,5 @@ pub(crate) async fn get_relating_events_route(
|
||||||
to,
|
to,
|
||||||
limit,
|
limit,
|
||||||
)
|
)
|
||||||
|
.map(RumaResponse)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,14 @@ use ruma::{
|
||||||
int,
|
int,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{services, Error, Result, Ruma};
|
use crate::{services, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/report/{eventId}`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/report/{eventId}`
|
||||||
///
|
///
|
||||||
/// Reports an inappropriate event to homeserver admins
|
/// Reports an inappropriate event to homeserver admins
|
||||||
pub(crate) async fn report_event_route(
|
pub(crate) async fn report_event_route(
|
||||||
body: Ruma<report_content::v3::Request>,
|
body: Ruma<report_content::v3::Request>,
|
||||||
) -> Result<report_content::v3::Response> {
|
) -> Result<RumaResponse<report_content::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let Some(pdu) = services().rooms.timeline.get_pdu(&body.event_id)? else {
|
let Some(pdu) = services().rooms.timeline.get_pdu(&body.event_id)? else {
|
||||||
|
|
@ -91,5 +91,5 @@ pub(crate) async fn report_event_route(
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
Ok(report_content::v3::Response {})
|
Ok(RumaResponse(report_content::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ use tracing::{info, warn};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::client_server::invite_helper, service::pdu::PduBuilder, services,
|
api::client_server::invite_helper, service::pdu::PduBuilder, services,
|
||||||
Error, Result, Ruma,
|
Error, Result, Ruma, RumaResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/createRoom`
|
/// # `POST /_matrix/client/r0/createRoom`
|
||||||
|
|
@ -53,7 +53,7 @@ use crate::{
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub(crate) async fn create_room_route(
|
pub(crate) async fn create_room_route(
|
||||||
body: Ruma<create_room::v3::Request>,
|
body: Ruma<create_room::v3::Request>,
|
||||||
) -> Result<create_room::v3::Response> {
|
) -> Result<RumaResponse<create_room::v3::Response>> {
|
||||||
use create_room::v3::RoomPreset;
|
use create_room::v3::RoomPreset;
|
||||||
|
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
@ -538,7 +538,7 @@ pub(crate) async fn create_room_route(
|
||||||
|
|
||||||
info!("{} created a room", sender_user);
|
info!("{} created a room", sender_user);
|
||||||
|
|
||||||
Ok(create_room::v3::Response::new(room_id))
|
Ok(RumaResponse(create_room::v3::Response::new(room_id)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomId}/event/{eventId}`
|
/// # `GET /_matrix/client/r0/rooms/{roomId}/event/{eventId}`
|
||||||
|
|
@ -549,7 +549,7 @@ pub(crate) async fn create_room_route(
|
||||||
/// visibility)
|
/// visibility)
|
||||||
pub(crate) async fn get_room_event_route(
|
pub(crate) async fn get_room_event_route(
|
||||||
body: Ruma<get_room_event::v3::Request>,
|
body: Ruma<get_room_event::v3::Request>,
|
||||||
) -> Result<get_room_event::v3::Response> {
|
) -> Result<RumaResponse<get_room_event::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let event = services().rooms.timeline.get_pdu(&body.event_id)?.ok_or_else(
|
let event = services().rooms.timeline.get_pdu(&body.event_id)?.ok_or_else(
|
||||||
|
|
@ -573,9 +573,9 @@ pub(crate) async fn get_room_event_route(
|
||||||
let mut event = (*event).clone();
|
let mut event = (*event).clone();
|
||||||
event.add_age()?;
|
event.add_age()?;
|
||||||
|
|
||||||
Ok(get_room_event::v3::Response {
|
Ok(RumaResponse(get_room_event::v3::Response {
|
||||||
event: event.to_room_event(),
|
event: event.to_room_event(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomId}/aliases`
|
/// # `GET /_matrix/client/r0/rooms/{roomId}/aliases`
|
||||||
|
|
@ -586,7 +586,7 @@ pub(crate) async fn get_room_event_route(
|
||||||
/// user to call it if `history_visibility` is world readable
|
/// user to call it if `history_visibility` is world readable
|
||||||
pub(crate) async fn get_room_aliases_route(
|
pub(crate) async fn get_room_aliases_route(
|
||||||
body: Ruma<aliases::v3::Request>,
|
body: Ruma<aliases::v3::Request>,
|
||||||
) -> Result<aliases::v3::Response> {
|
) -> Result<RumaResponse<aliases::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if !services().rooms.state_cache.is_joined(sender_user, &body.room_id)? {
|
if !services().rooms.state_cache.is_joined(sender_user, &body.room_id)? {
|
||||||
|
|
@ -596,14 +596,14 @@ pub(crate) async fn get_room_aliases_route(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(aliases::v3::Response {
|
Ok(RumaResponse(aliases::v3::Response {
|
||||||
aliases: services()
|
aliases: services()
|
||||||
.rooms
|
.rooms
|
||||||
.alias
|
.alias
|
||||||
.local_aliases_for_room(&body.room_id)
|
.local_aliases_for_room(&body.room_id)
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
.collect(),
|
.collect(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/upgrade`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/upgrade`
|
||||||
|
|
@ -619,7 +619,7 @@ pub(crate) async fn get_room_aliases_route(
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub(crate) async fn upgrade_room_route(
|
pub(crate) async fn upgrade_room_route(
|
||||||
body: Ruma<upgrade_room::v3::Request>,
|
body: Ruma<upgrade_room::v3::Request>,
|
||||||
) -> Result<upgrade_room::v3::Response> {
|
) -> Result<RumaResponse<upgrade_room::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if !services().globals.supported_room_versions().contains(&body.new_version)
|
if !services().globals.supported_room_versions().contains(&body.new_version)
|
||||||
|
|
@ -914,7 +914,7 @@ pub(crate) async fn upgrade_room_route(
|
||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
|
|
||||||
// Return the replacement room id
|
// Return the replacement room id
|
||||||
Ok(upgrade_room::v3::Response {
|
Ok(RumaResponse(upgrade_room::v3::Response {
|
||||||
replacement_room,
|
replacement_room,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use ruma::{
|
||||||
uint,
|
uint,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{services, Error, Result, Ruma};
|
use crate::{services, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/search`
|
/// # `POST /_matrix/client/r0/search`
|
||||||
///
|
///
|
||||||
|
|
@ -25,7 +25,7 @@ use crate::{services, Error, Result, Ruma};
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub(crate) async fn search_events_route(
|
pub(crate) async fn search_events_route(
|
||||||
body: Ruma<search_events::v3::Request>,
|
body: Ruma<search_events::v3::Request>,
|
||||||
) -> Result<search_events::v3::Response> {
|
) -> Result<RumaResponse<search_events::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let search_criteria = body.search_categories.room_events.as_ref().unwrap();
|
let search_criteria = body.search_categories.room_events.as_ref().unwrap();
|
||||||
|
|
@ -136,7 +136,7 @@ pub(crate) async fn search_events_route(
|
||||||
Some((skip + limit).to_string())
|
Some((skip + limit).to_string())
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(search_events::v3::Response::new(ResultCategories {
|
Ok(RumaResponse(search_events::v3::Response::new(ResultCategories {
|
||||||
room_events: ResultRoomEvents {
|
room_events: ResultRoomEvents {
|
||||||
count: None,
|
count: None,
|
||||||
// TODO
|
// TODO
|
||||||
|
|
@ -151,5 +151,5 @@ pub(crate) async fn search_events_route(
|
||||||
.map(str::to_lowercase)
|
.map(str::to_lowercase)
|
||||||
.collect(),
|
.collect(),
|
||||||
},
|
},
|
||||||
}))
|
})))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ use serde::Deserialize;
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
use super::{DEVICE_ID_LENGTH, TOKEN_LENGTH};
|
use super::{DEVICE_ID_LENGTH, TOKEN_LENGTH};
|
||||||
use crate::{services, utils, Error, Result, Ruma};
|
use crate::{services, utils, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct Claims {
|
struct Claims {
|
||||||
|
|
@ -29,13 +29,13 @@ struct Claims {
|
||||||
/// the `type` field when logging in.
|
/// the `type` field when logging in.
|
||||||
pub(crate) async fn get_login_types_route(
|
pub(crate) async fn get_login_types_route(
|
||||||
_body: Ruma<get_login_types::v3::Request>,
|
_body: Ruma<get_login_types::v3::Request>,
|
||||||
) -> Result<get_login_types::v3::Response> {
|
) -> Result<RumaResponse<get_login_types::v3::Response>> {
|
||||||
Ok(get_login_types::v3::Response::new(vec![
|
Ok(RumaResponse(get_login_types::v3::Response::new(vec![
|
||||||
get_login_types::v3::LoginType::Password(PasswordLoginType::default()),
|
get_login_types::v3::LoginType::Password(PasswordLoginType::default()),
|
||||||
get_login_types::v3::LoginType::ApplicationService(
|
get_login_types::v3::LoginType::ApplicationService(
|
||||||
ApplicationServiceLoginType::default(),
|
ApplicationServiceLoginType::default(),
|
||||||
),
|
),
|
||||||
]))
|
])))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/login`
|
/// # `POST /_matrix/client/r0/login`
|
||||||
|
|
@ -54,7 +54,7 @@ pub(crate) async fn get_login_types_route(
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub(crate) async fn login_route(
|
pub(crate) async fn login_route(
|
||||||
body: Ruma<login::v3::Request>,
|
body: Ruma<login::v3::Request>,
|
||||||
) -> Result<login::v3::Response> {
|
) -> Result<RumaResponse<login::v3::Response>> {
|
||||||
// To allow deprecated login methods
|
// To allow deprecated login methods
|
||||||
#![allow(deprecated)]
|
#![allow(deprecated)]
|
||||||
// Validate login method
|
// Validate login method
|
||||||
|
|
@ -256,7 +256,7 @@ pub(crate) async fn login_route(
|
||||||
|
|
||||||
// Homeservers are still required to send the `home_server` field
|
// Homeservers are still required to send the `home_server` field
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
Ok(login::v3::Response {
|
Ok(RumaResponse(login::v3::Response {
|
||||||
user_id,
|
user_id,
|
||||||
access_token: token,
|
access_token: token,
|
||||||
home_server: Some(services().globals.server_name().to_owned()),
|
home_server: Some(services().globals.server_name().to_owned()),
|
||||||
|
|
@ -264,7 +264,7 @@ pub(crate) async fn login_route(
|
||||||
well_known: None,
|
well_known: None,
|
||||||
refresh_token: None,
|
refresh_token: None,
|
||||||
expires_in: None,
|
expires_in: None,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/logout`
|
/// # `POST /_matrix/client/r0/logout`
|
||||||
|
|
@ -278,7 +278,7 @@ pub(crate) async fn login_route(
|
||||||
/// - Triggers device list updates
|
/// - Triggers device list updates
|
||||||
pub(crate) async fn logout_route(
|
pub(crate) async fn logout_route(
|
||||||
body: Ruma<logout::v3::Request>,
|
body: Ruma<logout::v3::Request>,
|
||||||
) -> Result<logout::v3::Response> {
|
) -> Result<RumaResponse<logout::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let sender_device =
|
let sender_device =
|
||||||
body.sender_device.as_ref().expect("user is authenticated");
|
body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
@ -294,7 +294,7 @@ pub(crate) async fn logout_route(
|
||||||
|
|
||||||
services().users.remove_device(sender_user, sender_device)?;
|
services().users.remove_device(sender_user, sender_device)?;
|
||||||
|
|
||||||
Ok(logout::v3::Response::new())
|
Ok(RumaResponse(logout::v3::Response::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/logout/all`
|
/// # `POST /_matrix/client/r0/logout/all`
|
||||||
|
|
@ -311,7 +311,7 @@ pub(crate) async fn logout_route(
|
||||||
/// /_matrix/client/r0/logout`](logout_route) from each device of this user.
|
/// /_matrix/client/r0/logout`](logout_route) from each device of this user.
|
||||||
pub(crate) async fn logout_all_route(
|
pub(crate) async fn logout_all_route(
|
||||||
body: Ruma<logout_all::v3::Request>,
|
body: Ruma<logout_all::v3::Request>,
|
||||||
) -> Result<logout_all::v3::Response> {
|
) -> Result<RumaResponse<logout_all::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if let Some(info) = &body.appservice_info {
|
if let Some(info) = &body.appservice_info {
|
||||||
|
|
@ -332,5 +332,5 @@ pub(crate) async fn logout_all_route(
|
||||||
services().users.remove_device(sender_user, &device_id)?;
|
services().users.remove_device(sender_user, &device_id)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(logout_all::v3::Response::new())
|
Ok(RumaResponse(logout_all::v3::Response::new()))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use ruma::{api::client::space::get_hierarchy, uint};
|
use ruma::{api::client::space::get_hierarchy, uint};
|
||||||
|
|
||||||
use crate::{services, Result, Ruma};
|
use crate::{services, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `GET /_matrix/client/v1/rooms/{room_id}/hierarchy`
|
/// # `GET /_matrix/client/v1/rooms/{room_id}/hierarchy`
|
||||||
///
|
///
|
||||||
|
|
@ -8,7 +8,7 @@ use crate::{services, Result, Ruma};
|
||||||
/// of a given space.
|
/// of a given space.
|
||||||
pub(crate) async fn get_hierarchy_route(
|
pub(crate) async fn get_hierarchy_route(
|
||||||
body: Ruma<get_hierarchy::v1::Request>,
|
body: Ruma<get_hierarchy::v1::Request>,
|
||||||
) -> Result<get_hierarchy::v1::Response> {
|
) -> Result<RumaResponse<get_hierarchy::v1::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let skip =
|
let skip =
|
||||||
|
|
@ -40,4 +40,5 @@ pub(crate) async fn get_hierarchy_route(
|
||||||
body.suggested_only,
|
body.suggested_only,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
.map(RumaResponse)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ use crate::{
|
||||||
/// - If event is new `canonical_alias`: Rejects if alias is incorrect
|
/// - If event is new `canonical_alias`: Rejects if alias is incorrect
|
||||||
pub(crate) async fn send_state_event_for_key_route(
|
pub(crate) async fn send_state_event_for_key_route(
|
||||||
body: Ruma<send_state_event::v3::Request>,
|
body: Ruma<send_state_event::v3::Request>,
|
||||||
) -> Result<send_state_event::v3::Response> {
|
) -> Result<RumaResponse<send_state_event::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let event_id = send_state_event_for_key_helper(
|
let event_id = send_state_event_for_key_helper(
|
||||||
|
|
@ -42,9 +42,9 @@ pub(crate) async fn send_state_event_for_key_route(
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let event_id = (*event_id).to_owned();
|
let event_id = (*event_id).to_owned();
|
||||||
Ok(send_state_event::v3::Response {
|
Ok(RumaResponse(send_state_event::v3::Response {
|
||||||
event_id,
|
event_id,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}`
|
/// # `PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}`
|
||||||
|
|
@ -94,7 +94,7 @@ pub(crate) async fn send_state_event_for_empty_key_route(
|
||||||
/// readable
|
/// readable
|
||||||
pub(crate) async fn get_state_events_route(
|
pub(crate) async fn get_state_events_route(
|
||||||
body: Ruma<get_state_events::v3::Request>,
|
body: Ruma<get_state_events::v3::Request>,
|
||||||
) -> Result<get_state_events::v3::Response> {
|
) -> Result<RumaResponse<get_state_events::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if !services()
|
if !services()
|
||||||
|
|
@ -108,7 +108,7 @@ pub(crate) async fn get_state_events_route(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_state_events::v3::Response {
|
Ok(RumaResponse(get_state_events::v3::Response {
|
||||||
room_state: services()
|
room_state: services()
|
||||||
.rooms
|
.rooms
|
||||||
.state_accessor
|
.state_accessor
|
||||||
|
|
@ -117,7 +117,7 @@ pub(crate) async fn get_state_events_route(
|
||||||
.values()
|
.values()
|
||||||
.map(|pdu| pdu.to_state_event())
|
.map(|pdu| pdu.to_state_event())
|
||||||
.collect(),
|
.collect(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomid}/state/{eventType}/{stateKey}`
|
/// # `GET /_matrix/client/r0/rooms/{roomid}/state/{eventType}/{stateKey}`
|
||||||
|
|
@ -128,7 +128,7 @@ pub(crate) async fn get_state_events_route(
|
||||||
/// readable
|
/// readable
|
||||||
pub(crate) async fn get_state_events_for_key_route(
|
pub(crate) async fn get_state_events_for_key_route(
|
||||||
body: Ruma<get_state_events_for_key::v3::Request>,
|
body: Ruma<get_state_events_for_key::v3::Request>,
|
||||||
) -> Result<get_state_events_for_key::v3::Response> {
|
) -> Result<RumaResponse<get_state_events_for_key::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if !services()
|
if !services()
|
||||||
|
|
@ -154,11 +154,11 @@ pub(crate) async fn get_state_events_for_key_route(
|
||||||
Error::BadRequest(ErrorKind::NotFound, "State event not found.")
|
Error::BadRequest(ErrorKind::NotFound, "State event not found.")
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(get_state_events_for_key::v3::Response {
|
Ok(RumaResponse(get_state_events_for_key::v3::Response {
|
||||||
content: serde_json::from_str(event.content.get()).map_err(|_| {
|
content: serde_json::from_str(event.content.get()).map_err(|_| {
|
||||||
Error::bad_database("Invalid event content in database")
|
Error::bad_database("Invalid event content in database")
|
||||||
})?,
|
})?,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomid}/state/{eventType}`
|
/// # `GET /_matrix/client/r0/rooms/{roomid}/state/{eventType}`
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,8 @@ use crate::{
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub(crate) async fn sync_events_route(
|
pub(crate) async fn sync_events_route(
|
||||||
body: Ruma<sync_events::v3::Request>,
|
body: Ruma<sync_events::v3::Request>,
|
||||||
) -> Result<sync_events::v3::Response, RumaResponse<UiaaResponse>> {
|
) -> Result<RumaResponse<sync_events::v3::Response>, RumaResponse<UiaaResponse>>
|
||||||
|
{
|
||||||
let sender_user = body.sender_user.expect("user is authenticated");
|
let sender_user = body.sender_user.expect("user is authenticated");
|
||||||
let sender_device = body.sender_device.expect("user is authenticated");
|
let sender_device = body.sender_device.expect("user is authenticated");
|
||||||
let body = body.body;
|
let body = body.body;
|
||||||
|
|
@ -457,10 +458,10 @@ pub(crate) async fn sync_events_route(
|
||||||
Ok(x) => x.expect("watcher should succeed"),
|
Ok(x) => x.expect("watcher should succeed"),
|
||||||
Err(error) => debug!(%error, "timed out"),
|
Err(error) => debug!(%error, "timed out"),
|
||||||
};
|
};
|
||||||
Ok(response)
|
Ok(RumaResponse(response))
|
||||||
} else {
|
} else {
|
||||||
// Only cache if we made progress
|
// Only cache if we made progress
|
||||||
Ok(response)
|
Ok(RumaResponse(response))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1127,7 +1128,8 @@ fn share_encrypted_room(
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub(crate) async fn sync_events_v4_route(
|
pub(crate) async fn sync_events_v4_route(
|
||||||
body: Ruma<sync_events::v4::Request>,
|
body: Ruma<sync_events::v4::Request>,
|
||||||
) -> Result<sync_events::v4::Response, RumaResponse<UiaaResponse>> {
|
) -> Result<RumaResponse<sync_events::v4::Response>, RumaResponse<UiaaResponse>>
|
||||||
|
{
|
||||||
let sender_user = body.sender_user.expect("user is authenticated");
|
let sender_user = body.sender_user.expect("user is authenticated");
|
||||||
let sender_device = body.sender_device.expect("user is authenticated");
|
let sender_device = body.sender_device.expect("user is authenticated");
|
||||||
let mut body = body.body;
|
let mut body = body.body;
|
||||||
|
|
@ -1700,7 +1702,7 @@ pub(crate) async fn sync_events_v4_route(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(sync_events::v4::Response {
|
Ok(RumaResponse(sync_events::v4::Response {
|
||||||
initial: globalsince == 0,
|
initial: globalsince == 0,
|
||||||
txn_id: body.txn_id.clone(),
|
txn_id: body.txn_id.clone(),
|
||||||
pos: next_batch.to_string(),
|
pos: next_batch.to_string(),
|
||||||
|
|
@ -1763,5 +1765,5 @@ pub(crate) async fn sync_events_v4_route(
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
delta_token: None,
|
delta_token: None,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use ruma::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{services, Error, Result, Ruma};
|
use crate::{services, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}`
|
/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}`
|
||||||
///
|
///
|
||||||
|
|
@ -17,7 +17,7 @@ use crate::{services, Error, Result, Ruma};
|
||||||
/// - Inserts the tag into the tag event of the room account data.
|
/// - Inserts the tag into the tag event of the room account data.
|
||||||
pub(crate) async fn update_tag_route(
|
pub(crate) async fn update_tag_route(
|
||||||
body: Ruma<create_tag::v3::Request>,
|
body: Ruma<create_tag::v3::Request>,
|
||||||
) -> Result<create_tag::v3::Response> {
|
) -> Result<RumaResponse<create_tag::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let event = services().account_data.get(
|
let event = services().account_data.get(
|
||||||
|
|
@ -53,7 +53,7 @@ pub(crate) async fn update_tag_route(
|
||||||
&serde_json::to_value(tags_event).expect("to json value always works"),
|
&serde_json::to_value(tags_event).expect("to json value always works"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(create_tag::v3::Response {})
|
Ok(RumaResponse(create_tag::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}`
|
/// # `DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}`
|
||||||
|
|
@ -63,7 +63,7 @@ pub(crate) async fn update_tag_route(
|
||||||
/// - Removes the tag from the tag event of the room account data.
|
/// - Removes the tag from the tag event of the room account data.
|
||||||
pub(crate) async fn delete_tag_route(
|
pub(crate) async fn delete_tag_route(
|
||||||
body: Ruma<delete_tag::v3::Request>,
|
body: Ruma<delete_tag::v3::Request>,
|
||||||
) -> Result<delete_tag::v3::Response> {
|
) -> Result<RumaResponse<delete_tag::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let event = services().account_data.get(
|
let event = services().account_data.get(
|
||||||
|
|
@ -96,7 +96,7 @@ pub(crate) async fn delete_tag_route(
|
||||||
&serde_json::to_value(tags_event).expect("to json value always works"),
|
&serde_json::to_value(tags_event).expect("to json value always works"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(delete_tag::v3::Response {})
|
Ok(RumaResponse(delete_tag::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags`
|
/// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags`
|
||||||
|
|
@ -106,7 +106,7 @@ pub(crate) async fn delete_tag_route(
|
||||||
/// - Gets the tag event of the room account data.
|
/// - Gets the tag event of the room account data.
|
||||||
pub(crate) async fn get_tags_route(
|
pub(crate) async fn get_tags_route(
|
||||||
body: Ruma<get_tags::v3::Request>,
|
body: Ruma<get_tags::v3::Request>,
|
||||||
) -> Result<get_tags::v3::Response> {
|
) -> Result<RumaResponse<get_tags::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let event = services().account_data.get(
|
let event = services().account_data.get(
|
||||||
|
|
@ -130,7 +130,7 @@ pub(crate) async fn get_tags_route(
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(get_tags::v3::Response {
|
Ok(RumaResponse(get_tags::v3::Response {
|
||||||
tags: tags_event.content.tags,
|
tags: tags_event.content.tags,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,16 @@ use std::collections::BTreeMap;
|
||||||
|
|
||||||
use ruma::api::client::thirdparty::get_protocols;
|
use ruma::api::client::thirdparty::get_protocols;
|
||||||
|
|
||||||
use crate::{Result, Ruma};
|
use crate::{Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/thirdparty/protocols`
|
/// # `GET /_matrix/client/r0/thirdparty/protocols`
|
||||||
///
|
///
|
||||||
/// TODO: Fetches all metadata about protocols supported by the homeserver.
|
/// TODO: Fetches all metadata about protocols supported by the homeserver.
|
||||||
pub(crate) async fn get_protocols_route(
|
pub(crate) async fn get_protocols_route(
|
||||||
_body: Ruma<get_protocols::v3::Request>,
|
_body: Ruma<get_protocols::v3::Request>,
|
||||||
) -> Result<get_protocols::v3::Response> {
|
) -> Result<RumaResponse<get_protocols::v3::Response>> {
|
||||||
// TODO
|
// TODO
|
||||||
Ok(get_protocols::v3::Response {
|
Ok(RumaResponse(get_protocols::v3::Response {
|
||||||
protocols: BTreeMap::new(),
|
protocols: BTreeMap::new(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
use ruma::api::client::{error::ErrorKind, threads::get_threads};
|
use ruma::api::client::{error::ErrorKind, threads::get_threads};
|
||||||
|
|
||||||
use crate::{services, Error, Result, Ruma};
|
use crate::{services, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomId}/threads`
|
/// # `GET /_matrix/client/r0/rooms/{roomId}/threads`
|
||||||
pub(crate) async fn get_threads_route(
|
pub(crate) async fn get_threads_route(
|
||||||
body: Ruma<get_threads::v1::Request>,
|
body: Ruma<get_threads::v1::Request>,
|
||||||
) -> Result<get_threads::v1::Response> {
|
) -> Result<RumaResponse<get_threads::v1::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
// Use limit or else 10, with maximum 100
|
// Use limit or else 10, with maximum 100
|
||||||
|
|
@ -36,11 +36,11 @@ pub(crate) async fn get_threads_route(
|
||||||
|
|
||||||
let next_batch = threads.last().map(|(count, _)| count.to_string());
|
let next_batch = threads.last().map(|(count, _)| count.to_string());
|
||||||
|
|
||||||
Ok(get_threads::v1::Response {
|
Ok(RumaResponse(get_threads::v1::Response {
|
||||||
chunk: threads
|
chunk: threads
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(_, pdu)| pdu.to_room_event())
|
.map(|(_, pdu)| pdu.to_room_event())
|
||||||
.collect(),
|
.collect(),
|
||||||
next_batch,
|
next_batch,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,14 @@ use ruma::{
|
||||||
to_device::DeviceIdOrAllDevices,
|
to_device::DeviceIdOrAllDevices,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{services, Error, Result, Ruma};
|
use crate::{services, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/sendToDevice/{eventType}/{txnId}`
|
/// # `PUT /_matrix/client/r0/sendToDevice/{eventType}/{txnId}`
|
||||||
///
|
///
|
||||||
/// Send a to-device event to a set of client devices.
|
/// Send a to-device event to a set of client devices.
|
||||||
pub(crate) async fn send_event_to_device_route(
|
pub(crate) async fn send_event_to_device_route(
|
||||||
body: Ruma<send_event_to_device::v3::Request>,
|
body: Ruma<send_event_to_device::v3::Request>,
|
||||||
) -> Result<send_event_to_device::v3::Response> {
|
) -> Result<RumaResponse<send_event_to_device::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let sender_device = body.sender_device.as_deref();
|
let sender_device = body.sender_device.as_deref();
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ pub(crate) async fn send_event_to_device_route(
|
||||||
.existing_txnid(sender_user, sender_device, &body.txn_id)?
|
.existing_txnid(sender_user, sender_device, &body.txn_id)?
|
||||||
.is_some()
|
.is_some()
|
||||||
{
|
{
|
||||||
return Ok(send_event_to_device::v3::Response {});
|
return Ok(RumaResponse(send_event_to_device::v3::Response {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (target_user_id, map) in &body.messages {
|
for (target_user_id, map) in &body.messages {
|
||||||
|
|
@ -103,5 +103,5 @@ pub(crate) async fn send_event_to_device_route(
|
||||||
&[],
|
&[],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(send_event_to_device::v3::Response {})
|
Ok(RumaResponse(send_event_to_device::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
use ruma::api::client::{error::ErrorKind, typing::create_typing_event};
|
use ruma::api::client::{error::ErrorKind, typing::create_typing_event};
|
||||||
|
|
||||||
use crate::{services, utils, Error, Result, Ruma};
|
use crate::{services, utils, Error, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}`
|
/// # `PUT /_matrix/client/r0/rooms/{roomId}/typing/{userId}`
|
||||||
///
|
///
|
||||||
/// Sets the typing state of the sender user.
|
/// Sets the typing state of the sender user.
|
||||||
pub(crate) async fn create_typing_event_route(
|
pub(crate) async fn create_typing_event_route(
|
||||||
body: Ruma<create_typing_event::v3::Request>,
|
body: Ruma<create_typing_event::v3::Request>,
|
||||||
) -> Result<create_typing_event::v3::Response> {
|
) -> Result<RumaResponse<create_typing_event::v3::Response>> {
|
||||||
use create_typing_event::v3::Typing;
|
use create_typing_event::v3::Typing;
|
||||||
|
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
@ -40,5 +40,5 @@ pub(crate) async fn create_typing_event_route(
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(create_typing_event::v3::Response {})
|
Ok(RumaResponse(create_typing_event::v3::Response {}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use std::{collections::BTreeMap, iter::FromIterator};
|
||||||
|
|
||||||
use ruma::api::client::discovery::get_supported_versions;
|
use ruma::api::client::discovery::get_supported_versions;
|
||||||
|
|
||||||
use crate::{Result, Ruma};
|
use crate::{Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `GET /_matrix/client/versions`
|
/// # `GET /_matrix/client/versions`
|
||||||
///
|
///
|
||||||
|
|
@ -18,7 +18,7 @@ use crate::{Result, Ruma};
|
||||||
/// should avoid using unstable features in their stable releases
|
/// should avoid using unstable features in their stable releases
|
||||||
pub(crate) async fn get_supported_versions_route(
|
pub(crate) async fn get_supported_versions_route(
|
||||||
_body: Ruma<get_supported_versions::Request>,
|
_body: Ruma<get_supported_versions::Request>,
|
||||||
) -> Result<get_supported_versions::Response> {
|
) -> Result<RumaResponse<get_supported_versions::Response>> {
|
||||||
let resp = get_supported_versions::Response {
|
let resp = get_supported_versions::Response {
|
||||||
versions: vec![
|
versions: vec![
|
||||||
"r0.5.0".to_owned(),
|
"r0.5.0".to_owned(),
|
||||||
|
|
@ -35,5 +35,5 @@ pub(crate) async fn get_supported_versions_route(
|
||||||
)]),
|
)]),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(resp)
|
Ok(RumaResponse(resp))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use ruma::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{services, Result, Ruma};
|
use crate::{services, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/user_directory/search`
|
/// # `POST /_matrix/client/r0/user_directory/search`
|
||||||
///
|
///
|
||||||
|
|
@ -17,7 +17,7 @@ use crate::{services, Result, Ruma};
|
||||||
/// and don't share a room with the sender
|
/// and don't share a room with the sender
|
||||||
pub(crate) async fn search_users_route(
|
pub(crate) async fn search_users_route(
|
||||||
body: Ruma<search_users::v3::Request>,
|
body: Ruma<search_users::v3::Request>,
|
||||||
) -> Result<search_users::v3::Response> {
|
) -> Result<RumaResponse<search_users::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let limit = body.limit.try_into().unwrap_or(usize::MAX);
|
let limit = body.limit.try_into().unwrap_or(usize::MAX);
|
||||||
|
|
||||||
|
|
@ -99,8 +99,8 @@ pub(crate) async fn search_users_route(
|
||||||
let results = users.by_ref().take(limit).collect();
|
let results = users.by_ref().take(limit).collect();
|
||||||
let limited = users.next().is_some();
|
let limited = users.next().is_some();
|
||||||
|
|
||||||
Ok(search_users::v3::Response {
|
Ok(RumaResponse(search_users::v3::Response {
|
||||||
results,
|
results,
|
||||||
limited,
|
limited,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use hmac::{Hmac, Mac};
|
||||||
use ruma::{api::client::voip::get_turn_server_info, SecondsSinceUnixEpoch};
|
use ruma::{api::client::voip::get_turn_server_info, SecondsSinceUnixEpoch};
|
||||||
use sha1::Sha1;
|
use sha1::Sha1;
|
||||||
|
|
||||||
use crate::{services, Result, Ruma};
|
use crate::{services, Result, Ruma, RumaResponse};
|
||||||
|
|
||||||
type HmacSha1 = Hmac<Sha1>;
|
type HmacSha1 = Hmac<Sha1>;
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@ type HmacSha1 = Hmac<Sha1>;
|
||||||
/// TODO: Returns information about the recommended turn server.
|
/// TODO: Returns information about the recommended turn server.
|
||||||
pub(crate) async fn turn_server_route(
|
pub(crate) async fn turn_server_route(
|
||||||
body: Ruma<get_turn_server_info::v3::Request>,
|
body: Ruma<get_turn_server_info::v3::Request>,
|
||||||
) -> Result<get_turn_server_info::v3::Response> {
|
) -> Result<RumaResponse<get_turn_server_info::v3::Response>> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let turn_secret = services().globals.turn_secret().clone();
|
let turn_secret = services().globals.turn_secret().clone();
|
||||||
|
|
@ -43,10 +43,10 @@ pub(crate) async fn turn_server_route(
|
||||||
(username, password)
|
(username, password)
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_turn_server_info::v3::Response {
|
Ok(RumaResponse(get_turn_server_info::v3::Response {
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
uris: services().globals.turn_uris().to_vec(),
|
uris: services().globals.turn_uris().to_vec(),
|
||||||
ttl: Duration::from_secs(services().globals.turn_ttl()),
|
ttl: Duration::from_secs(services().globals.turn_ttl()),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ use tracing::{debug, error, warn};
|
||||||
use crate::{
|
use crate::{
|
||||||
api::client_server::{self, claim_keys_helper, get_keys_helper},
|
api::client_server::{self, claim_keys_helper, get_keys_helper},
|
||||||
service::pdu::{gen_event_id_canonical_json, PduBuilder},
|
service::pdu::{gen_event_id_canonical_json, PduBuilder},
|
||||||
services, utils, Error, PduEvent, Result, Ruma,
|
services, utils, Error, PduEvent, Result, Ruma, RumaResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Wraps either an literal IP address plus port, or a hostname plus complement
|
/// Wraps either an literal IP address plus port, or a hostname plus complement
|
||||||
|
|
@ -554,13 +554,13 @@ async fn request_well_known(destination: &str) -> Option<String> {
|
||||||
/// Get version information on this server.
|
/// Get version information on this server.
|
||||||
pub(crate) async fn get_server_version_route(
|
pub(crate) async fn get_server_version_route(
|
||||||
_body: Ruma<get_server_version::v1::Request>,
|
_body: Ruma<get_server_version::v1::Request>,
|
||||||
) -> Result<get_server_version::v1::Response> {
|
) -> Result<RumaResponse<get_server_version::v1::Response>> {
|
||||||
Ok(get_server_version::v1::Response {
|
Ok(RumaResponse(get_server_version::v1::Response {
|
||||||
server: Some(get_server_version::v1::Server {
|
server: Some(get_server_version::v1::Server {
|
||||||
name: Some(env!("CARGO_PKG_NAME").to_owned()),
|
name: Some(env!("CARGO_PKG_NAME").to_owned()),
|
||||||
version: Some(crate::version()),
|
version: Some(crate::version()),
|
||||||
}),
|
}),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/key/v2/server`
|
/// # `GET /_matrix/key/v2/server`
|
||||||
|
|
@ -631,7 +631,7 @@ pub(crate) async fn get_server_keys_deprecated_route() -> impl IntoResponse {
|
||||||
/// Lists the public rooms on this server.
|
/// Lists the public rooms on this server.
|
||||||
pub(crate) async fn get_public_rooms_filtered_route(
|
pub(crate) async fn get_public_rooms_filtered_route(
|
||||||
body: Ruma<get_public_rooms_filtered::v1::Request>,
|
body: Ruma<get_public_rooms_filtered::v1::Request>,
|
||||||
) -> Result<get_public_rooms_filtered::v1::Response> {
|
) -> Result<RumaResponse<get_public_rooms_filtered::v1::Response>> {
|
||||||
let response = client_server::get_public_rooms_filtered_helper(
|
let response = client_server::get_public_rooms_filtered_helper(
|
||||||
None,
|
None,
|
||||||
body.limit,
|
body.limit,
|
||||||
|
|
@ -641,12 +641,12 @@ pub(crate) async fn get_public_rooms_filtered_route(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(get_public_rooms_filtered::v1::Response {
|
Ok(RumaResponse(get_public_rooms_filtered::v1::Response {
|
||||||
chunk: response.chunk,
|
chunk: response.chunk,
|
||||||
prev_batch: response.prev_batch,
|
prev_batch: response.prev_batch,
|
||||||
next_batch: response.next_batch,
|
next_batch: response.next_batch,
|
||||||
total_room_count_estimate: response.total_room_count_estimate,
|
total_room_count_estimate: response.total_room_count_estimate,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/publicRooms`
|
/// # `GET /_matrix/federation/v1/publicRooms`
|
||||||
|
|
@ -654,7 +654,7 @@ pub(crate) async fn get_public_rooms_filtered_route(
|
||||||
/// Lists the public rooms on this server.
|
/// Lists the public rooms on this server.
|
||||||
pub(crate) async fn get_public_rooms_route(
|
pub(crate) async fn get_public_rooms_route(
|
||||||
body: Ruma<get_public_rooms::v1::Request>,
|
body: Ruma<get_public_rooms::v1::Request>,
|
||||||
) -> Result<get_public_rooms::v1::Response> {
|
) -> Result<RumaResponse<get_public_rooms::v1::Response>> {
|
||||||
let response = client_server::get_public_rooms_filtered_helper(
|
let response = client_server::get_public_rooms_filtered_helper(
|
||||||
None,
|
None,
|
||||||
body.limit,
|
body.limit,
|
||||||
|
|
@ -664,12 +664,12 @@ pub(crate) async fn get_public_rooms_route(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(get_public_rooms::v1::Response {
|
Ok(RumaResponse(get_public_rooms::v1::Response {
|
||||||
chunk: response.chunk,
|
chunk: response.chunk,
|
||||||
prev_batch: response.prev_batch,
|
prev_batch: response.prev_batch,
|
||||||
next_batch: response.next_batch,
|
next_batch: response.next_batch,
|
||||||
total_room_count_estimate: response.total_room_count_estimate,
|
total_room_count_estimate: response.total_room_count_estimate,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_incoming_pdu(
|
pub(crate) fn parse_incoming_pdu(
|
||||||
|
|
@ -709,7 +709,7 @@ pub(crate) fn parse_incoming_pdu(
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub(crate) async fn send_transaction_message_route(
|
pub(crate) async fn send_transaction_message_route(
|
||||||
body: Ruma<send_transaction_message::v1::Request>,
|
body: Ruma<send_transaction_message::v1::Request>,
|
||||||
) -> Result<send_transaction_message::v1::Response> {
|
) -> Result<RumaResponse<send_transaction_message::v1::Response>> {
|
||||||
let sender_servername =
|
let sender_servername =
|
||||||
body.sender_servername.as_ref().expect("server is authenticated");
|
body.sender_servername.as_ref().expect("server is authenticated");
|
||||||
|
|
||||||
|
|
@ -976,12 +976,12 @@ pub(crate) async fn send_transaction_message_route(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(send_transaction_message::v1::Response {
|
Ok(RumaResponse(send_transaction_message::v1::Response {
|
||||||
pdus: resolved_map
|
pdus: resolved_map
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(e, r)| (e, r.map_err(|e| e.sanitized_error())))
|
.map(|(e, r)| (e, r.map_err(|e| e.sanitized_error())))
|
||||||
.collect(),
|
.collect(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/event/{eventId}`
|
/// # `GET /_matrix/federation/v1/event/{eventId}`
|
||||||
|
|
@ -992,7 +992,7 @@ pub(crate) async fn send_transaction_message_route(
|
||||||
/// room
|
/// room
|
||||||
pub(crate) async fn get_event_route(
|
pub(crate) async fn get_event_route(
|
||||||
body: Ruma<get_event::v1::Request>,
|
body: Ruma<get_event::v1::Request>,
|
||||||
) -> Result<get_event::v1::Response> {
|
) -> Result<RumaResponse<get_event::v1::Response>> {
|
||||||
let sender_servername =
|
let sender_servername =
|
||||||
body.sender_servername.as_ref().expect("server is authenticated");
|
body.sender_servername.as_ref().expect("server is authenticated");
|
||||||
|
|
||||||
|
|
@ -1035,11 +1035,11 @@ pub(crate) async fn get_event_route(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_event::v1::Response {
|
Ok(RumaResponse(get_event::v1::Response {
|
||||||
origin: services().globals.server_name().to_owned(),
|
origin: services().globals.server_name().to_owned(),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
||||||
pdu: PduEvent::convert_to_outgoing_federation_event(event),
|
pdu: PduEvent::convert_to_outgoing_federation_event(event),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/backfill/<room_id>`
|
/// # `GET /_matrix/federation/v1/backfill/<room_id>`
|
||||||
|
|
@ -1048,7 +1048,7 @@ pub(crate) async fn get_event_route(
|
||||||
/// history visibility allows.
|
/// history visibility allows.
|
||||||
pub(crate) async fn get_backfill_route(
|
pub(crate) async fn get_backfill_route(
|
||||||
body: Ruma<get_backfill::v1::Request>,
|
body: Ruma<get_backfill::v1::Request>,
|
||||||
) -> Result<get_backfill::v1::Response> {
|
) -> Result<RumaResponse<get_backfill::v1::Response>> {
|
||||||
let sender_servername =
|
let sender_servername =
|
||||||
body.sender_servername.as_ref().expect("server is authenticated");
|
body.sender_servername.as_ref().expect("server is authenticated");
|
||||||
|
|
||||||
|
|
@ -1106,11 +1106,11 @@ pub(crate) async fn get_backfill_route(
|
||||||
.map(PduEvent::convert_to_outgoing_federation_event)
|
.map(PduEvent::convert_to_outgoing_federation_event)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(get_backfill::v1::Response {
|
Ok(RumaResponse(get_backfill::v1::Response {
|
||||||
origin: services().globals.server_name().to_owned(),
|
origin: services().globals.server_name().to_owned(),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
||||||
pdus: events,
|
pdus: events,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/federation/v1/get_missing_events/{roomId}`
|
/// # `POST /_matrix/federation/v1/get_missing_events/{roomId}`
|
||||||
|
|
@ -1118,7 +1118,7 @@ pub(crate) async fn get_backfill_route(
|
||||||
/// Retrieves events that the sender is missing.
|
/// Retrieves events that the sender is missing.
|
||||||
pub(crate) async fn get_missing_events_route(
|
pub(crate) async fn get_missing_events_route(
|
||||||
body: Ruma<get_missing_events::v1::Request>,
|
body: Ruma<get_missing_events::v1::Request>,
|
||||||
) -> Result<get_missing_events::v1::Response> {
|
) -> Result<RumaResponse<get_missing_events::v1::Response>> {
|
||||||
let sender_servername =
|
let sender_servername =
|
||||||
body.sender_servername.as_ref().expect("server is authenticated");
|
body.sender_servername.as_ref().expect("server is authenticated");
|
||||||
|
|
||||||
|
|
@ -1208,9 +1208,9 @@ pub(crate) async fn get_missing_events_route(
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_missing_events::v1::Response {
|
Ok(RumaResponse(get_missing_events::v1::Response {
|
||||||
events,
|
events,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/event_auth/{roomId}/{eventId}`
|
/// # `GET /_matrix/federation/v1/event_auth/{roomId}/{eventId}`
|
||||||
|
|
@ -1220,7 +1220,7 @@ pub(crate) async fn get_missing_events_route(
|
||||||
/// - This does not include the event itself
|
/// - This does not include the event itself
|
||||||
pub(crate) async fn get_event_authorization_route(
|
pub(crate) async fn get_event_authorization_route(
|
||||||
body: Ruma<get_event_authorization::v1::Request>,
|
body: Ruma<get_event_authorization::v1::Request>,
|
||||||
) -> Result<get_event_authorization::v1::Response> {
|
) -> Result<RumaResponse<get_event_authorization::v1::Response>> {
|
||||||
let sender_servername =
|
let sender_servername =
|
||||||
body.sender_servername.as_ref().expect("server is authenticated");
|
body.sender_servername.as_ref().expect("server is authenticated");
|
||||||
|
|
||||||
|
|
@ -1263,14 +1263,14 @@ pub(crate) async fn get_event_authorization_route(
|
||||||
.get_auth_chain(room_id, vec![Arc::from(&*body.event_id)])
|
.get_auth_chain(room_id, vec![Arc::from(&*body.event_id)])
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(get_event_authorization::v1::Response {
|
Ok(RumaResponse(get_event_authorization::v1::Response {
|
||||||
auth_chain: auth_chain_ids
|
auth_chain: auth_chain_ids
|
||||||
.filter_map(|id| {
|
.filter_map(|id| {
|
||||||
services().rooms.timeline.get_pdu_json(&id).ok()?
|
services().rooms.timeline.get_pdu_json(&id).ok()?
|
||||||
})
|
})
|
||||||
.map(PduEvent::convert_to_outgoing_federation_event)
|
.map(PduEvent::convert_to_outgoing_federation_event)
|
||||||
.collect(),
|
.collect(),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/state/{roomId}`
|
/// # `GET /_matrix/federation/v1/state/{roomId}`
|
||||||
|
|
@ -1278,7 +1278,7 @@ pub(crate) async fn get_event_authorization_route(
|
||||||
/// Retrieves the current state of the room.
|
/// Retrieves the current state of the room.
|
||||||
pub(crate) async fn get_room_state_route(
|
pub(crate) async fn get_room_state_route(
|
||||||
body: Ruma<get_room_state::v1::Request>,
|
body: Ruma<get_room_state::v1::Request>,
|
||||||
) -> Result<get_room_state::v1::Response> {
|
) -> Result<RumaResponse<get_room_state::v1::Response>> {
|
||||||
let sender_servername =
|
let sender_servername =
|
||||||
body.sender_servername.as_ref().expect("server is authenticated");
|
body.sender_servername.as_ref().expect("server is authenticated");
|
||||||
|
|
||||||
|
|
@ -1326,7 +1326,7 @@ pub(crate) async fn get_room_state_route(
|
||||||
.get_auth_chain(&body.room_id, vec![Arc::from(&*body.event_id)])
|
.get_auth_chain(&body.room_id, vec![Arc::from(&*body.event_id)])
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(get_room_state::v1::Response {
|
Ok(RumaResponse(get_room_state::v1::Response {
|
||||||
auth_chain: auth_chain_ids
|
auth_chain: auth_chain_ids
|
||||||
.filter_map(|id| {
|
.filter_map(|id| {
|
||||||
if let Some(json) =
|
if let Some(json) =
|
||||||
|
|
@ -1340,7 +1340,7 @@ pub(crate) async fn get_room_state_route(
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
pdus,
|
pdus,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/state_ids/{roomId}`
|
/// # `GET /_matrix/federation/v1/state_ids/{roomId}`
|
||||||
|
|
@ -1348,7 +1348,7 @@ pub(crate) async fn get_room_state_route(
|
||||||
/// Retrieves the current state of the room.
|
/// Retrieves the current state of the room.
|
||||||
pub(crate) async fn get_room_state_ids_route(
|
pub(crate) async fn get_room_state_ids_route(
|
||||||
body: Ruma<get_room_state_ids::v1::Request>,
|
body: Ruma<get_room_state_ids::v1::Request>,
|
||||||
) -> Result<get_room_state_ids::v1::Response> {
|
) -> Result<RumaResponse<get_room_state_ids::v1::Response>> {
|
||||||
let sender_servername =
|
let sender_servername =
|
||||||
body.sender_servername.as_ref().expect("server is authenticated");
|
body.sender_servername.as_ref().expect("server is authenticated");
|
||||||
|
|
||||||
|
|
@ -1392,10 +1392,10 @@ pub(crate) async fn get_room_state_ids_route(
|
||||||
.get_auth_chain(&body.room_id, vec![Arc::from(&*body.event_id)])
|
.get_auth_chain(&body.room_id, vec![Arc::from(&*body.event_id)])
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(get_room_state_ids::v1::Response {
|
Ok(RumaResponse(get_room_state_ids::v1::Response {
|
||||||
auth_chain_ids: auth_chain_ids.map(|id| (*id).to_owned()).collect(),
|
auth_chain_ids: auth_chain_ids.map(|id| (*id).to_owned()).collect(),
|
||||||
pdu_ids,
|
pdu_ids,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/make_join/{roomId}/{userId}`
|
/// # `GET /_matrix/federation/v1/make_join/{roomId}/{userId}`
|
||||||
|
|
@ -1403,7 +1403,7 @@ pub(crate) async fn get_room_state_ids_route(
|
||||||
/// Creates a join template.
|
/// Creates a join template.
|
||||||
pub(crate) async fn create_join_event_template_route(
|
pub(crate) async fn create_join_event_template_route(
|
||||||
body: Ruma<prepare_join_event::v1::Request>,
|
body: Ruma<prepare_join_event::v1::Request>,
|
||||||
) -> Result<prepare_join_event::v1::Response> {
|
) -> Result<RumaResponse<prepare_join_event::v1::Response>> {
|
||||||
if !services().rooms.metadata.exists(&body.room_id)? {
|
if !services().rooms.metadata.exists(&body.room_id)? {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::NotFound,
|
ErrorKind::NotFound,
|
||||||
|
|
@ -1504,11 +1504,11 @@ pub(crate) async fn create_join_event_template_route(
|
||||||
|
|
||||||
pdu_json.remove("event_id");
|
pdu_json.remove("event_id");
|
||||||
|
|
||||||
Ok(prepare_join_event::v1::Response {
|
Ok(RumaResponse(prepare_join_event::v1::Response {
|
||||||
room_version: Some(room_version_id),
|
room_version: Some(room_version_id),
|
||||||
event: to_raw_value(&pdu_json)
|
event: to_raw_value(&pdu_json)
|
||||||
.expect("CanonicalJson can be serialized to JSON"),
|
.expect("CanonicalJson can be serialized to JSON"),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
|
|
@ -1661,16 +1661,16 @@ async fn create_join_event(
|
||||||
/// Submits a signed join event.
|
/// Submits a signed join event.
|
||||||
pub(crate) async fn create_join_event_v1_route(
|
pub(crate) async fn create_join_event_v1_route(
|
||||||
body: Ruma<create_join_event::v1::Request>,
|
body: Ruma<create_join_event::v1::Request>,
|
||||||
) -> Result<create_join_event::v1::Response> {
|
) -> Result<RumaResponse<create_join_event::v1::Response>> {
|
||||||
let sender_servername =
|
let sender_servername =
|
||||||
body.sender_servername.as_ref().expect("server is authenticated");
|
body.sender_servername.as_ref().expect("server is authenticated");
|
||||||
|
|
||||||
let room_state =
|
let room_state =
|
||||||
create_join_event(sender_servername, &body.room_id, &body.pdu).await?;
|
create_join_event(sender_servername, &body.room_id, &body.pdu).await?;
|
||||||
|
|
||||||
Ok(create_join_event::v1::Response {
|
Ok(RumaResponse(create_join_event::v1::Response {
|
||||||
room_state,
|
room_state,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/federation/v2/send_join/{roomId}/{eventId}`
|
/// # `PUT /_matrix/federation/v2/send_join/{roomId}/{eventId}`
|
||||||
|
|
@ -1678,7 +1678,7 @@ pub(crate) async fn create_join_event_v1_route(
|
||||||
/// Submits a signed join event.
|
/// Submits a signed join event.
|
||||||
pub(crate) async fn create_join_event_v2_route(
|
pub(crate) async fn create_join_event_v2_route(
|
||||||
body: Ruma<create_join_event::v2::Request>,
|
body: Ruma<create_join_event::v2::Request>,
|
||||||
) -> Result<create_join_event::v2::Response> {
|
) -> Result<RumaResponse<create_join_event::v2::Response>> {
|
||||||
let sender_servername =
|
let sender_servername =
|
||||||
body.sender_servername.as_ref().expect("server is authenticated");
|
body.sender_servername.as_ref().expect("server is authenticated");
|
||||||
|
|
||||||
|
|
@ -1695,9 +1695,9 @@ pub(crate) async fn create_join_event_v2_route(
|
||||||
servers_in_room: None,
|
servers_in_room: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(create_join_event::v2::Response {
|
Ok(RumaResponse(create_join_event::v2::Response {
|
||||||
room_state,
|
room_state,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/federation/v2/invite/{roomId}/{eventId}`
|
/// # `PUT /_matrix/federation/v2/invite/{roomId}/{eventId}`
|
||||||
|
|
@ -1706,7 +1706,7 @@ pub(crate) async fn create_join_event_v2_route(
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub(crate) async fn create_invite_route(
|
pub(crate) async fn create_invite_route(
|
||||||
body: Ruma<create_invite::v2::Request>,
|
body: Ruma<create_invite::v2::Request>,
|
||||||
) -> Result<create_invite::v2::Response> {
|
) -> Result<RumaResponse<create_invite::v2::Response>> {
|
||||||
let sender_servername =
|
let sender_servername =
|
||||||
body.sender_servername.as_ref().expect("server is authenticated");
|
body.sender_servername.as_ref().expect("server is authenticated");
|
||||||
|
|
||||||
|
|
@ -1827,9 +1827,9 @@ pub(crate) async fn create_invite_route(
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(create_invite::v2::Response {
|
Ok(RumaResponse(create_invite::v2::Response {
|
||||||
event: PduEvent::convert_to_outgoing_federation_event(signed_event),
|
event: PduEvent::convert_to_outgoing_federation_event(signed_event),
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/user/devices/{userId}`
|
/// # `GET /_matrix/federation/v1/user/devices/{userId}`
|
||||||
|
|
@ -1837,7 +1837,7 @@ pub(crate) async fn create_invite_route(
|
||||||
/// Gets information on all devices of the user.
|
/// Gets information on all devices of the user.
|
||||||
pub(crate) async fn get_devices_route(
|
pub(crate) async fn get_devices_route(
|
||||||
body: Ruma<get_devices::v1::Request>,
|
body: Ruma<get_devices::v1::Request>,
|
||||||
) -> Result<get_devices::v1::Response> {
|
) -> Result<RumaResponse<get_devices::v1::Response>> {
|
||||||
if body.user_id.server_name() != services().globals.server_name() {
|
if body.user_id.server_name() != services().globals.server_name() {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::InvalidParam,
|
ErrorKind::InvalidParam,
|
||||||
|
|
@ -1848,7 +1848,7 @@ pub(crate) async fn get_devices_route(
|
||||||
let sender_servername =
|
let sender_servername =
|
||||||
body.sender_servername.as_ref().expect("server is authenticated");
|
body.sender_servername.as_ref().expect("server is authenticated");
|
||||||
|
|
||||||
Ok(get_devices::v1::Response {
|
Ok(RumaResponse(get_devices::v1::Response {
|
||||||
user_id: body.user_id.clone(),
|
user_id: body.user_id.clone(),
|
||||||
stream_id: services()
|
stream_id: services()
|
||||||
.users
|
.users
|
||||||
|
|
@ -1881,7 +1881,7 @@ pub(crate) async fn get_devices_route(
|
||||||
&body.user_id,
|
&body.user_id,
|
||||||
&|u| u.server_name() == sender_servername,
|
&|u| u.server_name() == sender_servername,
|
||||||
)?,
|
)?,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/query/directory`
|
/// # `GET /_matrix/federation/v1/query/directory`
|
||||||
|
|
@ -1889,16 +1889,16 @@ pub(crate) async fn get_devices_route(
|
||||||
/// Resolve a room alias to a room id.
|
/// Resolve a room alias to a room id.
|
||||||
pub(crate) async fn get_room_information_route(
|
pub(crate) async fn get_room_information_route(
|
||||||
body: Ruma<get_room_information::v1::Request>,
|
body: Ruma<get_room_information::v1::Request>,
|
||||||
) -> Result<get_room_information::v1::Response> {
|
) -> Result<RumaResponse<get_room_information::v1::Response>> {
|
||||||
let room_id =
|
let room_id =
|
||||||
services().rooms.alias.resolve_local_alias(&body.room_alias)?.ok_or(
|
services().rooms.alias.resolve_local_alias(&body.room_alias)?.ok_or(
|
||||||
Error::BadRequest(ErrorKind::NotFound, "Room alias not found."),
|
Error::BadRequest(ErrorKind::NotFound, "Room alias not found."),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(get_room_information::v1::Response {
|
Ok(RumaResponse(get_room_information::v1::Response {
|
||||||
room_id,
|
room_id,
|
||||||
servers: vec![services().globals.server_name().to_owned()],
|
servers: vec![services().globals.server_name().to_owned()],
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/query/profile`
|
/// # `GET /_matrix/federation/v1/query/profile`
|
||||||
|
|
@ -1906,7 +1906,7 @@ pub(crate) async fn get_room_information_route(
|
||||||
/// Gets information on a profile.
|
/// Gets information on a profile.
|
||||||
pub(crate) async fn get_profile_information_route(
|
pub(crate) async fn get_profile_information_route(
|
||||||
body: Ruma<get_profile_information::v1::Request>,
|
body: Ruma<get_profile_information::v1::Request>,
|
||||||
) -> Result<get_profile_information::v1::Response> {
|
) -> Result<RumaResponse<get_profile_information::v1::Response>> {
|
||||||
if body.user_id.server_name() != services().globals.server_name() {
|
if body.user_id.server_name() != services().globals.server_name() {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::InvalidParam,
|
ErrorKind::InvalidParam,
|
||||||
|
|
@ -1935,11 +1935,11 @@ pub(crate) async fn get_profile_information_route(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_profile_information::v1::Response {
|
Ok(RumaResponse(get_profile_information::v1::Response {
|
||||||
displayname,
|
displayname,
|
||||||
avatar_url,
|
avatar_url,
|
||||||
blurhash,
|
blurhash,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/federation/v1/user/keys/query`
|
/// # `POST /_matrix/federation/v1/user/keys/query`
|
||||||
|
|
@ -1947,7 +1947,7 @@ pub(crate) async fn get_profile_information_route(
|
||||||
/// Gets devices and identity keys for the given users.
|
/// Gets devices and identity keys for the given users.
|
||||||
pub(crate) async fn get_keys_route(
|
pub(crate) async fn get_keys_route(
|
||||||
body: Ruma<get_keys::v1::Request>,
|
body: Ruma<get_keys::v1::Request>,
|
||||||
) -> Result<get_keys::v1::Response> {
|
) -> Result<RumaResponse<get_keys::v1::Response>> {
|
||||||
if body
|
if body
|
||||||
.device_keys
|
.device_keys
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -1964,11 +1964,11 @@ pub(crate) async fn get_keys_route(
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(get_keys::v1::Response {
|
Ok(RumaResponse(get_keys::v1::Response {
|
||||||
device_keys: result.device_keys,
|
device_keys: result.device_keys,
|
||||||
master_keys: result.master_keys,
|
master_keys: result.master_keys,
|
||||||
self_signing_keys: result.self_signing_keys,
|
self_signing_keys: result.self_signing_keys,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/federation/v1/user/keys/claim`
|
/// # `POST /_matrix/federation/v1/user/keys/claim`
|
||||||
|
|
@ -1976,7 +1976,7 @@ pub(crate) async fn get_keys_route(
|
||||||
/// Claims one-time keys.
|
/// Claims one-time keys.
|
||||||
pub(crate) async fn claim_keys_route(
|
pub(crate) async fn claim_keys_route(
|
||||||
body: Ruma<claim_keys::v1::Request>,
|
body: Ruma<claim_keys::v1::Request>,
|
||||||
) -> Result<claim_keys::v1::Response> {
|
) -> Result<RumaResponse<claim_keys::v1::Response>> {
|
||||||
if body
|
if body
|
||||||
.one_time_keys
|
.one_time_keys
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -1990,9 +1990,9 @@ pub(crate) async fn claim_keys_route(
|
||||||
|
|
||||||
let result = claim_keys_helper(&body.one_time_keys).await?;
|
let result = claim_keys_helper(&body.one_time_keys).await?;
|
||||||
|
|
||||||
Ok(claim_keys::v1::Response {
|
Ok(RumaResponse(claim_keys::v1::Response {
|
||||||
one_time_keys: result.one_time_keys,
|
one_time_keys: result.one_time_keys,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
|
|
@ -579,11 +579,13 @@ macro_rules! impl_ruma_handler {
|
||||||
( $($ty:ident),* $(,)? ) => {
|
( $($ty:ident),* $(,)? ) => {
|
||||||
#[axum::async_trait]
|
#[axum::async_trait]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
impl<Req, E, F, Fut, $($ty,)*> RumaHandler<($($ty,)* Ruma<Req>,)> for F
|
impl<Req, Resp, E, F, Fut, $($ty,)*>
|
||||||
|
RumaHandler<($($ty,)* Ruma<Req>,)> for F
|
||||||
where
|
where
|
||||||
Req: IncomingRequest + Send + 'static,
|
Req: IncomingRequest + Send + 'static,
|
||||||
|
Resp: IntoResponse,
|
||||||
F: FnOnce($($ty,)* Ruma<Req>) -> Fut + Clone + Send + 'static,
|
F: FnOnce($($ty,)* Ruma<Req>) -> Fut + Clone + Send + 'static,
|
||||||
Fut: Future<Output = Result<Req::OutgoingResponse, E>>
|
Fut: Future<Output = Result<Resp, E>>
|
||||||
+ Send,
|
+ Send,
|
||||||
E: IntoResponse,
|
E: IntoResponse,
|
||||||
$( $ty: FromRequestParts<()> + Send + 'static, )*
|
$( $ty: FromRequestParts<()> + Send + 'static, )*
|
||||||
|
|
@ -600,7 +602,7 @@ macro_rules! impl_ruma_handler {
|
||||||
on(
|
on(
|
||||||
method_filter,
|
method_filter,
|
||||||
|$( $ty: $ty, )* req| async move {
|
|$( $ty: $ty, )* req| async move {
|
||||||
handler($($ty,)* req).await.map(RumaResponse)
|
handler($($ty,)* req).await
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue