diff --git a/src/categories/topics.js b/src/categories/topics.js index a56545cfa9..3b7038fbe0 100644 --- a/src/categories/topics.js +++ b/src/categories/topics.js @@ -57,7 +57,7 @@ module.exports = function (Categories) { function (results, next) { var totalPinnedCount = results.pinnedTids.length; - pinnedTids = results.pinnedTids.slice(data.start, data.stop === -1 ? undefined : data.stop + 1); + pinnedTids = results.pinnedTids.slice(data.start, data.stop !== -1 ? data.stop + 1 : undefined); var pinnedCount = pinnedTids.length; diff --git a/src/topics/popular.js b/src/topics/popular.js index 99855b17d3..95bed19613 100644 --- a/src/topics/popular.js +++ b/src/topics/popular.js @@ -53,7 +53,7 @@ module.exports = function (Topics) { function (topics, next) { tids = topics.filter(function (topic) { return topic && parseInt(topic.deleted, 10) !== 1; - }).sort(sortPopular).slice(start, stop !== -1 ? stop - 1 : undefined).map(function (topic) { + }).sort(sortPopular).slice(start, stop !== -1 ? stop + 1 : undefined).map(function (topic) { return topic.tid; }); privileges.topics.filterTids('read', tids, uid, next); diff --git a/src/topics/recent.js b/src/topics/recent.js index 5b717d9639..6fea81f972 100644 --- a/src/topics/recent.js +++ b/src/topics/recent.js @@ -41,7 +41,7 @@ module.exports = function (Topics) { }, function (tids, next) { recentTopics.topicCount = tids.length; - tids = tids.slice(start, stop + 1); + tids = tids.slice(start, stop !== -1 ? stop + 1 : undefined); Topics.getTopicsByTids(tids, uid, next); }, function (topicData, next) { diff --git a/src/topics/suggested.js b/src/topics/suggested.js index 187af3706a..bb450a759d 100644 --- a/src/topics/suggested.js +++ b/src/topics/suggested.js @@ -35,13 +35,7 @@ module.exports = function (Topics) { } }, function (categoryTids, next) { - tids = _.uniq(tids.concat(categoryTids)); - if (stop === -1) { - tids = tids.slice(start); - } else { - tids = tids.slice(start, stop + 1); - } - + tids = _.uniq(tids.concat(categoryTids)).slice(start, stop !== -1 ? stop + 1 : undefined); Topics.getTopicsByTids(tids, uid, next); }, ], callback); diff --git a/src/topics/top.js b/src/topics/top.js index b4f10b9340..2d86cc8eb3 100644 --- a/src/topics/top.js +++ b/src/topics/top.js @@ -33,7 +33,7 @@ module.exports = function (Topics) { }, function (tids, next) { topTopics.topicCount = tids.length; - tids = tids.slice(start, stop + 1); + tids = tids.slice(start, stop !== -1 ? stop + 1 : undefined); Topics.getTopicsByTids(tids, uid, next); }, function (topicData, next) { diff --git a/src/topics/unread.js b/src/topics/unread.js index 7c068cfc40..86d3cac56a 100644 --- a/src/topics/unread.js +++ b/src/topics/unread.js @@ -42,11 +42,7 @@ module.exports = function (Topics) { return next(null, []); } - if (params.stop === -1) { - tids = tids.slice(params.start); - } else { - tids = tids.slice(params.start, params.stop + 1); - } + tids = tids.slice(params.start, params.stop !== -1 ? params.stop + 1 : undefined); Topics.getTopicsByTids(tids, params.uid, next); }, diff --git a/test/topics.js b/test/topics.js index 4dec7a37c4..af7d22f76e 100644 --- a/test/topics.js +++ b/test/topics.js @@ -1823,4 +1823,20 @@ describe('Topic\'s', function () { ], done); }); }); + + describe('top topics', function () { + it('should get top topics in category', function (done) { + var filters = ['', 'watched', 'unreplied', 'new']; + async.map(filters, function (filter, next) { + topics.getTopTopics(topic.categoryId, topic.userId, 0, -1, filter, next); + }, function (err, data) { + assert.ifError(err); + assert(data); + data.forEach(function (filterTopics) { + assert(Array.isArray(filterTopics.topics)); + }); + done(); + }); + }); + }); });