diff --git a/install/data/defaults.json b/install/data/defaults.json index feb55fda81..a4377ea7d3 100644 --- a/install/data/defaults.json +++ b/install/data/defaults.json @@ -110,6 +110,7 @@ "hsts-subdomains": 0, "hsts-preload": 0, "hsts-enabled": 0, + "eventLoopCheckEnabled": 1, "eventLoopLagThreshold": 100, "eventLoopInterval": 500, "onlineCutoff": 30 diff --git a/public/src/utils.js b/public/src/utils.js index 74ecc9231c..e9defd8377 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -513,7 +513,7 @@ timestamp = Math.min(timestamp, 8640000000000000); try { - return Date.prototype.toISOString ? new Date(parseInt(timestamp, 10)).toISOString() : timestamp; + return new Date(parseInt(timestamp, 10)).toISOString(); } catch (e) { return timestamp; } diff --git a/src/controllers/user.js b/src/controllers/user.js index 16ed5d615b..66eaeafa8e 100644 --- a/src/controllers/user.js +++ b/src/controllers/user.js @@ -84,7 +84,7 @@ userController.getUserDataByField = function (callerUid, field, fieldValue, call }; userController.getUserDataByUID = function (callerUid, uid, callback) { - if (!parseInt(callerUid, 10) && meta.config.privateUserInfo) { + if (parseInt(callerUid, 10) <= 0 && meta.config.privateUserInfo) { return callback(new Error('[[error:no-privileges]]')); } diff --git a/src/messaging/unread.js b/src/messaging/unread.js index 660eece5ce..bedbed7021 100644 --- a/src/messaging/unread.js +++ b/src/messaging/unread.js @@ -7,14 +7,14 @@ var sockets = require('../socket.io'); module.exports = function (Messaging) { Messaging.getUnreadCount = function (uid, callback) { - if (!parseInt(uid, 10)) { - return callback(null, 0); + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback, null, 0); } db.sortedSetCard('uid:' + uid + ':chat:rooms:unread', callback); }; Messaging.pushUnreadCount = function (uid) { - if (!parseInt(uid, 10)) { + if (parseInt(uid, 10) <= 0) { return; } Messaging.getUnreadCount(uid, function (err, unreadCount) { diff --git a/src/middleware/index.js b/src/middleware/index.js index 165342e3d7..b0aaf3dbd4 100644 --- a/src/middleware/index.js +++ b/src/middleware/index.js @@ -62,10 +62,10 @@ middleware.pageView = function (req, res, next) { user.updateOnlineUsers(req.uid, next); } else { user.updateOnlineUsers(req.uid); - next(); + setImmediate(next); } } else { - next(); + setImmediate(next); } }; @@ -156,11 +156,11 @@ middleware.privateUploads = function (req, res, next) { }; middleware.busyCheck = function (req, res, next) { - if (global.env === 'production' && (!meta.config.hasOwnProperty('eventLoopCheckEnabled') || meta.config.eventLoopCheckEnabled) && toobusy()) { + if (global.env === 'production' && meta.config.eventLoopCheckEnabled && toobusy()) { analytics.increment('errors:503'); res.status(503).type('text/html').sendFile(path.join(__dirname, '../../public/503.html')); } else { - next(); + setImmediate(next); } }; diff --git a/src/middleware/maintenance.js b/src/middleware/maintenance.js index 7828619ead..6b7bb65082 100644 --- a/src/middleware/maintenance.js +++ b/src/middleware/maintenance.js @@ -8,12 +8,12 @@ var user = require('../user'); module.exports = function (middleware) { middleware.maintenanceMode = function (req, res, callback) { if (!meta.config.maintenanceMode) { - return callback(); + return setImmediate(callback); } var url = req.url.replace(nconf.get('relative_path'), ''); if (url.startsWith('/login') || url.startsWith('/api/login')) { - return callback(); + return setImmediate(callback); } var data; async.waterfall([ diff --git a/src/middleware/user.js b/src/middleware/user.js index 2fe60fce64..5add292278 100644 --- a/src/middleware/user.js +++ b/src/middleware/user.js @@ -226,7 +226,7 @@ module.exports = function (middleware) { middleware.registrationComplete = function (req, res, next) { // If the user's session contains registration data, redirect the user to complete registration if (!req.session.hasOwnProperty('registration')) { - return next(); + return setImmediate(next); } if (!req.path.endsWith('/register/complete')) { // Append user data if present @@ -234,7 +234,7 @@ module.exports = function (middleware) { controllers.helpers.redirect(res, '/register/complete'); } else { - return next(); + return setImmediate(next); } }; }; diff --git a/src/notifications.js b/src/notifications.js index 13a9376713..69c9e89848 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -357,16 +357,16 @@ Notifications.rescind = function (nid, callback) { Notifications.markRead = function (nid, uid, callback) { callback = callback || function () {}; - if (!parseInt(uid, 10) || !nid) { - return callback(); + if (parseInt(uid, 10) <= 0 || !nid) { + return setImmediate(callback); } Notifications.markReadMultiple([nid], uid, callback); }; Notifications.markUnread = function (nid, uid, callback) { callback = callback || function () {}; - if (!parseInt(uid, 10) || !nid) { - return callback(); + if (parseInt(uid, 10) <= 0 || !nid) { + return setImmediate(callback); } async.waterfall([ function (next) { diff --git a/src/posts/bookmarks.js b/src/posts/bookmarks.js index c33591415c..241c5b85c3 100644 --- a/src/posts/bookmarks.js +++ b/src/posts/bookmarks.js @@ -15,7 +15,7 @@ module.exports = function (Posts) { }; function toggleBookmark(type, pid, uid, callback) { - if (!parseInt(uid, 10)) { + if (parseInt(uid, 10) <= 0) { return callback(new Error('[[error:not-logged-in]]')); } @@ -85,9 +85,9 @@ module.exports = function (Posts) { } Posts.hasBookmarked = function (pid, uid, callback) { - if (!parseInt(uid, 10)) { + if (parseInt(uid, 10) <= 0) { if (Array.isArray(pid)) { - callback(null, pid.map(function () { return false; })); + callback(null, pid.map(() => false)); } else { callback(null, false); } @@ -95,10 +95,7 @@ module.exports = function (Posts) { } if (Array.isArray(pid)) { - var sets = pid.map(function (pid) { - return 'pid:' + pid + ':users_bookmarked'; - }); - + var sets = pid.map(pid => 'pid:' + pid + ':users_bookmarked'); db.isMemberOfSets(sets, uid, callback); } else { db.isSetMember('pid:' + pid + ':users_bookmarked', uid, callback); diff --git a/src/posts/index.js b/src/posts/index.js index 3c7ee4d3fc..7790593d3f 100644 --- a/src/posts/index.js +++ b/src/posts/index.js @@ -35,7 +35,7 @@ Posts.exists = function (pid, callback) { Posts.getPidsFromSet = function (set, start, stop, reverse, callback) { if (isNaN(start) || isNaN(stop)) { - return callback(null, []); + return setImmediate(callback, null, []); } db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, stop, callback); }; diff --git a/src/posts/user.js b/src/posts/user.js index f22ea0559f..4e4edadbd9 100644 --- a/src/posts/user.js +++ b/src/posts/user.js @@ -144,8 +144,8 @@ module.exports = function (Posts) { }; Posts.isModerator = function (pids, uid, callback) { - if (!parseInt(uid, 10)) { - return callback(null, pids.map(function () { return false; })); + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback, null, pids.map(() => false)); } Posts.getCidsByPids(pids, function (err, cids) { if (err) { diff --git a/src/posts/votes.js b/src/posts/votes.js index 14481f400c..f1352676c0 100644 --- a/src/posts/votes.js +++ b/src/posts/votes.js @@ -85,8 +85,8 @@ module.exports = function (Posts) { }; Posts.hasVoted = function (pid, uid, callback) { - if (!parseInt(uid, 10)) { - return callback(null, { upvoted: false, downvoted: false }); + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback, null, { upvoted: false, downvoted: false }); } async.waterfall([ function (next) { @@ -99,9 +99,9 @@ module.exports = function (Posts) { }; Posts.getVoteStatusByPostIDs = function (pids, uid, callback) { - if (!parseInt(uid, 10)) { - var data = pids.map(function () { return false; }); - return callback(null, { upvotes: data, downvotes: data }); + if (parseInt(uid, 10) <= 0) { + var data = pids.map(() => false); + return setImmediate(callback, null, { upvotes: data, downvotes: data }); } var upvoteSets = []; var downvoteSets = []; @@ -110,15 +110,17 @@ module.exports = function (Posts) { upvoteSets.push('pid:' + pids[i] + ':upvote'); downvoteSets.push('pid:' + pids[i] + ':downvote'); } - - async.parallel({ - upvotes: function (next) { - db.isMemberOfSets(upvoteSets, uid, next); + async.waterfall([ + function (next) { + db.isMemberOfSets(upvoteSets.concat(downvoteSets), uid, next); }, - downvotes: function (next) { - db.isMemberOfSets(downvoteSets, uid, next); + function (data, next) { + next(null, { + upvotes: data.slice(0, pids.length), + downvotes: data.slice(pids.length, pids.length * 2), + }); }, - }, callback); + ], callback); }; Posts.getUpvotedUidsByPids = function (pids, callback) { diff --git a/src/privileges/categories.js b/src/privileges/categories.js index 71e800d158..80a8b56f7c 100644 --- a/src/privileges/categories.js +++ b/src/privileges/categories.js @@ -76,8 +76,8 @@ module.exports = function (privileges) { }; privileges.categories.isAdminOrMod = function (cid, uid, callback) { - if (!parseInt(uid, 10)) { - return callback(null, false); + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback, null, false); } helpers.some([ function (next) { diff --git a/src/privileges/topics.js b/src/privileges/topics.js index 4df8a158c6..7f14041b1f 100644 --- a/src/privileges/topics.js +++ b/src/privileges/topics.js @@ -17,7 +17,11 @@ module.exports = function (privileges) { privileges.topics.get = function (tid, uid, callback) { uid = parseInt(uid, 10); var topic; - var privs = ['topics:reply', 'topics:read', 'topics:tag', 'topics:delete', 'posts:edit', 'posts:history', 'posts:delete', 'posts:view_deleted', 'read', 'purge']; + var privs = [ + 'topics:reply', 'topics:read', 'topics:tag', + 'topics:delete', 'posts:edit', 'posts:history', + 'posts:delete', 'posts:view_deleted', 'read', 'purge', + ]; async.waterfall([ async.apply(topics.getTopicFields, tid, ['cid', 'uid', 'locked', 'deleted']), function (_topic, next) { diff --git a/src/privileges/users.js b/src/privileges/users.js index ca64e43946..b6070cf4fc 100644 --- a/src/privileges/users.js +++ b/src/privileges/users.js @@ -38,7 +38,7 @@ module.exports = function (privileges) { }; function isModeratorOfCategories(cids, uid, callback) { - if (!parseInt(uid, 10)) { + if (parseInt(uid, 10) <= 0) { return filterIsModerator(cids, uid, cids.map(function () { return false; }), callback); } var uniqueCids; diff --git a/src/social.js b/src/social.js index 43b8250522..9c4ae6e6b3 100644 --- a/src/social.js +++ b/src/social.js @@ -10,7 +10,7 @@ social.postSharing = null; social.getPostSharing = function (callback) { if (social.postSharing) { - return callback(null, social.postSharing); + return setImmediate(callback, null, social.postSharing); } var networks = [ @@ -55,9 +55,7 @@ social.getActivePostSharing = function (callback) { social.getPostSharing(next); }, function (networks, next) { - networks = networks.filter(function (network) { - return network && network.activated; - }); + networks = networks.filter(network => network && network.activated); next(null, networks); }, ], callback); diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index 91f41d69db..a3787099be 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -180,6 +180,9 @@ SocketAdmin.config.setMultiple = function (socket, data, callback) { var changes = {}; Object.keys(data).forEach(function (key) { + if (typeof meta.config[key] === 'number') { + data[key] = parseInt(data[key], 10); + } if (data[key] !== meta.config[key]) { changes[key] = data[key]; changes[key + '_old'] = meta.config[key]; diff --git a/src/socket.io/groups.js b/src/socket.io/groups.js index ebc80d66d5..05db6e486a 100644 --- a/src/socket.io/groups.js +++ b/src/socket.io/groups.js @@ -19,7 +19,7 @@ SocketGroups.before = function (socket, method, data, next) { }; SocketGroups.join = function (socket, data, callback) { - if (!parseInt(socket.uid, 10)) { + if (socket.uid <= 0) { return callback(new Error('[[error:invalid-uid]]')); } @@ -60,7 +60,7 @@ SocketGroups.join = function (socket, data, callback) { }; SocketGroups.leave = function (socket, data, callback) { - if (!parseInt(socket.uid, 10)) { + if (socket.uid <= 0) { return callback(new Error('[[error:invalid-uid]]')); } diff --git a/src/topics/bookmarks.js b/src/topics/bookmarks.js index 6952474ff6..ff62ef289d 100644 --- a/src/topics/bookmarks.js +++ b/src/topics/bookmarks.js @@ -8,21 +8,17 @@ var user = require('../user'); module.exports = function (Topics) { Topics.getUserBookmark = function (tid, uid, callback) { - if (!parseInt(uid, 10)) { + if (parseInt(uid, 10) <= 0) { return callback(null, null); } db.sortedSetScore('tid:' + tid + ':bookmarks', uid, callback); }; Topics.getUserBookmarks = function (tids, uid, callback) { - if (!parseInt(uid, 10)) { - return callback(null, tids.map(function () { - return null; - })); + if (parseInt(uid, 10) <= 0) { + return callback(null, tids.map(() => null)); } - db.sortedSetsScore(tids.map(function (tid) { - return 'tid:' + tid + ':bookmarks'; - }), uid, callback); + db.sortedSetsScore(tids.map(tid => 'tid:' + tid + ':bookmarks'), uid, callback); }; Topics.setUserBookmark = function (tid, uid, index, callback) { diff --git a/src/topics/data.js b/src/topics/data.js index 9df72b5f0c..fca7dc0239 100644 --- a/src/topics/data.js +++ b/src/topics/data.js @@ -90,7 +90,7 @@ module.exports = function (Topics) { function escapeTitle(topicData) { if (topicData) { if (topicData.title) { - topicData.title = translator.escape(validator.escape(String(topicData.title))); + topicData.title = translator.escape(validator.escape(topicData.title)); } if (topicData.titleRaw) { topicData.titleRaw = translator.escape(topicData.titleRaw); diff --git a/src/topics/follow.js b/src/topics/follow.js index a590ad2392..bb82d14aee 100644 --- a/src/topics/follow.js +++ b/src/topics/follow.js @@ -52,8 +52,8 @@ module.exports = function (Topics) { function setWatching(method1, method2, hook, tid, uid, callback) { callback = callback || function () {}; - if (!parseInt(uid, 10)) { - return callback(); + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback); } async.waterfall([ function (next) { @@ -121,16 +121,41 @@ module.exports = function (Topics) { isIgnoringOrFollowing('ignorers', tids, uid, callback); }; - function isIgnoringOrFollowing(set, tids, uid, callback) { + Topics.getFollowData = function (tids, uid, callback) { if (!Array.isArray(tids)) { - return callback(); + return setImmediate(callback); } - if (!parseInt(uid, 10)) { - return callback(null, tids.map(function () { return false; })); + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback, null, tids.map(() => ({ following: false, ignoring: false }))); } - var keys = tids.map(function (tid) { - return 'tid:' + tid + ':' + set; + const keys = []; + tids.forEach((tid) => { + keys.push('tid:' + tid + ':followers', 'tid:' + tid + ':ignorers'); }); + + db.isMemberOfSets(keys, uid, function (err, data) { + if (err) { + return callback(err); + } + const followData = []; + for (let i = 0; i < data.length; i += 2) { + followData.push({ + following: data[i], + ignoring: data[i + 1], + }); + } + callback(null, followData); + }); + }; + + function isIgnoringOrFollowing(set, tids, uid, callback) { + if (!Array.isArray(tids)) { + return setImmediate(callback); + } + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback, null, tids.map(() => false)); + } + var keys = tids.map(tid => 'tid:' + tid + ':' + set); db.isMemberOfSets(keys, uid, callback); } diff --git a/src/topics/index.js b/src/topics/index.js index f54dc9b325..6828f8eae3 100644 --- a/src/topics/index.js +++ b/src/topics/index.js @@ -159,8 +159,7 @@ Topics.getTopicWithPosts = function (topicData, set, uid, start, stop, reverse, category: async.apply(categories.getCategoryData, topicData.cid), tagWhitelist: async.apply(categories.getTagWhitelist, [topicData.cid]), threadTools: async.apply(plugins.fireHook, 'filter:topic.thread_tools', { topic: topicData, uid: uid, tools: [] }), - isFollowing: async.apply(Topics.isFollowing, [topicData.tid], uid), - isIgnoring: async.apply(Topics.isIgnoring, [topicData.tid], uid), + followData: async.apply(Topics.getFollowData, [topicData.tid], uid), bookmark: async.apply(Topics.getUserBookmark, topicData.tid, uid), postSharing: async.apply(social.getActivePostSharing), deleter: async.apply(getDeleter, topicData), @@ -183,9 +182,9 @@ Topics.getTopicWithPosts = function (topicData, set, uid, start, stop, reverse, topicData.category = results.category; topicData.tagWhitelist = results.tagWhitelist[0]; topicData.thread_tools = results.threadTools.tools; - topicData.isFollowing = results.isFollowing[0]; - topicData.isNotFollowing = !results.isFollowing[0] && !results.isIgnoring[0]; - topicData.isIgnoring = results.isIgnoring[0]; + topicData.isFollowing = results.followData[0].following; + topicData.isNotFollowing = !results.followData[0].following && !results.followData[0].ignoring; + topicData.isIgnoring = results.followData[0].ignoring; topicData.bookmark = results.bookmark; topicData.postSharing = results.postSharing; topicData.deleter = results.deleter; diff --git a/src/topics/posts.js b/src/topics/posts.js index fac337c0ea..005e5d4eed 100644 --- a/src/topics/posts.js +++ b/src/topics/posts.js @@ -63,6 +63,7 @@ module.exports = function (Topics) { } }); const uids = Object.keys(uidsMap); + async.waterfall([ function (next) { method(uids, next); @@ -110,7 +111,7 @@ module.exports = function (Topics) { postObj.downvoted = results.voteData.downvotes[i]; postObj.votes = postObj.votes || 0; postObj.replies = results.replies[i]; - postObj.selfPost = !!parseInt(uid, 10) && parseInt(uid, 10) === postObj.uid; + postObj.selfPost = parseInt(uid, 10) > 0 && parseInt(uid, 10) === postObj.uid; // Username override for guests, if enabled if (meta.config.allowGuestHandles && postObj.uid === 0 && postObj.handle) { @@ -130,7 +131,7 @@ module.exports = function (Topics) { }; Topics.modifyPostsByPrivilege = function (topicData, topicPrivileges) { - var loggedIn = !!parseInt(topicPrivileges.uid, 10); + var loggedIn = parseInt(topicPrivileges.uid, 10) > 0; topicData.posts.forEach(function (post) { if (post) { post.display_edit_tools = topicPrivileges.isAdminOrMod || (post.selfPost && topicPrivileges['posts:edit']); @@ -151,7 +152,7 @@ module.exports = function (Topics) { }).filter(Boolean); if (!parentPids.length) { - return callback(); + return setImmediate(callback); } var parentPosts; @@ -159,9 +160,7 @@ module.exports = function (Topics) { async.apply(posts.getPostsFields, parentPids, ['uid']), function (_parentPosts, next) { parentPosts = _parentPosts; - var parentUids = _.uniq(parentPosts.map(function (postObj) { - return postObj && parseInt(postObj.uid, 10); - })); + var parentUids = _.uniq(parentPosts.map(postObj => postObj && postObj.uid)); user.getUsersFields(parentUids, ['username'], next); }, @@ -391,9 +390,7 @@ module.exports = function (Topics) { var uniquePids; async.waterfall([ function (next) { - var keys = pids.map(function (pid) { - return 'pid:' + pid + ':replies'; - }); + const keys = pids.map(pid => 'pid:' + pid + ':replies'); db.getSortedSetsMembers(keys, next); }, function (arrayOfPids, next) { @@ -405,9 +402,7 @@ module.exports = function (Topics) { }, function (_replyData, next) { replyData = _replyData; - var uids = replyData.map(function (replyData) { - return replyData && replyData.uid; - }); + const uids = replyData.map(replyData => replyData && replyData.uid); uniqueUids = _.uniq(uids); diff --git a/src/topics/tags.js b/src/topics/tags.js index 564fbf034d..5f78c39b97 100644 --- a/src/topics/tags.js +++ b/src/topics/tags.js @@ -277,9 +277,7 @@ module.exports = function (Topics) { topicTags = _topicTags; uniqueTopicTags = _.uniq(_.flatten(topicTags)); - var tags = uniqueTopicTags.map(function (tag) { - return { value: tag }; - }); + var tags = uniqueTopicTags.map(tag => ({ value: tag })); async.parallel({ tagData: function (next) { diff --git a/src/user/auth.js b/src/user/auth.js index 96bfa57a64..40a9ad7d58 100644 --- a/src/user/auth.js +++ b/src/user/auth.js @@ -13,7 +13,7 @@ module.exports = function (User) { User.auth = {}; User.auth.logAttempt = function (uid, ip, callback) { - if (!parseInt(uid, 10)) { + if (parseInt(uid, 10) <= 0) { return setImmediate(callback); } async.waterfall([ @@ -49,8 +49,8 @@ module.exports = function (User) { }; User.auth.getFeedToken = function (uid, callback) { - if (!uid) { - return callback(); + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback); } var token; async.waterfall([ diff --git a/src/user/delete.js b/src/user/delete.js index f84ee25393..de82799505 100644 --- a/src/user/delete.js +++ b/src/user/delete.js @@ -18,7 +18,7 @@ module.exports = function (User) { var deletesInProgress = {}; User.delete = function (callerUid, uid, callback) { - if (!parseInt(uid, 10)) { + if (parseInt(uid, 10) <= 0) { return setImmediate(callback, new Error('[[error:invalid-uid]]')); } if (deletesInProgress[uid]) { diff --git a/src/user/follow.js b/src/user/follow.js index d2056065b4..b3ec7fd969 100644 --- a/src/user/follow.js +++ b/src/user/follow.js @@ -15,7 +15,7 @@ module.exports = function (User) { }; function toggleFollow(type, uid, theiruid, callback) { - if (!parseInt(uid, 10) || !parseInt(theiruid, 10)) { + if (parseInt(uid, 10) <= 0 || parseInt(theiruid, 10) <= 0) { return callback(new Error('[[error:invalid-uid]]')); } @@ -71,8 +71,8 @@ module.exports = function (User) { }; function getFollow(uid, type, start, stop, callback) { - if (!parseInt(uid, 10)) { - return callback(null, []); + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback, null, []); } async.waterfall([ function (next) { @@ -93,8 +93,8 @@ module.exports = function (User) { } User.isFollowing = function (uid, theirid, callback) { - if (!parseInt(uid, 10) || !parseInt(theirid, 10)) { - return callback(null, false); + if (parseInt(uid, 10) <= 0 || parseInt(theirid, 10) <= 0) { + return setImmediate(callback, null, false); } db.isSortedSetMember('following:' + uid, theirid, callback); }; diff --git a/src/user/notifications.js b/src/user/notifications.js index 563c06eccf..185c084324 100644 --- a/src/user/notifications.js +++ b/src/user/notifications.js @@ -13,8 +13,8 @@ var utils = require('../utils'); var UserNotifications = module.exports; UserNotifications.get = function (uid, callback) { - if (!parseInt(uid, 10)) { - return callback(null, { read: [], unread: [] }); + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback, null, { read: [], unread: [] }); } async.waterfall([ function (next) { @@ -177,8 +177,8 @@ UserNotifications.getDailyUnread = function (uid, callback) { }; UserNotifications.getUnreadCount = function (uid, callback) { - if (!parseInt(uid, 10)) { - return callback(null, 0); + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback, null, 0); } async.waterfall([ @@ -240,8 +240,8 @@ UserNotifications.getUnreadByField = function (uid, field, values, callback) { }; UserNotifications.deleteAll = function (uid, callback) { - if (!parseInt(uid, 10)) { - return callback(); + if (parseInt(uid, 10) <= 0) { + return setImmediate(callback); } async.parallel([ function (next) { diff --git a/src/user/posts.js b/src/user/posts.js index d03a2c9cc9..d8b7f999f6 100644 --- a/src/user/posts.js +++ b/src/user/posts.js @@ -94,7 +94,7 @@ module.exports = function (User) { User.incrementUserFieldBy(uid, 'postcount', value, next); }, function (newpostcount, next) { - if (!parseInt(uid, 10)) { + if (parseInt(uid, 10) <= 0) { return next(); } db.sortedSetAdd('users:postcount', newpostcount, uid, next); diff --git a/src/user/settings.js b/src/user/settings.js index 215d8c7d5b..0a7be7559a 100644 --- a/src/user/settings.js +++ b/src/user/settings.js @@ -10,7 +10,7 @@ var notifications = require('../notifications'); module.exports = function (User) { User.getSettings = function (uid, callback) { - if (!parseInt(uid, 10)) { + if (parseInt(uid, 10) <= 0) { return onSettingsLoaded(0, {}, callback); } @@ -181,7 +181,7 @@ module.exports = function (User) { }; User.setSetting = function (uid, key, value, callback) { - if (!parseInt(uid, 10)) { + if (parseInt(uid, 10) <= 0) { return setImmediate(callback); }