mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-09-02 19:23:49 +00:00
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:
parent
7c7e482936
commit
0af973c3a2
7 changed files with 31 additions and 1 deletions
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
|
@ -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<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)]
|
||||
|
@ -145,6 +160,7 @@ mod tests {
|
|||
))?
|
||||
.into(),
|
||||
local: true,
|
||||
removed: false,
|
||||
};
|
||||
|
||||
let read_private_message = PrivateMessage::read(pool, inserted_private_message.id).await?;
|
||||
|
|
|
@ -948,6 +948,7 @@ diesel::table! {
|
|||
#[max_length = 255]
|
||||
ap_id -> Varchar,
|
||||
local -> Bool,
|
||||
removed -> Bool,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ pub struct PrivateMessage {
|
|||
pub updated: Option<DateTime<Utc>>,
|
||||
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<Option<DateTime<Utc>>>,
|
||||
pub ap_id: Option<DbUrl>,
|
||||
pub local: Option<bool>,
|
||||
pub removed: Option<bool>,
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE private_message
|
||||
DROP COLUMN removed;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE private_message
|
||||
ADD COLUMN removed bool NOT NULL DEFAULT FALSE;
|
||||
|
Loading…
Reference in a new issue