Skip to content

Commit 6c6afef

Browse files
committed
allow a litte more context for big comment trees
1 parent 96226dd commit 6c6afef

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/item.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { COMMENT_DEPTH_LIMIT, FULL_COMMENTS_THRESHOLD, OLD_ITEM_DAYS } from './constants'
1+
import { COMMENT_DEPTH_LIMIT, COMMENTS_OF_COMMENT_LIMIT, FULL_COMMENTS_THRESHOLD, OLD_ITEM_DAYS } from './constants'
22
import { datePivot } from './time'
33

44
export const defaultCommentSort = (pinned, bio, createdAt) => {
@@ -106,10 +106,12 @@ export const deleteReminders = async ({ id, userId, models }) => {
106106
}
107107

108108
export const commentSubTreeRootId = (item, root) => {
109+
const path = item.path.split('.')
110+
111+
// if this is a limited comment tree, we can't be sure comments at our depth are visible
112+
// beyond COMMENTS_OF_COMMENT_LIMIT, so COMMENTS_OF_COMMENT_LIMIT is the max depth we can navigate to
109113
if (item.root?.ncomments > FULL_COMMENTS_THRESHOLD || root?.ncomments > FULL_COMMENTS_THRESHOLD) {
110-
return item.id
114+
return path.slice(-COMMENTS_OF_COMMENT_LIMIT)[0]
111115
}
112-
113-
const path = item.path.split('.')
114116
return path.slice(-(COMMENT_DEPTH_LIMIT - 1))[0]
115117
}

0 commit comments

Comments
 (0)