Can get current user identity
This commit is contained in:
18
src/user.rs
18
src/user.rs
@ -8,10 +8,15 @@ use crate::app_config::AppConfig;
|
||||
use crate::constants::TOKEN_LEN;
|
||||
use crate::utils::{curr_time, format_time, rand_str};
|
||||
|
||||
type HttpClient = ruma::client::http_client::HyperNativeTls;
|
||||
pub type RumaClient = ruma::Client<HttpClient>;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum UserError {
|
||||
#[error("failed to fetch user configuration: {0}")]
|
||||
FetchUserConfig(S3Error),
|
||||
#[error("missing matrix token")]
|
||||
MissingMatrixToken,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
|
||||
@ -220,4 +225,17 @@ impl UserConfig {
|
||||
pub fn find_client_by_id_mut(&mut self, id: &APIClientID) -> Option<&mut APIClient> {
|
||||
self.clients.iter_mut().find(|c| &c.id == id)
|
||||
}
|
||||
|
||||
/// Get a matrix client instance for the current user
|
||||
pub async fn matrix_client(&self) -> anyhow::Result<RumaClient> {
|
||||
if self.matrix_token.is_empty() {
|
||||
return Err(UserError::MissingMatrixToken.into());
|
||||
}
|
||||
|
||||
Ok(ruma::Client::builder()
|
||||
.homeserver_url(AppConfig::get().matrix_homeserver.to_string())
|
||||
.access_token(Some(self.matrix_token.clone()))
|
||||
.build()
|
||||
.await?)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user