Upgrade to matrix-rust-sdk 0.5.0

This commit is contained in:
Olivier 'reivilibre' 2022-05-23 21:52:07 +01:00
parent e8fcd33a01
commit 3f2170263b
4 changed files with 947 additions and 943 deletions

1855
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,10 +7,10 @@ edition = "2021"
[dependencies] [dependencies]
# we use new features not quite yet in a released matrix rust SDK # 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 = "0.5.0"
matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git", rev = "a49a7fe1f93a4e8791dbbe4fd6876c587c33d2fa", 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 = "0.4.4"
monzo-lib = { git = "https://github.com/danieleades/monzo-lib.git", rev = "e54ff827" } #monzo-lib = { git = "https://github.com/danieleades/monzo-lib.git", rev = "e54ff827" }
tokio = { version = "1.13.0", features = [ "full" ] } tokio = { version = "1.13.0", features = [ "full" ] }
anyhow = "1.0.45" anyhow = "1.0.45"
warp = "0.3.1" warp = "0.3.1"

View File

@ -1,11 +1,12 @@
use crate::monzo::monzo_client_freshened; use crate::monzo::monzo_client_freshened;
use crate::state::{Config, MonzoState, State, StateInner}; use crate::state::{Config, MonzoState, State, StateInner};
use crate::web::warp_main; use crate::web::warp_main;
use matrix_sdk::config::{ClientConfig, SyncSettings}; use matrix_sdk::config::SyncSettings;
use matrix_sdk::room::Room; use matrix_sdk::room::Room;
use matrix_sdk::ruma::events::room::message::{MessageType, RoomMessageEventContent}; use matrix_sdk::ruma::events::room::message::{MessageType, RoomMessageEventContent};
use matrix_sdk::ruma::events::SyncMessageEvent; use matrix_sdk::ruma::events::OriginalSyncMessageLikeEvent;
use matrix_sdk::ruma::UserId; use matrix_sdk::ruma::UserId;
use matrix_sdk::store::StateStore;
use matrix_sdk::{Client, Session}; use matrix_sdk::{Client, Session};
use std::convert::TryFrom; use std::convert::TryFrom;
use std::fs::File; use std::fs::File;
@ -18,7 +19,7 @@ pub mod state;
pub mod web; pub mod web;
async fn on_room_message( async fn on_room_message(
event: &SyncMessageEvent<RoomMessageEventContent>, event: &OriginalSyncMessageLikeEvent<RoomMessageEventContent>,
room: Room, room: Room,
state: &State, state: &State,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
@ -66,12 +67,22 @@ async fn main() -> anyhow::Result<()> {
let state_inner = StateInner::default(); let state_inner = StateInner::default();
let mxid = UserId::try_from(config.matrix_id.clone())?; let mxid = <&UserId>::try_from(config.matrix_id.as_str())?;
let store_path = config.matrix_store.clone(); let store_path = config.matrix_store.clone();
let client_config = ClientConfig::new().store_path(store_path); let state_store = Box::new(StateStore::open_with_path(store_path.join("state"))?);
let client = Client::new_from_user_id_with_config(&mxid, client_config).await?; let crypto_store = Box::new(matrix_sdk::store::CryptoStore::open_with_passphrase(
store_path.join("crypto"),
None,
)?);
let client = Client::builder()
.crypto_store(crypto_store)
.state_store(state_store)
.user_id(&mxid)
.build()
.await?;
let state = State { let state = State {
config: Arc::new(config.clone()), config: Arc::new(config.clone()),
@ -122,7 +133,7 @@ async fn main() -> anyhow::Result<()> {
client client
.register_event_handler( .register_event_handler(
move |ev: SyncMessageEvent<RoomMessageEventContent>, room: Room| { move |ev: OriginalSyncMessageLikeEvent<RoomMessageEventContent>, room: Room| {
let state_arc = state_arc.clone(); let state_arc = state_arc.clone();
async move { async move {
if let Err(error) = on_room_message(&ev, room, &state_arc).await { if let Err(error) = on_room_message(&ev, room, &state_arc).await {

View File

@ -140,7 +140,7 @@ async fn monzo_hook(hook: MonzoHook, state: State) -> anyhow::Result<impl warp::
let room = state let room = state
.matrix_client .matrix_client
.get_room(&RoomId::from_str(&state.config.matrix_room)?) .get_room(<&RoomId>::try_from(state.config.matrix_room.as_str())?)
.ok_or_else(|| anyhow::anyhow!("Matrix room not found!"))?; .ok_or_else(|| anyhow::anyhow!("Matrix room not found!"))?;
if let Room::Joined(room) = room { if let Room::Joined(room) = room {
let mut buf = String::new(); let mut buf = String::new();