mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	allow filtering /unread to only topics that have not yet been seen
This commit is contained in:
		| @@ -16,6 +16,7 @@ unreadController.get = function(req, res, next) { | |||||||
| 	var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1; | 	var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1; | ||||||
| 	var results; | 	var results; | ||||||
| 	var cid = req.query.cid; | 	var cid = req.query.cid; | ||||||
|  | 	var seen = !req.query.unseen; | ||||||
|  |  | ||||||
| 	async.waterfall([ | 	async.waterfall([ | ||||||
| 		function(next) { | 		function(next) { | ||||||
| @@ -24,7 +25,7 @@ unreadController.get = function(req, res, next) { | |||||||
| 					user.getWatchedCategories(req.uid, next); | 					user.getWatchedCategories(req.uid, next); | ||||||
| 				}, | 				}, | ||||||
| 				unreadTopics: function(next) { | 				unreadTopics: function(next) { | ||||||
| 					topics.getUnreadTopics(cid, req.uid, 0, stop, next); | 					topics.getUnreadTopics(cid, req.uid, 0, stop, seen, next); | ||||||
| 				} | 				} | ||||||
| 			}, next); | 			}, next); | ||||||
| 		}, | 		}, | ||||||
| @@ -64,7 +65,7 @@ unreadController.get = function(req, res, next) { | |||||||
|  |  | ||||||
|  |  | ||||||
| unreadController.unreadTotal = 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) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -14,13 +14,23 @@ var utils = require('../../public/src/utils'); | |||||||
|  |  | ||||||
| module.exports = function(Topics) { | module.exports = function(Topics) { | ||||||
|  |  | ||||||
| 	Topics.getTotalUnread = function(uid, callback) { | 	Topics.getTotalUnread = function(uid, allowSeen, callback) { | ||||||
| 		Topics.getUnreadTids(0, uid, 0, 99, function(err, tids) { | 		if (!callback) { | ||||||
|  | 			callback = allowSeen; | ||||||
|  | 			allowSeen = true; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		Topics.getUnreadTids(0, uid, 0, 99, allowSeen, function(err, tids) { | ||||||
| 			callback(err, tids ? tids.length : 0); | 			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 = { | 		var unreadTopics = { | ||||||
| 			showSelect: true, | 			showSelect: true, | ||||||
| @@ -30,7 +40,7 @@ module.exports = function(Topics) { | |||||||
|  |  | ||||||
| 		async.waterfall([ | 		async.waterfall([ | ||||||
| 			function(next) { | 			function(next) { | ||||||
| 				Topics.getUnreadTids(cid, uid, start, stop, next); | 				Topics.getUnreadTids(cid, uid, start, stop, allowSeen, next); | ||||||
| 			}, | 			}, | ||||||
| 			function(tids, next) { | 			function(tids, next) { | ||||||
| 				if (!tids.length) { | 				if (!tids.length) { | ||||||
| @@ -54,7 +64,12 @@ module.exports = function(Topics) { | |||||||
| 		return Date.now() - (parseInt(meta.config.unreadCutoff, 10) || 2) * 86400000; | 		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); | 		uid = parseInt(uid, 10); | ||||||
| 		if (uid === 0) { | 		if (uid === 0) { | ||||||
| 			return callback(null, []); | 			return callback(null, []); | ||||||
| @@ -95,7 +110,7 @@ module.exports = function(Topics) { | |||||||
| 			}); | 			}); | ||||||
|  |  | ||||||
| 			var tids = results.recentTids.filter(function(recentTopic) { | 			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) { | 			}).map(function(topic) { | ||||||
| 				return topic.value; | 				return topic.value; | ||||||
| 			}).filter(function(tid, index, array) { | 			}).filter(function(tid, index, array) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user