You've already forked AstralRinth
forked from didirus/AstralRinth
Fix deletion of private notes (#814)
This commit is contained in:
@@ -241,7 +241,8 @@ impl ThreadMessage {
|
|||||||
id: ThreadMessageId(x.id),
|
id: ThreadMessageId(x.id),
|
||||||
thread_id: ThreadId(x.thread_id),
|
thread_id: ThreadId(x.thread_id),
|
||||||
author_id: x.author_id.map(UserId),
|
author_id: x.author_id.map(UserId),
|
||||||
body: serde_json::from_value(x.body).unwrap_or(MessageBody::Deleted),
|
body: serde_json::from_value(x.body)
|
||||||
|
.unwrap_or(MessageBody::Deleted { private: false }),
|
||||||
created: x.created,
|
created: x.created,
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
@@ -253,6 +254,7 @@ impl ThreadMessage {
|
|||||||
|
|
||||||
pub async fn remove_full(
|
pub async fn remove_full(
|
||||||
id: ThreadMessageId,
|
id: ThreadMessageId,
|
||||||
|
private: bool,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||||
) -> Result<Option<()>, sqlx::error::Error> {
|
) -> Result<Option<()>, sqlx::error::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -262,7 +264,7 @@ impl ThreadMessage {
|
|||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
",
|
",
|
||||||
id as ThreadMessageId,
|
id as ThreadMessageId,
|
||||||
serde_json::to_value(MessageBody::Deleted).unwrap_or(serde_json::json!({}))
|
serde_json::to_value(MessageBody::Deleted { private }).unwrap_or(serde_json::json!({}))
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut **transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -40,7 +40,10 @@ pub enum LegacyMessageBody {
|
|||||||
},
|
},
|
||||||
ThreadClosure,
|
ThreadClosure,
|
||||||
ThreadReopen,
|
ThreadReopen,
|
||||||
Deleted,
|
Deleted {
|
||||||
|
#[serde(default)]
|
||||||
|
private: bool,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
|
#[derive(Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
|
||||||
@@ -90,7 +93,9 @@ impl From<crate::models::v3::threads::MessageBody> for LegacyMessageBody {
|
|||||||
crate::models::v3::threads::MessageBody::ThreadReopen => {
|
crate::models::v3::threads::MessageBody::ThreadReopen => {
|
||||||
LegacyMessageBody::ThreadReopen
|
LegacyMessageBody::ThreadReopen
|
||||||
}
|
}
|
||||||
crate::models::v3::threads::MessageBody::Deleted => LegacyMessageBody::Deleted,
|
crate::models::v3::threads::MessageBody::Deleted { private } => {
|
||||||
|
LegacyMessageBody::Deleted { private }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,10 @@ pub enum MessageBody {
|
|||||||
},
|
},
|
||||||
ThreadClosure,
|
ThreadClosure,
|
||||||
ThreadReopen,
|
ThreadReopen,
|
||||||
Deleted,
|
Deleted {
|
||||||
|
#[serde(default)]
|
||||||
|
private: bool,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
|
#[derive(Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
|
||||||
@@ -103,6 +106,8 @@ impl Thread {
|
|||||||
.filter(|x| {
|
.filter(|x| {
|
||||||
if let MessageBody::Text { private, .. } = x.body {
|
if let MessageBody::Text { private, .. } = x.body {
|
||||||
!private || user.role.is_mod()
|
!private || user.role.is_mod()
|
||||||
|
} else if let MessageBody::Deleted { private, .. } = x.body {
|
||||||
|
!private || user.role.is_mod()
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -611,7 +611,15 @@ pub async fn message_delete(
|
|||||||
database::Image::remove(image.id, &mut transaction, &redis).await?;
|
database::Image::remove(image.id, &mut transaction, &redis).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
database::models::ThreadMessage::remove_full(thread.id, &mut transaction).await?;
|
let private = if let MessageBody::Text { private, .. } = thread.body {
|
||||||
|
private
|
||||||
|
} else if let MessageBody::Deleted { private, .. } = thread.body {
|
||||||
|
private
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
|
database::models::ThreadMessage::remove_full(thread.id, private, &mut transaction).await?;
|
||||||
transaction.commit().await?;
|
transaction.commit().await?;
|
||||||
|
|
||||||
Ok(HttpResponse::NoContent().body(""))
|
Ok(HttpResponse::NoContent().body(""))
|
||||||
|
|||||||
Reference in New Issue
Block a user