Files
thoughts/crates/domain/src/models/thought.rs
Gabriel Kaszewski d56d34cc27 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.
2026-05-17 12:25:53 +02:00

75 lines
2.0 KiB
Rust

use crate::value_objects::{Content, ThoughtId, UserId};
use chrono::{DateTime, Utc};
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum Visibility {
Public,
Followers,
Unlisted,
Direct,
}
#[derive(Debug, Clone)]
pub struct Thought {
pub id: ThoughtId,
pub user_id: UserId,
pub content: Content,
pub in_reply_to_id: Option<ThoughtId>,
pub visibility: Visibility,
pub content_warning: Option<String>,
pub sensitive: bool,
pub local: bool,
pub created_at: DateTime<Utc>,
pub updated_at: Option<DateTime<Utc>>,
}
impl Visibility {
pub fn as_str(&self) -> &'static str {
match self {
Visibility::Public => "public",
Visibility::Followers => "followers",
Visibility::Unlisted => "unlisted",
Visibility::Direct => "direct",
}
}
pub fn from_db_str(s: &str) -> Result<Self, crate::errors::DomainError> {
match s {
"public" => Ok(Self::Public),
"followers" => Ok(Self::Followers),
"unlisted" => Ok(Self::Unlisted),
"direct" => Ok(Self::Direct),
other => Err(crate::errors::DomainError::Internal(format!(
"unknown visibility: '{other}'"
))),
}
}
}
pub struct NewThought {
pub id: ThoughtId,
pub user_id: UserId,
pub content: Content,
pub in_reply_to_id: Option<ThoughtId>,
pub visibility: Visibility,
pub content_warning: Option<String>,
pub sensitive: bool,
}
impl Thought {
pub fn new_local(p: NewThought) -> Self {
Self {
id: p.id,
user_id: p.user_id,
content: p.content,
in_reply_to_id: p.in_reply_to_id,
visibility: p.visibility,
content_warning: p.content_warning,
sensitive: p.sensitive,
local: true,
created_at: Utc::now(),
updated_at: None,
}
}
}