Node.js based forum software built for the modern web
allow filtering /unread to only topics that have not yet been seen
Ben Lubara61d9472956c
diff --git a/src/controllers/unread.js b/src/controllers/unread.jsindex d81774661f..d07c2d16a1 100644--- a/src/controllers/unread.js+++ b/src/controllers/unread.js@@ -16,6 +16,7 @@ unreadController.get = function(req, res, next) {var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1;var results;var cid = req.query.cid;+ var seen = !req.query.unseen;async.waterfall([function(next) {@@ -24,7 +25,7 @@ unreadController.get = function(req, res, next) {user.getWatchedCategories(req.uid, next);},unreadTopics: function(next) {- topics.getUnreadTopics(cid, req.uid, 0, stop, next);+ topics.getUnreadTopics(cid, req.uid, 0, stop, seen, next);}}, next);},@@ -64,7 +65,7 @@ unreadController.get = function(req, res, next) {unreadController.unreadTotal = function(req, res, next) {- topics.getTotalUnread(req.uid, function (err, data) {+ topics.getTotalUnread(req.uid, !req.query.unseen, function (err, data) {if (err) {return next(err);}diff --git a/src/topics/unread.js b/src/topics/unread.jsindex 28846640b7..713f4732fa 100644--- a/src/topics/unread.js+++ b/src/topics/unread.js@@ -14,13 +14,23 @@ var utils = require('../../public/src/utils');module.exports = function(Topics) {- Topics.getTotalUnread = function(uid, callback) {- Topics.getUnreadTids(0, uid, 0, 99, function(err, tids) {+ Topics.getTotalUnread = function(uid, allowSeen, callback) {+ if (!callback) {+ callback = allowSeen;+ allowSeen = true;+ }++ Topics.getUnreadTids(0, uid, 0, 99, allowSeen, function(err, tids) {callback(err, tids ? tids.length : 0);});};- Topics.getUnreadTopics = function(cid, uid, start, stop, callback) {+ Topics.getUnreadTopics = function(cid, uid, start, stop, allowSeen, callback) {+ if (!callback) {+ callback = allowSeen;+ allowSeen = true;+ }+var unreadTopics = {showSelect: true,@@ -30,7 +40,7 @@ module.exports = function(Topics) {async.waterfall([function(next) {- Topics.getUnreadTids(cid, uid, start, stop, next);+ Topics.getUnreadTids(cid, uid, start, stop, allowSeen, next);},function(tids, next) {if (!tids.length) {@@ -54,7 +64,12 @@ module.exports = function(Topics) {return Date.now() - (parseInt(meta.config.unreadCutoff, 10) || 2) * 86400000;};- Topics.getUnreadTids = function(cid, uid, start, stop, callback) {+ Topics.getUnreadTids = function(cid, uid, start, stop, allowSeen, callback) {+ if (!callback) {+ callback = allowSeen;+ allowSeen = true;+ }+uid = parseInt(uid, 10);if (uid === 0) {return callback(null, []);@@ -95,7 +110,7 @@ module.exports = function(Topics) {});var tids = results.recentTids.filter(function(recentTopic) {- return !userRead[recentTopic.value] || recentTopic.score > userRead[recentTopic.value];+ return !userRead[recentTopic.value] || allowSeen && recentTopic.score > userRead[recentTopic.value];}).map(function(topic) {return topic.value;}).filter(function(tid, index, array) {