mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 11:11:04 +01:00
Fix space-before-function-paren linter rule
This commit is contained in:
@@ -13,35 +13,35 @@ var privileges = require('../privileges');
|
||||
var batch = require('../batch');
|
||||
|
||||
|
||||
module.exports = function(Categories) {
|
||||
module.exports = function (Categories) {
|
||||
|
||||
Categories.getRecentReplies = function(cid, uid, count, callback) {
|
||||
Categories.getRecentReplies = function (cid, uid, count, callback) {
|
||||
if (!parseInt(count, 10)) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.getSortedSetRevRange('cid:' + cid + ':pids', 0, count - 1, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
function (pids, next) {
|
||||
privileges.posts.filter('read', pids, uid, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
function (pids, next) {
|
||||
posts.getPostSummaryByPids(pids, uid, {stripTags: true}, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
Categories.updateRecentTid = function(cid, tid, callback) {
|
||||
Categories.updateRecentTid = function (cid, tid, callback) {
|
||||
async.parallel({
|
||||
count: function(next) {
|
||||
count: function (next) {
|
||||
db.sortedSetCard('cid:' + cid + ':recent_tids', next);
|
||||
},
|
||||
numRecentReplies: function(next) {
|
||||
numRecentReplies: function (next) {
|
||||
db.getObjectField('category:' + cid, 'numRecentReplies', next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -50,46 +50,46 @@ module.exports = function(Categories) {
|
||||
return db.sortedSetAdd('cid:' + cid + ':recent_tids', Date.now(), tid, callback);
|
||||
}
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.getSortedSetRangeWithScores('cid:' + cid + ':recent_tids', 0, results.count - results.numRecentReplies, next);
|
||||
},
|
||||
function(data, next) {
|
||||
function (data, next) {
|
||||
if (!data.length) {
|
||||
return next();
|
||||
}
|
||||
db.sortedSetsRemoveRangeByScore(['cid:' + cid + ':recent_tids'], '-inf', data[data.length - 1].score, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetAdd('cid:' + cid + ':recent_tids', Date.now(), tid, next);
|
||||
}
|
||||
], callback);
|
||||
});
|
||||
};
|
||||
|
||||
Categories.getRecentTopicReplies = function(categoryData, uid, callback) {
|
||||
Categories.getRecentTopicReplies = function (categoryData, uid, callback) {
|
||||
if (!Array.isArray(categoryData) || !categoryData.length) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
var keys = categoryData.map(function(category) {
|
||||
function (next) {
|
||||
var keys = categoryData.map(function (category) {
|
||||
return 'cid:' + category.cid + ':recent_tids';
|
||||
});
|
||||
db.getSortedSetsMembers(keys, next);
|
||||
},
|
||||
function(results, next) {
|
||||
function (results, next) {
|
||||
var tids = _.flatten(results);
|
||||
|
||||
tids = tids.filter(function(tid, index, array) {
|
||||
tids = tids.filter(function (tid, index, array) {
|
||||
return !!tid && array.indexOf(tid) === index;
|
||||
});
|
||||
privileges.topics.filterTids('read', tids, uid, next);
|
||||
},
|
||||
function(tids, next) {
|
||||
function (tids, next) {
|
||||
getTopics(tids, next);
|
||||
},
|
||||
function(topics, next) {
|
||||
function (topics, next) {
|
||||
assignTopicsToCategories(categoryData, topics);
|
||||
|
||||
bubbleUpChildrenPosts(categoryData);
|
||||
@@ -105,16 +105,16 @@ module.exports = function(Categories) {
|
||||
function (next) {
|
||||
topics.getTopicsFields(tids, ['tid', 'mainPid', 'slug', 'title', 'teaserPid', 'cid', 'postcount'], next);
|
||||
},
|
||||
function(_topicData, next) {
|
||||
function (_topicData, next) {
|
||||
topicData = _topicData;
|
||||
topicData.forEach(function(topic) {
|
||||
topicData.forEach(function (topic) {
|
||||
if (topic) {
|
||||
topic.teaserPid = topic.teaserPid || topic.mainPid;
|
||||
}
|
||||
});
|
||||
var cids = _topicData.map(function(topic) {
|
||||
var cids = _topicData.map(function (topic) {
|
||||
return topic && topic.cid;
|
||||
}).filter(function(cid, index, array) {
|
||||
}).filter(function (cid, index, array) {
|
||||
return cid && array.indexOf(cid) === index;
|
||||
});
|
||||
|
||||
@@ -125,10 +125,10 @@ module.exports = function(Categories) {
|
||||
},
|
||||
function (results, next) {
|
||||
var parentCids = {};
|
||||
results.categoryData.forEach(function(category) {
|
||||
results.categoryData.forEach(function (category) {
|
||||
parentCids[category.cid] = category.parentCid;
|
||||
});
|
||||
results.teasers.forEach(function(teaser, index) {
|
||||
results.teasers.forEach(function (teaser, index) {
|
||||
if (teaser) {
|
||||
teaser.cid = topicData[index].cid;
|
||||
teaser.parentCid = parseInt(parentCids[teaser.cid]) || 0;
|
||||
@@ -146,25 +146,25 @@ module.exports = function(Categories) {
|
||||
}
|
||||
|
||||
function assignTopicsToCategories(categories, topics) {
|
||||
categories.forEach(function(category) {
|
||||
category.posts = topics.filter(function(topic) {
|
||||
categories.forEach(function (category) {
|
||||
category.posts = topics.filter(function (topic) {
|
||||
return topic.cid && (parseInt(topic.cid, 10) === parseInt(category.cid, 10) ||
|
||||
parseInt(topic.parentCid, 10) === parseInt(category.cid, 10));
|
||||
}).sort(function(a, b) {
|
||||
}).sort(function (a, b) {
|
||||
return b.pid - a.pid;
|
||||
}).slice(0, parseInt(category.numRecentReplies, 10));
|
||||
});
|
||||
}
|
||||
|
||||
function bubbleUpChildrenPosts(categoryData) {
|
||||
categoryData.forEach(function(category) {
|
||||
categoryData.forEach(function (category) {
|
||||
if (category.posts.length) {
|
||||
return;
|
||||
}
|
||||
var posts = [];
|
||||
getPostsRecursive(category, posts);
|
||||
|
||||
posts.sort(function(a, b) {
|
||||
posts.sort(function (a, b) {
|
||||
return b.pid - a.pid;
|
||||
});
|
||||
if (posts.length) {
|
||||
@@ -174,19 +174,19 @@ module.exports = function(Categories) {
|
||||
}
|
||||
|
||||
function getPostsRecursive(category, posts) {
|
||||
category.posts.forEach(function(p) {
|
||||
category.posts.forEach(function (p) {
|
||||
posts.push(p);
|
||||
});
|
||||
|
||||
category.children.forEach(function(child) {
|
||||
category.children.forEach(function (child) {
|
||||
getPostsRecursive(child, posts);
|
||||
});
|
||||
}
|
||||
|
||||
Categories.moveRecentReplies = function(tid, oldCid, cid, callback) {
|
||||
callback = callback || function() {};
|
||||
Categories.moveRecentReplies = function (tid, oldCid, cid, callback) {
|
||||
callback = callback || function () {};
|
||||
updatePostCount(tid, oldCid, cid);
|
||||
topics.getPids(tid, function(err, pids) {
|
||||
topics.getPids(tid, function (err, pids) {
|
||||
if (err) {
|
||||
return winston.error(err.message);
|
||||
}
|
||||
@@ -195,27 +195,27 @@ module.exports = function(Categories) {
|
||||
return;
|
||||
}
|
||||
|
||||
batch.processArray(pids, function(pids, next) {
|
||||
batch.processArray(pids, function (pids, next) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
posts.getPostsFields(pids, ['timestamp'], next);
|
||||
},
|
||||
function(postData, next) {
|
||||
var timestamps = postData.map(function(post) {
|
||||
function (postData, next) {
|
||||
var timestamps = postData.map(function (post) {
|
||||
return post && post.timestamp;
|
||||
});
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetRemove('cid:' + oldCid + ':pids', pids, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetAdd('cid:' + cid + ':pids', timestamps, pids, next);
|
||||
}
|
||||
], next);
|
||||
}
|
||||
], next);
|
||||
}, function(err) {
|
||||
}, function (err) {
|
||||
if (err) {
|
||||
winston.error(err.stack);
|
||||
}
|
||||
@@ -225,7 +225,7 @@ module.exports = function(Categories) {
|
||||
};
|
||||
|
||||
function updatePostCount(tid, oldCid, newCid) {
|
||||
topics.getTopicField(tid, 'postcount', function(err, postCount) {
|
||||
topics.getTopicField(tid, 'postcount', function (err, postCount) {
|
||||
if (err) {
|
||||
return winston.error(err.message);
|
||||
}
|
||||
@@ -233,13 +233,13 @@ module.exports = function(Categories) {
|
||||
return;
|
||||
}
|
||||
async.parallel([
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.incrObjectFieldBy('category:' + oldCid, 'post_count', -postCount, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.incrObjectFieldBy('category:' + newCid, 'post_count', postCount, next);
|
||||
}
|
||||
], function(err) {
|
||||
], function (err) {
|
||||
if (err) {
|
||||
winston.error(err.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user