mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	use _.uniq
This commit is contained in:
		| @@ -28,11 +28,9 @@ module.exports = function (Posts) { | ||||
| 			}, | ||||
| 			function (_postData, next) { | ||||
| 				postData = _postData; | ||||
| 				tids = postData.map(function (post) { | ||||
| 					return post.tid; | ||||
| 				}).filter(function (tid, index, array) { | ||||
| 					return tid && array.indexOf(tid) === index; | ||||
| 				}); | ||||
| 				tids = _.uniq(postData.map(function (post) { | ||||
| 					return post && post.tid; | ||||
| 				}).filter(Boolean)); | ||||
|  | ||||
| 				topics.getTopicsFields(tids, ['cid'], next); | ||||
| 			}, | ||||
|   | ||||
| @@ -232,9 +232,7 @@ module.exports = function (privileges) { | ||||
| 			return callback(null, []); | ||||
| 		} | ||||
|  | ||||
| 		cids = cids.filter(function (cid, index, array) { | ||||
| 			return array.indexOf(cid) === index; | ||||
| 		}); | ||||
| 		cids = _.uniq(cids); | ||||
|  | ||||
| 		async.waterfall([ | ||||
| 			function (next) { | ||||
|   | ||||
| @@ -2,6 +2,7 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| var async = require('async'); | ||||
| var _ = require('lodash'); | ||||
|  | ||||
| var meta = require('../meta'); | ||||
| var posts = require('../posts'); | ||||
| @@ -72,17 +73,18 @@ module.exports = function (privileges) { | ||||
| 		var tids; | ||||
| 		var tidToTopic = {}; | ||||
|  | ||||
| 		pids = _.uniq(pids); | ||||
|  | ||||
| 		async.waterfall([ | ||||
| 			function (next) { | ||||
| 				posts.getPostsFields(pids, ['uid', 'tid', 'deleted'], next); | ||||
| 			}, | ||||
| 			function (_posts, next) { | ||||
| 				postData = _posts; | ||||
| 				tids = _posts.map(function (post) { | ||||
| 				tids = _.uniq(_posts.map(function (post) { | ||||
| 					return post && post.tid; | ||||
| 				}).filter(function (tid, index, array) { | ||||
| 					return tid && array.indexOf(tid) === index; | ||||
| 				}); | ||||
| 				}).filter(Boolean)); | ||||
|  | ||||
| 				topics.getTopicsFields(tids, ['deleted', 'cid'], next); | ||||
| 			}, | ||||
| 			function (topicData, next) { | ||||
|   | ||||
| @@ -2,6 +2,7 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| var async = require('async'); | ||||
| var _ = require('lodash'); | ||||
|  | ||||
| var user = require('../user'); | ||||
| var groups = require('../groups'); | ||||
| @@ -51,9 +52,7 @@ module.exports = function (privileges) { | ||||
| 					return filterIsModerator(cids, uid, cids.map(function () { return true; }), callback); | ||||
| 				} | ||||
|  | ||||
| 				uniqueCids = cids.filter(function (cid, index, array) { | ||||
| 					return array.indexOf(cid) === index; | ||||
| 				}); | ||||
| 				uniqueCids = _.uniq(cids); | ||||
|  | ||||
| 				helpers.isUserAllowedTo('moderate', uid, uniqueCids, next); | ||||
| 			}, | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| var async = require('async'); | ||||
| var _ = require('lodash'); | ||||
|  | ||||
| var db = require('./database'); | ||||
| var posts = require('./posts'); | ||||
| @@ -79,9 +80,7 @@ function searchInContent(data, callback) { | ||||
| 		function (mainPids, next) { | ||||
| 			pids = mainPids.concat(pids).map(function (pid) { | ||||
| 				return pid && pid.toString(); | ||||
| 			}).filter(function (pid, index, array) { | ||||
| 				return pid && array.indexOf(pid) === index; | ||||
| 			}); | ||||
| 			}).filter(Boolean); | ||||
|  | ||||
| 			privileges.posts.filter('read', pids, data.uid, next); | ||||
| 		}, | ||||
| @@ -392,9 +391,8 @@ function getSearchCids(data, callback) { | ||||
| 			}, next); | ||||
| 		}, | ||||
| 		function (results, next) { | ||||
| 			var cids = results.watchedCids.concat(results.childrenCids).concat(data.categories).filter(function (cid, index, array) { | ||||
| 				return cid && array.indexOf(cid) === index; | ||||
| 			}); | ||||
| 			var cids = results.watchedCids.concat(results.childrenCids).concat(data.categories).filter(Boolean); | ||||
| 			cids = _.uniq(cids); | ||||
| 			next(null, cids); | ||||
| 		}, | ||||
| 	], callback); | ||||
|   | ||||
| @@ -101,14 +101,14 @@ Topics.getTopicsByTids = function (tids, uid, callback) { | ||||
| 			function mapFilter(array, field) { | ||||
| 				return array.map(function (topic) { | ||||
| 					return topic && topic[field] && topic[field].toString(); | ||||
| 				}).filter(function (value, index, array) { | ||||
| 					return utils.isNumber(value) && array.indexOf(value) === index; | ||||
| 				}).filter(function (value) { | ||||
| 					return utils.isNumber(value); | ||||
| 				}); | ||||
| 			} | ||||
|  | ||||
| 			topics = _topics; | ||||
| 			uids = mapFilter(topics, 'uid'); | ||||
| 			cids = mapFilter(topics, 'cid'); | ||||
| 			uids = _.uniq(mapFilter(topics, 'uid')); | ||||
| 			cids = _.uniq(mapFilter(topics, 'cid')); | ||||
|  | ||||
| 			async.parallel({ | ||||
| 				users: function (next) { | ||||
|   | ||||
| @@ -25,8 +25,8 @@ module.exports = function (Topics) { | ||||
| 			}, | ||||
| 			function (results, next) { | ||||
| 				var tids = results.tagTids.concat(results.searchTids).concat(results.categoryTids); | ||||
| 				tids = tids.filter(function (_tid, index, array) { | ||||
| 					return parseInt(_tid, 10) !== parseInt(tid, 10) && array.indexOf(_tid) === index; | ||||
| 				tids = _.uniq(tids).filter(function (_tid) { | ||||
| 					return parseInt(_tid, 10) !== parseInt(tid, 10); | ||||
| 				}); | ||||
|  | ||||
| 				if (stop === -1) { | ||||
|   | ||||
| @@ -23,11 +23,12 @@ module.exports = function (Topics) { | ||||
| 				plugins.fireHook('filter:tags.filter', { tags: tags, tid: tid }, next); | ||||
| 			}, | ||||
| 			function (data, next) { | ||||
| 				tags = data.tags.slice(0, meta.config.maximumTagsPerTopic || 5); | ||||
| 				tags = _.uniq(data.tags); | ||||
| 				tags = tags.slice(0, meta.config.maximumTagsPerTopic || 5); | ||||
| 				tags = tags.map(function (tag) { | ||||
| 					return utils.cleanUpTag(tag, meta.config.maximumTagLength); | ||||
| 				}).filter(function (tag, index, array) { | ||||
| 					return tag && tag.length >= (meta.config.minimumTagLength || 3) && array.indexOf(tag) === index; | ||||
| 				}).filter(function (tag) { | ||||
| 					return tag && tag.length >= (meta.config.minimumTagLength || 3); | ||||
| 				}); | ||||
|  | ||||
| 				filterCategoryTags(tags, tid, next); | ||||
|   | ||||
| @@ -2,6 +2,7 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| var async = require('async'); | ||||
| var _ = require('lodash'); | ||||
| var S = require('string'); | ||||
| var winston = require('winston'); | ||||
|  | ||||
| @@ -57,11 +58,9 @@ module.exports = function (Topics) { | ||||
| 			}, | ||||
| 			function (_postData, next) { | ||||
| 				postData = _postData; | ||||
| 				var uids = postData.map(function (post) { | ||||
| 				var uids = _.uniq(postData.map(function (post) { | ||||
| 					return post.uid; | ||||
| 				}).filter(function (uid, index, array) { | ||||
| 					return array.indexOf(uid) === index; | ||||
| 				}); | ||||
| 				})); | ||||
|  | ||||
| 				user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], next); | ||||
| 			}, | ||||
|   | ||||
| @@ -2,6 +2,7 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| var async = require('async'); | ||||
| var _ = require('lodash'); | ||||
|  | ||||
| var db = require('../database'); | ||||
| var user = require('../user'); | ||||
| @@ -118,10 +119,10 @@ module.exports = function (Topics) { | ||||
| 					} | ||||
| 				}).map(function (topic) { | ||||
| 					return topic.value; | ||||
| 				}).filter(function (tid, index, array) { | ||||
| 					return array.indexOf(tid) === index; | ||||
| 				}); | ||||
|  | ||||
| 				tids = _.uniq(tids); | ||||
|  | ||||
| 				if (params.filter === 'watched') { | ||||
| 					Topics.filterWatchedTids(tids, uid, next); | ||||
| 				} else { | ||||
| @@ -222,8 +223,8 @@ module.exports = function (Topics) { | ||||
| 			return setImmediate(callback, null, false); | ||||
| 		} | ||||
|  | ||||
| 		tids = tids.filter(function (tid, index, array) { | ||||
| 			return tid && utils.isNumber(tid) && array.indexOf(tid) === index; | ||||
| 		tids = _.uniq(tids).filter(function (tid) { | ||||
| 			return tid && utils.isNumber(tid); | ||||
| 		}); | ||||
|  | ||||
| 		if (!tids.length) { | ||||
| @@ -260,9 +261,9 @@ module.exports = function (Topics) { | ||||
| 			function (results, next) { | ||||
| 				var cids = results.topicData.map(function (topic) { | ||||
| 					return topic && topic.cid; | ||||
| 				}).filter(function (topic, index, array) { | ||||
| 					return topic && array.indexOf(topic) === index; | ||||
| 				}); | ||||
| 				}).filter(Boolean); | ||||
|  | ||||
| 				cids = _.uniq(cids); | ||||
|  | ||||
| 				categories.markAsRead(cids, uid, next); | ||||
| 			}, | ||||
|   | ||||
| @@ -64,9 +64,7 @@ User.getUsersWithFields = function (uids, fields, uid, callback) { | ||||
| 			plugins.fireHook('filter:users.addFields', { fields: fields }, next); | ||||
| 		}, | ||||
| 		function (data, next) { | ||||
| 			data.fields = data.fields.filter(function (field, index, array) { | ||||
| 				return array.indexOf(field) === index; | ||||
| 			}); | ||||
| 			data.fields = _.uniq(data.fields); | ||||
|  | ||||
| 			async.parallel({ | ||||
| 				userData: function (next) { | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| var async = require('async'); | ||||
| var _ = require('lodash'); | ||||
|  | ||||
| var db = require('../database'); | ||||
| var posts = require('../posts'); | ||||
| @@ -152,9 +153,7 @@ module.exports = function (User) { | ||||
| 				}, next); | ||||
| 			}, | ||||
| 			function (pids, next) { | ||||
| 				pids = pids.upvotedPids.concat(pids.downvotedPids).filter(function (pid, index, array) { | ||||
| 					return pid && array.indexOf(pid) === index; | ||||
| 				}); | ||||
| 				pids = _.uniq(pids.upvotedPids.concat(pids.downvotedPids).filter(Boolean)); | ||||
|  | ||||
| 				async.eachSeries(pids, function (pid, next) { | ||||
| 					posts.unvote(pid, uid, next); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user