all files / src/categories/ activeusers.js

41.67% Statements 5/12
0% Branches 0/2
14.29% Functions 1/7
41.67% Lines 5/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29                                               
'use strict';
 
var async = require('async');
var posts = require('../posts');
var db = require('../database');
 
module.exports = function(Categories) {
 
	Categories.getActiveUsers = function(cid, callback) {
		async.waterfall([
			function (next) {
				db.getSortedSetRevRange('cid:' + cid + ':pids', 0, 24, next);
			},
			function (pids, next) {
				posts.getPostsFields(pids, ['uid'], next);
			},
			function (posts, next) {
				var uids = posts.map(function(post) {
					return post.uid;
				}).filter(function(uid, index, array) {
					return parseInt(uid, 10) && array.indexOf(uid) === index;
				});
 
				next(null, uids);
			}
		], callback);
	};
};