Make deleted and removed comments show when they have childern

pull/3965/head
SleeplessOne1917 2023-09-17 23:38:07 -04:00
parent 6735a98d35
commit eab1862e9a
1 changed files with 16 additions and 25 deletions

View File

@ -1,37 +1,20 @@
use crate::structs::{CommentView, LocalUserView}; use crate::structs::{CommentView, LocalUserView};
use diesel::{ use diesel::{
pg::Pg, pg::Pg, result::Error, BoolExpressionMethods, ExpressionMethods, JoinOnDsl,
result::Error, NullableExpressionMethods, PgTextExpressionMethods, QueryDsl,
BoolExpressionMethods,
ExpressionMethods,
JoinOnDsl,
NullableExpressionMethods,
PgTextExpressionMethods,
QueryDsl,
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use diesel_ltree::{nlevel, subpath, Ltree, LtreeExtensions}; use diesel_ltree::{nlevel, subpath, Ltree, LtreeExtensions};
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId}, newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId},
schema::{ schema::{
comment, comment, comment_aggregates, comment_like, comment_saved, community, community_block,
comment_aggregates, community_follower, community_moderator, community_person_ban, local_user_language, person,
comment_like, person_block, post,
comment_saved,
community,
community_block,
community_follower,
community_moderator,
community_person_ban,
local_user_language,
person,
person_block,
post,
}, },
source::community::CommunityFollower, source::community::CommunityFollower,
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
CommentSortType, CommentSortType, ListingType,
ListingType,
}; };
fn queries<'a>() -> Queries< fn queries<'a>() -> Queries<
@ -193,7 +176,11 @@ fn queries<'a>() -> Queries<
let is_creator = options.creator_id == options.local_user.map(|l| l.person.id); let is_creator = options.creator_id == options.local_user.map(|l| l.person.id);
// only show deleted comments to creator // only show deleted comments to creator
if !is_creator { if !is_creator {
query = query.filter(comment::deleted.eq(false)); query = query.filter(
comment::deleted
.eq(false)
.or(comment_aggregates::child_count.gt(0)),
);
} }
let is_admin = options let is_admin = options
@ -202,7 +189,11 @@ fn queries<'a>() -> Queries<
.unwrap_or(false); .unwrap_or(false);
// only show removed comments to admin when viewing user profile // only show removed comments to admin when viewing user profile
if !(options.is_profile_view && is_admin) { if !(options.is_profile_view && is_admin) {
query = query.filter(comment::removed.eq(false)); query = query.filter(
comment::removed
.eq(false)
.or(comment_aggregates::child_count.gt(0)),
);
} }
if !options if !options