2020-03-28 17:50:02 +00:00
|
|
|
use directories::ProjectDirs;
|
2020-03-29 12:48:44 +01:00
|
|
|
use ruma_events::collections::all::RoomEvent;
|
2020-03-28 17:50:02 +00:00
|
|
|
use ruma_identifiers::UserId;
|
|
|
|
|
|
|
|
pub struct Data(sled::Db);
|
|
|
|
|
|
|
|
impl Data {
|
|
|
|
pub fn set_hostname(&self, hostname: &str) {
|
|
|
|
self.0.insert("hostname", hostname).unwrap();
|
|
|
|
}
|
|
|
|
pub fn hostname(&self) -> String {
|
|
|
|
String::from_utf8(self.0.get("hostname").unwrap().unwrap().to_vec()).unwrap()
|
|
|
|
}
|
|
|
|
pub fn load_or_create() -> Self {
|
|
|
|
Data(
|
|
|
|
sled::open(
|
|
|
|
ProjectDirs::from("xyz", "koesters", "matrixserver")
|
|
|
|
.unwrap()
|
|
|
|
.data_dir(),
|
|
|
|
)
|
|
|
|
.unwrap(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn user_exists(&self, user_id: &UserId) -> bool {
|
|
|
|
self.0
|
|
|
|
.open_tree("username_password")
|
|
|
|
.unwrap()
|
|
|
|
.contains_key(user_id.to_string())
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn user_add(&self, user_id: UserId, password: Option<String>) {
|
|
|
|
self.0
|
|
|
|
.open_tree("username_password")
|
|
|
|
.unwrap()
|
|
|
|
.insert(user_id.to_string(), &*password.unwrap_or_default())
|
|
|
|
.unwrap();
|
|
|
|
}
|
2020-03-29 12:48:44 +01:00
|
|
|
|
|
|
|
pub fn room_event_add(&self, room_event: &RoomEvent) {}
|
2020-03-28 17:50:02 +00:00
|
|
|
}
|