Node.js based forum software built for the modern web
fix index to post if sorting is by votes and pagination is used
barisusakli8bbd7d971b83
diff --git a/src/controllers/topics.js b/src/controllers/topics.jsindex 83d873b583..498a3d81db 100644--- a/src/controllers/topics.js+++ b/src/controllers/topics.js@@ -89,17 +89,23 @@ topicsController.get = function(req, res, next) {var postIndex = 0;page = parseInt(req.query.page, 10) || 1;req.params.post_index = parseInt(req.params.post_index, 10) || 0;+ if (reverse && req.params.post_index === 1) {+ req.params.post_index = 0;+ }if (!settings.usePagination) {if (reverse) {- if (req.params.post_index === 1) {- req.params.post_index = 0;- }- postIndex = Math.max(postCount - (req.params.post_index || postCount) - (settings.postsPerPage - 1), 0);+ postIndex = Math.max(0, postCount - (req.params.post_index || postCount) - (settings.postsPerPage - 1));} else {- postIndex = Math.max((req.params.post_index || 1) - (settings.postsPerPage + 1), 0);+ postIndex = Math.max(0, (req.params.post_index || 1) - (settings.postsPerPage + 1));}} else if (!req.query.page) {- var index = Math.max(req.params.post_index - 1, 0) || 0;+ var index = 0;+ if (reverse) {+ index = Math.max(0, postCount - (req.params.post_index || postCount));+ } else {+ index = Math.max(0, req.params.post_index - 1) || 0;+ }+page = Math.max(1, Math.ceil(index / settings.postsPerPage));}