aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'fedi/live_federation/database.rs')
-rw-r--r--fedi/live_federation/database.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/fedi/live_federation/database.rs b/fedi/live_federation/database.rs
new file mode 100644
index 0000000..967c534
--- /dev/null
+++ b/fedi/live_federation/database.rs
@@ -0,0 +1,26 @@
1use crate::{objects::person::DbUser, Error};
2use anyhow::anyhow;
3use std::sync::{Arc, Mutex};
4
5pub type DatabaseHandle = Arc<Database>;
6
7/// Our "database" which contains all known users (local and federated)
8pub struct Database {
9 pub users: Mutex<Vec<DbUser>>,
10}
11
12impl Database {
13 pub fn local_user(&self) -> DbUser {
14 let lock = self.users.lock().unwrap();
15 lock.first().unwrap().clone()
16 }
17
18 pub fn read_user(&self, name: &str) -> Result<DbUser, Error> {
19 let db_user = self.local_user();
20 if name == db_user.name {
21 Ok(db_user)
22 } else {
23 Err(anyhow!("Invalid user {name}").into())
24 }
25 }
26}
Powered by cgit v1.2.3 (git 2.41.0)