From 20e965a6552bfc1d0f5fb966d9baf6b508c22bd4 Mon Sep 17 00:00:00 2001 From: silverpill Date: Mon, 19 Dec 2022 22:29:04 +0000 Subject: [PATCH] Remove PostCreateData.clean() --- src/mastodon_api/statuses/views.rs | 7 +++++-- src/models/posts/types.rs | 24 ------------------------ 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/src/mastodon_api/statuses/views.rs b/src/mastodon_api/statuses/views.rs index aa2d25e..7e57cc3 100644 --- a/src/mastodon_api/statuses/views.rs +++ b/src/mastodon_api/statuses/views.rs @@ -33,6 +33,7 @@ use crate::models::posts::queries::{ delete_post, }; use crate::models::posts::types::{PostCreateData, Visibility}; +use crate::models::posts::validators::clean_content; use crate::models::reactions::queries::{ create_reaction, delete_reaction, @@ -98,7 +99,10 @@ async fn create_status( ); post_data.links.extend(link_map.values().map(|post| post.id)); let linked = link_map.into_values().collect(); + // Clean content + post_data.content = clean_content(&post_data.content)?; + // Links validation if post_data.links.len() > 0 && post_data.visibility != Visibility::Public { return Err(ValidationError("can't add links to non-public posts").into()); }; @@ -133,8 +137,7 @@ async fn create_status( // Remove duplicate mentions post_data.mentions.sort(); post_data.mentions.dedup(); - // Clean content - post_data.clean()?; + // Create post let mut post = create_post(db_client, ¤t_user.id, post_data).await?; post.in_reply_to = maybe_in_reply_to.map(|mut in_reply_to| { diff --git a/src/models/posts/types.rs b/src/models/posts/types.rs index 9815684..ad8eedd 100644 --- a/src/models/posts/types.rs +++ b/src/models/posts/types.rs @@ -9,10 +9,8 @@ use crate::database::{ DatabaseError, DatabaseTypeError, }; -use crate::errors::ValidationError; use crate::models::attachments::types::DbMediaAttachment; use crate::models::profiles::types::DbActorProfile; -use super::validators::clean_content; #[derive(Clone, Debug, PartialEq)] pub enum Visibility { @@ -265,31 +263,9 @@ impl PostCreateData { ..Default::default() } } - - /// Validate and clean post data (only for local posts). - pub fn clean(&mut self) -> Result<(), ValidationError> { - assert!(self.object_id.is_none()); - self.content = clean_content(&self.content)?; - Ok(()) - } } pub struct PostUpdateData { pub content: String, pub updated_at: DateTime, } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_post_data_clean() { - let mut post_data_2 = PostCreateData { - content: "test ".to_string(), - ..Default::default() - }; - assert_eq!(post_data_2.clean().is_ok(), true); - assert_eq!(post_data_2.content.as_str(), "test"); - } -}