From 808d45b893517e6b65afb21dd3842ab0f7748c7d Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Tue, 23 Nov 2021 22:24:09 +0000 Subject: [PATCH] Update to Matrix SDK from git (breaking, probably 0.5 prerelease) --- Cargo.lock | 192 ++++++++++++++++++++++----------------------------- Cargo.toml | 4 +- src/main.rs | 15 ++-- src/monzo.rs | 9 ++- src/web.rs | 5 +- 5 files changed, 100 insertions(+), 125 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c9b0d47..06bd7a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,12 +67,48 @@ version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee10e43ae4a853c0a3591d4e2ada1719e553be18199d9da9d4a83f5927c2f5c7" +[[package]] +name = "anymap2" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d301b3b94cb4b2f23d7917810addbbaff90738e0ca2be692bd027e70d7e0330c" + [[package]] name = "assign" version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f093eed78becd229346bf859eec0aa4dd7ddde0757287b2b4107a1f09c80002" +[[package]] +name = "async-lock" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6a8ea61bf9947a1007c5cada31e647dbc77b103c679858150003ba697ea798b" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-stream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" +dependencies = [ + "async-stream-impl", + "futures-core", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" +dependencies = [ + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.81", +] + [[package]] name = "async-trait" version = "0.1.51" @@ -134,6 +170,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bs58" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" + [[package]] name = "buf_redux" version = "0.8.4" @@ -514,7 +556,6 @@ checksum = "a12aa0eb539080d55c3f2d45a67c3b58b6b0773c1a3ca2dfec66d58c97fd66ca" dependencies = [ "futures-channel", "futures-core", - "futures-executor", "futures-io", "futures-sink", "futures-task", @@ -537,45 +578,12 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" -[[package]] -name = "futures-executor" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45025be030969d763025784f7f355043dc6bc74093e4ecc5000ca4dc50d8745c" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - [[package]] name = "futures-io" version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" -[[package]] -name = "futures-locks" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c4e684ddb2d8a4db5ca8a02b35156da129674ba4412b6f528698d58c594954" -dependencies = [ - "futures", -] - -[[package]] -name = "futures-macro" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb" -dependencies = [ - "autocfg", - "proc-macro-hack", - "proc-macro2 1.0.32", - "quote 1.0.10", - "syn 1.0.81", -] - [[package]] name = "futures-sink" version = "0.3.17" @@ -607,15 +615,10 @@ dependencies = [ "autocfg", "futures-channel", "futures-core", - "futures-io", - "futures-macro", "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", - "proc-macro-hack", - "proc-macro-nested", "slab", ] @@ -1039,8 +1042,7 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "matrix-qrcode" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4231739aa2ff90c6c55b07d7179c52b496622a86fc2f7e0431336d109ba7838d" +source = "git+https://github.com/matrix-org/matrix-rust-sdk.git?rev=a49a7fe1f93a4e8791dbbe4fd6876c587c33d2fa#a49a7fe1f93a4e8791dbbe4fd6876c587c33d2fa" dependencies = [ "base64", "byteorder", @@ -1054,15 +1056,17 @@ dependencies = [ [[package]] name = "matrix-sdk" version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5834b96fef26d6d61c8ffd21dda3569c7c0fc688f9cc8aebd35f6f8c3068a186" +source = "git+https://github.com/matrix-org/matrix-rust-sdk.git?rev=a49a7fe1f93a4e8791dbbe4fd6876c587c33d2fa#a49a7fe1f93a4e8791dbbe4fd6876c587c33d2fa" dependencies = [ + "anymap2", + "async-stream", "backoff", "bytes", "dashmap", "event-listener", - "futures", + "futures-core", "futures-timer", + "futures-util", "http", "matrix-sdk-base", "matrix-sdk-common", @@ -1074,7 +1078,6 @@ dependencies = [ "thiserror", "tokio", "tracing", - "tracing-futures", "url", "zeroize", ] @@ -1082,12 +1085,12 @@ dependencies = [ [[package]] name = "matrix-sdk-base" version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97c4d675ff70395c1b0cd94fae869cea4efd3f148b74bf4186e969ee622a9c7" +source = "git+https://github.com/matrix-org/matrix-rust-sdk.git?rev=a49a7fe1f93a4e8791dbbe4fd6876c587c33d2fa#a49a7fe1f93a4e8791dbbe4fd6876c587c33d2fa" dependencies = [ "chacha20poly1305", "dashmap", - "futures", + "futures-core", + "futures-util", "hmac", "lru", "matrix-sdk-common", @@ -1108,12 +1111,11 @@ dependencies = [ [[package]] name = "matrix-sdk-common" version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c004ca5d02a17eb827a2c3d8e34c9a84c075b42cfed7022895ba6418372ea5" +source = "git+https://github.com/matrix-org/matrix-rust-sdk.git?rev=a49a7fe1f93a4e8791dbbe4fd6876c587c33d2fa#a49a7fe1f93a4e8791dbbe4fd6876c587c33d2fa" dependencies = [ + "async-lock", "async-trait", - "futures", - "futures-locks", + "futures-util", "instant", "ruma", "serde", @@ -1125,22 +1127,23 @@ dependencies = [ [[package]] name = "matrix-sdk-crypto" version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d36626b188e0ea1d244eef6fe39ab1758c401de6ec84d0389df88f9f6ad761b9" +source = "git+https://github.com/matrix-org/matrix-rust-sdk.git?rev=a49a7fe1f93a4e8791dbbe4fd6876c587c33d2fa#a49a7fe1f93a4e8791dbbe4fd6876c587c33d2fa" dependencies = [ "aes", "aes-gcm", "atomic", "base64", + "bs58", "byteorder", "dashmap", - "futures", + "futures-util", "getrandom 0.2.3", "hmac", "matrix-qrcode", "matrix-sdk-common", "olm-rs", "pbkdf2", + "rand 0.8.4", "ruma", "serde", "serde_json", @@ -1352,9 +1355,9 @@ dependencies = [ [[package]] name = "olm-rs" -version = "2.0.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33a5773f317476f5687fc8200fc0120d97b075c30c133a5b15ca558252743720" +checksum = "28d071397525c2c184bb916a608d8e0be8f0c14f0ae4075c2949c7a7fbae52ad" dependencies = [ "getrandom 0.2.3", "olm-sys", @@ -1563,18 +1566,6 @@ dependencies = [ "toml", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - -[[package]] -name = "proc-macro-nested" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" - [[package]] name = "proc-macro2" version = "0.4.30" @@ -1788,9 +1779,9 @@ dependencies = [ [[package]] name = "rqrr" -version = "0.3.2" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88a63da014e6f18dbe76e3084feb2f6c5a570ad8d524cc1afff4a6db18404cd" +checksum = "6fa79947f53b20adb909a323d828d0fd744fa9d854792df07913b083bcd4d63b" dependencies = [ "g2p", "image", @@ -1800,8 +1791,7 @@ dependencies = [ [[package]] name = "ruma" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "668031e3108d6a2cfbe6eca271d8698f4593440e71a44afdadcf67ce3cb93c1f" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" dependencies = [ "assign", "js_int", @@ -1819,8 +1809,7 @@ dependencies = [ [[package]] name = "ruma-api" version = "0.18.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eda5ec9cf6163bb6be82c8a3994de09fdcd349dcf651aa6cabf649451f361eee" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" dependencies = [ "bytes", "http", @@ -1836,8 +1825,7 @@ dependencies = [ [[package]] name = "ruma-api-macros" version = "0.18.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72984e25b5e66fcce3267e97288e8dab96e966b151d4d205846049f5b2819e97" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" dependencies = [ "proc-macro-crate", "proc-macro2 1.0.32", @@ -1848,8 +1836,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef8acd3e66bf9d63d9472ecd17b9f497062ce1caaf13673b101d6697358b41a7" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" dependencies = [ "assign", "bytes", @@ -1869,8 +1856,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d5b7605f58dc0d9cf1848cc7f1af2bae4e4bcd1d2b7a87bbb9864c8a785b91" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" dependencies = [ "indexmap", "js_int", @@ -1885,8 +1871,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.24.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ba40ba9f4b6bdf6dc82b18ee7dfd7a029c86a12f9785a0efe4df04bd5dfa3c8" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" dependencies = [ "indoc", "js_int", @@ -1902,8 +1887,7 @@ dependencies = [ [[package]] name = "ruma-events-macros" version = "0.24.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "431a3dfadb48a8b7df9d00776274e32fed68df96cc19d9d9346bfed62540f91a" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" dependencies = [ "proc-macro-crate", "proc-macro2 1.0.32", @@ -1914,8 +1898,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa3d1db1a064ab26484df6ef5d96c384fc053022004f34d96c3b4939e13dc204" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" dependencies = [ "js_int", "ruma-api", @@ -1930,10 +1913,10 @@ dependencies = [ [[package]] name = "ruma-identifiers" version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb417d091e8dd5a633e4e5998231a156049d7fcc221045cfdc0642eb72067732" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" dependencies = [ "paste", + "percent-encoding", "ruma-identifiers-macros", "ruma-identifiers-validation", "ruma-serde", @@ -1944,8 +1927,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-macros" version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c708edad7f605638f26c951cbad7501fbf28ab01009e5ca65ea5a2db74a882b1" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" dependencies = [ "quote 1.0.10", "ruma-identifiers-validation", @@ -1955,14 +1937,15 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42285e7fb5d5f2d5268e45bb683e36d5c6fd9fc1e11a4559ba3c3521f3bbb2cb" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" +dependencies = [ + "thiserror", +] [[package]] name = "ruma-serde" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b2b22aae842e7ecda695e42b7b39d4558959d9d9a27acc2a16acf4f4f7f00c3" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" dependencies = [ "bytes", "form_urlencoded", @@ -1976,8 +1959,7 @@ dependencies = [ [[package]] name = "ruma-serde-macros" version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243e9bef188b08f94c79bc2f8fd1eb307a9e636b2b8e4571acf8c7be16381d28" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" dependencies = [ "proc-macro-crate", "proc-macro2 1.0.32", @@ -1988,8 +1970,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a4f64027165b59500162d10d435b1253898bf3ad4f5002cb0d56913fe7f76d7" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" dependencies = [ "base64", "ed25519-dalek", @@ -2006,8 +1987,7 @@ dependencies = [ [[package]] name = "ruma-state-res" version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "518c1afbddfcc5ffac8818a5cf0902709e6eca11aca8f24f6479df6f0601f1ba" +source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7" dependencies = [ "itertools", "js_int", @@ -2459,16 +2439,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project", - "tracing", -] - [[package]] name = "try-lock" version = "0.2.3" diff --git a/Cargo.toml b/Cargo.toml index b315789..0c22c86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -matrix-sdk = { version = "0.4.1", features = [ "encryption", "sled_cryptostore" ] } +# we use new features not quite yet in a released matrix rust SDK +#matrix-sdk = { version = "0.4.1", features = [ "encryption", "sled_cryptostore" ] } +matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git", rev = "a49a7fe1f93a4e8791dbbe4fd6876c587c33d2fa", features = ["encryption", "sled_cryptostore"] } #monzo-lib = "0.4.0" monzo-lib = { git = "https://github.com/danieleades/monzo-lib.git", rev = "e54ff827" } tokio = { version = "1.13.0", features = [ "full" ] } diff --git a/src/main.rs b/src/main.rs index 551c6fd..4540911 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,12 @@ use crate::monzo::monzo_client_freshened; use crate::state::{Config, MonzoState, State, StateInner}; use crate::web::warp_main; +use matrix_sdk::config::{ClientConfig, SyncSettings}; use matrix_sdk::room::Room; -use matrix_sdk::ruma::events::room::message::{MessageEventContent, MessageType}; +use matrix_sdk::ruma::events::room::message::{MessageType, RoomMessageEventContent}; use matrix_sdk::ruma::events::SyncMessageEvent; use matrix_sdk::ruma::UserId; -use matrix_sdk::{Client, ClientConfig, SyncSettings}; +use matrix_sdk::{Client, Session}; use std::convert::TryFrom; use std::sync::Arc; use tokio::io::AsyncReadExt; @@ -16,7 +17,7 @@ pub mod state; pub mod web; async fn on_room_message( - event: &SyncMessageEvent, + event: &SyncMessageEvent, room: Room, state: &State, ) -> anyhow::Result<()> { @@ -45,10 +46,10 @@ async fn on_room_message( buf.push_str("?currency"); } } - let content = MessageEventContent::text_plain(&buf); + let content = RoomMessageEventContent::text_plain(&buf); room.send(content, None).await.unwrap(); } else { - let content = MessageEventContent::text_plain("Not linked :(."); + let content = RoomMessageEventContent::text_plain("Not linked :(."); room.send(content, None).await.unwrap(); } } @@ -69,7 +70,7 @@ async fn main() -> anyhow::Result<()> { let client_config = ClientConfig::new().store_path(store_path); - let client = Client::new_from_user_id_with_config(mxid.clone(), client_config).await?; + let client = Client::new_from_user_id_with_config(&mxid, client_config).await?; let state = State { config: Arc::new(config.clone()), @@ -111,7 +112,7 @@ async fn main() -> anyhow::Result<()> { client .register_event_handler( - move |ev: SyncMessageEvent, room: Room| { + move |ev: SyncMessageEvent, room: Room| { let state_arc = state_arc.clone(); async move { if let Err(error) = on_room_message(&ev, room, &state_arc).await { diff --git a/src/monzo.rs b/src/monzo.rs index 92ff40e..c40a469 100644 --- a/src/monzo.rs +++ b/src/monzo.rs @@ -73,7 +73,11 @@ pub async fn monzo_client_freshened( drop(state_inner); let needs_refresh = exp_at_instant < SystemTime::now(); if needs_refresh { - eprintln!("Refreshing token; expiry {:?}; now {:?}.", exp_at_instant, SystemTime::now()); + eprintln!( + "Refreshing token; expiry {:?}; now {:?}.", + exp_at_instant, + SystemTime::now() + ); eprintln!("DEBUG refresh_token being used {:?}", &refresh_token); let client = reqwest::Client::new(); let resp = client @@ -87,8 +91,7 @@ pub async fn monzo_client_freshened( .send() .await?; eprintln!("DEBUG response status {:?}", resp.status()); - let jv: serde_json::Value = resp.json() - .await?; + let jv: serde_json::Value = resp.json().await?; eprintln!("DEBUG raw JV {:#?}", jv); let auth_resp: MonzoAuthResponse = serde_json::from_value(jv)?; let mut state_inner = state.inner.write().await; diff --git a/src/web.rs b/src/web.rs index a55dcb6..01434d5 100644 --- a/src/web.rs +++ b/src/web.rs @@ -3,7 +3,7 @@ use crate::monzo::{ }; use crate::state::State; use matrix_sdk::room::Room; -use matrix_sdk::ruma::events::room::message::MessageEventContent; +use matrix_sdk::ruma::events::room::message::RoomMessageEventContent; use matrix_sdk::ruma::RoomId; use monzo::accounts::Type; use serde::Deserialize; @@ -191,10 +191,9 @@ async fn monzo_hook(hook: MonzoHook, state: State) -> anyhow::Result