mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 14:35:47 +01:00
closes #5405
This commit is contained in:
@@ -40,7 +40,15 @@ unreadController.get = function (req, res, next) {
|
||||
settings = results.settings;
|
||||
var start = Math.max(0, (page - 1) * settings.topicsPerPage);
|
||||
var stop = start + settings.topicsPerPage - 1;
|
||||
topics.getUnreadTopics(cid, req.uid, start, stop, filter, next);
|
||||
var cutoff = req.session.unreadCutoff ? req.session.unreadCutoff : topics.unreadCutoff();
|
||||
topics.getUnreadTopics({
|
||||
cid: cid,
|
||||
uid: req.uid,
|
||||
start: start,
|
||||
stop: stop,
|
||||
filter: filter,
|
||||
cutoff: cutoff
|
||||
}, next);
|
||||
}
|
||||
], function (err, data) {
|
||||
if (err) {
|
||||
|
||||
@@ -98,7 +98,7 @@ module.exports = function (SocketTopics) {
|
||||
var start = parseInt(data.after, 10);
|
||||
var stop = start + 9;
|
||||
|
||||
topics.getUnreadTopics(data.cid, socket.uid, start, stop, data.filter, callback);
|
||||
topics.getUnreadTopics({cid: data.cid, uid: socket.uid, start: start, stop: stop, filter: data.filter}, callback);
|
||||
};
|
||||
|
||||
SocketTopics.loadMoreRecentTopics = function (socket, data, callback) {
|
||||
|
||||
@@ -51,7 +51,7 @@ module.exports = function (SocketTopics) {
|
||||
SocketTopics.markCategoryTopicsRead = function (socket, cid, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
topics.getUnreadTids(cid, socket.uid, '', next);
|
||||
topics.getUnreadTids({cid: cid, uid: socket.uid, filter: ''}, next);
|
||||
},
|
||||
function (tids, next) {
|
||||
SocketTopics.markAsRead(socket, tids, next);
|
||||
|
||||
@@ -18,14 +18,13 @@ module.exports = function (Topics) {
|
||||
callback = filter;
|
||||
filter = '';
|
||||
}
|
||||
Topics.getUnreadTids(0, uid, filter, function (err, tids) {
|
||||
Topics.getUnreadTids({cid: 0, uid: uid, filter: filter}, function (err, tids) {
|
||||
callback(err, Array.isArray(tids) ? tids.length : 0);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Topics.getUnreadTopics = function (cid, uid, start, stop, filter, callback) {
|
||||
|
||||
Topics.getUnreadTopics = function (params, callback) {
|
||||
var unreadTopics = {
|
||||
showSelect: true,
|
||||
nextStart : 0,
|
||||
@@ -34,7 +33,7 @@ module.exports = function (Topics) {
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Topics.getUnreadTids(cid, uid, filter, next);
|
||||
Topics.getUnreadTids(params, next);
|
||||
},
|
||||
function (tids, next) {
|
||||
unreadTopics.topicCount = tids.length;
|
||||
@@ -43,13 +42,13 @@ module.exports = function (Topics) {
|
||||
return next(null, []);
|
||||
}
|
||||
|
||||
if (stop === -1) {
|
||||
tids = tids.slice(start);
|
||||
if (params.stop === -1) {
|
||||
tids = tids.slice(params.start);
|
||||
} else {
|
||||
tids = tids.slice(start, stop + 1);
|
||||
tids = tids.slice(params.start, params.stop + 1);
|
||||
}
|
||||
|
||||
Topics.getTopicsByTids(tids, uid, next);
|
||||
Topics.getTopicsByTids(tids, params.uid, next);
|
||||
},
|
||||
function (topicData, next) {
|
||||
if (!Array.isArray(topicData) || !topicData.length) {
|
||||
@@ -57,7 +56,7 @@ module.exports = function (Topics) {
|
||||
}
|
||||
|
||||
unreadTopics.topics = topicData;
|
||||
unreadTopics.nextStart = stop + 1;
|
||||
unreadTopics.nextStart = params.stop + 1;
|
||||
next(null, unreadTopics);
|
||||
}
|
||||
], callback);
|
||||
@@ -67,21 +66,19 @@ module.exports = function (Topics) {
|
||||
return Date.now() - (parseInt(meta.config.unreadCutoff, 10) || 2) * 86400000;
|
||||
};
|
||||
|
||||
Topics.getUnreadTids = function (cid, uid, filter, callback) {
|
||||
uid = parseInt(uid, 10);
|
||||
Topics.getUnreadTids = function (params, callback) {
|
||||
var uid = parseInt(params.uid, 10);
|
||||
if (uid === 0) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
var cutoff = Topics.unreadCutoff();
|
||||
|
||||
var cutoff = params.cutoff || Topics.unreadCutoff();
|
||||
var ignoredCids;
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
ignoredCids: function (next) {
|
||||
if (filter === 'watched') {
|
||||
if (params.filter === 'watched') {
|
||||
return next(null, []);
|
||||
}
|
||||
user.getIgnoredCategories(uid, next);
|
||||
@@ -121,7 +118,7 @@ module.exports = function (Topics) {
|
||||
if (results.ignoredTids.indexOf(recentTopic.value.toString()) !== -1) {
|
||||
return false;
|
||||
}
|
||||
switch (filter) {
|
||||
switch (params.filter) {
|
||||
case 'new':
|
||||
return !userRead[recentTopic.value];
|
||||
default:
|
||||
@@ -133,7 +130,7 @@ module.exports = function (Topics) {
|
||||
return array.indexOf(tid) === index;
|
||||
});
|
||||
|
||||
if (filter === 'watched') {
|
||||
if (params.filter === 'watched') {
|
||||
Topics.filterWatchedTids(tids, uid, next);
|
||||
} else {
|
||||
next(null, tids);
|
||||
@@ -143,7 +140,7 @@ module.exports = function (Topics) {
|
||||
|
||||
tids = tids.slice(0, 200);
|
||||
|
||||
filterTopics(uid, tids, cid, ignoredCids, filter, next);
|
||||
filterTopics(uid, tids, params.cid, ignoredCids, params.filter, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -482,7 +482,7 @@ describe('Topic\'s', function () {
|
||||
topics.ignore( newTid, uid, done );
|
||||
},
|
||||
function (done) {
|
||||
topics.getUnreadTopics(0, uid, 0, -1, '', done );
|
||||
topics.getUnreadTopics({cid: 0, uid: uid, start: 0, stop: -1, filter: ''}, done );
|
||||
},
|
||||
function (results, done) {
|
||||
var topics = results.topics;
|
||||
@@ -526,7 +526,7 @@ describe('Topic\'s', function () {
|
||||
topics.follow( newTid, uid, done );
|
||||
},
|
||||
function (done) {
|
||||
topics.getUnreadTopics(0, uid, 0, -1, '', done );
|
||||
topics.getUnreadTopics({cid: 0, uid: uid, start: 0, stop: -1, filter: ''}, done );
|
||||
},
|
||||
function (results, done) {
|
||||
var topics = results.topics;
|
||||
@@ -546,7 +546,7 @@ describe('Topic\'s', function () {
|
||||
topics.follow( newTid, uid, done );
|
||||
},
|
||||
function (done) {
|
||||
topics.getUnreadTopics(0, uid, 0, -1, '', done );
|
||||
topics.getUnreadTopics({cid: 0, uid: uid, start: 0, stop: -1, filter: ''}, done );
|
||||
},
|
||||
function (results, done) {
|
||||
var topics = results.topics;
|
||||
|
||||
Reference in New Issue
Block a user