aboutsummaryrefslogtreecommitdiff
blob: 967c534ade6fc520fd153c0ebea41d1a7b6e2b4c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use crate::{objects::person::DbUser, Error};
use anyhow::anyhow;
use std::sync::{Arc, Mutex};

pub type DatabaseHandle = Arc<Database>;

/// Our "database" which contains all known users (local and federated)
pub struct Database {
    pub users: Mutex<Vec<DbUser>>,
}

impl Database {
    pub fn local_user(&self) -> DbUser {
        let lock = self.users.lock().unwrap();
        lock.first().unwrap().clone()
    }

    pub fn read_user(&self, name: &str) -> Result<DbUser, Error> {
        let db_user = self.local_user();
        if name == db_user.name {
            Ok(db_user)
        } else {
            Err(anyhow!("Invalid user {name}").into())
        }
    }
}
Powered by cgit v1.2.3 (git 2.41.0)