diff --git a/examples/command_bot.rs b/examples/command_bot.rs index fded958e..2b27bfe3 100644 --- a/examples/command_bot.rs +++ b/examples/command_bot.rs @@ -4,7 +4,7 @@ use std::{env, process::exit}; use matrix_sdk::{ self, events::room::message::{MessageEvent, MessageEventContent, TextMessageEventContent}, - AsyncClient, AsyncClientConfig, EventEmitter, Room, SyncSettings, + AsyncClient, AsyncClientConfig, EventEmitter, JsonStore, Room, SyncSettings, }; use tokio::sync::RwLock; use url::Url; @@ -63,9 +63,14 @@ async fn login_and_sync( username: String, password: String, ) -> Result<(), matrix_sdk::Error> { + let mut home = dirs::home_dir().expect("no home directory found"); + home.push("party_bot"); + + let store = JsonStore::open(&home)?; let client_config = AsyncClientConfig::new() .proxy("http://localhost:8080")? - .disable_ssl_verification(); + .disable_ssl_verification() + .state_store(Box::new(store)); let homeserver_url = Url::parse(&homeserver_url)?; // create a new AsyncClient with the given homeserver url and config diff --git a/src/state/mod.rs b/src/state/mod.rs index 1e9906eb..723bdb07 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -25,6 +25,13 @@ use crate::events::push_rules::Ruleset; use crate::identifiers::{DeviceId, RoomId, UserId}; use crate::models::Room; use crate::Result; + +/// `ClientState` holds all the information to restore a `BaseClient` +/// except the `access_token` as the default store is not secure. +/// +/// When implementing `StateStore` for something other than the filesystem +/// implement `From for YourDbType` this allows for easy conversion +/// when needed in `StateStore::load/store_client_state` #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct ClientState { /// The `UserId` for the current logged in user.