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:
@@ -7,9 +7,9 @@ use chrono::{DateTime, Utc};
|
||||
use std::sync::Arc;
|
||||
use url::Url;
|
||||
|
||||
use crate::note::ThoughtNote;
|
||||
use crate::note::{ThoughtNote, ThoughtNoteInput};
|
||||
use crate::urls::ThoughtsUrls;
|
||||
use activitypub_base::{ActivityPubRepository, ApObjectHandler};
|
||||
use activitypub_base::{AcceptNoteInput, ActivityPubRepository, ApObjectHandler};
|
||||
use domain::ports::{EventPublisher, TagRepository};
|
||||
use domain::value_objects::UserId;
|
||||
|
||||
@@ -58,16 +58,16 @@ impl ApObjectHandler for ThoughtsObjectHandler {
|
||||
.thought
|
||||
.in_reply_to_id
|
||||
.map(|id| self.urls.thought_url(id.as_uuid()));
|
||||
let note = ThoughtNote::new_public(
|
||||
note_url.clone(),
|
||||
let note = ThoughtNote::new_public(ThoughtNoteInput {
|
||||
id: note_url.clone(),
|
||||
actor_url,
|
||||
e.thought.content.as_str().to_owned(),
|
||||
e.thought.created_at,
|
||||
content: e.thought.content.as_str().to_owned(),
|
||||
published: e.thought.created_at,
|
||||
in_reply_to,
|
||||
e.thought.sensitive,
|
||||
e.thought.content_warning,
|
||||
followers,
|
||||
);
|
||||
sensitive: e.thought.sensitive,
|
||||
summary: e.thought.content_warning,
|
||||
followers_url: followers,
|
||||
});
|
||||
Ok((note_url, serde_json::to_value(¬e)?))
|
||||
})
|
||||
.collect()
|
||||
@@ -96,16 +96,16 @@ impl ApObjectHandler for ThoughtsObjectHandler {
|
||||
.thought
|
||||
.in_reply_to_id
|
||||
.map(|id| self.urls.thought_url(id.as_uuid()));
|
||||
let note = ThoughtNote::new_public(
|
||||
note_url.clone(),
|
||||
let note = ThoughtNote::new_public(ThoughtNoteInput {
|
||||
id: note_url.clone(),
|
||||
actor_url,
|
||||
e.thought.content.as_str().to_owned(),
|
||||
created_at,
|
||||
content: e.thought.content.as_str().to_owned(),
|
||||
published: created_at,
|
||||
in_reply_to,
|
||||
e.thought.sensitive,
|
||||
e.thought.content_warning,
|
||||
followers,
|
||||
);
|
||||
sensitive: e.thought.sensitive,
|
||||
summary: e.thought.content_warning,
|
||||
followers_url: followers,
|
||||
});
|
||||
Ok((note_url, serde_json::to_value(¬e)?, created_at))
|
||||
})
|
||||
.collect()
|
||||
@@ -143,16 +143,16 @@ impl ApObjectHandler for ThoughtsObjectHandler {
|
||||
|
||||
let thought_id = self
|
||||
.repo
|
||||
.accept_note(
|
||||
ap_id.as_str(),
|
||||
&author_id,
|
||||
¬e.content,
|
||||
note.published,
|
||||
note.sensitive,
|
||||
note.summary,
|
||||
.accept_note(AcceptNoteInput {
|
||||
ap_id: ap_id.as_str(),
|
||||
author_id: &author_id,
|
||||
content: ¬e.content,
|
||||
published: note.published,
|
||||
sensitive: note.sensitive,
|
||||
content_warning: note.summary,
|
||||
visibility,
|
||||
note.in_reply_to.as_ref().map(|u| u.as_str()),
|
||||
)
|
||||
in_reply_to: note.in_reply_to.as_ref().map(|u| u.as_str()),
|
||||
})
|
||||
.await
|
||||
.map_err(|e| anyhow!("{e}"))?;
|
||||
|
||||
|
||||
@@ -30,30 +30,31 @@ pub struct ThoughtNote {
|
||||
pub tag: Vec<serde_json::Value>,
|
||||
}
|
||||
|
||||
pub struct ThoughtNoteInput {
|
||||
pub id: Url,
|
||||
pub actor_url: Url,
|
||||
pub content: String,
|
||||
pub published: DateTime<Utc>,
|
||||
pub in_reply_to: Option<Url>,
|
||||
pub sensitive: bool,
|
||||
pub summary: Option<String>,
|
||||
pub followers_url: Url,
|
||||
}
|
||||
|
||||
impl ThoughtNote {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new_public(
|
||||
id: Url,
|
||||
actor_url: Url,
|
||||
content: String,
|
||||
published: DateTime<Utc>,
|
||||
in_reply_to: Option<Url>,
|
||||
sensitive: bool,
|
||||
summary: Option<String>,
|
||||
followers_url: Url,
|
||||
) -> Self {
|
||||
pub fn new_public(p: ThoughtNoteInput) -> Self {
|
||||
Self {
|
||||
kind: Default::default(),
|
||||
url: Some(id.clone()),
|
||||
id,
|
||||
attributed_to: actor_url,
|
||||
content,
|
||||
published,
|
||||
url: Some(p.id.clone()),
|
||||
id: p.id,
|
||||
attributed_to: p.actor_url,
|
||||
content: p.content,
|
||||
published: p.published,
|
||||
to: vec![AS_PUBLIC.to_string()],
|
||||
cc: vec![followers_url.to_string()],
|
||||
in_reply_to,
|
||||
sensitive,
|
||||
summary,
|
||||
cc: vec![p.followers_url.to_string()],
|
||||
in_reply_to: p.in_reply_to,
|
||||
sensitive: p.sensitive,
|
||||
summary: p.summary,
|
||||
tag: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,16 @@ use super::*;
|
||||
|
||||
#[test]
|
||||
fn note_serializes_with_public_audience() {
|
||||
let note = ThoughtNote::new_public(
|
||||
"https://example.com/thoughts/1".parse().unwrap(),
|
||||
"https://example.com/users/alice".parse().unwrap(),
|
||||
"Hello world".to_string(),
|
||||
chrono::Utc::now(),
|
||||
None,
|
||||
false,
|
||||
None,
|
||||
"https://example.com/users/alice/followers".parse().unwrap(),
|
||||
);
|
||||
let note = ThoughtNote::new_public(super::ThoughtNoteInput {
|
||||
id: "https://example.com/thoughts/1".parse().unwrap(),
|
||||
actor_url: "https://example.com/users/alice".parse().unwrap(),
|
||||
content: "Hello world".to_string(),
|
||||
published: chrono::Utc::now(),
|
||||
in_reply_to: None,
|
||||
sensitive: false,
|
||||
summary: None,
|
||||
followers_url: "https://example.com/users/alice/followers".parse().unwrap(),
|
||||
});
|
||||
let json = serde_json::to_string(¬e).unwrap();
|
||||
assert!(json.contains(AS_PUBLIC));
|
||||
assert!(json.contains("Hello world"));
|
||||
|
||||
Reference in New Issue
Block a user