From 8f57f73b666b8c35dc17374e8967469a1b167593 Mon Sep 17 00:00:00 2001 From: Devin R Date: Sat, 25 Apr 2020 06:26:35 -0400 Subject: [PATCH] command_bot: use JsonStore in example --- examples/command_bot.rs | 9 +++++++-- src/state/mod.rs | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) 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.