From 487ac435d7b687f071a0ed173d918fac480992b3 Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Sat, 12 Jul 2025 15:57:19 +0200 Subject: feat: create user --- src/state.rs | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'src/state.rs') 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); + +impl Deref for AppHandle { + type Target = Arc; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +pub struct AppState { + users: RwLock>, +} + +impl AppState { + pub async fn new() -> Result, 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) + } +} -- cgit v1.2.3