From c5ba327d8ff5d8737bd297661d1204db09e52f7d Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 27 Oct 2014 23:20:40 -0400 Subject: [PATCH] fix empty pages --- public/src/client/topic.js | 6 +++--- src/controllers/topics.js | 2 +- src/socket.io/topics.js | 12 +++++------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/public/src/client/topic.js b/public/src/client/topic.js index 38e690caa6..6b69944ce5 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -292,7 +292,7 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT function findInsertionPoint() { var firstPostTimestamp = parseInt(data.posts[0].timestamp, 10); var firstPostVotes = parseInt(data.posts[0].votes, 10); - var firstPostPid = data.posts[0].pid; + var firstPostPid = parseInt(data.posts[0].pid, 10); var firstReply = $('#post-container li.post-row[data-index!="0"]').first(); var lastReply = $('#post-container li.post-row[data-index!="0"]').last(); @@ -315,9 +315,9 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT } else if(firstPostVotes < parseInt(firstReply.attr('data-votes'), 10)) { after = lastReply; } else { - if (firstPostPid > firstReply.attr('data-pid')) { + if (firstPostPid <= parseInt(firstReply.attr('data-pid'), 10)) { before = firstReply; - } else if(firstPostPid <= firstReply.attr('data-pid')) { + } else if(firstPostPid > parseInt(firstReply.attr('data-pid'), 10)) { after = lastReply; } } diff --git a/src/controllers/topics.js b/src/controllers/topics.js index b3ea5b5f27..7be21fd793 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -44,7 +44,7 @@ topicsController.get = function(req, res, next) { }, function (results, next) { - var postCount = parseInt(results.postCount, 10) + 1; + var postCount = parseInt(results.postCount, 10); if (utils.isNumber(req.params.post_index)) { var url = ''; if (req.params.post_index > postCount) { diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js index 2dae9af430..045ad7a135 100644 --- a/src/socket.io/topics.js +++ b/src/socket.io/topics.js @@ -428,15 +428,13 @@ SocketTopics.loadMore = function(socket, data, callback) { reverse = false, start = Math.max(parseInt(data.after, 10) - 1, 0); - if (results.settings.topicPostSort === 'newest_to_oldest') { + if (results.settings.topicPostSort === 'newest_to_oldest' || results.settings.topicPostSort === 'most_votes') { reverse = true; - data.after = results.postCount - data.after; + data.after = results.postCount - 1 - data.after; start = Math.max(parseInt(data.after, 10), 0); - } else if (results.settings.topicPostSort === 'most_votes') { - reverse = true; - data.after = results.postCount - data.after; - start = Math.max(parseInt(data.after, 10), 0); - set = 'tid:' + data.tid + ':posts:votes'; + if (results.settings.topicPostSort === 'most_votes') { + set = 'tid:' + data.tid + ':posts:votes'; + } } var end = start + results.settings.postsPerPage - 1;