Simplify return type of most route handlers
This commit is contained in:
parent
77a87881c9
commit
5fa9190117
38 changed files with 358 additions and 414 deletions
|
@ -4,7 +4,7 @@ use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
|
||||||
use crate::{
|
use crate::{
|
||||||
database::{admin::make_user_admin, DatabaseGuard},
|
database::{admin::make_user_admin, DatabaseGuard},
|
||||||
pdu::PduBuilder,
|
pdu::PduBuilder,
|
||||||
utils, ConduitResult, Error, Ruma,
|
utils, Error, Result, Ruma,
|
||||||
};
|
};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{
|
api::client::{
|
||||||
|
@ -44,7 +44,7 @@ const GUEST_NAME_LENGTH: usize = 10;
|
||||||
pub async fn get_register_available_route(
|
pub async fn get_register_available_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_username_availability::Request<'_>>,
|
body: Ruma<get_username_availability::Request<'_>>,
|
||||||
) -> ConduitResult<get_username_availability::Response> {
|
) -> Result<get_username_availability::Response> {
|
||||||
// Validate user id
|
// Validate user id
|
||||||
let user_id =
|
let user_id =
|
||||||
UserId::parse_with_server_name(body.username.to_lowercase(), db.globals.server_name())
|
UserId::parse_with_server_name(body.username.to_lowercase(), db.globals.server_name())
|
||||||
|
@ -68,7 +68,7 @@ pub 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::Response { available: true }.into())
|
Ok(get_username_availability::Response { available: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/register`
|
/// # `POST /_matrix/client/r0/register`
|
||||||
|
@ -88,7 +88,7 @@ pub async fn get_register_available_route(
|
||||||
pub async fn register_route(
|
pub async fn register_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<register::Request<'_>>,
|
body: Ruma<register::Request<'_>>,
|
||||||
) -> ConduitResult<register::Response> {
|
) -> Result<register::Response> {
|
||||||
if !db.globals.allow_registration() && !body.from_appservice {
|
if !db.globals.allow_registration() && !body.from_appservice {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::Forbidden,
|
ErrorKind::Forbidden,
|
||||||
|
@ -212,8 +212,7 @@ pub async fn register_route(
|
||||||
access_token: None,
|
access_token: None,
|
||||||
user_id,
|
user_id,
|
||||||
device_id: None,
|
device_id: None,
|
||||||
}
|
});
|
||||||
.into());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate new device id if the user didn't specify one
|
// Generate new device id if the user didn't specify one
|
||||||
|
@ -251,8 +250,7 @@ pub async fn register_route(
|
||||||
access_token: Some(token),
|
access_token: Some(token),
|
||||||
user_id,
|
user_id,
|
||||||
device_id: Some(device_id),
|
device_id: Some(device_id),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/account/password`
|
/// # `POST /_matrix/client/r0/account/password`
|
||||||
|
@ -273,7 +271,7 @@ pub async fn register_route(
|
||||||
pub async fn change_password_route(
|
pub async fn change_password_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<change_password::Request<'_>>,
|
body: Ruma<change_password::Request<'_>>,
|
||||||
) -> ConduitResult<change_password::Response> {
|
) -> Result<change_password::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_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
|
@ -326,7 +324,7 @@ pub async fn change_password_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(change_password::Response {}.into())
|
Ok(change_password::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET _matrix/client/r0/account/whoami`
|
/// # `GET _matrix/client/r0/account/whoami`
|
||||||
|
@ -335,12 +333,11 @@ pub async fn change_password_route(
|
||||||
///
|
///
|
||||||
/// Note: Also works for Application Services
|
/// Note: Also works for Application Services
|
||||||
#[tracing::instrument(skip(body))]
|
#[tracing::instrument(skip(body))]
|
||||||
pub async fn whoami_route(body: Ruma<whoami::Request>) -> ConduitResult<whoami::Response> {
|
pub async fn whoami_route(body: Ruma<whoami::Request>) -> Result<whoami::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(whoami::Response {
|
Ok(whoami::Response {
|
||||||
user_id: sender_user.clone(),
|
user_id: sender_user.clone(),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/account/deactivate`
|
/// # `POST /_matrix/client/r0/account/deactivate`
|
||||||
|
@ -357,7 +354,7 @@ pub async fn whoami_route(body: Ruma<whoami::Request>) -> ConduitResult<whoami::
|
||||||
pub async fn deactivate_route(
|
pub async fn deactivate_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<deactivate::Request<'_>>,
|
body: Ruma<deactivate::Request<'_>>,
|
||||||
) -> ConduitResult<deactivate::Response> {
|
) -> Result<deactivate::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_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
|
@ -452,8 +449,7 @@ pub async fn deactivate_route(
|
||||||
|
|
||||||
Ok(deactivate::Response {
|
Ok(deactivate::Response {
|
||||||
id_server_unbind_result: ThirdPartyIdRemovalStatus::NoSupport,
|
id_server_unbind_result: ThirdPartyIdRemovalStatus::NoSupport,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET _matrix/client/r0/account/3pid`
|
/// # `GET _matrix/client/r0/account/3pid`
|
||||||
|
@ -461,10 +457,8 @@ pub async fn deactivate_route(
|
||||||
/// Get a list of third party identifiers associated with this account.
|
/// Get a list of third party identifiers associated with this account.
|
||||||
///
|
///
|
||||||
/// - Currently always returns empty list
|
/// - Currently always returns empty list
|
||||||
pub async fn third_party_route(
|
pub async fn third_party_route(body: Ruma<get_3pids::Request>) -> Result<get_3pids::Response> {
|
||||||
body: Ruma<get_3pids::Request>,
|
|
||||||
) -> ConduitResult<get_3pids::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_3pids::Response::new(Vec::new()).into())
|
Ok(get_3pids::Response::new(Vec::new()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, ConduitResult, Database, Error, Ruma};
|
use crate::{database::DatabaseGuard, Database, Error, Result, Ruma};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::{
|
api::{
|
||||||
|
@ -19,7 +19,7 @@ use ruma::{
|
||||||
pub async fn create_alias_route(
|
pub async fn create_alias_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<create_alias::Request<'_>>,
|
body: Ruma<create_alias::Request<'_>>,
|
||||||
) -> ConduitResult<create_alias::Response> {
|
) -> Result<create_alias::Response> {
|
||||||
if body.room_alias.server_name() != db.globals.server_name() {
|
if body.room_alias.server_name() != db.globals.server_name() {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::InvalidParam,
|
ErrorKind::InvalidParam,
|
||||||
|
@ -36,7 +36,7 @@ pub async fn create_alias_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(create_alias::Response::new().into())
|
Ok(create_alias::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/directory/room/{roomAlias}`
|
/// # `DELETE /_matrix/client/r0/directory/room/{roomAlias}`
|
||||||
|
@ -49,7 +49,7 @@ pub async fn create_alias_route(
|
||||||
pub async fn delete_alias_route(
|
pub async fn delete_alias_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<delete_alias::Request<'_>>,
|
body: Ruma<delete_alias::Request<'_>>,
|
||||||
) -> ConduitResult<delete_alias::Response> {
|
) -> Result<delete_alias::Response> {
|
||||||
if body.room_alias.server_name() != db.globals.server_name() {
|
if body.room_alias.server_name() != db.globals.server_name() {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::InvalidParam,
|
ErrorKind::InvalidParam,
|
||||||
|
@ -63,7 +63,7 @@ pub async fn delete_alias_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(delete_alias::Response::new().into())
|
Ok(delete_alias::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/directory/room/{roomAlias}`
|
/// # `GET /_matrix/client/r0/directory/room/{roomAlias}`
|
||||||
|
@ -75,14 +75,14 @@ pub async fn delete_alias_route(
|
||||||
pub async fn get_alias_route(
|
pub async fn get_alias_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_alias::Request<'_>>,
|
body: Ruma<get_alias::Request<'_>>,
|
||||||
) -> ConduitResult<get_alias::Response> {
|
) -> Result<get_alias::Response> {
|
||||||
get_alias_helper(&db, &body.room_alias).await
|
get_alias_helper(&db, &body.room_alias).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_alias_helper(
|
pub(crate) async fn get_alias_helper(
|
||||||
db: &Database,
|
db: &Database,
|
||||||
room_alias: &RoomAliasId,
|
room_alias: &RoomAliasId,
|
||||||
) -> ConduitResult<get_alias::Response> {
|
) -> Result<get_alias::Response> {
|
||||||
if room_alias.server_name() != db.globals.server_name() {
|
if room_alias.server_name() != db.globals.server_name() {
|
||||||
let response = db
|
let response = db
|
||||||
.sending
|
.sending
|
||||||
|
@ -93,7 +93,7 @@ pub(crate) async fn get_alias_helper(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Ok(get_alias::Response::new(response.room_id, response.servers).into());
|
return Ok(get_alias::Response::new(response.room_id, response.servers));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut room_id = None;
|
let mut room_id = None;
|
||||||
|
@ -144,5 +144,8 @@ pub(crate) async fn get_alias_helper(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_alias::Response::new(room_id, vec![db.globals.server_name().to_owned()]).into())
|
Ok(get_alias::Response::new(
|
||||||
|
room_id,
|
||||||
|
vec![db.globals.server_name().to_owned()],
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
use crate::{database::DatabaseGuard, Error, Result, Ruma};
|
||||||
use ruma::api::client::{
|
use ruma::api::client::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
r0::backup::{
|
r0::backup::{
|
||||||
|
@ -16,7 +16,7 @@ use ruma::api::client::{
|
||||||
pub async fn create_backup_route(
|
pub async fn create_backup_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<create_backup::Request>,
|
body: Ruma<create_backup::Request>,
|
||||||
) -> ConduitResult<create_backup::Response> {
|
) -> Result<create_backup::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 = db
|
let version = db
|
||||||
.key_backups
|
.key_backups
|
||||||
|
@ -24,7 +24,7 @@ pub async fn create_backup_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(create_backup::Response { version }.into())
|
Ok(create_backup::Response { version })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/version/{version}`
|
/// # `PUT /_matrix/client/r0/room_keys/version/{version}`
|
||||||
|
@ -34,14 +34,14 @@ pub async fn create_backup_route(
|
||||||
pub async fn update_backup_route(
|
pub async fn update_backup_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<update_backup::Request<'_>>,
|
body: Ruma<update_backup::Request<'_>>,
|
||||||
) -> ConduitResult<update_backup::Response> {
|
) -> Result<update_backup::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");
|
||||||
db.key_backups
|
db.key_backups
|
||||||
.update_backup(sender_user, &body.version, &body.algorithm, &db.globals)?;
|
.update_backup(sender_user, &body.version, &body.algorithm, &db.globals)?;
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(update_backup::Response {}.into())
|
Ok(update_backup::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/version`
|
/// # `GET /_matrix/client/r0/room_keys/version`
|
||||||
|
@ -51,7 +51,7 @@ pub async fn update_backup_route(
|
||||||
pub async fn get_latest_backup_route(
|
pub async fn get_latest_backup_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_latest_backup::Request>,
|
body: Ruma<get_latest_backup::Request>,
|
||||||
) -> ConduitResult<get_latest_backup::Response> {
|
) -> Result<get_latest_backup::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) =
|
let (version, algorithm) =
|
||||||
|
@ -67,8 +67,7 @@ pub async fn get_latest_backup_route(
|
||||||
count: (db.key_backups.count_keys(sender_user, &version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_user, &version)?,
|
etag: db.key_backups.get_etag(sender_user, &version)?,
|
||||||
version,
|
version,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/version`
|
/// # `GET /_matrix/client/r0/room_keys/version`
|
||||||
|
@ -78,7 +77,7 @@ pub async fn get_latest_backup_route(
|
||||||
pub async fn get_backup_route(
|
pub async fn get_backup_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_backup::Request<'_>>,
|
body: Ruma<get_backup::Request<'_>>,
|
||||||
) -> ConduitResult<get_backup::Response> {
|
) -> Result<get_backup::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 = db
|
let algorithm = db
|
||||||
.key_backups
|
.key_backups
|
||||||
|
@ -93,8 +92,7 @@ pub async fn get_backup_route(
|
||||||
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
||||||
version: body.version.to_owned(),
|
version: body.version.to_owned(),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/version/{version}`
|
/// # `DELETE /_matrix/client/r0/room_keys/version/{version}`
|
||||||
|
@ -106,14 +104,14 @@ pub async fn get_backup_route(
|
||||||
pub async fn delete_backup_route(
|
pub async fn delete_backup_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<delete_backup::Request<'_>>,
|
body: Ruma<delete_backup::Request<'_>>,
|
||||||
) -> ConduitResult<delete_backup::Response> {
|
) -> Result<delete_backup::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");
|
||||||
|
|
||||||
db.key_backups.delete_backup(sender_user, &body.version)?;
|
db.key_backups.delete_backup(sender_user, &body.version)?;
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(delete_backup::Response {}.into())
|
Ok(delete_backup::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/keys`
|
/// # `PUT /_matrix/client/r0/room_keys/keys`
|
||||||
|
@ -127,7 +125,7 @@ pub async fn delete_backup_route(
|
||||||
pub async fn add_backup_keys_route(
|
pub async fn add_backup_keys_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<add_backup_keys::Request<'_>>,
|
body: Ruma<add_backup_keys::Request<'_>>,
|
||||||
) -> ConduitResult<add_backup_keys::Response> {
|
) -> Result<add_backup_keys::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)
|
||||||
|
@ -160,8 +158,7 @@ pub async fn add_backup_keys_route(
|
||||||
Ok(add_backup_keys::Response {
|
Ok(add_backup_keys::Response {
|
||||||
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}`
|
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}`
|
||||||
|
@ -175,7 +172,7 @@ pub async fn add_backup_keys_route(
|
||||||
pub async fn add_backup_key_sessions_route(
|
pub async fn add_backup_key_sessions_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<add_backup_key_sessions::Request<'_>>,
|
body: Ruma<add_backup_key_sessions::Request<'_>>,
|
||||||
) -> ConduitResult<add_backup_key_sessions::Response> {
|
) -> Result<add_backup_key_sessions::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)
|
||||||
|
@ -206,8 +203,7 @@ pub async fn add_backup_key_sessions_route(
|
||||||
Ok(add_backup_key_sessions::Response {
|
Ok(add_backup_key_sessions::Response {
|
||||||
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
/// # `PUT /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
||||||
|
@ -221,7 +217,7 @@ pub async fn add_backup_key_sessions_route(
|
||||||
pub async fn add_backup_key_session_route(
|
pub async fn add_backup_key_session_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<add_backup_key_session::Request<'_>>,
|
body: Ruma<add_backup_key_session::Request<'_>>,
|
||||||
) -> ConduitResult<add_backup_key_session::Response> {
|
) -> Result<add_backup_key_session::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)
|
||||||
|
@ -250,8 +246,7 @@ pub async fn add_backup_key_session_route(
|
||||||
Ok(add_backup_key_session::Response {
|
Ok(add_backup_key_session::Response {
|
||||||
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/keys`
|
/// # `GET /_matrix/client/r0/room_keys/keys`
|
||||||
|
@ -261,12 +256,12 @@ pub async fn add_backup_key_session_route(
|
||||||
pub async fn get_backup_keys_route(
|
pub async fn get_backup_keys_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_backup_keys::Request<'_>>,
|
body: Ruma<get_backup_keys::Request<'_>>,
|
||||||
) -> ConduitResult<get_backup_keys::Response> {
|
) -> Result<get_backup_keys::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 = db.key_backups.get_all(sender_user, &body.version)?;
|
let rooms = db.key_backups.get_all(sender_user, &body.version)?;
|
||||||
|
|
||||||
Ok(get_backup_keys::Response { rooms }.into())
|
Ok(get_backup_keys::Response { rooms })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}`
|
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}`
|
||||||
|
@ -276,14 +271,14 @@ pub async fn get_backup_keys_route(
|
||||||
pub async fn get_backup_key_sessions_route(
|
pub async fn get_backup_key_sessions_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_backup_key_sessions::Request<'_>>,
|
body: Ruma<get_backup_key_sessions::Request<'_>>,
|
||||||
) -> ConduitResult<get_backup_key_sessions::Response> {
|
) -> Result<get_backup_key_sessions::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 = db
|
let sessions = db
|
||||||
.key_backups
|
.key_backups
|
||||||
.get_room(sender_user, &body.version, &body.room_id)?;
|
.get_room(sender_user, &body.version, &body.room_id)?;
|
||||||
|
|
||||||
Ok(get_backup_key_sessions::Response { sessions }.into())
|
Ok(get_backup_key_sessions::Response { sessions })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
||||||
|
@ -293,7 +288,7 @@ pub async fn get_backup_key_sessions_route(
|
||||||
pub async fn get_backup_key_session_route(
|
pub async fn get_backup_key_session_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_backup_key_session::Request<'_>>,
|
body: Ruma<get_backup_key_session::Request<'_>>,
|
||||||
) -> ConduitResult<get_backup_key_session::Response> {
|
) -> Result<get_backup_key_session::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 = db
|
let key_data = db
|
||||||
|
@ -304,7 +299,7 @@ pub async fn get_backup_key_session_route(
|
||||||
"Backup key not found for this user's session.",
|
"Backup key not found for this user's session.",
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
Ok(get_backup_key_session::Response { key_data }.into())
|
Ok(get_backup_key_session::Response { key_data })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/keys`
|
/// # `DELETE /_matrix/client/r0/room_keys/keys`
|
||||||
|
@ -314,7 +309,7 @@ pub async fn get_backup_key_session_route(
|
||||||
pub async fn delete_backup_keys_route(
|
pub async fn delete_backup_keys_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<delete_backup_keys::Request<'_>>,
|
body: Ruma<delete_backup_keys::Request<'_>>,
|
||||||
) -> ConduitResult<delete_backup_keys::Response> {
|
) -> Result<delete_backup_keys::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");
|
||||||
|
|
||||||
db.key_backups.delete_all_keys(sender_user, &body.version)?;
|
db.key_backups.delete_all_keys(sender_user, &body.version)?;
|
||||||
|
@ -324,8 +319,7 @@ pub async fn delete_backup_keys_route(
|
||||||
Ok(delete_backup_keys::Response {
|
Ok(delete_backup_keys::Response {
|
||||||
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}`
|
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}`
|
||||||
|
@ -335,7 +329,7 @@ pub async fn delete_backup_keys_route(
|
||||||
pub async fn delete_backup_key_sessions_route(
|
pub async fn delete_backup_key_sessions_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<delete_backup_key_sessions::Request<'_>>,
|
body: Ruma<delete_backup_key_sessions::Request<'_>>,
|
||||||
) -> ConduitResult<delete_backup_key_sessions::Response> {
|
) -> Result<delete_backup_key_sessions::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");
|
||||||
|
|
||||||
db.key_backups
|
db.key_backups
|
||||||
|
@ -346,8 +340,7 @@ pub async fn delete_backup_key_sessions_route(
|
||||||
Ok(delete_backup_key_sessions::Response {
|
Ok(delete_backup_key_sessions::Response {
|
||||||
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
/// # `DELETE /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
|
||||||
|
@ -357,7 +350,7 @@ pub async fn delete_backup_key_sessions_route(
|
||||||
pub async fn delete_backup_key_session_route(
|
pub async fn delete_backup_key_session_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<delete_backup_key_session::Request<'_>>,
|
body: Ruma<delete_backup_key_session::Request<'_>>,
|
||||||
) -> ConduitResult<delete_backup_key_session::Response> {
|
) -> Result<delete_backup_key_session::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");
|
||||||
|
|
||||||
db.key_backups
|
db.key_backups
|
||||||
|
@ -368,6 +361,5 @@ pub async fn delete_backup_key_session_route(
|
||||||
Ok(delete_backup_key_session::Response {
|
Ok(delete_backup_key_session::Response {
|
||||||
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{ConduitResult, Ruma};
|
use crate::{Result, Ruma};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::r0::capabilities::{
|
api::client::r0::capabilities::{
|
||||||
get_capabilities, Capabilities, RoomVersionStability, RoomVersionsCapability,
|
get_capabilities, Capabilities, RoomVersionStability, RoomVersionsCapability,
|
||||||
|
@ -13,7 +13,7 @@ use std::collections::BTreeMap;
|
||||||
#[tracing::instrument(skip(_body))]
|
#[tracing::instrument(skip(_body))]
|
||||||
pub async fn get_capabilities_route(
|
pub async fn get_capabilities_route(
|
||||||
_body: Ruma<get_capabilities::Request>,
|
_body: Ruma<get_capabilities::Request>,
|
||||||
) -> ConduitResult<get_capabilities::Response> {
|
) -> Result<get_capabilities::Response> {
|
||||||
let mut available = BTreeMap::new();
|
let mut available = BTreeMap::new();
|
||||||
available.insert(RoomVersionId::V5, RoomVersionStability::Stable);
|
available.insert(RoomVersionId::V5, RoomVersionStability::Stable);
|
||||||
available.insert(RoomVersionId::V6, RoomVersionStability::Stable);
|
available.insert(RoomVersionId::V6, RoomVersionStability::Stable);
|
||||||
|
@ -24,5 +24,5 @@ pub async fn get_capabilities_route(
|
||||||
available,
|
available,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_capabilities::Response { capabilities }.into())
|
Ok(get_capabilities::Response { capabilities })
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
use crate::{database::DatabaseGuard, Error, Result, Ruma};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{
|
api::client::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
|
@ -20,7 +20,7 @@ use serde_json::{json, value::RawValue as RawJsonValue};
|
||||||
pub async fn set_global_account_data_route(
|
pub async fn set_global_account_data_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<set_global_account_data::Request<'_>>,
|
body: Ruma<set_global_account_data::Request<'_>>,
|
||||||
) -> ConduitResult<set_global_account_data::Response> {
|
) -> Result<set_global_account_data::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.get())
|
let data: serde_json::Value = serde_json::from_str(body.data.get())
|
||||||
|
@ -41,7 +41,7 @@ pub async fn set_global_account_data_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(set_global_account_data::Response {}.into())
|
Ok(set_global_account_data::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
||||||
|
@ -51,7 +51,7 @@ pub async fn set_global_account_data_route(
|
||||||
pub async fn set_room_account_data_route(
|
pub async fn set_room_account_data_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<set_room_account_data::Request<'_>>,
|
body: Ruma<set_room_account_data::Request<'_>>,
|
||||||
) -> ConduitResult<set_room_account_data::Response> {
|
) -> Result<set_room_account_data::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.get())
|
let data: serde_json::Value = serde_json::from_str(body.data.get())
|
||||||
|
@ -72,7 +72,7 @@ pub async fn set_room_account_data_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(set_room_account_data::Response {}.into())
|
Ok(set_room_account_data::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/user/{userId}/account_data/{type}`
|
/// # `GET /_matrix/client/r0/user/{userId}/account_data/{type}`
|
||||||
|
@ -82,7 +82,7 @@ pub async fn set_room_account_data_route(
|
||||||
pub async fn get_global_account_data_route(
|
pub async fn get_global_account_data_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_global_account_data::Request<'_>>,
|
body: Ruma<get_global_account_data::Request<'_>>,
|
||||||
) -> ConduitResult<get_global_account_data::Response> {
|
) -> Result<get_global_account_data::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> = db
|
let event: Box<RawJsonValue> = db
|
||||||
|
@ -94,7 +94,7 @@ pub async fn get_global_account_data_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_global_account_data::Response { account_data }.into())
|
Ok(get_global_account_data::Response { account_data })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
/// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
||||||
|
@ -104,7 +104,7 @@ pub async fn get_global_account_data_route(
|
||||||
pub async fn get_room_account_data_route(
|
pub async fn get_room_account_data_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_room_account_data::Request<'_>>,
|
body: Ruma<get_room_account_data::Request<'_>>,
|
||||||
) -> ConduitResult<get_room_account_data::Response> {
|
) -> Result<get_room_account_data::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> = db
|
let event: Box<RawJsonValue> = db
|
||||||
|
@ -120,7 +120,7 @@ pub async fn get_room_account_data_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_room_account_data::Response { account_data }.into())
|
Ok(get_room_account_data::Response { account_data })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
use crate::{database::DatabaseGuard, Error, Result, Ruma};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{
|
api::client::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
|
@ -19,7 +19,7 @@ use tracing::error;
|
||||||
pub async fn get_context_route(
|
pub async fn get_context_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_context::Request<'_>>,
|
body: Ruma<get_context::Request<'_>>,
|
||||||
) -> ConduitResult<get_context::Response> {
|
) -> Result<get_context::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_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
|
@ -191,5 +191,5 @@ pub async fn get_context_route(
|
||||||
state,
|
state,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(resp.into())
|
Ok(resp)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, utils, ConduitResult, Error, Ruma};
|
use crate::{database::DatabaseGuard, utils, Error, Result, Ruma};
|
||||||
use ruma::api::client::{
|
use ruma::api::client::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
r0::{
|
r0::{
|
||||||
|
@ -16,7 +16,7 @@ use super::SESSION_ID_LENGTH;
|
||||||
pub async fn get_devices_route(
|
pub async fn get_devices_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_devices::Request>,
|
body: Ruma<get_devices::Request>,
|
||||||
) -> ConduitResult<get_devices::Response> {
|
) -> Result<get_devices::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> = db
|
let devices: Vec<device::Device> = db
|
||||||
|
@ -25,7 +25,7 @@ pub async fn get_devices_route(
|
||||||
.filter_map(|r| r.ok()) // Filter out buggy devices
|
.filter_map(|r| r.ok()) // Filter out buggy devices
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(get_devices::Response { devices }.into())
|
Ok(get_devices::Response { devices })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/devices/{deviceId}`
|
/// # `GET /_matrix/client/r0/devices/{deviceId}`
|
||||||
|
@ -35,7 +35,7 @@ pub async fn get_devices_route(
|
||||||
pub async fn get_device_route(
|
pub async fn get_device_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_device::Request<'_>>,
|
body: Ruma<get_device::Request<'_>>,
|
||||||
) -> ConduitResult<get_device::Response> {
|
) -> Result<get_device::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 = db
|
let device = db
|
||||||
|
@ -43,7 +43,7 @@ pub 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::Response { device }.into())
|
Ok(get_device::Response { device })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/devices/{deviceId}`
|
/// # `PUT /_matrix/client/r0/devices/{deviceId}`
|
||||||
|
@ -53,7 +53,7 @@ pub async fn get_device_route(
|
||||||
pub async fn update_device_route(
|
pub async fn update_device_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<update_device::Request<'_>>,
|
body: Ruma<update_device::Request<'_>>,
|
||||||
) -> ConduitResult<update_device::Response> {
|
) -> Result<update_device::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 = db
|
let mut device = db
|
||||||
|
@ -68,7 +68,7 @@ pub async fn update_device_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(update_device::Response {}.into())
|
Ok(update_device::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/devices/{deviceId}`
|
/// # `DELETE /_matrix/client/r0/devices/{deviceId}`
|
||||||
|
@ -84,7 +84,7 @@ pub async fn update_device_route(
|
||||||
pub async fn delete_device_route(
|
pub async fn delete_device_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<delete_device::Request<'_>>,
|
body: Ruma<delete_device::Request<'_>>,
|
||||||
) -> ConduitResult<delete_device::Response> {
|
) -> Result<delete_device::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_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ pub async fn delete_device_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(delete_device::Response {}.into())
|
Ok(delete_device::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/devices/{deviceId}`
|
/// # `PUT /_matrix/client/r0/devices/{deviceId}`
|
||||||
|
@ -143,7 +143,7 @@ pub async fn delete_device_route(
|
||||||
pub async fn delete_devices_route(
|
pub async fn delete_devices_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<delete_devices::Request<'_>>,
|
body: Ruma<delete_devices::Request<'_>>,
|
||||||
) -> ConduitResult<delete_devices::Response> {
|
) -> Result<delete_devices::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_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
|
@ -186,5 +186,5 @@ pub async fn delete_devices_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(delete_devices::Response {}.into())
|
Ok(delete_devices::Response {})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, ConduitResult, Database, Error, Result, Ruma};
|
use crate::{database::DatabaseGuard, Database, Error, Result, Ruma};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::{
|
api::{
|
||||||
client::{
|
client::{
|
||||||
|
@ -38,7 +38,7 @@ use tracing::{info, warn};
|
||||||
pub async fn get_public_rooms_filtered_route(
|
pub async fn get_public_rooms_filtered_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_public_rooms_filtered::Request<'_>>,
|
body: Ruma<get_public_rooms_filtered::Request<'_>>,
|
||||||
) -> ConduitResult<get_public_rooms_filtered::Response> {
|
) -> Result<get_public_rooms_filtered::Response> {
|
||||||
get_public_rooms_filtered_helper(
|
get_public_rooms_filtered_helper(
|
||||||
&db,
|
&db,
|
||||||
body.server.as_deref(),
|
body.server.as_deref(),
|
||||||
|
@ -59,7 +59,7 @@ pub async fn get_public_rooms_filtered_route(
|
||||||
pub async fn get_public_rooms_route(
|
pub async fn get_public_rooms_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_public_rooms::Request<'_>>,
|
body: Ruma<get_public_rooms::Request<'_>>,
|
||||||
) -> ConduitResult<get_public_rooms::Response> {
|
) -> Result<get_public_rooms::Response> {
|
||||||
let response = get_public_rooms_filtered_helper(
|
let response = get_public_rooms_filtered_helper(
|
||||||
&db,
|
&db,
|
||||||
body.server.as_deref(),
|
body.server.as_deref(),
|
||||||
|
@ -68,16 +68,14 @@ pub async fn get_public_rooms_route(
|
||||||
&IncomingFilter::default(),
|
&IncomingFilter::default(),
|
||||||
&IncomingRoomNetwork::Matrix,
|
&IncomingRoomNetwork::Matrix,
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.0;
|
|
||||||
|
|
||||||
Ok(get_public_rooms::Response {
|
Ok(get_public_rooms::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,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/directory/list/room/{roomId}`
|
/// # `PUT /_matrix/client/r0/directory/list/room/{roomId}`
|
||||||
|
@ -89,7 +87,7 @@ pub async fn get_public_rooms_route(
|
||||||
pub async fn set_room_visibility_route(
|
pub async fn set_room_visibility_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<set_room_visibility::Request<'_>>,
|
body: Ruma<set_room_visibility::Request<'_>>,
|
||||||
) -> ConduitResult<set_room_visibility::Response> {
|
) -> Result<set_room_visibility::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");
|
||||||
|
|
||||||
match &body.visibility {
|
match &body.visibility {
|
||||||
|
@ -108,7 +106,7 @@ pub async fn set_room_visibility_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(set_room_visibility::Response {}.into())
|
Ok(set_room_visibility::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/directory/list/room/{roomId}`
|
/// # `GET /_matrix/client/r0/directory/list/room/{roomId}`
|
||||||
|
@ -118,15 +116,14 @@ pub async fn set_room_visibility_route(
|
||||||
pub async fn get_room_visibility_route(
|
pub async fn get_room_visibility_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_room_visibility::Request<'_>>,
|
body: Ruma<get_room_visibility::Request<'_>>,
|
||||||
) -> ConduitResult<get_room_visibility::Response> {
|
) -> Result<get_room_visibility::Response> {
|
||||||
Ok(get_room_visibility::Response {
|
Ok(get_room_visibility::Response {
|
||||||
visibility: if db.rooms.is_public_room(&body.room_id)? {
|
visibility: if db.rooms.is_public_room(&body.room_id)? {
|
||||||
room::Visibility::Public
|
room::Visibility::Public
|
||||||
} else {
|
} else {
|
||||||
room::Visibility::Private
|
room::Visibility::Private
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_public_rooms_filtered_helper(
|
pub(crate) async fn get_public_rooms_filtered_helper(
|
||||||
|
@ -136,7 +133,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
||||||
since: Option<&str>,
|
since: Option<&str>,
|
||||||
filter: &IncomingFilter,
|
filter: &IncomingFilter,
|
||||||
_network: &IncomingRoomNetwork,
|
_network: &IncomingRoomNetwork,
|
||||||
) -> ConduitResult<get_public_rooms_filtered::Response> {
|
) -> Result<get_public_rooms_filtered::Response> {
|
||||||
if let Some(other_server) = server.filter(|server| *server != db.globals.server_name().as_str())
|
if let Some(other_server) = server.filter(|server| *server != db.globals.server_name().as_str())
|
||||||
{
|
{
|
||||||
let response = db
|
let response = db
|
||||||
|
@ -172,8 +169,7 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
||||||
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,
|
||||||
}
|
});
|
||||||
.into());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let limit = limit.map_or(10, u64::from);
|
let limit = limit.map_or(10, u64::from);
|
||||||
|
@ -353,6 +349,5 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
||||||
prev_batch,
|
prev_batch,
|
||||||
next_batch,
|
next_batch,
|
||||||
total_room_count_estimate: Some(total_room_count_estimate),
|
total_room_count_estimate: Some(total_room_count_estimate),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
use crate::{database::DatabaseGuard, Error, Result, Ruma};
|
||||||
use ruma::api::client::{
|
use ruma::api::client::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
r0::filter::{create_filter, get_filter},
|
r0::filter::{create_filter, get_filter},
|
||||||
|
@ -13,14 +13,14 @@ use ruma::api::client::{
|
||||||
pub async fn get_filter_route(
|
pub async fn get_filter_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_filter::Request<'_>>,
|
body: Ruma<get_filter::Request<'_>>,
|
||||||
) -> ConduitResult<get_filter::Response> {
|
) -> Result<get_filter::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 filter = match db.users.get_filter(sender_user, &body.filter_id)? {
|
let filter = match db.users.get_filter(sender_user, &body.filter_id)? {
|
||||||
Some(filter) => filter,
|
Some(filter) => filter,
|
||||||
None => return Err(Error::BadRequest(ErrorKind::NotFound, "Filter not found.")),
|
None => return Err(Error::BadRequest(ErrorKind::NotFound, "Filter not found.")),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(get_filter::Response::new(filter).into())
|
Ok(get_filter::Response::new(filter))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/user/{userId}/filter`
|
/// # `PUT /_matrix/client/r0/user/{userId}/filter`
|
||||||
|
@ -30,7 +30,9 @@ pub async fn get_filter_route(
|
||||||
pub async fn create_filter_route(
|
pub async fn create_filter_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<create_filter::Request<'_>>,
|
body: Ruma<create_filter::Request<'_>>,
|
||||||
) -> ConduitResult<create_filter::Response> {
|
) -> Result<create_filter::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::Response::new(db.users.create_filter(sender_user, &body.filter)?).into())
|
Ok(create_filter::Response::new(
|
||||||
|
db.users.create_filter(sender_user, &body.filter)?,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use super::SESSION_ID_LENGTH;
|
use super::SESSION_ID_LENGTH;
|
||||||
use crate::{database::DatabaseGuard, utils, ConduitResult, Database, Error, Result, Ruma};
|
use crate::{database::DatabaseGuard, utils, Database, Error, Result, Ruma};
|
||||||
use futures_util::{stream::FuturesUnordered, StreamExt};
|
use futures_util::{stream::FuturesUnordered, StreamExt};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::{
|
api::{
|
||||||
|
@ -31,7 +31,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
|
||||||
pub async fn upload_keys_route(
|
pub async fn upload_keys_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<upload_keys::Request>,
|
body: Ruma<upload_keys::Request>,
|
||||||
) -> ConduitResult<upload_keys::Response> {
|
) -> Result<upload_keys::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_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
|
@ -62,8 +62,7 @@ pub async fn upload_keys_route(
|
||||||
|
|
||||||
Ok(upload_keys::Response {
|
Ok(upload_keys::Response {
|
||||||
one_time_key_counts: db.users.count_one_time_keys(sender_user, sender_device)?,
|
one_time_key_counts: db.users.count_one_time_keys(sender_user, sender_device)?,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/query`
|
/// # `POST /_matrix/client/r0/keys/query`
|
||||||
|
@ -77,7 +76,7 @@ pub async fn upload_keys_route(
|
||||||
pub async fn get_keys_route(
|
pub async fn get_keys_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_keys::Request<'_>>,
|
body: Ruma<get_keys::Request<'_>>,
|
||||||
) -> ConduitResult<get_keys::Response> {
|
) -> Result<get_keys::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(
|
let response = get_keys_helper(
|
||||||
|
@ -88,7 +87,7 @@ pub async fn get_keys_route(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(response.into())
|
Ok(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/claim`
|
/// # `POST /_matrix/client/r0/keys/claim`
|
||||||
|
@ -98,12 +97,12 @@ pub async fn get_keys_route(
|
||||||
pub async fn claim_keys_route(
|
pub async fn claim_keys_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<claim_keys::Request>,
|
body: Ruma<claim_keys::Request>,
|
||||||
) -> ConduitResult<claim_keys::Response> {
|
) -> Result<claim_keys::Response> {
|
||||||
let response = claim_keys_helper(&body.one_time_keys, &db).await?;
|
let response = claim_keys_helper(&body.one_time_keys, &db).await?;
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(response.into())
|
Ok(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/device_signing/upload`
|
/// # `POST /_matrix/client/r0/keys/device_signing/upload`
|
||||||
|
@ -115,7 +114,7 @@ pub async fn claim_keys_route(
|
||||||
pub async fn upload_signing_keys_route(
|
pub async fn upload_signing_keys_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<upload_signing_keys::Request<'_>>,
|
body: Ruma<upload_signing_keys::Request<'_>>,
|
||||||
) -> ConduitResult<upload_signing_keys::Response> {
|
) -> Result<upload_signing_keys::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_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
|
@ -165,7 +164,7 @@ pub async fn upload_signing_keys_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(upload_signing_keys::Response {}.into())
|
Ok(upload_signing_keys::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/signatures/upload`
|
/// # `POST /_matrix/client/r0/keys/signatures/upload`
|
||||||
|
@ -175,7 +174,7 @@ pub async fn upload_signing_keys_route(
|
||||||
pub async fn upload_signatures_route(
|
pub async fn upload_signatures_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<upload_signatures::Request>,
|
body: Ruma<upload_signatures::Request>,
|
||||||
) -> ConduitResult<upload_signatures::Response> {
|
) -> Result<upload_signatures::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, signed_keys) in &body.signed_keys {
|
for (user_id, signed_keys) in &body.signed_keys {
|
||||||
|
@ -225,7 +224,7 @@ pub async fn upload_signatures_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(upload_signatures::Response {}.into())
|
Ok(upload_signatures::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/keys/changes`
|
/// # `POST /_matrix/client/r0/keys/changes`
|
||||||
|
@ -237,7 +236,7 @@ pub async fn upload_signatures_route(
|
||||||
pub async fn get_key_changes_route(
|
pub async fn get_key_changes_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_key_changes::Request<'_>>,
|
body: Ruma<get_key_changes::Request<'_>>,
|
||||||
) -> ConduitResult<get_key_changes::Response> {
|
) -> Result<get_key_changes::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();
|
||||||
|
@ -276,8 +275,7 @@ pub async fn get_key_changes_route(
|
||||||
Ok(get_key_changes::Response {
|
Ok(get_key_changes::Response {
|
||||||
changed: device_list_updates.into_iter().collect(),
|
changed: device_list_updates.into_iter().collect(),
|
||||||
left: Vec::new(), // TODO
|
left: Vec::new(), // TODO
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_keys_helper<F: Fn(&UserId) -> bool>(
|
pub(crate) async fn get_keys_helper<F: Fn(&UserId) -> bool>(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
database::{media::FileMeta, DatabaseGuard},
|
database::{media::FileMeta, DatabaseGuard},
|
||||||
utils, ConduitResult, Error, Ruma,
|
utils, Error, Result, Ruma,
|
||||||
};
|
};
|
||||||
use ruma::api::client::{
|
use ruma::api::client::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
|
@ -19,11 +19,10 @@ const MXC_LENGTH: usize = 32;
|
||||||
pub async fn get_media_config_route(
|
pub async fn get_media_config_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
_body: Ruma<get_media_config::Request>,
|
_body: Ruma<get_media_config::Request>,
|
||||||
) -> ConduitResult<get_media_config::Response> {
|
) -> Result<get_media_config::Response> {
|
||||||
Ok(get_media_config::Response {
|
Ok(get_media_config::Response {
|
||||||
upload_size: db.globals.max_request_size().into(),
|
upload_size: db.globals.max_request_size().into(),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/media/r0/upload`
|
/// # `POST /_matrix/media/r0/upload`
|
||||||
|
@ -36,7 +35,7 @@ pub async fn get_media_config_route(
|
||||||
pub async fn create_content_route(
|
pub async fn create_content_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<create_content::Request<'_>>,
|
body: Ruma<create_content::Request<'_>>,
|
||||||
) -> ConduitResult<create_content::Response> {
|
) -> Result<create_content::Response> {
|
||||||
let mxc = format!(
|
let mxc = format!(
|
||||||
"mxc://{}/{}",
|
"mxc://{}/{}",
|
||||||
db.globals.server_name(),
|
db.globals.server_name(),
|
||||||
|
@ -62,8 +61,7 @@ pub async fn create_content_route(
|
||||||
Ok(create_content::Response {
|
Ok(create_content::Response {
|
||||||
content_uri: mxc.try_into().expect("Invalid mxc:// URI"),
|
content_uri: mxc.try_into().expect("Invalid mxc:// URI"),
|
||||||
blurhash: None,
|
blurhash: None,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_remote_content(
|
pub async fn get_remote_content(
|
||||||
|
@ -107,7 +105,7 @@ pub async fn get_remote_content(
|
||||||
pub async fn get_content_route(
|
pub async fn get_content_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_content::Request<'_>>,
|
body: Ruma<get_content::Request<'_>>,
|
||||||
) -> ConduitResult<get_content::Response> {
|
) -> Result<get_content::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 {
|
||||||
|
@ -120,12 +118,11 @@ pub async fn get_content_route(
|
||||||
file,
|
file,
|
||||||
content_type,
|
content_type,
|
||||||
content_disposition,
|
content_disposition,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
} else if &*body.server_name != db.globals.server_name() && body.allow_remote {
|
} else if &*body.server_name != db.globals.server_name() && body.allow_remote {
|
||||||
let remote_content_response =
|
let remote_content_response =
|
||||||
get_remote_content(&db, &mxc, &body.server_name, &body.media_id).await?;
|
get_remote_content(&db, &mxc, &body.server_name, &body.media_id).await?;
|
||||||
Ok(remote_content_response.into())
|
Ok(remote_content_response)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
|
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
|
||||||
}
|
}
|
||||||
|
@ -140,7 +137,7 @@ pub async fn get_content_route(
|
||||||
pub async fn get_content_as_filename_route(
|
pub async fn get_content_as_filename_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_content_as_filename::Request<'_>>,
|
body: Ruma<get_content_as_filename::Request<'_>>,
|
||||||
) -> ConduitResult<get_content_as_filename::Response> {
|
) -> Result<get_content_as_filename::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 {
|
||||||
|
@ -153,8 +150,7 @@ pub async fn get_content_as_filename_route(
|
||||||
file,
|
file,
|
||||||
content_type,
|
content_type,
|
||||||
content_disposition: Some(format!("inline; filename={}", body.filename)),
|
content_disposition: Some(format!("inline; filename={}", body.filename)),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
} else if &*body.server_name != db.globals.server_name() && body.allow_remote {
|
} else if &*body.server_name != db.globals.server_name() && body.allow_remote {
|
||||||
let remote_content_response =
|
let remote_content_response =
|
||||||
get_remote_content(&db, &mxc, &body.server_name, &body.media_id).await?;
|
get_remote_content(&db, &mxc, &body.server_name, &body.media_id).await?;
|
||||||
|
@ -163,8 +159,7 @@ pub async fn get_content_as_filename_route(
|
||||||
content_disposition: Some(format!("inline: filename={}", body.filename)),
|
content_disposition: Some(format!("inline: filename={}", body.filename)),
|
||||||
content_type: remote_content_response.content_type,
|
content_type: remote_content_response.content_type,
|
||||||
file: remote_content_response.file,
|
file: remote_content_response.file,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
} else {
|
} else {
|
||||||
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
|
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
|
||||||
}
|
}
|
||||||
|
@ -179,7 +174,7 @@ pub async fn get_content_as_filename_route(
|
||||||
pub async fn get_content_thumbnail_route(
|
pub async fn get_content_thumbnail_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_content_thumbnail::Request<'_>>,
|
body: Ruma<get_content_thumbnail::Request<'_>>,
|
||||||
) -> ConduitResult<get_content_thumbnail::Response> {
|
) -> Result<get_content_thumbnail::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 {
|
||||||
|
@ -198,7 +193,7 @@ pub async fn get_content_thumbnail_route(
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
Ok(get_content_thumbnail::Response { file, content_type }.into())
|
Ok(get_content_thumbnail::Response { file, content_type })
|
||||||
} else if &*body.server_name != db.globals.server_name() && body.allow_remote {
|
} else if &*body.server_name != db.globals.server_name() && body.allow_remote {
|
||||||
let get_thumbnail_response = db
|
let get_thumbnail_response = db
|
||||||
.sending
|
.sending
|
||||||
|
@ -228,7 +223,7 @@ pub async fn get_content_thumbnail_route(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(get_thumbnail_response.into())
|
Ok(get_thumbnail_response)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
|
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
||||||
client_server,
|
client_server,
|
||||||
database::DatabaseGuard,
|
database::DatabaseGuard,
|
||||||
pdu::{EventHash, PduBuilder, PduEvent},
|
pdu::{EventHash, PduBuilder, PduEvent},
|
||||||
server_server, utils, ConduitResult, Database, Error, Result, Ruma,
|
server_server, utils, Database, Error, Result, Ruma,
|
||||||
};
|
};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::{
|
api::{
|
||||||
|
@ -46,7 +46,7 @@ use tracing::{debug, error, warn};
|
||||||
pub async fn join_room_by_id_route(
|
pub async fn join_room_by_id_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<join_room_by_id::Request<'_>>,
|
body: Ruma<join_room_by_id::Request<'_>>,
|
||||||
) -> ConduitResult<join_room_by_id::Response> {
|
) -> Result<join_room_by_id::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 servers: HashSet<_> = db
|
let mut servers: HashSet<_> = db
|
||||||
|
@ -87,7 +87,7 @@ pub async fn join_room_by_id_route(
|
||||||
pub async fn join_room_by_id_or_alias_route(
|
pub async fn join_room_by_id_or_alias_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<join_room_by_id_or_alias::Request<'_>>,
|
body: Ruma<join_room_by_id_or_alias::Request<'_>>,
|
||||||
) -> ConduitResult<join_room_by_id_or_alias::Response> {
|
) -> Result<join_room_by_id_or_alias::Response> {
|
||||||
let sender_user = body.sender_user.as_deref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_deref().expect("user is authenticated");
|
||||||
let body = body.body;
|
let body = body.body;
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ pub async fn join_room_by_id_or_alias_route(
|
||||||
Err(room_alias) => {
|
Err(room_alias) => {
|
||||||
let response = client_server::get_alias_helper(&db, &room_alias).await?;
|
let response = client_server::get_alias_helper(&db, &room_alias).await?;
|
||||||
|
|
||||||
(response.0.servers.into_iter().collect(), response.0.room_id)
|
(response.servers.into_iter().collect(), response.room_id)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -127,9 +127,8 @@ pub async fn join_room_by_id_or_alias_route(
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(join_room_by_id_or_alias::Response {
|
Ok(join_room_by_id_or_alias::Response {
|
||||||
room_id: join_room_response.0.room_id,
|
room_id: join_room_response.room_id,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/leave`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/leave`
|
||||||
|
@ -141,14 +140,14 @@ pub async fn join_room_by_id_or_alias_route(
|
||||||
pub async fn leave_room_route(
|
pub async fn leave_room_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<leave_room::Request<'_>>,
|
body: Ruma<leave_room::Request<'_>>,
|
||||||
) -> ConduitResult<leave_room::Response> {
|
) -> Result<leave_room::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");
|
||||||
|
|
||||||
db.rooms.leave_room(sender_user, &body.room_id, &db).await?;
|
db.rooms.leave_room(sender_user, &body.room_id, &db).await?;
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(leave_room::Response::new().into())
|
Ok(leave_room::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/invite`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/invite`
|
||||||
|
@ -158,13 +157,13 @@ pub async fn leave_room_route(
|
||||||
pub async fn invite_user_route(
|
pub async fn invite_user_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<invite_user::Request<'_>>,
|
body: Ruma<invite_user::Request<'_>>,
|
||||||
) -> ConduitResult<invite_user::Response> {
|
) -> Result<invite_user::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::IncomingInvitationRecipient::UserId { user_id } = &body.recipient {
|
if let invite_user::IncomingInvitationRecipient::UserId { user_id } = &body.recipient {
|
||||||
invite_helper(sender_user, user_id, &body.room_id, &db, false).await?;
|
invite_helper(sender_user, user_id, &body.room_id, &db, false).await?;
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
Ok(invite_user::Response {}.into())
|
Ok(invite_user::Response {})
|
||||||
} else {
|
} else {
|
||||||
Err(Error::BadRequest(ErrorKind::NotFound, "User not found."))
|
Err(Error::BadRequest(ErrorKind::NotFound, "User not found."))
|
||||||
}
|
}
|
||||||
|
@ -177,7 +176,7 @@ pub async fn invite_user_route(
|
||||||
pub async fn kick_user_route(
|
pub async fn kick_user_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<kick_user::Request<'_>>,
|
body: Ruma<kick_user::Request<'_>>,
|
||||||
) -> ConduitResult<kick_user::Response> {
|
) -> Result<kick_user::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 event: RoomMemberEventContent = serde_json::from_str(
|
let mut event: RoomMemberEventContent = serde_json::from_str(
|
||||||
|
@ -227,7 +226,7 @@ pub async fn kick_user_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(kick_user::Response::new().into())
|
Ok(kick_user::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/ban`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/ban`
|
||||||
|
@ -237,7 +236,7 @@ pub async fn kick_user_route(
|
||||||
pub async fn ban_user_route(
|
pub async fn ban_user_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<ban_user::Request<'_>>,
|
body: Ruma<ban_user::Request<'_>>,
|
||||||
) -> ConduitResult<ban_user::Response> {
|
) -> Result<ban_user::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");
|
||||||
|
|
||||||
// TODO: reason
|
// TODO: reason
|
||||||
|
@ -298,7 +297,7 @@ pub async fn ban_user_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(ban_user::Response::new().into())
|
Ok(ban_user::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/unban`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/unban`
|
||||||
|
@ -308,7 +307,7 @@ pub async fn ban_user_route(
|
||||||
pub async fn unban_user_route(
|
pub async fn unban_user_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<unban_user::Request<'_>>,
|
body: Ruma<unban_user::Request<'_>>,
|
||||||
) -> ConduitResult<unban_user::Response> {
|
) -> Result<unban_user::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 event: RoomMemberEventContent = serde_json::from_str(
|
let mut event: RoomMemberEventContent = serde_json::from_str(
|
||||||
|
@ -357,7 +356,7 @@ pub async fn unban_user_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(unban_user::Response::new().into())
|
Ok(unban_user::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/forget`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/forget`
|
||||||
|
@ -372,14 +371,14 @@ pub async fn unban_user_route(
|
||||||
pub async fn forget_room_route(
|
pub async fn forget_room_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<forget_room::Request<'_>>,
|
body: Ruma<forget_room::Request<'_>>,
|
||||||
) -> ConduitResult<forget_room::Response> {
|
) -> Result<forget_room::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");
|
||||||
|
|
||||||
db.rooms.forget(&body.room_id, sender_user)?;
|
db.rooms.forget(&body.room_id, sender_user)?;
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(forget_room::Response::new().into())
|
Ok(forget_room::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/joined_rooms`
|
/// # `POST /_matrix/client/r0/joined_rooms`
|
||||||
|
@ -389,7 +388,7 @@ pub async fn forget_room_route(
|
||||||
pub async fn joined_rooms_route(
|
pub async fn joined_rooms_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<joined_rooms::Request>,
|
body: Ruma<joined_rooms::Request>,
|
||||||
) -> ConduitResult<joined_rooms::Response> {
|
) -> Result<joined_rooms::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::Response {
|
Ok(joined_rooms::Response {
|
||||||
|
@ -398,8 +397,7 @@ pub async fn joined_rooms_route(
|
||||||
.rooms_joined(sender_user)
|
.rooms_joined(sender_user)
|
||||||
.filter_map(|r| r.ok())
|
.filter_map(|r| r.ok())
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/members`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/members`
|
||||||
|
@ -411,7 +409,7 @@ pub async fn joined_rooms_route(
|
||||||
pub async fn get_member_events_route(
|
pub async fn get_member_events_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_member_events::Request<'_>>,
|
body: Ruma<get_member_events::Request<'_>>,
|
||||||
) -> ConduitResult<get_member_events::Response> {
|
) -> Result<get_member_events::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");
|
||||||
|
|
||||||
// TODO: check history visibility?
|
// TODO: check history visibility?
|
||||||
|
@ -430,8 +428,7 @@ pub async fn get_member_events_route(
|
||||||
.filter(|(key, _)| key.0 == EventType::RoomMember)
|
.filter(|(key, _)| key.0 == EventType::RoomMember)
|
||||||
.map(|(_, pdu)| pdu.to_member_event())
|
.map(|(_, pdu)| pdu.to_member_event())
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/joined_members`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/joined_members`
|
||||||
|
@ -444,7 +441,7 @@ pub async fn get_member_events_route(
|
||||||
pub async fn joined_members_route(
|
pub async fn joined_members_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<joined_members::Request<'_>>,
|
body: Ruma<joined_members::Request<'_>>,
|
||||||
) -> ConduitResult<joined_members::Response> {
|
) -> Result<joined_members::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 !db.rooms.is_joined(sender_user, &body.room_id)? {
|
if !db.rooms.is_joined(sender_user, &body.room_id)? {
|
||||||
|
@ -468,7 +465,7 @@ pub async fn joined_members_route(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(joined_members::Response { joined }.into())
|
Ok(joined_members::Response { joined })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(db))]
|
#[tracing::instrument(skip(db))]
|
||||||
|
@ -478,7 +475,7 @@ async fn join_room_by_id_helper(
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
servers: &HashSet<Box<ServerName>>,
|
servers: &HashSet<Box<ServerName>>,
|
||||||
_third_party_signed: Option<&IncomingThirdPartySigned>,
|
_third_party_signed: Option<&IncomingThirdPartySigned>,
|
||||||
) -> ConduitResult<join_room_by_id::Response> {
|
) -> Result<join_room_by_id::Response> {
|
||||||
let sender_user = sender_user.expect("user is authenticated");
|
let sender_user = sender_user.expect("user is authenticated");
|
||||||
|
|
||||||
let mutex_state = Arc::clone(
|
let mutex_state = Arc::clone(
|
||||||
|
@ -734,7 +731,7 @@ async fn join_room_by_id_helper(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(join_room_by_id::Response::new(room_id.to_owned()).into())
|
Ok(join_room_by_id::Response::new(room_id.to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_and_add_event_id(
|
fn validate_and_add_event_id(
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, pdu::PduBuilder, utils, ConduitResult, Error, Ruma};
|
use crate::{database::DatabaseGuard, pdu::PduBuilder, utils, Error, Result, Ruma};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{
|
api::client::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
|
@ -22,7 +22,7 @@ use std::{
|
||||||
pub async fn send_message_event_route(
|
pub async fn send_message_event_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<send_message_event::Request<'_>>,
|
body: Ruma<send_message_event::Request<'_>>,
|
||||||
) -> ConduitResult<send_message_event::Response> {
|
) -> Result<send_message_event::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();
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ pub async fn send_message_event_route(
|
||||||
.map_err(|_| Error::bad_database("Invalid txnid bytes in database."))?
|
.map_err(|_| Error::bad_database("Invalid txnid bytes in database."))?
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(|_| Error::bad_database("Invalid event id in txnid data."))?;
|
.map_err(|_| Error::bad_database("Invalid event id in txnid data."))?;
|
||||||
return Ok(send_message_event::Response { event_id }.into());
|
return Ok(send_message_event::Response { event_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut unsigned = BTreeMap::new();
|
let mut unsigned = BTreeMap::new();
|
||||||
|
@ -94,7 +94,7 @@ pub async fn send_message_event_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(send_message_event::Response::new((*event_id).to_owned()).into())
|
Ok(send_message_event::Response::new((*event_id).to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomId}/messages`
|
/// # `GET /_matrix/client/r0/rooms/{roomId}/messages`
|
||||||
|
@ -107,7 +107,7 @@ pub async fn send_message_event_route(
|
||||||
pub async fn get_message_events_route(
|
pub async fn get_message_events_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_message_events::Request<'_>>,
|
body: Ruma<get_message_events::Request<'_>>,
|
||||||
) -> ConduitResult<get_message_events::Response> {
|
) -> Result<get_message_events::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_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
|
@ -235,5 +235,5 @@ pub async fn get_message_events_route(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(resp.into())
|
Ok(resp)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, utils, ConduitResult, Ruma};
|
use crate::{database::DatabaseGuard, utils, Result, Ruma};
|
||||||
use ruma::api::client::r0::presence::{get_presence, set_presence};
|
use ruma::api::client::r0::presence::{get_presence, set_presence};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ use std::time::Duration;
|
||||||
pub async fn set_presence_route(
|
pub async fn set_presence_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<set_presence::Request<'_>>,
|
body: Ruma<set_presence::Request<'_>>,
|
||||||
) -> ConduitResult<set_presence::Response> {
|
) -> Result<set_presence::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 room_id in db.rooms.rooms_joined(sender_user) {
|
for room_id in db.rooms.rooms_joined(sender_user) {
|
||||||
|
@ -39,7 +39,7 @@ pub async fn set_presence_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(set_presence::Response {}.into())
|
Ok(set_presence::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/presence/{userId}/status`
|
/// # `GET /_matrix/client/r0/presence/{userId}/status`
|
||||||
|
@ -51,7 +51,7 @@ pub async fn set_presence_route(
|
||||||
pub async fn get_presence_route(
|
pub async fn get_presence_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_presence::Request<'_>>,
|
body: Ruma<get_presence::Request<'_>>,
|
||||||
) -> ConduitResult<get_presence::Response> {
|
) -> Result<get_presence::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 presence_event = None;
|
let mut presence_event = None;
|
||||||
|
@ -82,8 +82,7 @@ pub async fn get_presence_route(
|
||||||
.last_active_ago
|
.last_active_ago
|
||||||
.map(|millis| Duration::from_millis(millis.into())),
|
.map(|millis| Duration::from_millis(millis.into())),
|
||||||
presence: presence.content.presence,
|
presence: presence.content.presence,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
} else {
|
} else {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, pdu::PduBuilder, utils, ConduitResult, Error, Ruma};
|
use crate::{database::DatabaseGuard, pdu::PduBuilder, utils, Error, Result, Ruma};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::{
|
api::{
|
||||||
client::{
|
client::{
|
||||||
|
@ -23,7 +23,7 @@ use std::sync::Arc;
|
||||||
pub async fn set_displayname_route(
|
pub async fn set_displayname_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<set_display_name::Request<'_>>,
|
body: Ruma<set_display_name::Request<'_>>,
|
||||||
) -> ConduitResult<set_display_name::Response> {
|
) -> Result<set_display_name::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");
|
||||||
|
|
||||||
db.users
|
db.users
|
||||||
|
@ -109,7 +109,7 @@ pub async fn set_displayname_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(set_display_name::Response {}.into())
|
Ok(set_display_name::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/profile/{userId}/displayname`
|
/// # `GET /_matrix/client/r0/profile/{userId}/displayname`
|
||||||
|
@ -121,7 +121,7 @@ pub async fn set_displayname_route(
|
||||||
pub async fn get_displayname_route(
|
pub async fn get_displayname_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_display_name::Request<'_>>,
|
body: Ruma<get_display_name::Request<'_>>,
|
||||||
) -> ConduitResult<get_display_name::Response> {
|
) -> Result<get_display_name::Response> {
|
||||||
if body.user_id.server_name() != db.globals.server_name() {
|
if body.user_id.server_name() != db.globals.server_name() {
|
||||||
let response = db
|
let response = db
|
||||||
.sending
|
.sending
|
||||||
|
@ -137,14 +137,12 @@ pub async fn get_displayname_route(
|
||||||
|
|
||||||
return Ok(get_display_name::Response {
|
return Ok(get_display_name::Response {
|
||||||
displayname: response.displayname,
|
displayname: response.displayname,
|
||||||
}
|
});
|
||||||
.into());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_display_name::Response {
|
Ok(get_display_name::Response {
|
||||||
displayname: db.users.displayname(&body.user_id)?,
|
displayname: db.users.displayname(&body.user_id)?,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/profile/{userId}/avatar_url`
|
/// # `PUT /_matrix/client/r0/profile/{userId}/avatar_url`
|
||||||
|
@ -156,7 +154,7 @@ pub async fn get_displayname_route(
|
||||||
pub async fn set_avatar_url_route(
|
pub async fn set_avatar_url_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<set_avatar_url::Request<'_>>,
|
body: Ruma<set_avatar_url::Request<'_>>,
|
||||||
) -> ConduitResult<set_avatar_url::Response> {
|
) -> Result<set_avatar_url::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");
|
||||||
|
|
||||||
db.users
|
db.users
|
||||||
|
@ -244,7 +242,7 @@ pub async fn set_avatar_url_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(set_avatar_url::Response {}.into())
|
Ok(set_avatar_url::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/profile/{userId}/avatar_url`
|
/// # `GET /_matrix/client/r0/profile/{userId}/avatar_url`
|
||||||
|
@ -256,7 +254,7 @@ pub async fn set_avatar_url_route(
|
||||||
pub async fn get_avatar_url_route(
|
pub async fn get_avatar_url_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_avatar_url::Request<'_>>,
|
body: Ruma<get_avatar_url::Request<'_>>,
|
||||||
) -> ConduitResult<get_avatar_url::Response> {
|
) -> Result<get_avatar_url::Response> {
|
||||||
if body.user_id.server_name() != db.globals.server_name() {
|
if body.user_id.server_name() != db.globals.server_name() {
|
||||||
let response = db
|
let response = db
|
||||||
.sending
|
.sending
|
||||||
|
@ -273,15 +271,13 @@ pub async fn get_avatar_url_route(
|
||||||
return Ok(get_avatar_url::Response {
|
return Ok(get_avatar_url::Response {
|
||||||
avatar_url: response.avatar_url,
|
avatar_url: response.avatar_url,
|
||||||
blurhash: response.blurhash,
|
blurhash: response.blurhash,
|
||||||
}
|
});
|
||||||
.into());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_avatar_url::Response {
|
Ok(get_avatar_url::Response {
|
||||||
avatar_url: db.users.avatar_url(&body.user_id)?,
|
avatar_url: db.users.avatar_url(&body.user_id)?,
|
||||||
blurhash: db.users.blurhash(&body.user_id)?,
|
blurhash: db.users.blurhash(&body.user_id)?,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/profile/{userId}`
|
/// # `GET /_matrix/client/r0/profile/{userId}`
|
||||||
|
@ -293,7 +289,7 @@ pub async fn get_avatar_url_route(
|
||||||
pub async fn get_profile_route(
|
pub async fn get_profile_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_profile::Request<'_>>,
|
body: Ruma<get_profile::Request<'_>>,
|
||||||
) -> ConduitResult<get_profile::Response> {
|
) -> Result<get_profile::Response> {
|
||||||
if body.user_id.server_name() != db.globals.server_name() {
|
if body.user_id.server_name() != db.globals.server_name() {
|
||||||
let response = db
|
let response = db
|
||||||
.sending
|
.sending
|
||||||
|
@ -311,8 +307,7 @@ pub async fn get_profile_route(
|
||||||
displayname: response.displayname,
|
displayname: response.displayname,
|
||||||
avatar_url: response.avatar_url,
|
avatar_url: response.avatar_url,
|
||||||
blurhash: response.blurhash,
|
blurhash: response.blurhash,
|
||||||
}
|
});
|
||||||
.into());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !db.users.exists(&body.user_id)? {
|
if !db.users.exists(&body.user_id)? {
|
||||||
|
@ -327,6 +322,5 @@ pub async fn get_profile_route(
|
||||||
avatar_url: db.users.avatar_url(&body.user_id)?,
|
avatar_url: db.users.avatar_url(&body.user_id)?,
|
||||||
blurhash: db.users.blurhash(&body.user_id)?,
|
blurhash: db.users.blurhash(&body.user_id)?,
|
||||||
displayname: db.users.displayname(&body.user_id)?,
|
displayname: db.users.displayname(&body.user_id)?,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
use crate::{database::DatabaseGuard, Error, Result, Ruma};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{
|
api::client::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
|
@ -19,7 +19,7 @@ use ruma::{
|
||||||
pub async fn get_pushrules_all_route(
|
pub async fn get_pushrules_all_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_pushrules_all::Request>,
|
body: Ruma<get_pushrules_all::Request>,
|
||||||
) -> ConduitResult<get_pushrules_all::Response> {
|
) -> Result<get_pushrules_all::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: PushRulesEvent = db
|
let event: PushRulesEvent = db
|
||||||
|
@ -32,8 +32,7 @@ pub async fn get_pushrules_all_route(
|
||||||
|
|
||||||
Ok(get_pushrules_all::Response {
|
Ok(get_pushrules_all::Response {
|
||||||
global: event.content.global,
|
global: event.content.global,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
|
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
|
||||||
|
@ -43,7 +42,7 @@ pub async fn get_pushrules_all_route(
|
||||||
pub async fn get_pushrule_route(
|
pub async fn get_pushrule_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_pushrule::Request<'_>>,
|
body: Ruma<get_pushrule::Request<'_>>,
|
||||||
) -> ConduitResult<get_pushrule::Response> {
|
) -> Result<get_pushrule::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: PushRulesEvent = db
|
let event: PushRulesEvent = db
|
||||||
|
@ -80,7 +79,7 @@ pub async fn get_pushrule_route(
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(rule) = rule {
|
if let Some(rule) = rule {
|
||||||
Ok(get_pushrule::Response { rule }.into())
|
Ok(get_pushrule::Response { rule })
|
||||||
} else {
|
} else {
|
||||||
Err(Error::BadRequest(
|
Err(Error::BadRequest(
|
||||||
ErrorKind::NotFound,
|
ErrorKind::NotFound,
|
||||||
|
@ -96,7 +95,7 @@ pub async fn get_pushrule_route(
|
||||||
pub async fn set_pushrule_route(
|
pub async fn set_pushrule_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<set_pushrule::Request<'_>>,
|
body: Ruma<set_pushrule::Request<'_>>,
|
||||||
) -> ConduitResult<set_pushrule::Response> {
|
) -> Result<set_pushrule::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;
|
||||||
|
|
||||||
|
@ -183,7 +182,7 @@ pub async fn set_pushrule_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(set_pushrule::Response {}.into())
|
Ok(set_pushrule::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions`
|
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions`
|
||||||
|
@ -193,7 +192,7 @@ pub async fn set_pushrule_route(
|
||||||
pub async fn get_pushrule_actions_route(
|
pub async fn get_pushrule_actions_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_pushrule_actions::Request<'_>>,
|
body: Ruma<get_pushrule_actions::Request<'_>>,
|
||||||
) -> ConduitResult<get_pushrule_actions::Response> {
|
) -> Result<get_pushrule_actions::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 != "global" {
|
if body.scope != "global" {
|
||||||
|
@ -240,8 +239,7 @@ pub async fn get_pushrule_actions_route(
|
||||||
|
|
||||||
Ok(get_pushrule_actions::Response {
|
Ok(get_pushrule_actions::Response {
|
||||||
actions: actions.unwrap_or_default(),
|
actions: actions.unwrap_or_default(),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions`
|
/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions`
|
||||||
|
@ -251,7 +249,7 @@ pub async fn get_pushrule_actions_route(
|
||||||
pub async fn set_pushrule_actions_route(
|
pub async fn set_pushrule_actions_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<set_pushrule_actions::Request<'_>>,
|
body: Ruma<set_pushrule_actions::Request<'_>>,
|
||||||
) -> ConduitResult<set_pushrule_actions::Response> {
|
) -> Result<set_pushrule_actions::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 != "global" {
|
if body.scope != "global" {
|
||||||
|
@ -309,7 +307,7 @@ pub async fn set_pushrule_actions_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(set_pushrule_actions::Response {}.into())
|
Ok(set_pushrule_actions::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled`
|
/// # `GET /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled`
|
||||||
|
@ -319,7 +317,7 @@ pub async fn set_pushrule_actions_route(
|
||||||
pub async fn get_pushrule_enabled_route(
|
pub async fn get_pushrule_enabled_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_pushrule_enabled::Request<'_>>,
|
body: Ruma<get_pushrule_enabled::Request<'_>>,
|
||||||
) -> ConduitResult<get_pushrule_enabled::Response> {
|
) -> Result<get_pushrule_enabled::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 != "global" {
|
if body.scope != "global" {
|
||||||
|
@ -369,7 +367,7 @@ pub async fn get_pushrule_enabled_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(get_pushrule_enabled::Response { enabled }.into())
|
Ok(get_pushrule_enabled::Response { enabled })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled`
|
/// # `PUT /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled`
|
||||||
|
@ -379,7 +377,7 @@ pub async fn get_pushrule_enabled_route(
|
||||||
pub async fn set_pushrule_enabled_route(
|
pub async fn set_pushrule_enabled_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<set_pushrule_enabled::Request<'_>>,
|
body: Ruma<set_pushrule_enabled::Request<'_>>,
|
||||||
) -> ConduitResult<set_pushrule_enabled::Response> {
|
) -> Result<set_pushrule_enabled::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 != "global" {
|
if body.scope != "global" {
|
||||||
|
@ -442,7 +440,7 @@ pub async fn set_pushrule_enabled_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(set_pushrule_enabled::Response {}.into())
|
Ok(set_pushrule_enabled::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
|
/// # `DELETE /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}`
|
||||||
|
@ -452,7 +450,7 @@ pub async fn set_pushrule_enabled_route(
|
||||||
pub async fn delete_pushrule_route(
|
pub async fn delete_pushrule_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<delete_pushrule::Request<'_>>,
|
body: Ruma<delete_pushrule::Request<'_>>,
|
||||||
) -> ConduitResult<delete_pushrule::Response> {
|
) -> Result<delete_pushrule::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 != "global" {
|
if body.scope != "global" {
|
||||||
|
@ -505,7 +503,7 @@ pub async fn delete_pushrule_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(delete_pushrule::Response {}.into())
|
Ok(delete_pushrule::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/pushers`
|
/// # `GET /_matrix/client/r0/pushers`
|
||||||
|
@ -515,13 +513,12 @@ pub async fn delete_pushrule_route(
|
||||||
pub async fn get_pushers_route(
|
pub async fn get_pushers_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_pushers::Request>,
|
body: Ruma<get_pushers::Request>,
|
||||||
) -> ConduitResult<get_pushers::Response> {
|
) -> Result<get_pushers::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::Response {
|
Ok(get_pushers::Response {
|
||||||
pushers: db.pusher.get_pushers(sender_user)?,
|
pushers: db.pusher.get_pushers(sender_user)?,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/pushers/set`
|
/// # `POST /_matrix/client/r0/pushers/set`
|
||||||
|
@ -533,7 +530,7 @@ pub async fn get_pushers_route(
|
||||||
pub async fn set_pushers_route(
|
pub async fn set_pushers_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<set_pusher::Request>,
|
body: Ruma<set_pusher::Request>,
|
||||||
) -> ConduitResult<set_pusher::Response> {
|
) -> Result<set_pusher::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 pusher = body.pusher.clone();
|
let pusher = body.pusher.clone();
|
||||||
|
|
||||||
|
@ -541,5 +538,5 @@ pub async fn set_pushers_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(set_pusher::Response::default().into())
|
Ok(set_pusher::Response::default())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
use crate::{database::DatabaseGuard, Error, Result, Ruma};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{
|
api::client::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
|
@ -20,7 +20,7 @@ use std::collections::BTreeMap;
|
||||||
pub async fn set_read_marker_route(
|
pub async fn set_read_marker_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<set_read_marker::Request<'_>>,
|
body: Ruma<set_read_marker::Request<'_>>,
|
||||||
) -> ConduitResult<set_read_marker::Response> {
|
) -> Result<set_read_marker::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 fully_read_event = ruma::events::fully_read::FullyReadEvent {
|
let fully_read_event = ruma::events::fully_read::FullyReadEvent {
|
||||||
|
@ -76,7 +76,7 @@ pub async fn set_read_marker_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(set_read_marker::Response {}.into())
|
Ok(set_read_marker::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}`
|
||||||
|
@ -86,7 +86,7 @@ pub async fn set_read_marker_route(
|
||||||
pub async fn create_receipt_route(
|
pub async fn create_receipt_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<create_receipt::Request<'_>>,
|
body: Ruma<create_receipt::Request<'_>>,
|
||||||
) -> ConduitResult<create_receipt::Response> {
|
) -> Result<create_receipt::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");
|
||||||
|
|
||||||
db.rooms.edus.private_read_set(
|
db.rooms.edus.private_read_set(
|
||||||
|
@ -128,5 +128,5 @@ pub async fn create_receipt_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(create_receipt::Response {}.into())
|
Ok(create_receipt::Response {})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{database::DatabaseGuard, pdu::PduBuilder, ConduitResult, Ruma};
|
use crate::{database::DatabaseGuard, pdu::PduBuilder, Result, Ruma};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::r0::redact::redact_event,
|
api::client::r0::redact::redact_event,
|
||||||
events::{room::redaction::RoomRedactionEventContent, EventType},
|
events::{room::redaction::RoomRedactionEventContent, EventType},
|
||||||
|
@ -17,7 +17,7 @@ use serde_json::value::to_raw_value;
|
||||||
pub async fn redact_event_route(
|
pub async fn redact_event_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<redact_event::Request<'_>>,
|
body: Ruma<redact_event::Request<'_>>,
|
||||||
) -> ConduitResult<redact_event::Response> {
|
) -> Result<redact_event::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;
|
||||||
|
|
||||||
|
@ -53,5 +53,5 @@ pub async fn redact_event_route(
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
let event_id = (*event_id).to_owned();
|
let event_id = (*event_id).to_owned();
|
||||||
Ok(redact_event::Response { event_id }.into())
|
Ok(redact_event::Response { event_id })
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, utils::HtmlEscape, ConduitResult, Error, Ruma};
|
use crate::{database::DatabaseGuard, utils::HtmlEscape, Error, Result, Ruma};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{error::ErrorKind, r0::room::report_content},
|
api::client::{error::ErrorKind, r0::room::report_content},
|
||||||
events::room::message,
|
events::room::message,
|
||||||
|
@ -13,7 +13,7 @@ use ruma::{
|
||||||
pub async fn report_event_route(
|
pub async fn report_event_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<report_content::Request<'_>>,
|
body: Ruma<report_content::Request<'_>>,
|
||||||
) -> ConduitResult<report_content::Response> {
|
) -> Result<report_content::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 pdu = match db.rooms.get_pdu(&body.event_id)? {
|
let pdu = match db.rooms.get_pdu(&body.event_id)? {
|
||||||
|
@ -69,5 +69,5 @@ pub async fn report_event_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(report_content::Response {}.into())
|
Ok(report_content::Response {})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
client_server::invite_helper, database::DatabaseGuard, pdu::PduBuilder, ConduitResult, Error,
|
client_server::invite_helper, database::DatabaseGuard, pdu::PduBuilder, Error, Result, Ruma,
|
||||||
Ruma,
|
|
||||||
};
|
};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{
|
api::client::{
|
||||||
|
@ -50,7 +49,7 @@ use tracing::{info, warn};
|
||||||
pub async fn create_room_route(
|
pub async fn create_room_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<create_room::Request<'_>>,
|
body: Ruma<create_room::Request<'_>>,
|
||||||
) -> ConduitResult<create_room::Response> {
|
) -> Result<create_room::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 room_id = RoomId::new(db.globals.server_name());
|
let room_id = RoomId::new(db.globals.server_name());
|
||||||
|
@ -410,7 +409,7 @@ pub async fn create_room_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(create_room::Response::new(room_id).into())
|
Ok(create_room::Response::new(room_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomId}/event/{eventId}`
|
/// # `GET /_matrix/client/r0/rooms/{roomId}/event/{eventId}`
|
||||||
|
@ -422,7 +421,7 @@ pub async fn create_room_route(
|
||||||
pub async fn get_room_event_route(
|
pub async fn get_room_event_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_room_event::Request<'_>>,
|
body: Ruma<get_room_event::Request<'_>>,
|
||||||
) -> ConduitResult<get_room_event::Response> {
|
) -> Result<get_room_event::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 !db.rooms.is_joined(sender_user, &body.room_id)? {
|
if !db.rooms.is_joined(sender_user, &body.room_id)? {
|
||||||
|
@ -438,8 +437,7 @@ pub async fn get_room_event_route(
|
||||||
.get_pdu(&body.event_id)?
|
.get_pdu(&body.event_id)?
|
||||||
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Event not found."))?
|
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Event not found."))?
|
||||||
.to_room_event(),
|
.to_room_event(),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomId}/aliases`
|
/// # `GET /_matrix/client/r0/rooms/{roomId}/aliases`
|
||||||
|
@ -451,7 +449,7 @@ pub async fn get_room_event_route(
|
||||||
pub async fn get_room_aliases_route(
|
pub async fn get_room_aliases_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<aliases::Request<'_>>,
|
body: Ruma<aliases::Request<'_>>,
|
||||||
) -> ConduitResult<aliases::Response> {
|
) -> Result<aliases::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 !db.rooms.is_joined(sender_user, &body.room_id)? {
|
if !db.rooms.is_joined(sender_user, &body.room_id)? {
|
||||||
|
@ -467,8 +465,7 @@ pub async fn get_room_aliases_route(
|
||||||
.room_aliases(&body.room_id)
|
.room_aliases(&body.room_id)
|
||||||
.filter_map(|a| a.ok())
|
.filter_map(|a| a.ok())
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/rooms/{roomId}/upgrade`
|
/// # `POST /_matrix/client/r0/rooms/{roomId}/upgrade`
|
||||||
|
@ -485,7 +482,7 @@ pub async fn get_room_aliases_route(
|
||||||
pub async fn upgrade_room_route(
|
pub async fn upgrade_room_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<upgrade_room::Request<'_>>,
|
body: Ruma<upgrade_room::Request<'_>>,
|
||||||
) -> ConduitResult<upgrade_room::Response> {
|
) -> Result<upgrade_room::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!(body.new_version, RoomVersionId::V5 | RoomVersionId::V6) {
|
if !matches!(body.new_version, RoomVersionId::V5 | RoomVersionId::V6) {
|
||||||
|
@ -709,5 +706,5 @@ pub async fn upgrade_room_route(
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
// Return the replacement room id
|
// Return the replacement room id
|
||||||
Ok(upgrade_room::Response { replacement_room }.into())
|
Ok(upgrade_room::Response { replacement_room })
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
use crate::{database::DatabaseGuard, Error, Result, Ruma};
|
||||||
use ruma::api::client::{error::ErrorKind, r0::search::search_events};
|
use ruma::api::client::{error::ErrorKind, r0::search::search_events};
|
||||||
|
|
||||||
use search_events::{EventContextResult, ResultCategories, ResultRoomEvents, SearchResult};
|
use search_events::{EventContextResult, ResultCategories, ResultRoomEvents, SearchResult};
|
||||||
|
@ -13,7 +13,7 @@ use std::collections::BTreeMap;
|
||||||
pub async fn search_events_route(
|
pub async fn search_events_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<search_events::Request<'_>>,
|
body: Ruma<search_events::Request<'_>>,
|
||||||
) -> ConduitResult<search_events::Response> {
|
) -> Result<search_events::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();
|
||||||
|
@ -111,6 +111,5 @@ pub async fn search_events_route(
|
||||||
.map(str::to_lowercase)
|
.map(str::to_lowercase)
|
||||||
.collect(),
|
.collect(),
|
||||||
},
|
},
|
||||||
})
|
}))
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use super::{DEVICE_ID_LENGTH, TOKEN_LENGTH};
|
use super::{DEVICE_ID_LENGTH, TOKEN_LENGTH};
|
||||||
use crate::{database::DatabaseGuard, utils, ConduitResult, Error, Ruma};
|
use crate::{database::DatabaseGuard, utils, Error, Result, Ruma};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{
|
api::client::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
|
@ -26,13 +26,10 @@ struct Claims {
|
||||||
#[tracing::instrument(skip(_body))]
|
#[tracing::instrument(skip(_body))]
|
||||||
pub async fn get_login_types_route(
|
pub async fn get_login_types_route(
|
||||||
_body: Ruma<get_login_types::Request>,
|
_body: Ruma<get_login_types::Request>,
|
||||||
) -> ConduitResult<get_login_types::Response> {
|
) -> Result<get_login_types::Response> {
|
||||||
Ok(
|
Ok(get_login_types::Response::new(vec![
|
||||||
get_login_types::Response::new(vec![get_login_types::LoginType::Password(
|
get_login_types::LoginType::Password(Default::default()),
|
||||||
Default::default(),
|
]))
|
||||||
)])
|
|
||||||
.into(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/login`
|
/// # `POST /_matrix/client/r0/login`
|
||||||
|
@ -50,7 +47,7 @@ pub async fn get_login_types_route(
|
||||||
pub async fn login_route(
|
pub async fn login_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<login::Request<'_>>,
|
body: Ruma<login::Request<'_>>,
|
||||||
) -> ConduitResult<login::Response> {
|
) -> Result<login::Response> {
|
||||||
// Validate login method
|
// Validate login method
|
||||||
// TODO: Other login methods
|
// TODO: Other login methods
|
||||||
let user_id = match &body.login_info {
|
let user_id = match &body.login_info {
|
||||||
|
@ -155,8 +152,7 @@ pub async fn login_route(
|
||||||
home_server: Some(db.globals.server_name().to_owned()),
|
home_server: Some(db.globals.server_name().to_owned()),
|
||||||
device_id,
|
device_id,
|
||||||
well_known: None,
|
well_known: None,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/logout`
|
/// # `POST /_matrix/client/r0/logout`
|
||||||
|
@ -171,7 +167,7 @@ pub async fn login_route(
|
||||||
pub async fn logout_route(
|
pub async fn logout_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<logout::Request>,
|
body: Ruma<logout::Request>,
|
||||||
) -> ConduitResult<logout::Response> {
|
) -> Result<logout::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_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
|
@ -179,7 +175,7 @@ pub async fn logout_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(logout::Response::new().into())
|
Ok(logout::Response::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/logout/all`
|
/// # `POST /_matrix/client/r0/logout/all`
|
||||||
|
@ -197,7 +193,7 @@ pub async fn logout_route(
|
||||||
pub async fn logout_all_route(
|
pub async fn logout_all_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<logout_all::Request>,
|
body: Ruma<logout_all::Request>,
|
||||||
) -> ConduitResult<logout_all::Response> {
|
) -> Result<logout_all::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 device_id in db.users.all_device_ids(sender_user).flatten() {
|
for device_id in db.users.all_device_ids(sender_user).flatten() {
|
||||||
|
@ -206,5 +202,5 @@ pub async fn logout_all_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(logout_all::Response::new().into())
|
Ok(logout_all::Response::new())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
database::DatabaseGuard, pdu::PduBuilder, ConduitResult, Database, Error, Result, Ruma,
|
database::DatabaseGuard, pdu::PduBuilder, Database, Error, Result, Ruma, RumaResponse,
|
||||||
};
|
};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{
|
api::client::{
|
||||||
|
@ -30,7 +30,7 @@ use ruma::{
|
||||||
pub async fn send_state_event_for_key_route(
|
pub async fn send_state_event_for_key_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<send_state_event::Request<'_>>,
|
body: Ruma<send_state_event::Request<'_>>,
|
||||||
) -> ConduitResult<send_state_event::Response> {
|
) -> Result<send_state_event::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(
|
||||||
|
@ -46,7 +46,7 @@ pub async fn send_state_event_for_key_route(
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
let event_id = (*event_id).to_owned();
|
let event_id = (*event_id).to_owned();
|
||||||
Ok(send_state_event::Response { event_id }.into())
|
Ok(send_state_event::Response { event_id })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}`
|
/// # `PUT /_matrix/client/r0/rooms/{roomId}/state/{eventType}`
|
||||||
|
@ -60,7 +60,7 @@ pub async fn send_state_event_for_key_route(
|
||||||
pub async fn send_state_event_for_empty_key_route(
|
pub async fn send_state_event_for_empty_key_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<send_state_event::Request<'_>>,
|
body: Ruma<send_state_event::Request<'_>>,
|
||||||
) -> ConduitResult<send_state_event::Response> {
|
) -> Result<RumaResponse<send_state_event::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");
|
||||||
|
|
||||||
// Forbid m.room.encryption if encryption is disabled
|
// Forbid m.room.encryption if encryption is disabled
|
||||||
|
@ -96,7 +96,7 @@ pub async fn send_state_event_for_empty_key_route(
|
||||||
pub async fn get_state_events_route(
|
pub async fn get_state_events_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_state_events::Request<'_>>,
|
body: Ruma<get_state_events::Request<'_>>,
|
||||||
) -> ConduitResult<get_state_events::Response> {
|
) -> Result<get_state_events::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");
|
||||||
|
|
||||||
#[allow(clippy::blocks_in_if_conditions)]
|
#[allow(clippy::blocks_in_if_conditions)]
|
||||||
|
@ -131,8 +131,7 @@ pub async fn get_state_events_route(
|
||||||
.values()
|
.values()
|
||||||
.map(|pdu| pdu.to_state_event())
|
.map(|pdu| pdu.to_state_event())
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomid}/state/{eventType}/{stateKey}`
|
/// # `GET /_matrix/client/r0/rooms/{roomid}/state/{eventType}/{stateKey}`
|
||||||
|
@ -144,7 +143,7 @@ pub async fn get_state_events_route(
|
||||||
pub async fn get_state_events_for_key_route(
|
pub async fn get_state_events_for_key_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_state_events_for_key::Request<'_>>,
|
body: Ruma<get_state_events_for_key::Request<'_>>,
|
||||||
) -> ConduitResult<get_state_events_for_key::Response> {
|
) -> Result<get_state_events_for_key::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");
|
||||||
|
|
||||||
#[allow(clippy::blocks_in_if_conditions)]
|
#[allow(clippy::blocks_in_if_conditions)]
|
||||||
|
@ -183,8 +182,7 @@ pub async fn get_state_events_for_key_route(
|
||||||
Ok(get_state_events_for_key::Response {
|
Ok(get_state_events_for_key::Response {
|
||||||
content: serde_json::from_str(event.content.get())
|
content: serde_json::from_str(event.content.get())
|
||||||
.map_err(|_| Error::bad_database("Invalid event content in database"))?,
|
.map_err(|_| Error::bad_database("Invalid event content in database"))?,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/rooms/{roomid}/state/{eventType}`
|
/// # `GET /_matrix/client/r0/rooms/{roomid}/state/{eventType}`
|
||||||
|
@ -196,7 +194,7 @@ pub async fn get_state_events_for_key_route(
|
||||||
pub async fn get_state_events_for_empty_key_route(
|
pub async fn get_state_events_for_empty_key_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_state_events_for_key::Request<'_>>,
|
body: Ruma<get_state_events_for_key::Request<'_>>,
|
||||||
) -> ConduitResult<get_state_events_for_key::Response> {
|
) -> Result<RumaResponse<get_state_events_for_key::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");
|
||||||
|
|
||||||
#[allow(clippy::blocks_in_if_conditions)]
|
#[allow(clippy::blocks_in_if_conditions)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, ConduitResult, Database, Error, Result, Ruma, RumaResponse};
|
use crate::{database::DatabaseGuard, Database, Error, Result, Ruma, RumaResponse};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::r0::{
|
api::client::r0::{
|
||||||
filter::{IncomingFilterDefinition, LazyLoadOptions},
|
filter::{IncomingFilterDefinition, LazyLoadOptions},
|
||||||
|
@ -58,7 +58,7 @@ use tracing::error;
|
||||||
pub async fn sync_events_route(
|
pub async fn sync_events_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<sync_events::Request<'_>>,
|
body: Ruma<sync_events::Request<'_>>,
|
||||||
) -> Result<RumaResponse<sync_events::Response>, RumaResponse<UiaaResponse>> {
|
) -> Result<sync_events::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;
|
||||||
|
@ -132,7 +132,7 @@ async fn sync_helper_wrapper(
|
||||||
sender_user: Box<UserId>,
|
sender_user: Box<UserId>,
|
||||||
sender_device: Box<DeviceId>,
|
sender_device: Box<DeviceId>,
|
||||||
body: sync_events::IncomingRequest,
|
body: sync_events::IncomingRequest,
|
||||||
tx: Sender<Option<ConduitResult<sync_events::Response>>>,
|
tx: Sender<Option<Result<sync_events::Response>>>,
|
||||||
) {
|
) {
|
||||||
let since = body.since.clone();
|
let since = body.since.clone();
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ async fn sync_helper_wrapper(
|
||||||
|
|
||||||
drop(db);
|
drop(db);
|
||||||
|
|
||||||
let _ = tx.send(Some(r.map(|(r, _)| r.into())));
|
let _ = tx.send(Some(r.map(|(r, _)| r)));
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn sync_helper(
|
async fn sync_helper(
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, ConduitResult, Ruma};
|
use crate::{database::DatabaseGuard, Result, Ruma};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::r0::tag::{create_tag, delete_tag, get_tags},
|
api::client::r0::tag::{create_tag, delete_tag, get_tags},
|
||||||
events::{
|
events::{
|
||||||
|
@ -17,7 +17,7 @@ use std::collections::BTreeMap;
|
||||||
pub async fn update_tag_route(
|
pub async fn update_tag_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<create_tag::Request<'_>>,
|
body: Ruma<create_tag::Request<'_>>,
|
||||||
) -> ConduitResult<create_tag::Response> {
|
) -> Result<create_tag::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 tags_event = db
|
let mut tags_event = db
|
||||||
|
@ -43,7 +43,7 @@ pub async fn update_tag_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(create_tag::Response {}.into())
|
Ok(create_tag::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}`
|
/// # `DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}`
|
||||||
|
@ -55,7 +55,7 @@ pub async fn update_tag_route(
|
||||||
pub async fn delete_tag_route(
|
pub async fn delete_tag_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<delete_tag::Request<'_>>,
|
body: Ruma<delete_tag::Request<'_>>,
|
||||||
) -> ConduitResult<delete_tag::Response> {
|
) -> Result<delete_tag::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 tags_event = db
|
let mut tags_event = db
|
||||||
|
@ -78,7 +78,7 @@ pub async fn delete_tag_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(delete_tag::Response {}.into())
|
Ok(delete_tag::Response {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags`
|
/// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags`
|
||||||
|
@ -90,7 +90,7 @@ pub async fn delete_tag_route(
|
||||||
pub async fn get_tags_route(
|
pub async fn get_tags_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_tags::Request<'_>>,
|
body: Ruma<get_tags::Request<'_>>,
|
||||||
) -> ConduitResult<get_tags::Response> {
|
) -> Result<get_tags::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_tags::Response {
|
Ok(get_tags::Response {
|
||||||
|
@ -104,6 +104,5 @@ pub async fn get_tags_route(
|
||||||
})
|
})
|
||||||
.content
|
.content
|
||||||
.tags,
|
.tags,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{ConduitResult, Ruma};
|
use crate::{Result, Ruma};
|
||||||
use ruma::api::client::r0::thirdparty::get_protocols;
|
use ruma::api::client::r0::thirdparty::get_protocols;
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
@ -9,10 +9,9 @@ use std::collections::BTreeMap;
|
||||||
#[tracing::instrument(skip(_body))]
|
#[tracing::instrument(skip(_body))]
|
||||||
pub async fn get_protocols_route(
|
pub async fn get_protocols_route(
|
||||||
_body: Ruma<get_protocols::Request>,
|
_body: Ruma<get_protocols::Request>,
|
||||||
) -> ConduitResult<get_protocols::Response> {
|
) -> Result<get_protocols::Response> {
|
||||||
// TODO
|
// TODO
|
||||||
Ok(get_protocols::Response {
|
Ok(get_protocols::Response {
|
||||||
protocols: BTreeMap::new(),
|
protocols: BTreeMap::new(),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use crate::{database::DatabaseGuard, ConduitResult, Error, Ruma};
|
use crate::{database::DatabaseGuard, Error, Result, Ruma};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::{
|
api::{
|
||||||
client::{error::ErrorKind, r0::to_device::send_event_to_device},
|
client::{error::ErrorKind, r0::to_device::send_event_to_device},
|
||||||
|
@ -17,7 +17,7 @@ use ruma::{
|
||||||
pub async fn send_event_to_device_route(
|
pub async fn send_event_to_device_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<send_event_to_device::Request<'_>>,
|
body: Ruma<send_event_to_device::Request<'_>>,
|
||||||
) -> ConduitResult<send_event_to_device::Response> {
|
) -> Result<send_event_to_device::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();
|
||||||
|
|
||||||
|
@ -94,5 +94,5 @@ pub async fn send_event_to_device_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(send_event_to_device::Response {}.into())
|
Ok(send_event_to_device::Response {})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, utils, ConduitResult, Ruma};
|
use crate::{database::DatabaseGuard, utils, Result, Ruma};
|
||||||
use create_typing_event::Typing;
|
use create_typing_event::Typing;
|
||||||
use ruma::api::client::r0::typing::create_typing_event;
|
use ruma::api::client::r0::typing::create_typing_event;
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ use ruma::api::client::r0::typing::create_typing_event;
|
||||||
pub async fn create_typing_event_route(
|
pub async fn create_typing_event_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<create_typing_event::Request<'_>>,
|
body: Ruma<create_typing_event::Request<'_>>,
|
||||||
) -> ConduitResult<create_typing_event::Response> {
|
) -> Result<create_typing_event::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 Typing::Yes(duration) = body.state {
|
if let Typing::Yes(duration) = body.state {
|
||||||
|
@ -25,5 +25,5 @@ pub async fn create_typing_event_route(
|
||||||
.typing_remove(sender_user, &body.room_id, &db.globals)?;
|
.typing_remove(sender_user, &body.room_id, &db.globals)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(create_typing_event::Response {}.into())
|
Ok(create_typing_event::Response {})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{collections::BTreeMap, iter::FromIterator};
|
use std::{collections::BTreeMap, iter::FromIterator};
|
||||||
|
|
||||||
use crate::{ConduitResult, Ruma};
|
use crate::{Result, Ruma};
|
||||||
use ruma::api::client::unversioned::get_supported_versions;
|
use ruma::api::client::unversioned::get_supported_versions;
|
||||||
|
|
||||||
/// # `GET /_matrix/client/versions`
|
/// # `GET /_matrix/client/versions`
|
||||||
|
@ -16,11 +16,11 @@ use ruma::api::client::unversioned::get_supported_versions;
|
||||||
#[tracing::instrument(skip(_body))]
|
#[tracing::instrument(skip(_body))]
|
||||||
pub async fn get_supported_versions_route(
|
pub async fn get_supported_versions_route(
|
||||||
_body: Ruma<get_supported_versions::Request>,
|
_body: Ruma<get_supported_versions::Request>,
|
||||||
) -> ConduitResult<get_supported_versions::Response> {
|
) -> Result<get_supported_versions::Response> {
|
||||||
let resp = get_supported_versions::Response {
|
let resp = get_supported_versions::Response {
|
||||||
versions: vec!["r0.5.0".to_owned(), "r0.6.0".to_owned()],
|
versions: vec!["r0.5.0".to_owned(), "r0.6.0".to_owned()],
|
||||||
unstable_features: BTreeMap::from_iter([("org.matrix.e2e_cross_signing".to_owned(), true)]),
|
unstable_features: BTreeMap::from_iter([("org.matrix.e2e_cross_signing".to_owned(), true)]),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(resp.into())
|
Ok(resp)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::DatabaseGuard, ConduitResult, Ruma};
|
use crate::{database::DatabaseGuard, Result, Ruma};
|
||||||
use ruma::api::client::r0::user_directory::search_users;
|
use ruma::api::client::r0::user_directory::search_users;
|
||||||
|
|
||||||
/// # `POST /_matrix/client/r0/user_directory/search`
|
/// # `POST /_matrix/client/r0/user_directory/search`
|
||||||
|
@ -10,7 +10,7 @@ use ruma::api::client::r0::user_directory::search_users;
|
||||||
pub async fn search_users_route(
|
pub async fn search_users_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<search_users::Request<'_>>,
|
body: Ruma<search_users::Request<'_>>,
|
||||||
) -> ConduitResult<search_users::Response> {
|
) -> Result<search_users::Response> {
|
||||||
let limit = u64::from(body.limit) as usize;
|
let limit = u64::from(body.limit) as usize;
|
||||||
|
|
||||||
let mut users = db.users.iter().filter_map(|user_id| {
|
let mut users = db.users.iter().filter_map(|user_id| {
|
||||||
|
@ -48,5 +48,5 @@ pub 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::Response { results, limited }.into())
|
Ok(search_users::Response { results, limited })
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::{database::DatabaseGuard, ConduitResult, Ruma};
|
use crate::{database::DatabaseGuard, Result, Ruma};
|
||||||
use hmac::{Hmac, Mac, NewMac};
|
use hmac::{Hmac, Mac, NewMac};
|
||||||
use ruma::api::client::r0::voip::get_turn_server_info;
|
use ruma::{api::client::r0::voip::get_turn_server_info, SecondsSinceUnixEpoch};
|
||||||
use ruma::SecondsSinceUnixEpoch;
|
|
||||||
use sha1::Sha1;
|
use sha1::Sha1;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
|
@ -14,7 +13,7 @@ type HmacSha1 = Hmac<Sha1>;
|
||||||
pub async fn turn_server_route(
|
pub async fn turn_server_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_turn_server_info::Request>,
|
body: Ruma<get_turn_server_info::Request>,
|
||||||
) -> ConduitResult<get_turn_server_info::Response> {
|
) -> Result<get_turn_server_info::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 = db.globals.turn_secret();
|
let turn_secret = db.globals.turn_secret();
|
||||||
|
@ -46,6 +45,5 @@ pub async fn turn_server_route(
|
||||||
password,
|
password,
|
||||||
uris: db.globals.turn_uris().to_vec(),
|
uris: db.globals.turn_uris().to_vec(),
|
||||||
ttl: Duration::from_secs(db.globals.turn_ttl()),
|
ttl: Duration::from_secs(db.globals.turn_ttl()),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
use super::{super::Config, watchers::Watchers, DatabaseEngine, Tree};
|
use super::{super::Config, watchers::Watchers, DatabaseEngine, Tree};
|
||||||
use crate::{utils, Result};
|
use crate::{utils, Result};
|
||||||
use std::{future::Future, pin::Pin, sync::Arc, sync::RwLock};
|
use std::{
|
||||||
|
future::Future,
|
||||||
|
pin::Pin,
|
||||||
|
sync::{Arc, RwLock},
|
||||||
|
};
|
||||||
|
|
||||||
pub struct Engine {
|
pub struct Engine {
|
||||||
rocks: rocksdb::DBWithThreadMode<rocksdb::MultiThreaded>,
|
rocks: rocksdb::DBWithThreadMode<rocksdb::MultiThreaded>,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{database::Config, server_server::FedDest, utils, ConduitResult, Error, Result};
|
use crate::{database::Config, server_server::FedDest, utils, Error, Result};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::{
|
api::{
|
||||||
client::r0::sync::sync_events,
|
client::r0::sync::sync_events,
|
||||||
|
@ -28,7 +28,7 @@ type TlsNameMap = HashMap<String, (Vec<IpAddr>, u16)>;
|
||||||
type RateLimitState = (Instant, u32); // Time if last failed try, number of failed tries
|
type RateLimitState = (Instant, u32); // Time if last failed try, number of failed tries
|
||||||
type SyncHandle = (
|
type SyncHandle = (
|
||||||
Option<String>, // since
|
Option<String>, // since
|
||||||
Receiver<Option<ConduitResult<sync_events::Response>>>, // rx
|
Receiver<Option<Result<sync_events::Response>>>, // rx
|
||||||
);
|
);
|
||||||
|
|
||||||
pub struct Globals {
|
pub struct Globals {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::collections::BTreeMap;
|
use std::{
|
||||||
use std::sync::Arc;
|
collections::BTreeMap,
|
||||||
use std::sync::RwLock;
|
sync::{Arc, RwLock},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{client_server::SESSION_ID_LENGTH, utils, Error, Result};
|
use crate::{client_server::SESSION_ID_LENGTH, utils, Error, Result};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
|
|
|
@ -22,4 +22,4 @@ pub use config::Config;
|
||||||
pub use database::Database;
|
pub use database::Database;
|
||||||
pub use error::{Error, Result};
|
pub use error::{Error, Result};
|
||||||
pub use pdu::PduEvent;
|
pub use pdu::PduEvent;
|
||||||
pub use ruma_wrapper::{ConduitResult, Ruma, RumaResponse};
|
pub use ruma_wrapper::{Ruma, RumaResponse};
|
||||||
|
|
62
src/main.rs
62
src/main.rs
|
@ -11,7 +11,6 @@ use std::{future::Future, net::SocketAddr, sync::Arc, time::Duration};
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{FromRequest, MatchedPath},
|
extract::{FromRequest, MatchedPath},
|
||||||
handler::Handler,
|
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
routing::{get, on, MethodFilter},
|
routing::{get, on, MethodFilter},
|
||||||
Router,
|
Router,
|
||||||
|
@ -25,10 +24,7 @@ use http::{
|
||||||
Method,
|
Method,
|
||||||
};
|
};
|
||||||
use opentelemetry::trace::{FutureExt, Tracer};
|
use opentelemetry::trace::{FutureExt, Tracer};
|
||||||
use ruma::{
|
use ruma::{api::IncomingRequest, Outgoing};
|
||||||
api::{IncomingRequest, Metadata},
|
|
||||||
Outgoing,
|
|
||||||
};
|
|
||||||
use tokio::{signal, sync::RwLock};
|
use tokio::{signal, sync::RwLock};
|
||||||
use tower::ServiceBuilder;
|
use tower::ServiceBuilder;
|
||||||
use tower_http::{
|
use tower_http::{
|
||||||
|
@ -353,25 +349,15 @@ impl RouterExt for Router {
|
||||||
H: RumaHandler<T>,
|
H: RumaHandler<T>,
|
||||||
T: 'static,
|
T: 'static,
|
||||||
{
|
{
|
||||||
let meta = H::METADATA;
|
handler.add_to_router(self)
|
||||||
let method_filter = match meta.method {
|
|
||||||
Method::DELETE => MethodFilter::DELETE,
|
|
||||||
Method::GET => MethodFilter::GET,
|
|
||||||
Method::HEAD => MethodFilter::HEAD,
|
|
||||||
Method::OPTIONS => MethodFilter::OPTIONS,
|
|
||||||
Method::PATCH => MethodFilter::PATCH,
|
|
||||||
Method::POST => MethodFilter::POST,
|
|
||||||
Method::PUT => MethodFilter::PUT,
|
|
||||||
Method::TRACE => MethodFilter::TRACE,
|
|
||||||
m => panic!("Unsupported HTTP method: {:?}", m),
|
|
||||||
};
|
|
||||||
|
|
||||||
self.route(meta.path, on(method_filter, handler))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait RumaHandler<T>: Handler<T> {
|
pub trait RumaHandler<T> {
|
||||||
const METADATA: Metadata;
|
// Can't transform to a handler without boxing or relying on the nightly-only
|
||||||
|
// impl-trait-in-traits feature. Moving a small amount of extra logic into the trait
|
||||||
|
// allows bypassing both.
|
||||||
|
fn add_to_router(self, router: Router) -> Router;
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_ruma_handler {
|
macro_rules! impl_ruma_handler {
|
||||||
|
@ -380,17 +366,22 @@ macro_rules! impl_ruma_handler {
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
impl<Req, E, F, Fut, $($ty,)*> RumaHandler<($($ty,)* Ruma<Req>,)> for F
|
impl<Req, E, F, Fut, $($ty,)*> RumaHandler<($($ty,)* Ruma<Req>,)> for F
|
||||||
where
|
where
|
||||||
Req: Outgoing,
|
Req: Outgoing + 'static,
|
||||||
Req::Incoming: IncomingRequest + Send,
|
Req::Incoming: IncomingRequest + Send,
|
||||||
F: FnOnce($($ty,)* Ruma<Req>) -> Fut + Clone + Send + 'static,
|
F: FnOnce($($ty,)* Ruma<Req>) -> Fut + Clone + Send + 'static,
|
||||||
Fut: Future<Output = Result<
|
Fut: Future<Output = Result<<Req::Incoming as IncomingRequest>::OutgoingResponse, E>>
|
||||||
RumaResponse<<Req::Incoming as IncomingRequest>::OutgoingResponse>,
|
+ Send,
|
||||||
E,
|
|
||||||
>> + Send,
|
|
||||||
E: IntoResponse,
|
E: IntoResponse,
|
||||||
$( $ty: FromRequest<axum::body::Body> + Send, )*
|
$( $ty: FromRequest<axum::body::Body> + Send + 'static, )*
|
||||||
{
|
{
|
||||||
const METADATA: Metadata = Req::Incoming::METADATA;
|
fn add_to_router(self, router: Router) -> Router {
|
||||||
|
let meta = Req::Incoming::METADATA;
|
||||||
|
let method_filter = method_to_filter(meta.method);
|
||||||
|
|
||||||
|
router.route(meta.path, on(method_filter, |$( $ty: $ty, )* req| async move {
|
||||||
|
self($($ty,)* req).await.map(RumaResponse)
|
||||||
|
}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -404,3 +395,18 @@ impl_ruma_handler!(T1, T2, T3, T4, T5);
|
||||||
impl_ruma_handler!(T1, T2, T3, T4, T5, T6);
|
impl_ruma_handler!(T1, T2, T3, T4, T5, T6);
|
||||||
impl_ruma_handler!(T1, T2, T3, T4, T5, T6, T7);
|
impl_ruma_handler!(T1, T2, T3, T4, T5, T6, T7);
|
||||||
impl_ruma_handler!(T1, T2, T3, T4, T5, T6, T7, T8);
|
impl_ruma_handler!(T1, T2, T3, T4, T5, T6, T7, T8);
|
||||||
|
|
||||||
|
fn method_to_filter(method: Method) -> MethodFilter {
|
||||||
|
let method_filter = match method {
|
||||||
|
Method::DELETE => MethodFilter::DELETE,
|
||||||
|
Method::GET => MethodFilter::GET,
|
||||||
|
Method::HEAD => MethodFilter::HEAD,
|
||||||
|
Method::OPTIONS => MethodFilter::OPTIONS,
|
||||||
|
Method::PATCH => MethodFilter::PATCH,
|
||||||
|
Method::POST => MethodFilter::POST,
|
||||||
|
Method::PUT => MethodFilter::PUT,
|
||||||
|
Method::TRACE => MethodFilter::TRACE,
|
||||||
|
m => panic!("Unsupported HTTP method: {:?}", m),
|
||||||
|
};
|
||||||
|
method_filter
|
||||||
|
}
|
||||||
|
|
|
@ -29,9 +29,6 @@ impl<T: Outgoing> Deref for Ruma<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This struct converts ruma structs to http responses.
|
|
||||||
pub type ConduitResult<T> = Result<RumaResponse<T>, Error>;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct RumaResponse<T>(pub T);
|
pub struct RumaResponse<T>(pub T);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
||||||
client_server::{self, claim_keys_helper, get_keys_helper},
|
client_server::{self, claim_keys_helper, get_keys_helper},
|
||||||
database::{rooms::CompressedStateEvent, DatabaseGuard},
|
database::{rooms::CompressedStateEvent, DatabaseGuard},
|
||||||
pdu::EventHash,
|
pdu::EventHash,
|
||||||
utils, ConduitResult, Database, Error, PduEvent, Result, Ruma,
|
utils, Database, Error, PduEvent, Result, Ruma,
|
||||||
};
|
};
|
||||||
use axum::{response::IntoResponse, Json};
|
use axum::{response::IntoResponse, Json};
|
||||||
use futures_util::{stream::FuturesUnordered, StreamExt};
|
use futures_util::{stream::FuturesUnordered, StreamExt};
|
||||||
|
@ -494,7 +494,7 @@ async fn request_well_known(
|
||||||
pub async fn get_server_version_route(
|
pub async fn get_server_version_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
_body: Ruma<get_server_version::v1::Request>,
|
_body: Ruma<get_server_version::v1::Request>,
|
||||||
) -> ConduitResult<get_server_version::v1::Response> {
|
) -> Result<get_server_version::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -504,8 +504,7 @@ pub async fn get_server_version_route(
|
||||||
name: Some("Conduit".to_owned()),
|
name: Some("Conduit".to_owned()),
|
||||||
version: Some(env!("CARGO_PKG_VERSION").to_owned()),
|
version: Some(env!("CARGO_PKG_VERSION").to_owned()),
|
||||||
}),
|
}),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/key/v2/server`
|
/// # `GET /_matrix/key/v2/server`
|
||||||
|
@ -577,7 +576,7 @@ pub async fn get_server_keys_deprecated_route(db: DatabaseGuard) -> impl IntoRes
|
||||||
pub async fn get_public_rooms_filtered_route(
|
pub async fn get_public_rooms_filtered_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_public_rooms_filtered::v1::Request<'_>>,
|
body: Ruma<get_public_rooms_filtered::v1::Request<'_>>,
|
||||||
) -> ConduitResult<get_public_rooms_filtered::v1::Response> {
|
) -> Result<get_public_rooms_filtered::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -590,8 +589,7 @@ pub async fn get_public_rooms_filtered_route(
|
||||||
&body.filter,
|
&body.filter,
|
||||||
&body.room_network,
|
&body.room_network,
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.0;
|
|
||||||
|
|
||||||
Ok(get_public_rooms_filtered::v1::Response {
|
Ok(get_public_rooms_filtered::v1::Response {
|
||||||
chunk: response
|
chunk: response
|
||||||
|
@ -609,8 +607,7 @@ pub async fn get_public_rooms_filtered_route(
|
||||||
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,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/publicRooms`
|
/// # `GET /_matrix/federation/v1/publicRooms`
|
||||||
|
@ -620,7 +617,7 @@ pub async fn get_public_rooms_filtered_route(
|
||||||
pub async fn get_public_rooms_route(
|
pub async fn get_public_rooms_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_public_rooms::v1::Request<'_>>,
|
body: Ruma<get_public_rooms::v1::Request<'_>>,
|
||||||
) -> ConduitResult<get_public_rooms::v1::Response> {
|
) -> Result<get_public_rooms::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -633,8 +630,7 @@ pub async fn get_public_rooms_route(
|
||||||
&IncomingFilter::default(),
|
&IncomingFilter::default(),
|
||||||
&IncomingRoomNetwork::Matrix,
|
&IncomingRoomNetwork::Matrix,
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.0;
|
|
||||||
|
|
||||||
Ok(get_public_rooms::v1::Response {
|
Ok(get_public_rooms::v1::Response {
|
||||||
chunk: response
|
chunk: response
|
||||||
|
@ -652,8 +648,7 @@ pub async fn get_public_rooms_route(
|
||||||
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,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/federation/v1/send/{txnId}`
|
/// # `PUT /_matrix/federation/v1/send/{txnId}`
|
||||||
|
@ -663,7 +658,7 @@ pub async fn get_public_rooms_route(
|
||||||
pub async fn send_transaction_message_route(
|
pub async fn send_transaction_message_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<send_transaction_message::v1::Request<'_>>,
|
body: Ruma<send_transaction_message::v1::Request<'_>>,
|
||||||
) -> ConduitResult<send_transaction_message::v1::Response> {
|
) -> Result<send_transaction_message::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -875,7 +870,7 @@ pub async fn send_transaction_message_route(
|
||||||
|
|
||||||
db.flush()?;
|
db.flush()?;
|
||||||
|
|
||||||
Ok(send_transaction_message::v1::Response { pdus: resolved_map }.into())
|
Ok(send_transaction_message::v1::Response { pdus: resolved_map })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An async function that can recursively call itself.
|
/// An async function that can recursively call itself.
|
||||||
|
@ -2293,7 +2288,7 @@ fn get_auth_chain_inner(
|
||||||
pub async fn get_event_route(
|
pub async fn get_event_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_event::v1::Request<'_>>,
|
body: Ruma<get_event::v1::Request<'_>>,
|
||||||
) -> ConduitResult<get_event::v1::Response> {
|
) -> Result<get_event::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -2327,8 +2322,7 @@ pub async fn get_event_route(
|
||||||
origin: db.globals.server_name().to_owned(),
|
origin: db.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),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/federation/v1/get_missing_events/{roomId}`
|
/// # `POST /_matrix/federation/v1/get_missing_events/{roomId}`
|
||||||
|
@ -2338,7 +2332,7 @@ pub async fn get_event_route(
|
||||||
pub async fn get_missing_events_route(
|
pub async fn get_missing_events_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_missing_events::v1::Request<'_>>,
|
body: Ruma<get_missing_events::v1::Request<'_>>,
|
||||||
) -> ConduitResult<get_missing_events::v1::Response> {
|
) -> Result<get_missing_events::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -2400,7 +2394,7 @@ pub async fn get_missing_events_route(
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(get_missing_events::v1::Response { events }.into())
|
Ok(get_missing_events::v1::Response { events })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/event_auth/{roomId}/{eventId}`
|
/// # `GET /_matrix/federation/v1/event_auth/{roomId}/{eventId}`
|
||||||
|
@ -2412,7 +2406,7 @@ pub async fn get_missing_events_route(
|
||||||
pub async fn get_event_authorization_route(
|
pub async fn get_event_authorization_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_event_authorization::v1::Request<'_>>,
|
body: Ruma<get_event_authorization::v1::Request<'_>>,
|
||||||
) -> ConduitResult<get_event_authorization::v1::Response> {
|
) -> Result<get_event_authorization::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -2451,8 +2445,7 @@ pub async fn get_event_authorization_route(
|
||||||
.filter_map(|id| db.rooms.get_pdu_json(&id).ok()?)
|
.filter_map(|id| db.rooms.get_pdu_json(&id).ok()?)
|
||||||
.map(PduEvent::convert_to_outgoing_federation_event)
|
.map(PduEvent::convert_to_outgoing_federation_event)
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/state/{roomId}`
|
/// # `GET /_matrix/federation/v1/state/{roomId}`
|
||||||
|
@ -2462,7 +2455,7 @@ pub async fn get_event_authorization_route(
|
||||||
pub async fn get_room_state_route(
|
pub async fn get_room_state_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_room_state::v1::Request<'_>>,
|
body: Ruma<get_room_state::v1::Request<'_>>,
|
||||||
) -> ConduitResult<get_room_state::v1::Response> {
|
) -> Result<get_room_state::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -2512,8 +2505,7 @@ pub async fn get_room_state_route(
|
||||||
.filter_map(|r| r.ok())
|
.filter_map(|r| r.ok())
|
||||||
.collect(),
|
.collect(),
|
||||||
pdus,
|
pdus,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/state_ids/{roomId}`
|
/// # `GET /_matrix/federation/v1/state_ids/{roomId}`
|
||||||
|
@ -2523,7 +2515,7 @@ pub async fn get_room_state_route(
|
||||||
pub async fn get_room_state_ids_route(
|
pub async fn get_room_state_ids_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_room_state_ids::v1::Request<'_>>,
|
body: Ruma<get_room_state_ids::v1::Request<'_>>,
|
||||||
) -> ConduitResult<get_room_state_ids::v1::Response> {
|
) -> Result<get_room_state_ids::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -2562,8 +2554,7 @@ pub async fn get_room_state_ids_route(
|
||||||
Ok(get_room_state_ids::v1::Response {
|
Ok(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,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/make_join/{roomId}/{userId}`
|
/// # `GET /_matrix/federation/v1/make_join/{roomId}/{userId}`
|
||||||
|
@ -2573,7 +2564,7 @@ pub async fn get_room_state_ids_route(
|
||||||
pub async fn create_join_event_template_route(
|
pub async fn create_join_event_template_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<create_join_event_template::v1::Request<'_>>,
|
body: Ruma<create_join_event_template::v1::Request<'_>>,
|
||||||
) -> ConduitResult<create_join_event_template::v1::Response> {
|
) -> Result<create_join_event_template::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -2738,8 +2729,7 @@ pub async fn create_join_event_template_route(
|
||||||
Ok(create_join_event_template::v1::Response {
|
Ok(create_join_event_template::v1::Response {
|
||||||
room_version: Some(room_version_id),
|
room_version: Some(room_version_id),
|
||||||
event: to_raw_value(&pdu_json).expect("CanonicalJson can be serialized to JSON"),
|
event: to_raw_value(&pdu_json).expect("CanonicalJson can be serialized to JSON"),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_join_event(
|
async fn create_join_event(
|
||||||
|
@ -2855,7 +2845,7 @@ async fn create_join_event(
|
||||||
pub async fn create_join_event_v1_route(
|
pub async fn create_join_event_v1_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<create_join_event::v1::Request<'_>>,
|
body: Ruma<create_join_event::v1::Request<'_>>,
|
||||||
) -> ConduitResult<create_join_event::v1::Response> {
|
) -> Result<create_join_event::v1::Response> {
|
||||||
let sender_servername = body
|
let sender_servername = body
|
||||||
.sender_servername
|
.sender_servername
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -2863,7 +2853,7 @@ pub async fn create_join_event_v1_route(
|
||||||
|
|
||||||
let room_state = create_join_event(&db, sender_servername, &body.room_id, &body.pdu).await?;
|
let room_state = create_join_event(&db, sender_servername, &body.room_id, &body.pdu).await?;
|
||||||
|
|
||||||
Ok(create_join_event::v1::Response { room_state }.into())
|
Ok(create_join_event::v1::Response { room_state })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/federation/v2/send_join/{roomId}/{eventId}`
|
/// # `PUT /_matrix/federation/v2/send_join/{roomId}/{eventId}`
|
||||||
|
@ -2873,7 +2863,7 @@ pub async fn create_join_event_v1_route(
|
||||||
pub async fn create_join_event_v2_route(
|
pub async fn create_join_event_v2_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<create_join_event::v2::Request<'_>>,
|
body: Ruma<create_join_event::v2::Request<'_>>,
|
||||||
) -> ConduitResult<create_join_event::v2::Response> {
|
) -> Result<create_join_event::v2::Response> {
|
||||||
let sender_servername = body
|
let sender_servername = body
|
||||||
.sender_servername
|
.sender_servername
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -2881,7 +2871,7 @@ pub async fn create_join_event_v2_route(
|
||||||
|
|
||||||
let room_state = create_join_event(&db, sender_servername, &body.room_id, &body.pdu).await?;
|
let room_state = create_join_event(&db, sender_servername, &body.room_id, &body.pdu).await?;
|
||||||
|
|
||||||
Ok(create_join_event::v2::Response { room_state }.into())
|
Ok(create_join_event::v2::Response { room_state })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `PUT /_matrix/federation/v2/invite/{roomId}/{eventId}`
|
/// # `PUT /_matrix/federation/v2/invite/{roomId}/{eventId}`
|
||||||
|
@ -2891,7 +2881,7 @@ pub async fn create_join_event_v2_route(
|
||||||
pub async fn create_invite_route(
|
pub async fn create_invite_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<create_invite::v2::Request<'_>>,
|
body: Ruma<create_invite::v2::Request<'_>>,
|
||||||
) -> ConduitResult<create_invite::v2::Response> {
|
) -> Result<create_invite::v2::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -2992,8 +2982,7 @@ pub async fn create_invite_route(
|
||||||
|
|
||||||
Ok(create_invite::v2::Response {
|
Ok(create_invite::v2::Response {
|
||||||
event: PduEvent::convert_to_outgoing_federation_event(signed_event),
|
event: PduEvent::convert_to_outgoing_federation_event(signed_event),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/user/devices/{userId}`
|
/// # `GET /_matrix/federation/v1/user/devices/{userId}`
|
||||||
|
@ -3003,7 +2992,7 @@ pub async fn create_invite_route(
|
||||||
pub async fn get_devices_route(
|
pub async fn get_devices_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_devices::v1::Request<'_>>,
|
body: Ruma<get_devices::v1::Request<'_>>,
|
||||||
) -> ConduitResult<get_devices::v1::Response> {
|
) -> Result<get_devices::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -3031,8 +3020,7 @@ pub async fn get_devices_route(
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/query/directory`
|
/// # `GET /_matrix/federation/v1/query/directory`
|
||||||
|
@ -3042,7 +3030,7 @@ pub async fn get_devices_route(
|
||||||
pub async fn get_room_information_route(
|
pub async fn get_room_information_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_room_information::v1::Request<'_>>,
|
body: Ruma<get_room_information::v1::Request<'_>>,
|
||||||
) -> ConduitResult<get_room_information::v1::Response> {
|
) -> Result<get_room_information::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -3058,8 +3046,7 @@ pub async fn get_room_information_route(
|
||||||
Ok(get_room_information::v1::Response {
|
Ok(get_room_information::v1::Response {
|
||||||
room_id,
|
room_id,
|
||||||
servers: vec![db.globals.server_name().to_owned()],
|
servers: vec![db.globals.server_name().to_owned()],
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `GET /_matrix/federation/v1/query/profile`
|
/// # `GET /_matrix/federation/v1/query/profile`
|
||||||
|
@ -3069,7 +3056,7 @@ pub async fn get_room_information_route(
|
||||||
pub async fn get_profile_information_route(
|
pub async fn get_profile_information_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_profile_information::v1::Request<'_>>,
|
body: Ruma<get_profile_information::v1::Request<'_>>,
|
||||||
) -> ConduitResult<get_profile_information::v1::Response> {
|
) -> Result<get_profile_information::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -3097,8 +3084,7 @@ pub async fn get_profile_information_route(
|
||||||
blurhash,
|
blurhash,
|
||||||
displayname,
|
displayname,
|
||||||
avatar_url,
|
avatar_url,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/federation/v1/user/keys/query`
|
/// # `POST /_matrix/federation/v1/user/keys/query`
|
||||||
|
@ -3108,7 +3094,7 @@ pub async fn get_profile_information_route(
|
||||||
pub async fn get_keys_route(
|
pub async fn get_keys_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<get_keys::v1::Request>,
|
body: Ruma<get_keys::v1::Request>,
|
||||||
) -> ConduitResult<get_keys::v1::Response> {
|
) -> Result<get_keys::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -3127,8 +3113,7 @@ pub async fn get_keys_route(
|
||||||
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,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # `POST /_matrix/federation/v1/user/keys/claim`
|
/// # `POST /_matrix/federation/v1/user/keys/claim`
|
||||||
|
@ -3138,7 +3123,7 @@ pub async fn get_keys_route(
|
||||||
pub async fn claim_keys_route(
|
pub async fn claim_keys_route(
|
||||||
db: DatabaseGuard,
|
db: DatabaseGuard,
|
||||||
body: Ruma<claim_keys::v1::Request>,
|
body: Ruma<claim_keys::v1::Request>,
|
||||||
) -> ConduitResult<claim_keys::v1::Response> {
|
) -> Result<claim_keys::v1::Response> {
|
||||||
if !db.globals.allow_federation() {
|
if !db.globals.allow_federation() {
|
||||||
return Err(Error::bad_config("Federation is disabled."));
|
return Err(Error::bad_config("Federation is disabled."));
|
||||||
}
|
}
|
||||||
|
@ -3149,8 +3134,7 @@ pub async fn claim_keys_route(
|
||||||
|
|
||||||
Ok(claim_keys::v1::Response {
|
Ok(claim_keys::v1::Response {
|
||||||
one_time_keys: result.one_time_keys,
|
one_time_keys: result.one_time_keys,
|
||||||
}
|
})
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(event, pub_key_map, db))]
|
#[tracing::instrument(skip(event, pub_key_map, db))]
|
||||||
|
|
Loading…
Add table
Reference in a new issue