mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
closes #3128
This commit is contained in:
@@ -6,5 +6,8 @@
|
||||
"selected": "Selected",
|
||||
"all": "All",
|
||||
"all_categories": "All categories",
|
||||
"topics_marked_as_read.success": "Topics marked as read!"
|
||||
"topics_marked_as_read.success": "Topics marked as read!",
|
||||
"all-topics": "All Topics",
|
||||
"new-topics": "New Topics",
|
||||
"watched-topics": "Watched Topics"
|
||||
}
|
||||
@@ -5,14 +5,14 @@ var async = require('async');
|
||||
var meta = require('../meta');
|
||||
var categories = require('../categories');
|
||||
var privileges = require('../privileges');
|
||||
var user = require('../user')
|
||||
var user = require('../user');
|
||||
var topics = require('../topics');
|
||||
var helpers = require('./helpers');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
var unreadController = {};
|
||||
|
||||
var validFilter = {'': true, 'new': true};
|
||||
var validFilter = {'': true, 'new': true, 'watched': true};
|
||||
|
||||
unreadController.get = function(req, res, next) {
|
||||
var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1;
|
||||
@@ -57,6 +57,23 @@ unreadController.get = function(req, res, next) {
|
||||
|
||||
results.unreadTopics.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[unread:title]]'}]);
|
||||
results.unreadTopics.title = '[[pages:unread]]';
|
||||
results.unreadTopics.filters = [{
|
||||
name: '[[unread:all-topics]]',
|
||||
url: 'unread',
|
||||
selected: filter === ''
|
||||
}, {
|
||||
name: '[[unread:new-topics]]',
|
||||
url: 'unread/new',
|
||||
selected: filter === 'new'
|
||||
}, {
|
||||
name: '[[unread:watched-topics]]',
|
||||
url: 'unread/watched',
|
||||
selected: filter === 'watched'
|
||||
}];
|
||||
|
||||
results.unreadTopics.selectedFilter = results.unreadTopics.filters.filter(function(filter) {
|
||||
return filter && filter.selected;
|
||||
})[0];
|
||||
|
||||
plugins.fireHook('filter:unread.build', {req: req, res: res, templateData: results.unreadTopics}, next);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ module.exports = function(Topics) {
|
||||
filter = '';
|
||||
}
|
||||
|
||||
|
||||
var unreadTopics = {
|
||||
showSelect: true,
|
||||
nextStart : 0,
|
||||
@@ -77,8 +76,15 @@ module.exports = function(Topics) {
|
||||
|
||||
var cutoff = Topics.unreadCutoff();
|
||||
|
||||
var ignoredCids;
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
ignoredCids: function(next) {
|
||||
if (filter === 'watched') {
|
||||
return next(null, []);
|
||||
}
|
||||
user.getIgnoredCategories(uid, next);
|
||||
},
|
||||
recentTids: function(next) {
|
||||
@@ -90,15 +96,15 @@ module.exports = function(Topics) {
|
||||
tids_unread: function(next) {
|
||||
db.getSortedSetRevRangeWithScores('uid:' + uid + ':tids_unread', 0, -1, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
if (results.recentTids && !results.recentTids.length && !results.tids_unread.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
ignoredCids = results.ignoredCids;
|
||||
|
||||
var userRead = {};
|
||||
results.userScores.forEach(function(userItem) {
|
||||
userRead[userItem.value] = userItem.score;
|
||||
@@ -111,10 +117,10 @@ module.exports = function(Topics) {
|
||||
|
||||
var tids = results.recentTids.filter(function(recentTopic) {
|
||||
switch (filter) {
|
||||
default:
|
||||
return !userRead[recentTopic.value] || recentTopic.score > userRead[recentTopic.value];
|
||||
case 'new':
|
||||
return !userRead[recentTopic.value];
|
||||
default:
|
||||
return !userRead[recentTopic.value] || recentTopic.score > userRead[recentTopic.value];
|
||||
}
|
||||
}).map(function(topic) {
|
||||
return topic.value;
|
||||
@@ -122,12 +128,19 @@ module.exports = function(Topics) {
|
||||
return array.indexOf(tid) === index;
|
||||
});
|
||||
|
||||
if (filter === 'watched') {
|
||||
filterWatchedTids(uid, tids, next);
|
||||
} else {
|
||||
next(null, tids);
|
||||
}
|
||||
},
|
||||
function (tids, next) {
|
||||
|
||||
tids = tids.slice(0, 100);
|
||||
|
||||
filterTopics(uid, tids, cid, results.ignoredCids, function(err, tids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
filterTopics(uid, tids, cid, ignoredCids, next);
|
||||
},
|
||||
function (tids, next) {
|
||||
|
||||
if (stop === -1) {
|
||||
tids = tids.slice(start);
|
||||
@@ -135,10 +148,22 @@ module.exports = function(Topics) {
|
||||
tids = tids.slice(start, stop + 1);
|
||||
}
|
||||
|
||||
next(null, tids);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
function filterWatchedTids(uid, tids, callback) {
|
||||
db.sortedSetScores('uid:' + uid + ':followed_tids', tids, function(err, scores) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
tids = tids.filter(function(tid, index) {
|
||||
return tid && !!scores[index];
|
||||
});
|
||||
callback(null, tids);
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function filterTopics(uid, tids, cid, ignoredCids, callback) {
|
||||
if (!Array.isArray(ignoredCids) || !tids.length) {
|
||||
|
||||
Reference in New Issue
Block a user