user.js: ladies and gentlemen, I'm going to satisfy jshint right before your eyes!

v1.18.x
Denis Wolf 11 years ago
parent 05de4870b0
commit b179991be4

@ -1,6 +1,5 @@
var utils = require('./../public/src/utils.js'), var utils = require('./../public/src/utils.js'),
RDB = require('./redis.js'), RDB = require('./redis.js'),
crypto = require('crypto'),
emailjs = require('emailjs'), emailjs = require('emailjs'),
meta = require('./meta.js'), meta = require('./meta.js'),
emailjsServer = emailjs.server.connect(meta.config['email:smtp:host'] || '127.0.0.1'), emailjsServer = emailjs.server.connect(meta.config['email:smtp:host'] || '127.0.0.1'),
@ -10,26 +9,36 @@ var utils = require('./../public/src/utils.js'),
topics = require('./topics.js'), topics = require('./topics.js'),
async = require('async'), async = require('async'),
nconf = require('nconf'), nconf = require('nconf'),
userSearch = require('reds').createSearch('nodebbusersearch'); userSearch = require('reds').createSearch('nodebbusersearch'),
winston = require('winston');
(function(User) { (function(User) {
'use strict';
User.create = function(username, password, email, callback) { User.create = function(username, password, email, callback) {
var userslug = utils.slugify(username); var userslug = utils.slugify(username);
username = username.trim(); username = username.trim();
if (email !== undefined) email = email.trim(); if (email !== undefined) {
email = email.trim();
}
async.parallel([ async.parallel([
function(next) { function(next) {
if (email !== undefined) next(!utils.isEmailValid(email) ? new Error('Invalid Email!') : null); if (email !== undefined) {
else next(); next(!utils.isEmailValid(email) ? new Error('Invalid Email!') : null);
}else {
next();
}
}, },
function(next) { function(next) {
next(!utils.isUserNameValid(username) ? new Error('Invalid Username!') : null); next(!utils.isUserNameValid(username) ? new Error('Invalid Username!') : null);
}, },
function(next) { function(next) {
if (password !== undefined) next(!utils.isPasswordValid(password) ? new Error('Invalid Password!') : null); if (password !== undefined) {
else next(); next(!utils.isPasswordValid(password) ? new Error('Invalid Password!') : null);
}else {
next();
}
}, },
function(next) { function(next) {
User.exists(userslug, function(exists) { User.exists(userslug, function(exists) {
@ -39,14 +48,19 @@ var utils = require('./../public/src/utils.js'),
function(next) { function(next) {
if (email !== undefined) { if (email !== undefined) {
User.isEmailAvailable(email, function(err, available) { User.isEmailAvailable(email, function(err, available) {
if (err) if (err) {
return next(err); return next(err);
}
next(!available ? new Error('Email taken!') : null); next(!available ? new Error('Email taken!') : null);
}); });
} else next(); } else {
next();
}
} }
], function(err, results) { ], function(err, results) {
if (err) return callback(err, null); if (err) {
return callback(err, null);
}
RDB.incr('global:next_user_id', function(err, uid) { RDB.incr('global:next_user_id', function(err, uid) {
RDB.handle(err); RDB.handle(err);
@ -87,9 +101,11 @@ var utils = require('./../public/src/utils.js'),
RDB.incr('usercount', function(err, count) { RDB.incr('usercount', function(err, count) {
RDB.handle(err); RDB.handle(err);
if (typeof io !== 'undefined') io.sockets.emit('user.count', { if (typeof io !== 'undefined') {
io.sockets.emit('user.count', {
count: count count: count
}); });
}
}); });
RDB.zadd('users:joindate', timestamp, uid); RDB.zadd('users:joindate', timestamp, uid);
@ -98,36 +114,40 @@ var utils = require('./../public/src/utils.js'),
userSearch.index(username, uid); userSearch.index(username, uid);
if (typeof io !== 'undefined') io.sockets.emit('user.latest', { if (typeof io !== 'undefined') {
io.sockets.emit('user.latest', {
userslug: userslug, userslug: userslug,
username: username username: username
}); });
}
if (password !== undefined) { if (password !== undefined) {
User.hashPassword(password, function(err, hash) { User.hashPassword(password, function(err, hash) {
User.setUserField(uid, 'password', hash); User.setUserField(uid, 'password', hash);
callback(null, uid); callback(null, uid);
}); });
} else callback(null, uid); } else {
callback(null, uid);
}
}); });
}); });
}; };
User.ban = function(uid, callback) { User.ban = function(uid, callback) {
User.setUserField(uid, 'banned', 1, callback); User.setUserField(uid, 'banned', 1, callback);
} };
User.unban = function(uid, callback) { User.unban = function(uid, callback) {
User.setUserField(uid, 'banned', 0, callback); User.setUserField(uid, 'banned', 0, callback);
} };
User.getUserField = function(uid, field, callback) { User.getUserField = function(uid, field, callback) {
RDB.hget('user:' + uid, field, callback); RDB.hget('user:' + uid, field, callback);
} };
User.getUserFields = function(uid, fields, callback) { User.getUserFields = function(uid, fields, callback) {
RDB.hmgetObject('user:' + uid, fields, callback); RDB.hmgetObject('user:' + uid, fields, callback);
} };
User.getMultipleUserFields = function(uids, fields, callback) { User.getMultipleUserFields = function(uids, fields, callback) {
if (uids.length === 0) { if (uids.length === 0) {
@ -136,14 +156,15 @@ var utils = require('./../public/src/utils.js'),
var returnData = []; var returnData = [];
uuids = uids.filter(function(value, index, self) { var uuids = uids.filter(function(value, index, self) {
return self.indexOf(value) === index; return self.indexOf(value) === index;
}); });
function iterator(uid, next) { function iterator(uid, next) {
User.getUserFields(uid, fields, function(err, userData) { User.getUserFields(uid, fields, function(err, userData) {
if (err) if (err) {
return next(err); return next(err);
}
returnData.push(userData); returnData.push(userData);
next(null); next(null);
}); });
@ -152,23 +173,23 @@ var utils = require('./../public/src/utils.js'),
async.eachSeries(uuids, iterator, function(err) { async.eachSeries(uuids, iterator, function(err) {
callback(err, returnData); callback(err, returnData);
}); });
} };
User.getUserData = function(uid, callback) { User.getUserData = function(uid, callback) {
RDB.hgetall('user:' + uid, function(err, data) { RDB.hgetall('user:' + uid, function(err, data) {
if (data && data['password']) { if (data && data.password) {
delete data['password']; delete data.password;
} }
callback(err, data); callback(err, data);
}); });
} };
User.filterBannedUsers = function(users) { User.filterBannedUsers = function(users) {
return users.filter(function(user) { return users.filter(function(user) {
return (!user.banned || user.banned === '0'); return (!user.banned || user.banned === '0');
}); });
} };
User.updateProfile = function(uid, data, callback) { User.updateProfile = function(uid, data, callback) {
@ -178,7 +199,7 @@ var utils = require('./../public/src/utils.js'),
}; };
function isSignatureValid(next) { function isSignatureValid(next) {
if (data['signature'] !== undefined && data['signature'].length > 150) { if (data.signature !== undefined && data.signature.length > 150) {
next({ next({
error: 'Signature can\'t be longer than 150 characters!' error: 'Signature can\'t be longer than 150 characters!'
}, false); }, false);
@ -188,15 +209,16 @@ var utils = require('./../public/src/utils.js'),
} }
function isEmailAvailable(next) { function isEmailAvailable(next) {
if (!data['email']) { if (!data.email) {
return next(null, true); return next(null, true);
} }
User.getUserField(uid, 'email', function(err, email) { User.getUserField(uid, 'email', function(err, email) {
if (email !== data['email']) { if (email !== data.email) {
User.isEmailAvailable(data['email'], function(err, available) { User.isEmailAvailable(data.email, function(err, available) {
if (err) if (err) {
return next(err, null); return next(err, null);
}
if (!available) { if (!available) {
next({ next({
error: 'Email not available!' error: 'Email not available!'
@ -232,11 +254,12 @@ var utils = require('./../public/src/utils.js'),
var gravatarpicture = User.createGravatarURLFromEmail(data[field]); var gravatarpicture = User.createGravatarURLFromEmail(data[field]);
User.setUserField(uid, 'gravatarpicture', gravatarpicture); User.setUserField(uid, 'gravatarpicture', gravatarpicture);
User.getUserFields(uid, ['email', 'picture', 'uploadedpicture'], function(err, userData) { User.getUserFields(uid, ['email', 'picture', 'uploadedpicture'], function(err, userData) {
if (err) if (err) {
return next(err); return next(err);
}
RDB.hdel('email:uid', userData['email']); RDB.hdel('email:uid', userData.email);
RDB.hset('email:uid', data['email'], uid); RDB.hset('email:uid', data.email, uid);
User.setUserField(uid, field, data[field]); User.setUserField(uid, field, data[field]);
if (userData.picture !== userData.uploadedpicture) { if (userData.picture !== userData.uploadedpicture) {
returnData.picture = gravatarpicture; returnData.picture = gravatarpicture;
@ -257,13 +280,13 @@ var utils = require('./../public/src/utils.js'),
next(null); next(null);
} }
} }
} };
User.isEmailAvailable = function(email, callback) { User.isEmailAvailable = function(email, callback) {
RDB.hexists('email:uid', email, function(err, exists) { RDB.hexists('email:uid', email, function(err, exists) {
callback(err, !exists); callback(err, !exists);
}); });
} };
User.changePassword = function(uid, data, callback) { User.changePassword = function(uid, data, callback) {
if (!utils.isPasswordValid(data.newPassword)) { if (!utils.isPasswordValid(data.newPassword)) {
@ -291,23 +314,23 @@ var utils = require('./../public/src/utils.js'),
} }
}); });
}); });
} };
User.setUserField = function(uid, field, value, callback) { User.setUserField = function(uid, field, value, callback) {
RDB.hset('user:' + uid, field, value, callback); RDB.hset('user:' + uid, field, value, callback);
} };
User.setUserFields = function(uid, data) { User.setUserFields = function(uid, data) {
RDB.hmset('user:' + uid, data); RDB.hmset('user:' + uid, data);
} };
User.incrementUserFieldBy = function(uid, field, value, callback) { User.incrementUserFieldBy = function(uid, field, value, callback) {
RDB.hincrby('user:' + uid, field, value, callback); RDB.hincrby('user:' + uid, field, value, callback);
} };
User.decrementUserFieldBy = function(uid, field, value, callback) { User.decrementUserFieldBy = function(uid, field, value, callback) {
RDB.hincrby('user:' + uid, field, -value, callback); RDB.hincrby('user:' + uid, field, -value, callback);
} };
User.getUsers = function(set, start, stop, callback) { User.getUsers = function(set, start, stop, callback) {
var data = []; var data = [];
@ -334,22 +357,23 @@ var utils = require('./../public/src/utils.js'),
}); });
}); });
} };
User.createGravatarURLFromEmail = function(email) { User.createGravatarURLFromEmail = function(email) {
var options = { var options = {
size: '128', size: '128',
default: 'identicon', default: 'identicon',
rating: 'pg' rating: 'pg'
}; },
https = nconf.get('https');
if (!email) { if (!email) {
email = ''; email = '';
options.forcedefault = 'y'; options.forcedefault = 'y';
} }
return require('gravatar').url(email, options, https = nconf.get('https')); return require('gravatar').url(email, options, https);
} };
User.hashPassword = function(password, callback) { User.hashPassword = function(password, callback) {
if (!password) { if (!password) {
@ -360,7 +384,7 @@ var utils = require('./../public/src/utils.js'),
bcrypt.genSalt(nconf.get('bcrypt_rounds'), function(err, salt) { bcrypt.genSalt(nconf.get('bcrypt_rounds'), function(err, salt) {
bcrypt.hash(password, salt, callback); bcrypt.hash(password, salt, callback);
}); });
} };
User.reIndexAll = function(callback) { User.reIndexAll = function(callback) {
User.getUsers('users:joindate', 0, -1, function(err, usersData) { User.getUsers('users:joindate', 0, -1, function(err, usersData) {
@ -371,7 +395,7 @@ var utils = require('./../public/src/utils.js'),
function reIndexUser(uid, username) { function reIndexUser(uid, username) {
userSearch.remove(uid, function() { userSearch.remove(uid, function() {
userSearch.index(username, uid); userSearch.index(username, uid);
}) });
} }
for (var i = 0; i < usersData.length; ++i) { for (var i = 0; i < usersData.length; ++i) {
@ -379,15 +403,14 @@ var utils = require('./../public/src/utils.js'),
} }
callback(null, 1); callback(null, 1);
}); });
} };
User.search = function(username, callback) { User.search = function(username, callback) {
if (!username) { if (!username) {
callback([]); callback([]);
return; return;
} }
userSearch.query(username).type('or').end(function(err, uids) {
userSearch.query(query = username).type('or').end(function(err, uids) {
if (err) { if (err) {
console.log(err); console.log(err);
return; return;
@ -400,7 +423,7 @@ var utils = require('./../public/src/utils.js'),
callback([]); callback([]);
} }
}); });
} };
User.onNewPostMade = function(uid, tid, pid, timestamp) { User.onNewPostMade = function(uid, tid, pid, timestamp) {
User.addPostIdToUser(uid, pid); User.addPostIdToUser(uid, pid);
@ -412,29 +435,30 @@ var utils = require('./../public/src/utils.js'),
User.setUserField(uid, 'lastposttime', timestamp); User.setUserField(uid, 'lastposttime', timestamp);
User.sendPostNotificationToFollowers(uid, tid, pid); User.sendPostNotificationToFollowers(uid, tid, pid);
} };
User.addPostIdToUser = function(uid, pid) { User.addPostIdToUser = function(uid, pid) {
RDB.lpush('uid:' + uid + ':posts', pid); RDB.lpush('uid:' + uid + ':posts', pid);
} };
User.addTopicIdToUser = function(uid, tid) { User.addTopicIdToUser = function(uid, tid) {
RDB.lpush('uid:' + uid + ':topics', tid); RDB.lpush('uid:' + uid + ':topics', tid);
} };
User.getPostIds = function(uid, start, end, callback) { User.getPostIds = function(uid, start, end, callback) {
RDB.lrange('uid:' + uid + ':posts', start, end, function(err, pids) { RDB.lrange('uid:' + uid + ':posts', start, end, function(err, pids) {
if (!err) { if (!err) {
if (pids && pids.length) if (pids && pids.length) {
callback(pids); callback(pids);
else }else {
callback([]); callback([]);
}
} else { } else {
console.log(err); console.log(err);
callback([]); callback([]);
} }
}); });
} };
User.sendConfirmationEmail = function(email) { User.sendConfirmationEmail = function(email) {
if (meta.config['email:smtp:host'] && meta.config['email:smtp:port'] && meta.config['email:from']) { if (meta.config['email:smtp:host'] && meta.config['email:smtp:port'] && meta.config['email:from']) {
@ -475,7 +499,7 @@ var utils = require('./../public/src/utils.js'),
} }
}); });
} }
} };
User.follow = function(uid, followid, callback) { User.follow = function(uid, followid, callback) {
RDB.sadd('following:' + uid, followid, function(err, data) { RDB.sadd('following:' + uid, followid, function(err, data) {
@ -493,7 +517,7 @@ var utils = require('./../public/src/utils.js'),
callback(false); callback(false);
} }
}); });
} };
User.unfollow = function(uid, unfollowid, callback) { User.unfollow = function(uid, unfollowid, callback) {
RDB.srem('following:' + uid, unfollowid, function(err, data) { RDB.srem('following:' + uid, unfollowid, function(err, data) {
@ -505,7 +529,7 @@ var utils = require('./../public/src/utils.js'),
console.log(err); console.log(err);
} }
}); });
} };
User.getFollowing = function(uid, callback) { User.getFollowing = function(uid, callback) {
RDB.smembers('following:' + uid, function(err, userIds) { RDB.smembers('following:' + uid, function(err, userIds) {
@ -515,7 +539,7 @@ var utils = require('./../public/src/utils.js'),
console.log(err); console.log(err);
} }
}); });
} };
User.getFollowers = function(uid, callback) { User.getFollowers = function(uid, callback) {
RDB.smembers('followers:' + uid, function(err, userIds) { RDB.smembers('followers:' + uid, function(err, userIds) {
@ -525,7 +549,7 @@ var utils = require('./../public/src/utils.js'),
console.log(err); console.log(err);
} }
}); });
} };
User.getFollowingCount = function(uid, callback) { User.getFollowingCount = function(uid, callback) {
RDB.smembers('following:' + uid, function(err, userIds) { RDB.smembers('following:' + uid, function(err, userIds) {
@ -538,7 +562,7 @@ var utils = require('./../public/src/utils.js'),
callback(userIds.length); callback(userIds.length);
} }
}); });
} };
User.getFollowerCount = function(uid, callback) { User.getFollowerCount = function(uid, callback) {
RDB.smembers('followers:' + uid, function(err, userIds) { RDB.smembers('followers:' + uid, function(err, userIds) {
@ -551,7 +575,7 @@ var utils = require('./../public/src/utils.js'),
callback(userIds.length); callback(userIds.length);
} }
}); });
} };
User.getDataForUsers = function(uids, callback) { User.getDataForUsers = function(uids, callback) {
var returnData = []; var returnData = [];
@ -562,8 +586,9 @@ var utils = require('./../public/src/utils.js'),
} }
function iterator(uid, callback) { function iterator(uid, callback) {
if(uid === "0") if(uid === "0") {
return callback(null); return callback(null);
}
User.getUserData(uid, function(err, userData) { User.getUserData(uid, function(err, userData) {
returnData.push(userData); returnData.push(userData);
@ -575,7 +600,7 @@ var utils = require('./../public/src/utils.js'),
async.eachSeries(uids, iterator, function(err) { async.eachSeries(uids, iterator, function(err) {
callback(returnData); callback(returnData);
}); });
} };
User.sendPostNotificationToFollowers = function(uid, tid, pid) { User.sendPostNotificationToFollowers = function(uid, tid, pid) {
User.getUserField(uid, 'username', function(err, username) { User.getUserField(uid, 'username', function(err, username) {
@ -589,7 +614,7 @@ var utils = require('./../public/src/utils.js'),
}); });
}); });
}); });
} };
User.isFollowing = function(uid, theirid, callback) { User.isFollowing = function(uid, theirid, callback) {
RDB.sismember('following:' + uid, theirid, function(err, data) { RDB.sismember('following:' + uid, theirid, function(err, data) {
@ -599,13 +624,13 @@ var utils = require('./../public/src/utils.js'),
console.log(err); console.log(err);
} }
}); });
} };
User.exists = function(userslug, callback) { User.exists = function(userslug, callback) {
User.getUidByUserslug(userslug, function(err, exists) { User.getUidByUserslug(userslug, function(err, exists) {
callback( !! exists); callback( !! exists);
}); });
} };
User.count = function(socket) { User.count = function(socket) {
RDB.get('usercount', function(err, count) { RDB.get('usercount', function(err, count) {
@ -615,29 +640,30 @@ var utils = require('./../public/src/utils.js'),
count: count ? count : 0 count: count ? count : 0
}); });
}); });
} };
User.latest = function(socket) { User.latest = function(socket) {
RDB.zrevrange('users:joindate', 0, 0, function(err, uid) { RDB.zrevrange('users:joindate', 0, 0, function(err, uid) {
RDB.handle(err); RDB.handle(err);
User.getUserFields(uid, ['username', 'userslug'], function(err, userData) { User.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
if (!err && userData) if (!err && userData) {
socket.emit('user.latest', { socket.emit('user.latest', {
userslug: userData.userslug, userslug: userData.userslug,
username: userData.username username: userData.username
}); });
}
}); });
}); });
} };
User.getUidByUsername = function(username, callback) { User.getUidByUsername = function(username, callback) {
RDB.hget('username:uid', username, callback); RDB.hget('username:uid', username, callback);
} };
User.getUidByUserslug = function(userslug, callback) { User.getUidByUserslug = function(userslug, callback) {
RDB.hget('userslug:uid', userslug, callback); RDB.hget('userslug:uid', userslug, callback);
} };
User.getUsernamesByUids = function(uids, callback) { User.getUsernamesByUids = function(uids, callback) {
var usernames = []; var usernames = [];
@ -656,7 +682,7 @@ var utils = require('./../public/src/utils.js'),
async.eachSeries(uids, iterator, function(err) { async.eachSeries(uids, iterator, function(err) {
callback(usernames); callback(usernames);
}); });
} };
User.getUserSlugsByUids = function(uids, callback) { User.getUserSlugsByUids = function(uids, callback) {
var userslugs = []; var userslugs = [];
@ -675,7 +701,7 @@ var utils = require('./../public/src/utils.js'),
async.eachSeries(uids, iterator, function(err) { async.eachSeries(uids, iterator, function(err) {
callback(userslugs); callback(userslugs);
}); });
} };
User.getUidByEmail = function(email, callback) { User.getUidByEmail = function(email, callback) {
RDB.hget('email:uid', email, function(err, data) { RDB.hget('email:uid', email, function(err, data) {
@ -684,7 +710,7 @@ var utils = require('./../public/src/utils.js'),
} }
callback(data); callback(data);
}); });
} };
User.getUidByTwitterId = function(twid, callback) { User.getUidByTwitterId = function(twid, callback) {
RDB.hget('twid:uid', twid, function(err, uid) { RDB.hget('twid:uid', twid, function(err, uid) {
@ -693,7 +719,7 @@ var utils = require('./../public/src/utils.js'),
} }
callback(uid); callback(uid);
}); });
} };
User.getUidByGoogleId = function(gplusid, callback) { User.getUidByGoogleId = function(gplusid, callback) {
RDB.hget('gplusid:uid', gplusid, function(err, uid) { RDB.hget('gplusid:uid', gplusid, function(err, uid) {
@ -702,7 +728,7 @@ var utils = require('./../public/src/utils.js'),
} }
callback(uid); callback(uid);
}); });
} };
User.getUidByFbid = function(fbid, callback) { User.getUidByFbid = function(fbid, callback) {
RDB.hget('fbid:uid', fbid, function(err, uid) { RDB.hget('fbid:uid', fbid, function(err, uid) {
@ -711,14 +737,14 @@ var utils = require('./../public/src/utils.js'),
} }
callback(uid); callback(uid);
}); });
} };
User.isModerator = function(uid, cid, callback) { User.isModerator = function(uid, cid, callback) {
RDB.sismember('cid:' + cid + ':moderators', uid, function(err, exists) { RDB.sismember('cid:' + cid + ':moderators', uid, function(err, exists) {
RDB.handle(err); RDB.handle(err);
callback( !! exists); callback( !! exists);
}); });
} };
User.isAdministrator = function(uid, callback) { User.isAdministrator = function(uid, callback) {
Groups.getGidFromName('Administrators', function(err, gid) { Groups.getGidFromName('Administrators', function(err, gid) {
@ -726,7 +752,7 @@ var utils = require('./../public/src/utils.js'),
callback( !! isAdmin); callback( !! isAdmin);
}); });
}); });
} };
User.reset = { User.reset = {
validate: function(socket, code, callback) { validate: function(socket, code, callback) {
@ -851,7 +877,7 @@ var utils = require('./../public/src/utils.js'),
} }
}); });
} }
} };
User.email = { User.email = {
exists: function(socket, email, callback) { exists: function(socket, email, callback) {
@ -898,7 +924,9 @@ var utils = require('./../public/src/utils.js'),
var unread = []; var unread = [];
// Cap the number of notifications returned // Cap the number of notifications returned
if (nids.length > maxNotifs) nids.length = maxNotifs; if (nids.length > maxNotifs) {
nids.length = maxNotifs;
}
if (nids && nids.length > 0) { if (nids && nids.length > 0) {
async.eachSeries(nids, function(nid, next) { async.eachSeries(nids, function(nid, next) {
@ -926,7 +954,9 @@ var utils = require('./../public/src/utils.js'),
var read = []; var read = [];
// Cap the number of notifications returned // Cap the number of notifications returned
if (nids.length > maxNotifs) nids.length = maxNotifs; if (nids.length > maxNotifs) {
nids.length = maxNotifs;
}
if (nids && nids.length > 0) { if (nids && nids.length > 0) {
async.eachSeries(nids, function(nid, next) { async.eachSeries(nids, function(nid, next) {
@ -960,8 +990,12 @@ var utils = require('./../public/src/utils.js'),
getAll: function(uid, limit, before, callback) { getAll: function(uid, limit, before, callback) {
var now = new Date(); var now = new Date();
if (!limit || parseInt(limit) <= 0) limit = 25; if (!limit || parseInt(limit,10) <= 0) {
if (before) before = new Date(parseInt(before, 10)); limit = 25;
}
if (before) {
before = new Date(parseInt(before, 10));
}
RDB.multi() RDB.multi()
.zrevrangebyscore('uid:' + uid + ':notifications:read', before ? before.getTime(): now.getTime(), -Infinity, 'LIMIT', 0, limit) .zrevrangebyscore('uid:' + uid + ':notifications:read', before ? before.getTime(): now.getTime(), -Infinity, 'LIMIT', 0, limit)
@ -985,7 +1019,7 @@ var utils = require('./../public/src/utils.js'),
}); });
callback(err, notifs); callback(err, notifs);
}) });
}); });
}, },
getUnreadCount: function(uid, callback) { getUnreadCount: function(uid, callback) {
@ -995,13 +1029,16 @@ var utils = require('./../public/src/utils.js'),
RDB.zrange('uid:' + uid + ':notifications:unread', 0, -1, function(err, nids) { RDB.zrange('uid:' + uid + ':notifications:unread', 0, -1, function(err, nids) {
async.filter(nids, function(nid, next) { async.filter(nids, function(nid, next) {
notifications.get(nid, uid, function(notifObj) { notifications.get(nid, uid, function(notifObj) {
if (notifObj.uniqueId === uniqueId) next(true); if (notifObj.uniqueId === uniqueId) {
else next(false); next(true);
}else {
next(false);
}
}); });
}, function(nids) { }, function(nids) {
callback(null, nids); callback(null, nids);
}); });
}); });
} }
} };
}(exports)); }(exports));
Loading…
Cancel
Save