From af2f09ea4cbb97d3ee91e30bb58e85508989d63a Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Wed, 26 Jul 2023 12:37:38 -0700 Subject: add example from https://github.com/LemmyNet/activitypub-federation-rust --- fedi/live_federation/database.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 fedi/live_federation/database.rs (limited to 'fedi/live_federation/database.rs') 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 @@ +use crate::{objects::person::DbUser, Error}; +use anyhow::anyhow; +use std::sync::{Arc, Mutex}; + +pub type DatabaseHandle = Arc; + +/// Our "database" which contains all known users (local and federated) +pub struct Database { + pub users: Mutex>, +} + +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 { + let db_user = self.local_user(); + if name == db_user.name { + Ok(db_user) + } else { + Err(anyhow!("Invalid user {name}").into()) + } + } +} -- cgit v1.2.3