From dbea8f435f3cdd5e8ee0473fadce35e7b5348b68 Mon Sep 17 00:00:00 2001 From: hole-thu Date: Sat, 4 Jun 2022 14:24:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9C=89=E8=AF=84=E8=AE=BA=E5=90=8E?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E5=88=A0=E9=99=A4=E4=B8=BB=E6=A5=BC=E5=86=85?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/mod.rs | 2 +- src/api/operation.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index 95b3115..635e17f 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -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 }); diff --git a/src/api/operation.rs b/src/api/operation.rs index f95c66b..210080a 100644 --- a/src/api/operation.rs +++ b/src/api/operation.rs @@ -41,7 +41,18 @@ pub async fn delete(di: Form, user: CurrentUser, db: Db, rconn: Rds } "pid" => { let mut p = Post::get(&db, &rconn, di.id).await?; - p.soft_delete(&user, &db).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;