Bugfix when linking to 1st comment on secondary pages of thread

This commit is contained in:
Noah Petherbridge 2024-08-03 21:00:51 -07:00
parent b8be14ea8d
commit f1cf1bd958

View File

@ -172,6 +172,14 @@ func FindPageByComment(user *User, comment *Comment, pageSize int) (int, error)
for i, cid := range allCommentIDs {
if cid == comment.ID {
var page = int(math.Ceil(float64(i) / float64(pageSize)))
// If the comment index is an equal multiple of the page size
// (e.g. comment #20 is the 1st comment on page 2, since 0-19 is page 1),
// account for an off-by-one error.
if i%pageSize == 0 {
page++
}
if page == 0 {
page = 1
}