From 28170c95d4881b9e01896c13d6c7700bc24ea16d Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Tue, 2 Jun 2026 20:44:08 +0200 Subject: [PATCH] chore: fmt + remove dead federation module --- crates/application/src/context.rs | 9 +-- .../src/diary/get_activity_feed.rs | 65 ++++++++--------- .../src/federation/get_remote_watchlist.rs | 10 --- crates/application/src/federation/mod.rs | 1 - crates/application/src/lib.rs | 2 - crates/application/src/test_helpers.rs | 11 +-- crates/application/src/users/get_profile.rs | 71 +++++++++---------- crates/application/src/users/get_users.rs | 6 -- crates/application/src/watchlist/get_page.rs | 19 ++--- crates/domain/src/testing.rs | 27 +++++++ crates/presentation/src/main.rs | 4 ++ crates/presentation/src/tests/extractors.rs | 2 - crates/presentation/tests/api_test.rs | 2 - crates/worker/src/main.rs | 4 ++ 14 files changed, 107 insertions(+), 126 deletions(-) delete mode 100644 crates/application/src/federation/get_remote_watchlist.rs delete mode 100644 crates/application/src/federation/mod.rs diff --git a/crates/application/src/context.rs b/crates/application/src/context.rs index 7dc4a51..670924f 100644 --- a/crates/application/src/context.rs +++ b/crates/application/src/context.rs @@ -4,11 +4,10 @@ use domain::ports::{ AuthService, DiaryExporter, DiaryRepository, DocumentParser, EventPublisher, ImageStorage, ImportProfileRepository, ImportSessionRepository, MetadataClient, MovieProfileRepository, MovieRepository, PasswordHasher, PersonCommand, PersonQuery, PosterFetcherClient, - ReviewRepository, SearchCommand, SearchPort, StatsRepository, UserProfileFieldsRepository, - UserRepository, WatchEventRepository, WatchlistRepository, WebhookTokenRepository, + RemoteWatchlistRepository, ReviewRepository, SearchCommand, SearchPort, SocialQueryPort, + StatsRepository, UserProfileFieldsRepository, UserRepository, WatchEventRepository, + WatchlistRepository, WebhookTokenRepository, }; -#[cfg(feature = "federation")] -use domain::ports::{RemoteWatchlistRepository, SocialQueryPort}; use crate::config::AppConfig; @@ -30,9 +29,7 @@ pub struct Repositories { pub search_port: Arc, pub search_command: Arc, pub profile_fields: Arc, - #[cfg(feature = "federation")] pub remote_watchlist: Arc, - #[cfg(feature = "federation")] pub social_query: Arc, } diff --git a/crates/application/src/diary/get_activity_feed.rs b/crates/application/src/diary/get_activity_feed.rs index e31f5f4..aaf351d 100644 --- a/crates/application/src/diary/get_activity_feed.rs +++ b/crates/application/src/diary/get_activity_feed.rs @@ -28,44 +28,39 @@ pub async fn execute( } async fn build_following_filter( - _ctx: &AppContext, + ctx: &AppContext, query: &GetActivityFeedQuery, ) -> Option { - #[cfg(not(feature = "federation"))] - { - let _ = query; + if !query.filter_following { return None; } - #[cfg(feature = "federation")] - { - if !query.filter_following { - return None; - } - let viewer_id = match query.viewer_user_id { - Some(id) => id, - None => return None, - }; - let urls = _ctx - .repos - .social_query - .get_accepted_following_urls(viewer_id) - .await - .unwrap_or_default(); - let base_url = &_ctx.config.base_url; - let mut local_ids = vec![viewer_id]; - let mut remote_urls = Vec::new(); - for url in urls { - if let Some(suffix) = url.strip_prefix(&format!("{}/users/", base_url)) - && let Ok(parsed_id) = uuid::Uuid::parse_str(suffix) - { - local_ids.push(parsed_id); - continue; - } - remote_urls.push(url); - } - Some(FollowingFilter { - local_user_ids: local_ids, - remote_actor_urls: remote_urls, - }) + let viewer_id = query.viewer_user_id?; + let urls = ctx + .repos + .social_query + .get_accepted_following_urls(viewer_id) + .await + .unwrap_or_default(); + if urls.is_empty() { + return Some(FollowingFilter { + local_user_ids: vec![viewer_id], + remote_actor_urls: vec![], + }); } + let base_url = &ctx.config.base_url; + let mut local_ids = vec![viewer_id]; + let mut remote_urls = Vec::new(); + for url in urls { + if let Some(suffix) = url.strip_prefix(&format!("{}/users/", base_url)) + && let Ok(parsed_id) = uuid::Uuid::parse_str(suffix) + { + local_ids.push(parsed_id); + continue; + } + remote_urls.push(url); + } + Some(FollowingFilter { + local_user_ids: local_ids, + remote_actor_urls: remote_urls, + }) } diff --git a/crates/application/src/federation/get_remote_watchlist.rs b/crates/application/src/federation/get_remote_watchlist.rs deleted file mode 100644 index 4e2f097..0000000 --- a/crates/application/src/federation/get_remote_watchlist.rs +++ /dev/null @@ -1,10 +0,0 @@ -use domain::{errors::DomainError, models::RemoteWatchlistEntry}; - -use crate::context::AppContext; - -pub async fn execute( - ctx: &AppContext, - uuid: uuid::Uuid, -) -> Result, DomainError> { - ctx.repos.remote_watchlist.get_by_derived_uuid(uuid).await -} diff --git a/crates/application/src/federation/mod.rs b/crates/application/src/federation/mod.rs deleted file mode 100644 index c53ea6f..0000000 --- a/crates/application/src/federation/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod get_remote_watchlist; diff --git a/crates/application/src/lib.rs b/crates/application/src/lib.rs index 027a117..674058e 100644 --- a/crates/application/src/lib.rs +++ b/crates/application/src/lib.rs @@ -6,8 +6,6 @@ pub mod worker; pub mod auth; pub mod diary; -#[cfg(feature = "federation")] -pub mod federation; pub mod import; pub mod integrations; pub mod movies; diff --git a/crates/application/src/test_helpers.rs b/crates/application/src/test_helpers.rs index 9ad8a8e..ac46aa1 100644 --- a/crates/application/src/test_helpers.rs +++ b/crates/application/src/test_helpers.rs @@ -1,9 +1,6 @@ use std::sync::Arc; -#[cfg(feature = "federation")] -use domain::testing::PanicRemoteWatchlistRepository; -#[cfg(feature = "federation")] -use domain::testing::PanicSocialQueryPort; +use domain::testing::{NoopRemoteWatchlistRepository, NoopSocialQueryPort}; use domain::{ ports::{ AuthService, DiaryExporter, DiaryRepository, DocumentParser, EventPublisher, ImageStorage, @@ -145,10 +142,8 @@ impl TestContextBuilder { person_query: self.person_query, search_port: self.search_port, search_command: self.search_command, - #[cfg(feature = "federation")] - remote_watchlist: Arc::new(PanicRemoteWatchlistRepository), - #[cfg(feature = "federation")] - social_query: Arc::new(PanicSocialQueryPort), + remote_watchlist: Arc::new(NoopRemoteWatchlistRepository), + social_query: Arc::new(NoopSocialQueryPort), }, services: Services { auth: self.auth_service, diff --git a/crates/application/src/users/get_profile.rs b/crates/application/src/users/get_profile.rs index e6e9e8e..cb12b4a 100644 --- a/crates/application/src/users/get_profile.rs +++ b/crates/application/src/users/get_profile.rs @@ -76,47 +76,40 @@ pub async fn execute( } async fn load_social_counts( - _ctx: &AppContext, - _user_id: uuid::Uuid, - _is_own_profile: bool, + ctx: &AppContext, + user_id: uuid::Uuid, + is_own_profile: bool, ) -> (usize, usize, Vec) { - #[cfg(not(feature = "federation"))] - { - (0, 0, vec![]) - } - #[cfg(feature = "federation")] - { - if !_is_own_profile { - return (0, 0, vec![]); - } - let following = _ctx - .repos - .social_query - .count_following(_user_id) - .await - .unwrap_or(0); - let followers = _ctx - .repos - .social_query - .count_accepted_followers(_user_id) - .await - .unwrap_or(0); - let pending = _ctx - .repos - .social_query - .get_pending_followers(_user_id) - .await - .unwrap_or_default() - .into_iter() - .map(|p| PendingFollowerView { - url: p.url, - handle: p.handle, - display_name: p.display_name, - avatar_url: p.avatar_url, - }) - .collect(); - (following, followers, pending) + if !is_own_profile { + return (0, 0, vec![]); } + let following = ctx + .repos + .social_query + .count_following(user_id) + .await + .unwrap_or(0); + let followers = ctx + .repos + .social_query + .count_accepted_followers(user_id) + .await + .unwrap_or(0); + let pending = ctx + .repos + .social_query + .get_pending_followers(user_id) + .await + .unwrap_or_default() + .into_iter() + .map(|p| PendingFollowerView { + url: p.url, + handle: p.handle, + display_name: p.display_name, + avatar_url: p.avatar_url, + }) + .collect(); + (following, followers, pending) } fn feed_sort_to_direction(sort_by: FeedSortBy) -> SortDirection { diff --git a/crates/application/src/users/get_users.rs b/crates/application/src/users/get_users.rs index 405da44..616faa6 100644 --- a/crates/application/src/users/get_users.rs +++ b/crates/application/src/users/get_users.rs @@ -10,16 +10,10 @@ pub async fn execute( ctx: &AppContext, _query: GetUsersQuery, ) -> Result { - #[cfg(feature = "federation")] let (users_result, actors_result) = tokio::join!( ctx.repos.user.list_with_stats(), ctx.repos.social_query.list_all_followed_remote_actors() ); - #[cfg(not(feature = "federation"))] - let (users_result, actors_result) = ( - ctx.repos.user.list_with_stats().await, - Ok::, DomainError>(vec![]), - ); Ok(UsersListData { users: users_result?, diff --git a/crates/application/src/watchlist/get_page.rs b/crates/application/src/watchlist/get_page.rs index b759357..9b103de 100644 --- a/crates/application/src/watchlist/get_page.rs +++ b/crates/application/src/watchlist/get_page.rs @@ -55,25 +55,14 @@ pub async fn execute( } } -#[cfg(not(feature = "federation"))] -async fn load_remote_watchlist( - _ctx: &AppContext, - _user_id: uuid::Uuid, -) -> Result { - Ok(WatchlistPageResult { - display_entries: vec![], - has_more: false, - current_offset: 0, - limit: 0, - }) -} - -#[cfg(feature = "federation")] async fn load_remote_watchlist( ctx: &AppContext, user_id: uuid::Uuid, ) -> Result { - let remote_entries = crate::federation::get_remote_watchlist::execute(ctx, user_id) + let remote_entries = ctx + .repos + .remote_watchlist + .get_by_derived_uuid(user_id) .await .unwrap_or_default(); let len = remote_entries.len() as u32; diff --git a/crates/domain/src/testing.rs b/crates/domain/src/testing.rs index 7137723..4a39e1b 100644 --- a/crates/domain/src/testing.rs +++ b/crates/domain/src/testing.rs @@ -800,6 +800,33 @@ impl crate::ports::RemoteWatchlistRepository for PanicRemoteWatchlistRepository } } +pub struct NoopRemoteWatchlistRepository; + +#[async_trait] +impl crate::ports::RemoteWatchlistRepository for NoopRemoteWatchlistRepository { + async fn save(&self, _: crate::models::RemoteWatchlistEntry) -> Result<(), DomainError> { + Ok(()) + } + async fn remove_by_ap_id(&self, _: &str, _: &str) -> Result<(), DomainError> { + Ok(()) + } + async fn get_by_actor_url( + &self, + _: &str, + ) -> Result, DomainError> { + Ok(vec![]) + } + async fn remove_all_by_actor(&self, _: &str) -> Result<(), DomainError> { + Ok(()) + } + async fn get_by_derived_uuid( + &self, + _: uuid::Uuid, + ) -> Result, DomainError> { + Ok(vec![]) + } +} + pub struct PanicProfileFieldsRepo; #[async_trait] diff --git a/crates/presentation/src/main.rs b/crates/presentation/src/main.rs index 1f1aca6..4462ced 100644 --- a/crates/presentation/src/main.rs +++ b/crates/presentation/src/main.rs @@ -187,8 +187,12 @@ async fn wire_dependencies() -> anyhow::Result<(AppState, axum::Router)> { profile_fields: db.profile_fields, #[cfg(feature = "federation")] remote_watchlist: remote_watchlist_repo, + #[cfg(not(feature = "federation"))] + remote_watchlist: Arc::new(domain::testing::NoopRemoteWatchlistRepository), #[cfg(feature = "federation")] social_query: social_query.clone(), + #[cfg(not(feature = "federation"))] + social_query: Arc::new(domain::testing::NoopSocialQueryPort), }, services: Services { auth: auth_service, diff --git a/crates/presentation/src/tests/extractors.rs b/crates/presentation/src/tests/extractors.rs index bcda303..ed2fc68 100644 --- a/crates/presentation/src/tests/extractors.rs +++ b/crates/presentation/src/tests/extractors.rs @@ -591,9 +591,7 @@ pub fn make_test_state(auth_service: Arc) -> crate::state::AppS person_query: Arc::clone(&repo) as _, search_port: Arc::clone(&repo) as _, search_command: Arc::clone(&repo) as _, - #[cfg(feature = "federation")] remote_watchlist: Arc::clone(&repo) as _, - #[cfg(feature = "federation")] social_query: Arc::clone(&repo) as _, }, services: Services { diff --git a/crates/presentation/tests/api_test.rs b/crates/presentation/tests/api_test.rs index 95ac848..40bc1ad 100644 --- a/crates/presentation/tests/api_test.rs +++ b/crates/presentation/tests/api_test.rs @@ -413,9 +413,7 @@ async fn test_app() -> Router { person_query: Arc::new(PanicPersonQuery), search_port: Arc::new(PanicSearchPort), search_command: Arc::new(PanicSearchCommand), - #[cfg(feature = "federation")] remote_watchlist: Arc::new(PanicRemoteWatchlist), - #[cfg(feature = "federation")] social_query: Arc::new(PanicSocialQuery), }, services: Services { diff --git a/crates/worker/src/main.rs b/crates/worker/src/main.rs index a27f62d..2675294 100644 --- a/crates/worker/src/main.rs +++ b/crates/worker/src/main.rs @@ -86,8 +86,12 @@ async fn main() -> anyhow::Result<()> { search_command: db.search_command, #[cfg(feature = "federation")] remote_watchlist: fed_remote_watchlist_repo.clone(), + #[cfg(not(feature = "federation"))] + remote_watchlist: Arc::new(domain::testing::NoopRemoteWatchlistRepository), #[cfg(feature = "federation")] social_query: fed_social_query, + #[cfg(not(feature = "federation"))] + social_query: Arc::new(domain::testing::NoopSocialQueryPort), }, services: Services { auth: auth_service,