Also remove private messages when banning user with "remove content" (#5414)

* Also remove private messages when banning user with "remove content"

* add private message removed

* fix formatting
This commit is contained in:
Nutomic 2025-02-12 12:45:07 +00:00 committed by GitHub
parent 7c7e482936
commit 0af973c3a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 31 additions and 1 deletions

View file

@ -37,6 +37,7 @@ use lemmy_db_schema::{
person::{Person, PersonUpdateForm}, person::{Person, PersonUpdateForm},
person_block::PersonBlock, person_block::PersonBlock,
post::{Post, PostLike}, post::{Post, PostLike},
private_message::PrivateMessage,
registration_application::RegistrationApplication, registration_application::RegistrationApplication,
site::Site, site::Site,
}, },
@ -807,6 +808,9 @@ pub async fn remove_or_restore_user_data(
) )
.await?; .await?;
// Private messages
PrivateMessage::update_removed_for_creator(pool, banned_person_id, removed).await?;
Ok(()) Ok(())
} }

View file

@ -87,6 +87,21 @@ impl PrivateMessage {
let domain = settings.get_protocol_and_hostname(); let domain = settings.get_protocol_and_hostname();
Ok(Url::parse(&format!("{domain}/private_message/{}", self.id))?.into()) 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<Vec<Self>, 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::<Self>(conn)
.await
}
} }
#[cfg(test)] #[cfg(test)]
@ -145,6 +160,7 @@ mod tests {
))? ))?
.into(), .into(),
local: true, local: true,
removed: false,
}; };
let read_private_message = PrivateMessage::read(pool, inserted_private_message.id).await?; let read_private_message = PrivateMessage::read(pool, inserted_private_message.id).await?;

View file

@ -948,6 +948,7 @@ diesel::table! {
#[max_length = 255] #[max_length = 255]
ap_id -> Varchar, ap_id -> Varchar,
local -> Bool, local -> Bool,
removed -> Bool,
} }
} }

View file

@ -33,6 +33,7 @@ pub struct PrivateMessage {
pub updated: Option<DateTime<Utc>>, pub updated: Option<DateTime<Utc>>,
pub ap_id: DbUrl, pub ap_id: DbUrl,
pub local: bool, pub local: bool,
pub removed: bool,
} }
#[derive(Clone, derive_new::new)] #[derive(Clone, derive_new::new)]
@ -67,4 +68,5 @@ pub struct PrivateMessageUpdateForm {
pub updated: Option<Option<DateTime<Utc>>>, pub updated: Option<Option<DateTime<Utc>>>,
pub ap_id: Option<DbUrl>, pub ap_id: Option<DbUrl>,
pub local: Option<bool>, pub local: Option<bool>,
pub removed: Option<bool>,
} }

View file

@ -92,7 +92,8 @@ impl InboxCombinedViewInternal {
// This could be a simple join, but you need to check for deleted here // This could be a simple join, but you need to check for deleted here
let private_message_join = inbox_combined::private_message_id let private_message_join = inbox_combined::private_message_id
.eq(private_message::id.nullable()) .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); let community_join = post::community_id.eq(community::id);

View file

@ -0,0 +1,3 @@
ALTER TABLE private_message
DROP COLUMN removed;

View file

@ -0,0 +1,3 @@
ALTER TABLE private_message
ADD COLUMN removed bool NOT NULL DEFAULT FALSE;