feat: split accept/reject into DB+event; broadcast_move via event in API
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
use activitypub::ActivityPubRepository;
|
use activitypub::ActivityPubRepository;
|
||||||
use domain::{
|
use domain::{
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
|
events::DomainEvent,
|
||||||
models::{
|
models::{
|
||||||
actor_connection_summary::ActorConnectionSummary,
|
actor_connection_summary::ActorConnectionSummary,
|
||||||
feed::{FeedEntry, PageParams, Paginated},
|
feed::{FeedEntry, PageParams, Paginated},
|
||||||
@@ -25,18 +26,38 @@ pub async fn list_pending_requests(
|
|||||||
|
|
||||||
pub async fn accept_follow_request(
|
pub async fn accept_follow_request(
|
||||||
federation: &dyn FederationFollowRequestPort,
|
federation: &dyn FederationFollowRequestPort,
|
||||||
|
events: &dyn EventPublisher,
|
||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
actor_url: &str,
|
actor_url: &str,
|
||||||
) -> Result<(), DomainError> {
|
) -> 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(
|
pub async fn reject_follow_request(
|
||||||
federation: &dyn FederationFollowRequestPort,
|
federation: &dyn FederationFollowRequestPort,
|
||||||
|
events: &dyn EventPublisher,
|
||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
actor_url: &str,
|
actor_url: &str,
|
||||||
) -> Result<(), DomainError> {
|
) -> 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(
|
pub async fn list_remote_followers(
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ pub async fn post_accept_request(
|
|||||||
AuthUser(uid): AuthUser,
|
AuthUser(uid): AuthUser,
|
||||||
Json(body): Json<ActorUrlBody>,
|
Json(body): Json<ActorUrlBody>,
|
||||||
) -> Result<StatusCode, ApiError> {
|
) -> 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)
|
Ok(StatusCode::NO_CONTENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ pub async fn delete_follower(
|
|||||||
AuthUser(uid): AuthUser,
|
AuthUser(uid): AuthUser,
|
||||||
Json(body): Json<ActorUrlBody>,
|
Json(body): Json<ActorUrlBody>,
|
||||||
) -> Result<StatusCode, ApiError> {
|
) -> 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)
|
Ok(StatusCode::NO_CONTENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,12 +118,15 @@ pub async fn post_move_account(
|
|||||||
AuthUser(uid): AuthUser,
|
AuthUser(uid): AuthUser,
|
||||||
Json(body): Json<MoveBody>,
|
Json(body): Json<MoveBody>,
|
||||||
) -> Result<StatusCode, ApiError> {
|
) -> 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()))?;
|
.map_err(|_| ApiError::BadRequest("invalid new_actor_url".into()))?;
|
||||||
d.federation
|
d.events
|
||||||
.broadcast_move(&uid, new_url)
|
.publish(&domain::events::DomainEvent::ActorMoved {
|
||||||
|
user_id: uid,
|
||||||
|
new_actor_url: body.new_actor_url,
|
||||||
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(ApiError::from)?;
|
.map_err(|e| ApiError::Domain(domain::errors::DomainError::Internal(e.to_string())))?;
|
||||||
Ok(StatusCode::NO_CONTENT)
|
Ok(StatusCode::NO_CONTENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user