| 
									
										
										
										
											2014-03-01 16:59:04 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-17 20:15:14 +02:00
										 |  |  | var async = require('async'); | 
					
						
							| 
									
										
										
										
											2014-11-08 23:54:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-17 20:15:14 +02:00
										 |  |  | var db = require('./database'); | 
					
						
							|  |  |  | var user = require('./user'); | 
					
						
							|  |  |  | var Groups = require('./groups'); | 
					
						
							|  |  |  | var plugins = require('./plugins'); | 
					
						
							| 
									
										
										
										
											2016-08-27 01:52:08 +03:00
										 |  |  | var privileges = require('./privileges'); | 
					
						
							| 
									
										
										
										
											2013-05-09 01:04:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | var Categories = module.exports; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require('./categories/data')(Categories); | 
					
						
							|  |  |  | require('./categories/create')(Categories); | 
					
						
							|  |  |  | require('./categories/delete')(Categories); | 
					
						
							|  |  |  | require('./categories/topics')(Categories); | 
					
						
							|  |  |  | require('./categories/unread')(Categories); | 
					
						
							|  |  |  | require('./categories/activeusers')(Categories); | 
					
						
							|  |  |  | require('./categories/recentreplies')(Categories); | 
					
						
							|  |  |  | require('./categories/update')(Categories); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.exists = function (cid, callback) { | 
					
						
							|  |  |  | 	db.isSortedSetMember('categories:cid', cid, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.getCategoryById = function (data, callback) { | 
					
						
							|  |  |  | 	var category; | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			Categories.getCategories([data.cid], data.uid, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (categories, next) { | 
					
						
							| 
									
										
										
										
											2017-05-27 00:47:04 -04:00
										 |  |  | 			if (!categories[0]) { | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 				return next(new Error('[[error:invalid-cid]]')); | 
					
						
							| 
									
										
										
										
											2014-01-24 22:26:11 -05:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 			category = categories[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			async.parallel({ | 
					
						
							|  |  |  | 				topics: function (next) { | 
					
						
							|  |  |  | 					Categories.getCategoryTopics(data, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				topicCount: function (next) { | 
					
						
							|  |  |  | 					if (Array.isArray(data.set)) { | 
					
						
							|  |  |  | 						db.sortedSetIntersectCard(data.set, next); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						next(null, category.topic_count); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				isIgnored: function (next) { | 
					
						
							|  |  |  | 					Categories.isIgnored([data.cid], data.uid, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			}, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (results, next) { | 
					
						
							|  |  |  | 			category.topics = results.topics.topics; | 
					
						
							|  |  |  | 			category.nextStart = results.topics.nextStart; | 
					
						
							|  |  |  | 			category.isIgnored = results.isIgnored[0]; | 
					
						
							|  |  |  | 			category.topic_count = results.topicCount; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			plugins.fireHook('filter:category.get', { category: category, uid: data.uid }, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (data, next) { | 
					
						
							|  |  |  | 			next(null, data.category); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.isIgnored = function (cids, uid, callback) { | 
					
						
							|  |  |  | 	db.isSortedSetMembers('uid:' + uid + ':ignored:cids', cids, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.getPageCount = function (cid, uid, callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			async.parallel({ | 
					
						
							|  |  |  | 				topicCount: async.apply(Categories.getCategoryField, cid, 'topic_count'), | 
					
						
							|  |  |  | 				settings: async.apply(user.getSettings, uid), | 
					
						
							|  |  |  | 			}, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (results, next) { | 
					
						
							| 
									
										
										
										
											2014-11-09 00:33:26 -05:00
										 |  |  | 			if (!parseInt(results.topicCount, 10)) { | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 				return next(null, 1); | 
					
						
							| 
									
										
										
										
											2014-02-22 18:56:37 -05:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 			next(null, Math.ceil(parseInt(results.topicCount, 10) / results.settings.topicsPerPage)); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.getAllCategories = function (uid, callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			db.getSortedSetRange('categories:cid', 0, -1, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (cids, next) { | 
					
						
							|  |  |  | 			Categories.getCategories(cids, uid, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.getCategoriesByPrivilege = function (set, uid, privilege, callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			db.getSortedSetRange(set, 0, -1, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (cids, next) { | 
					
						
							|  |  |  | 			privileges.categories.filterCids(privilege, cids, uid, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (cids, next) { | 
					
						
							|  |  |  | 			Categories.getCategories(cids, uid, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.getModerators = function (cid, callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							| 
									
										
										
										
											2017-05-26 23:21:46 -04:00
										 |  |  | 			Groups.getMembers('cid:' + cid + ':privileges:moderate', 0, -1, next); | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		function (uids, next) { | 
					
						
							|  |  |  | 			user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-07-03 12:59:45 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | Categories.getCategories = function (cids, uid, callback) { | 
					
						
							|  |  |  | 	if (!Array.isArray(cids)) { | 
					
						
							|  |  |  | 		return callback(new Error('[[error:invalid-cid]]')); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-07-29 21:51:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 	if (!cids.length) { | 
					
						
							|  |  |  | 		return callback(null, []); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-08-20 12:11:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			async.parallel({ | 
					
						
							|  |  |  | 				categories: function (next) { | 
					
						
							|  |  |  | 					Categories.getCategoriesData(cids, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				children: function (next) { | 
					
						
							|  |  |  | 					Categories.getChildren(cids, uid, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				parents: function (next) { | 
					
						
							|  |  |  | 					Categories.getParents(cids, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				tagWhitelist: function (next) { | 
					
						
							|  |  |  | 					Categories.getTagWhitelist(cids, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				hasRead: function (next) { | 
					
						
							|  |  |  | 					Categories.hasReadCategories(cids, uid, next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			}, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (results, next) { | 
					
						
							| 
									
										
										
										
											2014-03-09 23:09:08 -04:00
										 |  |  | 			uid = parseInt(uid, 10); | 
					
						
							| 
									
										
										
										
											2016-12-09 18:53:08 +03:00
										 |  |  | 			results.categories.forEach(function (category, i) { | 
					
						
							|  |  |  | 				if (category) { | 
					
						
							|  |  |  | 					category['unread-class'] = (parseInt(category.topic_count, 10) === 0 || (results.hasRead[i] && uid !== 0)) ? '' : 'unread'; | 
					
						
							|  |  |  | 					category.children = results.children[i]; | 
					
						
							|  |  |  | 					category.parent = results.parents[i] || undefined; | 
					
						
							|  |  |  | 					category.tagWhitelist = results.tagWhitelist[i]; | 
					
						
							|  |  |  | 					calculateTopicPostCount(category); | 
					
						
							| 
									
										
										
										
											2014-09-01 18:46:42 -04:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-12-09 18:53:08 +03:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 			next(null, results.categories); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.getTagWhitelist = function (cids, callback) { | 
					
						
							|  |  |  | 	var keys = cids.map(function (cid) { | 
					
						
							|  |  |  | 		return 'cid:' + cid + ':tag:whitelist'; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	db.getSortedSetsMembers(keys, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function calculateTopicPostCount(category) { | 
					
						
							|  |  |  | 	if (!category) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-08-18 14:17:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 	var postCount = parseInt(category.post_count, 10) || 0; | 
					
						
							|  |  |  | 	var topicCount = parseInt(category.topic_count, 10) || 0; | 
					
						
							|  |  |  | 	if (!Array.isArray(category.children) || !category.children.length) { | 
					
						
							| 
									
										
										
										
											2015-05-17 15:53:42 -04:00
										 |  |  | 		category.totalPostCount = postCount; | 
					
						
							|  |  |  | 		category.totalTopicCount = topicCount; | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2015-04-19 15:18:55 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 	category.children.forEach(function (child) { | 
					
						
							|  |  |  | 		calculateTopicPostCount(child); | 
					
						
							|  |  |  | 		postCount += parseInt(child.totalPostCount, 10) || 0; | 
					
						
							|  |  |  | 		topicCount += parseInt(child.totalTopicCount, 10) || 0; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	category.totalPostCount = postCount; | 
					
						
							|  |  |  | 	category.totalTopicCount = topicCount; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.getParents = function (cids, callback) { | 
					
						
							|  |  |  | 	var categoriesData; | 
					
						
							|  |  |  | 	var parentCids; | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			Categories.getCategoriesFields(cids, ['parentCid'], next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (_categoriesData, next) { | 
					
						
							|  |  |  | 			categoriesData = _categoriesData; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			parentCids = categoriesData.filter(function (category) { | 
					
						
							|  |  |  | 				return category && category.hasOwnProperty('parentCid') && parseInt(category.parentCid, 10); | 
					
						
							|  |  |  | 			}).map(function (category) { | 
					
						
							|  |  |  | 				return parseInt(category.parentCid, 10); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2015-08-18 14:17:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 			if (!parentCids.length) { | 
					
						
							|  |  |  | 				return callback(null, cids.map(function () { return null; })); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-08-18 14:17:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 			Categories.getCategoriesData(parentCids, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (parentData, next) { | 
					
						
							|  |  |  | 			parentData = categoriesData.map(function (category) { | 
					
						
							|  |  |  | 				return parentData[parentCids.indexOf(parseInt(category.parentCid, 10))]; | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			next(null, parentData); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.getChildren = function (cids, uid, callback) { | 
					
						
							|  |  |  | 	var categories = cids.map(function (cid) { | 
					
						
							|  |  |  | 		return { cid: cid }; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	async.each(categories, function (category, next) { | 
					
						
							|  |  |  | 		getChildrenRecursive(category, uid, next); | 
					
						
							|  |  |  | 	}, function (err) { | 
					
						
							|  |  |  | 		callback(err, categories.map(function (c) { | 
					
						
							|  |  |  | 			return c && c.children; | 
					
						
							|  |  |  | 		})); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getChildrenRecursive(category, uid, callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			db.getSortedSetRange('cid:' + category.cid + ':children', 0, -1, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (children, next) { | 
					
						
							|  |  |  | 			privileges.categories.filterCids('find', children, uid, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (children, next) { | 
					
						
							|  |  |  | 			children = children.filter(function (cid) { | 
					
						
							|  |  |  | 				return parseInt(category.cid, 10) !== parseInt(cid, 10); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			if (!children.length) { | 
					
						
							|  |  |  | 				category.children = []; | 
					
						
							|  |  |  | 				return callback(); | 
					
						
							| 
									
										
										
										
											2015-08-18 14:17:16 -04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 			Categories.getCategoriesData(children, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (childrenData, next) { | 
					
						
							|  |  |  | 			childrenData = childrenData.filter(Boolean); | 
					
						
							|  |  |  | 			category.children = childrenData; | 
					
						
							|  |  |  | 			async.each(category.children, function (child, next) { | 
					
						
							|  |  |  | 				getChildrenRecursive(child, uid, next); | 
					
						
							|  |  |  | 			}, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.flattenCategories = function (allCategories, categoryData) { | 
					
						
							|  |  |  | 	categoryData.forEach(function (category) { | 
					
						
							|  |  |  | 		if (category) { | 
					
						
							|  |  |  | 			if (!category.parent) { | 
					
						
							|  |  |  | 				allCategories.push(category); | 
					
						
							| 
									
										
										
										
											2015-06-04 14:24:33 -04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-05-30 18:44:31 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 			if (Array.isArray(category.children) && category.children.length) { | 
					
						
							|  |  |  | 				Categories.flattenCategories(allCategories, category.children); | 
					
						
							| 
									
										
										
										
											2015-06-04 14:24:33 -04:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Recursively build tree | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param categories {array} flat list of categories | 
					
						
							|  |  |  |  * @param parentCid {number} start from 0 to build full tree | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | Categories.getTree = function (categories, parentCid) { | 
					
						
							|  |  |  | 	var tree = []; | 
					
						
							|  |  |  | 	var i = 0; | 
					
						
							|  |  |  | 	var len = categories.length; | 
					
						
							|  |  |  | 	var category; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i; i < len; i += 1) { | 
					
						
							|  |  |  | 		category = categories[i]; | 
					
						
							|  |  |  | 		if (!category.hasOwnProperty('parentCid') || category.parentCid === null) { | 
					
						
							|  |  |  | 			category.parentCid = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-05-30 18:44:31 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 		if (parseInt(category.parentCid, 10) === parseInt(parentCid, 10)) { | 
					
						
							|  |  |  | 			tree.push(category); | 
					
						
							|  |  |  | 			category.children = Categories.getTree(categories, category.cid); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-05-30 18:44:31 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 	return tree; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-09-16 14:20:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | Categories.buildForSelect = function (uid, callback) { | 
					
						
							| 
									
										
										
										
											2017-05-30 14:10:12 -04:00
										 |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			Categories.getCategoriesByPrivilege('cid:0:children', uid, 'read', next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (categories, next) { | 
					
						
							|  |  |  | 			Categories.buildForSelectCategories(categories, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.buildForSelectCategories = function (categories, callback) { | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 	function recursive(category, categoriesData, level) { | 
					
						
							|  |  |  | 		if (category.link) { | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-09-16 14:20:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | 		var bullet = level ? '• ' : ''; | 
					
						
							|  |  |  | 		category.value = category.cid; | 
					
						
							|  |  |  | 		category.text = level + bullet + category.name; | 
					
						
							|  |  |  | 		categoriesData.push(category); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		category.children.forEach(function (child) { | 
					
						
							|  |  |  | 			recursive(child, categoriesData, '    ' + level); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-09-16 14:20:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-30 14:10:12 -04:00
										 |  |  | 	var categoriesData = []; | 
					
						
							| 
									
										
										
										
											2016-09-16 14:20:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-30 14:10:12 -04:00
										 |  |  | 	categories = categories.filter(function (category) { | 
					
						
							|  |  |  | 		return category && !category.link && !parseInt(category.parentCid, 10); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	categories.forEach(function (category) { | 
					
						
							|  |  |  | 		recursive(category, categoriesData, ''); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	callback(null, categoriesData); | 
					
						
							| 
									
										
										
										
											2017-05-26 16:56:26 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.getIgnorers = function (cid, start, stop, callback) { | 
					
						
							|  |  |  | 	db.getSortedSetRevRange('cid:' + cid + ':ignorers', start, stop, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.filterIgnoringUids = function (cid, uids, callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function (next) { | 
					
						
							|  |  |  | 			db.isSortedSetMembers('cid:' + cid + ':ignorers', uids, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (isIgnoring, next) { | 
					
						
							|  |  |  | 			var readingUids = uids.filter(function (uid, index) { | 
					
						
							|  |  |  | 				return uid && !isIgnoring[index]; | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			next(null, readingUids); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	], callback); | 
					
						
							|  |  |  | }; |