refactor(ports): CQRS split — FederationActionPort into four focused sub-ports
This commit is contained in:
@@ -1626,7 +1626,7 @@ impl domain::ports::FederationSchedulerPort for ActivityPubService {
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl domain::ports::FederationActionPort for ActivityPubService {
|
||||
impl domain::ports::FederationLookupPort for ActivityPubService {
|
||||
async fn lookup_actor(
|
||||
&self,
|
||||
handle: &str,
|
||||
@@ -1703,31 +1703,6 @@ impl domain::ports::FederationActionPort for ActivityPubService {
|
||||
})
|
||||
}
|
||||
|
||||
async fn follow_remote(
|
||||
&self,
|
||||
local_user_id: &domain::value_objects::UserId,
|
||||
handle: &str,
|
||||
) -> Result<(), domain::errors::DomainError> {
|
||||
self.follow(local_user_id.as_uuid(), handle)
|
||||
.await
|
||||
.map_err(|e| domain::errors::DomainError::ExternalService(e.to_string()))
|
||||
}
|
||||
|
||||
async fn unfollow_remote(
|
||||
&self,
|
||||
local_user_id: &domain::value_objects::UserId,
|
||||
handle: &str,
|
||||
) -> Result<(), domain::errors::DomainError> {
|
||||
let data = self.federation_config.to_request_data();
|
||||
let remote_actor: DbActor = Self::webfinger_https(handle, &data)
|
||||
.await
|
||||
.map_err(|e| domain::errors::DomainError::ExternalService(e.to_string()))?;
|
||||
let actor_url = remote_actor.ap_id.to_string();
|
||||
self.unfollow(local_user_id.as_uuid(), &actor_url)
|
||||
.await
|
||||
.map_err(|e| domain::errors::DomainError::ExternalService(e.to_string()))
|
||||
}
|
||||
|
||||
async fn actor_json(
|
||||
&self,
|
||||
user_id: &domain::value_objects::UserId,
|
||||
@@ -1832,7 +1807,10 @@ impl domain::ports::FederationActionPort for ActivityPubService {
|
||||
serde_json::to_string(&obj)
|
||||
.map_err(|e| domain::errors::DomainError::ExternalService(e.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl domain::ports::FederationFetchPort for ActivityPubService {
|
||||
async fn fetch_outbox_page(
|
||||
&self,
|
||||
outbox_url: &str,
|
||||
@@ -2026,7 +2004,48 @@ impl domain::ports::FederationActionPort for ActivityPubService {
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl domain::ports::FederationFollowPort for ActivityPubService {
|
||||
async fn follow_remote(
|
||||
&self,
|
||||
local_user_id: &domain::value_objects::UserId,
|
||||
handle: &str,
|
||||
) -> Result<(), domain::errors::DomainError> {
|
||||
self.follow(local_user_id.as_uuid(), handle)
|
||||
.await
|
||||
.map_err(|e| domain::errors::DomainError::ExternalService(e.to_string()))
|
||||
}
|
||||
|
||||
async fn unfollow_remote(
|
||||
&self,
|
||||
local_user_id: &domain::value_objects::UserId,
|
||||
handle: &str,
|
||||
) -> Result<(), domain::errors::DomainError> {
|
||||
let data = self.federation_config.to_request_data();
|
||||
let remote_actor: DbActor = Self::webfinger_https(handle, &data)
|
||||
.await
|
||||
.map_err(|e| domain::errors::DomainError::ExternalService(e.to_string()))?;
|
||||
let actor_url = remote_actor.ap_id.to_string();
|
||||
self.unfollow(local_user_id.as_uuid(), &actor_url)
|
||||
.await
|
||||
.map_err(|e| domain::errors::DomainError::ExternalService(e.to_string()))
|
||||
}
|
||||
|
||||
async fn get_remote_following(
|
||||
&self,
|
||||
user_id: &domain::value_objects::UserId,
|
||||
) -> Result<Vec<domain::models::remote_actor::RemoteActor>, domain::errors::DomainError> {
|
||||
self.get_following(user_id.as_uuid())
|
||||
.await
|
||||
.map(|v| v.into_iter().map(Self::adapter_actor_to_domain).collect())
|
||||
.map_err(|e| domain::errors::DomainError::ExternalService(e.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl domain::ports::FederationFollowRequestPort for ActivityPubService {
|
||||
async fn get_pending_followers(
|
||||
&self,
|
||||
user_id: &domain::value_objects::UserId,
|
||||
@@ -2076,16 +2095,6 @@ impl domain::ports::FederationActionPort for ActivityPubService {
|
||||
.await
|
||||
.map_err(|e| domain::errors::DomainError::ExternalService(e.to_string()))
|
||||
}
|
||||
|
||||
async fn get_remote_following(
|
||||
&self,
|
||||
user_id: &domain::value_objects::UserId,
|
||||
) -> Result<Vec<domain::models::remote_actor::RemoteActor>, domain::errors::DomainError> {
|
||||
self.get_following(user_id.as_uuid())
|
||||
.await
|
||||
.map(|v| v.into_iter().map(Self::adapter_actor_to_domain).collect())
|
||||
.map_err(|e| domain::errors::DomainError::ExternalService(e.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -1,10 +1,28 @@
|
||||
fn _assert_impl_federation_action_port()
|
||||
fn _assert_impl_federation_lookup_port()
|
||||
where
|
||||
crate::service::ActivityPubService: domain::ports::FederationActionPort,
|
||||
crate::service::ActivityPubService: domain::ports::FederationLookupPort,
|
||||
{
|
||||
}
|
||||
|
||||
fn _assert_impl_federation_action_port_connections()
|
||||
fn _assert_impl_federation_follow_port()
|
||||
where
|
||||
crate::service::ActivityPubService: domain::ports::FederationFollowPort,
|
||||
{
|
||||
}
|
||||
|
||||
fn _assert_impl_federation_follow_request_port()
|
||||
where
|
||||
crate::service::ActivityPubService: domain::ports::FederationFollowRequestPort,
|
||||
{
|
||||
}
|
||||
|
||||
fn _assert_impl_federation_fetch_port()
|
||||
where
|
||||
crate::service::ActivityPubService: domain::ports::FederationFetchPort,
|
||||
{
|
||||
}
|
||||
|
||||
fn _assert_impl_federation_action_port()
|
||||
where
|
||||
crate::service::ActivityPubService: domain::ports::FederationActionPort,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user