mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-12-23 18:40:34 +00:00
Merge pull request #249 from Plume-org/delete-posts
Delete posts when deleting account
This commit is contained in:
commit
4b8c090def
1 changed files with 21 additions and 1 deletions
|
@ -15,7 +15,7 @@ use openssl::{
|
||||||
};
|
};
|
||||||
use plume_common::activity_pub::{
|
use plume_common::activity_pub::{
|
||||||
ap_accept_header, ActivityStream, Id, IntoId, ApSignature, PublicKey,
|
ap_accept_header, ActivityStream, Id, IntoId, ApSignature, PublicKey,
|
||||||
inbox::WithInbox,
|
inbox::{Deletable, WithInbox},
|
||||||
sign::{Signer, gen_keypair}
|
sign::{Signer, gen_keypair}
|
||||||
};
|
};
|
||||||
use reqwest::{
|
use reqwest::{
|
||||||
|
@ -107,6 +107,26 @@ impl User {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(&self, conn: &Connection) {
|
pub fn delete(&self, conn: &Connection) {
|
||||||
|
use schema::post_authors;
|
||||||
|
|
||||||
|
// delete the posts if they is the only author
|
||||||
|
let all_their_posts_ids: Vec<i32> = post_authors::table
|
||||||
|
.filter(post_authors::author_id.eq(self.id))
|
||||||
|
.select(post_authors::post_id)
|
||||||
|
.load(conn)
|
||||||
|
.expect("Couldn't load posts IDs");
|
||||||
|
for post_id in all_their_posts_ids {
|
||||||
|
let has_other_authors = post_authors::table
|
||||||
|
.filter(post_authors::post_id.eq(post_id))
|
||||||
|
.filter(post_authors::author_id.ne(self.id))
|
||||||
|
.count()
|
||||||
|
.load(conn)
|
||||||
|
.expect("Couldn't count other authors").iter().next().unwrap_or(&0) > &0;
|
||||||
|
if !has_other_authors {
|
||||||
|
Post::get(conn, post_id).expect("Post is already gone").delete(conn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
diesel::delete(self).execute(conn).expect("Couldn't remove user from DB");
|
diesel::delete(self).execute(conn).expect("Couldn't remove user from DB");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue