refactor: delegate mark_follower_accepted/rejected through k-ap service, remove federation_repo from ApFederationAdapter

This commit is contained in:
2026-05-28 02:45:59 +02:00
parent af5c4481b6
commit d68c628335
8 changed files with 14 additions and 24 deletions

6
Cargo.lock generated
View File

@@ -2015,8 +2015,8 @@ dependencies = [
[[package]] [[package]]
name = "k-ap" name = "k-ap"
version = "0.1.9" version = "0.1.10"
source = "git+https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git?tag=v0.1.9#432f39cbb4f8d74255a1f614a9bb7c8bbfe11cde" source = "git+https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git?tag=v0.1.10#d80cfd0431205498161db8665fd884710866ca95"
dependencies = [ dependencies = [
"activitypub_federation", "activitypub_federation",
"anyhow", "anyhow",
@@ -4566,7 +4566,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [ dependencies = [
"windows-sys 0.61.2", "windows-sys 0.48.0",
] ]
[[package]] [[package]]

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.9" } k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.10" }
domain = { workspace = true } domain = { workspace = true }
url = { workspace = true } url = { workspace = true }
serde = { workspace = true } serde = { workspace = true }

View File

@@ -209,19 +209,16 @@ async fn webfinger_resolve_actor_url(handle: &str) -> anyhow::Result<String> {
pub struct ApFederationAdapter { pub struct ApFederationAdapter {
pub(crate) inner: Arc<ActivityPubService>, pub(crate) inner: Arc<ActivityPubService>,
pub(crate) connections_repo: Arc<dyn RemoteActorConnectionRepository>, pub(crate) connections_repo: Arc<dyn RemoteActorConnectionRepository>,
pub(crate) federation_repo: Arc<dyn k_ap::FederationRepository>,
} }
impl ApFederationAdapter { impl ApFederationAdapter {
pub fn new( pub fn new(
inner: Arc<ActivityPubService>, inner: Arc<ActivityPubService>,
connections_repo: Arc<dyn RemoteActorConnectionRepository>, connections_repo: Arc<dyn RemoteActorConnectionRepository>,
federation_repo: Arc<dyn k_ap::FederationRepository>,
) -> Self { ) -> Self {
Self { Self {
inner, inner,
connections_repo, connections_repo,
federation_repo,
} }
} }
@@ -816,8 +813,8 @@ impl FederationFollowRequestPort for ApFederationAdapter {
user_id: &UserId, user_id: &UserId,
actor_url: &str, actor_url: &str,
) -> Result<(), DomainError> { ) -> Result<(), DomainError> {
self.federation_repo self.inner
.update_follower_status(user_id.as_uuid(), actor_url, k_ap::FollowerStatus::Accepted) .mark_follower_accepted(user_id.as_uuid(), actor_url)
.await .await
.map_err(|e| DomainError::Internal(e.to_string())) .map_err(|e| DomainError::Internal(e.to_string()))
} }
@@ -827,8 +824,8 @@ impl FederationFollowRequestPort for ApFederationAdapter {
user_id: &UserId, user_id: &UserId,
actor_url: &str, actor_url: &str,
) -> Result<(), DomainError> { ) -> Result<(), DomainError> {
self.federation_repo self.inner
.remove_follower(user_id.as_uuid(), actor_url) .mark_follower_rejected(user_id.as_uuid(), actor_url)
.await .await
.map_err(|e| DomainError::Internal(e.to_string())) .map_err(|e| DomainError::Internal(e.to_string()))
} }

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.9" } k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.10" }
sqlx = { workspace = true } sqlx = { workspace = true }
uuid = { workspace = true } uuid = { workspace = true }
chrono = { workspace = true } chrono = { workspace = true }

View File

@@ -14,7 +14,7 @@ postgres = { workspace = true }
postgres-search = { workspace = true } postgres-search = { workspace = true }
postgres-federation = { workspace = true } postgres-federation = { workspace = true }
activitypub = { workspace = true } activitypub = { workspace = true }
k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.9" } k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.10" }
nats = { workspace = true } nats = { workspace = true }
event-transport = { workspace = true } event-transport = { workspace = true }
auth = { workspace = true } auth = { workspace = true }

View File

@@ -76,10 +76,9 @@ pub async fn build(cfg: &Config) -> Infrastructure {
// 3. ActivityPub federation // 3. ActivityPub federation
let connections_repo = Arc::new(PgRemoteActorConnectionRepository::new(pool.clone())); let connections_repo = Arc::new(PgRemoteActorConnectionRepository::new(pool.clone()));
let federation_repo = Arc::new(PostgresFederationRepository::new(pool.clone()));
let raw_ap_service = Arc::new( let raw_ap_service = Arc::new(
ActivityPubService::builder( ActivityPubService::builder(
federation_repo.clone(), Arc::new(PostgresFederationRepository::new(pool.clone())),
Arc::new(PostgresApUserRepository::new( Arc::new(PostgresApUserRepository::new(
pool.clone(), pool.clone(),
cfg.base_url.clone(), cfg.base_url.clone(),
@@ -99,11 +98,7 @@ pub async fn build(cfg: &Config) -> Infrastructure {
.await .await
.expect("Failed to build ActivityPubService"), .expect("Failed to build ActivityPubService"),
); );
let ap_service = Arc::new(ApFederationAdapter::new( let ap_service = Arc::new(ApFederationAdapter::new(raw_ap_service, connections_repo));
raw_ap_service,
connections_repo,
federation_repo,
));
// 4. Storage adapter // 4. Storage adapter
let storage_cfg = StorageConfig { let storage_cfg = StorageConfig {

View File

@@ -13,7 +13,7 @@ application = { workspace = true }
nats = { workspace = true } nats = { workspace = true }
event-transport = { workspace = true } event-transport = { workspace = true }
event-payload = { workspace = true } event-payload = { workspace = true }
k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.9" } k-ap = { git = "https://git.gabrielkaszewski.dev/GKaszewski/k-ap.git", tag = "v0.1.10" }
activitypub = { workspace = true } activitypub = { workspace = true }
postgres = { workspace = true } postgres = { workspace = true }
postgres-federation = { workspace = true } postgres-federation = { workspace = true }

View File

@@ -43,10 +43,9 @@ pub async fn build(database_url: &str, base_url: &str, nats_url: &str) -> Worker
// ActivityPub service (for federation fan-out) // ActivityPub service (for federation fan-out)
let connections_repo_worker = Arc::new(PgRemoteActorConnectionRepository::new(pool.clone())); let connections_repo_worker = Arc::new(PgRemoteActorConnectionRepository::new(pool.clone()));
let federation_repo_worker = Arc::new(PostgresFederationRepository::new(pool.clone()));
let raw_ap_service = Arc::new( let raw_ap_service = Arc::new(
ActivityPubService::builder( ActivityPubService::builder(
federation_repo_worker.clone(), Arc::new(PostgresFederationRepository::new(pool.clone())),
Arc::new(PostgresApUserRepository::new( Arc::new(PostgresApUserRepository::new(
pool.clone(), pool.clone(),
base_url.to_string(), base_url.to_string(),
@@ -67,7 +66,6 @@ pub async fn build(database_url: &str, base_url: &str, nats_url: &str) -> Worker
let ap_service = Arc::new(ApFederationAdapter::new( let ap_service = Arc::new(ApFederationAdapter::new(
raw_ap_service, raw_ap_service,
connections_repo_worker, connections_repo_worker,
federation_repo_worker,
)); ));
let ap_outbound = ap_service.clone() as Arc<dyn OutboundFederationPort>; let ap_outbound = ap_service.clone() as Arc<dyn OutboundFederationPort>;
let ap_repo_worker = let ap_repo_worker =