From c7b5cd48bae54f67fe93e523f53aeb86587092fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 24 Mar 2015 13:10:10 -0400 Subject: [PATCH] closes #2773 --- src/topics/unread.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/topics/unread.js b/src/topics/unread.js index e6910b9b5a..be4a548226 100644 --- a/src/topics/unread.js +++ b/src/topics/unread.js @@ -12,6 +12,8 @@ var async = require('async'), module.exports = function(Topics) { + var unreadCutoff = 86400000; + Topics.getTotalUnread = function(uid, callback) { Topics.getUnreadTids(uid, 0, 20, function(err, tids) { callback(err, tids ? tids.length : 0); @@ -54,17 +56,17 @@ module.exports = function(Topics) { return callback(null, []); } - var yesterday = Date.now() - 86400000; + var cutoff = Date.now() - unreadCutoff; async.parallel({ ignoredCids: function(next) { user.getIgnoredCategories(uid, next); }, recentTids: function(next) { - db.getSortedSetRevRangeByScoreWithScores('topics:recent', 0, -1, '+inf', yesterday, next); + db.getSortedSetRevRangeByScoreWithScores('topics:recent', 0, -1, '+inf', cutoff, next); }, userScores: function(next) { - db.getSortedSetRevRangeByScoreWithScores('uid:' + uid + ':tids_read', 0, -1, '+inf', yesterday, next); + db.getSortedSetRevRangeByScoreWithScores('uid:' + uid + ':tids_read', 0, -1, '+inf', cutoff, next); } }, function(err, results) { if (err) { @@ -247,8 +249,9 @@ module.exports = function(Topics) { if (err) { return callback(err); } + var cutoff = Date.now() - unreadCutoff; var result = tids.map(function(tid, index) { - return !!(results.userScores[index] && results.userScores[index] >= results.recentScores[index]); + return results.recentScores[index] < cutoff || !!(results.userScores[index] && results.userScores[index] >= results.recentScores[index]); }); callback(null, result);