From 4e6409f325bca5b2727b19c24d77ffa2b59109b1 Mon Sep 17 00:00:00 2001 From: kartikynwa Date: Wed, 21 Sep 2022 07:03:33 +0530 Subject: [PATCH] Allow filtering out of deleted and removed comments when getting person details (#2446) undefined --- crates/api_common/src/person.rs | 1 + crates/api_crud/src/user/read.rs | 2 ++ crates/db_views/src/comment_view.rs | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/crates/api_common/src/person.rs b/crates/api_common/src/person.rs index 8c4131dd6..4b29070ac 100644 --- a/crates/api_common/src/person.rs +++ b/crates/api_common/src/person.rs @@ -99,6 +99,7 @@ pub struct GetPersonDetails { pub limit: Option, pub community_id: Option, pub saved_only: Option, + pub show_deleted_and_removed: Option, pub auth: Option>, } diff --git a/crates/api_crud/src/user/read.rs b/crates/api_crud/src/user/read.rs index 820905d82..d47bc5337 100644 --- a/crates/api_crud/src/user/read.rs +++ b/crates/api_crud/src/user/read.rs @@ -60,6 +60,7 @@ impl PerformCrud for GetPersonDetails { let page = data.page; let limit = data.limit; let saved_only = data.saved_only; + let show_deleted_and_removed = data.show_deleted_and_removed; let community_id = data.community_id; let (posts, comments) = blocking(context.pool(), move |conn| { @@ -77,6 +78,7 @@ impl PerformCrud for GetPersonDetails { .local_user(local_user.as_ref()) .sort(sort.map(post_to_comment_sort_type)) .saved_only(saved_only) + .show_deleted_and_removed(show_deleted_and_removed) .community_id(community_id) .page(page) .limit(limit); diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 2b496b4eb..0efc4e11f 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -165,6 +165,7 @@ pub struct CommentQuery<'a> { local_user: Option<&'a LocalUser>, search_term: Option, saved_only: Option, + show_deleted_and_removed: Option, page: Option, limit: Option, max_depth: Option, @@ -302,6 +303,11 @@ impl<'a> CommentQuery<'a> { query = query.filter(comment_saved::id.is_not_null()); } + if !self.show_deleted_and_removed.unwrap_or(true) { + query = query.filter(comment::deleted.eq(false)); + query = query.filter(comment::removed.eq(false)); + } + if !self.local_user.map(|l| l.show_bot_accounts).unwrap_or(true) { query = query.filter(person::bot_account.eq(false)); };