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