Browse Source

Do sync properly, now that it matters, and let you specify a data store directory.

master
treyzania 2 years ago
parent
commit
20d781adb3
3 changed files with 32 additions and 2 deletions
  1. 22
    0
      src/client.rs
  2. 7
    1
      src/config.rs
  3. 3
    1
      src/main.rs

+ 22
- 0
src/client.rs View File

@@ -52,9 +52,15 @@ impl Message {
pub async fn create_and_auth_client(acct: Account) -> Result<Arc<MatrixClient>, Error> {
let hs_url = url::Url::parse(&acct.homeserver).map_err(|_| Error::BadUrl)?;

// This is so annoying, why don't they use `&mut`?
let cc = matrix_sdk::ClientConfig::new()
.user_agent("mtxspooler")
.unwrap();
let cc = match acct.store_dir {
Some(sdir) => cc.store_path(sdir),
None => cc,
};

let c = matrix_sdk::Client::new_with_config(hs_url, cc).map_err(Error::Matrix)?;

// Now log in.
@@ -67,6 +73,22 @@ pub async fn create_and_auth_client(acct: Account) -> Result<Arc<MatrixClient>,
}
}

// I think we need to spawn a task to sync.
let c_sync = c.clone();
tokio::spawn(async move {
c_sync.sync(matrix_sdk::SyncSettings::new()).await;
});

// Let's list all the rooms we know about!
tokio::time::sleep(::std::time::Duration::from_secs(1)).await;
for r in c.rooms() {
if let Some(name) = r.name() {
eprintln!("[client] found room: {}", name);
} else {
eprintln!("[client] found room: {:?}", r.room_id());
}
}

Ok(Arc::new(c))
}


+ 7
- 1
src/config.rs View File

@@ -49,6 +49,7 @@ pub struct Account {
pub display: Option<String>,
pub device_id: Option<String>,
pub auth: Auth,
pub store_dir: Option<PathBuf>,
}

#[derive(Clone, Debug)]
@@ -76,6 +77,7 @@ pub struct ConfigAccount {
homeserver: String,
username: String,
password: String,
datadir: Option<String>,
}

#[derive(Clone, Debug, Deserialize)]
@@ -108,7 +110,10 @@ pub async fn parse_configs(paths: &Vec<PathBuf>) -> Result<Config, Error> {
let mut conf = Config::default();

for p in paths {
println!("Reading config: {}", p.to_str().unwrap_or("[non-UTF-8]"));
println!(
"[init] reading config: {}",
p.to_str().unwrap_or("[non-UTF-8]")
);
let val = match load_toml(p).await {
Ok(t) => t,
Err(_) => {
@@ -129,6 +134,7 @@ pub async fn parse_configs(paths: &Vec<PathBuf>) -> Result<Config, Error> {
auth: Auth::UsernamePass(a.username, a.password),
device_id: None,
display: None,
store_dir: a.datadir.map(PathBuf::from),
};

conf.accounts.insert(a.label, acct);

+ 3
- 1
src/main.rs View File

@@ -48,7 +48,7 @@ fn main() {
eprintln!("[init] warning: reload trigger file specified, but this option is not supported yet, ignoring...");
}

let mut rt = make_runtime();
let rt = make_runtime();
rt.block_on(main_inner(opts));
}

@@ -115,6 +115,8 @@ async fn main_inner(opts: Opts) {
fn make_runtime() -> runtime::Runtime {
runtime::Builder::new_current_thread()
.thread_name("mtxspooler-worker")
.worker_threads(1)
.max_blocking_threads(1)
.enable_all()
.build()
.expect("rt: init")

Loading…
Cancel
Save