feat: 有评论后允许删除主楼内容

This commit is contained in:
2022-06-04 14:24:47 +08:00
parent 9a33ef5a88
commit dbea8f435f
2 changed files with 13 additions and 2 deletions

View File

@@ -221,7 +221,7 @@ impl UGC for Post {
self.is_deleted
}
fn extra_delete_condition(&self) -> bool {
self.n_comments == 0 && !self.content.starts_with("[系统自动代发]\n")
!self.content.starts_with("[系统自动代发]\n")
}
async fn do_set_deleted(&mut self, db: &Db) -> API<()> {
update!(*self, posts, db, { is_deleted, to true });

View File

@@ -41,7 +41,18 @@ pub async fn delete(di: Form<DeleteInput>, user: CurrentUser, db: Db, rconn: Rds
}
"pid" => {
let mut p = Post::get(&db, &rconn, di.id).await?;
// 有评论:清空主楼而非删除
if p.author_hash == user.namehash && p.n_comments > 0 {
update! {
p,
posts,
&db,
{ content, to "[洞主已删除]" }
}
} else {
p.soft_delete(&user, &db).await?;
}
// 如果是删除需要也从0号缓存队列中去掉
p.refresh_cache(&rconn, true).await;