fix: close #279, deleted/removed posts are still shown

This commit is contained in:
Xylight committed 2024-03-15 14:34:51 -07:00
1 parent c7e3f4d56e
commit df0cfbd932
5 files changed
+23 -7

No files matched your search

+5 -2
View File
@@ -24,7 +24,8 @@ function getDepthFromComment(comment?: Comment): number | undefined {
export function buildCommentsTree( export function buildCommentsTree(
comments: CommentView[], comments: CommentView[],
baseDepth: number = 0 baseDepth: number = 0,
filter: (c: CommentView) => boolean = (c) => true
): CommentNodeI[] { ): CommentNodeI[] {
const map = new Map<number, CommentNodeI>() const map = new Map<number, CommentNodeI>()
@@ -38,7 +39,9 @@ export function buildCommentsTree(
depth: depth, depth: depth,
} }
min_depth = Math.min(min_depth, depth) min_depth = Math.min(min_depth, depth)
map.set(comment_view.comment.id, { ...node }) if (filter(comment_view)) {
map.set(comment_view.comment.id, { ...node })
}
} }
const tree: CommentNodeI[] = [] const tree: CommentNodeI[] = []
@@ -37,7 +37,12 @@
const seenUrls = new Set<string>() const seenUrls = new Set<string>()
posts?.forEach((post) => { posts?.forEach((post) => {
if (!post) return if (
!post ||
($userSettings.hidePosts.deleted && post.post.deleted) ||
($userSettings.hidePosts.removed && post.post.removed)
)
return
if (!post?.post?.url) { if (!post?.post?.url) {
results.push(post) results.push(post)
return return
+1 -1
View File
@@ -98,7 +98,7 @@ export const defaultSettings: Settings = {
comments: env.PUBLIC_DEFAULT_COMMENT_SORT ?? ('Hot' as any), comments: env.PUBLIC_DEFAULT_COMMENT_SORT ?? ('Hot' as any),
}, },
hidePosts: { hidePosts: {
deleted: toBool(env.PUBLIC_HIDE_DELETED) ?? true, deleted: toBool(env.PUBLIC_HIDE_DELETED) ?? false,
removed: toBool(env.PUBLIC_HIDE_REMOVED) ?? false, removed: toBool(env.PUBLIC_HIDE_REMOVED) ?? false,
}, },
expandSidebar: toBool(env.PUBLIC_EXPAND_SIDEBAR) ?? true, expandSidebar: toBool(env.PUBLIC_EXPAND_SIDEBAR) ?? true,
@@ -302,7 +302,15 @@
{/if} {/if}
<Comments <Comments
post={post.post_view.post} post={post.post_view.post}
nodes={buildCommentsTree(data.comments.comments)} nodes={buildCommentsTree(
data.comments.comments,
undefined,
(c) =>
!(
($userSettings.hidePosts.deleted && c.comment.deleted) ||
($userSettings.hidePosts.removed && c.comment.removed)
)
)}
isParent={true} isParent={true}
/> />
{#if post.post_view.counts.comments > 5} {#if post.post_view.counts.comments > 5}
+2 -2
View File
@@ -191,9 +191,9 @@
description="Blur images and remove post bodies of NSFW content." description="Blur images and remove post bodies of NSFW content."
/> />
<Setting> <Setting>
<span slot="title">Hide Posts</span> <span slot="title">Hide Submissions</span>
<span slot="description"> <span slot="description">
<p>Hide certain types of posts.</p> <p>Hide certain types of submissions.</p>
<p> <p>
Looking to hide read posts? That was moved to your <Link Looking to hide read posts? That was moved to your <Link
href="/profile/settings" href="/profile/settings"