fix: comment thread paths are inaccurate

This commit is contained in:
James Xylight committed 2025-08-08 14:22:29 -07:00
1 parent d839724a33
commit 671908f40d
4 files changed
+67 -43

No files matched your search

@@ -25,6 +25,7 @@
import CommentForm from './CommentForm.svelte' import CommentForm from './CommentForm.svelte'
import type { CommentNodeI } from './comments.svelte' import type { CommentNodeI } from './comments.svelte'
import { page } from '$app/state' import { page } from '$app/state'
import { settings } from '$lib/settings.svelte'
interface Props { interface Props {
node: CommentNodeI node: CommentNodeI
@@ -189,6 +190,11 @@
/> />
{/if} {/if}
</span> </span>
{#if settings.debugInfo}
<span class="text-slate-600 dark:text-zinc-400 font-mono ml-auto">
#{node.comment_view.comment.id}
</span>
{/if}
</button> </button>
{/if} {/if}
<div class={['expand max-w-full', open && 'open', contentClass]}> <div class={['expand max-w-full', open && 'open', contentClass]}>
+14 -1
View File
@@ -14,8 +14,21 @@ export async function load({ params, fetch }) {
id: Number(params.id), id: Number(params.id),
}) })
const split = comment.comment_view.comment.path.split('.')
const threadPath =
split.length > 4
? comment.comment_view.comment.id
: split.slice(-5).join('.')
redirect( redirect(
302, 302,
`/post/${profile.current.instance}/${comment.comment_view.post.id}?thread=${comment.comment_view.comment.path}#${comment.comment_view.comment.id}`, resolveRoute(
`/post/[instance]/[id]?thread=${threadPath}#${comment.comment_view.comment.id}`,
{
instance: params.instance,
id: comment.comment_view.post.id.toString(),
},
),
) )
} }
@@ -194,13 +194,12 @@
{#await data.post.value.meta then meta} {#await data.post.value.meta then meta}
{@const crossposts = meta.cross_posts} {@const crossposts = meta.cross_posts}
{#if crossposts?.length > 0} {#if crossposts?.length > 0}
<Expandable <Expandable class="text-base mt-2 w-full cursor-pointer">
class="text-base mt-2 w-full cursor-pointer"
open={crossposts?.length <= 3}
>
{#snippet title()} {#snippet title()}
<div <div
class="flex items-center gap-1 w-full text-left text-base font-normal" class={[
'flex items-center gap-1 w-full text-left text-base font-normal',
]}
> >
<span class="font-bold">{crossposts.length}</span> <span class="font-bold">{crossposts.length}</span>
{$t('routes.post.crosspostCount')} {$t('routes.post.crosspostCount')}
@@ -222,32 +221,37 @@
{/if} {/if}
{/await} {/await}
</article> </article>
{#if data.thread.value.showContext || data.thread.value.singleThread} {#await data.comments.value then comments}
<div {#if data.thread.value.showContext || data.thread.value.singleThread}
class="sticky mx-auto z-50 max-w-md min-w-0 flex flex-col items-center overflow-auto gap-1 <div
class="sticky mx-auto z-50 max-w-md min-w-0 flex flex-col items-center overflow-auto gap-1
bg-slate-50/50 dark:bg-zinc-900/50 backdrop-blur-xl border border-slate-200/50 dark:border-zinc-800/50 bg-slate-50/50 dark:bg-zinc-900/50 backdrop-blur-xl border border-slate-200/50 dark:border-zinc-800/50
p-1 rounded-full justify-between top-6 lg:top-22" p-1 rounded-full justify-between top-6 lg:top-22"
>
<Button
color="none"
rounding="pill"
{loading}
disabled={loading}
href={data.thread.value.showContext
? `/comment/${page.params.instance}/${data.thread.value.showContext}`
: undefined}
class="hover:bg-white/50 dark:hover:bg-zinc-800/30"
onclick={data.thread.value.singleThread ? reloadComments : undefined}
> >
{data.thread.value.showContext <Button
? $t('routes.post.thread.context') color="none"
: $t('routes.post.thread.allComments')} rounding="pill"
{#snippet suffix()} {loading}
<Icon src={ArrowRight} size="16" micro /> disabled={loading}
{/snippet} href={data.thread.value.showContext
</Button> ? `/comment/${
</div> // split first comment path to get 5 before
{/if} comments.comments[0].comment.path.split('.').slice(-5)[0]
}`
: undefined}
class="hover:bg-white/50 dark:hover:bg-zinc-800/30"
onclick={data.thread.value.singleThread ? reloadComments : undefined}
>
{data.thread.value.showContext
? $t('routes.post.thread.context')
: $t('routes.post.thread.allComments')}
{#snippet suffix()}
<Icon src={ArrowRight} size="16" micro />
{/snippet}
</Button>
</div>
{/if}
{/await}
<section class="mt-4 flex flex-col gap-2 w-full" id="comments"> <section class="mt-4 flex flex-col gap-2 w-full" id="comments">
<header> <header>
<div class="text-base"> <div class="text-base">
@@ -25,21 +25,19 @@ interface PartialPost {
function buildContext(thread?: string) { function buildContext(thread?: string) {
let parentId: number | undefined let parentId: number | undefined
let showContext: string | undefined let showContext: boolean = false
let max_depth = 3 const max_depth = 3
if (thread) { if (thread) {
const split = thread.split('.') const split = thread.split('.')
if (split.length >= 9) {
const sliced = split.slice(0, split.length - 4) if (split[0] == '0') parentId = Number(thread.split('.')[1])
showContext = sliced[sliced.length - 1] else {
parentId = Number(split[split.length - 5]) parentId = Number(thread.split('.')[0])
} else { showContext = true
parentId = Number(split[1])
} }
} }
if (parentId) max_depth = 10
return { parentId, showContext, max_depth, focus: thread?.split('.').at(-1) } return { parentId, showContext, max_depth, focus: thread?.split('.').at(-1) }
} }
@@ -77,16 +75,19 @@ export async function load({ params, url, fetch }) {
// TODO use Lemmy profile default settings // TODO use Lemmy profile default settings
const sort = settings?.defaultSort?.comments ?? 'Hot' const sort = settings?.defaultSort?.comments ?? 'Hot'
const { parentId, showContext, focus } = buildContext(
url.searchParams.get('thread') || undefined,
)
const cachedPost = const cachedPost =
findInFeed(Number(params.id), 'main') ?? findInFeed(Number(params.id), 'main') ??
findInFeed(Number(params.id), 'community') findInFeed(Number(params.id), 'community')
const max_depth = (cachedPost?.post_view.counts.comments ?? 0) > 100 ? 1 : 3 const {
parentId,
showContext,
focus,
max_depth: passedMaxDepth,
} = buildContext(url.searchParams.get('thread') || undefined)
const max_depth =
(cachedPost?.post_view.counts.comments ?? 0) > 100 ? 1 : passedMaxDepth
const commentParams: GetComments = { const commentParams: GetComments = {
post_id: Number(params.id), post_id: Number(params.id),
type_: 'All', type_: 'All',