Node.js based forum software built for the modern web
#5513 (#5520)
psychobunnya67d48e71994
diff --git a/public/src/client/account/topics.js b/public/src/client/account/topics.jsindex 340c2e11b9..c16ffd913d 100644--- a/public/src/client/account/topics.js+++ b/public/src/client/account/topics.js@@ -27,6 +27,7 @@ define('forum/account/topics', ['forum/account/header', 'forum/infinitescroll'],infinitescroll.loadMore('topics.loadMoreFromSet', {set: set,after: $('[component="category"]').attr('data-nextstart'),+ count: config.topicsPerPage,}, function (data, done) {if (data.topics && data.topics.length) {onTopicsLoaded(data.topics, done);diff --git a/public/src/client/recent.js b/public/src/client/recent.jsindex 981baabd12..b8f9380198 100644--- a/public/src/client/recent.js+++ b/public/src/client/recent.js@@ -132,6 +132,7 @@ define('forum/recent', ['forum/infinitescroll', 'components'], function (infinitinfinitescroll.loadMore('topics.loadMoreRecentTopics', {after: $('[component="category"]').attr('data-nextstart'),+ count: config.topicsPerPage,cid: utils.params().cid,filter: ajaxify.data.selectedFilter.filter,set: $('[component="category"]').attr('data-set') ? $('[component="category"]').attr('data-set') : 'topics:recent',diff --git a/public/src/client/tag.js b/public/src/client/tag.jsindex 2b74c17193..e07126cb2e 100644--- a/public/src/client/tag.js+++ b/public/src/client/tag.js@@ -27,6 +27,7 @@ define('forum/tag', ['forum/recent', 'forum/infinitescroll'], function (recent,infinitescroll.loadMore('topics.loadMoreFromSet', {set: 'tag:' + ajaxify.data.tag + ':topics',after: $('[component="category"]').attr('data-nextstart'),+ count: config.topicsPerPage,}, function (data, done) {if (data.topics && data.topics.length) {recent.onTopicsLoaded('tag', data.topics, false, done);diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.jsindex 72f580b582..fb9074b3be 100644--- a/public/src/client/topic/posts.js+++ b/public/src/client/topic/posts.js@@ -227,6 +227,7 @@ define('forum/topic/posts', [infinitescroll.loadMore('topics.loadMore', {tid: tid,after: after,+ count: config.postsPerPage,direction: direction,topicPostSort: config.topicPostSort,}, function (data, done) {diff --git a/public/src/client/unread.js b/public/src/client/unread.jsindex f5b1dd73ed..01ef9cff52 100644--- a/public/src/client/unread.js+++ b/public/src/client/unread.js@@ -92,6 +92,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll', 'var cid = params.cid;infinitescroll.loadMore('topics.loadMoreUnreadTopics', {after: $('[component="category"]').attr('data-nextstart'),+ count: config.topicsPerPage,cid: cid,filter: ajaxify.data.selectedFilter.filter,}, function (data, done) {diff --git a/src/socket.io/topics/infinitescroll.js b/src/socket.io/topics/infinitescroll.jsindex 023ad6266e..cf7c37e050 100644--- a/src/socket.io/topics/infinitescroll.js+++ b/src/socket.io/topics/infinitescroll.js@@ -40,19 +40,19 @@ module.exports = function (SocketTopics) {var reverse = data.topicPostSort === 'newest_to_oldest' || data.topicPostSort === 'most_votes';var start = Math.max(0, parseInt(data.after, 10));- var infScrollPostsPerPage = 10;+ var infScrollPostsPerPage = Math.max(0, Math.min(meta.config.postsPerPage, parseInt(data.postsPerPage, 10) || meta.config.postsPerPage) - 1);if (data.direction > 0) {if (reverse) {start = results.topic.postcount - start;}} else if (reverse) {- start = results.topic.postcount - start - infScrollPostsPerPage - 1;+ start = results.topic.postcount - start - infScrollPostsPerPage;} else {- start = start - infScrollPostsPerPage - 1;+ start = start - infScrollPostsPerPage;}- var stop = start + (infScrollPostsPerPage - 1);+ var stop = start + (infScrollPostsPerPage);start = Math.max(0, start);stop = Math.max(0, stop);@@ -93,7 +93,7 @@ module.exports = function (SocketTopics) {}var start = parseInt(data.after, 10);- var stop = start + 9;+ var stop = start + Math.max(0, Math.min(meta.config.topicsPerPage, parseInt(data.topicsPerPage, 10) || meta.config.topicsPerPage) - 1);topics.getUnreadTopics({ cid: data.cid, uid: socket.uid, start: start, stop: stop, filter: data.filter }, callback);};@@ -104,7 +104,7 @@ module.exports = function (SocketTopics) {}var start = parseInt(data.after, 10);- var stop = start + 9;+ var stop = start + Math.max(0, Math.min(meta.config.topicsPerPage, parseInt(data.topicsPerPage, 10) || meta.config.topicsPerPage) - 1);topics.getRecentTopics(data.cid, socket.uid, start, stop, data.filter, callback);};@@ -115,7 +115,7 @@ module.exports = function (SocketTopics) {}var start = parseInt(data.after, 10);- var stop = start + 9;+ var stop = start + Math.max(0, Math.min(meta.config.topicsPerPage, parseInt(data.topicsPerPage, 10) || meta.config.topicsPerPage) - 1);topics.getTopicsFromSet(data.set, socket.uid, start, stop, callback);};diff --git a/test/topics.js b/test/topics.jsindex 097ffb8c37..ad481ade1e 100644--- a/test/topics.js+++ b/test/topics.js@@ -902,7 +902,7 @@ describe('Topic\'s', function () {});it('should infinite load topic posts', function (done) {- socketTopics.loadMore({ uid: adminUid }, { tid: tid, after: 0 }, function (err, data) {+ socketTopics.loadMore({ uid: adminUid }, { tid: tid, after: 0, count: 10 }, function (err, data) {assert.ifError(err);assert(data.mainPost);assert(data.posts);@@ -921,7 +921,7 @@ describe('Topic\'s', function () {it('should load more unread topics', function (done) {socketTopics.markUnread({ uid: adminUid }, tid, function (err) {assert.ifError(err);- socketTopics.loadMoreUnreadTopics({ uid: adminUid }, { cid: topic.categoryId, after: 0 }, function (err, data) {+ socketTopics.loadMoreUnreadTopics({ uid: adminUid }, { cid: topic.categoryId, after: 0, count: 10 }, function (err, data) {assert.ifError(err);assert(data);assert(Array.isArray(data.topics));@@ -939,7 +939,7 @@ describe('Topic\'s', function () {it('should load more recent topics', function (done) {- socketTopics.loadMoreRecentTopics({ uid: adminUid }, { cid: topic.categoryId, after: 0 }, function (err, data) {+ socketTopics.loadMoreRecentTopics({ uid: adminUid }, { cid: topic.categoryId, after: 0, count: 10 }, function (err, data) {assert.ifError(err);assert(data);assert(Array.isArray(data.topics));@@ -955,7 +955,7 @@ describe('Topic\'s', function () {});it('should load more from custom set', function (done) {- socketTopics.loadMoreFromSet({ uid: adminUid }, { set: 'uid:' + adminUid + ':topics', after: 0 }, function (err, data) {+ socketTopics.loadMoreFromSet({ uid: adminUid }, { set: 'uid:' + adminUid + ':topics', after: 0, count: 10 }, function (err, data) {assert.ifError(err);assert(data);assert(Array.isArray(data.topics));