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:
@@ -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