1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2024-12-27 11:44:21 +01:00

Update ruma

This commit is contained in:
chenyuqide 2022-03-05 10:16:21 +08:00 committed by Timo Kösters
parent 21bc099ccf
commit ee96a03d60
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
8 changed files with 144 additions and 144 deletions

128
Cargo.lock generated
View file

@ -2101,12 +2101,11 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.4.0" version = "0.5.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0" source = "git+https://github.com/ruma/ruma?rev=588fe9c006eb140264160e68f4a21ea1fb28af18#588fe9c006eb140264160e68f4a21ea1fb28af18"
dependencies = [ dependencies = [
"assign", "assign",
"js_int", "js_int",
"ruma-api",
"ruma-appservice-api", "ruma-appservice-api",
"ruma-client-api", "ruma-client-api",
"ruma-common", "ruma-common",
@ -2120,40 +2119,11 @@ dependencies = [
"ruma-state-res", "ruma-state-res",
] ]
[[package]]
name = "ruma-api"
version = "0.20.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0"
dependencies = [
"bytes",
"http",
"percent-encoding",
"ruma-api-macros",
"ruma-identifiers",
"ruma-serde",
"serde",
"serde_json",
"thiserror",
"tracing",
]
[[package]]
name = "ruma-api-macros"
version = "0.20.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "ruma-appservice-api" name = "ruma-appservice-api"
version = "0.4.0" version = "0.5.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0" source = "git+https://github.com/ruma/ruma?rev=588fe9c006eb140264160e68f4a21ea1fb28af18#588fe9c006eb140264160e68f4a21ea1fb28af18"
dependencies = [ dependencies = [
"ruma-api",
"ruma-common", "ruma-common",
"ruma-events", "ruma-events",
"ruma-identifiers", "ruma-identifiers",
@ -2165,7 +2135,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.13.0" version = "0.13.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0" source = "git+https://github.com/ruma/ruma?rev=588fe9c006eb140264160e68f4a21ea1fb28af18#588fe9c006eb140264160e68f4a21ea1fb28af18"
dependencies = [ dependencies = [
"assign", "assign",
"bytes", "bytes",
@ -2173,7 +2143,6 @@ dependencies = [
"js_int", "js_int",
"maplit", "maplit",
"percent-encoding", "percent-encoding",
"ruma-api",
"ruma-common", "ruma-common",
"ruma-events", "ruma-events",
"ruma-identifiers", "ruma-identifiers",
@ -2185,14 +2154,19 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.8.0" version = "0.8.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0" source = "git+https://github.com/ruma/ruma?rev=588fe9c006eb140264160e68f4a21ea1fb28af18#588fe9c006eb140264160e68f4a21ea1fb28af18"
dependencies = [ dependencies = [
"bytes",
"http",
"indexmap", "indexmap",
"js_int", "js_int",
"percent-encoding",
"ruma-identifiers", "ruma-identifiers",
"ruma-macros",
"ruma-serde", "ruma-serde",
"serde", "serde",
"serde_json", "serde_json",
"thiserror",
"tracing", "tracing",
"wildmatch", "wildmatch",
] ]
@ -2200,13 +2174,13 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events" name = "ruma-events"
version = "0.26.0" version = "0.26.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0" source = "git+https://github.com/ruma/ruma?rev=588fe9c006eb140264160e68f4a21ea1fb28af18#588fe9c006eb140264160e68f4a21ea1fb28af18"
dependencies = [ dependencies = [
"indoc", "indoc",
"js_int", "js_int",
"ruma-common", "ruma-common",
"ruma-events-macros",
"ruma-identifiers", "ruma-identifiers",
"ruma-macros",
"ruma-serde", "ruma-serde",
"serde", "serde",
"serde_json", "serde_json",
@ -2214,24 +2188,12 @@ dependencies = [
"wildmatch", "wildmatch",
] ]
[[package]]
name = "ruma-events-macros"
version = "0.26.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.3.1" version = "0.4.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0" source = "git+https://github.com/ruma/ruma?rev=588fe9c006eb140264160e68f4a21ea1fb28af18#588fe9c006eb140264160e68f4a21ea1fb28af18"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api",
"ruma-common", "ruma-common",
"ruma-events", "ruma-events",
"ruma-identifiers", "ruma-identifiers",
@ -2243,33 +2205,22 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers" name = "ruma-identifiers"
version = "0.22.0" version = "0.22.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0" source = "git+https://github.com/ruma/ruma?rev=588fe9c006eb140264160e68f4a21ea1fb28af18#588fe9c006eb140264160e68f4a21ea1fb28af18"
dependencies = [ dependencies = [
"percent-encoding", "percent-encoding",
"rand 0.8.4", "rand 0.8.4",
"ruma-identifiers-macros",
"ruma-identifiers-validation", "ruma-identifiers-validation",
"ruma-macros",
"ruma-serde", "ruma-serde",
"ruma-serde-macros",
"serde", "serde",
"url", "url",
"uuid", "uuid",
] ]
[[package]]
name = "ruma-identifiers-macros"
version = "0.22.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0"
dependencies = [
"quote",
"ruma-identifiers-validation",
"syn",
]
[[package]] [[package]]
name = "ruma-identifiers-validation" name = "ruma-identifiers-validation"
version = "0.7.0" version = "0.7.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0" source = "git+https://github.com/ruma/ruma?rev=588fe9c006eb140264160e68f4a21ea1fb28af18#588fe9c006eb140264160e68f4a21ea1fb28af18"
dependencies = [ dependencies = [
"thiserror", "thiserror",
"url", "url",
@ -2277,24 +2228,34 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identity-service-api" name = "ruma-identity-service-api"
version = "0.3.0" version = "0.4.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0" source = "git+https://github.com/ruma/ruma?rev=588fe9c006eb140264160e68f4a21ea1fb28af18#588fe9c006eb140264160e68f4a21ea1fb28af18"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api",
"ruma-common", "ruma-common",
"ruma-identifiers", "ruma-identifiers",
"ruma-serde", "ruma-serde",
"serde", "serde",
] ]
[[package]]
name = "ruma-macros"
version = "0.1.0"
source = "git+https://github.com/ruma/ruma?rev=588fe9c006eb140264160e68f4a21ea1fb28af18#588fe9c006eb140264160e68f4a21ea1fb28af18"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"ruma-identifiers-validation",
"syn",
]
[[package]] [[package]]
name = "ruma-push-gateway-api" name = "ruma-push-gateway-api"
version = "0.3.0" version = "0.4.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0" source = "git+https://github.com/ruma/ruma?rev=588fe9c006eb140264160e68f4a21ea1fb28af18#588fe9c006eb140264160e68f4a21ea1fb28af18"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api",
"ruma-common", "ruma-common",
"ruma-events", "ruma-events",
"ruma-identifiers", "ruma-identifiers",
@ -2306,33 +2267,22 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde" name = "ruma-serde"
version = "0.6.0" version = "0.6.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0" source = "git+https://github.com/ruma/ruma?rev=588fe9c006eb140264160e68f4a21ea1fb28af18#588fe9c006eb140264160e68f4a21ea1fb28af18"
dependencies = [ dependencies = [
"base64 0.13.0", "base64 0.13.0",
"bytes", "bytes",
"form_urlencoded", "form_urlencoded",
"itoa 1.0.1", "itoa 1.0.1",
"js_int", "js_int",
"ruma-serde-macros", "ruma-macros",
"serde", "serde",
"serde_json", "serde_json",
] ]
[[package]]
name = "ruma-serde-macros"
version = "0.6.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.10.0" version = "0.10.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0" source = "git+https://github.com/ruma/ruma?rev=588fe9c006eb140264160e68f4a21ea1fb28af18#588fe9c006eb140264160e68f4a21ea1fb28af18"
dependencies = [ dependencies = [
"base64 0.13.0", "base64 0.13.0",
"ed25519-dalek", "ed25519-dalek",
@ -2348,8 +2298,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-state-res" name = "ruma-state-res"
version = "0.5.0" version = "0.6.0"
source = "git+https://github.com/ruma/ruma?rev=95fdb303c82e257eee18f5064b87ed4e2ed01ac0#95fdb303c82e257eee18f5064b87ed4e2ed01ac0" source = "git+https://github.com/ruma/ruma?rev=588fe9c006eb140264160e68f4a21ea1fb28af18#588fe9c006eb140264160e68f4a21ea1fb28af18"
dependencies = [ dependencies = [
"itertools", "itertools",
"js_int", "js_int",

View file

@ -21,7 +21,7 @@ tower-http = { version = "0.2.1", features = ["add-extension", "cors", "compress
# Used for matrix spec type definitions and helpers # Used for matrix spec type definitions and helpers
#ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { version = "0.4.0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "95fdb303c82e257eee18f5064b87ed4e2ed01ac0", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-pre-spec", "unstable-exhaustive-types"] } ruma = { git = "https://github.com/ruma/ruma", rev = "588fe9c006eb140264160e68f4a21ea1fb28af18", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-msc2448", "unstable-pre-spec", "unstable-exhaustive-types"] }
#ruma = { git = "https://github.com/timokoesters/ruma", rev = "50c1db7e0a3a21fc794b0cce3b64285a4c750c71", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { git = "https://github.com/timokoesters/ruma", rev = "50c1db7e0a3a21fc794b0cce3b64285a4c750c71", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }
#ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] }

View file

@ -342,8 +342,12 @@ pub async fn change_password_route(
/// Note: Also works for Application Services /// Note: Also works for Application Services
pub async fn whoami_route(body: Ruma<whoami::v3::Request>) -> Result<whoami::v3::Response> { pub async fn whoami_route(body: Ruma<whoami::v3::Request>) -> Result<whoami::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let device_id = body.sender_device.as_ref().cloned();
let is_guest = device_id.is_none();
Ok(whoami::v3::Response { Ok(whoami::v3::Response {
user_id: sender_user.clone(), user_id: sender_user.clone(),
device_id,
is_guest,
}) })
} }

View file

@ -1,10 +1,11 @@
use crate::{database::DatabaseGuard, Error, Result, Ruma}; use crate::{database::DatabaseGuard, Error, Result, Ruma};
use ruma::api::client::{ use ruma::api::client::{
backup::{ backup::{
add_backup_key_session, add_backup_key_sessions, add_backup_keys, create_backup, add_backup_keys, add_backup_keys_for_room, add_backup_keys_for_session,
delete_backup, delete_backup_key_session, delete_backup_key_sessions, delete_backup_keys, create_backup_version, delete_backup_keys, delete_backup_keys_for_room,
get_backup, get_backup_key_session, get_backup_key_sessions, get_backup_keys, delete_backup_keys_for_session, delete_backup_version, get_backup_info, get_backup_keys,
get_latest_backup, update_backup, get_backup_keys_for_room, get_backup_keys_for_session, get_latest_backup_info,
update_backup_version,
}, },
error::ErrorKind, error::ErrorKind,
}; };
@ -14,8 +15,8 @@ use ruma::api::client::{
/// Creates a new backup. /// Creates a new backup.
pub async fn create_backup_route( pub async fn create_backup_route(
db: DatabaseGuard, db: DatabaseGuard,
body: Ruma<create_backup::v3::Request>, body: Ruma<create_backup_version::v3::Request>,
) -> Result<create_backup::v3::Response> { ) -> Result<create_backup_version::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let version = db let version = db
.key_backups .key_backups
@ -23,7 +24,7 @@ pub async fn create_backup_route(
db.flush()?; db.flush()?;
Ok(create_backup::v3::Response { version }) Ok(create_backup_version::v3::Response { version })
} }
/// # `PUT /_matrix/client/r0/room_keys/version/{version}` /// # `PUT /_matrix/client/r0/room_keys/version/{version}`
@ -31,15 +32,15 @@ pub async fn create_backup_route(
/// Update information about an existing backup. Only `auth_data` can be modified. /// Update information about an existing backup. Only `auth_data` can be modified.
pub async fn update_backup_route( pub async fn update_backup_route(
db: DatabaseGuard, db: DatabaseGuard,
body: Ruma<update_backup::v3::Request<'_>>, body: Ruma<update_backup_version::v3::Request<'_>>,
) -> Result<update_backup::v3::Response> { ) -> Result<update_backup_version::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
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::v3::Response {}) Ok(update_backup_version::v3::Response {})
} }
/// # `GET /_matrix/client/r0/room_keys/version` /// # `GET /_matrix/client/r0/room_keys/version`
@ -47,8 +48,8 @@ pub async fn update_backup_route(
/// Get information about the latest backup version. /// Get information about the latest backup version.
pub async fn get_latest_backup_route( pub async fn get_latest_backup_route(
db: DatabaseGuard, db: DatabaseGuard,
body: Ruma<get_latest_backup::v3::Request>, body: Ruma<get_latest_backup_info::v3::Request>,
) -> Result<get_latest_backup::v3::Response> { ) -> Result<get_latest_backup_info::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let (version, algorithm) = let (version, algorithm) =
@ -59,7 +60,7 @@ pub async fn get_latest_backup_route(
"Key backup does not exist.", "Key backup does not exist.",
))?; ))?;
Ok(get_latest_backup::v3::Response { Ok(get_latest_backup_info::v3::Response {
algorithm, algorithm,
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)?,
@ -72,8 +73,8 @@ pub async fn get_latest_backup_route(
/// Get information about an existing backup. /// Get information about an existing backup.
pub async fn get_backup_route( pub async fn get_backup_route(
db: DatabaseGuard, db: DatabaseGuard,
body: Ruma<get_backup::v3::Request<'_>>, body: Ruma<get_backup_info::v3::Request<'_>>,
) -> Result<get_backup::v3::Response> { ) -> Result<get_backup_info::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let algorithm = db let algorithm = db
.key_backups .key_backups
@ -83,7 +84,7 @@ pub async fn get_backup_route(
"Key backup does not exist.", "Key backup does not exist.",
))?; ))?;
Ok(get_backup::v3::Response { Ok(get_backup_info::v3::Response {
algorithm, algorithm,
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)?,
@ -98,15 +99,15 @@ pub async fn get_backup_route(
/// - Deletes both information about the backup, as well as all key data related to the backup /// - Deletes both information about the backup, as well as all key data related to the backup
pub async fn delete_backup_route( pub async fn delete_backup_route(
db: DatabaseGuard, db: DatabaseGuard,
body: Ruma<delete_backup::v3::Request<'_>>, body: Ruma<delete_backup_version::v3::Request<'_>>,
) -> Result<delete_backup::v3::Response> { ) -> Result<delete_backup_version::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
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::v3::Response {}) Ok(delete_backup_version::v3::Response {})
} }
/// # `PUT /_matrix/client/r0/room_keys/keys` /// # `PUT /_matrix/client/r0/room_keys/keys`
@ -164,8 +165,8 @@ pub async fn add_backup_keys_route(
/// - Returns the new number of keys in this backup and the etag /// - Returns the new number of keys in this backup and the etag
pub 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::v3::Request<'_>>, body: Ruma<add_backup_keys_for_room::v3::Request<'_>>,
) -> Result<add_backup_key_sessions::v3::Response> { ) -> Result<add_backup_keys_for_room::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
if Some(&body.version) if Some(&body.version)
@ -193,7 +194,7 @@ pub async fn add_backup_key_sessions_route(
db.flush()?; db.flush()?;
Ok(add_backup_key_sessions::v3::Response { Ok(add_backup_keys_for_room::v3::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)?,
}) })
@ -208,8 +209,8 @@ pub async fn add_backup_key_sessions_route(
/// - Returns the new number of keys in this backup and the etag /// - Returns the new number of keys in this backup and the etag
pub 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::v3::Request<'_>>, body: Ruma<add_backup_keys_for_session::v3::Request<'_>>,
) -> Result<add_backup_key_session::v3::Response> { ) -> Result<add_backup_keys_for_session::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
if Some(&body.version) if Some(&body.version)
@ -235,7 +236,7 @@ pub async fn add_backup_key_session_route(
db.flush()?; db.flush()?;
Ok(add_backup_key_session::v3::Response { Ok(add_backup_keys_for_session::v3::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)?,
}) })
@ -260,15 +261,15 @@ pub async fn get_backup_keys_route(
/// Retrieves all keys from the backup for a given room. /// Retrieves all keys from the backup for a given room.
pub 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::v3::Request<'_>>, body: Ruma<get_backup_keys_for_room::v3::Request<'_>>,
) -> Result<get_backup_key_sessions::v3::Response> { ) -> Result<get_backup_keys_for_room::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let sessions = 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::v3::Response { sessions }) Ok(get_backup_keys_for_room::v3::Response { sessions })
} }
/// # `GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}` /// # `GET /_matrix/client/r0/room_keys/keys/{roomId}/{sessionId}`
@ -276,8 +277,8 @@ pub async fn get_backup_key_sessions_route(
/// Retrieves a key from the backup. /// Retrieves a key from the backup.
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::v3::Request<'_>>, body: Ruma<get_backup_keys_for_session::v3::Request<'_>>,
) -> Result<get_backup_key_session::v3::Response> { ) -> Result<get_backup_keys_for_session::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let key_data = db let key_data = db
@ -288,7 +289,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::v3::Response { key_data }) Ok(get_backup_keys_for_session::v3::Response { key_data })
} }
/// # `DELETE /_matrix/client/r0/room_keys/keys` /// # `DELETE /_matrix/client/r0/room_keys/keys`
@ -315,8 +316,8 @@ pub async fn delete_backup_keys_route(
/// Delete the keys from the backup for a given room. /// Delete the keys from the backup for a given room.
pub 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::v3::Request<'_>>, body: Ruma<delete_backup_keys_for_room::v3::Request<'_>>,
) -> Result<delete_backup_key_sessions::v3::Response> { ) -> Result<delete_backup_keys_for_room::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
db.key_backups db.key_backups
@ -324,7 +325,7 @@ pub async fn delete_backup_key_sessions_route(
db.flush()?; db.flush()?;
Ok(delete_backup_key_sessions::v3::Response { Ok(delete_backup_keys_for_room::v3::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)?,
}) })
@ -335,8 +336,8 @@ pub async fn delete_backup_key_sessions_route(
/// Delete a key from the backup. /// Delete a key from the backup.
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::v3::Request<'_>>, body: Ruma<delete_backup_keys_for_session::v3::Request<'_>>,
) -> Result<delete_backup_key_session::v3::Response> { ) -> Result<delete_backup_keys_for_session::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
db.key_backups db.key_backups
@ -344,7 +345,7 @@ pub async fn delete_backup_key_session_route(
db.flush()?; db.flush()?;
Ok(delete_backup_key_session::v3::Response { Ok(delete_backup_keys_for_session::v3::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)?,
}) })

View file

@ -22,7 +22,7 @@ pub async fn set_global_account_data_route(
) -> Result<set_global_account_data::v3::Response> { ) -> Result<set_global_account_data::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let data: serde_json::Value = serde_json::from_str(body.data.get()) let data: serde_json::Value = serde_json::from_str(body.data.json().get())
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Data is invalid."))?; .map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Data is invalid."))?;
let event_type = body.event_type.to_string(); let event_type = body.event_type.to_string();
@ -52,7 +52,7 @@ pub async fn set_room_account_data_route(
) -> Result<set_room_account_data::v3::Response> { ) -> Result<set_room_account_data::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let data: serde_json::Value = serde_json::from_str(body.data.get()) let data: serde_json::Value = serde_json::from_str(body.data.json().get())
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Data is invalid."))?; .map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Data is invalid."))?;
let event_type = body.event_type.to_string(); let event_type = body.event_type.to_string();

View file

@ -11,13 +11,17 @@ use ruma::{
}, },
federation, federation,
}, },
directory::{Filter, IncomingFilter, IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork}, directory::{
Filter, IncomingFilter, IncomingRoomNetwork, PublicRoomJoinRule, PublicRoomsChunk,
RoomNetwork,
},
events::{ events::{
room::{ room::{
avatar::RoomAvatarEventContent, avatar::RoomAvatarEventContent,
canonical_alias::RoomCanonicalAliasEventContent, canonical_alias::RoomCanonicalAliasEventContent,
guest_access::{GuestAccess, RoomGuestAccessEventContent}, guest_access::{GuestAccess, RoomGuestAccessEventContent},
history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent}, history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent},
join_rules::{JoinRule, RoomJoinRulesEventContent},
name::RoomNameEventContent, name::RoomNameEventContent,
topic::RoomTopicEventContent, topic::RoomTopicEventContent,
}, },
@ -265,6 +269,25 @@ pub(crate) async fn get_public_rooms_filtered_helper(
.transpose()? .transpose()?
// url is now an Option<String> so we must flatten // url is now an Option<String> so we must flatten
.flatten(), .flatten(),
join_rule: db
.rooms
.room_state_get(&room_id, &EventType::RoomJoinRules, "")?
.map(|s| {
serde_json::from_str(s.content.get())
.map(|c: RoomJoinRulesEventContent| match c.join_rule {
JoinRule::Public => Some(PublicRoomJoinRule::Public),
JoinRule::Knock => Some(PublicRoomJoinRule::Knock),
_ => None,
})
.map_err(|_| {
Error::bad_database("Invalid room join rule event in database.")
})
})
.transpose()?
.flatten()
.ok_or(Error::bad_database(
"Invalid room join rule event in database.",
))?,
room_id, room_id,
}; };
Ok(chunk) Ok(chunk)

View file

@ -25,14 +25,14 @@ pub async fn report_event_route(
} }
}; };
if body.score > int!(0) || body.score < int!(-100) { if let Some(true) = body.score.map(|s| s > int!(0) || s < int!(-100)) {
return Err(Error::BadRequest( return Err(Error::BadRequest(
ErrorKind::InvalidParam, ErrorKind::InvalidParam,
"Invalid score, must be within 0 to -100", "Invalid score, must be within 0 to -100",
)); ));
}; };
if body.reason.chars().count() > 250 { if let Some(true) = body.reason.clone().map(|s| s.chars().count() > 250) {
return Err(Error::BadRequest( return Err(Error::BadRequest(
ErrorKind::InvalidParam, ErrorKind::InvalidParam,
"Reason too long, should be 250 characters or fewer", "Reason too long, should be 250 characters or fewer",
@ -43,26 +43,26 @@ pub async fn report_event_route(
.send_message(message::RoomMessageEventContent::text_html( .send_message(message::RoomMessageEventContent::text_html(
format!( format!(
"Report received from: {}\n\n\ "Report received from: {}\n\n\
Event ID: {}\n\ Event ID: {:?}\n\
Room ID: {}\n\ Room ID: {:?}\n\
Sent By: {}\n\n\ Sent By: {:?}\n\n\
Report Score: {}\n\ Report Score: {:?}\n\
Report Reason: {}", Report Reason: {:?}",
sender_user, pdu.event_id, pdu.room_id, pdu.sender, body.score, body.reason sender_user, pdu.event_id, pdu.room_id, pdu.sender, body.score, body.reason
), ),
format!( format!(
"<details><summary>Report received from: <a href=\"https://matrix.to/#/{0}\">{0}\ "<details><summary>Report received from: <a href=\"https://matrix.to/#/{0:?}\">{0:?}\
</a></summary><ul><li>Event Info<ul><li>Event ID: <code>{1}</code>\ </a></summary><ul><li>Event Info<ul><li>Event ID: <code>{1:?}</code>\
<a href=\"https://matrix.to/#/{2}/{1}\">🔗</a></li><li>Room ID: <code>{2}</code>\ <a href=\"https://matrix.to/#/{2:?}/{1:?}\">🔗</a></li><li>Room ID: <code>{2:?}</code>\
</li><li>Sent By: <a href=\"https://matrix.to/#/{3}\">{3}</a></li></ul></li><li>\ </li><li>Sent By: <a href=\"https://matrix.to/#/{3:?}\">{3:?}</a></li></ul></li><li>\
Report Info<ul><li>Report Score: {4}</li><li>Report Reason: {5}</li></ul></li>\ Report Info<ul><li>Report Score: {4:?}</li><li>Report Reason: {5}</li></ul></li>\
</ul></details>", </ul></details>",
sender_user, sender_user,
pdu.event_id, pdu.event_id,
pdu.room_id, pdu.room_id,
pdu.sender, pdu.sender,
body.score, body.score,
HtmlEscape(&body.reason) HtmlEscape(&body.reason.clone().unwrap_or(String::new()))
), ),
)); ));

View file

@ -30,7 +30,7 @@ use ruma::{
}, },
query::{get_profile_information, get_room_information}, query::{get_profile_information, get_room_information},
transactions::{ transactions::{
edu::{DeviceListUpdateContent, DirectDeviceContent, Edu}, edu::{DeviceListUpdateContent, DirectDeviceContent, Edu, SigningKeyUpdateContent},
send_transaction_message, send_transaction_message,
}, },
}, },
@ -840,6 +840,22 @@ pub async fn send_transaction_message_route(
db.transaction_ids db.transaction_ids
.add_txnid(&sender, None, &message_id, &[])?; .add_txnid(&sender, None, &message_id, &[])?;
} }
Edu::SigningKeyUpdate(SigningKeyUpdateContent {
user_id,
master_key,
self_signing_key,
}) => {
if let Some(master_key) = master_key {
db.users.add_cross_signing_keys(
&user_id,
&master_key,
&self_signing_key,
&None,
&db.rooms,
&db.globals,
)?;
}
}
Edu::_Custom(_) => {} Edu::_Custom(_) => {}
} }
} }
@ -2998,6 +3014,12 @@ pub async fn get_devices_route(
}) })
}) })
.collect(), .collect(),
master_key: db
.users
.get_master_key(&body.user_id, |u| u == &body.user_id)?,
self_signing_key: db
.users
.get_self_signing_key(&body.user_id, |u| u == &body.user_id)?,
}) })
} }