diff --git a/pkg/models/comment.go b/pkg/models/comment.go index bf4d79c..8136a18 100644 --- a/pkg/models/comment.go +++ b/pkg/models/comment.go @@ -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 }