From f6046871f42beca8b21c22807e306b8fafea49d5 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Jun 2021 20:12:36 +0200 Subject: [PATCH 1/6] Upgrade Ruma --- Cargo.lock | 301 +++++++++++++++++---------------- Cargo.toml | 2 +- src/client_server/account.rs | 2 +- src/client_server/room.rs | 4 +- src/client_server/to_device.rs | 32 ++-- src/database/users.rs | 4 +- src/server_server.rs | 18 +- 7 files changed, 183 insertions(+), 180 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 630d4142..c3d7408b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,9 +8,9 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" dependencies = [ "memchr", ] @@ -174,9 +174,9 @@ checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "cc" -version = "1.0.68" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" +checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" dependencies = [ "jobserver", ] @@ -272,13 +272,14 @@ dependencies = [ [[package]] name = "const-oid" version = "0.5.2" -source = "git+https://github.com/RustCrypto/utils?rev=51e7c9d734e4d3c5279ba1c181c65b1bd77bcad0#51e7c9d734e4d3c5279ba1c181c65b1bd77bcad0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "279bc8fc53f788a75c7804af68237d1fce02cde1e275a886a4b320604dc2aeda" [[package]] name = "const_fn" -version = "0.4.8" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f92cfa0fd5690b3cf8c1ef2cabbd9b7ef22fa53cf5e1f92b05103f6d5d1cf6e7" +checksum = "402da840495de3f976eaefc3485b7f5eb5b0bf9761f9a47be27fe975b3b8c2ec" [[package]] name = "constant_time_eq" @@ -339,9 +340,9 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.4" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52fb27eab85b17fbb9f6fd667089e07d6a2eb8743d02639ee7f6a7a7729c9c94" +checksum = "2584f639eb95fea8c798496315b297cf81b9b58b6d30ab066a75455333cf4b12" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -352,9 +353,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.4" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feb231f0d4d6af81aed15928e58ecf5816aa62a2393e2c82f46973e92a9a278" +checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" dependencies = [ "autocfg", "cfg-if 1.0.0", @@ -392,17 +393,18 @@ dependencies = [ [[package]] name = "der" -version = "0.3.4" -source = "git+https://github.com/RustCrypto/utils?rev=51e7c9d734e4d3c5279ba1c181c65b1bd77bcad0#51e7c9d734e4d3c5279ba1c181c65b1bd77bcad0" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eeb9d92785d1facb50567852ce75d0858630630e7eabea59cf7eb7474051087" dependencies = [ "const-oid", ] [[package]] name = "derive_more" -version = "0.99.14" +version = "0.99.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc7b9cef1e351660e5443924e4f43ab25fbbed3e9a5f052df3677deb4d6b320" +checksum = "f82b1b72f1263f214c0f823371768776c4f5841b942c9883aa8e5ec584fd0ba6" dependencies = [ "convert_case", "proc-macro2", @@ -451,18 +453,18 @@ dependencies = [ [[package]] name = "directories" -version = "3.0.2" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e69600ff1703123957937708eb27f7a564e48885c537782722ed0ba3189ce1d7" +checksum = "f8fed639d60b58d0f53498ab13d26f621fd77569cc6edb031f4cc36a2ad9da0f" dependencies = [ "dirs-sys", ] [[package]] name = "dirs-sys" -version = "0.3.6" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780" +checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a" dependencies = [ "libc", "redox_users", @@ -586,9 +588,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.15" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7e43a803dae2fa37c1f6a8fe121e1f7bf9548b4dfc0522a42f34145dadfc27" +checksum = "a9d5813545e459ad3ca1bff9915e9ad7f1a47dc6a91b627ce321d5863b7dd253" dependencies = [ "futures-channel", "futures-core", @@ -601,9 +603,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.15" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2" +checksum = "ce79c6a52a299137a6013061e0cf0e688fce5d7f1bc60125f520912fdb29ec25" dependencies = [ "futures-core", "futures-sink", @@ -611,15 +613,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.15" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1" +checksum = "098cd1c6dda6ca01650f1a37a794245eb73181d0d4d4e955e2f3c37db7af1815" [[package]] name = "futures-executor" -version = "0.3.15" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "badaa6a909fac9e7236d0620a2f57f7664640c56575b71a7552fbd68deafab79" +checksum = "10f6cb7042eda00f0049b1d2080aa4b93442997ee507eb3828e8bd7577f94c9d" dependencies = [ "futures-core", "futures-task", @@ -628,17 +630,16 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.15" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1" +checksum = "365a1a1fb30ea1c03a830fdb2158f5236833ac81fa0ad12fe35b29cddc35cb04" [[package]] name = "futures-macro" -version = "0.3.15" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121" +checksum = "668c6733a182cd7deb4f1de7ba3bf2120823835b3bcfbeacf7d2c4a773c1bb8b" dependencies = [ - "autocfg", "proc-macro-hack", "proc-macro2", "quote", @@ -647,23 +648,22 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.15" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282" +checksum = "5c5629433c555de3d82861a7a4e3794a4c40040390907cfbfd7143a92a426c23" [[package]] name = "futures-task" -version = "0.3.15" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae" +checksum = "ba7aa51095076f3ba6d9a1f702f74bd05ec65f555d70d2033d55ba8d69f581bc" [[package]] name = "futures-util" -version = "0.3.15" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967" +checksum = "3c144ad54d60f23927f0a6b6d816e4271278b64f005ad65e4e35291d2de9c025" dependencies = [ - "autocfg", "futures-channel", "futures-core", "futures-io", @@ -723,9 +723,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.3" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ "cfg-if 1.0.0", "libc", @@ -750,9 +750,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "h2" -version = "0.3.3" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "825343c4eef0b63f541f8903f395dc5beb362a979b5799a84062527ef1e37726" +checksum = "fc018e188373e2777d0ef2467ebff62a08e66c3f5857b23c8fbec3018210dc00" dependencies = [ "bytes", "fnv", @@ -815,9 +815,9 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.2" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" +checksum = "5dfb77c123b4e2f72a2069aeae0b4b4949cc7e966df277813fc16347e7549737" dependencies = [ "bytes", "http", @@ -826,15 +826,15 @@ dependencies = [ [[package]] name = "httparse" -version = "1.4.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a87b616e37e93c22fb19bcd386f02f3af5ea98a25670ad0fce773de23c5e68" +checksum = "4a1ce40d6fc9764887c2fdc7305c3dcc429ba11ff981c1509416afd5697e4437" [[package]] name = "httpdate" -version = "1.0.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" +checksum = "05842d0d43232b23ccb7060ecb0f0626922c21f30012e97b767b30afd4a5d4b9" [[package]] name = "humantime" @@ -847,9 +847,9 @@ dependencies = [ [[package]] name = "hyper" -version = "0.14.8" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3f71a7eea53a3f8257a7b4795373ff886397178cd634430ea94e12d7fe4fe34" +checksum = "1e5f105c494081baa3bf9e200b279e27ec1623895cd504c7dbef8d0b080fcf54" dependencies = [ "bytes", "futures-channel", @@ -1012,18 +1012,18 @@ checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2" [[package]] name = "js-sys" -version = "0.3.51" +version = "0.3.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062" +checksum = "2d99f9e3e84b8f67f846ef5b4cbbc3b1c29f6c759fcbce6f01aa0e73d932a24c" dependencies = [ "wasm-bindgen", ] [[package]] name = "js_int" -version = "0.2.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "defaba9bcd19568a4b4b3736b23e368e5b75e3ea126fd4cb3e4ad2ea5af274fd" +checksum = "fcae89e078a96b781b38f36225bb3a174b8f6e905dfec550dd16a13539c82acc" dependencies = [ "serde", ] @@ -1056,9 +1056,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.95" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" +checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" [[package]] name = "libloading" @@ -1090,9 +1090,9 @@ checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" [[package]] name = "lock_api" -version = "0.4.4" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" +checksum = "5a3c91c24eae6777794bb1997ad98bbb87daf92890acab859f7eaa4320333176" dependencies = [ "scopeguard", ] @@ -1157,9 +1157,9 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "memchr" -version = "2.4.0" +version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] name = "memoffset" @@ -1321,9 +1321,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl-probe" -version = "0.1.4" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" +checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "opentelemetry" @@ -1383,7 +1383,7 @@ dependencies = [ "cfg-if 1.0.0", "instant", "libc", - "redox_syscall", + "redox_syscall 0.2.6", "smallvec", "winapi", ] @@ -1396,9 +1396,9 @@ checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" [[package]] name = "pear" -version = "0.2.3" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e44241c5e4c868e3eaa78b7c1848cadd6344ed4f54d029832d32b415a58702" +checksum = "86ab3a2b792945ed67eadbbdcbd2898f8dd2319392b2a45ac21adea5245cb113" dependencies = [ "inlinable_string", "pear_codegen", @@ -1407,9 +1407,9 @@ dependencies = [ [[package]] name = "pear_codegen" -version = "0.2.3" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82a5ca643c2303ecb740d506539deba189e16f2754040a42901cd8105d0282d0" +checksum = "620c9c4776ba41b59ab101360c9b1419c0c8c81cd2e6e39fae7109e7425994cb" dependencies = [ "proc-macro2", "proc-macro2-diagnostics", @@ -1474,8 +1474,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkcs8" -version = "0.6.0" -source = "git+https://github.com/RustCrypto/utils?rev=51e7c9d734e4d3c5279ba1c181c65b1bd77bcad0#51e7c9d734e4d3c5279ba1c181c65b1bd77bcad0" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9c2f795bc591cb3384cb64082a578b89207ac92bb89c9d98c1ea2ace7cd8110" dependencies = [ "der", "spki", @@ -1534,9 +1535,9 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.27" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" dependencies = [ "unicode-xid", ] @@ -1629,7 +1630,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" dependencies = [ - "getrandom 0.2.3", + "getrandom 0.2.2", ] [[package]] @@ -1652,21 +1653,28 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.8" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + +[[package]] +name = "redox_syscall" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8270314b5ccceb518e7e578952f0b72b88222d02e8f77f5ecf7abbb673539041" dependencies = [ "bitflags", ] [[package]] name = "redox_users" -version = "0.4.0" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" +checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" dependencies = [ - "getrandom 0.2.3", - "redox_syscall", + "getrandom 0.1.16", + "redox_syscall 0.1.57", + "rust-argon2", ] [[package]] @@ -1691,9 +1699,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.5.4" +version = "1.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759" dependencies = [ "aho-corasick", "memchr", @@ -1712,9 +1720,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.6.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" [[package]] name = "remove_dir_all" @@ -1874,7 +1882,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.1.2" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "assign", "js_int", @@ -1895,7 +1903,7 @@ dependencies = [ [[package]] name = "ruma-api" version = "0.17.0" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "bytes", "http", @@ -1911,7 +1919,7 @@ dependencies = [ [[package]] name = "ruma-api-macros" version = "0.17.0" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1922,7 +1930,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.2.0" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "ruma-api", "ruma-common", @@ -1936,7 +1944,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.10.2" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "assign", "bytes", @@ -1955,8 +1963,8 @@ dependencies = [ [[package]] name = "ruma-common" -version = "0.5.2" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +version = "0.5.3" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "indexmap", "js_int", @@ -1971,7 +1979,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.22.2" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "indoc", "js_int", @@ -1986,7 +1994,7 @@ dependencies = [ [[package]] name = "ruma-events-macros" version = "0.22.2" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1997,7 +2005,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.1.0" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "js_int", "ruma-api", @@ -2011,8 +2019,8 @@ dependencies = [ [[package]] name = "ruma-identifiers" -version = "0.19.1" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +version = "0.19.2" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "paste", "rand 0.8.3", @@ -2025,8 +2033,8 @@ dependencies = [ [[package]] name = "ruma-identifiers-macros" -version = "0.19.1" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +version = "0.19.2" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "quote", "ruma-identifiers-validation", @@ -2036,12 +2044,12 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.4.0" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" [[package]] name = "ruma-identity-service-api" version = "0.1.0" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "js_int", "ruma-api", @@ -2054,7 +2062,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.1.0" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "js_int", "ruma-api", @@ -2069,7 +2077,7 @@ dependencies = [ [[package]] name = "ruma-serde" version = "0.4.0" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "bytes", "form_urlencoded", @@ -2083,7 +2091,7 @@ dependencies = [ [[package]] name = "ruma-serde-macros" version = "0.4.0" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2094,7 +2102,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.7.2" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "base64 0.13.0", "ed25519-dalek", @@ -2112,7 +2120,7 @@ dependencies = [ [[package]] name = "ruma-state-res" version = "0.1.0" -source = "git+https://github.com/ruma/ruma?rev=b39537812c12caafcbf8b7bd744a06d196d45281#b39537812c12caafcbf8b7bd744a06d196d45281" +source = "git+https://github.com/ruma/ruma?rev=5a7e2cddcf257e367465cced51442c91e8f557c9#5a7e2cddcf257e367465cced51442c91e8f557c9" dependencies = [ "itertools 0.10.0", "js_int", @@ -2182,9 +2190,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.5" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61b3909d758bb75c79f23d4736fac9433868679d3ad2ea7a61e3c25cfda9a088" +checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd" [[package]] name = "ryu" @@ -2436,7 +2444,8 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spki" version = "0.3.0" -source = "git+https://github.com/RustCrypto/utils?rev=51e7c9d734e4d3c5279ba1c181c65b1bd77bcad0#51e7c9d734e4d3c5279ba1c181c65b1bd77bcad0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dae7e047abc519c96350e9484a96c6bf1492348af912fd3446dd2dc323f6268" dependencies = [ "der", ] @@ -2524,9 +2533,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" -version = "1.0.72" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +checksum = "b9505f307c872bab8eb46f77ae357c8eba1fdacead58ee5a850116b1d7f82883" dependencies = [ "proc-macro2", "quote", @@ -2554,7 +2563,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "rand 0.8.3", - "redox_syscall", + "redox_syscall 0.2.6", "remove_dir_all", "winapi", ] @@ -2570,18 +2579,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.25" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6" +checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.25" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d" +checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" dependencies = [ "proc-macro2", "quote", @@ -2684,9 +2693,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.6.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd3076b5c8cc18138b8f8814895c11eb4de37114a5d127bafdc5e55798ceef37" +checksum = "83f0c8e7c0addab50b663055baf787d0af7f413a46e6e7fb9559a4e4db7137a5" dependencies = [ "autocfg", "bytes", @@ -2703,9 +2712,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.2.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c49e3df43841dafb86046472506755d8501c5615673955f6aa17181125d13c37" +checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" dependencies = [ "proc-macro2", "quote", @@ -2725,9 +2734,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.6.7" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" +checksum = "940a12c99365c31ea8dd9ba04ec1be183ffe4920102bb7122c2f515437601e8e" dependencies = [ "bytes", "futures-core", @@ -2820,9 +2829,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.2.18" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa5553bf0883ba7c9cbe493b085c29926bd41b66afc31ff72cf17ff4fb60dcd5" +checksum = "705096c6f83bf68ea5d357a6aa01829ddbdac531b357b45abeca842938085baa" dependencies = [ "ansi_term", "chrono", @@ -2842,9 +2851,9 @@ dependencies = [ [[package]] name = "trust-dns-proto" -version = "0.20.3" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0d7f5db438199a6e2609debe3f69f808d074e0a2888ee0bccb45fe234d03f4" +checksum = "952a078337565ba39007de99b151770f41039253a31846f0a3d5cd5a4ac8eedf" dependencies = [ "async-trait", "cfg-if 1.0.0", @@ -2867,9 +2876,9 @@ dependencies = [ [[package]] name = "trust-dns-resolver" -version = "0.20.3" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ad17b608a64bd0735e67bde16b0636f8aa8591f831a25d18443ed00a699770" +checksum = "da9c97f7d103e0f94dbe384a57908833505ae5870126492f166821b7cf685589" dependencies = [ "cfg-if 1.0.0", "futures-util", @@ -2893,9 +2902,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "twoway" -version = "0.2.2" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c57ffb460d7c24cd6eda43694110189030a3d1dfe418416d9468fd1c1d290b47" +checksum = "6b40075910de3a912adbd80b5d8bad6ad10a23eeb1f5bf9d4006839e899ba5bc" dependencies = [ "memchr", "unchecked-index", @@ -2958,9 +2967,9 @@ checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" [[package]] name = "unicode-xid" -version = "0.2.2" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "unindent" @@ -2976,9 +2985,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" dependencies = [ "form_urlencoded", "idna", @@ -3016,9 +3025,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.74" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" +checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9" dependencies = [ "cfg-if 1.0.0", "serde", @@ -3028,9 +3037,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.74" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" +checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae" dependencies = [ "bumpalo", "lazy_static", @@ -3043,9 +3052,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.24" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fba7978c679d53ce2d0ac80c8c175840feb849a161664365d1287b41f2e67f1" +checksum = "81b8b767af23de6ac18bf2168b690bed2902743ddf0fb39252e36f9e2bfc63ea" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -3055,9 +3064,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.74" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" +checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3065,9 +3074,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.74" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" +checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c" dependencies = [ "proc-macro2", "quote", @@ -3078,15 +3087,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.74" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" +checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489" [[package]] name = "web-sys" -version = "0.3.51" +version = "0.3.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582" +checksum = "a905d57e488fec8861446d3393670fb50d27a262344013181c2cdf9fff5481be" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index e7ebadf2..96260ecc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ rust = "1.50" rocket = { git = "https://github.com/SergioBenitez/Rocket.git", rev = "801e04bd5369eb39e126c75f6d11e1e9597304d8", features = ["tls"] } # Used to handle requests # Used for matrix spec type definitions and helpers -ruma = { git = "https://github.com/ruma/ruma", rev = "b39537812c12caafcbf8b7bd744a06d196d45281", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } +ruma = { git = "https://github.com/ruma/ruma", rev = "5a7e2cddcf257e367465cced51442c91e8f557c9", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } #ruma = { path = "../ruma/crates/ruma", features = ["compat", "rand", "appservice-api-c", "client-api", "federation-api", "push-gateway-api-c", "state-res", "unstable-pre-spec", "unstable-exhaustive-types"] } # Used for long polling and federation sender, should be the same as rocket::tokio diff --git a/src/client_server/account.rs b/src/client_server/account.rs index 56de5fc9..f43f73ec 100644 --- a/src/client_server/account.rs +++ b/src/client_server/account.rs @@ -295,7 +295,7 @@ pub async fn register_route( state_default: 50.into(), users, users_default: 0.into(), - notifications: ruma::events::room::power_levels::NotificationPowerLevels { + notifications: ruma::power_levels::NotificationPowerLevels { room: 50.into(), }, }, diff --git a/src/client_server/room.rs b/src/client_server/room.rs index 7c507750..72b2d604 100644 --- a/src/client_server/room.rs +++ b/src/client_server/room.rs @@ -122,9 +122,7 @@ pub async fn create_room_route( state_default: 50.into(), users, users_default: 0.into(), - notifications: ruma::events::room::power_levels::NotificationPowerLevels { - room: 50.into(), - }, + notifications: ruma::power_levels::NotificationPowerLevels { room: 50.into() }, }) .expect("event is valid, we just created it"); diff --git a/src/client_server/to_device.rs b/src/client_server/to_device.rs index f2a97abd..ada0c9a1 100644 --- a/src/client_server/to_device.rs +++ b/src/client_server/to_device.rs @@ -2,9 +2,9 @@ use std::sync::Arc; use super::State; use crate::{ConduitResult, Database, Error, Ruma}; -use ruma::api::client::{ - error::ErrorKind, - r0::to_device::{self, send_event_to_device}, +use ruma::{ + api::client::{error::ErrorKind, r0::to_device::send_event_to_device}, + to_device::DeviceIdOrAllDevices, }; #[cfg(feature = "conduit_bin")] @@ -34,27 +34,25 @@ pub async fn send_event_to_device_route( for (target_user_id, map) in &body.messages { for (target_device_id_maybe, event) in map { match target_device_id_maybe { - to_device::DeviceIdOrAllDevices::DeviceId(target_device_id) => { - db.users.add_to_device_event( - sender_user, - &target_user_id, - &target_device_id, - &body.event_type, - serde_json::from_str(event.get()).map_err(|_| { - Error::BadRequest(ErrorKind::InvalidParam, "Event is invalid") - })?, - &db.globals, - )? - } + DeviceIdOrAllDevices::DeviceId(target_device_id) => db.users.add_to_device_event( + sender_user, + &target_user_id, + &target_device_id, + &body.event_type, + event.deserialize_as().map_err(|_| { + Error::BadRequest(ErrorKind::InvalidParam, "Event is invalid") + })?, + &db.globals, + )?, - to_device::DeviceIdOrAllDevices::AllDevices => { + DeviceIdOrAllDevices::AllDevices => { for target_device_id in db.users.all_device_ids(&target_user_id) { db.users.add_to_device_event( sender_user, &target_user_id, &target_device_id?, &body.event_type, - serde_json::from_str(event.get()).map_err(|_| { + event.deserialize_as().map_err(|_| { Error::BadRequest(ErrorKind::InvalidParam, "Event is invalid") })?, &db.globals, diff --git a/src/database/users.rs b/src/database/users.rs index b6d3b3c4..d89569a3 100644 --- a/src/database/users.rs +++ b/src/database/users.rs @@ -719,7 +719,7 @@ impl Users { sender: &UserId, target_user_id: &UserId, target_device_id: &DeviceId, - event_type: &EventType, + event_type: &str, content: serde_json::Value, globals: &super::globals::Globals, ) -> Result<()> { @@ -730,7 +730,7 @@ impl Users { key.extend_from_slice(&globals.next_count()?.to_be_bytes()); let mut json = serde_json::Map::new(); - json.insert("type".to_owned(), event_type.to_string().into()); + json.insert("type".to_owned(), event_type.to_owned().into()); json.insert("sender".to_owned(), sender.to_string().into()); json.insert("content".to_owned(), content); diff --git a/src/server_server.rs b/src/server_server.rs index 8384a9ed..f6d65949 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -9,10 +9,7 @@ use regex::Regex; use rocket::{response::content::Json, State}; use ruma::{ api::{ - client::{ - error::{Error as RumaError, ErrorKind}, - r0::to_device, - }, + client::error::{Error as RumaError, ErrorKind}, federation::{ authorization::get_event_authorization, device::get_devices::{self, v1::UserDevice}, @@ -49,6 +46,7 @@ use ruma::{ serde::Raw, signatures::{CanonicalJsonObject, CanonicalJsonValue}, state_res::{self, Event, EventMap, RoomVersion, StateMap}, + to_device::DeviceIdOrAllDevices, uint, EventId, MilliSecondsSinceUnixEpoch, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId, }; @@ -748,13 +746,13 @@ pub async fn send_transaction_message_route( for (target_user_id, map) in &messages { for (target_device_id_maybe, event) in map { match target_device_id_maybe { - to_device::DeviceIdOrAllDevices::DeviceId(target_device_id) => { + DeviceIdOrAllDevices::DeviceId(target_device_id) => { db.users.add_to_device_event( &sender, &target_user_id, &target_device_id, - &ev_type, - serde_json::from_str(event.get()).map_err(|_| { + &ev_type.to_string(), + event.deserialize_as().map_err(|_| { Error::BadRequest( ErrorKind::InvalidParam, "Event is invalid", @@ -764,14 +762,14 @@ pub async fn send_transaction_message_route( )? } - to_device::DeviceIdOrAllDevices::AllDevices => { + DeviceIdOrAllDevices::AllDevices => { for target_device_id in db.users.all_device_ids(&target_user_id) { db.users.add_to_device_event( &sender, &target_user_id, &target_device_id?, - &ev_type, - serde_json::from_str(event.get()).map_err(|_| { + &ev_type.to_string(), + event.deserialize_as().map_err(|_| { Error::BadRequest( ErrorKind::InvalidParam, "Event is invalid", From 7fa54e44113054818ad81030a988be08582c27d7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Jun 2021 20:14:37 +0200 Subject: [PATCH 2/6] Use Ruma-provided default power levels for shorter code --- src/client_server/account.rs | 12 +----------- src/client_server/room.rs | 10 +--------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/client_server/account.rs b/src/client_server/account.rs index f43f73ec..2fc8b192 100644 --- a/src/client_server/account.rs +++ b/src/client_server/account.rs @@ -286,18 +286,8 @@ pub async fn register_route( event_type: EventType::RoomPowerLevels, content: serde_json::to_value( ruma::events::room::power_levels::PowerLevelsEventContent { - ban: 50.into(), - events: BTreeMap::new(), - events_default: 0.into(), - invite: 50.into(), - kick: 50.into(), - redact: 50.into(), - state_default: 50.into(), users, - users_default: 0.into(), - notifications: ruma::power_levels::NotificationPowerLevels { - room: 50.into(), - }, + ..Default::default() }, ) .expect("event is valid, we just created it"), diff --git a/src/client_server/room.rs b/src/client_server/room.rs index 72b2d604..3f913249 100644 --- a/src/client_server/room.rs +++ b/src/client_server/room.rs @@ -113,16 +113,8 @@ pub async fn create_room_route( let mut power_levels_content = serde_json::to_value(ruma::events::room::power_levels::PowerLevelsEventContent { - ban: 50.into(), - events: BTreeMap::new(), - events_default: 0.into(), - invite: 50.into(), - kick: 50.into(), - redact: 50.into(), - state_default: 50.into(), users, - users_default: 0.into(), - notifications: ruma::power_levels::NotificationPowerLevels { room: 50.into() }, + ..Default::default() }) .expect("event is valid, we just created it"); From af2ce5803ebabb8b4b03ab24952878d997db05a1 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Jun 2021 20:29:02 +0200 Subject: [PATCH 3/6] Remove pointless double deserialization --- src/client_server/sync.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/client_server/sync.rs b/src/client_server/sync.rs index 2f28706a..dc92fb29 100644 --- a/src/client_server/sync.rs +++ b/src/client_server/sync.rs @@ -286,10 +286,8 @@ pub async fn sync_events_route( .filter(|(_, pdu)| pdu.kind == EventType::RoomMember) .map(|(_, pdu)| { let content = serde_json::from_value::< - Raw, + ruma::events::room::member::MemberEventContent, >(pdu.content.clone()) - .expect("Raw::from_value always works") - .deserialize() .map_err(|_| { Error::bad_database("Invalid member event in database.") })?; From f3e630c064c255bd8228de50363aa6a7fc720996 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Jun 2021 20:34:14 +0200 Subject: [PATCH 4/6] Fix lots of clippy lints --- src/client_server/alias.rs | 3 +- src/client_server/directory.rs | 4 +- src/client_server/membership.rs | 10 +- src/client_server/session.rs | 6 +- src/client_server/sync.rs | 15 ++- src/database/appservice.rs | 18 ++-- src/database/globals.rs | 8 +- src/database/key_backups.rs | 5 +- src/database/media.rs | 12 +-- src/database/pusher.rs | 8 +- src/database/rooms.rs | 168 +++++++++++++------------------- src/database/rooms/edus.rs | 10 +- src/database/transaction_ids.rs | 2 +- src/database/uiaa.rs | 4 +- src/database/users.rs | 31 +++--- src/server_server.rs | 13 +-- src/utils.rs | 25 +++-- 17 files changed, 140 insertions(+), 202 deletions(-) diff --git a/src/client_server/alias.rs b/src/client_server/alias.rs index 40252af2..a2ca0c82 100644 --- a/src/client_server/alias.rs +++ b/src/client_server/alias.rs @@ -97,13 +97,12 @@ pub async fn get_alias_helper( .map_or_else(Vec::new, |aliases| { aliases .iter() - .map(|aliases| { + .filter_map(|aliases| { aliases .get("regex") .and_then(|regex| regex.as_str()) .and_then(|regex| Regex::new(regex).ok()) }) - .filter_map(|o| o) .collect::>() }); diff --git a/src/client_server/directory.rs b/src/client_server/directory.rs index c41e81e4..dfef34d4 100644 --- a/src/client_server/directory.rs +++ b/src/client_server/directory.rs @@ -135,9 +135,7 @@ pub async fn get_public_rooms_filtered_helper( filter: &IncomingFilter, _network: &IncomingRoomNetwork, ) -> ConduitResult { - if let Some(other_server) = server - .clone() - .filter(|server| *server != db.globals.server_name().as_str()) + if let Some(other_server) = server.filter(|server| *server != db.globals.server_name().as_str()) { let response = db .sending diff --git a/src/client_server/membership.rs b/src/client_server/membership.rs index a3f1389a..2dfa0776 100644 --- a/src/client_server/membership.rs +++ b/src/client_server/membership.rs @@ -743,12 +743,10 @@ pub async fn invite_helper( let create_event_content = create_event .as_ref() .map(|create_event| { - Ok::<_, Error>( - serde_json::from_value::>(create_event.content.clone()) - .expect("Raw::from_value always works.") - .deserialize() - .map_err(|_| Error::bad_database("Invalid PowerLevels event in db."))?, - ) + serde_json::from_value::>(create_event.content.clone()) + .expect("Raw::from_value always works.") + .deserialize() + .map_err(|_| Error::bad_database("Invalid PowerLevels event in db.")) }) .transpose()?; diff --git a/src/client_server/session.rs b/src/client_server/session.rs index 9a75ae28..dd504f18 100644 --- a/src/client_server/session.rs +++ b/src/client_server/session.rs @@ -202,10 +202,8 @@ pub async fn logout_all_route( ) -> ConduitResult { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - for device_id in db.users.all_device_ids(sender_user) { - if let Ok(device_id) = device_id { - db.users.remove_device(&sender_user, &device_id)?; - } + for device_id in db.users.all_device_ids(sender_user).flatten() { + db.users.remove_device(&sender_user, &device_id)?; } db.flush().await?; diff --git a/src/client_server/sync.rs b/src/client_server/sync.rs index dc92fb29..1c078e91 100644 --- a/src/client_server/sync.rs +++ b/src/client_server/sync.rs @@ -146,11 +146,9 @@ pub async fn sync_events_route( let since_state = since_shortstatehash .as_ref() .map(|since_shortstatehash| { - Ok::<_, Error>( - since_shortstatehash - .map(|since_shortstatehash| db.rooms.state_full(since_shortstatehash)) - .transpose()?, - ) + since_shortstatehash + .map(|since_shortstatehash| db.rooms.state_full(since_shortstatehash)) + .transpose() }) .transpose()?; @@ -255,7 +253,7 @@ pub async fn sync_events_route( device_list_updates.extend( db.rooms .room_members(&room_id) - .filter_map(|user_id| Some(user_id.ok()?)) + .flatten() .filter(|user_id| { // Don't send key updates from the sender to the sender sender_user != user_id @@ -313,9 +311,10 @@ pub async fn sync_events_route( Ok(None) } }) - .filter_map(|u| u.ok()) // Filter out buggy users + // Filter out buggy users + .filter_map(|u| u.ok()) // Filter for possible heroes - .filter_map(|u| u) + .flatten() { if heroes.contains(&hero) || hero == sender_user.as_str() { continue; diff --git a/src/database/appservice.rs b/src/database/appservice.rs index 21b18a76..4bf3a218 100644 --- a/src/database/appservice.rs +++ b/src/database/appservice.rs @@ -34,29 +34,25 @@ impl Appservice { .get(id) .map_or_else( || { - Ok(self - .id_appserviceregistrations + self.id_appserviceregistrations .get(id.as_bytes())? .map(|bytes| { - Ok::<_, Error>(serde_yaml::from_slice(&bytes).map_err(|_| { + serde_yaml::from_slice(&bytes).map_err(|_| { Error::bad_database( "Invalid registration bytes in id_appserviceregistrations.", ) - })?) + }) }) - .transpose()?) + .transpose() }, |r| Ok(Some(r.clone())), ) } - pub fn iter_ids<'a>( - &'a self, - ) -> Result> + Send + Sync + 'a> { + pub fn iter_ids(&self) -> Result> + Send + Sync + '_> { Ok(self.id_appserviceregistrations.iter().map(|(id, _)| { - Ok(utils::string_from_bytes(&id).map_err(|_| { - Error::bad_database("Invalid id bytes in id_appserviceregistrations.") - })?) + utils::string_from_bytes(&id) + .map_err(|_| Error::bad_database("Invalid id bytes in id_appserviceregistrations.")) })) } diff --git a/src/database/globals.rs b/src/database/globals.rs index 55256443..1ce87bd2 100644 --- a/src/database/globals.rs +++ b/src/database/globals.rs @@ -171,14 +171,14 @@ impl Globals { } pub fn next_count(&self) -> Result { - Ok(utils::u64_from_bytes(&self.globals.increment(COUNTER)?) - .map_err(|_| Error::bad_database("Count has invalid bytes."))?) + utils::u64_from_bytes(&self.globals.increment(COUNTER)?) + .map_err(|_| Error::bad_database("Count has invalid bytes.")) } pub fn current_count(&self) -> Result { self.globals.get(COUNTER)?.map_or(Ok(0_u64), |bytes| { - Ok(utils::u64_from_bytes(&bytes) - .map_err(|_| Error::bad_database("Count has invalid bytes."))?) + utils::u64_from_bytes(&bytes) + .map_err(|_| Error::bad_database("Count has invalid bytes.")) }) } diff --git a/src/database/key_backups.rs b/src/database/key_backups.rs index 0685c482..2bb3b6d5 100644 --- a/src/database/key_backups.rs +++ b/src/database/key_backups.rs @@ -119,9 +119,8 @@ impl KeyBackups { self.backupid_algorithm .get(&key)? .map_or(Ok(None), |bytes| { - Ok(serde_json::from_slice(&bytes).map_err(|_| { - Error::bad_database("Algorithm in backupid_algorithm is invalid.") - })?) + serde_json::from_slice(&bytes) + .map_err(|_| Error::bad_database("Algorithm in backupid_algorithm is invalid.")) }) } diff --git a/src/database/media.rs b/src/database/media.rs index 944c5bdc..a1fe26e1 100644 --- a/src/database/media.rs +++ b/src/database/media.rs @@ -110,9 +110,9 @@ impl Media { let content_type = parts .next() .map(|bytes| { - Ok::<_, Error>(utils::string_from_bytes(bytes).map_err(|_| { + utils::string_from_bytes(bytes).map_err(|_| { Error::bad_database("Content type in mediaid_file is invalid unicode.") - })?) + }) }) .transpose()?; @@ -199,9 +199,9 @@ impl Media { let content_type = parts .next() .map(|bytes| { - Ok::<_, Error>(utils::string_from_bytes(bytes).map_err(|_| { + utils::string_from_bytes(bytes).map_err(|_| { Error::bad_database("Content type in mediaid_file is invalid unicode.") - })?) + }) }) .transpose()?; @@ -235,9 +235,9 @@ impl Media { let content_type = parts .next() .map(|bytes| { - Ok::<_, Error>(utils::string_from_bytes(bytes).map_err(|_| { + utils::string_from_bytes(bytes).map_err(|_| { Error::bad_database("Content type in mediaid_file is invalid unicode.") - })?) + }) }) .transpose()?; diff --git a/src/database/pusher.rs b/src/database/pusher.rs index 39b631dc..358c3c98 100644 --- a/src/database/pusher.rs +++ b/src/database/pusher.rs @@ -51,8 +51,8 @@ impl PushData { self.senderkey_pusher .get(senderkey)? .map(|push| { - Ok(serde_json::from_slice(&*push) - .map_err(|_| Error::bad_database("Invalid Pusher in db."))?) + serde_json::from_slice(&*push) + .map_err(|_| Error::bad_database("Invalid Pusher in db.")) }) .transpose() } @@ -64,8 +64,8 @@ impl PushData { self.senderkey_pusher .scan_prefix(prefix) .map(|(_, push)| { - Ok(serde_json::from_slice(&*push) - .map_err(|_| Error::bad_database("Invalid Pusher in db."))?) + serde_json::from_slice(&*push) + .map_err(|_| Error::bad_database("Invalid Pusher in db.")) }) .collect() } diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 0820395e..9e1245f2 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -93,14 +93,10 @@ impl Rooms { .map(|(_, bytes)| self.shorteventid_eventid.get(&bytes).ok().flatten()) .flatten() .map(|bytes| { - Ok::<_, Error>( - EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { - Error::bad_database("EventID in stateid_shorteventid is invalid unicode.") - })?) - .map_err(|_| { - Error::bad_database("EventId in stateid_shorteventid is invalid.") - })?, - ) + EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { + Error::bad_database("EventID in stateid_shorteventid is invalid unicode.") + })?) + .map_err(|_| Error::bad_database("EventId in stateid_shorteventid is invalid.")) }) .filter_map(|r| r.ok()) .collect()) @@ -116,14 +112,10 @@ impl Rooms { .map(|(_, bytes)| self.shorteventid_eventid.get(&bytes).ok().flatten()) .flatten() .map(|bytes| { - Ok::<_, Error>( - EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { - Error::bad_database("EventID in stateid_shorteventid is invalid unicode.") - })?) - .map_err(|_| { - Error::bad_database("EventId in stateid_shorteventid is invalid.") - })?, - ) + EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { + Error::bad_database("EventID in stateid_shorteventid is invalid unicode.") + })?) + .map_err(|_| Error::bad_database("EventId in stateid_shorteventid is invalid.")) }) .filter_map(|r| r.ok()) .map(|eventid| self.get_pdu(&eventid)) @@ -168,16 +160,10 @@ impl Rooms { .map(|bytes| self.shorteventid_eventid.get(&bytes).ok().flatten()) .flatten() .map(|bytes| { - Ok::<_, Error>( - EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { - Error::bad_database( - "EventID in stateid_shorteventid is invalid unicode.", - ) - })?) - .map_err(|_| { - Error::bad_database("EventId in stateid_shorteventid is invalid.") - })?, - ) + EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { + Error::bad_database("EventID in stateid_shorteventid is invalid unicode.") + })?) + .map_err(|_| Error::bad_database("EventId in stateid_shorteventid is invalid.")) }) .map(|r| r.ok()) .flatten()) @@ -204,16 +190,16 @@ impl Rooms { self.eventid_shorteventid .get(event_id.as_bytes())? .map_or(Ok(None), |shorteventid| { - Ok(self - .shorteventid_shortstatehash - .get(&shorteventid)? - .map_or(Ok::<_, Error>(None), |bytes| { + self.shorteventid_shortstatehash.get(&shorteventid)?.map_or( + Ok::<_, Error>(None), + |bytes| { Ok(Some(utils::u64_from_bytes(&bytes).map_err(|_| { Error::bad_database( "Invalid shortstatehash bytes in shorteventid_shortstatehash", ) })?)) - })?) + }, + ) }) } @@ -485,7 +471,7 @@ impl Rooms { self.eventid_pduid .get(event_id.as_bytes())? .map_or_else::, _, _>( - || Ok(self.eventid_outlierpdu.get(event_id.as_bytes())?), + || self.eventid_outlierpdu.get(event_id.as_bytes()), |pduid| { Ok(Some(self.pduid_pdu.get(&pduid)?.ok_or_else(|| { Error::bad_database("Invalid pduid in eventid_pduid.") @@ -493,8 +479,7 @@ impl Rooms { }, )? .map(|pdu| { - Ok(serde_json::from_slice(&pdu) - .map_err(|_| Error::bad_database("Invalid PDU in db."))?) + serde_json::from_slice(&pdu).map_err(|_| Error::bad_database("Invalid PDU in db.")) }) .transpose() } @@ -521,8 +506,7 @@ impl Rooms { }, )? .map(|pdu| { - Ok(serde_json::from_slice(&pdu) - .map_err(|_| Error::bad_database("Invalid PDU in db."))?) + serde_json::from_slice(&pdu).map_err(|_| Error::bad_database("Invalid PDU in db.")) }) .transpose() } @@ -534,7 +518,7 @@ impl Rooms { self.eventid_pduid .get(event_id.as_bytes())? .map_or_else::, _, _>( - || Ok(self.eventid_outlierpdu.get(event_id.as_bytes())?), + || self.eventid_outlierpdu.get(event_id.as_bytes()), |pduid| { Ok(Some(self.pduid_pdu.get(&pduid)?.ok_or_else(|| { Error::bad_database("Invalid pduid in eventid_pduid.") @@ -542,8 +526,7 @@ impl Rooms { }, )? .map(|pdu| { - Ok(serde_json::from_slice(&pdu) - .map_err(|_| Error::bad_database("Invalid PDU in db."))?) + serde_json::from_slice(&pdu).map_err(|_| Error::bad_database("Invalid PDU in db.")) }) .transpose() } @@ -594,12 +577,10 @@ impl Rooms { self.roomid_pduleaves .scan_prefix(prefix) .map(|(_, bytes)| { - Ok::<_, Error>( - EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { - Error::bad_database("EventID in roomid_pduleaves is invalid unicode.") - })?) - .map_err(|_| Error::bad_database("EventId in roomid_pduleaves is invalid."))?, - ) + EventId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { + Error::bad_database("EventID in roomid_pduleaves is invalid unicode.") + })?) + .map_err(|_| Error::bad_database("EventId in roomid_pduleaves is invalid.")) }) .collect() } @@ -1213,12 +1194,10 @@ impl Rooms { let create_event_content = create_event .as_ref() .map(|create_event| { - Ok::<_, Error>( - serde_json::from_value::>(create_event.content.clone()) - .expect("Raw::from_value always works.") - .deserialize() - .map_err(|_| Error::bad_database("Invalid PowerLevels event in db."))?, - ) + serde_json::from_value::>(create_event.content.clone()) + .expect("Raw::from_value always works.") + .deserialize() + .map_err(|_| Error::bad_database("Invalid PowerLevels event in db.")) }) .transpose()?; @@ -1382,13 +1361,12 @@ impl Rooms { .map_or_else(Vec::new, |users| { users .iter() - .map(|users| { + .filter_map(|users| { users .get("regex") .and_then(|regex| regex.as_str()) .and_then(|regex| Regex::new(regex).ok()) }) - .filter_map(|o| o) .collect::>() }); let aliases = namespaces @@ -1397,13 +1375,12 @@ impl Rooms { .map_or_else(Vec::new, |aliases| { aliases .iter() - .map(|aliases| { + .filter_map(|aliases| { aliases .get("regex") .and_then(|regex| regex.as_str()) .and_then(|regex| Regex::new(regex).ok()) }) - .filter_map(|o| o) .collect::>() }); let rooms = namespaces @@ -2011,10 +1988,10 @@ impl Rooms { prefix.push(0xff); self.aliasid_alias.scan_prefix(prefix).map(|(_, bytes)| { - Ok(utils::string_from_bytes(&bytes) + utils::string_from_bytes(&bytes) .map_err(|_| Error::bad_database("Invalid alias bytes in aliasid_alias."))? .try_into() - .map_err(|_| Error::bad_database("Invalid alias in aliasid_alias."))?) + .map_err(|_| Error::bad_database("Invalid alias in aliasid_alias.")) }) } @@ -2032,14 +2009,14 @@ impl Rooms { Ok(self.publicroomids.get(room_id.as_bytes())?.is_some()) } - pub fn public_rooms<'a>(&'a self) -> impl Iterator> + 'a { + pub fn public_rooms(&self) -> impl Iterator> + '_ { self.publicroomids.iter().map(|(bytes, _)| { - Ok( - RoomId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { + RoomId::try_from( + utils::string_from_bytes(&bytes).map_err(|_| { Error::bad_database("Room ID in publicroomids is invalid unicode.") - })?) - .map_err(|_| Error::bad_database("Room ID in publicroomids is invalid."))?, + })?, ) + .map_err(|_| Error::bad_database("Room ID in publicroomids is invalid.")) }) } @@ -2105,34 +2082,27 @@ impl Rooms { &'a self, users: Vec, ) -> Result> + 'a> { - let iterators = users - .into_iter() - .map(move |user_id| { - let mut prefix = user_id.as_bytes().to_vec(); - prefix.push(0xff); + let iterators = users.into_iter().map(move |user_id| { + let mut prefix = user_id.as_bytes().to_vec(); + prefix.push(0xff); - Ok::<_, Error>( - self.userroomid_joined - .scan_prefix(prefix) - .map(|(key, _)| { - let roomid_index = key - .iter() - .enumerate() - .find(|(_, &b)| b == 0xff) - .ok_or_else(|| { - Error::bad_database("Invalid userroomid_joined in db.") - })? - .0 - + 1; // +1 because the room id starts AFTER the separator + self.userroomid_joined + .scan_prefix(prefix) + .map(|(key, _)| { + let roomid_index = key + .iter() + .enumerate() + .find(|(_, &b)| b == 0xff) + .ok_or_else(|| Error::bad_database("Invalid userroomid_joined in db."))? + .0 + + 1; // +1 because the room id starts AFTER the separator - let room_id = key[roomid_index..].to_vec(); + let room_id = key[roomid_index..].to_vec(); - Ok::<_, Error>(room_id) - }) - .filter_map(|r| r.ok()), - ) - }) - .filter_map(|r| r.ok()); + Ok::<_, Error>(room_id) + }) + .filter_map(|r| r.ok()) + }); // We use the default compare function because keys are sorted correctly (not reversed) Ok(utils::common_elements(iterators, Ord::cmp) @@ -2154,7 +2124,7 @@ impl Rooms { prefix.push(0xff); self.roomserverids.scan_prefix(prefix).map(|(key, _)| { - Ok(Box::::try_from( + Box::::try_from( utils::string_from_bytes( &key.rsplit(|&b| b == 0xff) .next() @@ -2164,7 +2134,7 @@ impl Rooms { Error::bad_database("Server name in roomserverids is invalid unicode.") })?, ) - .map_err(|_| Error::bad_database("Server name in roomserverids is invalid."))?) + .map_err(|_| Error::bad_database("Server name in roomserverids is invalid.")) }) } @@ -2177,7 +2147,7 @@ impl Rooms { prefix.push(0xff); self.serverroomids.scan_prefix(prefix).map(|(key, _)| { - Ok(RoomId::try_from( + RoomId::try_from( utils::string_from_bytes( &key.rsplit(|&b| b == 0xff) .next() @@ -2185,7 +2155,7 @@ impl Rooms { ) .map_err(|_| Error::bad_database("RoomId in serverroomids is invalid unicode."))?, ) - .map_err(|_| Error::bad_database("RoomId in serverroomids is invalid."))?) + .map_err(|_| Error::bad_database("RoomId in serverroomids is invalid.")) }) } @@ -2199,7 +2169,7 @@ impl Rooms { prefix.push(0xff); self.roomuserid_joined.scan_prefix(prefix).map(|(key, _)| { - Ok(UserId::try_from( + UserId::try_from( utils::string_from_bytes( &key.rsplit(|&b| b == 0xff) .next() @@ -2209,7 +2179,7 @@ impl Rooms { Error::bad_database("User ID in roomuserid_joined is invalid unicode.") })?, ) - .map_err(|_| Error::bad_database("User ID in roomuserid_joined is invalid."))?) + .map_err(|_| Error::bad_database("User ID in roomuserid_joined is invalid.")) }) } @@ -2224,7 +2194,7 @@ impl Rooms { self.roomuseroncejoinedids .scan_prefix(prefix) .map(|(key, _)| { - Ok(UserId::try_from( + UserId::try_from( utils::string_from_bytes( &key.rsplit(|&b| b == 0xff) .next() @@ -2234,7 +2204,7 @@ impl Rooms { Error::bad_database("User ID in room_useroncejoined is invalid unicode.") })?, ) - .map_err(|_| Error::bad_database("User ID in room_useroncejoined is invalid."))?) + .map_err(|_| Error::bad_database("User ID in room_useroncejoined is invalid.")) }) } @@ -2250,7 +2220,7 @@ impl Rooms { self.roomuserid_invitecount .scan_prefix(prefix) .map(|(key, _)| { - Ok(UserId::try_from( + UserId::try_from( utils::string_from_bytes( &key.rsplit(|&b| b == 0xff) .next() @@ -2260,7 +2230,7 @@ impl Rooms { Error::bad_database("User ID in roomuserid_invited is invalid unicode.") })?, ) - .map_err(|_| Error::bad_database("User ID in roomuserid_invited is invalid."))?) + .map_err(|_| Error::bad_database("User ID in roomuserid_invited is invalid.")) }) } @@ -2303,7 +2273,7 @@ impl Rooms { self.userroomid_joined .scan_prefix(user_id.as_bytes().to_vec()) .map(|(key, _)| { - Ok(RoomId::try_from( + RoomId::try_from( utils::string_from_bytes( &key.rsplit(|&b| b == 0xff) .next() @@ -2313,7 +2283,7 @@ impl Rooms { Error::bad_database("Room ID in userroomid_joined is invalid unicode.") })?, ) - .map_err(|_| Error::bad_database("Room ID in userroomid_joined is invalid."))?) + .map_err(|_| Error::bad_database("Room ID in userroomid_joined is invalid.")) }) } diff --git a/src/database/rooms/edus.rs b/src/database/rooms/edus.rs index 677d26eb..9a5cdeb2 100644 --- a/src/database/rooms/edus.rs +++ b/src/database/rooms/edus.rs @@ -306,12 +306,10 @@ impl RoomEdus { .typingid_userid .scan_prefix(prefix) .map(|(_, user_id)| { - Ok::<_, Error>( - UserId::try_from(utils::string_from_bytes(&user_id).map_err(|_| { - Error::bad_database("User ID in typingid_userid is invalid unicode.") - })?) - .map_err(|_| Error::bad_database("User ID in typingid_userid is invalid."))?, - ) + UserId::try_from(utils::string_from_bytes(&user_id).map_err(|_| { + Error::bad_database("User ID in typingid_userid is invalid unicode.") + })?) + .map_err(|_| Error::bad_database("User ID in typingid_userid is invalid.")) }) { user_ids.insert(user_id?); diff --git a/src/database/transaction_ids.rs b/src/database/transaction_ids.rs index 3e377798..f3467572 100644 --- a/src/database/transaction_ids.rs +++ b/src/database/transaction_ids.rs @@ -41,6 +41,6 @@ impl TransactionIds { key.extend_from_slice(txn_id.as_bytes()); // If there's no entry, this is a new transaction - Ok(self.userdevicetxnid_response.get(&key)?) + self.userdevicetxnid_response.get(&key) } } diff --git a/src/database/uiaa.rs b/src/database/uiaa.rs index f7f3d1f8..1372fef5 100644 --- a/src/database/uiaa.rs +++ b/src/database/uiaa.rs @@ -57,9 +57,7 @@ impl Uiaa { { let mut uiaainfo = session .as_ref() - .map(|session| { - Ok::<_, Error>(self.get_uiaa_session(&user_id, &device_id, session)?) - }) + .map(|session| self.get_uiaa_session(&user_id, &device_id, session)) .unwrap_or_else(|| Ok(uiaainfo.clone()))?; if uiaainfo.session.is_none() { diff --git a/src/database/users.rs b/src/database/users.rs index d89569a3..f99084fa 100644 --- a/src/database/users.rs +++ b/src/database/users.rs @@ -88,14 +88,12 @@ impl Users { } /// Returns an iterator over all users on this homeserver. - pub fn iter<'a>(&'a self) -> impl Iterator> + 'a { + pub fn iter(&self) -> impl Iterator> + '_ { self.userid_password.iter().map(|(bytes, _)| { - Ok( - UserId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { - Error::bad_database("User ID in userid_password is invalid unicode.") - })?) - .map_err(|_| Error::bad_database("User ID in userid_password is invalid."))?, - ) + UserId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { + Error::bad_database("User ID in userid_password is invalid unicode.") + })?) + .map_err(|_| Error::bad_database("User ID in userid_password is invalid.")) }) } @@ -588,16 +586,10 @@ impl Users { .iter_from(&start, false) .take_while(move |(k, _)| k.starts_with(&prefix)) .map(|(_, bytes)| { - Ok( - UserId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { - Error::bad_database( - "User ID in devicekeychangeid_userid is invalid unicode.", - ) - })?) - .map_err(|_| { - Error::bad_database("User ID in devicekeychangeid_userid is invalid.") - })?, - ) + UserId::try_from(utils::string_from_bytes(&bytes).map_err(|_| { + Error::bad_database("User ID in devicekeychangeid_userid is invalid unicode.") + })?) + .map_err(|_| Error::bad_database("User ID in devicekeychangeid_userid is invalid.")) }) } @@ -863,9 +855,8 @@ impl Users { self.userdeviceid_metadata .scan_prefix(key) .map(|(_, bytes)| { - Ok(serde_json::from_slice::(&bytes).map_err(|_| { - Error::bad_database("Device in userdeviceid_metadata is invalid.") - })?) + serde_json::from_slice::(&bytes) + .map_err(|_| Error::bad_database("Device in userdeviceid_metadata is invalid.")) }) } diff --git a/src/server_server.rs b/src/server_server.rs index f6d65949..f34633ac 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -1691,13 +1691,12 @@ pub(crate) fn append_incoming_pdu( .map_or_else(Vec::new, |users| { users .iter() - .map(|users| { + .filter_map(|users| { users .get("regex") .and_then(|regex| regex.as_str()) .and_then(|regex| Regex::new(regex).ok()) }) - .filter_map(|o| o) .collect::>() }); let aliases = namespaces @@ -2026,12 +2025,10 @@ pub fn create_join_event_template_route( let create_event_content = create_event .as_ref() .map(|create_event| { - Ok::<_, Error>( - serde_json::from_value::>(create_event.content.clone()) - .expect("Raw::from_value always works.") - .deserialize() - .map_err(|_| Error::bad_database("Invalid PowerLevels event in db."))?, - ) + serde_json::from_value::>(create_event.content.clone()) + .expect("Raw::from_value always works.") + .deserialize() + .map_err(|_| Error::bad_database("Invalid PowerLevels event in db.")) }) .transpose()?; diff --git a/src/utils.rs b/src/utils.rs index 0c8fb5ca..2b5336c2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -84,22 +84,19 @@ pub fn common_elements( let mut other_iterators = iterators.map(|i| i.peekable()).collect::>(); Some(first_iterator.filter(move |target| { - other_iterators - .iter_mut() - .map(|it| { - while let Some(element) = it.peek() { - match check_order(element, target) { - Ordering::Greater => return false, // We went too far - Ordering::Equal => return true, // Element is in both iters - Ordering::Less => { - // Keep searching - it.next(); - } + other_iterators.iter_mut().all(|it| { + while let Some(element) = it.peek() { + match check_order(element, target) { + Ordering::Greater => return false, // We went too far + Ordering::Equal => return true, // Element is in both iters + Ordering::Less => { + // Keep searching + it.next(); } } - false - }) - .all(|b| b) + } + false + }) })) } From b291e765729c5e367841de855578e38cdec43f21 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Jun 2021 20:37:07 +0200 Subject: [PATCH 5/6] Use try operator for Option more --- src/client_server/alias.rs | 7 +------ src/database/rooms.rs | 14 ++------------ src/server_server.rs | 7 +------ 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/src/client_server/alias.rs b/src/client_server/alias.rs index a2ca0c82..a54bd36d 100644 --- a/src/client_server/alias.rs +++ b/src/client_server/alias.rs @@ -97,12 +97,7 @@ pub async fn get_alias_helper( .map_or_else(Vec::new, |aliases| { aliases .iter() - .filter_map(|aliases| { - aliases - .get("regex") - .and_then(|regex| regex.as_str()) - .and_then(|regex| Regex::new(regex).ok()) - }) + .filter_map(|aliases| Regex::new(aliases.get("regex")?.as_str()?).ok()) .collect::>() }); diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 9e1245f2..7bb019e5 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -1361,12 +1361,7 @@ impl Rooms { .map_or_else(Vec::new, |users| { users .iter() - .filter_map(|users| { - users - .get("regex") - .and_then(|regex| regex.as_str()) - .and_then(|regex| Regex::new(regex).ok()) - }) + .filter_map(|users| Regex::new(users.get("regex")?.as_str()?).ok()) .collect::>() }); let aliases = namespaces @@ -1375,12 +1370,7 @@ impl Rooms { .map_or_else(Vec::new, |aliases| { aliases .iter() - .filter_map(|aliases| { - aliases - .get("regex") - .and_then(|regex| regex.as_str()) - .and_then(|regex| Regex::new(regex).ok()) - }) + .filter_map(|aliases| Regex::new(aliases.get("regex")?.as_str()?).ok()) .collect::>() }); let rooms = namespaces diff --git a/src/server_server.rs b/src/server_server.rs index f34633ac..6d074ec6 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -1691,12 +1691,7 @@ pub(crate) fn append_incoming_pdu( .map_or_else(Vec::new, |users| { users .iter() - .filter_map(|users| { - users - .get("regex") - .and_then(|regex| regex.as_str()) - .and_then(|regex| Regex::new(regex).ok()) - }) + .filter_map(|users| Regex::new(users.get("regex")?.as_str()?).ok()) .collect::>() }); let aliases = namespaces From 808741bcb685820fb7aa237f7f803a2e5c92ca49 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Jun 2021 20:44:29 +0200 Subject: [PATCH 6/6] Remove unnecessary Option-wrapping and successive unwrapping --- src/client_server/directory.rs | 11 +++---- src/database/rooms.rs | 52 +++++++++++++++------------------- src/server_server.rs | 20 ++++--------- 3 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/client_server/directory.rs b/src/client_server/directory.rs index dfef34d4..be5501ab 100644 --- a/src/client_server/directory.rs +++ b/src/client_server/directory.rs @@ -160,15 +160,12 @@ pub async fn get_public_rooms_filtered_helper( .map(|c| { // Convert ruma::api::federation::directory::get_public_rooms::v1::PublicRoomsChunk // to ruma::api::client::r0::directory::PublicRoomsChunk - Ok::<_, Error>( - serde_json::from_str( - &serde_json::to_string(&c) - .expect("PublicRoomsChunk::to_string always works"), - ) - .expect("federation and client-server PublicRoomsChunk are the same type"), + serde_json::from_str( + &serde_json::to_string(&c) + .expect("PublicRoomsChunk::to_string always works"), ) + .expect("federation and client-server PublicRoomsChunk are the same type") }) - .filter_map(|r| r.ok()) .collect(), prev_batch: response.prev_batch, next_batch: response.next_batch, diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 7bb019e5..f19d4b99 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -2023,39 +2023,33 @@ impl Rooms { .map(str::to_lowercase) .collect::>(); - let iterators = words - .clone() - .into_iter() - .map(move |word| { - let mut prefix2 = prefix.clone(); - prefix2.extend_from_slice(word.as_bytes()); - prefix2.push(0xff); + let iterators = words.clone().into_iter().map(move |word| { + let mut prefix2 = prefix.clone(); + prefix2.extend_from_slice(word.as_bytes()); + prefix2.push(0xff); - let mut last_possible_id = prefix2.clone(); - last_possible_id.extend_from_slice(&u64::MAX.to_be_bytes()); + let mut last_possible_id = prefix2.clone(); + last_possible_id.extend_from_slice(&u64::MAX.to_be_bytes()); - Ok::<_, Error>( - self.tokenids - .iter_from(&last_possible_id, true) // Newest pdus first - .take_while(move |(k, _)| k.starts_with(&prefix2)) - .map(|(key, _)| { - let pduid_index = key - .iter() - .enumerate() - .filter(|(_, &b)| b == 0xff) - .nth(1) - .ok_or_else(|| Error::bad_database("Invalid tokenid in db."))? - .0 - + 1; // +1 because the pdu id starts AFTER the separator + self.tokenids + .iter_from(&last_possible_id, true) // Newest pdus first + .take_while(move |(k, _)| k.starts_with(&prefix2)) + .map(|(key, _)| { + let pduid_index = key + .iter() + .enumerate() + .filter(|(_, &b)| b == 0xff) + .nth(1) + .ok_or_else(|| Error::bad_database("Invalid tokenid in db."))? + .0 + + 1; // +1 because the pdu id starts AFTER the separator - let pdu_id = key[pduid_index..].to_vec(); + let pdu_id = key[pduid_index..].to_vec(); - Ok::<_, Error>(pdu_id) - }) - .filter_map(|r| r.ok()), - ) - }) - .filter_map(|r| r.ok()); + Ok::<_, Error>(pdu_id) + }) + .filter_map(|r| r.ok()) + }); Ok(( utils::common_elements(iterators, |a, b| { diff --git a/src/server_server.rs b/src/server_server.rs index 6d074ec6..961cc9d8 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -532,15 +532,11 @@ pub async fn get_public_rooms_filtered_route( .map(|c| { // Convert ruma::api::federation::directory::get_public_rooms::v1::PublicRoomsChunk // to ruma::api::client::r0::directory::PublicRoomsChunk - Ok::<_, Error>( - serde_json::from_str( - &serde_json::to_string(&c) - .expect("PublicRoomsChunk::to_string always works"), - ) - .expect("federation and client-server PublicRoomsChunk are the same type"), + serde_json::from_str( + &serde_json::to_string(&c).expect("PublicRoomsChunk::to_string always works"), ) + .expect("federation and client-server PublicRoomsChunk are the same type") }) - .filter_map(|r| r.ok()) .collect(), prev_batch: response.prev_batch, next_batch: response.next_batch, @@ -580,15 +576,11 @@ pub async fn get_public_rooms_route( .map(|c| { // Convert ruma::api::federation::directory::get_public_rooms::v1::PublicRoomsChunk // to ruma::api::client::r0::directory::PublicRoomsChunk - Ok::<_, Error>( - serde_json::from_str( - &serde_json::to_string(&c) - .expect("PublicRoomsChunk::to_string always works"), - ) - .expect("federation and client-server PublicRoomsChunk are the same type"), + serde_json::from_str( + &serde_json::to_string(&c).expect("PublicRoomsChunk::to_string always works"), ) + .expect("federation and client-server PublicRoomsChunk are the same type") }) - .filter_map(|r| r.ok()) .collect(), prev_batch: response.prev_batch, next_batch: response.next_batch,