command_bot: use JsonStore in example

master
Devin R 2020-04-25 06:26:35 -04:00
parent 0749e59af8
commit 8f57f73b66
2 changed files with 14 additions and 2 deletions

View File

@ -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

View File

@ -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<ClientState> 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.