summaryrefslogtreecommitdiffstats
path: root/src/state.rs
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2025-07-12 15:57:19 +0200
committerrtkay123 <dev@kanjala.com>2025-07-12 15:57:19 +0200
commit487ac435d7b687f071a0ed173d918fac480992b3 (patch)
tree3dd870414508cc437a4b070ba93ace7d3e2df5ad /src/state.rs
parentba14505f39d8634921f260d715aa8e66f2a14406 (diff)
downloadsellershut-487ac435d7b687f071a0ed173d918fac480992b3.tar.bz2
sellershut-487ac435d7b687f071a0ed173d918fac480992b3.zip
feat: create user
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs45
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)
+ }
+}