Remove PostCreateData.clean()
This commit is contained in:
parent
2232bf814c
commit
20e965a655
2 changed files with 5 additions and 26 deletions
|
@ -33,6 +33,7 @@ use crate::models::posts::queries::{
|
||||||
delete_post,
|
delete_post,
|
||||||
};
|
};
|
||||||
use crate::models::posts::types::{PostCreateData, Visibility};
|
use crate::models::posts::types::{PostCreateData, Visibility};
|
||||||
|
use crate::models::posts::validators::clean_content;
|
||||||
use crate::models::reactions::queries::{
|
use crate::models::reactions::queries::{
|
||||||
create_reaction,
|
create_reaction,
|
||||||
delete_reaction,
|
delete_reaction,
|
||||||
|
@ -98,7 +99,10 @@ async fn create_status(
|
||||||
);
|
);
|
||||||
post_data.links.extend(link_map.values().map(|post| post.id));
|
post_data.links.extend(link_map.values().map(|post| post.id));
|
||||||
let linked = link_map.into_values().collect();
|
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 {
|
if post_data.links.len() > 0 && post_data.visibility != Visibility::Public {
|
||||||
return Err(ValidationError("can't add links to non-public posts").into());
|
return Err(ValidationError("can't add links to non-public posts").into());
|
||||||
};
|
};
|
||||||
|
@ -133,8 +137,7 @@ async fn create_status(
|
||||||
// Remove duplicate mentions
|
// Remove duplicate mentions
|
||||||
post_data.mentions.sort();
|
post_data.mentions.sort();
|
||||||
post_data.mentions.dedup();
|
post_data.mentions.dedup();
|
||||||
// Clean content
|
|
||||||
post_data.clean()?;
|
|
||||||
// Create post
|
// Create post
|
||||||
let mut post = create_post(db_client, ¤t_user.id, post_data).await?;
|
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| {
|
post.in_reply_to = maybe_in_reply_to.map(|mut in_reply_to| {
|
||||||
|
|
|
@ -9,10 +9,8 @@ use crate::database::{
|
||||||
DatabaseError,
|
DatabaseError,
|
||||||
DatabaseTypeError,
|
DatabaseTypeError,
|
||||||
};
|
};
|
||||||
use crate::errors::ValidationError;
|
|
||||||
use crate::models::attachments::types::DbMediaAttachment;
|
use crate::models::attachments::types::DbMediaAttachment;
|
||||||
use crate::models::profiles::types::DbActorProfile;
|
use crate::models::profiles::types::DbActorProfile;
|
||||||
use super::validators::clean_content;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Visibility {
|
pub enum Visibility {
|
||||||
|
@ -265,31 +263,9 @@ impl PostCreateData {
|
||||||
..Default::default()
|
..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 struct PostUpdateData {
|
||||||
pub content: String,
|
pub content: String,
|
||||||
pub updated_at: DateTime<Utc>,
|
pub updated_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue