use std::path::PathBuf;
use matrix_sdk::ruma::{OwnedDeviceId, OwnedUserId};
pub struct MatrixConfig {
pub(crate) homeserver_url: String,
pub(crate) auth: MatrixAuth,
pub(crate) command_prefix: String,
pub(crate) device_name: Option<String>,
pub(crate) state_store_path: Option<PathBuf>,
pub(crate) auto_join_rooms: bool,
}
pub enum MatrixAuth {
Password {
user_id: String,
password: String,
},
AccessToken {
user_id: OwnedUserId,
access_token: String,
device_id: OwnedDeviceId,
},
}
impl MatrixConfig {
pub fn new(homeserver_url: impl Into<String>) -> Self {
Self {
homeserver_url: homeserver_url.into(),
auth: MatrixAuth::Password {
user_id: String::new(),
password: String::new(),
},
command_prefix: "!".to_string(),
device_name: None,
state_store_path: None,
auto_join_rooms: false,
}
}
pub fn password_auth(
mut self,
user_id: impl Into<String>,
password: impl Into<String>,
) -> Self {
self.auth = MatrixAuth::Password {
user_id: user_id.into(),
password: password.into(),
};
self
}
pub fn access_token_auth(
mut self,
user_id: OwnedUserId,
access_token: impl Into<String>,
device_id: OwnedDeviceId,
) -> Self {
self.auth = MatrixAuth::AccessToken {
user_id,
access_token: access_token.into(),
device_id,
};
self
}
pub fn command_prefix(mut self, prefix: impl Into<String>) -> Self {
self.command_prefix = prefix.into();
self
}
pub fn device_name(mut self, name: impl Into<String>) -> Self {
self.device_name = Some(name.into());
self
}
pub fn state_store_path(mut self, path: impl Into<PathBuf>) -> Self {
self.state_store_path = Some(path.into());
self
}
pub fn auto_join_rooms(mut self, enabled: bool) -> Self {
self.auto_join_rooms = enabled;
self
}
}