Fix creation date in reposts

This commit is contained in:
silverpill 2022-10-04 23:18:01 +00:00
parent 6fd0c16997
commit c7499cb0dc
3 changed files with 14 additions and 9 deletions

View file

@ -43,11 +43,7 @@ pub async fn handle_announce(
post.id
},
};
let repost_data = PostCreateData {
repost_of_id: Some(post_id),
object_id: Some(repost_object_id),
..Default::default()
};
let repost_data = PostCreateData::repost(post_id, Some(repost_object_id));
create_post(db_client, &author.id, repost_data).await?;
Ok(Some(NOTE))
}

View file

@ -341,10 +341,7 @@ async fn reblog(
if !post.is_public() || post.repost_of_id.is_some() {
return Err(HttpError::NotFoundError("post"));
};
let repost_data = PostCreateData {
repost_of_id: Some(status_id.into_inner()),
..Default::default()
};
let repost_data = PostCreateData::repost(status_id.into_inner(), None);
let mut repost = create_post(db_client, &current_user.id, repost_data).await?;
post.repost_count += 1;
repost.repost_of = Some(Box::new(post));

View file

@ -248,6 +248,18 @@ pub struct PostCreateData {
}
impl PostCreateData {
pub fn repost(
repost_of_id: Uuid,
object_id: Option<String>,
) -> Self {
Self {
repost_of_id: Some(repost_of_id),
object_id: object_id,
created_at: Utc::now(),
..Default::default()
}
}
/// Validate and clean post data (only for local posts).
pub fn clean(&mut self, character_limit: usize) -> Result<(), ValidationError> {
assert!(self.object_id.is_none());