diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index 944f8e4fb..1aa40863d 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -37,6 +37,7 @@ use lemmy_db_schema::{ person::{Person, PersonUpdateForm}, person_block::PersonBlock, post::{Post, PostLike}, + private_message::PrivateMessage, registration_application::RegistrationApplication, site::Site, }, @@ -807,6 +808,9 @@ pub async fn remove_or_restore_user_data( ) .await?; + // Private messages + PrivateMessage::update_removed_for_creator(pool, banned_person_id, removed).await?; + Ok(()) } diff --git a/crates/db_schema/src/impls/private_message.rs b/crates/db_schema/src/impls/private_message.rs index f2a0fe520..ced75312f 100644 --- a/crates/db_schema/src/impls/private_message.rs +++ b/crates/db_schema/src/impls/private_message.rs @@ -87,6 +87,21 @@ impl PrivateMessage { let domain = settings.get_protocol_and_hostname(); Ok(Url::parse(&format!("{domain}/private_message/{}", self.id))?.into()) } + + pub async fn update_removed_for_creator( + pool: &mut DbPool<'_>, + for_creator_id: PersonId, + removed: bool, + ) -> Result, Error> { + let conn = &mut get_conn(pool).await?; + diesel::update(private_message::table.filter(private_message::creator_id.eq(for_creator_id))) + .set(( + private_message::removed.eq(removed), + private_message::updated.eq(Utc::now()), + )) + .get_results::(conn) + .await + } } #[cfg(test)] @@ -145,6 +160,7 @@ mod tests { ))? .into(), local: true, + removed: false, }; let read_private_message = PrivateMessage::read(pool, inserted_private_message.id).await?; diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 77cdfec26..c7d6efa02 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -948,6 +948,7 @@ diesel::table! { #[max_length = 255] ap_id -> Varchar, local -> Bool, + removed -> Bool, } } diff --git a/crates/db_schema/src/source/private_message.rs b/crates/db_schema/src/source/private_message.rs index f15373907..68db9154a 100644 --- a/crates/db_schema/src/source/private_message.rs +++ b/crates/db_schema/src/source/private_message.rs @@ -33,6 +33,7 @@ pub struct PrivateMessage { pub updated: Option>, pub ap_id: DbUrl, pub local: bool, + pub removed: bool, } #[derive(Clone, derive_new::new)] @@ -67,4 +68,5 @@ pub struct PrivateMessageUpdateForm { pub updated: Option>>, pub ap_id: Option, pub local: Option, + pub removed: Option, } diff --git a/crates/db_views/src/combined/inbox_combined_view.rs b/crates/db_views/src/combined/inbox_combined_view.rs index 8c3f3ae11..49f342cc3 100644 --- a/crates/db_views/src/combined/inbox_combined_view.rs +++ b/crates/db_views/src/combined/inbox_combined_view.rs @@ -92,7 +92,8 @@ impl InboxCombinedViewInternal { // This could be a simple join, but you need to check for deleted here let private_message_join = inbox_combined::private_message_id .eq(private_message::id.nullable()) - .and(not(private_message::deleted)); + .and(not(private_message::deleted)) + .and(not(private_message::removed)); let community_join = post::community_id.eq(community::id); diff --git a/migrations/2025-02-11-131045_ban-remove-content-pm/down.sql b/migrations/2025-02-11-131045_ban-remove-content-pm/down.sql new file mode 100644 index 000000000..b535bb021 --- /dev/null +++ b/migrations/2025-02-11-131045_ban-remove-content-pm/down.sql @@ -0,0 +1,3 @@ +ALTER TABLE private_message + DROP COLUMN removed; + diff --git a/migrations/2025-02-11-131045_ban-remove-content-pm/up.sql b/migrations/2025-02-11-131045_ban-remove-content-pm/up.sql new file mode 100644 index 000000000..9724bee16 --- /dev/null +++ b/migrations/2025-02-11-131045_ban-remove-content-pm/up.sql @@ -0,0 +1,3 @@ +ALTER TABLE private_message + ADD COLUMN removed bool NOT NULL DEFAULT FALSE; +