feat(domain): FederationActionPort trait + avatar_url on RemoteActor

This commit is contained in:
2026-05-14 19:55:10 +02:00
parent 8eb59bfac6
commit 82f8772104
6 changed files with 54 additions and 1 deletions

View File

@@ -12,6 +12,8 @@ pub enum DomainError {
Conflict(String),
#[error("invalid input: {0}")]
InvalidInput(String),
#[error("external service error: {0}")]
ExternalService(String),
#[error("internal error: {0}")]
Internal(String),
}

View File

@@ -8,5 +8,6 @@ pub struct RemoteActor {
pub inbox_url: String,
pub shared_inbox_url: Option<String>,
pub public_key: String,
pub avatar_url: Option<String>,
pub last_fetched_at: DateTime<Utc>,
}

View File

@@ -194,6 +194,12 @@ pub trait RemoteActorRepository: Send + Sync {
async fn find_by_url(&self, url: &str) -> Result<Option<RemoteActor>, DomainError>;
}
#[async_trait]
pub trait FederationActionPort: Send + Sync {
async fn lookup_actor(&self, handle: &str) -> Result<RemoteActor, DomainError>;
async fn follow_remote(&self, local_user_id: &UserId, handle: &str) -> Result<(), DomainError>;
}
#[async_trait]
pub trait FeedRepository: Send + Sync {
async fn home_feed(

View File

@@ -534,6 +534,21 @@ impl RemoteActorRepository for TestStore {
}
}
#[async_trait]
impl FederationActionPort for TestStore {
async fn lookup_actor(&self, _handle: &str) -> Result<RemoteActor, DomainError> {
Err(DomainError::NotFound)
}
async fn follow_remote(
&self,
_local_user_id: &UserId,
_handle: &str,
) -> Result<(), DomainError> {
Ok(())
}
}
#[async_trait]
impl FeedRepository for TestStore {
async fn home_feed(
@@ -767,6 +782,32 @@ mod ap_repo_tests {
}
}
#[cfg(test)]
mod federation_port_tests {
use super::*;
use crate::value_objects::UserId;
fn uid() -> UserId {
UserId::new()
}
#[tokio::test]
async fn test_store_lookup_returns_not_found() {
let store = TestStore::default();
let err = store.lookup_actor("@alice@example.com").await.unwrap_err();
assert!(matches!(err, DomainError::NotFound));
}
#[tokio::test]
async fn test_store_follow_remote_is_noop_ok() {
let store = TestStore::default();
store
.follow_remote(&uid(), "@alice@example.com")
.await
.unwrap();
}
}
#[cfg(test)]
mod search_tests {
use super::*;