From e1777e9071b1b71fc164f88c74df56462ff11904 Mon Sep 17 00:00:00 2001 From: trinity-1686a Date: Sun, 9 Apr 2023 12:54:29 +0200 Subject: [PATCH] delete comments properly when deleting users --- plume-models/src/comments.rs | 1 + plume-models/src/inbox.rs | 6 +++--- plume-models/src/users.rs | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/plume-models/src/comments.rs b/plume-models/src/comments.rs index 91e7c6c2..53db4482 100644 --- a/plume-models/src/comments.rs +++ b/plume-models/src/comments.rs @@ -73,6 +73,7 @@ impl Comment { }); get!(comments); list_by!(comments, list_by_post, post_id as i32); + list_by!(comments, list_by_author, author_id as i32); find_by!(comments, find_by_ap_url, ap_url as &str); pub fn get_author(&self, conn: &Connection) -> Result { diff --git a/plume-models/src/inbox.rs b/plume-models/src/inbox.rs index ab10ca8e..2796ebb4 100644 --- a/plume-models/src/inbox.rs +++ b/plume-models/src/inbox.rs @@ -7,7 +7,7 @@ use crate::{ posts::{Post, PostUpdate}, reshares::Reshare, users::User, - Error, CONFIG, + Connection, Error, CONFIG, }; use plume_common::activity_pub::inbox::Inbox; @@ -46,8 +46,8 @@ impl_into_inbox_result! { Reshare => Reshared } -pub fn inbox(conn: &DbConn, act: serde_json::Value) -> Result { - Inbox::handle(&**conn, act) +pub fn inbox(conn: &Connection, act: serde_json::Value) -> Result { + Inbox::handle(conn, act) .with::(CONFIG.proxy()) .with::(CONFIG.proxy()) .with::(CONFIG.proxy()) diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index 82b7ab19..d80fb33e 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -1,8 +1,8 @@ use crate::{ - ap_url, blocklisted_emails::BlocklistedEmail, blogs::Blog, db_conn::DbConn, follows::Follow, - instance::*, medias::Media, notifications::Notification, post_authors::PostAuthor, posts::Post, - safe_string::SafeString, schema::users, timeline::Timeline, Connection, Error, Result, - UserEvent::*, CONFIG, ITEMS_PER_PAGE, USER_CHAN, + ap_url, blocklisted_emails::BlocklistedEmail, blogs::Blog, comments::Comment, db_conn::DbConn, + follows::Follow, instance::*, medias::Media, notifications::Notification, + post_authors::PostAuthor, posts::Post, safe_string::SafeString, schema::users, + timeline::Timeline, Connection, Error, Result, UserEvent::*, CONFIG, ITEMS_PER_PAGE, USER_CHAN, }; use activitystreams::{ activity::Delete, @@ -168,6 +168,14 @@ impl User { notif.delete(conn)? } + for comment in Comment::list_by_author(conn, self.id)? { + let delete_activity = comment.build_delete(&conn)?; + crate::inbox::inbox( + conn, + serde_json::to_value(&delete_activity).map_err(Error::from)?, + )?; + } + diesel::delete(self) .execute(conn) .map(|_| ())