diff options
author | Colin Reeder <colin@vpzom.click> | 2020-08-08 13:42:52 -0600 |
---|---|---|
committer | Colin Reeder <colin@vpzom.click> | 2020-08-08 13:42:52 -0600 |
commit | 2f346ded19eed8896e889549e43b673a3defac26 (patch) | |
tree | 255e4e1cbad77db425649e36c45c3721aed431c9 | |
parent | 319e2b6ea9ba06e6082030d8ce0b84d710738fda (diff) |
Hide deleted comments with no replies (#75)
-rw-r--r-- | src/routes/api/mod.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/routes/api/mod.rs b/src/routes/api/mod.rs index 10a47d0..56991ca 100644 --- a/src/routes/api/mod.rs +++ b/src/routes/api/mod.rs @@ -465,7 +465,7 @@ async fn apply_comments_replies<'a, T>( let mut replies = get_comments_replies_box(&ids, include_your_for, depth - 1, db, local_hostname).await?; - for (_, comment) in comments { + for (_, comment) in comments.iter_mut() { let current = replies.remove(&comment.base.id).unwrap_or_else(Vec::new); comment.has_replies = !current.is_empty(); comment.replies = Some(current); @@ -486,11 +486,19 @@ async fn apply_comments_replies<'a, T>( .try_collect() .await?; - for (_, comment) in comments { + for (_, comment) in comments.iter_mut() { comment.has_replies = with_replies.contains(&comment.base.id); } } + comments.retain(|(_, comment)| { + if comment.deleted && !comment.has_replies { + false + } else { + true + } + }); + Ok(()) } |