Upgrade to matrix-rust-sdk 0.5.0
This commit is contained in:
parent
e8fcd33a01
commit
3f2170263b
File diff suppressed because it is too large
Load Diff
|
@ -7,10 +7,10 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
# 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" }
|
||||
matrix-sdk = "0.5.0"
|
||||
#matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git", rev = "a49a7fe1f93a4e8791dbbe4fd6876c587c33d2fa", features = ["encryption", "sled_cryptostore"] }
|
||||
monzo-lib = "0.4.4"
|
||||
#monzo-lib = { git = "https://github.com/danieleades/monzo-lib.git", rev = "e54ff827" }
|
||||
tokio = { version = "1.13.0", features = [ "full" ] }
|
||||
anyhow = "1.0.45"
|
||||
warp = "0.3.1"
|
||||
|
|
25
src/main.rs
25
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::config::SyncSettings;
|
||||
use matrix_sdk::room::Room;
|
||||
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::store::StateStore;
|
||||
use matrix_sdk::{Client, Session};
|
||||
use std::convert::TryFrom;
|
||||
use std::fs::File;
|
||||
|
@ -18,7 +19,7 @@ pub mod state;
|
|||
pub mod web;
|
||||
|
||||
async fn on_room_message(
|
||||
event: &SyncMessageEvent<RoomMessageEventContent>,
|
||||
event: &OriginalSyncMessageLikeEvent<RoomMessageEventContent>,
|
||||
room: Room,
|
||||
state: &State,
|
||||
) -> anyhow::Result<()> {
|
||||
|
@ -66,12 +67,22 @@ async fn main() -> anyhow::Result<()> {
|
|||
|
||||
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 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 {
|
||||
config: Arc::new(config.clone()),
|
||||
|
@ -122,7 +133,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
|
||||
client
|
||||
.register_event_handler(
|
||||
move |ev: SyncMessageEvent<RoomMessageEventContent>, room: Room| {
|
||||
move |ev: OriginalSyncMessageLikeEvent<RoomMessageEventContent>, room: Room| {
|
||||
let state_arc = state_arc.clone();
|
||||
async move {
|
||||
if let Err(error) = on_room_message(&ev, room, &state_arc).await {
|
||||
|
|
|
@ -140,7 +140,7 @@ async fn monzo_hook(hook: MonzoHook, state: State) -> anyhow::Result<impl warp::
|
|||
|
||||
let room = state
|
||||
.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!"))?;
|
||||
if let Room::Joined(room) = room {
|
||||
let mut buf = String::new();
|
||||
|
|
Loading…
Reference in New Issue