command_bot: use JsonStore in example
parent
0749e59af8
commit
8f57f73b66
|
@ -4,7 +4,7 @@ use std::{env, process::exit};
|
||||||
use matrix_sdk::{
|
use matrix_sdk::{
|
||||||
self,
|
self,
|
||||||
events::room::message::{MessageEvent, MessageEventContent, TextMessageEventContent},
|
events::room::message::{MessageEvent, MessageEventContent, TextMessageEventContent},
|
||||||
AsyncClient, AsyncClientConfig, EventEmitter, Room, SyncSettings,
|
AsyncClient, AsyncClientConfig, EventEmitter, JsonStore, Room, SyncSettings,
|
||||||
};
|
};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -63,9 +63,14 @@ async fn login_and_sync(
|
||||||
username: String,
|
username: String,
|
||||||
password: String,
|
password: String,
|
||||||
) -> Result<(), matrix_sdk::Error> {
|
) -> 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()
|
let client_config = AsyncClientConfig::new()
|
||||||
.proxy("http://localhost:8080")?
|
.proxy("http://localhost:8080")?
|
||||||
.disable_ssl_verification();
|
.disable_ssl_verification()
|
||||||
|
.state_store(Box::new(store));
|
||||||
|
|
||||||
let homeserver_url = Url::parse(&homeserver_url)?;
|
let homeserver_url = Url::parse(&homeserver_url)?;
|
||||||
// create a new AsyncClient with the given homeserver url and config
|
// create a new AsyncClient with the given homeserver url and config
|
||||||
|
|
|
@ -25,6 +25,13 @@ use crate::events::push_rules::Ruleset;
|
||||||
use crate::identifiers::{DeviceId, RoomId, UserId};
|
use crate::identifiers::{DeviceId, RoomId, UserId};
|
||||||
use crate::models::Room;
|
use crate::models::Room;
|
||||||
use crate::Result;
|
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)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct ClientState {
|
pub struct ClientState {
|
||||||
/// The `UserId` for the current logged in user.
|
/// The `UserId` for the current logged in user.
|
||||||
|
|
Loading…
Reference in New Issue