use std::{ops::Deref, sync::Arc}; use activitypub_federation::config::FederationConfig; use tokio::sync::RwLock; use crate::{entity::user::User, error::AppError}; #[derive(Clone)] pub struct AppHandle(Arc); impl Deref for AppHandle { type Target = Arc; fn deref(&self) -> &Self::Target { &self.0 } } pub struct AppState { pub users: RwLock>, } impl AppState { pub async fn new() -> Result, AppError> { let user = User::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) } }