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

pub async fn create_and_auth_client(acct: Account) -> Result<Arc<MatrixClient>, Error> { 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)?; 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() let cc = matrix_sdk::ClientConfig::new()
.user_agent("mtxspooler") .user_agent("mtxspooler")
.unwrap(); .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)?; let c = matrix_sdk::Client::new_with_config(hs_url, cc).map_err(Error::Matrix)?;


// Now log in. // Now log in.
} }
} }


// 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)) Ok(Arc::new(c))
} }



+ 7
- 1
src/config.rs View File

pub display: Option<String>, pub display: Option<String>,
pub device_id: Option<String>, pub device_id: Option<String>,
pub auth: Auth, pub auth: Auth,
pub store_dir: Option<PathBuf>,
} }


#[derive(Clone, Debug)] #[derive(Clone, Debug)]
homeserver: String, homeserver: String,
username: String, username: String,
password: String, password: String,
datadir: Option<String>,
} }


#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
let mut conf = Config::default(); let mut conf = Config::default();


for p in paths { 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 { let val = match load_toml(p).await {
Ok(t) => t, Ok(t) => t,
Err(_) => { Err(_) => {
auth: Auth::UsernamePass(a.username, a.password), auth: Auth::UsernamePass(a.username, a.password),
device_id: None, device_id: None,
display: None, display: None,
store_dir: a.datadir.map(PathBuf::from),
}; };


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

+ 3
- 1
src/main.rs View File

eprintln!("[init] warning: reload trigger file specified, but this option is not supported yet, ignoring..."); 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)); rt.block_on(main_inner(opts));
} }


fn make_runtime() -> runtime::Runtime { fn make_runtime() -> runtime::Runtime {
runtime::Builder::new_current_thread() runtime::Builder::new_current_thread()
.thread_name("mtxspooler-worker") .thread_name("mtxspooler-worker")
.worker_threads(1)
.max_blocking_threads(1)
.enable_all() .enable_all()
.build() .build()
.expect("rt: init") .expect("rt: init")

Loading…
Cancel
Save