feat(application): add FederationManagementEventService

This commit is contained in:
2026-05-28 02:28:15 +02:00
parent 9c93baaa39
commit 0dce4fbe64
2 changed files with 58 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
use domain::{errors::DomainError, events::DomainEvent, ports::FederationActionPort};
use std::sync::Arc;
pub struct FederationManagementEventService {
pub federation: Arc<dyn FederationActionPort>,
}
impl FederationManagementEventService {
pub async fn process(&self, event: &DomainEvent) -> Result<(), DomainError> {
match event {
DomainEvent::RemoteFollowAccepted {
local_user_id,
remote_actor_url,
} => {
tracing::info!(
local_user_id = %local_user_id,
actor = %remote_actor_url,
"federation-mgmt: accepting follow — sending Accept + backfill"
);
self.federation
.accept_follow_request(local_user_id, remote_actor_url)
.await
}
DomainEvent::RemoteFollowRejected {
local_user_id,
remote_actor_url,
} => {
tracing::info!(
local_user_id = %local_user_id,
actor = %remote_actor_url,
"federation-mgmt: rejecting follow — sending Reject"
);
self.federation
.reject_follow_request(local_user_id, remote_actor_url)
.await
}
DomainEvent::ActorMoved {
user_id,
new_actor_url,
} => {
tracing::info!(
user_id = %user_id,
target = %new_actor_url,
"federation-mgmt: broadcasting Move"
);
let url = url::Url::parse(new_actor_url)
.map_err(|e| DomainError::Internal(e.to_string()))?;
self.federation
.broadcast_move(user_id, url)
.await
.map_err(|e| DomainError::Internal(e.to_string()))
}
_ => Ok(()),
}
}
}

View File

@@ -1,5 +1,7 @@
pub mod federation_event; pub mod federation_event;
pub mod federation_management_event;
pub mod notification_event; pub mod notification_event;
pub use federation_event::FederationEventService; pub use federation_event::FederationEventService;
pub use federation_management_event::FederationManagementEventService;
pub use notification_event::NotificationEventService; pub use notification_event::NotificationEventService;