Merge branch 'up-ruma' into 'develop'

Upgrade ruma

See merge request famedly/conduit!48
merge-requests/50/head
Timo Kösters 3 years ago
commit d0cdbe2e2b

159
Cargo.lock generated

@ -213,9 +213,9 @@ dependencies = [
[[package]] [[package]]
name = "const_fn" name = "const_fn"
version = "0.4.5" version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6" checksum = "076a6803b0dacd6a88cfe64deba628b01533ff5ef265687e6938280c1afd0a28"
[[package]] [[package]]
name = "constant_time_eq" name = "constant_time_eq"
@ -356,9 +356,9 @@ checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
[[package]] [[package]]
name = "dtoa" name = "dtoa"
version = "0.4.7" version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d7ed2934d741c6b37e33e3832298e8850b53fd2d2bea03873375596c7cea4e" checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
[[package]] [[package]]
name = "either" name = "either"
@ -402,9 +402,9 @@ dependencies = [
[[package]] [[package]]
name = "figment" name = "figment"
version = "0.10.3" version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c38799b106530aa30f774f7fca6d8f7e5f6234a79f427c4fad3c975eaf678931" checksum = "0ca029e813a72b7526d28273d25f3e4a2f365d1b7a1018a6f93ec9053a119763"
dependencies = [ dependencies = [
"atomic", "atomic",
"pear", "pear",
@ -693,9 +693,9 @@ dependencies = [
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "0.14.4" version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8e946c2b1349055e0b72ae281b238baf1a3ea7307c7e9f9d64673bdd9c26ac7" checksum = "8bf09f61b52cfcf4c00de50df88ae423d6c02354e385a86341133b5338630ad1"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-channel", "futures-channel",
@ -708,7 +708,7 @@ dependencies = [
"httpdate", "httpdate",
"itoa", "itoa",
"pin-project", "pin-project",
"socket2", "socket2 0.4.0",
"tokio", "tokio",
"tower-service", "tower-service",
"tracing", "tracing",
@ -764,6 +764,7 @@ checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"hashbrown", "hashbrown",
"serde",
] ]
[[package]] [[package]]
@ -793,7 +794,7 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7e2f18aece9709094573a9f24f483c4f65caa4298e2f7ae1b71cc65d853fad7" checksum = "f7e2f18aece9709094573a9f24f483c4f65caa4298e2f7ae1b71cc65d853fad7"
dependencies = [ dependencies = [
"socket2", "socket2 0.3.19",
"widestring", "widestring",
"winapi", "winapi",
"winreg 0.6.2", "winreg 0.6.2",
@ -846,9 +847,9 @@ checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.49" version = "0.3.50"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc15e39392125075f60c95ba416f5381ff6c3a948ff02ab12464715adf56c821" checksum = "2d99f9e3e84b8f67f846ef5b4cbbc3b1c29f6c759fcbce6f01aa0e73d932a24c"
dependencies = [ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
@ -884,9 +885,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.91" version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8916b1f6ca17130ec6568feccee27c156ad12037880833a3b842a823236502e7" checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714"
[[package]] [[package]]
name = "linked-hash-map" name = "linked-hash-map"
@ -896,9 +897,9 @@ checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.2" version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312" checksum = "5a3c91c24eae6777794bb1997ad98bbb87daf92890acab859f7eaa4320333176"
dependencies = [ dependencies = [
"scopeguard", "scopeguard",
] ]
@ -956,9 +957,9 @@ checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
[[package]] [[package]]
name = "memoffset" name = "memoffset"
version = "0.6.2" version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc14fc54a812b4472b4113facc3e44d099fbc0ea2ce0551fa5c703f8edfbfd38" checksum = "f83fb6581e8ed1f85fd45c116db8405483899489e38406156c25eb743554361d"
dependencies = [ dependencies = [
"autocfg", "autocfg",
] ]
@ -1315,10 +1316,11 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro-crate" name = "proc-macro-crate"
version = "0.1.5" version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" checksum = "41fdbd1df62156fbc5945f4762632564d7d038153091c3fcf1067f6aef7cff92"
dependencies = [ dependencies = [
"thiserror",
"toml", "toml",
] ]
@ -1336,9 +1338,9 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.24" version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec"
dependencies = [ dependencies = [
"unicode-xid", "unicode-xid",
] ]
@ -1623,7 +1625,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.0.2" version = "0.0.2"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"assign", "assign",
"js_int", "js_int",
@ -1643,7 +1645,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api" name = "ruma-api"
version = "0.17.0-alpha.2" version = "0.17.0-alpha.2"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"http", "http",
"percent-encoding", "percent-encoding",
@ -1658,7 +1660,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-api-macros" name = "ruma-api-macros"
version = "0.17.0-alpha.2" version = "0.17.0-alpha.2"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1669,7 +1671,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-appservice-api" name = "ruma-appservice-api"
version = "0.2.0-alpha.2" version = "0.2.0-alpha.2"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
@ -1683,7 +1685,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.10.0-alpha.2" version = "0.10.0-alpha.2"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"assign", "assign",
"http", "http",
@ -1701,21 +1703,24 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.3.0-alpha.1" version = "0.3.1"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"indexmap",
"js_int", "js_int",
"maplit", "maplit",
"ruma-identifiers", "ruma-identifiers",
"ruma-serde", "ruma-serde",
"serde", "serde",
"serde_json", "serde_json",
"tracing",
"wildmatch",
] ]
[[package]] [[package]]
name = "ruma-events" name = "ruma-events"
version = "0.22.0-alpha.2" version = "0.22.0-alpha.2"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -1729,7 +1734,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events-macros" name = "ruma-events-macros"
version = "0.22.0-alpha.2" version = "0.22.0-alpha.2"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1740,7 +1745,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.1.0-alpha.1" version = "0.1.0-alpha.1"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -1754,8 +1759,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers" name = "ruma-identifiers"
version = "0.18.0-alpha.1" version = "0.18.1"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"paste", "paste",
"rand", "rand",
@ -1768,8 +1773,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-macros" name = "ruma-identifiers-macros"
version = "0.18.0-alpha.1" version = "0.18.1"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1779,13 +1784,13 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-validation" name = "ruma-identifiers-validation"
version = "0.2.0" version = "0.2.2"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
[[package]] [[package]]
name = "ruma-identity-service-api" name = "ruma-identity-service-api"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"ruma-api", "ruma-api",
"ruma-common", "ruma-common",
@ -1798,7 +1803,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-push-gateway-api" name = "ruma-push-gateway-api"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-api", "ruma-api",
@ -1812,8 +1817,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde" name = "ruma-serde"
version = "0.3.0" version = "0.3.1"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"form_urlencoded", "form_urlencoded",
"itoa", "itoa",
@ -1825,8 +1830,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-serde-macros" name = "ruma-serde-macros"
version = "0.3.0" version = "0.3.1"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1836,8 +1841,8 @@ dependencies = [
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.6.0-alpha.1" version = "0.6.0"
source = "git+https://github.com/ruma/ruma?rev=f196f5b6f164973d6b343af31ab4e0457f743675#f196f5b6f164973d6b343af31ab4e0457f743675" source = "git+https://github.com/ruma/ruma?rev=a310ccc318a4eb51062923d570d5a86c1468e8a1#a310ccc318a4eb51062923d570d5a86c1468e8a1"
dependencies = [ dependencies = [
"base64 0.13.0", "base64 0.13.0",
"ring", "ring",
@ -1915,9 +1920,9 @@ dependencies = [
[[package]] [[package]]
name = "security-framework" name = "security-framework"
version = "2.1.2" version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d493c5f39e02dfb062cd8f33301f90f9b13b650e8c1b1d0fd75c19dd64bff69d" checksum = "3670b1d2fdf6084d192bc71ead7aabe6c06aa2ea3fbd9cc3ac111fa5c2b1bd84"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"core-foundation", "core-foundation",
@ -1928,9 +1933,9 @@ dependencies = [
[[package]] [[package]]
name = "security-framework-sys" name = "security-framework-sys"
version = "2.1.1" version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dee48cdde5ed250b0d3252818f646e174ab414036edb884dde62d80a3ac6082d" checksum = "3676258fd3cfe2c9a0ec99ce3038798d847ce3e4bb17746373eb9f0f1ac16339"
dependencies = [ dependencies = [
"core-foundation-sys", "core-foundation-sys",
"libc", "libc",
@ -2081,6 +2086,16 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "socket2"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2"
dependencies = [
"libc",
"winapi",
]
[[package]] [[package]]
name = "spin" name = "spin"
version = "0.5.2" version = "0.5.2"
@ -2105,7 +2120,7 @@ checksum = "3015a7d0a5fd5105c91c3710d42f9ccf0abfb287d62206484dcc67f9569a6483"
[[package]] [[package]]
name = "state-res" name = "state-res"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/timokoesters/state-res?branch=improvements#625c37cb776b381a83ab7ee58b13e32506849648" source = "git+https://github.com/ruma/state-res?rev=af450d0fe2b0e1c890284d0bc3b9d6d4008ac475#af450d0fe2b0e1c890284d0bc3b9d6d4008ac475"
dependencies = [ dependencies = [
"itertools 0.10.0", "itertools 0.10.0",
"log", "log",
@ -2167,9 +2182,9 @@ checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.64" version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fd9d1e9976102a03c542daa2eff1b43f9d72306342f3f8b3ed5fb8908195d6f" checksum = "3ce15dd3ed8aa2f8eeac4716d6ef5ab58b6b9256db41d7e1a0224c2788e8fd87"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2300,9 +2315,9 @@ dependencies = [
[[package]] [[package]]
name = "tinyvec" name = "tinyvec"
version = "1.1.1" version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342"
dependencies = [ dependencies = [
"tinyvec_macros", "tinyvec_macros",
] ]
@ -2634,9 +2649,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.72" version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fe8f61dba8e5d645a4d8132dc7a0a66861ed5e1045d2c0ed940fab33bac0fbe" checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"serde", "serde",
@ -2646,9 +2661,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-backend" name = "wasm-bindgen-backend"
version = "0.2.72" version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "046ceba58ff062da072c7cb4ba5b22a37f00a302483f7e2a6cdc18fedbdc1fd3" checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"lazy_static", "lazy_static",
@ -2661,9 +2676,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-futures" name = "wasm-bindgen-futures"
version = "0.4.22" version = "0.4.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73157efb9af26fb564bb59a009afd1c7c334a44db171d280690d0c3faaec3468" checksum = "81b8b767af23de6ac18bf2168b690bed2902743ddf0fb39252e36f9e2bfc63ea"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys", "js-sys",
@ -2673,9 +2688,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.72" version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ef9aa01d36cda046f797c57959ff5f3c615c9cc63997a8d545831ec7976819b" checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@ -2683,9 +2698,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.72" version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96eb45c1b2ee33545a813a92dbb53856418bf7eb54ab34f7f7ff1448a5b3735d" checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2696,15 +2711,15 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.72" version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7148f4696fb4960a346eaa60bbfb42a1ac4ebba21f750f75fc1375b098d5ffa" checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489"
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.49" version = "0.3.50"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59fe19d70f5dacc03f6e46777213facae5ac3801575d56ca6cbd4c93dcd12310" checksum = "a905d57e488fec8861446d3393670fb50d27a262344013181c2cdf9fff5481be"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@ -2732,6 +2747,12 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c"
[[package]]
name = "wildmatch"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07ae7ce410f81ba679081aac1d4874f3b1c328535b630209aa5b4cdaaf895e20"
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"

@ -18,12 +18,12 @@ rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "93e62c86e
#rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] } #rocket = { git = "https://github.com/timokoesters/Rocket.git", branch = "empty_parameters", default-features = false, features = ["tls"] }
# Used for matrix spec type definitions and helpers # Used for matrix spec type definitions and helpers
ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "appservice-api", "client-api", "federation-api", "push-gateway-api", "unstable-pre-spec", "unstable-synapse-quirks", "unstable-exhaustive-types"], rev = "f196f5b6f164973d6b343af31ab4e0457f743675" } ruma = { git = "https://github.com/ruma/ruma", rev = "a310ccc318a4eb51062923d570d5a86c1468e8a1", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "unstable-pre-spec", "unstable-exhaustive-types"] }
#ruma = { git = "https://github.com/DevinR528/ruma", features = ["rand", "client-api", "federation-api", "push-gateway-api", "unstable-exhaustive-types", "unstable-pre-spec", "unstable-synapse-quirks"], branch = "verified-export" } #ruma = { git = "https://github.com/DevinR528/ruma", features = ["rand", "client-api", "federation-api", "push-gateway-api", "unstable-exhaustive-types", "unstable-pre-spec", "unstable-synapse-quirks"], branch = "verified-export" }
#ruma = { path = "../ruma/ruma", features = ["unstable-exhaustive-types", "rand", "client-api", "federation-api", "push-gateway-api", "unstable-pre-spec", "unstable-synapse-quirks"] } #ruma = { path = "../ruma/ruma", features = ["unstable-exhaustive-types", "rand", "client-api", "federation-api", "push-gateway-api", "unstable-pre-spec", "unstable-synapse-quirks"] }
# Used when doing state resolution # Used when doing state resolution
state-res = { git = "https://github.com/timokoesters/state-res", branch = "improvements", features = ["unstable-pre-spec"] } state-res = { git = "https://github.com/ruma/state-res", rev = "af450d0fe2b0e1c890284d0bc3b9d6d4008ac475", features = ["unstable-pre-spec"] }
# TODO: remove the gen-eventid feature # TODO: remove the gen-eventid feature
#state-res = { git = "https://github.com/ruma/state-res", branch = "main", features = ["unstable-pre-spec", "gen-eventid"] } #state-res = { git = "https://github.com/ruma/state-res", branch = "main", features = ["unstable-pre-spec", "gen-eventid"] }
#state-res = { git = "https://github.com/ruma/state-res", rev = "1621a491a9e867a1ad4dff9f2f92b0c1e2d44aa0", features = ["unstable-pre-spec", "gen-eventid"] } #state-res = { git = "https://github.com/ruma/state-res", rev = "1621a491a9e867a1ad4dff9f2f92b0c1e2d44aa0", features = ["unstable-pre-spec", "gen-eventid"] }

@ -21,7 +21,7 @@ use ruma::{
}, },
EventType, EventType,
}, },
RoomAliasId, RoomId, RoomVersionId, UserId, push, RoomAliasId, RoomId, RoomVersionId, UserId,
}; };
use register::RegistrationKind; use register::RegistrationKind;
@ -181,7 +181,7 @@ pub async fn register_route(
EventType::PushRules, EventType::PushRules,
&ruma::events::push_rules::PushRulesEvent { &ruma::events::push_rules::PushRulesEvent {
content: ruma::events::push_rules::PushRulesEventContent { content: ruma::events::push_rules::PushRulesEventContent {
global: crate::push_rules::default_pushrules(&user_id), global: push::Ruleset::server_default(&user_id),
}, },
}, },
&db.globals, &db.globals,

@ -46,7 +46,7 @@ pub async fn create_content_route(
db.flush().await?; db.flush().await?;
Ok(create_content::Response { Ok(create_content::Response {
content_uri: mxc, content_uri: mxc.try_into().expect("Invalid mxc:// URI"),
blurhash: None, blurhash: None,
} }
.into()) .into())

@ -10,10 +10,7 @@ use ruma::{
}, },
}, },
events::{push_rules, EventType}, events::{push_rules, EventType},
push::{ push::{ConditionalPushRuleInit, PatternedPushRuleInit, SimplePushRuleInit},
ConditionalPushRuleInit, ContentPushRule, OverridePushRule, PatternedPushRuleInit,
RoomPushRule, SenderPushRule, SimplePushRuleInit, UnderridePushRule,
},
}; };
#[cfg(feature = "conduit_bin")] #[cfg(feature = "conduit_bin")]
@ -67,29 +64,24 @@ pub async fn get_pushrule_route(
let rule = match body.kind { let rule = match body.kind {
RuleKind::Override => global RuleKind::Override => global
.override_ .override_
.iter() .get(body.rule_id.as_str())
.find(|rule| rule.0.rule_id == body.rule_id) .map(|rule| rule.clone().into()),
.map(|rule| rule.0.clone().into()),
RuleKind::Underride => global RuleKind::Underride => global
.underride .underride
.iter() .get(body.rule_id.as_str())
.find(|rule| rule.0.rule_id == body.rule_id) .map(|rule| rule.clone().into()),
.map(|rule| rule.0.clone().into()),
RuleKind::Sender => global RuleKind::Sender => global
.sender .sender
.iter() .get(body.rule_id.as_str())
.find(|rule| rule.0.rule_id == body.rule_id) .map(|rule| rule.clone().into()),
.map(|rule| rule.0.clone().into()),
RuleKind::Room => global RuleKind::Room => global
.room .room
.iter() .get(body.rule_id.as_str())
.find(|rule| rule.0.rule_id == body.rule_id) .map(|rule| rule.clone().into()),
.map(|rule| rule.0.clone().into()),
RuleKind::Content => global RuleKind::Content => global
.content .content
.iter() .get(body.rule_id.as_str())
.find(|rule| rule.0.rule_id == body.rule_id) .map(|rule| rule.clone().into()),
.map(|rule| rule.0.clone().into()),
RuleKind::_Custom(_) => None, RuleKind::_Custom(_) => None,
}; };
@ -105,14 +97,15 @@ pub async fn get_pushrule_route(
#[cfg_attr( #[cfg_attr(
feature = "conduit_bin", feature = "conduit_bin",
put("/_matrix/client/r0/pushrules/<_>/<_>/<_>", data = "<body>") put("/_matrix/client/r0/pushrules/<_>/<_>/<_>", data = "<req>")
)] )]
#[tracing::instrument(skip(db, body))] #[tracing::instrument(skip(db, req))]
pub async fn set_pushrule_route( pub async fn set_pushrule_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<set_pushrule::Request<'_>>, req: Ruma<set_pushrule::Request<'_>>,
) -> ConduitResult<set_pushrule::Response> { ) -> ConduitResult<set_pushrule::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_user = req.sender_user.as_ref().expect("user is authenticated");
let body = req.body;
if body.scope != "global" { if body.scope != "global" {
return Err(Error::BadRequest( return Err(Error::BadRequest(
@ -132,107 +125,62 @@ pub async fn set_pushrule_route(
let global = &mut event.content.global; let global = &mut event.content.global;
match body.kind { match body.kind {
RuleKind::Override => { RuleKind::Override => {
if let Some(rule) = global global.override_.replace(
.override_
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.override_.remove(&rule);
}
global.override_.insert(OverridePushRule(
ConditionalPushRuleInit { ConditionalPushRuleInit {
actions: body.actions.clone(), actions: body.actions,
default: false, default: false,
enabled: true, enabled: true,
rule_id: body.rule_id.clone(), rule_id: body.rule_id,
conditions: body.conditions.clone(), conditions: body.conditions,
} }
.into(), .into(),
)); );
} }
RuleKind::Underride => { RuleKind::Underride => {
if let Some(rule) = global global.underride.replace(
.underride
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.underride.remove(&rule);
}
global.underride.insert(UnderridePushRule(
ConditionalPushRuleInit { ConditionalPushRuleInit {
actions: body.actions.clone(), actions: body.actions,
default: false, default: false,
enabled: true, enabled: true,
rule_id: body.rule_id.clone(), rule_id: body.rule_id,
conditions: body.conditions.clone(), conditions: body.conditions,
} }
.into(), .into(),
)); );
} }
RuleKind::Sender => { RuleKind::Sender => {
if let Some(rule) = global global.sender.replace(
.sender
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.sender.remove(&rule);
}
global.sender.insert(SenderPushRule(
SimplePushRuleInit { SimplePushRuleInit {
actions: body.actions.clone(), actions: body.actions,
default: false, default: false,
enabled: true, enabled: true,
rule_id: body.rule_id.clone(), rule_id: body.rule_id,
} }
.into(), .into(),
)); );
} }
RuleKind::Room => { RuleKind::Room => {
if let Some(rule) = global global.room.replace(
.room
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.room.remove(&rule);
}
global.room.insert(RoomPushRule(
SimplePushRuleInit { SimplePushRuleInit {
actions: body.actions.clone(), actions: body.actions,
default: false, default: false,
enabled: true, enabled: true,
rule_id: body.rule_id.clone(), rule_id: body.rule_id,
} }
.into(), .into(),
)); );
} }
RuleKind::Content => { RuleKind::Content => {
if let Some(rule) = global global.content.replace(
.content
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.content.remove(&rule);
}
global.content.insert(ContentPushRule(
PatternedPushRuleInit { PatternedPushRuleInit {
actions: body.actions.clone(), actions: body.actions,
default: false, default: false,
enabled: true, enabled: true,
rule_id: body.rule_id.clone(), rule_id: body.rule_id,
pattern: body.pattern.clone().unwrap_or_default(), pattern: body.pattern.unwrap_or_default(),
} }
.into(), .into(),
)); );
} }
RuleKind::_Custom(_) => {} RuleKind::_Custom(_) => {}
} }
@ -280,29 +228,24 @@ pub async fn get_pushrule_actions_route(
let actions = match body.kind { let actions = match body.kind {
RuleKind::Override => global RuleKind::Override => global
.override_ .override_
.iter() .get(body.rule_id.as_str())
.find(|rule| rule.0.rule_id == body.rule_id) .map(|rule| rule.actions.clone()),
.map(|rule| rule.0.actions.clone()),
RuleKind::Underride => global RuleKind::Underride => global
.underride .underride
.iter() .get(body.rule_id.as_str())
.find(|rule| rule.0.rule_id == body.rule_id) .map(|rule| rule.actions.clone()),
.map(|rule| rule.0.actions.clone()),
RuleKind::Sender => global RuleKind::Sender => global
.sender .sender
.iter() .get(body.rule_id.as_str())
.find(|rule| rule.0.rule_id == body.rule_id) .map(|rule| rule.actions.clone()),
.map(|rule| rule.0.actions.clone()),
RuleKind::Room => global RuleKind::Room => global
.room .room
.iter() .get(body.rule_id.as_str())
.find(|rule| rule.0.rule_id == body.rule_id) .map(|rule| rule.actions.clone()),
.map(|rule| rule.0.actions.clone()),
RuleKind::Content => global RuleKind::Content => global
.content .content
.iter() .get(body.rule_id.as_str())
.find(|rule| rule.0.rule_id == body.rule_id) .map(|rule| rule.actions.clone()),
.map(|rule| rule.0.actions.clone()),
RuleKind::_Custom(_) => None, RuleKind::_Custom(_) => None,
}; };
@ -343,63 +286,33 @@ pub async fn set_pushrule_actions_route(
let global = &mut event.content.global; let global = &mut event.content.global;
match body.kind { match body.kind {
RuleKind::Override => { RuleKind::Override => {
if let Some(mut rule) = global if let Some(mut rule) = global.override_.get(body.rule_id.as_str()).cloned() {
.override_ rule.actions = body.actions.clone();
.iter() global.override_.replace(rule);
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.override_.remove(&rule);
rule.0.actions = body.actions.clone();
global.override_.insert(rule);
} }
} }
RuleKind::Underride => { RuleKind::Underride => {
if let Some(mut rule) = global if let Some(mut rule) = global.underride.get(body.rule_id.as_str()).cloned() {
.underride rule.actions = body.actions.clone();
.iter() global.underride.replace(rule);
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.underride.remove(&rule);
rule.0.actions = body.actions.clone();
global.underride.insert(rule);
} }
} }
RuleKind::Sender => { RuleKind::Sender => {
if let Some(mut rule) = global if let Some(mut rule) = global.sender.get(body.rule_id.as_str()).cloned() {
.sender rule.actions = body.actions.clone();
.iter() global.sender.replace(rule);
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.sender.remove(&rule);
rule.0.actions = body.actions.clone();
global.sender.insert(rule);
} }
} }
RuleKind::Room => { RuleKind::Room => {
if let Some(mut rule) = global if let Some(mut rule) = global.room.get(body.rule_id.as_str()).cloned() {
.room rule.actions = body.actions.clone();
.iter() global.room.replace(rule);
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.room.remove(&rule);
rule.0.actions = body.actions.clone();
global.room.insert(rule);
} }
} }
RuleKind::Content => { RuleKind::Content => {
if let Some(mut rule) = global if let Some(mut rule) = global.content.get(body.rule_id.as_str()).cloned() {
.content rule.actions = body.actions.clone();
.iter() global.content.replace(rule);
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.content.remove(&rule);
rule.0.actions = body.actions.clone();
global.content.insert(rule);
} }
} }
RuleKind::_Custom(_) => {} RuleKind::_Custom(_) => {}
@ -449,28 +362,28 @@ pub async fn get_pushrule_enabled_route(
RuleKind::Override => global RuleKind::Override => global
.override_ .override_
.iter() .iter()
.find(|rule| rule.0.rule_id == body.rule_id) .find(|rule| rule.rule_id == body.rule_id)
.map_or(false, |rule| rule.0.enabled), .map_or(false, |rule| rule.enabled),
RuleKind::Underride => global RuleKind::Underride => global
.underride .underride
.iter() .iter()
.find(|rule| rule.0.rule_id == body.rule_id) .find(|rule| rule.rule_id == body.rule_id)
.map_or(false, |rule| rule.0.enabled), .map_or(false, |rule| rule.enabled),
RuleKind::Sender => global RuleKind::Sender => global
.sender .sender
.iter() .iter()
.find(|rule| rule.0.rule_id == body.rule_id) .find(|rule| rule.rule_id == body.rule_id)
.map_or(false, |rule| rule.0.enabled), .map_or(false, |rule| rule.enabled),
RuleKind::Room => global RuleKind::Room => global
.room .room
.iter() .iter()
.find(|rule| rule.0.rule_id == body.rule_id) .find(|rule| rule.rule_id == body.rule_id)
.map_or(false, |rule| rule.0.enabled), .map_or(false, |rule| rule.enabled),
RuleKind::Content => global RuleKind::Content => global
.content .content
.iter() .iter()
.find(|rule| rule.0.rule_id == body.rule_id) .find(|rule| rule.rule_id == body.rule_id)
.map_or(false, |rule| rule.0.enabled), .map_or(false, |rule| rule.enabled),
RuleKind::_Custom(_) => false, RuleKind::_Custom(_) => false,
}; };
@ -508,62 +421,37 @@ pub async fn set_pushrule_enabled_route(
let global = &mut event.content.global; let global = &mut event.content.global;
match body.kind { match body.kind {
RuleKind::Override => { RuleKind::Override => {
if let Some(mut rule) = global if let Some(mut rule) = global.override_.get(body.rule_id.as_str()).cloned() {
.override_
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.override_.remove(&rule); global.override_.remove(&rule);
rule.0.enabled = body.enabled; rule.enabled = body.enabled;
global.override_.insert(rule); global.override_.insert(rule);
} }
} }
RuleKind::Underride => { RuleKind::Underride => {
if let Some(mut rule) = global if let Some(mut rule) = global.underride.get(body.rule_id.as_str()).cloned() {
.underride
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.underride.remove(&rule); global.underride.remove(&rule);
rule.0.enabled = body.enabled; rule.enabled = body.enabled;
global.underride.insert(rule); global.underride.insert(rule);
} }
} }
RuleKind::Sender => { RuleKind::Sender => {
if let Some(mut rule) = global if let Some(mut rule) = global.sender.get(body.rule_id.as_str()).cloned() {
.sender
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.sender.remove(&rule); global.sender.remove(&rule);
rule.0.enabled = body.enabled; rule.enabled = body.enabled;
global.sender.insert(rule); global.sender.insert(rule);
} }
} }
RuleKind::Room => { RuleKind::Room => {
if let Some(mut rule) = global if let Some(mut rule) = global.room.get(body.rule_id.as_str()).cloned() {
.room
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.room.remove(&rule); global.room.remove(&rule);
rule.0.enabled = body.enabled; rule.enabled = body.enabled;
global.room.insert(rule); global.room.insert(rule);
} }
} }
RuleKind::Content => { RuleKind::Content => {
if let Some(mut rule) = global if let Some(mut rule) = global.content.get(body.rule_id.as_str()).cloned() {
.content
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.content.remove(&rule); global.content.remove(&rule);
rule.0.enabled = body.enabled; rule.enabled = body.enabled;
global.content.insert(rule); global.content.insert(rule);
} }
} }
@ -612,52 +500,27 @@ pub async fn delete_pushrule_route(
let global = &mut event.content.global; let global = &mut event.content.global;
match body.kind { match body.kind {
RuleKind::Override => { RuleKind::Override => {
if let Some(rule) = global if let Some(rule) = global.override_.get(body.rule_id.as_str()).cloned() {
.override_
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.override_.remove(&rule); global.override_.remove(&rule);
} }
} }
RuleKind::Underride => { RuleKind::Underride => {
if let Some(rule) = global if let Some(rule) = global.underride.get(body.rule_id.as_str()).cloned() {
.underride
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.underride.remove(&rule); global.underride.remove(&rule);
} }
} }
RuleKind::Sender => { RuleKind::Sender => {
if let Some(rule) = global if let Some(rule) = global.sender.get(body.rule_id.as_str()).cloned() {
.sender
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.sender.remove(&rule); global.sender.remove(&rule);
} }
} }
RuleKind::Room => { RuleKind::Room => {
if let Some(rule) = global if let Some(rule) = global.room.get(body.rule_id.as_str()).cloned() {
.room
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.room.remove(&rule); global.room.remove(&rule);
} }
} }
RuleKind::Content => { RuleKind::Content => {
if let Some(rule) = global if let Some(rule) = global.content.get(body.rule_id.as_str()).cloned() {
.content
.iter()
.find(|rule| rule.0.rule_id == body.rule_id)
.cloned()
{
global.content.remove(&rule); global.content.remove(&rule);
} }
} }

@ -3,10 +3,7 @@ use crate::{pdu::PduBuilder, ConduitResult, Database, Error, Result, Ruma};
use ruma::{ use ruma::{
api::client::{ api::client::{
error::ErrorKind, error::ErrorKind,
r0::state::{ r0::state::{get_state_events, get_state_events_for_key, send_state_event},
get_state_events, get_state_events_for_empty_key, get_state_events_for_key,
send_state_event_for_empty_key, send_state_event_for_key,
},
}, },
events::{ events::{
room::history_visibility::{HistoryVisibility, HistoryVisibilityEventContent}, room::history_visibility::{HistoryVisibility, HistoryVisibilityEventContent},
@ -25,8 +22,8 @@ use rocket::{get, put};
#[tracing::instrument(skip(db, body))] #[tracing::instrument(skip(db, body))]
pub async fn send_state_event_for_key_route( pub async fn send_state_event_for_key_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<send_state_event_for_key::Request<'_>>, body: Ruma<send_state_event::Request<'_>>,
) -> ConduitResult<send_state_event_for_key::Response> { ) -> ConduitResult<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 content = serde_json::from_str::<serde_json::Value>( let content = serde_json::from_str::<serde_json::Value>(
@ -49,7 +46,7 @@ pub async fn send_state_event_for_key_route(
db.flush().await?; db.flush().await?;
Ok(send_state_event_for_key::Response { event_id }.into()) Ok(send_state_event::Response { event_id }.into())
} }
#[cfg_attr( #[cfg_attr(
@ -59,8 +56,8 @@ pub async fn send_state_event_for_key_route(
#[tracing::instrument(skip(db, body))] #[tracing::instrument(skip(db, body))]
pub async fn send_state_event_for_empty_key_route( pub async fn send_state_event_for_empty_key_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<send_state_event_for_empty_key::Request<'_>>, body: Ruma<send_state_event::Request<'_>>,
) -> ConduitResult<send_state_event_for_empty_key::Response> { ) -> ConduitResult<send_state_event::Response> {
// This just calls send_state_event_for_key_route // This just calls send_state_event_for_key_route
let Ruma { let Ruma {
body, body,
@ -81,7 +78,7 @@ pub async fn send_state_event_for_empty_key_route(
&db, &db,
sender_user sender_user
.as_ref() .as_ref()
.expect("no user for send state empty key rout"), .expect("no user for send state empty key route"),
&body.content, &body.content,
json, json,
&body.room_id, &body.room_id,
@ -91,7 +88,7 @@ pub async fn send_state_event_for_empty_key_route(
db.flush().await?; db.flush().await?;
Ok(send_state_event_for_empty_key::Response { event_id }.into()) Ok(send_state_event::Response { event_id }.into())
} }
#[cfg_attr( #[cfg_attr(
@ -199,8 +196,8 @@ pub async fn get_state_events_for_key_route(
#[tracing::instrument(skip(db, body))] #[tracing::instrument(skip(db, body))]
pub async fn get_state_events_for_empty_key_route( pub async fn get_state_events_for_empty_key_route(
db: State<'_, Database>, db: State<'_, Database>,
body: Ruma<get_state_events_for_empty_key::Request<'_>>, body: Ruma<get_state_events_for_key::Request<'_>>,
) -> ConduitResult<get_state_events_for_empty_key::Response> { ) -> ConduitResult<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)]
@ -236,7 +233,7 @@ pub async fn get_state_events_for_empty_key_route(
"State event not found.", "State event not found.",
))?; ))?;
Ok(get_state_events_for_empty_key::Response { Ok(get_state_events_for_key::Response {
content: serde_json::value::to_raw_value(&event.content) content: serde_json::value::to_raw_value(&event.content)
.map_err(|_| Error::bad_database("Invalid event content in database"))?, .map_err(|_| Error::bad_database("Invalid event content in database"))?,
} }

@ -217,7 +217,7 @@ impl Database {
} }
pub async fn watch(&self, user_id: &UserId, device_id: &DeviceId) { pub async fn watch(&self, user_id: &UserId, device_id: &DeviceId) {
let userid_bytes = user_id.to_string().as_bytes().to_vec(); let userid_bytes = user_id.as_bytes().to_vec();
let mut userid_prefix = userid_bytes.clone(); let mut userid_prefix = userid_bytes.clone();
userid_prefix.push(0xff); userid_prefix.push(0xff);
@ -241,7 +241,7 @@ impl Database {
// Events for rooms we are in // Events for rooms we are in
for room_id in self.rooms.rooms_joined(user_id).filter_map(|r| r.ok()) { for room_id in self.rooms.rooms_joined(user_id).filter_map(|r| r.ok()) {
let roomid_bytes = room_id.to_string().as_bytes().to_vec(); let roomid_bytes = room_id.as_bytes().to_vec();
let mut roomid_prefix = roomid_bytes.clone(); let mut roomid_prefix = roomid_bytes.clone();
roomid_prefix.push(0xff); roomid_prefix.push(0xff);

@ -30,7 +30,7 @@ impl AccountData {
.as_bytes() .as_bytes()
.to_vec(); .to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(&user_id.to_string().as_bytes()); prefix.extend_from_slice(&user_id.as_bytes());
prefix.push(0xff); prefix.push(0xff);
// Remove old entry // Remove old entry
@ -42,7 +42,7 @@ impl AccountData {
let mut key = prefix; let mut key = prefix;
key.extend_from_slice(&globals.next_count()?.to_be_bytes()); key.extend_from_slice(&globals.next_count()?.to_be_bytes());
key.push(0xff); key.push(0xff);
key.extend_from_slice(event_type.to_string().as_bytes()); key.extend_from_slice(event_type.as_ref().as_bytes());
let json = serde_json::to_value(data).expect("all types here can be serialized"); // TODO: maybe add error handling let json = serde_json::to_value(data).expect("all types here can be serialized"); // TODO: maybe add error handling
if json.get("type").is_none() || json.get("content").is_none() { if json.get("type").is_none() || json.get("content").is_none() {
@ -89,7 +89,7 @@ impl AccountData {
.as_bytes() .as_bytes()
.to_vec(); .to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(&user_id.to_string().as_bytes()); prefix.extend_from_slice(&user_id.as_bytes());
prefix.push(0xff); prefix.push(0xff);
// Skip the data that's exactly at since, because we sent that last time // Skip the data that's exactly at since, because we sent that last time
@ -135,7 +135,7 @@ impl AccountData {
.as_bytes() .as_bytes()
.to_vec(); .to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(&user_id.to_string().as_bytes()); prefix.extend_from_slice(&user_id.as_bytes());
prefix.push(0xff); prefix.push(0xff);
let kind = kind.clone(); let kind = kind.clone();
@ -148,7 +148,7 @@ impl AccountData {
k.rsplit(|&b| b == 0xff) k.rsplit(|&b| b == 0xff)
.next() .next()
.map(|current_event_type| { .map(|current_event_type| {
current_event_type == kind.to_string().as_bytes() current_event_type == kind.as_ref().as_bytes()
}) })
.unwrap_or(false) .unwrap_or(false)
}) })

@ -24,7 +24,7 @@ impl KeyBackups {
) -> Result<String> { ) -> Result<String> {
let version = globals.next_count()?.to_string(); let version = globals.next_count()?.to_string();
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(&version.as_bytes()); key.extend_from_slice(&version.as_bytes());
@ -39,7 +39,7 @@ impl KeyBackups {
} }
pub fn delete_backup(&self, user_id: &UserId, version: &str) -> Result<()> { pub fn delete_backup(&self, user_id: &UserId, version: &str) -> Result<()> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(&version.as_bytes()); key.extend_from_slice(&version.as_bytes());
@ -67,7 +67,7 @@ impl KeyBackups {
backup_metadata: &BackupAlgorithm, backup_metadata: &BackupAlgorithm,
globals: &super::globals::Globals, globals: &super::globals::Globals,
) -> Result<String> { ) -> Result<String> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(&version.as_bytes()); key.extend_from_slice(&version.as_bytes());
@ -89,7 +89,7 @@ impl KeyBackups {
} }
pub fn get_latest_backup(&self, user_id: &UserId) -> Result<Option<(String, BackupAlgorithm)>> { pub fn get_latest_backup(&self, user_id: &UserId) -> Result<Option<(String, BackupAlgorithm)>> {
let mut prefix = user_id.to_string().as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
self.backupid_algorithm self.backupid_algorithm
.scan_prefix(&prefix) .scan_prefix(&prefix)
@ -113,7 +113,7 @@ impl KeyBackups {
} }
pub fn get_backup(&self, user_id: &UserId, version: &str) -> Result<Option<BackupAlgorithm>> { pub fn get_backup(&self, user_id: &UserId, version: &str) -> Result<Option<BackupAlgorithm>> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(version.as_bytes()); key.extend_from_slice(version.as_bytes());
@ -132,7 +132,7 @@ impl KeyBackups {
key_data: &KeyBackupData, key_data: &KeyBackupData,
globals: &super::globals::Globals, globals: &super::globals::Globals,
) -> Result<()> { ) -> Result<()> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(version.as_bytes()); key.extend_from_slice(version.as_bytes());
@ -147,7 +147,7 @@ impl KeyBackups {
.insert(&key, &globals.next_count()?.to_be_bytes())?; .insert(&key, &globals.next_count()?.to_be_bytes())?;
key.push(0xff); key.push(0xff);
key.extend_from_slice(room_id.to_string().as_bytes()); key.extend_from_slice(room_id.as_bytes());
key.push(0xff); key.push(0xff);
key.extend_from_slice(session_id.as_bytes()); key.extend_from_slice(session_id.as_bytes());
@ -160,7 +160,7 @@ impl KeyBackups {
} }
pub fn count_keys(&self, user_id: &UserId, version: &str) -> Result<usize> { pub fn count_keys(&self, user_id: &UserId, version: &str) -> Result<usize> {
let mut prefix = user_id.to_string().as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(version.as_bytes()); prefix.extend_from_slice(version.as_bytes());
@ -168,7 +168,7 @@ impl KeyBackups {
} }
pub fn get_etag(&self, user_id: &UserId, version: &str) -> Result<String> { pub fn get_etag(&self, user_id: &UserId, version: &str) -> Result<String> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(&version.as_bytes()); key.extend_from_slice(&version.as_bytes());
@ -187,7 +187,7 @@ impl KeyBackups {
user_id: &UserId, user_id: &UserId,
version: &str, version: &str,
) -> Result<BTreeMap<RoomId, RoomKeyBackup>> { ) -> Result<BTreeMap<RoomId, RoomKeyBackup>> {
let mut prefix = user_id.to_string().as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(version.as_bytes()); prefix.extend_from_slice(version.as_bytes());
prefix.push(0xff); prefix.push(0xff);
@ -240,7 +240,7 @@ impl KeyBackups {
version: &str, version: &str,
room_id: &RoomId, room_id: &RoomId,
) -> BTreeMap<String, KeyBackupData> { ) -> BTreeMap<String, KeyBackupData> {
let mut prefix = user_id.to_string().as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(version.as_bytes()); prefix.extend_from_slice(version.as_bytes());
prefix.push(0xff); prefix.push(0xff);
@ -278,7 +278,7 @@ impl KeyBackups {
room_id: &RoomId, room_id: &RoomId,
session_id: &str, session_id: &str,
) -> Result<Option<KeyBackupData>> { ) -> Result<Option<KeyBackupData>> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(version.as_bytes()); key.extend_from_slice(version.as_bytes());
key.push(0xff); key.push(0xff);
@ -297,7 +297,7 @@ impl KeyBackups {
} }
pub fn delete_all_keys(&self, user_id: &UserId, version: &str) -> Result<()> { pub fn delete_all_keys(&self, user_id: &UserId, version: &str) -> Result<()> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(&version.as_bytes()); key.extend_from_slice(&version.as_bytes());
key.push(0xff); key.push(0xff);
@ -320,7 +320,7 @@ impl KeyBackups {
version: &str, version: &str,
room_id: &RoomId, room_id: &RoomId,
) -> Result<()> { ) -> Result<()> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(&version.as_bytes()); key.extend_from_slice(&version.as_bytes());
key.push(0xff); key.push(0xff);
@ -346,7 +346,7 @@ impl KeyBackups {
room_id: &RoomId, room_id: &RoomId,
session_id: &str, session_id: &str,
) -> Result<()> { ) -> Result<()> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(&version.as_bytes()); key.extend_from_slice(&version.as_bytes());
key.push(0xff); key.push(0xff);

@ -9,15 +9,8 @@ use ruma::{
}, },
OutgoingRequest, OutgoingRequest,
}, },
events::{ events::{room::power_levels::PowerLevelsEventContent, EventType},
room::{ push::{Action, PushConditionRoomCtx, PushFormat, Ruleset, Tweak},
member::{MemberEventContent, MembershipState},
message::{MessageEventContent, MessageType, TextMessageEventContent},
power_levels::PowerLevelsEventContent,
},
EventType,
},
push::{Action, PushCondition, PushFormat, Ruleset, Tweak},
uint, UInt, UserId, uint, UInt, UserId,
}; };
use sled::IVec; use sled::IVec;
@ -181,276 +174,56 @@ pub async fn send_push_notice(
pdu: &PduEvent, pdu: &PduEvent,
db: &Database, db: &Database,
) -> Result<()> { ) -> Result<()> {
if let Some(msgtype) = pdu.content.get("msgtype").and_then(|b| b.as_str()) { let power_levels: PowerLevelsEventContent = db
if msgtype == "m.notice" { .rooms
return Ok(()); .room_state_get(&pdu.room_id, &EventType::RoomPowerLevels, "")?
.map(|ev| {
serde_json::from_value(ev.content)
.map_err(|_| Error::bad_database("invalid m.room.power_levels event"))
})
.transpose()?
.unwrap_or_default();
let ctx = PushConditionRoomCtx {
room_id: pdu.room_id.clone(),
member_count: (db.rooms.room_members(&pdu.room_id).count() as u32).into(),
user_display_name: user.localpart().into(), // TODO: Use actual display name
users_power_levels: power_levels.users,
default_power_level: power_levels.users_default,
notification_power_levels: power_levels.notifications,
};
let mut notify = None;
let mut tweaks = Vec::new();
for action in ruleset.get_actions(&pdu.to_sync_state_event(), &ctx) {
let n = match action {
Action::DontNotify => false,
// TODO: Implement proper support for coalesce
Action::Notify | Action::Coalesce => true,
Action::SetTweak(tweak) => {
tweaks.push(tweak.clone());
continue;
}
};
if notify.is_some() {
return Err(Error::bad_database(
r#"Malformed pushrule contains more than one of these actions: ["dont_notify", "notify", "coalesce"]"#,
));
} }
notify = Some(n);
} }
for rule in ruleset.into_iter() { let notify = notify.ok_or_else(|| {
// TODO: can actions contain contradictory Actions Error::bad_database(
if rule r#"Malformed pushrule contains none of these actions: ["dont_notify", "notify", "coalesce"]"#,
.actions )
.iter() })?;
.any(|act| matches!(act, ruma::push::Action::DontNotify))
|| !rule.enabled
{
continue;
}
match rule.rule_id.as_str() { if notify {
".m.rule.master" => {} send_notice(unread, pusher, tweaks, pdu, db).await?;
".m.rule.suppress_notices" => {
if pdu.kind == EventType::RoomMessage
&& pdu
.content
.get("msgtype")
.map_or(false, |ty| ty == "m.notice")
{
let tweaks = rule
.actions
.iter()
.filter_map(|a| match a {
Action::SetTweak(tweak) => Some(tweak.clone()),
_ => None,
})
.collect::<Vec<_>>();
send_notice(unread, pusher, tweaks, pdu, db).await?;
break;
}
}
".m.rule.invite_for_me" => {
if let EventType::RoomMember = &pdu.kind {
if pdu.state_key.as_deref() == Some(user.as_str())
&& serde_json::from_value::<MemberEventContent>(pdu.content.clone())
.map_err(|_| Error::bad_database("PDU contained bad message content"))?
.membership
== MembershipState::Invite
{
let tweaks = rule
.actions
.iter()
.filter_map(|a| match a {
Action::SetTweak(tweak) => Some(tweak.clone()),
_ => None,
})
.collect::<Vec<_>>();
send_notice(unread, pusher, tweaks, pdu, db).await?;
break;
}
}
}
".m.rule.member_event" => {
if let EventType::RoomMember = &pdu.kind {
// TODO use this?
let _member = serde_json::from_value::<MemberEventContent>(pdu.content.clone())
.map_err(|_| Error::bad_database("PDU contained bad message content"))?;
if let Some(conditions) = rule.conditions {
if conditions.iter().any(|cond| match cond {
PushCondition::EventMatch { key, pattern } => {
let mut json =
serde_json::to_value(pdu).expect("PDU is valid JSON");
for key in key.split('.') {
json = json[key].clone();
}
// TODO: this is baddddd
json.to_string().contains(pattern)
}
_ => false,
}) {
let tweaks = rule
.actions
.iter()
.filter_map(|a| match a {
Action::SetTweak(tweak) => Some(tweak.clone()),
_ => None,
})
.collect::<Vec<_>>();
send_notice(unread, pusher, tweaks, pdu, db).await?;
break;
}
}
}
}
".m.rule.contains_display_name" => {
if let EventType::RoomMessage = &pdu.kind {
let msg_content =
serde_json::from_value::<MessageEventContent>(pdu.content.clone())
.map_err(|_| {
Error::bad_database("PDU contained bad message content")
})?;
if let MessageType::Text(TextMessageEventContent { body, .. }) =
&msg_content.msgtype
{
if body.contains(user.localpart()) {
let tweaks = rule
.actions
.iter()
.filter_map(|a| match a {
Action::SetTweak(tweak) => Some(tweak.clone()),
_ => None,
})
.collect::<Vec<_>>();
send_notice(unread, pusher, tweaks, pdu, db).await?;
break;
}
}
}
}
".m.rule.tombstone" => {
if pdu.kind == EventType::RoomTombstone && pdu.state_key.as_deref() == Some("") {
let tweaks = rule
.actions
.iter()
.filter_map(|a| match a {
Action::SetTweak(tweak) => Some(tweak.clone()),
_ => None,
})
.collect::<Vec<_>>();
send_notice(unread, pusher, tweaks, pdu, db).await?;
break;
}
}
".m.rule.roomnotif" => {
if let EventType::RoomMessage = &pdu.kind {
let msg_content =
serde_json::from_value::<MessageEventContent>(pdu.content.clone())
.map_err(|_| {
Error::bad_database("PDU contained bad message content")
})?;
if let MessageType::Text(TextMessageEventContent { body, .. }) =
&msg_content.msgtype
{
let power_level_cmp = |pl: PowerLevelsEventContent| {
&pl.notifications.room
<= pl.users.get(&pdu.sender).unwrap_or(&ruma::int!(0))
};
let deserialize = |pl: PduEvent| {
serde_json::from_value::<PowerLevelsEventContent>(pl.content).ok()
};
if body.contains("@room")
&& db
.rooms
.room_state_get(&pdu.room_id, &EventType::RoomPowerLevels, "")?
.map(deserialize)
.flatten()
.map_or(false, power_level_cmp)
{
let tweaks = rule
.actions
.iter()
.filter_map(|a| match a {
Action::SetTweak(tweak) => Some(tweak.clone()),
_ => None,
})
.collect::<Vec<_>>();
send_notice(unread, pusher, tweaks, pdu, db).await?;
break;
}
}
}
}
".m.rule.contains_user_name" => {
if let EventType::RoomMessage = &pdu.kind {
let msg_content =
serde_json::from_value::<MessageEventContent>(pdu.content.clone())
.map_err(|_| {
Error::bad_database("PDU contained bad message content")
})?;
if let MessageType::Text(TextMessageEventContent { body, .. }) =
&msg_content.msgtype
{
if body.contains(user.localpart()) {
let tweaks = rule
.actions
.iter()
.filter_map(|a| match a {
Action::SetTweak(tweak) => Some(tweak.clone()),
_ => None,
})
.collect::<Vec<_>>();
send_notice(unread, pusher, tweaks, pdu, db).await?;
break;
}
}
}
}
".m.rule.call" => {
if pdu.kind == EventType::CallInvite {
let tweaks = rule
.actions
.iter()
.filter_map(|a| match a {
Action::SetTweak(tweak) => Some(tweak.clone()),
_ => None,
})
.collect::<Vec<_>>();
send_notice(unread, pusher, tweaks, pdu, db).await?;
break;
}
}
".m.rule.encrypted_room_one_to_one" => {
if db.rooms.room_members(&pdu.room_id).count() == 2
&& pdu.kind == EventType::RoomEncrypted
{
let tweaks = rule
.actions
.iter()
.filter_map(|a| match a {
Action::SetTweak(tweak) => Some(tweak.clone()),
_ => None,
})
.collect::<Vec<_>>();
send_notice(unread, pusher, tweaks, pdu, db).await?;
break;
}
}
".m.rule.room_one_to_one" => {
if db.rooms.room_members(&pdu.room_id).count() == 2
&& pdu.kind == EventType::RoomMessage
{
let tweaks = rule
.actions
.iter()
.filter_map(|a| match a {
Action::SetTweak(tweak) => Some(tweak.clone()),
_ => None,
})
.collect::<Vec<_>>();
send_notice(unread, pusher, tweaks, pdu, db).await?;
break;
}
}
".m.rule.message" => {
if pdu.kind == EventType::RoomMessage {
let tweaks = rule
.actions
.iter()
.filter_map(|a| match a {
Action::SetTweak(tweak) => Some(tweak.clone()),
_ => None,
})
.collect::<Vec<_>>();
send_notice(unread, pusher, tweaks, pdu, db).await?;
break;
}
}
".m.rule.encrypted" => {
if pdu.kind == EventType::RoomEncrypted {
let tweaks = rule
.actions
.iter()
.filter_map(|a| match a {
Action::SetTweak(tweak) => Some(tweak.clone()),
_ => None,
})
.collect::<Vec<_>>();
send_notice(unread, pusher, tweaks, pdu, db).await?;
break;
}
}
_ => {}
}
} }
Ok(()) Ok(())

@ -151,7 +151,7 @@ impl Rooms {
event_type: &EventType, event_type: &EventType,
state_key: &str, state_key: &str,
) -> Result<Option<PduEvent>> { ) -> Result<Option<PduEvent>> {
let mut key = event_type.to_string().as_bytes().to_vec(); let mut key = event_type.as_ref().as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(&state_key.as_bytes()); key.extend_from_slice(&state_key.as_bytes());
@ -416,7 +416,7 @@ impl Rooms {
/// Returns the pdu's id. /// Returns the pdu's id.
pub fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<IVec>> { pub fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<IVec>> {
self.eventid_pduid self.eventid_pduid
.get(event_id.to_string().as_bytes())? .get(event_id.as_bytes())?
.map_or(Ok(None), |pdu_id| Ok(Some(pdu_id))) .map_or(Ok(None), |pdu_id| Ok(Some(pdu_id)))
} }
@ -531,7 +531,7 @@ impl Rooms {
self.roomid_pduleaves.remove(key?)?; self.roomid_pduleaves.remove(key?)?;
} }
for event_id in event_ids.iter() { for event_id in event_ids {
let mut key = prefix.to_owned(); let mut key = prefix.to_owned();
key.extend_from_slice(event_id.as_bytes()); key.extend_from_slice(event_id.as_bytes());
self.roomid_pduleaves.insert(&key, event_id.as_bytes())?; self.roomid_pduleaves.insert(&key, event_id.as_bytes())?;
@ -690,7 +690,7 @@ impl Rooms {
.split_terminator(|c: char| !c.is_alphanumeric()) .split_terminator(|c: char| !c.is_alphanumeric())
.map(str::to_lowercase) .map(str::to_lowercase)
{ {
let mut key = pdu.room_id.to_string().as_bytes().to_vec(); let mut key = pdu.room_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(word.as_bytes()); key.extend_from_slice(word.as_bytes());
key.push(0xff); key.push(0xff);
@ -1264,7 +1264,7 @@ impl Rooms {
room_id: &RoomId, room_id: &RoomId,
since: u64, since: u64,
) -> Result<impl DoubleEndedIterator<Item = Result<(IVec, PduEvent)>>> { ) -> Result<impl DoubleEndedIterator<Item = Result<(IVec, PduEvent)>>> {
let mut prefix = room_id.to_string().as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
// Skip the first pdu if it's exactly at since, because we sent that last time // Skip the first pdu if it's exactly at since, because we sent that last time
@ -1298,7 +1298,7 @@ impl Rooms {
until: u64, until: u64,
) -> impl Iterator<Item = Result<(IVec, PduEvent)>> { ) -> impl Iterator<Item = Result<(IVec, PduEvent)>> {
// Create the first part of the full pdu id // Create the first part of the full pdu id
let mut prefix = room_id.to_string().as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
let mut current = prefix.clone(); let mut current = prefix.clone();
@ -1332,7 +1332,7 @@ impl Rooms {
from: u64, from: u64,
) -> impl Iterator<Item = Result<(IVec, PduEvent)>> { ) -> impl Iterator<Item = Result<(IVec, PduEvent)>> {
// Create the first part of the full pdu id // Create the first part of the full pdu id
let mut prefix = room_id.to_string().as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
let mut current = prefix.clone(); let mut current = prefix.clone();
@ -1883,9 +1883,9 @@ impl Rooms {
} }
pub fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> { pub fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
let mut userroom_id = user_id.to_string().as_bytes().to_vec(); let mut userroom_id = user_id.as_bytes().to_vec();
userroom_id.push(0xff); userroom_id.push(0xff);
userroom_id.extend_from_slice(room_id.to_string().as_bytes()); userroom_id.extend_from_slice(room_id.as_bytes());
Ok(self.roomuseroncejoinedids.get(userroom_id)?.is_some()) Ok(self.roomuseroncejoinedids.get(userroom_id)?.is_some())
} }

@ -34,7 +34,7 @@ impl RoomEdus {
event: EduEvent, event: EduEvent,
globals: &super::super::globals::Globals, globals: &super::super::globals::Globals,
) -> Result<()> { ) -> Result<()> {
let mut prefix = room_id.to_string().as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
// Remove old entry // Remove old entry
@ -49,7 +49,7 @@ impl RoomEdus {
key.rsplit(|&b| b == 0xff) key.rsplit(|&b| b == 0xff)
.next() .next()
.expect("rsplit always returns an element") .expect("rsplit always returns an element")
== user_id.to_string().as_bytes() == user_id.as_bytes()
}) })
{ {
// This is the old room_latest // This is the old room_latest
@ -59,7 +59,7 @@ impl RoomEdus {
let mut room_latest_id = prefix; let mut room_latest_id = prefix;
room_latest_id.extend_from_slice(&globals.next_count()?.to_be_bytes()); room_latest_id.extend_from_slice(&globals.next_count()?.to_be_bytes());
room_latest_id.push(0xff); room_latest_id.push(0xff);
room_latest_id.extend_from_slice(&user_id.to_string().as_bytes()); room_latest_id.extend_from_slice(&user_id.as_bytes());
self.readreceiptid_readreceipt.insert( self.readreceiptid_readreceipt.insert(
room_latest_id, room_latest_id,
@ -76,7 +76,7 @@ impl RoomEdus {
room_id: &RoomId, room_id: &RoomId,
since: u64, since: u64,
) -> Result<impl Iterator<Item = Result<Raw<ruma::events::AnySyncEphemeralRoomEvent>>>> { ) -> Result<impl Iterator<Item = Result<Raw<ruma::events::AnySyncEphemeralRoomEvent>>>> {
let mut prefix = room_id.to_string().as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
let mut first_possible_edu = prefix.clone(); let mut first_possible_edu = prefix.clone();
@ -102,9 +102,9 @@ impl RoomEdus {
count: u64, count: u64,
globals: &super::super::globals::Globals, globals: &super::super::globals::Globals,
) -> Result<()> { ) -> Result<()> {
let mut key = room_id.to_string().as_bytes().to_vec(); let mut key = room_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(&user_id.to_string().as_bytes()); key.extend_from_slice(&user_id.as_bytes());
self.roomuserid_privateread self.roomuserid_privateread
.insert(&key, &count.to_be_bytes())?; .insert(&key, &count.to_be_bytes())?;
@ -118,9 +118,9 @@ impl RoomEdus {
/// Returns the private read marker. /// Returns the private read marker.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn private_read_get(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> { pub fn private_read_get(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> {
let mut key = room_id.to_string().as_bytes().to_vec(); let mut key = room_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(&user_id.to_string().as_bytes()); key.extend_from_slice(&user_id.as_bytes());
self.roomuserid_privateread.get(key)?.map_or(Ok(None), |v| { self.roomuserid_privateread.get(key)?.map_or(Ok(None), |v| {
Ok(Some(utils::u64_from_bytes(&v).map_err(|_| { Ok(Some(utils::u64_from_bytes(&v).map_err(|_| {
@ -131,9 +131,9 @@ impl RoomEdus {
/// Returns the count of the last typing update in this room. /// Returns the count of the last typing update in this room.
pub fn last_privateread_update(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> { pub fn last_privateread_update(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
let mut key = room_id.to_string().as_bytes().to_vec(); let mut key = room_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(&user_id.to_string().as_bytes()); key.extend_from_slice(&user_id.as_bytes());
Ok(self Ok(self
.roomuserid_lastprivatereadupdate .roomuserid_lastprivatereadupdate
@ -155,7 +155,7 @@ impl RoomEdus {
timeout: u64, timeout: u64,
globals: &super::super::globals::Globals, globals: &super::super::globals::Globals,
) -> Result<()> { ) -> Result<()> {
let mut prefix = room_id.to_string().as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
let count = globals.next_count()?.to_be_bytes(); let count = globals.next_count()?.to_be_bytes();
@ -166,10 +166,10 @@ impl RoomEdus {
room_typing_id.extend_from_slice(&count); room_typing_id.extend_from_slice(&count);
self.typingid_userid self.typingid_userid
.insert(&room_typing_id, &*user_id.to_string().as_bytes())?; .insert(&room_typing_id, &*user_id.as_bytes())?;
self.roomid_lasttypingupdate self.roomid_lasttypingupdate
.insert(&room_id.to_string().as_bytes(), &count)?; .insert(&room_id.as_bytes(), &count)?;
Ok(()) Ok(())
} }
@ -181,7 +181,7 @@ impl RoomEdus {
room_id: &RoomId, room_id: &RoomId,
globals: &super::super::globals::Globals, globals: &super::super::globals::Globals,
) -> Result<()> { ) -> Result<()> {
let mut prefix = room_id.to_string().as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
let user_id = user_id.to_string(); let user_id = user_id.to_string();
@ -200,10 +200,8 @@ impl RoomEdus {
} }
if found_outdated { if found_outdated {
self.roomid_lasttypingupdate.insert( self.roomid_lasttypingupdate
&room_id.to_string().as_bytes(), .insert(&room_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
&globals.next_count()?.to_be_bytes(),
)?;
} }
Ok(()) Ok(())
@ -215,7 +213,7 @@ impl RoomEdus {
room_id: &RoomId, room_id: &RoomId,
globals: &super::super::globals::Globals, globals: &super::super::globals::Globals,
) -> Result<()> { ) -> Result<()> {
let mut prefix = room_id.to_string().as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
let current_timestamp = utils::millis_since_unix_epoch(); let current_timestamp = utils::millis_since_unix_epoch();
@ -248,10 +246,8 @@ impl RoomEdus {
} }
if found_outdated { if found_outdated {
self.roomid_lasttypingupdate.insert( self.roomid_lasttypingupdate
&room_id.to_string().as_bytes(), .insert(&room_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
&globals.next_count()?.to_be_bytes(),
)?;
} }
Ok(()) Ok(())
@ -268,7 +264,7 @@ impl RoomEdus {
Ok(self Ok(self
.roomid_lasttypingupdate .roomid_lasttypingupdate
.get(&room_id.to_string().as_bytes())? .get(&room_id.as_bytes())?
.map_or(Ok::<_, Error>(None), |bytes| { .map_or(Ok::<_, Error>(None), |bytes| {
Ok(Some(utils::u64_from_bytes(&bytes).map_err(|_| { Ok(Some(utils::u64_from_bytes(&bytes).map_err(|_| {
Error::bad_database("Count in roomid_lastroomactiveupdate is invalid.") Error::bad_database("Count in roomid_lastroomactiveupdate is invalid.")
@ -281,7 +277,7 @@ impl RoomEdus {
&self, &self,
room_id: &RoomId, room_id: &RoomId,
) -> Result<SyncEphemeralRoomEvent<ruma::events::typing::TypingEventContent>> { ) -> Result<SyncEphemeralRoomEvent<ruma::events::typing::TypingEventContent>> {
let mut prefix = room_id.to_string().as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
let mut user_ids = Vec::new(); let mut user_ids = Vec::new();
@ -322,11 +318,11 @@ impl RoomEdus {
let count = globals.next_count()?.to_be_bytes(); let count = globals.next_count()?.to_be_bytes();
let mut presence_id = room_id.to_string().as_bytes().to_vec(); let mut presence_id = room_id.as_bytes().to_vec();
presence_id.push(0xff); presence_id.push(0xff);
presence_id.extend_from_slice(&count); presence_id.extend_from_slice(&count);
presence_id.push(0xff); presence_id.push(0xff);
presence_id.extend_from_slice(&presence.sender.to_string().as_bytes()); presence_id.extend_from_slice(&presence.sender.as_bytes());
self.presenceid_presence.insert( self.presenceid_presence.insert(
presence_id, presence_id,
@ -334,7 +330,7 @@ impl RoomEdus {
)?; )?;
self.userid_lastpresenceupdate.insert( self.userid_lastpresenceupdate.insert(
&user_id.to_string().as_bytes(), &user_id.as_bytes(),
&utils::millis_since_unix_epoch().to_be_bytes(), &utils::millis_since_unix_epoch().to_be_bytes(),
)?; )?;
@ -345,7 +341,7 @@ impl RoomEdus {
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn ping_presence(&self, user_id: &UserId) -> Result<()> { pub fn ping_presence(&self, user_id: &UserId) -> Result<()> {
self.userid_lastpresenceupdate.insert( self.userid_lastpresenceupdate.insert(
&user_id.to_string().as_bytes(), &user_id.as_bytes(),
&utils::millis_since_unix_epoch().to_be_bytes(), &utils::millis_since_unix_epoch().to_be_bytes(),
)?; )?;
@ -355,7 +351,7 @@ impl RoomEdus {
/// Returns the timestamp of the last presence update of this user in millis since the unix epoch. /// Returns the timestamp of the last presence update of this user in millis since the unix epoch.
pub fn last_presence_update(&self, user_id: &UserId) -> Result<Option<u64>> { pub fn last_presence_update(&self, user_id: &UserId) -> Result<Option<u64>> {
self.userid_lastpresenceupdate self.userid_lastpresenceupdate
.get(&user_id.to_string().as_bytes())? .get(&user_id.as_bytes())?
.map(|bytes| { .map(|bytes| {
utils::u64_from_bytes(&bytes).map_err(|_| { utils::u64_from_bytes(&bytes).map_err(|_| {
Error::bad_database("Invalid timestamp in userid_lastpresenceupdate.") Error::bad_database("Invalid timestamp in userid_lastpresenceupdate.")
@ -398,7 +394,7 @@ impl RoomEdus {
.try_into() .try_into()
.map_err(|_| Error::bad_database("Invalid UserId in userid_lastpresenceupdate."))?; .map_err(|_| Error::bad_database("Invalid UserId in userid_lastpresenceupdate."))?;
for room_id in rooms.rooms_joined(&user_id).filter_map(|r| r.ok()) { for room_id in rooms.rooms_joined(&user_id).filter_map(|r| r.ok()) {
let mut presence_id = room_id.to_string().as_bytes().to_vec(); let mut presence_id = room_id.as_bytes().to_vec();
presence_id.push(0xff); presence_id.push(0xff);
presence_id.extend_from_slice(&count); presence_id.extend_from_slice(&count);
presence_id.push(0xff); presence_id.push(0xff);
@ -424,7 +420,7 @@ impl RoomEdus {
} }
self.userid_lastpresenceupdate.insert( self.userid_lastpresenceupdate.insert(
&user_id.to_string().as_bytes(), &user_id.as_bytes(),
&utils::millis_since_unix_epoch().to_be_bytes(), &utils::millis_since_unix_epoch().to_be_bytes(),
)?; )?;
} }
@ -443,7 +439,7 @@ impl RoomEdus {
) -> Result<HashMap<UserId, PresenceEvent>> { ) -> Result<HashMap<UserId, PresenceEvent>> {
self.presence_maintain(rooms, globals)?; self.presence_maintain(rooms, globals)?;
let mut prefix = room_id.to_string().as_bytes().to_vec(); let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
let mut first_possible_edu = prefix.clone(); let mut first_possible_edu = prefix.clone();

@ -16,7 +16,7 @@ use rocket::futures::stream::{FuturesUnordered, StreamExt};
use ruma::{ use ruma::{
api::{appservice, federation, OutgoingRequest}, api::{appservice, federation, OutgoingRequest},
events::{push_rules, EventType}, events::{push_rules, EventType},
uint, ServerName, UInt, UserId, push, uint, ServerName, UInt, UserId,
}; };
use sled::IVec; use sled::IVec;
use tokio::{select, sync::Semaphore}; use tokio::{select, sync::Semaphore};
@ -428,7 +428,7 @@ impl Sending {
.get::<push_rules::PushRulesEvent>(None, &userid, EventType::PushRules) .get::<push_rules::PushRulesEvent>(None, &userid, EventType::PushRules)
.map_err(|e| (OutgoingKind::Push(user.clone(), pushkey.clone()), e))? .map_err(|e| (OutgoingKind::Push(user.clone(), pushkey.clone()), e))?
.map(|ev| ev.content.global) .map(|ev| ev.content.global)
.unwrap_or_else(|| crate::push_rules::default_pushrules(&userid)); .unwrap_or_else(|| push::Ruleset::server_default(&userid));
let unread: UInt = if let Some(last_read) = db let unread: UInt = if let Some(last_read) = db
.rooms .rooms

@ -148,7 +148,7 @@ impl Uiaa {
device_id: &DeviceId, device_id: &DeviceId,
uiaainfo: Option<&UiaaInfo>, uiaainfo: Option<&UiaaInfo>,
) -> Result<()> { ) -> Result<()> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
@ -170,7 +170,7 @@ impl Uiaa {
device_id: &DeviceId, device_id: &DeviceId,
session: &str, session: &str,
) -> Result<UiaaInfo> { ) -> Result<UiaaInfo> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());

@ -9,6 +9,7 @@ use ruma::{
}, },
encryption::DeviceKeys, encryption::DeviceKeys,
events::{AnyToDeviceEvent, EventType}, events::{AnyToDeviceEvent, EventType},
identifiers::MxcUri,
serde::Raw, serde::Raw,
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, UInt, UserId, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, UInt, UserId,
}; };
@ -150,21 +151,22 @@ impl Users {
} }
/// Get a the avatar_url of a user. /// Get a the avatar_url of a user.
pub fn avatar_url(&self, user_id: &UserId) -> Result<Option<String>> { pub fn avatar_url(&self, user_id: &UserId) -> Result<Option<MxcUri>> {
self.userid_avatarurl self.userid_avatarurl
.get(user_id.to_string())? .get(user_id.to_string())?
.map_or(Ok(None), |bytes| { .map(|bytes| {
Ok(Some(utils::string_from_bytes(&bytes).map_err(|_| { let s = utils::string_from_bytes(&bytes)
Error::bad_database("Avatar URL in db is invalid.") .map_err(|_| Error::bad_database("Avatar URL in db is invalid."))?;
})?)) MxcUri::try_from(s).map_err(|_| Error::bad_database("Avatar URL in db is invalid."))
}) })
.transpose()
} }
/// Sets a new avatar_url or removes it if avatar_url is None. /// Sets a new avatar_url or removes it if avatar_url is None.
pub fn set_avatar_url(&self, user_id: &UserId, avatar_url: Option<String>) -> Result<()> { pub fn set_avatar_url(&self, user_id: &UserId, avatar_url: Option<MxcUri>) -> Result<()> {
if let Some(avatar_url) = avatar_url { if let Some(avatar_url) = avatar_url {
self.userid_avatarurl self.userid_avatarurl
.insert(user_id.to_string(), &*avatar_url)?; .insert(user_id.to_string(), avatar_url.to_string().as_str())?;
} else { } else {
self.userid_avatarurl.remove(user_id.to_string())?; self.userid_avatarurl.remove(user_id.to_string())?;
} }
@ -183,7 +185,7 @@ impl Users {
// This method should never be called for nonexistent users. // This method should never be called for nonexistent users.
assert!(self.exists(user_id)?); assert!(self.exists(user_id)?);
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
@ -206,7 +208,7 @@ impl Users {
/// Removes a device from a user. /// Removes a device from a user.
pub fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { pub fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
@ -232,7 +234,7 @@ impl Users {
/// Returns an iterator over all device ids of this user. /// Returns an iterator over all device ids of this user.
pub fn all_device_ids(&self, user_id: &UserId) -> impl Iterator<Item = Result<Box<DeviceId>>> { pub fn all_device_ids(&self, user_id: &UserId) -> impl Iterator<Item = Result<Box<DeviceId>>> {
let mut prefix = user_id.to_string().as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
// All devices have metadata // All devices have metadata
self.userdeviceid_metadata self.userdeviceid_metadata
@ -252,7 +254,7 @@ impl Users {
/// Replaces the access token of one device. /// Replaces the access token of one device.
pub fn set_token(&self, user_id: &UserId, device_id: &DeviceId, token: &str) -> Result<()> { pub fn set_token(&self, user_id: &UserId, device_id: &DeviceId, token: &str) -> Result<()> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
@ -280,7 +282,7 @@ impl Users {
one_time_key_value: &OneTimeKey, one_time_key_value: &OneTimeKey,
globals: &super::globals::Globals, globals: &super::globals::Globals,
) -> Result<()> { ) -> Result<()> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(device_id.as_bytes()); key.extend_from_slice(device_id.as_bytes());
@ -303,10 +305,8 @@ impl Users {
.expect("OneTimeKey::to_string always works"), .expect("OneTimeKey::to_string always works"),
)?; )?;
self.userid_lastonetimekeyupdate.insert( self.userid_lastonetimekeyupdate
&user_id.to_string().as_bytes(), .insert(&user_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
&globals.next_count()?.to_be_bytes(),
)?;
Ok(()) Ok(())
} }
@ -314,7 +314,7 @@ impl Users {
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
pub fn last_one_time_keys_update(&self, user_id: &UserId) -> Result<u64> { pub fn last_one_time_keys_update(&self, user_id: &UserId) -> Result<u64> {
self.userid_lastonetimekeyupdate self.userid_lastonetimekeyupdate
.get(&user_id.to_string().as_bytes())? .get(&user_id.as_bytes())?
.map(|bytes| { .map(|bytes| {
utils::u64_from_bytes(&bytes).map_err(|_| { utils::u64_from_bytes(&bytes).map_err(|_| {
Error::bad_database("Count in roomid_lastroomactiveupdate is invalid.") Error::bad_database("Count in roomid_lastroomactiveupdate is invalid.")
@ -330,18 +330,16 @@ impl Users {
key_algorithm: &DeviceKeyAlgorithm, key_algorithm: &DeviceKeyAlgorithm,
globals: &super::globals::Globals, globals: &super::globals::Globals,
) -> Result<Option<(DeviceKeyId, OneTimeKey)>> { ) -> Result<Option<(DeviceKeyId, OneTimeKey)>> {
let mut prefix = user_id.to_string().as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(device_id.as_bytes()); prefix.extend_from_slice(device_id.as_bytes());
prefix.push(0xff); prefix.push(0xff);
prefix.push(b'"'); // Annoying quotation mark prefix.push(b'"'); // Annoying quotation mark
prefix.extend_from_slice(key_algorithm.to_string().as_bytes()); prefix.extend_from_slice(key_algorithm.as_ref().as_bytes());
prefix.push(b':'); prefix.push(b':');
self.userid_lastonetimekeyupdate.insert( self.userid_lastonetimekeyupdate
&user_id.to_string().as_bytes(), .insert(&user_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
&globals.next_count()?.to_be_bytes(),
)?;
self.onetimekeyid_onetimekeys self.onetimekeyid_onetimekeys
.scan_prefix(&prefix) .scan_prefix(&prefix)
@ -371,7 +369,7 @@ impl Users {
user_id: &UserId, user_id: &UserId,
device_id: &DeviceId, device_id: &DeviceId,
) -> Result<BTreeMap<DeviceKeyAlgorithm, UInt>> { ) -> Result<BTreeMap<DeviceKeyAlgorithm, UInt>> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
@ -407,7 +405,7 @@ impl Users {
rooms: &super::rooms::Rooms, rooms: &super::rooms::Rooms,
globals: &super::globals::Globals, globals: &super::globals::Globals,
) -> Result<()> { ) -> Result<()> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
@ -432,7 +430,7 @@ impl Users {
) -> Result<()> { ) -> Result<()> {
// TODO: Check signatures // TODO: Check signatures
let mut prefix = user_id.to_string().as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
// Master key // Master key
@ -530,9 +528,9 @@ impl Users {
rooms: &super::rooms::Rooms, rooms: &super::rooms::Rooms,
globals: &super::globals::Globals, globals: &super::globals::Globals,
) -> Result<()> { ) -> Result<()> {
let mut key = target_id.to_string().as_bytes().to_vec(); let mut key = target_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(key_id.to_string().as_bytes()); key.extend_from_slice(key_id.as_bytes());
let mut cross_signing_key = let mut cross_signing_key =
serde_json::from_slice::<serde_json::Value>(&self.keyid_key.get(&key)?.ok_or( serde_json::from_slice::<serde_json::Value>(&self.keyid_key.get(&key)?.ok_or(
@ -615,14 +613,14 @@ impl Users {
continue; continue;
} }
let mut key = room_id.to_string().as_bytes().to_vec(); let mut key = room_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(&count); key.extend_from_slice(&count);
self.keychangeid_userid.insert(key, &*user_id.to_string())?; self.keychangeid_userid.insert(key, &*user_id.to_string())?;
} }
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(&count); key.extend_from_slice(&count);
self.keychangeid_userid.insert(key, &*user_id.to_string())?; self.keychangeid_userid.insert(key, &*user_id.to_string())?;
@ -635,7 +633,7 @@ impl Users {
user_id: &UserId, user_id: &UserId,
device_id: &DeviceId, device_id: &DeviceId,
) -> Result<Option<DeviceKeys>> { ) -> Result<Option<DeviceKeys>> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(device_id.as_bytes()); key.extend_from_slice(device_id.as_bytes());
@ -722,7 +720,7 @@ impl Users {
content: serde_json::Value, content: serde_json::Value,
globals: &super::globals::Globals, globals: &super::globals::Globals,
) -> Result<()> { ) -> Result<()> {
let mut key = target_user_id.to_string().as_bytes().to_vec(); let mut key = target_user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
key.extend_from_slice(target_device_id.as_bytes()); key.extend_from_slice(target_device_id.as_bytes());
key.push(0xff); key.push(0xff);
@ -749,7 +747,7 @@ impl Users {
) -> Result<Vec<Raw<AnyToDeviceEvent>>> { ) -> Result<Vec<Raw<AnyToDeviceEvent>>> {
let mut events = Vec::new(); let mut events = Vec::new();
let mut prefix = user_id.to_string().as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(device_id.as_bytes()); prefix.extend_from_slice(device_id.as_bytes());
prefix.push(0xff); prefix.push(0xff);
@ -771,7 +769,7 @@ impl Users {
device_id: &DeviceId, device_id: &DeviceId,
until: u64, until: u64,
) -> Result<()> { ) -> Result<()> {
let mut prefix = user_id.to_string().as_bytes().to_vec(); let mut prefix = user_id.as_bytes().to_vec();
prefix.push(0xff); prefix.push(0xff);
prefix.extend_from_slice(device_id.as_bytes()); prefix.extend_from_slice(device_id.as_bytes());
prefix.push(0xff); prefix.push(0xff);
@ -806,7 +804,7 @@ impl Users {
device_id: &DeviceId, device_id: &DeviceId,
device: &Device, device: &Device,
) -> Result<()> { ) -> Result<()> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
@ -829,7 +827,7 @@ impl Users {
user_id: &UserId, user_id: &UserId,
device_id: &DeviceId, device_id: &DeviceId,
) -> Result<Option<Device>> { ) -> Result<Option<Device>> {
let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); let mut userdeviceid = user_id.as_bytes().to_vec();
userdeviceid.push(0xff); userdeviceid.push(0xff);
userdeviceid.extend_from_slice(device_id.as_bytes()); userdeviceid.extend_from_slice(device_id.as_bytes());
@ -843,7 +841,7 @@ impl Users {
} }
pub fn all_devices_metadata(&self, user_id: &UserId) -> impl Iterator<Item = Result<Device>> { pub fn all_devices_metadata(&self, user_id: &UserId) -> impl Iterator<Item = Result<Device>> {
let mut key = user_id.to_string().as_bytes().to_vec(); let mut key = user_id.as_bytes().to_vec();
key.push(0xff); key.push(0xff);
self.userdeviceid_metadata self.userdeviceid_metadata

@ -3,7 +3,6 @@ pub mod client_server;
mod database; mod database;
mod error; mod error;
mod pdu; mod pdu;
mod push_rules;
mod ruma_wrapper; mod ruma_wrapper;
pub mod server_server; pub mod server_server;
mod utils; mod utils;

@ -7,7 +7,6 @@ pub mod server_server;
mod database; mod database;
mod error; mod error;
mod pdu; mod pdu;
mod push_rules;
mod ruma_wrapper; mod ruma_wrapper;
mod utils; mod utils;

@ -1,256 +0,0 @@
use ruma::{
push::{
Action, ConditionalPushRule, ConditionalPushRuleInit, ContentPushRule, OverridePushRule,
PatternedPushRule, PatternedPushRuleInit, PushCondition, RoomMemberCountIs, Ruleset, Tweak,
UnderridePushRule,
},
UserId,
};
pub fn default_pushrules(user_id: &UserId) -> Ruleset {
let mut rules = Ruleset::default();
rules.add(ContentPushRule(contains_user_name_rule(&user_id)));
for rule in vec![
master_rule(),
suppress_notices_rule(),
invite_for_me_rule(),
member_event_rule(),
contains_display_name_rule(),
tombstone_rule(),
roomnotif_rule(),
] {
rules.add(OverridePushRule(rule));
}
for rule in vec![
call_rule(),
encrypted_room_one_to_one_rule(),
room_one_to_one_rule(),
message_rule(),
encrypted_rule(),
] {
rules.add(UnderridePushRule(rule));
}
rules
}
pub fn master_rule() -> ConditionalPushRule {
ConditionalPushRuleInit {
actions: vec![Action::DontNotify],
default: true,
enabled: false,
rule_id: ".m.rule.master".to_owned(),
conditions: vec![],
}
.into()
}
pub fn suppress_notices_rule() -> ConditionalPushRule {
ConditionalPushRuleInit {
actions: vec![Action::DontNotify],
default: true,
enabled: true,
rule_id: ".m.rule.suppress_notices".to_owned(),
conditions: vec![PushCondition::EventMatch {
key: "content.msgtype".to_owned(),
pattern: "m.notice".to_owned(),
}],
}
.into()
}
pub fn invite_for_me_rule() -> ConditionalPushRule {
ConditionalPushRuleInit {
actions: vec![
Action::Notify,
Action::SetTweak(Tweak::Sound("default".to_owned())),
Action::SetTweak(Tweak::Highlight(false)),
],
default: true,
enabled: true,
rule_id: ".m.rule.invite_for_me".to_owned(),
conditions: vec![PushCondition::EventMatch {
key: "content.membership".to_owned(),
pattern: "m.invite".to_owned(),
}],
}
.into()
}
pub fn member_event_rule() -> ConditionalPushRule {
ConditionalPushRuleInit {
actions: vec![Action::DontNotify],
default: true,
enabled: true,
rule_id: ".m.rule.member_event".to_owned(),
conditions: vec![PushCondition::EventMatch {
key: "content.membership".to_owned(),
pattern: "type".to_owned(),
}],
}
.into()
}
pub fn contains_display_name_rule() -> ConditionalPushRule {
ConditionalPushRuleInit {
actions: vec![
Action::Notify,
Action::SetTweak(Tweak::Sound("default".to_owned())),
Action::SetTweak(Tweak::Highlight(true)),
],
default: true,
enabled: true,
rule_id: ".m.rule.contains_display_name".to_owned(),
conditions: vec![PushCondition::ContainsDisplayName],
}
.into()
}
pub fn tombstone_rule() -> ConditionalPushRule {
ConditionalPushRuleInit {
actions: vec![Action::Notify, Action::SetTweak(Tweak::Highlight(true))],
default: true,
enabled: true,
rule_id: ".m.rule.tombstone".to_owned(),
conditions: vec![
PushCondition::EventMatch {
key: "type".to_owned(),
pattern: "m.room.tombstone".to_owned(),
},
PushCondition::EventMatch {
key: "state_key".to_owned(),
pattern: "".to_owned(),
},
],
}
.into()
}
pub fn roomnotif_rule() -> ConditionalPushRule {
ConditionalPushRuleInit {
actions: vec![Action::Notify, Action::SetTweak(Tweak::Highlight(true))],
default: true,
enabled: true,
rule_id: ".m.rule.roomnotif".to_owned(),
conditions: vec![
PushCondition::EventMatch {
key: "content.body".to_owned(),
pattern: "@room".to_owned(),
},
PushCondition::SenderNotificationPermission {
key: "room".to_owned(),
},
],
}
.into()
}
pub fn contains_user_name_rule(user_id: &UserId) -> PatternedPushRule {
PatternedPushRuleInit {
actions: vec![
Action::Notify,
Action::SetTweak(Tweak::Sound("default".to_owned())),
Action::SetTweak(Tweak::Highlight(true)),
],
default: true,
enabled: true,
rule_id: ".m.rule.contains_user_name".to_owned(),
pattern: user_id.localpart().to_owned(),
}
.into()
}
pub fn call_rule() -> ConditionalPushRule {
ConditionalPushRuleInit {
actions: vec![
Action::Notify,
Action::SetTweak(Tweak::Sound("ring".to_owned())),
Action::SetTweak(Tweak::Highlight(false)),
],
default: true,
enabled: true,
rule_id: ".m.rule.call".to_owned(),
conditions: vec![PushCondition::EventMatch {
key: "type".to_owned(),
pattern: "m.call.invite".to_owned(),
}],
}
.into()
}
pub fn encrypted_room_one_to_one_rule() -> ConditionalPushRule {
ConditionalPushRuleInit {
actions: vec![
Action::Notify,
Action::SetTweak(Tweak::Sound("default".to_owned())),
Action::SetTweak(Tweak::Highlight(false)),
],
default: true,
enabled: true,
rule_id: ".m.rule.encrypted_room_one_to_one".to_owned(),
conditions: vec![
PushCondition::RoomMemberCount {
is: RoomMemberCountIs::from(2_u32.into()..),
},
PushCondition::EventMatch {
key: "type".to_owned(),
pattern: "m.room.encrypted".to_owned(),
},
],
}
.into()
}
pub fn room_one_to_one_rule() -> ConditionalPushRule {
ConditionalPushRuleInit {
actions: vec![
Action::Notify,
Action::SetTweak(Tweak::Sound("default".to_owned())),
Action::SetTweak(Tweak::Highlight(false)),
],
default: true,
enabled: true,
rule_id: ".m.rule.room_one_to_one".to_owned(),
conditions: vec![
PushCondition::RoomMemberCount {
is: RoomMemberCountIs::from(2_u32.into()..),
},
PushCondition::EventMatch {
key: "type".to_owned(),
pattern: "m.room.message".to_owned(),
},
],
}
.into()
}
pub fn message_rule() -> ConditionalPushRule {
ConditionalPushRuleInit {
actions: vec![Action::Notify, Action::SetTweak(Tweak::Highlight(false))],
default: true,
enabled: true,
rule_id: ".m.rule.message".to_owned(),
conditions: vec![PushCondition::EventMatch {
key: "type".to_owned(),
pattern: "m.room.message".to_owned(),
}],
}
.into()
}
pub fn encrypted_rule() -> ConditionalPushRule {
ConditionalPushRuleInit {
actions: vec![Action::Notify, Action::SetTweak(Tweak::Highlight(false))],
default: true,
enabled: true,
rule_id: ".m.rule.encrypted".to_owned(),
conditions: vec![PushCondition::EventMatch {
key: "type".to_owned(),
pattern: "m.room.encrypted".to_owned(),
}],
}
.into()
}

@ -1,6 +1,5 @@
use crate::Error; use crate::Error;
use ruma::{ use ruma::{
api::OutgoingRequest,
identifiers::{DeviceId, UserId}, identifiers::{DeviceId, UserId},
Outgoing, Outgoing,
}; };
@ -28,7 +27,7 @@ use {
/// This struct converts rocket requests into ruma structs by converting them into http requests /// This struct converts rocket requests into ruma structs by converting them into http requests
/// first. /// first.
pub struct Ruma<T: Outgoing + OutgoingRequest> { pub struct Ruma<T: Outgoing> {
pub body: T::Incoming, pub body: T::Incoming,
pub sender_user: Option<UserId>, pub sender_user: Option<UserId>,
pub sender_device: Option<Box<DeviceId>>, pub sender_device: Option<Box<DeviceId>>,
@ -37,7 +36,7 @@ pub struct Ruma<T: Outgoing + OutgoingRequest> {
} }
#[cfg(feature = "conduit_bin")] #[cfg(feature = "conduit_bin")]
impl<'a, T: Outgoing + OutgoingRequest> FromTransformedData<'a> for Ruma<T> impl<'a, T: Outgoing> FromTransformedData<'a> for Ruma<T>
where where
T::Incoming: IncomingRequest, T::Incoming: IncomingRequest,
{ {
@ -56,6 +55,8 @@ where
request: &'a Request<'_>, request: &'a Request<'_>,
outcome: Transformed<'a, Self>, outcome: Transformed<'a, Self>,
) -> FromDataFuture<'a, Self, Self::Error> { ) -> FromDataFuture<'a, Self, Self::Error> {
let metadata = T::Incoming::METADATA;
Box::pin(async move { Box::pin(async move {
let data = rocket::try_outcome!(outcome.owned()); let data = rocket::try_outcome!(outcome.owned());
let db = request let db = request
@ -80,7 +81,7 @@ where
.and_then(|as_token| as_token.as_str()) .and_then(|as_token| as_token.as_str())
.map_or(false, |as_token| token.as_deref() == Some(as_token)) .map_or(false, |as_token| token.as_deref() == Some(as_token))
}) { }) {
match T::METADATA.authentication { match metadata.authentication {
AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => { AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => {
let user_id = request.get_query_value::<String>("user_id").map_or_else( let user_id = request.get_query_value::<String>("user_id").map_or_else(
|| { || {
@ -112,7 +113,7 @@ where
AuthScheme::None => (None, None, true), AuthScheme::None => (None, None, true),
} }
} else { } else {
match T::METADATA.authentication { match metadata.authentication {
AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => { AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => {
if let Some(token) = token { if let Some(token) = token {
match db.users.find_from_token(&token).unwrap() { match db.users.find_from_token(&token).unwrap() {
@ -166,7 +167,7 @@ where
} }
} }
impl<T: Outgoing + OutgoingRequest> Deref for Ruma<T> { impl<T: Outgoing> Deref for Ruma<T> {
type Target = T::Incoming; type Target = T::Incoming;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {

@ -552,7 +552,7 @@ pub async fn send_transaction_message_route<'a>(
// events that it references. // events that it references.
let mut auth_cache = EventMap::new(); let mut auth_cache = EventMap::new();
for pdu in body.pdus.iter() { for pdu in &body.pdus {
// We do not add the event_id field to the pdu here because of signature and hashes checks // We do not add the event_id field to the pdu here because of signature and hashes checks
let (event_id, value) = match crate::pdu::gen_event_id_canonical_json(pdu) { let (event_id, value) = match crate::pdu::gen_event_id_canonical_json(pdu) {
Ok(t) => t, Ok(t) => t,
@ -757,7 +757,7 @@ fn handle_incoming_pdu<'a>(
// Build map of auth events // Build map of auth events
let mut auth_events = BTreeMap::new(); let mut auth_events = BTreeMap::new();
for id in incoming_pdu.auth_events.iter() { for id in &incoming_pdu.auth_events {
let auth_event = auth_cache.get(id).ok_or_else(|| { let auth_event = auth_cache.get(id).ok_or_else(|| {
"Auth event not found, event failed recursive auth checks.".to_string() "Auth event not found, event failed recursive auth checks.".to_string()
})?; })?;
@ -869,7 +869,7 @@ fn handle_incoming_pdu<'a>(
}; };
let mut state = BTreeMap::new(); let mut state = BTreeMap::new();
for pdu in state_vec.into_iter() { for pdu in state_vec {
match state.entry((pdu.kind.clone(), pdu.state_key.clone().ok_or_else(|| "Found non-state pdu in state events.".to_owned())?)) { match state.entry((pdu.kind.clone(), pdu.state_key.clone().ok_or_else(|| "Found non-state pdu in state events.".to_owned())?)) {
Entry::Vacant(v) => { Entry::Vacant(v) => {
v.insert(pdu); v.insert(pdu);
@ -1268,7 +1268,7 @@ pub(crate) async fn fetch_signing_keys(
.await .await
{ {
debug!("Got signing keys: {:?}", keys); debug!("Got signing keys: {:?}", keys);
for k in keys.server_keys.into_iter() { for k in keys.server_keys {
db.globals.add_signing_key(origin, &k)?; db.globals.add_signing_key(origin, &k)?;
result.extend( result.extend(
k.verify_keys k.verify_keys

Loading…
Cancel
Save