diff options
Diffstat (limited to 'src/state.rs')
-rw-r--r-- | src/state.rs | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/src/state.rs b/src/state.rs index 69c6208..64c2e7c 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,3 +1,44 @@ -pub struct AppState {} +use std::{ + ops::Deref, + sync::{Arc, RwLock}, +}; -impl AppState {} +use activitypub_federation::config::FederationConfig; + +use crate::{entity::user::LocalUser, error::AppError}; + +#[derive(Clone)] +pub struct AppHandle(pub Arc<AppState>); + +impl Deref for AppHandle { + type Target = Arc<AppState>; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +pub struct AppState { + users: RwLock<Vec<LocalUser>>, +} + +impl AppState { + pub async fn new() -> Result<FederationConfig<AppHandle>, AppError> { + let user = LocalUser::new("sellershut")?; + let domain = "localhost"; + + let config = FederationConfig::builder() + .domain(domain) + .signed_fetch_actor(&user) + .app_data(AppHandle(Arc::new(Self { + users: RwLock::new(vec![user]), + }))) + // .url_verifier(Box::new(MyUrlVerifier())) + // TODO: could change this to env variable? + .debug(cfg!(debug_assertions)) + .build() + .await?; + + Ok(config) + } +} |