mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
remove parseInts
This commit is contained in:
@@ -227,7 +227,7 @@ module.exports = function (Categories) {
|
|||||||
topics.getTopicField(tid, 'postcount', next);
|
topics.getTopicField(tid, 'postcount', next);
|
||||||
},
|
},
|
||||||
function (postCount, next) {
|
function (postCount, next) {
|
||||||
if (!parseInt(postCount, 10)) {
|
if (!postCount) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
async.parallel([
|
async.parallel([
|
||||||
|
|||||||
@@ -178,12 +178,10 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
|
|||||||
|
|
||||||
userData.sso = results.sso.associations;
|
userData.sso = results.sso.associations;
|
||||||
userData.status = user.getStatus(userData);
|
userData.status = user.getStatus(userData);
|
||||||
userData.banned = parseInt(userData.banned, 10) === 1;
|
userData.banned = userData.banned === 1;
|
||||||
userData.website = validator.escape(String(userData.website || ''));
|
userData.website = validator.escape(String(userData.website || ''));
|
||||||
userData.websiteLink = !userData.website.startsWith('http') ? 'http://' + userData.website : userData.website;
|
userData.websiteLink = !userData.website.startsWith('http') ? 'http://' + userData.website : userData.website;
|
||||||
userData.websiteName = userData.website.replace(validator.escape('http://'), '').replace(validator.escape('https://'), '');
|
userData.websiteName = userData.website.replace(validator.escape('http://'), '').replace(validator.escape('https://'), '');
|
||||||
userData.followingCount = parseInt(userData.followingCount, 10) || 0;
|
|
||||||
userData.followerCount = parseInt(userData.followerCount, 10) || 0;
|
|
||||||
|
|
||||||
userData.email = validator.escape(String(userData.email || ''));
|
userData.email = validator.escape(String(userData.email || ''));
|
||||||
userData.fullname = validator.escape(String(userData.fullname || ''));
|
userData.fullname = validator.escape(String(userData.fullname || ''));
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ topicsController.get = function (req, res, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
settings = results.settings;
|
settings = results.settings;
|
||||||
var postCount = parseInt(results.topic.postcount, 10);
|
var postCount = results.topic.postcount;
|
||||||
pageCount = Math.max(1, Math.ceil(postCount / settings.postsPerPage));
|
pageCount = Math.max(1, Math.ceil(postCount / settings.postsPerPage));
|
||||||
results.topic.postcount = postCount;
|
results.topic.postcount = postCount;
|
||||||
|
|
||||||
@@ -390,7 +390,7 @@ topicsController.pagination = function (req, res, callback) {
|
|||||||
return helpers.notAllowed(req, res);
|
return helpers.notAllowed(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
var postCount = parseInt(results.topic.postcount, 10);
|
var postCount = results.topic.postcount;
|
||||||
var pageCount = Math.max(1, Math.ceil(postCount / results.settings.postsPerPage));
|
var pageCount = Math.max(1, Math.ceil(postCount / results.settings.postsPerPage));
|
||||||
|
|
||||||
var paginationData = pagination.create(currentPage, pageCount);
|
var paginationData = pagination.create(currentPage, pageCount);
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ Flags.validate = function (payload, callback) {
|
|||||||
|
|
||||||
if (data.target.deleted) {
|
if (data.target.deleted) {
|
||||||
return callback(new Error('[[error:post-deleted]]'));
|
return callback(new Error('[[error:post-deleted]]'));
|
||||||
} else if (parseInt(data.reporter.banned, 10)) {
|
} else if (data.reporter.banned) {
|
||||||
return callback(new Error('[[error:user-banned]]'));
|
return callback(new Error('[[error:user-banned]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,9 +64,7 @@ module.exports = function (Groups) {
|
|||||||
Groups.getGroupsFields(groupNames, ['name', 'hidden', 'memberCount'], next);
|
Groups.getGroupsFields(groupNames, ['name', 'hidden', 'memberCount'], next);
|
||||||
},
|
},
|
||||||
function (groupData, next) {
|
function (groupData, next) {
|
||||||
var visibleGroups = groupData.filter(function (groupData) {
|
var visibleGroups = groupData.filter(groupData => groupData && !groupData.hidden);
|
||||||
return groupData && parseInt(groupData.hidden, 10) !== 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (visibleGroups.length) {
|
if (visibleGroups.length) {
|
||||||
db.sortedSetAdd('groups:visible:memberCount', visibleGroups.map(groupData => groupData.memberCount), visibleGroups.map(groupData => groupData.name), next);
|
db.sortedSetAdd('groups:visible:memberCount', visibleGroups.map(groupData => groupData.memberCount), visibleGroups.map(groupData => groupData.name), next);
|
||||||
|
|||||||
@@ -47,15 +47,13 @@ module.exports = function (Groups) {
|
|||||||
var tasks = [];
|
var tasks = [];
|
||||||
|
|
||||||
var emptyPrivilegeGroups = groupData.filter(function (groupData) {
|
var emptyPrivilegeGroups = groupData.filter(function (groupData) {
|
||||||
return groupData && Groups.isPrivilegeGroup(groupData.name) && parseInt(groupData.memberCount, 10) === 0;
|
return groupData && Groups.isPrivilegeGroup(groupData.name) && groupData.memberCount === 0;
|
||||||
});
|
});
|
||||||
if (emptyPrivilegeGroups.length) {
|
if (emptyPrivilegeGroups.length) {
|
||||||
tasks.push(async.apply(Groups.destroy, emptyPrivilegeGroups));
|
tasks.push(async.apply(Groups.destroy, emptyPrivilegeGroups));
|
||||||
}
|
}
|
||||||
|
|
||||||
var visibleGroups = groupData.filter(function (groupData) {
|
var visibleGroups = groupData.filter(groupData => groupData && !groupData.hidden);
|
||||||
return groupData && parseInt(groupData.hidden, 10) !== 1;
|
|
||||||
});
|
|
||||||
if (visibleGroups.length) {
|
if (visibleGroups.length) {
|
||||||
tasks.push(async.apply(db.sortedSetAdd, 'groups:visible:memberCount', visibleGroups.map(groupData => groupData.memberCount), visibleGroups.map(groupData => groupData.name)));
|
tasks.push(async.apply(db.sortedSetAdd, 'groups:visible:memberCount', visibleGroups.map(groupData => groupData.memberCount), visibleGroups.map(groupData => groupData.name)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ module.exports = function (Groups) {
|
|||||||
Groups.getGroupFields(groupName, ['private'], next);
|
Groups.getGroupFields(groupName, ['private'], next);
|
||||||
},
|
},
|
||||||
function (currentValue, next) {
|
function (currentValue, next) {
|
||||||
var currentlyPrivate = parseInt(currentValue.private, 10) === 1;
|
var currentlyPrivate = currentValue.private === 1;
|
||||||
if (!currentlyPrivate || currentlyPrivate === isPrivate) {
|
if (!currentlyPrivate || currentlyPrivate === isPrivate) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
@@ -142,11 +142,9 @@ module.exports = function (Groups) {
|
|||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
var scores = uids.map(function () { return now; });
|
|
||||||
|
|
||||||
winston.verbose('[groups.update] Group is now public, automatically adding ' + uids.length + ' new members, who were pending prior.');
|
winston.verbose('[groups.update] Group is now public, automatically adding ' + uids.length + ' new members, who were pending prior.');
|
||||||
async.series([
|
async.series([
|
||||||
async.apply(db.sortedSetAdd, 'group:' + groupName + ':members', scores, uids),
|
async.apply(db.sortedSetAdd, 'group:' + groupName + ':members', uids.map(() => now), uids),
|
||||||
async.apply(db.delete, 'group:' + groupName + ':pending'),
|
async.apply(db.delete, 'group:' + groupName + ':pending'),
|
||||||
], next);
|
], next);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ module.exports = function (Messaging) {
|
|||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(Messaging.getMessageField, mid, 'deleted'),
|
async.apply(Messaging.getMessageField, mid, 'deleted'),
|
||||||
function (deleted, next) {
|
function (deleted, next) {
|
||||||
if (parseInt(deleted, 10)) {
|
if (deleted) {
|
||||||
return next(new Error('[[error:chat-deleted-already]]'));
|
return next(new Error('[[error:chat-deleted-already]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ module.exports = function (Messaging) {
|
|||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(Messaging.getMessageField, mid, 'deleted'),
|
async.apply(Messaging.getMessageField, mid, 'deleted'),
|
||||||
function (deleted, next) {
|
function (deleted, next) {
|
||||||
if (!parseInt(deleted, 10)) {
|
if (!deleted) {
|
||||||
return next(new Error('[[error:chat-restored-already]]'));
|
return next(new Error('[[error:chat-restored-already]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -268,11 +268,11 @@ Messaging.canMessageUser = function (uid, toUid, callback) {
|
|||||||
user.getUserFields(uid, ['banned', 'email:confirmed'], next);
|
user.getUserFields(uid, ['banned', 'email:confirmed'], next);
|
||||||
},
|
},
|
||||||
function (userData, next) {
|
function (userData, next) {
|
||||||
if (parseInt(userData.banned, 10) === 1) {
|
if (userData.banned) {
|
||||||
return callback(new Error('[[error:user-banned]]'));
|
return callback(new Error('[[error:user-banned]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meta.config.requireEmailConfirmation && parseInt(userData['email:confirmed'], 10) !== 1) {
|
if (meta.config.requireEmailConfirmation && !userData['email:confirmed']) {
|
||||||
return callback(new Error('[[error:email-not-confirmed-chat]]'));
|
return callback(new Error('[[error:email-not-confirmed-chat]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,11 +322,11 @@ Messaging.canMessageRoom = function (uid, roomId, callback) {
|
|||||||
user.getUserFields(uid, ['banned', 'email:confirmed'], next);
|
user.getUserFields(uid, ['banned', 'email:confirmed'], next);
|
||||||
},
|
},
|
||||||
function (userData, next) {
|
function (userData, next) {
|
||||||
if (parseInt(userData.banned, 10) === 1) {
|
if (userData.banned) {
|
||||||
return next(new Error('[[error:user-banned]]'));
|
return next(new Error('[[error:user-banned]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meta.config.requireEmailConfirmation && parseInt(userData['email:confirmed'], 10) !== 1) {
|
if (meta.config.requireEmailConfirmation && !userData['email:confirmed']) {
|
||||||
return next(new Error('[[error:email-not-confirmed-chat]]'));
|
return next(new Error('[[error:email-not-confirmed-chat]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ module.exports = function (middleware) {
|
|||||||
function (results, next) {
|
function (results, next) {
|
||||||
var userData = results.userData;
|
var userData = results.userData;
|
||||||
userData.uid = req.uid;
|
userData.uid = req.uid;
|
||||||
userData['email:confirmed'] = parseInt(userData['email:confirmed'], 10) === 1;
|
userData['email:confirmed'] = userData['email:confirmed'] === 1;
|
||||||
|
|
||||||
var acpPath = req.path.slice(1).split('/');
|
var acpPath = req.path.slice(1).split('/');
|
||||||
acpPath.forEach(function (path, i) {
|
acpPath.forEach(function (path, i) {
|
||||||
|
|||||||
@@ -137,9 +137,8 @@ module.exports = function (middleware) {
|
|||||||
results.user.privileges = results.privileges;
|
results.user.privileges = results.privileges;
|
||||||
results.user[results.user.status] = true;
|
results.user[results.user.status] = true;
|
||||||
|
|
||||||
results.user.uid = parseInt(results.user.uid, 10);
|
|
||||||
results.user.email = String(results.user.email);
|
results.user.email = String(results.user.email);
|
||||||
results.user['email:confirmed'] = parseInt(results.user['email:confirmed'], 10) === 1;
|
results.user['email:confirmed'] = results.user['email:confirmed'] === 1;
|
||||||
results.user.isEmailConfirmSent = !!results.isEmailConfirmSent;
|
results.user.isEmailConfirmSent = !!results.isEmailConfirmSent;
|
||||||
|
|
||||||
setBootswatchCSS(templateValues, res.locals.config);
|
setBootswatchCSS(templateValues, res.locals.config);
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ module.exports = function (Posts) {
|
|||||||
topics.updateLastPostTimeFromLastPid(postData.tid, next);
|
topics.updateLastPostTimeFromLastPid(postData.tid, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
if (parseInt(topicData.pinned, 10) !== 1) {
|
if (!topicData.pinned) {
|
||||||
db.sortedSetIncrBy('cid:' + topicData.cid + ':tids:posts', -1, postData.tid, next);
|
db.sortedSetIncrBy('cid:' + topicData.cid + ':tids:posts', -1, postData.tid, next);
|
||||||
} else {
|
} else {
|
||||||
next();
|
next();
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ module.exports = function (Posts) {
|
|||||||
Posts.getPostField(pid, 'deleted', next);
|
Posts.getPostField(pid, 'deleted', next);
|
||||||
},
|
},
|
||||||
function (deleted, next) {
|
function (deleted, next) {
|
||||||
if (parseInt(deleted, 10) === 1 && isDelete) {
|
if (deleted && isDelete) {
|
||||||
return next(new Error('[[error:post-already-deleted]]'));
|
return next(new Error('[[error:post-already-deleted]]'));
|
||||||
} else if (parseInt(deleted, 10) !== 1 && !isDelete) {
|
} else if (!deleted && !isDelete) {
|
||||||
return next(new Error('[[error:post-already-restored]]'));
|
return next(new Error('[[error:post-already-restored]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ module.exports = function (Posts) {
|
|||||||
userData.userslug = userData.userslug || '';
|
userData.userslug = userData.userslug || '';
|
||||||
userData.reputation = userData.reputation || 0;
|
userData.reputation = userData.reputation || 0;
|
||||||
userData.postcount = userData.postcount || 0;
|
userData.postcount = userData.postcount || 0;
|
||||||
userData.banned = parseInt(userData.banned, 10) === 1;
|
userData.banned = userData.banned === 1;
|
||||||
userData.picture = userData.picture || '';
|
userData.picture = userData.picture || '';
|
||||||
userData.status = user.getStatus(userData);
|
userData.status = user.getStatus(userData);
|
||||||
userData.signature = validator.escape(String(userData.signature || ''));
|
userData.signature = validator.escape(String(userData.signature || ''));
|
||||||
|
|||||||
@@ -294,8 +294,8 @@ module.exports = function (Posts) {
|
|||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
postData.upvotes = parseInt(results.upvotes, 10);
|
postData.upvotes = results.upvotes;
|
||||||
postData.downvotes = parseInt(results.downvotes, 10);
|
postData.downvotes = results.downvotes;
|
||||||
postData.votes = postData.upvotes - postData.downvotes;
|
postData.votes = postData.upvotes - postData.downvotes;
|
||||||
Posts.updatePostVoteCount(postData, next);
|
Posts.updatePostVoteCount(postData, next);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -351,14 +351,14 @@ function generateTopicsFeed(feedOptions, feedTopics, callback) {
|
|||||||
var feed = new rss(feedOptions);
|
var feed = new rss(feedOptions);
|
||||||
|
|
||||||
if (feedTopics.length > 0) {
|
if (feedTopics.length > 0) {
|
||||||
feed.pubDate = new Date(parseInt(feedTopics[0].lastposttime, 10)).toUTCString();
|
feed.pubDate = new Date(feedTopics[0].lastposttime).toUTCString();
|
||||||
}
|
}
|
||||||
|
|
||||||
async.eachSeries(feedTopics, function (topicData, next) {
|
async.eachSeries(feedTopics, function (topicData, next) {
|
||||||
var feedItem = {
|
var feedItem = {
|
||||||
title: utils.stripHTMLTags(topicData.title, utils.tags),
|
title: utils.stripHTMLTags(topicData.title, utils.tags),
|
||||||
url: nconf.get('url') + '/topic/' + topicData.slug,
|
url: nconf.get('url') + '/topic/' + topicData.slug,
|
||||||
date: new Date(parseInt(topicData.lastposttime, 10)).toUTCString(),
|
date: new Date(topicData.lastposttime).toUTCString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (topicData.teaser && topicData.teaser.user && !feedOptions.useMainPost) {
|
if (topicData.teaser && topicData.teaser.user && !feedOptions.useMainPost) {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ User.makeAdmins = function (socket, uids, callback) {
|
|||||||
},
|
},
|
||||||
function (userData, next) {
|
function (userData, next) {
|
||||||
for (var i = 0; i < userData.length; i += 1) {
|
for (var i = 0; i < userData.length; i += 1) {
|
||||||
if (userData[i] && parseInt(userData[i].banned, 10) === 1) {
|
if (userData[i] && userData[i].banned) {
|
||||||
return callback(new Error('[[error:cant-make-banned-users-admin]]'));
|
return callback(new Error('[[error:cant-make-banned-users-admin]]'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ SocketPosts.getRawPost = function (socket, pid, callback) {
|
|||||||
posts.getPostFields(pid, ['content', 'deleted'], next);
|
posts.getPostFields(pid, ['content', 'deleted'], next);
|
||||||
},
|
},
|
||||||
function (postData, next) {
|
function (postData, next) {
|
||||||
if (parseInt(postData.deleted, 10) === 1) {
|
if (postData.deleted) {
|
||||||
return next(new Error('[[error:no-post]]'));
|
return next(new Error('[[error:no-post]]'));
|
||||||
}
|
}
|
||||||
next(null, postData.content);
|
next(null, postData.content);
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ module.exports = function (SocketPosts) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
payload.deleted = parseInt(payload.deleted, 10);
|
|
||||||
payload.privileges = payload.privileges[0];
|
payload.privileges = payload.privileges[0];
|
||||||
|
|
||||||
const allowed = payload.privileges['posts:history'] && (payload.deleted ? payload.privileges['posts:view_deleted'] : true);
|
const allowed = payload.privileges['posts:history'] && (payload.deleted ? payload.privileges['posts:view_deleted'] : true);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ module.exports = function (SocketPosts) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(result.post.deleted, 10) !== 1) {
|
if (!result.post.deleted) {
|
||||||
websockets.in('topic_' + result.topic.tid).emit('event:post_edited', result);
|
websockets.in('topic_' + result.topic.tid).emit('event:post_edited', result);
|
||||||
return callback(null, result.post);
|
return callback(null, result.post);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ helpers.postCommand = function (socket, command, eventName, notification, data,
|
|||||||
return next(new Error('[[error:invalid-pid]]'));
|
return next(new Error('[[error:invalid-pid]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(results.deleted, 10) === 1) {
|
if (results.deleted) {
|
||||||
return next(new Error('[[error:post-deleted]]'));
|
return next(new Error('[[error:post-deleted]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,9 +60,8 @@ module.exports = function (SocketPosts) {
|
|||||||
function (results, next) {
|
function (results, next) {
|
||||||
var posts = results.posts;
|
var posts = results.posts;
|
||||||
posts.tools = results.tools.tools;
|
posts.tools = results.tools.tools;
|
||||||
posts.deleted = parseInt(posts.deleted, 10) === 1;
|
|
||||||
posts.bookmarked = results.bookmarked;
|
posts.bookmarked = results.bookmarked;
|
||||||
posts.selfPost = socket.uid && socket.uid === parseInt(posts.uid, 10);
|
posts.selfPost = socket.uid && socket.uid === posts.uid;
|
||||||
posts.display_edit_tools = results.canEdit.flag;
|
posts.display_edit_tools = results.canEdit.flag;
|
||||||
posts.display_delete_tools = results.canDelete.flag;
|
posts.display_delete_tools = results.canDelete.flag;
|
||||||
posts.display_purge_tools = results.canPurge;
|
posts.display_purge_tools = results.canPurge;
|
||||||
@@ -226,9 +225,9 @@ module.exports = function (SocketPosts) {
|
|||||||
posts.getTopicFields(pid, ['tid', 'cid', 'deleted'], next);
|
posts.getTopicFields(pid, ['tid', 'cid', 'deleted'], next);
|
||||||
},
|
},
|
||||||
function (topic, next) {
|
function (topic, next) {
|
||||||
if (parseInt(topic.deleted, 10) !== 1 && command === 'delete') {
|
if (command === 'delete' && !topic.deleted) {
|
||||||
socketTopics.doTopicAction('delete', 'event:topic_deleted', socket, { tids: [topic.tid], cid: topic.cid }, next);
|
socketTopics.doTopicAction('delete', 'event:topic_deleted', socket, { tids: [topic.tid], cid: topic.cid }, next);
|
||||||
} else if (parseInt(topic.deleted, 10) === 1 && command === 'restore') {
|
} else if (command === 'restore' && topic.deleted) {
|
||||||
socketTopics.doTopicAction('restore', 'event:topic_restored', socket, { tids: [topic.tid], cid: topic.cid }, next);
|
socketTopics.doTopicAction('restore', 'event:topic_restored', socket, { tids: [topic.tid], cid: topic.cid }, next);
|
||||||
} else {
|
} else {
|
||||||
setImmediate(next);
|
setImmediate(next);
|
||||||
@@ -244,7 +243,7 @@ module.exports = function (SocketPosts) {
|
|||||||
},
|
},
|
||||||
isLast: function (next) {
|
isLast: function (next) {
|
||||||
posts.getTopicFields(pid, ['postcount'], function (err, topic) {
|
posts.getTopicFields(pid, ['postcount'], function (err, topic) {
|
||||||
next(err, topic ? parseInt(topic.postcount, 10) === 1 : false);
|
next(err, topic ? topic.postcount === 1 : false);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}, callback);
|
}, callback);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ module.exports = function (SocketTopics) {
|
|||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
if (!results.privileges['topics:read'] || (parseInt(results.topic.deleted, 10) && !results.privileges.view_deleted)) {
|
if (!results.privileges['topics:read'] || (results.topic.deleted && !results.privileges.view_deleted)) {
|
||||||
return callback(new Error('[[error:no-privileges]]'));
|
return callback(new Error('[[error:no-privileges]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -226,11 +226,11 @@ module.exports = function (Topics) {
|
|||||||
return next(new Error('[[error:no-topic]]'));
|
return next(new Error('[[error:no-topic]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(results.topicData.locked, 10) === 1 && !results.isAdminOrMod) {
|
if (results.topicData.locked && !results.isAdminOrMod) {
|
||||||
return next(new Error('[[error:topic-locked]]'));
|
return next(new Error('[[error:topic-locked]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(results.topicData.deleted, 10) === 1 && !results.isAdminOrMod) {
|
if (results.topicData.deleted && !results.isAdminOrMod) {
|
||||||
return next(new Error('[[error:topic-deleted]]'));
|
return next(new Error('[[error:topic-deleted]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +311,7 @@ module.exports = function (Topics) {
|
|||||||
function (results, next) {
|
function (results, next) {
|
||||||
postData.user = results.userInfo[0];
|
postData.user = results.userInfo[0];
|
||||||
postData.topic = results.topicInfo;
|
postData.topic = results.topicInfo;
|
||||||
postData.index = parseInt(results.topicInfo.postcount, 10) - 1;
|
postData.index = results.topicInfo.postcount - 1;
|
||||||
|
|
||||||
// Username override for guests, if enabled
|
// Username override for guests, if enabled
|
||||||
if (meta.config.allowGuestHandles && postData.uid === 0 && data.handle) {
|
if (meta.config.allowGuestHandles && postData.uid === 0 && data.handle) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ var translator = require('../translator');
|
|||||||
|
|
||||||
const intFields = [
|
const intFields = [
|
||||||
'tid', 'cid', 'uid', 'mainPid', 'deleted', 'locked', 'pinned',
|
'tid', 'cid', 'uid', 'mainPid', 'deleted', 'locked', 'pinned',
|
||||||
'timestamp', 'upvotes', 'downvotes',
|
'timestamp', 'upvotes', 'downvotes', 'lastposttime',
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = function (Topics) {
|
module.exports = function (Topics) {
|
||||||
@@ -114,6 +114,7 @@ function modifyTopic(topic) {
|
|||||||
if (topic.hasOwnProperty('timestamp')) {
|
if (topic.hasOwnProperty('timestamp')) {
|
||||||
topic.timestampISO = utils.toISOString(topic.timestamp);
|
topic.timestampISO = utils.toISOString(topic.timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (topic.hasOwnProperty('lastposttime')) {
|
if (topic.hasOwnProperty('lastposttime')) {
|
||||||
topic.lastposttimeISO = utils.toISOString(topic.lastposttime);
|
topic.lastposttimeISO = utils.toISOString(topic.lastposttime);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,9 +85,7 @@ module.exports = function (Topics) {
|
|||||||
posts.getPostsFields(pids, ['pid', 'timestamp', 'deleted'], next);
|
posts.getPostsFields(pids, ['pid', 'timestamp', 'deleted'], next);
|
||||||
},
|
},
|
||||||
function (postData, next) {
|
function (postData, next) {
|
||||||
postData = postData.filter(function (post) {
|
postData = postData.filter(post => post && !post.deleted);
|
||||||
return post && parseInt(post.deleted, 10) !== 1;
|
|
||||||
});
|
|
||||||
var pidsToAdd = [];
|
var pidsToAdd = [];
|
||||||
var scores = [];
|
var scores = [];
|
||||||
postData.forEach(function (post) {
|
postData.forEach(function (post) {
|
||||||
@@ -247,8 +245,6 @@ module.exports = function (Topics) {
|
|||||||
Topics.getTopicFields(tid, ['cid', 'postcount'], next);
|
Topics.getTopicFields(tid, ['cid', 'postcount'], next);
|
||||||
},
|
},
|
||||||
function (topicData, next) {
|
function (topicData, next) {
|
||||||
topicData.postcount = parseInt(topicData.postcount, 10);
|
|
||||||
topicData.postcount = topicData.postcount || 0;
|
|
||||||
var postCountChange = incr * topicData.postcount;
|
var postCountChange = incr * topicData.postcount;
|
||||||
|
|
||||||
async.parallel([
|
async.parallel([
|
||||||
|
|||||||
@@ -79,9 +79,7 @@ Topics.getTopicsByTids = function (tids, uid, callback) {
|
|||||||
function mapFilter(array, field) {
|
function mapFilter(array, field) {
|
||||||
return array.map(function (topic) {
|
return array.map(function (topic) {
|
||||||
return topic && topic[field] && topic[field].toString();
|
return topic && topic[field] && topic[field].toString();
|
||||||
}).filter(function (value) {
|
}).filter(value => utils.isNumber(value));
|
||||||
return utils.isNumber(value);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
topics = _topics;
|
topics = _topics;
|
||||||
@@ -132,25 +130,17 @@ Topics.getTopicsByTids = function (tids, uid, callback) {
|
|||||||
topics[i].teaser = results.teasers[i];
|
topics[i].teaser = results.teasers[i];
|
||||||
topics[i].tags = results.tags[i];
|
topics[i].tags = results.tags[i];
|
||||||
|
|
||||||
topics[i].isOwner = parseInt(topics[i].uid, 10) === parseInt(uid, 10);
|
topics[i].isOwner = topics[i].uid === parseInt(uid, 10);
|
||||||
topics[i].pinned = parseInt(topics[i].pinned, 10) === 1;
|
|
||||||
topics[i].locked = parseInt(topics[i].locked, 10) === 1;
|
|
||||||
topics[i].deleted = parseInt(topics[i].deleted, 10) === 1;
|
|
||||||
topics[i].ignored = results.isIgnored[i];
|
topics[i].ignored = results.isIgnored[i];
|
||||||
topics[i].unread = !results.hasRead[i] && !results.isIgnored[i];
|
topics[i].unread = !results.hasRead[i] && !results.isIgnored[i];
|
||||||
topics[i].bookmark = results.bookmarks[i];
|
topics[i].bookmark = results.bookmarks[i];
|
||||||
topics[i].unreplied = !topics[i].teaser;
|
topics[i].unreplied = !topics[i].teaser;
|
||||||
|
|
||||||
topics[i].upvotes = parseInt(topics[i].upvotes, 10) || 0;
|
|
||||||
topics[i].downvotes = parseInt(topics[i].downvotes, 10) || 0;
|
|
||||||
topics[i].votes = topics[i].upvotes - topics[i].downvotes;
|
|
||||||
topics[i].icons = [];
|
topics[i].icons = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
topics = topics.filter(function (topic) {
|
topics = topics.filter(topic => topic && topic.category && !topic.category.disabled);
|
||||||
return topic && topic.category && !topic.category.disabled;
|
|
||||||
});
|
|
||||||
|
|
||||||
plugins.fireHook('filter:topics.get', { topics: topics, uid: uid }, next);
|
plugins.fireHook('filter:topics.get', { topics: topics, uid: uid }, next);
|
||||||
},
|
},
|
||||||
@@ -203,10 +193,7 @@ Topics.getTopicWithPosts = function (topicData, set, uid, start, stop, reverse,
|
|||||||
topicData.mergedTimestampISO = utils.toISOString(topicData.mergedTimestamp);
|
topicData.mergedTimestampISO = utils.toISOString(topicData.mergedTimestamp);
|
||||||
topicData.related = results.related || [];
|
topicData.related = results.related || [];
|
||||||
|
|
||||||
topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
|
topicData.unreplied = topicData.postcount === 1;
|
||||||
topicData.deleted = parseInt(topicData.deleted, 10) === 1;
|
|
||||||
topicData.locked = parseInt(topicData.locked, 10) === 1;
|
|
||||||
topicData.pinned = parseInt(topicData.pinned, 10) === 1;
|
|
||||||
|
|
||||||
topicData.icons = [];
|
topicData.icons = [];
|
||||||
|
|
||||||
@@ -338,7 +325,7 @@ function getMainPosts(mainPids, uid, callback) {
|
|||||||
|
|
||||||
Topics.isLocked = function (tid, callback) {
|
Topics.isLocked = function (tid, callback) {
|
||||||
Topics.getTopicField(tid, 'locked', function (err, locked) {
|
Topics.getTopicField(tid, 'locked', function (err, locked) {
|
||||||
callback(err, parseInt(locked, 10) === 1);
|
callback(err, locked === 1);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -48,9 +48,7 @@ module.exports = function (Topics) {
|
|||||||
if (!Array.isArray(postData) || !postData.length) {
|
if (!Array.isArray(postData) || !postData.length) {
|
||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
var pids = postData.map(function (post) {
|
var pids = postData.map(post => post && post.pid);
|
||||||
return post && post.pid;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!Array.isArray(pids) || !pids.length) {
|
if (!Array.isArray(pids) || !pids.length) {
|
||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
@@ -105,15 +103,14 @@ module.exports = function (Topics) {
|
|||||||
function (results, next) {
|
function (results, next) {
|
||||||
postData.forEach(function (postObj, i) {
|
postData.forEach(function (postObj, i) {
|
||||||
if (postObj) {
|
if (postObj) {
|
||||||
postObj.deleted = parseInt(postObj.deleted, 10) === 1;
|
postObj.user = postObj.uid ? results.userData[postObj.uid] : _.clone(results.userData[postObj.uid]);
|
||||||
postObj.user = parseInt(postObj.uid, 10) ? results.userData[postObj.uid] : _.clone(results.userData[postObj.uid]);
|
|
||||||
postObj.editor = postObj.editor ? results.editors[postObj.editor] : null;
|
postObj.editor = postObj.editor ? results.editors[postObj.editor] : null;
|
||||||
postObj.bookmarked = results.bookmarks[i];
|
postObj.bookmarked = results.bookmarks[i];
|
||||||
postObj.upvoted = results.voteData.upvotes[i];
|
postObj.upvoted = results.voteData.upvotes[i];
|
||||||
postObj.downvoted = results.voteData.downvotes[i];
|
postObj.downvoted = results.voteData.downvotes[i];
|
||||||
postObj.votes = postObj.votes || 0;
|
postObj.votes = postObj.votes || 0;
|
||||||
postObj.replies = results.replies[i];
|
postObj.replies = results.replies[i];
|
||||||
postObj.selfPost = !!parseInt(uid, 10) && parseInt(uid, 10) === parseInt(postObj.uid, 10);
|
postObj.selfPost = !!parseInt(uid, 10) && parseInt(uid, 10) === postObj.uid;
|
||||||
|
|
||||||
// Username override for guests, if enabled
|
// Username override for guests, if enabled
|
||||||
if (meta.config.allowGuestHandles && postObj.uid === 0 && postObj.handle) {
|
if (meta.config.allowGuestHandles && postObj.uid === 0 && postObj.handle) {
|
||||||
@@ -238,7 +235,7 @@ module.exports = function (Topics) {
|
|||||||
posts.getPostField(pids[0], 'deleted', _next);
|
posts.getPostField(pids[0], 'deleted', _next);
|
||||||
},
|
},
|
||||||
function (deleted, _next) {
|
function (deleted, _next) {
|
||||||
isDeleted = parseInt(deleted, 10) === 1;
|
isDeleted = deleted;
|
||||||
if (!isDeleted) {
|
if (!isDeleted) {
|
||||||
latestPid = pids[0];
|
latestPid = pids[0];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,11 +86,11 @@ module.exports = function (Topics) {
|
|||||||
async.apply(db.sortedSetAdd, 'cid:' + topicData.cid + ':tids:lastposttime', lastposttime, tid),
|
async.apply(db.sortedSetAdd, 'cid:' + topicData.cid + ':tids:lastposttime', lastposttime, tid),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (parseInt(topicData.deleted, 10) !== 1) {
|
if (!topicData.deleted) {
|
||||||
tasks.push(async.apply(Topics.updateRecent, tid, lastposttime));
|
tasks.push(async.apply(Topics.updateRecent, tid, lastposttime));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(topicData.pinned, 10) !== 1) {
|
if (!topicData.pinned) {
|
||||||
tasks.push(async.apply(db.sortedSetAdd, 'cid:' + topicData.cid + ':tids', lastposttime, tid));
|
tasks.push(async.apply(db.sortedSetAdd, 'cid:' + topicData.cid + ':tids', lastposttime, tid));
|
||||||
}
|
}
|
||||||
async.series(tasks, next);
|
async.series(tasks, next);
|
||||||
|
|||||||
@@ -89,9 +89,7 @@ module.exports = function (Topics) {
|
|||||||
} else if (params.sort === 'votes') {
|
} else if (params.sort === 'votes') {
|
||||||
sortFn = sortVotes;
|
sortFn = sortVotes;
|
||||||
}
|
}
|
||||||
tids = topicData.sort(sortFn).map(function (topic) {
|
tids = topicData.sort(sortFn).map(topic => topic && topic.tid);
|
||||||
return topic && topic.tid;
|
|
||||||
});
|
|
||||||
next(null, tids);
|
next(null, tids);
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
@@ -102,17 +100,17 @@ module.exports = function (Topics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sortVotes(a, b) {
|
function sortVotes(a, b) {
|
||||||
if (parseInt(a.votes, 10) !== parseInt(b.votes, 10)) {
|
if (a.votes !== b.votes) {
|
||||||
return b.votes - a.votes;
|
return b.votes - a.votes;
|
||||||
}
|
}
|
||||||
return parseInt(b.postcount, 10) - parseInt(a.postcount, 10);
|
return b.postcount - a.postcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortPopular(a, b) {
|
function sortPopular(a, b) {
|
||||||
if (parseInt(a.postcount, 10) !== parseInt(b.postcount, 10)) {
|
if (a.postcount !== b.postcount) {
|
||||||
return b.postcount - a.postcount;
|
return b.postcount - a.postcount;
|
||||||
}
|
}
|
||||||
return parseInt(b.viewcount, 10) - parseInt(a.viewcount, 10);
|
return b.viewcount - a.viewcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterTids(tids, params, callback) {
|
function filterTids(tids, params, callback) {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ module.exports = function (Topics) {
|
|||||||
var tidToPost = {};
|
var tidToPost = {};
|
||||||
|
|
||||||
topics.forEach(function (topic) {
|
topics.forEach(function (topic) {
|
||||||
counts.push(topic && (parseInt(topic.postcount, 10) || 0));
|
counts.push(topic && topic.postcount);
|
||||||
if (topic) {
|
if (topic) {
|
||||||
if (topic.teaserPid === 'null') {
|
if (topic.teaserPid === 'null') {
|
||||||
delete topic.teaserPid;
|
delete topic.teaserPid;
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ module.exports = function (Topics) {
|
|||||||
function (_topicData, next) {
|
function (_topicData, next) {
|
||||||
topicData = _topicData;
|
topicData = _topicData;
|
||||||
|
|
||||||
if (parseInt(topicData.deleted, 10) === 1 && isDelete) {
|
if (topicData.deleted && isDelete) {
|
||||||
return callback(new Error('[[error:topic-already-deleted]]'));
|
return callback(new Error('[[error:topic-already-deleted]]'));
|
||||||
} else if (parseInt(topicData.deleted, 10) !== 1 && !isDelete) {
|
} else if (!topicData.deleted && !isDelete) {
|
||||||
return callback(new Error('[[error:topic-already-restored]]'));
|
return callback(new Error('[[error:topic-already-restored]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +289,7 @@ module.exports = function (Topics) {
|
|||||||
db.sortedSetAdd('cid:' + cid + ':tids:posts', topic.postcount, tid, next);
|
db.sortedSetAdd('cid:' + cid + ':tids:posts', topic.postcount, tid, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
var votes = (parseInt(topic.upvotes, 10) || 0) - (parseInt(topic.downvotes, 10) || 0);
|
var votes = topic.upvotes - topic.downvotes;
|
||||||
db.sortedSetAdd('cid:' + cid + ':tids:votes', votes, tid, next);
|
db.sortedSetAdd('cid:' + cid + ':tids:votes', votes, tid, next);
|
||||||
},
|
},
|
||||||
], function (err) {
|
], function (err) {
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ module.exports = function (Topics) {
|
|||||||
tidsByFilter.watched.push(topic.tid);
|
tidsByFilter.watched.push(topic.tid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(topic.postcount, 10) <= 1) {
|
if (topic.postcount <= 1) {
|
||||||
counts.unreplied += 1;
|
counts.unreplied += 1;
|
||||||
tidsByFilter.unreplied.push(topic.tid);
|
tidsByFilter.unreplied.push(topic.tid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,13 +67,13 @@ module.exports = function (User) {
|
|||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(User.getUserFields, uid, ['banned', 'banned:expire']),
|
async.apply(User.getUserFields, uid, ['banned', 'banned:expire']),
|
||||||
function (userData, next) {
|
function (userData, next) {
|
||||||
var banned = userData && parseInt(userData.banned, 10) === 1;
|
var banned = userData && userData.banned;
|
||||||
if (!banned) {
|
if (!banned) {
|
||||||
return next(null, banned);
|
return next(null, banned);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If they are banned, see if the ban has expired
|
// If they are banned, see if the ban has expired
|
||||||
var stillBanned = !parseInt(userData['banned:expire'], 10) || Date.now() < parseInt(userData['banned:expire'], 10);
|
var stillBanned = !userData['banned:expire'] || Date.now() < userData['banned:expire'];
|
||||||
|
|
||||||
if (stillBanned) {
|
if (stillBanned) {
|
||||||
return next(null, true);
|
return next(null, true);
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ var utils = require('../utils');
|
|||||||
|
|
||||||
const intFields = [
|
const intFields = [
|
||||||
'uid', 'postcount', 'topiccount', 'reputation', 'profileviews',
|
'uid', 'postcount', 'topiccount', 'reputation', 'profileviews',
|
||||||
'banned', 'email:confirmed', 'joindate', 'lastonline', 'lastqueuetime',
|
'banned', 'banned:expire', 'email:confirmed', 'joindate', 'lastonline', 'lastqueuetime',
|
||||||
'lastposttime',
|
'lastposttime', 'followingCount', 'followerCount',
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = function (User) {
|
module.exports = function (User) {
|
||||||
@@ -167,7 +167,7 @@ module.exports = function (User) {
|
|||||||
user.picture = User.getDefaultAvatar();
|
user.picture = User.getDefaultAvatar();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.hasOwnProperty('status') && parseInt(user.lastonline, 10)) {
|
if (user.hasOwnProperty('status') && user.lastonline) {
|
||||||
user.status = User.getStatus(user);
|
user.status = User.getStatus(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +192,7 @@ module.exports = function (User) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (user.hasOwnProperty('banned:expire')) {
|
if (user.hasOwnProperty('banned:expire')) {
|
||||||
user.banned_until = parseInt(user['banned:expire'], 10) || 0;
|
user.banned_until = user['banned:expire'];
|
||||||
user.banned_until_readable = user.banned_until ? new Date(user.banned_until).toString() : 'Not Banned';
|
user.banned_until_readable = user.banned_until ? new Date(user.banned_until).toString() : 'Not Banned';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -85,14 +85,6 @@ User.getUsersWithFields = function (uids, fields, uid, callback) {
|
|||||||
if (user.hasOwnProperty('status')) {
|
if (user.hasOwnProperty('status')) {
|
||||||
user.status = User.getStatus(user);
|
user.status = User.getStatus(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.hasOwnProperty('banned')) {
|
|
||||||
user.banned = parseInt(user.banned, 10) === 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user.hasOwnProperty(['email:confirmed'])) {
|
|
||||||
user['email:confirmed'] = parseInt(user['email:confirmed'], 10) === 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
plugins.fireHook('filter:userlist.get', { users: results.userData, uid: uid }, next);
|
plugins.fireHook('filter:userlist.get', { users: results.userData, uid: uid }, next);
|
||||||
@@ -112,10 +104,10 @@ User.getUsers = function (uids, uid, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
User.getStatus = function (userData) {
|
User.getStatus = function (userData) {
|
||||||
if (parseInt(userData.uid, 10) <= 0) {
|
if (userData.uid <= 0) {
|
||||||
return 'offline';
|
return 'offline';
|
||||||
}
|
}
|
||||||
var isOnline = (Date.now() - parseInt(userData.lastonline, 10)) < 300000;
|
var isOnline = (Date.now() - userData.lastonline) < 300000;
|
||||||
return isOnline ? (userData.status || 'online') : 'offline';
|
return isOnline ? (userData.status || 'online') : 'offline';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ module.exports = function (User) {
|
|||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
if (!parseInt(results.userData.uid, 10)) {
|
if (!results.userData.uid) {
|
||||||
return next(new Error('[[error:no-user]]'));
|
return next(new Error('[[error:no-user]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ module.exports = function (User) {
|
|||||||
|
|
||||||
var userData = results.userData;
|
var userData = results.userData;
|
||||||
|
|
||||||
if (parseInt(userData.banned, 10) === 1) {
|
if (userData.banned) {
|
||||||
return next(new Error('[[error:user-banned]]'));
|
return next(new Error('[[error:user-banned]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,9 +81,7 @@ module.exports = function (User) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function filterAndSortUids(uids, data, callback) {
|
function filterAndSortUids(uids, data, callback) {
|
||||||
uids = uids.filter(function (uid) {
|
uids = uids.filter(uid => parseInt(uid, 10));
|
||||||
return parseInt(uid, 10);
|
|
||||||
});
|
|
||||||
|
|
||||||
var fields = [];
|
var fields = [];
|
||||||
|
|
||||||
@@ -111,31 +109,24 @@ module.exports = function (User) {
|
|||||||
User.getUsersFields(uids, fields, next);
|
User.getUsersFields(uids, fields, next);
|
||||||
},
|
},
|
||||||
function (userData, next) {
|
function (userData, next) {
|
||||||
|
userData = userData.filter(Boolean);
|
||||||
if (data.onlineOnly) {
|
if (data.onlineOnly) {
|
||||||
userData = userData.filter(function (user) {
|
userData = userData.filter(user => user.status !== 'offline' && (Date.now() - user.lastonline < 300000));
|
||||||
return user && user.status !== 'offline' && (Date.now() - parseInt(user.lastonline, 10) < 300000);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.bannedOnly) {
|
if (data.bannedOnly) {
|
||||||
userData = userData.filter(function (user) {
|
userData = userData.filter(user => user.banned);
|
||||||
return user && parseInt(user.banned, 10) === 1;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.flaggedOnly) {
|
if (data.flaggedOnly) {
|
||||||
userData = userData.filter(function (user) {
|
userData = userData.filter(user => parseInt(user.flags, 10) > 0);
|
||||||
return user && parseInt(user.flags, 10) > 0;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.sortBy) {
|
if (data.sortBy) {
|
||||||
sortUsers(userData, data.sortBy);
|
sortUsers(userData, data.sortBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
uids = userData.map(function (user) {
|
uids = userData.map(user => user.uid);
|
||||||
return user && user.uid;
|
|
||||||
});
|
|
||||||
|
|
||||||
next(null, uids);
|
next(null, uids);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -156,6 +156,14 @@ describe('Set methods', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return 0 if set does not exist', function (done) {
|
||||||
|
db.setCount('doesnotexist', function (err, count) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.strictEqual(count, 0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('setsCount()', function () {
|
describe('setsCount()', function () {
|
||||||
|
|||||||
@@ -273,10 +273,10 @@ describe('Post\'s', function () {
|
|||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
posts.getPostField(replyPid, 'deleted', function (err, deleted) {
|
posts.getPostField(replyPid, 'deleted', function (err, deleted) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(parseInt(deleted, 10), 1);
|
assert.strictEqual(deleted, 1);
|
||||||
posts.getPostField(mainPid, 'deleted', function (err, deleted) {
|
posts.getPostField(mainPid, 'deleted', function (err, deleted) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(parseInt(deleted, 10), 1);
|
assert.strictEqual(deleted, 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -290,7 +290,7 @@ describe('Post\'s', function () {
|
|||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
topics.getTopicField(data.topicData.tid, 'deleted', function (err, deleted) {
|
topics.getTopicField(data.topicData.tid, 'deleted', function (err, deleted) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(parseInt(deleted, 10), 1);
|
assert.strictEqual(deleted, 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -373,9 +373,9 @@ describe('Topic\'s', function () {
|
|||||||
it('should pin topic', function (done) {
|
it('should pin topic', function (done) {
|
||||||
socketTopics.pin({ uid: 1 }, { tids: [newTopic.tid], cid: categoryObj.cid }, function (err) {
|
socketTopics.pin({ uid: 1 }, { tids: [newTopic.tid], cid: categoryObj.cid }, function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
db.getObjectField('topic:' + newTopic.tid, 'pinned', function (err, pinned) {
|
topics.getTopicField(newTopic.tid, 'pinned', function (err, pinned) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.strictEqual(parseInt(pinned, 10), 1);
|
assert.strictEqual(pinned, 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -384,9 +384,9 @@ describe('Topic\'s', function () {
|
|||||||
it('should unpin topic', function (done) {
|
it('should unpin topic', function (done) {
|
||||||
socketTopics.unpin({ uid: 1 }, { tids: [newTopic.tid], cid: categoryObj.cid }, function (err) {
|
socketTopics.unpin({ uid: 1 }, { tids: [newTopic.tid], cid: categoryObj.cid }, function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
db.getObjectField('topic:' + newTopic.tid, 'pinned', function (err, pinned) {
|
topics.getTopicField(newTopic.tid, 'pinned', function (err, pinned) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.strictEqual(parseInt(pinned, 10), 0);
|
assert.strictEqual(pinned, 0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
13
test/user.js
13
test/user.js
@@ -456,12 +456,19 @@ describe('User', function () {
|
|||||||
User.reset.commit(code, 'newpassword', function (err) {
|
User.reset.commit(code, 'newpassword', function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
db.getObject('user:' + uid, function (err, userData) {
|
async.parallel({
|
||||||
|
userData: function (next) {
|
||||||
|
User.getUserData(uid, next);
|
||||||
|
},
|
||||||
|
password: function (next) {
|
||||||
|
db.getObjectField('user:' + uid, 'password', next);
|
||||||
|
},
|
||||||
|
}, function (err, results) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
Password.compare('newpassword', userData.password, function (err, match) {
|
Password.compare('newpassword', results.password, function (err, match) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert(match);
|
assert(match);
|
||||||
assert.equal(parseInt(userData['email:confirmed'], 10), 1);
|
assert.strictEqual(results.userData['email:confirmed'], 1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user