Prepare Delete(Note) before deleting post from database
This commit is contained in:
parent
ea62f1fdaf
commit
f6c3cbc0fa
2 changed files with 22 additions and 11 deletions
20
src/cli.rs
20
src/cli.rs
|
@ -185,14 +185,22 @@ impl DeletePost {
|
|||
db_client: &mut impl GenericClient,
|
||||
) -> Result<(), Error> {
|
||||
let post = get_post_by_id(db_client, &self.id).await?;
|
||||
let mut maybe_delete_note = None;
|
||||
if post.author.is_local() {
|
||||
let author = get_user_by_id(db_client, &post.author.id).await?;
|
||||
let activity = prepare_delete_note(
|
||||
db_client,
|
||||
config.instance(),
|
||||
&author,
|
||||
&post,
|
||||
).await?;
|
||||
maybe_delete_note = Some(activity);
|
||||
};
|
||||
let deletion_queue = delete_post(db_client, &post.id).await?;
|
||||
deletion_queue.process(config).await;
|
||||
if post.author.is_local() {
|
||||
// Send Delete(Note) activity
|
||||
let author = get_user_by_id(db_client, &post.author.id).await?;
|
||||
prepare_delete_note(db_client, config.instance(), &author, &post)
|
||||
.await?
|
||||
.deliver().await?;
|
||||
// Send Delete(Note) activity
|
||||
if let Some(activity) = maybe_delete_note {
|
||||
activity.deliver().await?;
|
||||
};
|
||||
println!("post deleted");
|
||||
Ok(())
|
||||
|
|
|
@ -242,14 +242,17 @@ async fn delete_status(
|
|||
if post.author.id != current_user.id {
|
||||
return Err(HttpError::PermissionError);
|
||||
};
|
||||
let delete_note = prepare_delete_note(
|
||||
db_client,
|
||||
config.instance(),
|
||||
¤t_user,
|
||||
&post,
|
||||
).await?;
|
||||
let deletion_queue = delete_post(db_client, &status_id).await?;
|
||||
let config_clone = config.clone();
|
||||
tokio::spawn(async move {
|
||||
deletion_queue.process(&config_clone).await;
|
||||
deletion_queue.process(&config).await;
|
||||
});
|
||||
|
||||
prepare_delete_note(db_client, config.instance(), ¤t_user, &post).await?
|
||||
.spawn_deliver();
|
||||
delete_note.spawn_deliver();
|
||||
|
||||
Ok(HttpResponse::NoContent().finish())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue