feat(bootstrap): wire ActivityPubService as FederationActionPort in AppState

This commit is contained in:
2026-05-14 20:03:49 +02:00
parent 1d50b54227
commit a08bb3d698
3 changed files with 24 additions and 20 deletions

View File

@@ -3,7 +3,7 @@ use sqlx::PgPool;
use std::sync::Arc; use std::sync::Arc;
use activitypub::ThoughtsObjectHandler; use activitypub::ThoughtsObjectHandler;
use activitypub_base::{ApFederationConfig, FederationData}; use activitypub_base::service::ActivityPubService;
use domain::{errors::DomainError, events::DomainEvent, ports::EventPublisher}; use domain::{errors::DomainError, events::DomainEvent, ports::EventPublisher};
use event_transport::EventPublisherAdapter; use event_transport::EventPublisherAdapter;
use nats::NatsTransport; use nats::NatsTransport;
@@ -16,7 +16,7 @@ use crate::config::Config;
/// Everything the binary needs to start serving. /// Everything the binary needs to start serving.
pub struct Infrastructure { pub struct Infrastructure {
pub state: AppState, pub state: AppState,
pub fed_config: ApFederationConfig, pub ap_service: Arc<ActivityPubService>,
} }
struct NoOpEventPublisher; struct NoOpEventPublisher;
@@ -61,7 +61,8 @@ pub async fn build(cfg: &Config) -> Infrastructure {
}; };
// 3. ActivityPub federation // 3. ActivityPub federation
let fed_data = FederationData::new( let ap_service = Arc::new(
ActivityPubService::new(
Arc::new(PostgresFederationRepository::new(pool.clone())), Arc::new(PostgresFederationRepository::new(pool.clone())),
Arc::new(PostgresApUserRepository::new( Arc::new(PostgresApUserRepository::new(
pool.clone(), pool.clone(),
@@ -74,11 +75,12 @@ pub async fn build(cfg: &Config) -> Infrastructure {
cfg.base_url.clone(), cfg.base_url.clone(),
cfg.allow_registration, cfg.allow_registration,
"thoughts".to_string(), "thoughts".to_string(),
cfg.debug,
None, None,
); )
let fed_config = ApFederationConfig::new(fed_data, cfg.debug)
.await .await
.expect("Failed to build federation config"); .expect("Failed to build ActivityPubService"),
);
// 4. Application state // 4. Application state
let state = AppState { let state = AppState {
@@ -107,7 +109,8 @@ pub async fn build(cfg: &Config) -> Infrastructure {
)), )),
hasher: Arc::new(auth::Argon2PasswordHasher), hasher: Arc::new(auth::Argon2PasswordHasher),
events: event_publisher, events: event_publisher,
federation: ap_service.clone() as Arc<dyn domain::ports::FederationActionPort>,
}; };
Infrastructure { state, fed_config } Infrastructure { state, ap_service }
} }

View File

@@ -67,7 +67,7 @@ async fn main() {
"/users/{username}/following", "/users/{username}/following",
axum::routing::get(following_handler), axum::routing::get(following_handler),
) )
.layer(infra.fed_config.middleware()); .layer(infra.ap_service.federation_config().middleware());
let base = presentation::routes::router() let base = presentation::routes::router()
.merge(ap_router) .merge(ap_router)

View File

@@ -19,4 +19,5 @@ pub struct AppState {
pub auth: Arc<dyn AuthService>, pub auth: Arc<dyn AuthService>,
pub hasher: Arc<dyn PasswordHasher>, pub hasher: Arc<dyn PasswordHasher>,
pub events: Arc<dyn EventPublisher>, pub events: Arc<dyn EventPublisher>,
pub federation: Arc<dyn FederationActionPort>,
} }