diff --git a/src/lib/components/lemmy/comment/Comment.svelte b/src/lib/components/lemmy/comment/Comment.svelte index 932573d9..fb56e2bd 100644 --- a/src/lib/components/lemmy/comment/Comment.svelte +++ b/src/lib/components/lemmy/comment/Comment.svelte @@ -25,6 +25,7 @@ import CommentForm from './CommentForm.svelte' import type { CommentNodeI } from './comments.svelte' import { page } from '$app/state' + import { settings } from '$lib/settings.svelte' interface Props { node: CommentNodeI @@ -189,6 +190,11 @@ /> {/if} + {#if settings.debugInfo} + + #{node.comment_view.comment.id} + + {/if} {/if}
diff --git a/src/routes/comment/[instance]/[id]/+page.ts b/src/routes/comment/[instance]/[id]/+page.ts index d87dc733..43624d65 100644 --- a/src/routes/comment/[instance]/[id]/+page.ts +++ b/src/routes/comment/[instance]/[id]/+page.ts @@ -14,8 +14,21 @@ export async function load({ params, fetch }) { 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( 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(), + }, + ), ) } diff --git a/src/routes/post/[instance]/[id=integer]/+page.svelte b/src/routes/post/[instance]/[id=integer]/+page.svelte index 7aac7fda..7659cc2f 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.svelte +++ b/src/routes/post/[instance]/[id=integer]/+page.svelte @@ -194,13 +194,12 @@ {#await data.post.value.meta then meta} {@const crossposts = meta.cross_posts} {#if crossposts?.length > 0} - + {#snippet title()}
{crossposts.length} {$t('routes.post.crosspostCount')} @@ -222,32 +221,37 @@ {/if} {/await} -{#if data.thread.value.showContext || data.thread.value.singleThread} -
- -
-{/if} + +
+ {/if} +{/await}
diff --git a/src/routes/post/[instance]/[id=integer]/+page.ts b/src/routes/post/[instance]/[id=integer]/+page.ts index c3dbf91f..7ca9b91b 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.ts +++ b/src/routes/post/[instance]/[id=integer]/+page.ts @@ -25,21 +25,19 @@ interface PartialPost { function buildContext(thread?: string) { let parentId: number | undefined - let showContext: string | undefined - let max_depth = 3 + let showContext: boolean = false + const max_depth = 3 if (thread) { const split = thread.split('.') - if (split.length >= 9) { - const sliced = split.slice(0, split.length - 4) - showContext = sliced[sliced.length - 1] - parentId = Number(split[split.length - 5]) - } else { - parentId = Number(split[1]) + + if (split[0] == '0') parentId = Number(thread.split('.')[1]) + else { + parentId = Number(thread.split('.')[0]) + showContext = true } } - if (parentId) max_depth = 10 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 const sort = settings?.defaultSort?.comments ?? 'Hot' - const { parentId, showContext, focus } = buildContext( - url.searchParams.get('thread') || undefined, - ) - const cachedPost = findInFeed(Number(params.id), 'main') ?? 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 = { post_id: Number(params.id), type_: 'All',