fix: deserialize sync event body

This commit is contained in:
timokoesters 2020-04-03 21:17:27 +02:00
parent 2855d1acdf
commit f9cfede2a8
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
4 changed files with 48 additions and 36 deletions

66
Cargo.lock generated
View file

@ -69,6 +69,12 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
[[package]]
name = "base64"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d5ca2cd0adc3f48f9e9ea5a6bbdf9ccc0bfade884847e484d452414c7ccffb3"
[[package]]
name = "binascii"
version = "0.1.4"
@ -208,7 +214,7 @@ version = "0.3.0"
source = "git+https://github.com/SergioBenitez/Devise.git?rev=e58b3ac9a#e58b3ac9afc3b6ff10a8aaf02a3e768a8f530089"
dependencies = [
"bitflags",
"proc-macro2 1.0.9",
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
]
@ -313,9 +319,9 @@ dependencies = [
[[package]]
name = "hermit-abi"
version = "0.1.8"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1010591b26bbfe835e9faeabeb11866061cc7dcebffd56ad7d0942d0e61aefd8"
checksum = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e"
dependencies = [
"libc",
]
@ -425,9 +431,9 @@ dependencies = [
[[package]]
name = "js_int"
version = "0.1.3"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4937d8b6672d78c0dd9689d671e3faf2c9744fa36cbcb437e22cc8b1bd59ac25"
checksum = "f97dc0d13f3bf0369f00504ad806499490045d6f93524a6ead4081c380703a2f"
dependencies = [
"serde",
]
@ -619,9 +625,9 @@ dependencies = [
[[package]]
name = "proc-macro-hack"
version = "0.5.14"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcfdefadc3d57ca21cf17990a28ef4c0f7c61383a28cb7604cf4a18e6ede1420"
checksum = "0d659fe7c6d27f25e9d80a1a094c223f5246f6a6596453e09d7229bf42750b63"
[[package]]
name = "proc-macro2"
@ -634,9 +640,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.9"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435"
checksum = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3"
dependencies = [
"unicode-xid 0.2.0",
]
@ -662,7 +668,7 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f"
dependencies = [
"proc-macro2 1.0.9",
"proc-macro2 1.0.10",
]
[[package]]
@ -831,16 +837,16 @@ version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfc523efc9c1ba7033ff17888551c1d378e12eae087cfbe4fcee938ff516759e"
dependencies = [
"proc-macro2 1.0.9",
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
]
[[package]]
name = "ruma-client-api"
version = "0.7.0"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a64241cdc0cff76038484451d7a5d2689f8ea4e59b6695cd3c8448af7bcc016"
checksum = "b390a86d36e87cc56111802bfd281eed1095f5097a89677101d0271d8e6b1306"
dependencies = [
"http",
"js_int",
@ -872,7 +878,7 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff95b6b4480c570db471b490b35ad70add5470651654e75faf0b97052b4f29e1"
dependencies = [
"proc-macro2 1.0.9",
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
]
@ -903,10 +909,10 @@ dependencies = [
[[package]]
name = "ruma-signatures"
version = "0.5.0"
source = "git+https://github.com/ruma/ruma-signatures.git#a08fc01c0bce63f913e1b4b1a673169d59738b63"
version = "0.6.0-dev.1"
source = "git+https://github.com/ruma/ruma-signatures.git#9947e94cb28daea456904197f7cd754a8e48797a"
dependencies = [
"base64 0.11.0",
"base64 0.12.0",
"ring",
"serde_json",
"untrusted",
@ -952,7 +958,7 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3bba175698996010c4f6dce5e7f173b6eb781fce25d2cfc45e27091ce0b79f6"
dependencies = [
"proc-macro2 1.0.9",
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
]
@ -1015,7 +1021,7 @@ version = "1.0.105"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac5d00fc561ba2724df6758a17de23df5914f20e41cb00f94d5b7ae42fffaff8"
dependencies = [
"proc-macro2 1.0.9",
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
]
@ -1079,9 +1085,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "standback"
version = "0.2.1"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4edf667ea8f60afc06d6aeec079d20d5800351109addec1faea678a8663da4e1"
checksum = "ee531c64ad0f80d289504bd32fb047f42a9e957cda584276ab96eb587e9abac3"
[[package]]
name = "state"
@ -1109,7 +1115,7 @@ version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
dependencies = [
"proc-macro2 1.0.9",
"proc-macro2 1.0.10",
"quote 1.0.3",
"serde",
"serde_derive",
@ -1123,7 +1129,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11"
dependencies = [
"base-x",
"proc-macro2 1.0.9",
"proc-macro2 1.0.10",
"quote 1.0.3",
"serde",
"serde_derive",
@ -1154,7 +1160,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87c85aa3f8ea653bfd3ddf25f7ee357ee4d204731f6aa9ad04002306f6e2774c"
dependencies = [
"heck",
"proc-macro2 1.0.9",
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
]
@ -1176,7 +1182,7 @@ version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03"
dependencies = [
"proc-macro2 1.0.9",
"proc-macro2 1.0.10",
"quote 1.0.3",
"unicode-xid 0.2.0",
]
@ -1242,7 +1248,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e987cfe0537f575b5fc99909de6185f6c19c3ad8889e2275e686a873d0869ba1"
dependencies = [
"proc-macro-hack",
"proc-macro2 1.0.9",
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
]
@ -1379,7 +1385,7 @@ dependencies = [
"bumpalo",
"lazy_static",
"log 0.4.8",
"proc-macro2 1.0.9",
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
"wasm-bindgen-shared",
@ -1401,7 +1407,7 @@ version = "0.2.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d68a5b36eef1be7868f668632863292e37739656a80fc4b9acec7b0bd35a4931"
dependencies = [
"proc-macro2 1.0.9",
"proc-macro2 1.0.10",
"quote 1.0.3",
"syn 1.0.17",
"wasm-bindgen-backend",
@ -1461,9 +1467,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.3"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80"
checksum = "fa515c5163a99cc82bab70fd3bfdd36d827be85de63737b40fcef2ce084a436e"
dependencies = [
"winapi",
]

View file

@ -9,7 +9,7 @@ edition = "2018"
[dependencies]
rocket = { git = "https://github.com/SergioBenitez/Rocket.git", features = ["tls"] }
http = "0.2.1"
ruma-client-api = "0.7.0"
ruma-client-api = "0.7.1"
pretty_env_logger = "0.4.0"
log = "0.4.8"
sled = "0.31.0"
@ -17,7 +17,7 @@ directories = "2.0.2"
ruma-identifiers = "0.14.1"
ruma-api = "0.15.0"
ruma-events = "0.18.0"
js_int = "0.1.3"
js_int = "0.1.4"
serde_json = "1.0.50"
ruma-signatures = { git = "https://github.com/ruma/ruma-signatures.git" }
ruma-federation-api = "0.0.1"

View file

@ -240,8 +240,11 @@ fn create_message_event_route(
MatrixResult(Ok(create_message_event::Response { event_id }))
}
#[get("/_matrix/client/r0/sync")]
fn sync_route(data: State<Data>) -> MatrixResult<sync_events::Response> {
#[get("/_matrix/client/r0/sync", data = "<body>")]
fn sync_route(
data: State<Data>,
body: Ruma<sync_events::Request>,
) -> MatrixResult<sync_events::Response> {
let pdus = data.pdus_all();
let mut joined_rooms = HashMap::new();
joined_rooms.insert(

View file

@ -84,8 +84,11 @@ where
body: t,
user_id,
// TODO: Can we avoid parsing it again?
json_body: serde_json::from_slice(&body)
.expect("Ruma already parsed it successfuly"),
json_body: if !body.is_empty() {
serde_json::from_slice(&body).expect("Ruma already parsed it successfully")
} else {
serde_json::Value::default()
},
}),
Err(e) => {
log::error!("{:?}", e);