diff --git a/src/convert/npf.rs b/src/convert/npf.rs index b95b83e..49fad19 100644 --- a/src/convert/npf.rs +++ b/src/convert/npf.rs @@ -14,6 +14,7 @@ pub mod layout_blocks; pub mod objects; pub mod text_formatting; +mod objects_post; use content_blocks::{BlockText, BlockValue}; use text_formatting::{FormatTypeBold, FormatTypeItalic, FormatValue}; diff --git a/src/convert/npf/objects.rs b/src/convert/npf/objects.rs index bb59bce..f2527f0 100644 --- a/src/convert/npf/objects.rs +++ b/src/convert/npf/objects.rs @@ -1,5 +1,7 @@ use serde::{Deserialize, Serialize}; +pub use super::objects_post::Post; + #[serde_with::skip_serializing_none] #[derive(Debug, Deserialize, Serialize, Clone)] pub struct BlogInfo { @@ -73,120 +75,6 @@ pub struct Avatar { pub accessories: Vec, // TODO: Find values for accessories } -#[serde_with::skip_serializing_none] -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct Post { - object_type: String, - pub id: u64, - pub id_string: String, - pub r#type: Option, - pub tumblelog_uuid: Option, - pub original_type: Option, - pub is_blocks_post_format: Option, - pub blog_name: Option, - pub blog: Option, - pub is_blazed: Option, - pub is_bale_pending: Option, - pub can_ignite: Option, - pub can_blaze: Option, - pub post_url: Option, - pub slug: Option, - pub date: Option, - pub timestamp: Option, - pub state: Option, - pub reblog_key: Option, - pub tags: Option>, - pub short_url: Option, - pub summary: Option, - pub should_open_in_legacy: Option, - pub recommended_source: Option, - pub recommended_color: Option, - pub followed: Option, - pub post_author: Option, - pub author_blog: Option, - pub post_author_avatar: Option, - pub liked: Option, - pub note_count: Option, - pub content: Vec, - pub layout: Vec, - pub trail: Vec, - pub can_line: Option, - pub interactability_reblog: Option, - pub interactability_blaze: Option, - pub can_reblog: Option, - pub can_send_in_message: Option, - pub muted: Option, - pub mute_end_timestamp: Option, - pub can_mute: Option, -} -impl Post { - pub fn new(id: u64) -> Self { - Self::from(id) - } - pub fn is_valid(&self) -> bool { - if let Ok(i) = self.id_string.parse::() { - self.id == i - } else { - false - } - } - fn default() -> Self { - Self { - object_type: String::from("post"), - r#type: None, - id: 0, - id_string: String::from("0"), - tumblelog_uuid: None, - original_type: None, - is_blocks_post_format: None, - blog_name: None, - blog: None, - is_blazed: None, - is_bale_pending: None, - can_ignite: None, - can_blaze: None, - post_url: None, - slug: None, - date: None, - timestamp: None, - state: None, - reblog_key: None, - tags: None, - short_url: None, - summary: None, - should_open_in_legacy: None, - recommended_source: None, - recommended_color: None, - followed: None, - post_author: None, - author_blog: None, - post_author_avatar: None, - liked: None, - note_count: None, - content: vec![], - layout: vec![], - trail: vec![], - can_line: None, - interactability_reblog: None, - interactability_blaze: None, - can_reblog: None, - can_send_in_message: None, - muted: None, - mute_end_timestamp: None, - can_mute: None, - } - } -} -impl From for Post { - fn from(value: u64) -> Self { - Self { - id: value, - id_string: value.to_string(), - ..Self::default() - } - } -} - #[serde_with::skip_serializing_none] #[derive(Debug, Deserialize, Serialize, Clone)] pub struct Media { diff --git a/src/convert/npf/objects_post.rs b/src/convert/npf/objects_post.rs new file mode 100644 index 0000000..0964d89 --- /dev/null +++ b/src/convert/npf/objects_post.rs @@ -0,0 +1,116 @@ +use serde::{Deserialize, Serialize}; +#[serde_with::skip_serializing_none] +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct Post { + object_type: String, + pub id: u64, + pub id_string: String, + pub r#type: Option, + pub tumblelog_uuid: Option, + pub original_type: Option, + pub is_blocks_post_format: Option, + pub blog_name: Option, + pub blog: Option, + pub is_blazed: Option, + pub is_bale_pending: Option, + pub can_ignite: Option, + pub can_blaze: Option, + pub post_url: Option, + pub slug: Option, + pub date: Option, + pub timestamp: Option, + pub state: Option, + pub reblog_key: Option, + pub tags: Option>, + pub short_url: Option, + pub summary: Option, + pub should_open_in_legacy: Option, + pub recommended_source: Option, + pub recommended_color: Option, + pub followed: Option, + pub post_author: Option, + pub author_blog: Option, + pub post_author_avatar: Option, + pub liked: Option, + pub note_count: Option, + pub content: Vec, + pub layout: Vec, + pub trail: Vec, + pub can_line: Option, + pub interactability_reblog: Option, + pub interactability_blaze: Option, + pub can_reblog: Option, + pub can_send_in_message: Option, + pub muted: Option, + pub mute_end_timestamp: Option, + pub can_mute: Option, +} +impl Post { + pub fn new(id: u64) -> Self { + Self::from(id) + } + pub fn is_valid(&self) -> bool { + if let Ok(i) = self.id_string.parse::() { + self.id == i + } else { + false + } + } + fn default() -> Self { + Self { + object_type: String::from("post"), + r#type: None, + id: 0, + id_string: String::from("0"), + tumblelog_uuid: None, + original_type: None, + is_blocks_post_format: None, + blog_name: None, + blog: None, + is_blazed: None, + is_bale_pending: None, + can_ignite: None, + can_blaze: None, + post_url: None, + slug: None, + date: None, + timestamp: None, + state: None, + reblog_key: None, + tags: None, + short_url: None, + summary: None, + should_open_in_legacy: None, + recommended_source: None, + recommended_color: None, + followed: None, + post_author: None, + author_blog: None, + post_author_avatar: None, + liked: None, + note_count: None, + content: vec![], + layout: vec![], + trail: vec![], + can_line: None, + interactability_reblog: None, + interactability_blaze: None, + can_reblog: None, + can_send_in_message: None, + muted: None, + mute_end_timestamp: None, + can_mute: None, + } + } +} + +impl From for Post { + fn from(value: u64) -> Self { + Self { + id: value, + id_string: value.to_string(), + ..Self::default() + } + } +} +