diff --git a/crates/application/src/use_cases/federation_management/mod.rs b/crates/application/src/use_cases/federation_management/mod.rs index 3d04d66..6ba7140 100644 --- a/crates/application/src/use_cases/federation_management/mod.rs +++ b/crates/application/src/use_cases/federation_management/mod.rs @@ -1,6 +1,7 @@ use activitypub::ActivityPubRepository; use domain::{ errors::DomainError, + events::DomainEvent, models::{ actor_connection_summary::ActorConnectionSummary, feed::{FeedEntry, PageParams, Paginated}, @@ -25,18 +26,38 @@ pub async fn list_pending_requests( pub async fn accept_follow_request( federation: &dyn FederationFollowRequestPort, + events: &dyn EventPublisher, user_id: &UserId, actor_url: &str, ) -> Result<(), DomainError> { - federation.accept_follow_request(user_id, actor_url).await + federation + .mark_follower_accepted(user_id, actor_url) + .await?; + events + .publish(&DomainEvent::RemoteFollowAccepted { + local_user_id: user_id.clone(), + remote_actor_url: actor_url.to_string(), + }) + .await + .map_err(|e| DomainError::Internal(e.to_string())) } pub async fn reject_follow_request( federation: &dyn FederationFollowRequestPort, + events: &dyn EventPublisher, user_id: &UserId, actor_url: &str, ) -> Result<(), DomainError> { - federation.reject_follow_request(user_id, actor_url).await + federation + .mark_follower_rejected(user_id, actor_url) + .await?; + events + .publish(&DomainEvent::RemoteFollowRejected { + local_user_id: user_id.clone(), + remote_actor_url: actor_url.to_string(), + }) + .await + .map_err(|e| DomainError::Internal(e.to_string())) } pub async fn list_remote_followers( diff --git a/crates/presentation/src/handlers/federation_management.rs b/crates/presentation/src/handlers/federation_management.rs index 9189d05..843b9ad 100644 --- a/crates/presentation/src/handlers/federation_management.rs +++ b/crates/presentation/src/handlers/federation_management.rs @@ -67,7 +67,7 @@ pub async fn post_accept_request( AuthUser(uid): AuthUser, Json(body): Json, ) -> Result { - accept_follow_request(&*d.federation, &uid, &body.actor_url).await?; + accept_follow_request(&*d.federation, &*d.events, &uid, &body.actor_url).await?; Ok(StatusCode::NO_CONTENT) } @@ -76,7 +76,7 @@ pub async fn delete_follower( AuthUser(uid): AuthUser, Json(body): Json, ) -> Result { - reject_follow_request(&*d.federation, &uid, &body.actor_url).await?; + reject_follow_request(&*d.federation, &*d.events, &uid, &body.actor_url).await?; Ok(StatusCode::NO_CONTENT) } @@ -118,12 +118,15 @@ pub async fn post_move_account( AuthUser(uid): AuthUser, Json(body): Json, ) -> Result { - let new_url = url::Url::parse(&body.new_actor_url) + url::Url::parse(&body.new_actor_url) .map_err(|_| ApiError::BadRequest("invalid new_actor_url".into()))?; - d.federation - .broadcast_move(&uid, new_url) + d.events + .publish(&domain::events::DomainEvent::ActorMoved { + user_id: uid, + new_actor_url: body.new_actor_url, + }) .await - .map_err(ApiError::from)?; + .map_err(|e| ApiError::Domain(domain::errors::DomainError::Internal(e.to_string())))?; Ok(StatusCode::NO_CONTENT) }