feat: split accept/reject into DB+event; broadcast_move via event in API

This commit is contained in:
2026-05-28 02:32:50 +02:00
parent a06d09c101
commit 915163aac4
2 changed files with 32 additions and 8 deletions

View File

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

View File

@@ -67,7 +67,7 @@ pub async fn post_accept_request(
AuthUser(uid): AuthUser,
Json(body): Json<ActorUrlBody>,
) -> Result<StatusCode, ApiError> {
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<ActorUrlBody>,
) -> Result<StatusCode, ApiError> {
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<MoveBody>,
) -> Result<StatusCode, ApiError> {
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)
}