From a08bb3d698d825c8588b307b2a94fcc7dc2869e5 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Thu, 14 May 2026 20:03:49 +0200 Subject: [PATCH] feat(bootstrap): wire ActivityPubService as FederationActionPort in AppState --- crates/bootstrap/src/factory.rs | 41 +++++++++++++++++--------------- crates/bootstrap/src/main.rs | 2 +- crates/presentation/src/state.rs | 1 + 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/crates/bootstrap/src/factory.rs b/crates/bootstrap/src/factory.rs index dd85510..7624935 100644 --- a/crates/bootstrap/src/factory.rs +++ b/crates/bootstrap/src/factory.rs @@ -3,7 +3,7 @@ use sqlx::PgPool; use std::sync::Arc; use activitypub::ThoughtsObjectHandler; -use activitypub_base::{ApFederationConfig, FederationData}; +use activitypub_base::service::ActivityPubService; use domain::{errors::DomainError, events::DomainEvent, ports::EventPublisher}; use event_transport::EventPublisherAdapter; use nats::NatsTransport; @@ -16,7 +16,7 @@ use crate::config::Config; /// Everything the binary needs to start serving. pub struct Infrastructure { pub state: AppState, - pub fed_config: ApFederationConfig, + pub ap_service: Arc, } struct NoOpEventPublisher; @@ -61,24 +61,26 @@ pub async fn build(cfg: &Config) -> Infrastructure { }; // 3. ActivityPub federation - let fed_data = FederationData::new( - Arc::new(PostgresFederationRepository::new(pool.clone())), - Arc::new(PostgresApUserRepository::new( - pool.clone(), + let ap_service = Arc::new( + ActivityPubService::new( + Arc::new(PostgresFederationRepository::new(pool.clone())), + Arc::new(PostgresApUserRepository::new( + pool.clone(), + cfg.base_url.clone(), + )), + Arc::new(ThoughtsObjectHandler::new( + Arc::new(PgActivityPubRepository::new(pool.clone())), + &cfg.base_url, + )), cfg.base_url.clone(), - )), - Arc::new(ThoughtsObjectHandler::new( - Arc::new(PgActivityPubRepository::new(pool.clone())), - &cfg.base_url, - )), - cfg.base_url.clone(), - cfg.allow_registration, - "thoughts".to_string(), - None, - ); - let fed_config = ApFederationConfig::new(fed_data, cfg.debug) + cfg.allow_registration, + "thoughts".to_string(), + cfg.debug, + None, + ) .await - .expect("Failed to build federation config"); + .expect("Failed to build ActivityPubService"), + ); // 4. Application state let state = AppState { @@ -107,7 +109,8 @@ pub async fn build(cfg: &Config) -> Infrastructure { )), hasher: Arc::new(auth::Argon2PasswordHasher), events: event_publisher, + federation: ap_service.clone() as Arc, }; - Infrastructure { state, fed_config } + Infrastructure { state, ap_service } } diff --git a/crates/bootstrap/src/main.rs b/crates/bootstrap/src/main.rs index a1d9ae1..50bce03 100644 --- a/crates/bootstrap/src/main.rs +++ b/crates/bootstrap/src/main.rs @@ -67,7 +67,7 @@ async fn main() { "/users/{username}/following", axum::routing::get(following_handler), ) - .layer(infra.fed_config.middleware()); + .layer(infra.ap_service.federation_config().middleware()); let base = presentation::routes::router() .merge(ap_router) diff --git a/crates/presentation/src/state.rs b/crates/presentation/src/state.rs index c6a8c59..7dcd1ef 100644 --- a/crates/presentation/src/state.rs +++ b/crates/presentation/src/state.rs @@ -19,4 +19,5 @@ pub struct AppState { pub auth: Arc, pub hasher: Arc, pub events: Arc, + pub federation: Arc, }