Fix parents traversal 4 real
This commit is contained in:
@@ -162,12 +162,16 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
|
|
||||||
for (let i = 0; i < thread.data.items.length; i++) {
|
for (let i = 0; i < thread.data.items.length; i++) {
|
||||||
const item = thread.data.items[i]
|
const item = thread.data.items[i]
|
||||||
|
/*
|
||||||
|
* Need to check `depth`, since not found or blocked posts are not
|
||||||
|
* `threadPost`s, but still have `depth`.
|
||||||
|
*/
|
||||||
|
const hasDepth = 'depth' in item
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle anchor post. Need to check only `depth`, since not found or
|
* Handle anchor post.
|
||||||
* blocked posts are not `threadPost`s, but still have `depth`.
|
|
||||||
*/
|
*/
|
||||||
if ('depth' in item && item.depth === 0) {
|
if (hasDepth && item.depth === 0) {
|
||||||
results.push(item)
|
results.push(item)
|
||||||
|
|
||||||
// Recalculate total parents current index.
|
// Recalculate total parents current index.
|
||||||
@@ -180,7 +184,7 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
*/
|
*/
|
||||||
if (!deferParents) {
|
if (!deferParents) {
|
||||||
const start = i - 1
|
const start = i - 1
|
||||||
if (start > 0) {
|
if (start >= 0) {
|
||||||
const limit = Math.max(0, start - maxParentCount)
|
const limit = Math.max(0, start - maxParentCount)
|
||||||
for (let pi = start; pi >= limit; pi--) {
|
for (let pi = start; pi >= limit; pi--) {
|
||||||
results.unshift(thread.data.items[pi])
|
results.unshift(thread.data.items[pi])
|
||||||
@@ -189,7 +193,7 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// ignore parents
|
// ignore parents
|
||||||
if (item.type === 'threadPost' && item.depth < 0) continue
|
if (hasDepth && item.depth < 0) continue
|
||||||
// can exit early if we've reached the max children count
|
// can exit early if we've reached the max children count
|
||||||
if (childrenCount > maxChildrenCount) break
|
if (childrenCount > maxChildrenCount) break
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user