refactor: replace long arg lists with input/config structs and builder

- Thought::new_local → NewThought struct (7 args → 1)
- UserWriter::update_profile → UpdateProfileInput struct (6 args → 2)
- update_profile use case → UpdateProfileInput (8 args → 3)
- ActivityPubService::new → builder pattern (9 args → 5 required + 4 optional setters)
- accept_note → AcceptNoteInput struct (8 args → 1)
- ThoughtNote::new_public → ThoughtNoteInput struct (8 args → 1)

Remove all #[allow(clippy::too_many_arguments)] annotations.
This commit is contained in:
2026-05-17 12:25:53 +02:00
parent 2f5c89c381
commit d56d34cc27
31 changed files with 449 additions and 450 deletions

View File

@@ -5,6 +5,17 @@ use domain::{
value_objects::{ThoughtId, UserId, Username},
};
pub struct AcceptNoteInput<'a> {
pub ap_id: &'a str,
pub author_id: &'a UserId,
pub content: &'a str,
pub published: chrono::DateTime<chrono::Utc>,
pub sensitive: bool,
pub content_warning: Option<String>,
pub visibility: &'a str,
pub in_reply_to: Option<&'a str>,
}
/// AP-protocol endpoints for a locally-stored user (local or interned remote).
#[derive(Debug, Clone)]
pub struct ActorApUrls {
@@ -61,18 +72,8 @@ pub trait ActivityPubRepository: Send + Sync {
// ── Inbox processing (remote → local) ───────────────────────────
/// Persist an incoming remote Note. Idempotent on ap_id.
#[allow(clippy::too_many_arguments)]
async fn accept_note(
&self,
ap_id: &str,
author_id: &UserId,
content: &str,
published: chrono::DateTime<chrono::Utc>,
sensitive: bool,
content_warning: Option<String>,
visibility: &str,
in_reply_to: Option<&str>,
) -> Result<ThoughtId, DomainError>;
async fn accept_note(&self, input: AcceptNoteInput<'_>) -> Result<ThoughtId, DomainError>;
/// Apply an Update to a previously accepted remote Note.
async fn apply_note_update(&self, ap_id: &str, new_content: &str) -> Result<(), DomainError>;

View File

@@ -18,7 +18,9 @@ pub mod user;
pub mod webfinger;
pub use activitypub_federation::kinds::object::NoteType;
pub use ap_ports::{ActivityPubRepository, ActorApUrls, OutboundFederationPort, OutboxEntry};
pub use ap_ports::{
AcceptNoteInput, ActivityPubRepository, ActorApUrls, OutboundFederationPort, OutboxEntry,
};
pub use content::ApObjectHandler;
pub use data::FederationData;
pub use error::Error;

View File

@@ -163,34 +163,73 @@ pub struct ActivityPubService {
connections_repo: Arc<dyn domain::ports::RemoteActorConnectionRepository>,
}
pub struct ActivityPubServiceBuilder {
repo: Arc<dyn FederationRepository>,
user_repo: Arc<dyn ApUserRepository>,
object_handler: Arc<dyn ApObjectHandler>,
base_url: String,
connections_repo: Arc<dyn domain::ports::RemoteActorConnectionRepository>,
allow_registration: bool,
software_name: String,
debug: bool,
event_publisher: Option<Arc<dyn domain::ports::EventPublisher>>,
}
impl ActivityPubServiceBuilder {
pub fn allow_registration(mut self, v: bool) -> Self {
self.allow_registration = v;
self
}
pub fn software_name(mut self, v: impl Into<String>) -> Self {
self.software_name = v.into();
self
}
pub fn debug(mut self, v: bool) -> Self {
self.debug = v;
self
}
pub fn event_publisher(mut self, v: Arc<dyn domain::ports::EventPublisher>) -> Self {
self.event_publisher = Some(v);
self
}
pub async fn build(self) -> anyhow::Result<ActivityPubService> {
let data = FederationData::new(
self.repo,
self.user_repo,
self.object_handler,
self.base_url.clone(),
self.allow_registration,
self.software_name,
self.event_publisher,
);
let federation_config = ApFederationConfig::new(data, self.debug).await?;
Ok(ActivityPubService {
federation_config,
base_url: self.base_url,
connections_repo: self.connections_repo,
})
}
}
impl ActivityPubService {
#[allow(clippy::too_many_arguments)]
pub async fn new(
pub fn builder(
repo: Arc<dyn FederationRepository>,
user_repo: Arc<dyn ApUserRepository>,
object_handler: Arc<dyn ApObjectHandler>,
base_url: String,
allow_registration: bool,
software_name: String,
debug: bool,
event_publisher: Option<Arc<dyn domain::ports::EventPublisher>>,
base_url: impl Into<String>,
connections_repo: Arc<dyn domain::ports::RemoteActorConnectionRepository>,
) -> anyhow::Result<Self> {
let data = FederationData::new(
) -> ActivityPubServiceBuilder {
ActivityPubServiceBuilder {
repo,
user_repo,
object_handler,
base_url.clone(),
allow_registration,
software_name,
event_publisher,
);
let federation_config = ApFederationConfig::new(data, debug).await?;
Ok(Self {
federation_config,
base_url,
base_url: base_url.into(),
connections_repo,
})
allow_registration: false,
software_name: String::new(),
debug: false,
event_publisher: None,
}
}
pub fn federation_config(&self) -> &ApFederationConfig {