Files
thoughts/crates/domain/src/models/thought.rs
Gabriel Kaszewski 550865bad4
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 9m25s
test / unit (pull_request) Successful in 16m57s
test / integration (pull_request) Failing after 17m29s
fix: resolve all clippy warnings — redundant closures, dead code, collapsible_if, needless borrow
2026-05-14 16:33:34 +02:00

72 lines
1.7 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,
}
impl Visibility {
pub fn from_db_str(s: &str) -> Self {
match s {
"followers" => Self::Followers,
"unlisted" => Self::Unlisted,
"direct" => Self::Direct,
_ => Self::Public,
}
}
pub fn as_str(&self) -> &str {
match self {
Self::Public => "public",
Self::Followers => "followers",
Self::Unlisted => "unlisted",
Self::Direct => "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 in_reply_to_url: Option<String>,
pub ap_id: Option<String>,
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 Thought {
pub fn new_local(
id: ThoughtId,
user_id: UserId,
content: Content,
in_reply_to_id: Option<ThoughtId>,
visibility: Visibility,
content_warning: Option<String>,
sensitive: bool,
) -> Self {
Self {
id,
user_id,
content,
in_reply_to_id,
in_reply_to_url: None,
ap_id: None,
visibility,
content_warning,
sensitive,
local: true,
created_at: Utc::now(),
updated_at: None,
}
}
}