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 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<ActivityPubService>,
}
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<dyn domain::ports::FederationActionPort>,
};
Infrastructure { state, fed_config }
Infrastructure { state, ap_service }
}

View File

@@ -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)