Do you really want to purge this category "' + $('form.category').find('input[data-name="name"]').val() + '"?
Purging a category will remove all topics and posts, and delete the category from the database. If you want to remove a category temporarily, you\'ll want to "disable" the category instead.
', function(confirm) {
+ bootbox.confirm('Do you really want to purge this category "' + $('form.category').find('input[data-name="name"]').val() + '"?
Purging a category will remove all topics and posts, and delete the category from the database. If you want to remove a category temporarily, you\'ll want to "disable" the category instead.
', function (confirm) {
if (!confirm) {
return;
}
- socket.emit('admin.categories.purge', ajaxify.data.category.cid, function(err) {
+ socket.emit('admin.categories.purge', ajaxify.data.category.cid, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -103,9 +103,9 @@ define('admin/manage/category', [
});
});
- $('.copy-settings').on('click', function() {
- selectCategoryModal(function(cid) {
- socket.emit('admin.categories.copySettingsFrom', {fromCid: cid, toCid: ajaxify.data.category.cid}, function(err) {
+ $('.copy-settings').on('click', function () {
+ selectCategoryModal(function (cid) {
+ socket.emit('admin.categories.copySettingsFrom', {fromCid: cid, toCid: ajaxify.data.category.cid}, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -116,7 +116,7 @@ define('admin/manage/category', [
return false;
});
- $('.upload-button').on('click', function() {
+ $('.upload-button').on('click', function () {
var inputEl = $(this);
var cid = inputEl.attr('data-cid');
@@ -124,7 +124,7 @@ define('admin/manage/category', [
title: 'Upload category image',
route: config.relative_path + '/api/admin/category/uploadpicture',
params: {cid: cid}
- }, function(imageUrlOnServer) {
+ }, function (imageUrlOnServer) {
$('#category-image').val(imageUrlOnServer);
var previewBox = inputEl.parent().parent().siblings('.category-preview');
previewBox.css('background', 'url(' + imageUrlOnServer + '?' + new Date().getTime() + ')');
@@ -133,11 +133,11 @@ define('admin/manage/category', [
});
});
- $('#category-image').on('change', function() {
+ $('#category-image').on('change', function () {
$('.category-preview').css('background-image', $(this).val() ? ('url("' + $(this).val() + '")') : '');
});
- $('.delete-image').on('click', function(e) {
+ $('.delete-image').on('click', function (e) {
e.preventDefault();
var inputEl = $('#category-image');
@@ -149,18 +149,18 @@ define('admin/manage/category', [
$(this).parent().addClass('hide').hide();
});
- $('.category-preview').on('click', function() {
+ $('.category-preview').on('click', function () {
iconSelect.init($(this).find('i'), modified);
});
$('button[data-action="setParent"], button[data-action="changeParent"]').on('click', Category.launchParentSelector);
- $('button[data-action="removeParent"]').on('click', function() {
+ $('button[data-action="removeParent"]').on('click', function () {
var payload = {};
payload[ajaxify.data.category.cid] = {
parentCid: 0
};
- socket.emit('admin.categories.update', payload, function(err) {
+ socket.emit('admin.categories.update', payload, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -173,8 +173,8 @@ define('admin/manage/category', [
Category.setupPrivilegeTable();
};
- Category.setupPrivilegeTable = function() {
- $('.privilege-table-container').on('change', 'input[type="checkbox"]', function() {
+ Category.setupPrivilegeTable = function () {
+ $('.privilege-table-container').on('change', 'input[type="checkbox"]', function () {
var checkboxEl = $(this),
privilege = checkboxEl.parent().attr('data-privilege'),
state = checkboxEl.prop('checked'),
@@ -185,7 +185,7 @@ define('admin/manage/category', [
if (member) {
if (isGroup && privilege === 'groups:moderate' && !isPrivate && state) {
- bootbox.confirm('');
@@ -284,14 +284,14 @@
}
},
- isMobile: function() {
+ isMobile: function () {
var env = utils.findBootstrapEnvironment();
- return ['xs', 'sm'].some(function(targetEnv) {
+ return ['xs', 'sm'].some(function (targetEnv) {
return targetEnv === env;
});
},
- getHoursArray: function() {
+ getHoursArray: function () {
var currentHour = new Date().getHours(),
labels = [];
@@ -303,7 +303,7 @@
return labels.reverse();
},
- getDaysArray: function(from) {
+ getDaysArray: function (from) {
var currentDay = new Date(from || Date.now()).getTime(),
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
labels = [],
@@ -318,7 +318,7 @@
},
/* Retrieved from http://stackoverflow.com/a/7557433 @ 27 Mar 2016 */
- isElementInViewport: function(el) {
+ isElementInViewport: function (el) {
//special bonus for those using jQuery
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];
@@ -335,7 +335,7 @@
},
// get all the url params in a single key/value hash
- params: function(options) {
+ params: function (options) {
var a, hash = {}, params;
options = options || {};
@@ -346,7 +346,7 @@
}
params = (a ? a.search : window.location.search).substring(1).split("&");
- params.forEach(function(param) {
+ params.forEach(function (param) {
var val = param.split('='),
key = decodeURI(val[0]),
value = options.skipToType[key] ? decodeURI(val[1]) : utils.toType(decodeURI(val[1]));
@@ -368,11 +368,11 @@
return hash;
},
- param: function(key) {
+ param: function (key) {
return this.params()[key];
},
- urlToLocation: function(url) {
+ urlToLocation: function (url) {
var a = document.createElement('a');
a.href = url;
return a;
@@ -380,7 +380,7 @@
// return boolean if string 'true' or string 'false', or if a parsable string which is a number
// also supports JSON object and/or arrays parsing
- toType: function(str) {
+ toType: function (str) {
var type = typeof str;
if (type !== 'string') {
return str;
@@ -409,7 +409,7 @@
// get example: utils.props(A, 'a.b.c') // returns {d: 10}
// get example: utils.props(A, 'a.b.c.foo.bar') // returns undefined without throwing a TypeError
// credits to github.com/gkindel
- props: function(obj, props, value) {
+ props: function (obj, props, value) {
if(obj === undefined) {
obj = window;
}
@@ -433,7 +433,7 @@
return utils.props(obj[prop], newProps, value);
},
- isInternalURI: function(targetLocation, referenceLocation, relative_path) {
+ isInternalURI: function (targetLocation, referenceLocation, relative_path) {
return targetLocation.host === '' || // Relative paths are always internal links
(
targetLocation.host === referenceLocation.host && targetLocation.protocol === referenceLocation.protocol && // Otherwise need to check if protocol and host match
@@ -455,7 +455,7 @@
}
if (typeof String.prototype.endsWith != 'function') {
- String.prototype.endsWith = function(suffix) {
+ String.prototype.endsWith = function (suffix) {
if (this.length < suffix.length) {
return false;
}
@@ -469,7 +469,7 @@
}
if (typeof String.prototype.rtrim != 'function') {
- String.prototype.rtrim = function() {
+ String.prototype.rtrim = function () {
return this.replace(/\s+$/g, '');
};
}
diff --git a/public/src/widgets.js b/public/src/widgets.js
index c798ce0f93..ede518db4d 100644
--- a/public/src/widgets.js
+++ b/public/src/widgets.js
@@ -1,11 +1,11 @@
"use strict";
/*global ajaxify, templates, config, utils*/
-(function(ajaxify) {
+(function (ajaxify) {
ajaxify.widgets = {};
- ajaxify.widgets.reposition = function(location) {
- $('body [no-widget-class]').each(function() {
+ ajaxify.widgets.reposition = function (location) {
+ $('body [no-widget-class]').each(function () {
var $this = $(this);
if ($this.attr('no-widget-target') === location) {
$this.removeClass();
@@ -14,15 +14,15 @@
});
};
- ajaxify.widgets.render = function(template, url, callback) {
- callback = callback || function() {};
+ ajaxify.widgets.render = function (template, url, callback) {
+ callback = callback || function () {};
if (template.match(/^admin/)) {
return callback();
}
var widgetLocations = ['sidebar', 'footer', 'header'], numLocations;
- $('#content [widget-area]').each(function() {
+ $('#content [widget-area]').each(function () {
var location = $(this).attr('widget-area');
if ($.inArray(location, widgetLocations) === -1) {
widgetLocations.push(location);
@@ -41,7 +41,7 @@
template: template + '.tpl',
url: url,
isMobile: utils.isMobile()
- }, function(renderedAreas) {
+ }, function (renderedAreas) {
for (var x = 0; x < renderedAreas.length; ++x) {
var renderedWidgets = renderedAreas[x].widgets,
location = renderedAreas[x].location,
@@ -82,7 +82,7 @@
var widgetAreas = $('#content [widget-area]');
widgetAreas.find('img:not(.not-responsive)').addClass('img-responsive');
widgetAreas.find('.timeago').timeago();
- widgetAreas.find('img[title].teaser-pic,img[title].user-img').each(function() {
+ widgetAreas.find('img[title].teaser-pic,img[title].user-img').each(function () {
$(this).tooltip({
placement: 'top',
title: $(this).attr('title')
diff --git a/src/analytics.js b/src/analytics.js
index f757832934..ab834b75b2 100644
--- a/src/analytics.js
+++ b/src/analytics.js
@@ -6,7 +6,7 @@ var winston = require('winston');
var db = require('./database');
-(function(Analytics) {
+(function (Analytics) {
var counters = {};
var pageViews = 0;
@@ -15,24 +15,24 @@ var db = require('./database');
var isCategory = /^(?:\/api)?\/category\/(\d+)/;
- new cronJob('*/10 * * * *', function() {
+ new cronJob('*/10 * * * *', function () {
Analytics.writeData();
}, null, true);
- Analytics.increment = function(keys) {
+ Analytics.increment = function (keys) {
keys = Array.isArray(keys) ? keys : [keys];
- keys.forEach(function(key) {
+ keys.forEach(function (key) {
counters[key] = counters[key] || 0;
++counters[key];
});
};
- Analytics.pageView = function(payload) {
+ Analytics.pageView = function (payload) {
++pageViews;
if (payload.ip) {
- db.sortedSetScore('ip:recent', payload.ip, function(err, score) {
+ db.sortedSetScore('ip:recent', payload.ip, function (err, score) {
if (err) {
return;
}
@@ -58,7 +58,7 @@ var db = require('./database');
}
};
- Analytics.writeData = function() {
+ Analytics.writeData = function () {
var today = new Date();
var month = new Date();
var dbQueue = [];
@@ -92,14 +92,14 @@ var db = require('./database');
}
}
- async.parallel(dbQueue, function(err) {
+ async.parallel(dbQueue, function (err) {
if (err) {
winston.error('[analytics] Encountered error while writing analytics to data store: ' + err.message);
}
});
};
- Analytics.getHourlyStatsForSet = function(set, hour, numHours, callback) {
+ Analytics.getHourlyStatsForSet = function (set, hour, numHours, callback) {
var terms = {},
hoursArr = [];
@@ -111,19 +111,19 @@ var db = require('./database');
hour.setHours(hour.getHours() - 1, 0, 0, 0);
}
- db.sortedSetScores(set, hoursArr, function(err, counts) {
+ db.sortedSetScores(set, hoursArr, function (err, counts) {
if (err) {
return callback(err);
}
- hoursArr.forEach(function(term, index) {
+ hoursArr.forEach(function (term, index) {
terms[term] = parseInt(counts[index], 10) || 0;
});
var termsArr = [];
hoursArr.reverse();
- hoursArr.forEach(function(hour) {
+ hoursArr.forEach(function (hour) {
termsArr.push(terms[hour]);
});
@@ -131,36 +131,36 @@ var db = require('./database');
});
};
- Analytics.getDailyStatsForSet = function(set, day, numDays, callback) {
+ Analytics.getDailyStatsForSet = function (set, day, numDays, callback) {
var daysArr = [];
day = new Date(day);
day.setDate(day.getDate() + 1); // set the date to tomorrow, because getHourlyStatsForSet steps *backwards* 24 hours to sum up the values
day.setHours(0, 0, 0, 0);
- async.whilst(function() {
+ async.whilst(function () {
return numDays--;
- }, function(next) {
- Analytics.getHourlyStatsForSet(set, day.getTime() - (1000 * 60 * 60 * 24 * numDays), 24, function(err, day) {
+ }, function (next) {
+ Analytics.getHourlyStatsForSet(set, day.getTime() - (1000 * 60 * 60 * 24 * numDays), 24, function (err, day) {
if (err) {
return next(err);
}
- daysArr.push(day.reduce(function(cur, next) {
+ daysArr.push(day.reduce(function (cur, next) {
return cur + next;
}));
next();
});
- }, function(err) {
+ }, function (err) {
callback(err, daysArr);
});
};
- Analytics.getUnwrittenPageviews = function() {
+ Analytics.getUnwrittenPageviews = function () {
return pageViews;
};
- Analytics.getMonthlyPageViews = function(callback) {
+ Analytics.getMonthlyPageViews = function (callback) {
var thisMonth = new Date();
var lastMonth = new Date();
thisMonth.setMonth(thisMonth.getMonth(), 1);
@@ -170,7 +170,7 @@ var db = require('./database');
var values = [thisMonth.getTime(), lastMonth.getTime()];
- db.sortedSetScores('analytics:pageviews:month', values, function(err, scores) {
+ db.sortedSetScores('analytics:pageviews:month', values, function (err, scores) {
if (err) {
return callback(err);
}
@@ -178,7 +178,7 @@ var db = require('./database');
});
};
- Analytics.getCategoryAnalytics = function(cid, callback) {
+ Analytics.getCategoryAnalytics = function (cid, callback) {
async.parallel({
'pageviews:hourly': async.apply(Analytics.getHourlyStatsForSet, 'analytics:pageviews:byCid:' + cid, Date.now(), 24),
'pageviews:daily': async.apply(Analytics.getDailyStatsForSet, 'analytics:pageviews:byCid:' + cid, Date.now(), 30),
@@ -187,7 +187,7 @@ var db = require('./database');
}, callback);
};
- Analytics.getErrorAnalytics = function(callback) {
+ Analytics.getErrorAnalytics = function (callback) {
async.parallel({
'not-found': async.apply(Analytics.getDailyStatsForSet, 'analytics:errors:404', Date.now(), 7),
'toobusy': async.apply(Analytics.getDailyStatsForSet, 'analytics:errors:503', Date.now(), 7)
diff --git a/src/batch.js b/src/batch.js
index 329ae624d5..ca0944b80d 100644
--- a/src/batch.js
+++ b/src/batch.js
@@ -6,17 +6,17 @@ var async = require('async'),
db = require('./database'),
utils = require('../public/src/utils');
-(function(Batch) {
+(function (Batch) {
var DEFAULT_BATCH_SIZE = 100;
- Batch.processSortedSet = function(setKey, process, options, callback) {
+ Batch.processSortedSet = function (setKey, process, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
- callback = typeof callback === 'function' ? callback : function() {};
+ callback = typeof callback === 'function' ? callback : function () {};
options = options || {};
if (typeof process !== 'function') {
@@ -29,7 +29,7 @@ var async = require('async'),
}
// custom done condition
- options.doneIf = typeof options.doneIf === 'function' ? options.doneIf : function(){};
+ options.doneIf = typeof options.doneIf === 'function' ? options.doneIf : function (){};
var batch = options.batch || DEFAULT_BATCH_SIZE;
var start = 0;
@@ -37,11 +37,11 @@ var async = require('async'),
var done = false;
async.whilst(
- function() {
+ function () {
return !done;
},
- function(next) {
- db.getSortedSetRange(setKey, start, stop, function(err, ids) {
+ function (next) {
+ db.getSortedSetRange(setKey, start, stop, function (err, ids) {
if (err) {
return next(err);
}
@@ -49,7 +49,7 @@ var async = require('async'),
done = true;
return next();
}
- process(ids, function(err) {
+ process(ids, function (err) {
if (err) {
return next(err);
}
@@ -63,13 +63,13 @@ var async = require('async'),
);
};
- Batch.processArray = function(array, process, options, callback) {
+ Batch.processArray = function (array, process, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
- callback = typeof callback === 'function' ? callback : function() {};
+ callback = typeof callback === 'function' ? callback : function () {};
options = options || {};
if (!Array.isArray(array) || !array.length) {
@@ -84,16 +84,16 @@ var async = require('async'),
var done = false;
async.whilst(
- function() {
+ function () {
return !done;
},
- function(next) {
+ function (next) {
var currentBatch = array.slice(start, start + batch);
if (!currentBatch.length) {
done = true;
return next();
}
- process(currentBatch, function(err) {
+ process(currentBatch, function (err) {
if (err) {
return next(err);
}
@@ -105,7 +105,7 @@ var async = require('async'),
}
});
},
- function(err) {
+ function (err) {
callback(err);
}
);
diff --git a/src/categories.js b/src/categories.js
index 1885e192fb..4e2c435f8e 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -9,7 +9,7 @@ var Groups = require('./groups');
var plugins = require('./plugins');
var privileges = require('./privileges');
-(function(Categories) {
+(function (Categories) {
require('./categories/data')(Categories);
require('./categories/create')(Categories);
@@ -20,11 +20,11 @@ var privileges = require('./privileges');
require('./categories/recentreplies')(Categories);
require('./categories/update')(Categories);
- Categories.exists = function(cid, callback) {
+ Categories.exists = function (cid, callback) {
db.isSortedSetMember('categories:cid', cid, callback);
};
- Categories.getCategoryById = function(data, callback) {
+ Categories.getCategoryById = function (data, callback) {
var category;
async.waterfall([
function (next) {
@@ -37,17 +37,17 @@ var privileges = require('./privileges');
category = categories[0];
async.parallel({
- topics: function(next) {
+ topics: function (next) {
Categories.getCategoryTopics(data, next);
},
- topicCount: function(next) {
+ topicCount: function (next) {
if (Array.isArray(data.set)) {
db.sortedSetIntersectCard(data.set, next);
} else {
next(null, category.topic_count);
}
},
- isIgnored: function(next) {
+ isIgnored: function (next) {
Categories.isIgnored([data.cid], data.uid, next);
}
}, next);
@@ -66,24 +66,24 @@ var privileges = require('./privileges');
], callback);
};
- Categories.isIgnored = function(cids, uid, callback) {
- user.getIgnoredCategories(uid, function(err, ignoredCids) {
+ Categories.isIgnored = function (cids, uid, callback) {
+ user.getIgnoredCategories(uid, function (err, ignoredCids) {
if (err) {
return callback(err);
}
- cids = cids.map(function(cid) {
+ cids = cids.map(function (cid) {
return ignoredCids.indexOf(cid.toString()) !== -1;
});
callback(null, cids);
});
};
- Categories.getPageCount = function(cid, uid, callback) {
+ Categories.getPageCount = function (cid, uid, callback) {
async.parallel({
topicCount: async.apply(Categories.getCategoryField, cid, 'topic_count'),
settings: async.apply(user.getSettings, uid)
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -96,8 +96,8 @@ var privileges = require('./privileges');
});
};
- Categories.getAllCategories = function(uid, callback) {
- db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
+ Categories.getAllCategories = function (uid, callback) {
+ db.getSortedSetRange('categories:cid', 0, -1, function (err, cids) {
if (err || !Array.isArray(cids) || !cids.length) {
return callback(err, []);
}
@@ -106,22 +106,22 @@ var privileges = require('./privileges');
});
};
- Categories.getCategoriesByPrivilege = function(set, uid, privilege, callback) {
+ Categories.getCategoriesByPrivilege = function (set, uid, privilege, callback) {
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRange(set, 0, -1, next);
},
- function(cids, next) {
+ function (cids, next) {
privileges.categories.filterCids(privilege, cids, uid, next);
},
- function(cids, next) {
+ function (cids, next) {
Categories.getCategories(cids, uid, next);
}
], callback);
};
- Categories.getModerators = function(cid, callback) {
- Groups.getMembers('cid:' + cid + ':privileges:mods', 0, -1, function(err, uids) {
+ Categories.getModerators = function (cid, callback) {
+ Groups.getMembers('cid:' + cid + ':privileges:mods', 0, -1, function (err, uids) {
if (err || !Array.isArray(uids) || !uids.length) {
return callback(err, []);
}
@@ -131,7 +131,7 @@ var privileges = require('./privileges');
};
- Categories.getCategories = function(cids, uid, callback) {
+ Categories.getCategories = function (cids, uid, callback) {
if (!Array.isArray(cids)) {
return callback(new Error('[[error:invalid-cid]]'));
}
@@ -141,19 +141,19 @@ var privileges = require('./privileges');
}
async.parallel({
- categories: function(next) {
+ categories: function (next) {
Categories.getCategoriesData(cids, next);
},
- children: function(next) {
+ children: function (next) {
Categories.getChildren(cids, uid, next);
},
- parents: function(next) {
+ parents: function (next) {
Categories.getParents(cids, next);
},
- hasRead: function(next) {
+ hasRead: function (next) {
Categories.hasReadCategories(cids, uid, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -187,7 +187,7 @@ var privileges = require('./privileges');
return;
}
- category.children.forEach(function(child) {
+ category.children.forEach(function (child) {
calculateTopicPostCount(child);
postCount += parseInt(child.totalPostCount, 10) || 0;
topicCount += parseInt(child.totalTopicCount, 10) || 0;
@@ -197,7 +197,7 @@ var privileges = require('./privileges');
category.totalTopicCount = topicCount;
}
- Categories.getParents = function(cids, callback) {
+ Categories.getParents = function (cids, callback) {
var categoriesData;
var parentCids;
async.waterfall([
@@ -207,20 +207,20 @@ var privileges = require('./privileges');
function (_categoriesData, next) {
categoriesData = _categoriesData;
- parentCids = categoriesData.filter(function(category) {
+ parentCids = categoriesData.filter(function (category) {
return category && category.hasOwnProperty('parentCid') && parseInt(category.parentCid, 10);
- }).map(function(category) {
+ }).map(function (category) {
return parseInt(category.parentCid, 10);
});
if (!parentCids.length) {
- return callback(null, cids.map(function() {return null;}));
+ return callback(null, cids.map(function () {return null;}));
}
Categories.getCategoriesData(parentCids, next);
},
function (parentData, next) {
- parentData = categoriesData.map(function(category) {
+ parentData = categoriesData.map(function (category) {
return parentData[parentCids.indexOf(parseInt(category.parentCid, 10))];
});
next(null, parentData);
@@ -228,15 +228,15 @@ var privileges = require('./privileges');
], callback);
};
- Categories.getChildren = function(cids, uid, callback) {
- var categories = cids.map(function(cid) {
+ Categories.getChildren = function (cids, uid, callback) {
+ var categories = cids.map(function (cid) {
return {cid: cid};
});
- async.each(categories, function(category, next) {
+ async.each(categories, function (category, next) {
getChildrenRecursive(category, uid, next);
}, function (err) {
- callback(err, categories.map(function(c) {
+ callback(err, categories.map(function (c) {
return c && c.children;
}));
});
@@ -251,7 +251,7 @@ var privileges = require('./privileges');
privileges.categories.filterCids('find', children, uid, next);
},
function (children, next) {
- children = children.filter(function(cid) {
+ children = children.filter(function (cid) {
return parseInt(category.cid, 10) !== parseInt(cid, 10);
});
if (!children.length) {
@@ -263,15 +263,15 @@ var privileges = require('./privileges');
function (childrenData, next) {
childrenData = childrenData.filter(Boolean);
category.children = childrenData;
- async.each(category.children, function(child, next) {
+ async.each(category.children, function (child, next) {
getChildrenRecursive(child, uid, next);
}, next);
}
], callback);
}
- Categories.flattenCategories = function(allCategories, categoryData) {
- categoryData.forEach(function(category) {
+ Categories.flattenCategories = function (allCategories, categoryData) {
+ categoryData.forEach(function (category) {
if (!category) {
return;
}
@@ -292,7 +292,7 @@ var privileges = require('./privileges');
* @param categories {array} flat list of categories
* @param parentCid {number} start from 0 to build full tree
*/
- Categories.getTree = function(categories, parentCid) {
+ Categories.getTree = function (categories, parentCid) {
var tree = [], i = 0, len = categories.length, category;
for (i; i < len; ++i) {
@@ -310,7 +310,7 @@ var privileges = require('./privileges');
return tree;
};
- Categories.buildForSelect = function(uid, callback) {
+ Categories.buildForSelect = function (uid, callback) {
function recursive(category, categoriesData, level) {
if (category.link) {
return;
@@ -321,39 +321,39 @@ var privileges = require('./privileges');
category.text = level + bullet + category.name
categoriesData.push(category);
- category.children.forEach(function(child) {
+ category.children.forEach(function (child) {
recursive(child, categoriesData, ' ' + level);
});
}
- Categories.getCategoriesByPrivilege('cid:0:children', uid, 'read', function(err, categories) {
+ Categories.getCategoriesByPrivilege('cid:0:children', uid, 'read', function (err, categories) {
if (err) {
return callback(err);
}
var categoriesData = [];
- categories = categories.filter(function(category) {
+ categories = categories.filter(function (category) {
return category && !category.link && !parseInt(category.parentCid, 10);
});
- categories.forEach(function(category) {
+ categories.forEach(function (category) {
recursive(category, categoriesData, '');
});
callback(null, categoriesData);
});
};
- Categories.getIgnorers = function(cid, start, stop, callback) {
+ Categories.getIgnorers = function (cid, start, stop, callback) {
db.getSortedSetRevRange('cid:' + cid + ':ignorers', start, stop, callback);
};
- Categories.filterIgnoringUids = function(cid, uids, callback) {
+ Categories.filterIgnoringUids = function (cid, uids, callback) {
async.waterfall([
function (next){
db.sortedSetScores('cid:' + cid + ':ignorers', uids, next);
},
function (scores, next) {
- var readingUids = uids.filter(function(uid, index) {
+ var readingUids = uids.filter(function (uid, index) {
return uid && !!scores[index];
});
next(null, readingUids);
diff --git a/src/categories/activeusers.js b/src/categories/activeusers.js
index 4eba4a5525..15673939ae 100644
--- a/src/categories/activeusers.js
+++ b/src/categories/activeusers.js
@@ -4,9 +4,9 @@ var async = require('async');
var posts = require('../posts');
var db = require('../database');
-module.exports = function(Categories) {
+module.exports = function (Categories) {
- Categories.getActiveUsers = function(cid, callback) {
+ Categories.getActiveUsers = function (cid, callback) {
async.waterfall([
function (next) {
db.getSortedSetRevRange('cid:' + cid + ':pids', 0, 24, next);
@@ -15,9 +15,9 @@ module.exports = function(Categories) {
posts.getPostsFields(pids, ['uid'], next);
},
function (posts, next) {
- var uids = posts.map(function(post) {
+ var uids = posts.map(function (post) {
return post.uid;
- }).filter(function(uid, index, array) {
+ }).filter(function (uid, index, array) {
return parseInt(uid, 10) && array.indexOf(uid) === index;
});
diff --git a/src/categories/create.js b/src/categories/create.js
index 5c3a81578d..508d8ab348 100644
--- a/src/categories/create.js
+++ b/src/categories/create.js
@@ -8,17 +8,17 @@ var plugins = require('../plugins');
var privileges = require('../privileges');
var utils = require('../../public/src/utils');
-module.exports = function(Categories) {
+module.exports = function (Categories) {
- Categories.create = function(data, callback) {
+ Categories.create = function (data, callback) {
var category;
var parentCid = data.parentCid ? data.parentCid : 0;
async.waterfall([
- function(next) {
+ function (next) {
db.incrObjectField('global', 'nextCid', next);
},
- function(cid, next) {
+ function (cid, next) {
data.name = data.name || 'Category ' + cid;
var slug = cid + '/' + utils.slugify(data.name);
var order = data.order || cid; // If no order provided, place it at the end
@@ -46,7 +46,7 @@ module.exports = function(Categories) {
plugins.fireHook('filter:category.create', {category: category, data: data}, next);
},
- function(data, next) {
+ function (data, next) {
category = data.category;
var defaultPrivileges = ['find', 'read', 'topics:read', 'topics:create', 'topics:reply', 'posts:edit', 'posts:delete', 'topics:delete', 'upload:post:image'];
@@ -66,20 +66,20 @@ module.exports = function(Categories) {
async.apply(privileges.categories.give, ['find', 'read', 'topics:read'], category.cid, 'guests')
], next);
},
- function(results, next) {
+ function (results, next) {
if (data.cloneFromCid && parseInt(data.cloneFromCid, 10)) {
return Categories.copySettingsFrom(data.cloneFromCid, category.cid, !data.parentCid, next);
}
next(null, category);
},
- function(category, next) {
+ function (category, next) {
plugins.fireHook('action:category.create', category);
next(null, category);
}
], callback);
};
- Categories.assignColours = function() {
+ Categories.assignColours = function () {
var backgrounds = ['#AB4642', '#DC9656', '#F7CA88', '#A1B56C', '#86C1B9', '#7CAFC2', '#BA8BAF', '#A16946'];
var text = ['#fff', '#fff', '#333', '#fff', '#333', '#fff', '#fff', '#fff'];
var index = Math.floor(Math.random() * backgrounds.length);
@@ -87,7 +87,7 @@ module.exports = function(Categories) {
return [backgrounds[index], text[index]];
};
- Categories.copySettingsFrom = function(fromCid, toCid, copyParent, callback) {
+ Categories.copySettingsFrom = function (fromCid, toCid, copyParent, callback) {
var destination;
async.waterfall([
function (next) {
@@ -133,13 +133,13 @@ module.exports = function(Categories) {
function (results, next) {
Categories.copyPrivilegesFrom(fromCid, toCid, next);
}
- ], function(err) {
+ ], function (err) {
callback(err, destination);
});
};
- Categories.copyPrivilegesFrom = function(fromCid, toCid, callback) {
- async.each(privileges.privilegeList, function(privilege, next) {
+ Categories.copyPrivilegesFrom = function (fromCid, toCid, callback) {
+ async.each(privileges.privilegeList, function (privilege, next) {
copyPrivilege(privilege, fromCid, toCid, next);
}, callback);
};
@@ -150,7 +150,7 @@ module.exports = function(Categories) {
db.getSortedSetRange('group:cid:' + toCid + ':privileges:' + privilege + ':members', 0, -1, next);
},
function (currentMembers, next) {
- async.eachSeries(currentMembers, function(member, next) {
+ async.eachSeries(currentMembers, function (member, next) {
groups.leave('cid:' + toCid + ':privileges:' + privilege, member, next);
}, next);
},
@@ -162,7 +162,7 @@ module.exports = function(Categories) {
return callback();
}
- async.eachSeries(members, function(member, next) {
+ async.eachSeries(members, function (member, next) {
groups.join('cid:' + toCid + ':privileges:' + privilege, member, next);
}, next);
}
diff --git a/src/categories/data.js b/src/categories/data.js
index a9f70ab359..ccc31343d9 100644
--- a/src/categories/data.js
+++ b/src/categories/data.js
@@ -6,10 +6,10 @@ var winston = require('winston');
var db = require('../database');
-module.exports = function(Categories) {
+module.exports = function (Categories) {
- Categories.getCategoryData = function(cid, callback) {
- db.getObject('category:' + cid, function(err, category) {
+ Categories.getCategoryData = function (cid, callback) {
+ db.getObject('category:' + cid, function (err, category) {
if (err) {
return callback(err);
}
@@ -19,15 +19,15 @@ module.exports = function(Categories) {
});
};
- Categories.getCategoriesData = function(cids, callback) {
+ Categories.getCategoriesData = function (cids, callback) {
if (!Array.isArray(cids) || !cids.length) {
return callback(null, []);
}
- var keys = cids.map(function(cid) {
+ var keys = cids.map(function (cid) {
return 'category:' + cid;
});
- db.getObjects(keys, function(err, categories) {
+ db.getObjects(keys, function (err, categories) {
if (err || !Array.isArray(categories) || !categories.length) {
return callback(err, []);
}
@@ -63,20 +63,20 @@ module.exports = function(Categories) {
}
}
- Categories.getCategoryField = function(cid, field, callback) {
+ Categories.getCategoryField = function (cid, field, callback) {
db.getObjectField('category:' + cid, field, callback);
};
- Categories.getCategoriesFields = function(cids, fields, callback) {
+ Categories.getCategoriesFields = function (cids, fields, callback) {
if (!Array.isArray(cids) || !cids.length) {
return callback(null, []);
}
- var keys = cids.map(function(cid) {
+ var keys = cids.map(function (cid) {
return 'category:' + cid;
});
- db.getObjectsFields(keys, fields, function(err, categories) {
+ db.getObjectsFields(keys, fields, function (err, categories) {
if (err) {
return callback(err);
}
@@ -86,29 +86,29 @@ module.exports = function(Categories) {
});
};
- Categories.getMultipleCategoryFields = function(cids, fields, callback) {
+ Categories.getMultipleCategoryFields = function (cids, fields, callback) {
winston.warn('[deprecated] Categories.getMultipleCategoryFields is deprecated please use Categories.getCategoriesFields');
Categories.getCategoriesFields(cids, fields, callback);
};
- Categories.getAllCategoryFields = function(fields, callback) {
+ Categories.getAllCategoryFields = function (fields, callback) {
async.waterfall([
async.apply(db.getSortedSetRange, 'categories:cid', 0, -1),
- function(cids, next) {
+ function (cids, next) {
Categories.getCategoriesFields(cids, fields, next);
}
], callback);
};
- Categories.getCategoryFields = function(cid, fields, callback) {
+ Categories.getCategoryFields = function (cid, fields, callback) {
db.getObjectFields('category:' + cid, fields, callback);
};
- Categories.setCategoryField = function(cid, field, value, callback) {
+ Categories.setCategoryField = function (cid, field, value, callback) {
db.setObjectField('category:' + cid, field, value, callback);
};
- Categories.incrementCategoryFieldBy = function(cid, field, value, callback) {
+ Categories.incrementCategoryFieldBy = function (cid, field, value, callback) {
db.incrObjectFieldBy('category:' + cid, field, value, callback);
};
diff --git a/src/categories/delete.js b/src/categories/delete.js
index 897e45916e..5c8e5bdf9a 100644
--- a/src/categories/delete.js
+++ b/src/categories/delete.js
@@ -8,14 +8,14 @@ var topics = require('../topics');
var groups = require('../groups');
var privileges = require('../privileges');
-module.exports = function(Categories) {
+module.exports = function (Categories) {
- Categories.purge = function(cid, uid, callback) {
- batch.processSortedSet('cid:' + cid + ':tids', function(tids, next) {
- async.eachLimit(tids, 10, function(tid, next) {
+ Categories.purge = function (cid, uid, callback) {
+ batch.processSortedSet('cid:' + cid + ':tids', function (tids, next) {
+ async.eachLimit(tids, 10, function (tid, next) {
topics.purgePostsAndTopic(tid, uid, next);
}, next);
- }, {alwaysStartAt: 0}, function(err) {
+ }, {alwaysStartAt: 0}, function (err) {
if (err) {
return callback(err);
}
@@ -28,13 +28,13 @@ module.exports = function(Categories) {
function purgeCategory(cid, callback) {
async.series([
- function(next) {
+ function (next) {
db.sortedSetRemove('categories:cid', cid, next);
},
- function(next) {
+ function (next) {
removeFromParent(cid, next);
},
- function(next) {
+ function (next) {
db.deleteAll([
'cid:' + cid + ':tids',
'cid:' + cid + ':tids:posts',
@@ -45,8 +45,8 @@ module.exports = function(Categories) {
'category:' + cid
], next);
},
- function(next) {
- async.each(privileges.privilegeList, function(privilege, next) {
+ function (next) {
+ async.each(privileges.privilegeList, function (privilege, next) {
groups.destroy('cid:' + cid + ':privileges:' + privilege, next);
}, next);
}
@@ -55,29 +55,29 @@ module.exports = function(Categories) {
function removeFromParent(cid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
async.parallel({
- parentCid: function(next) {
+ parentCid: function (next) {
Categories.getCategoryField(cid, 'parentCid', next);
},
- children: function(next) {
+ children: function (next) {
db.getSortedSetRange('cid:' + cid + ':children', 0, -1, next);
}
}, next);
},
- function(results, next) {
+ function (results, next) {
async.parallel([
- function(next) {
+ function (next) {
results.parentCid = parseInt(results.parentCid, 10) || 0;
db.sortedSetRemove('cid:' + results.parentCid + ':children', cid, next);
},
- function(next) {
- async.each(results.children, function(cid, next) {
+ function (next) {
+ async.each(results.children, function (cid, next) {
async.parallel([
- function(next) {
+ function (next) {
db.setObjectField('category:' + cid, 'parentCid', 0, next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('cid:0:children', cid, cid, next);
}
], next);
@@ -85,7 +85,7 @@ module.exports = function(Categories) {
}
], next);
}
- ], function(err) {
+ ], function (err) {
callback(err);
});
}
diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js
index c71c1b907c..831991d61a 100644
--- a/src/categories/recentreplies.js
+++ b/src/categories/recentreplies.js
@@ -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);
}
diff --git a/src/categories/topics.js b/src/categories/topics.js
index 48892dd865..b9ab96bee2 100644
--- a/src/categories/topics.js
+++ b/src/categories/topics.js
@@ -6,9 +6,9 @@ var db = require('../database');
var topics = require('../topics');
var plugins = require('../plugins');
-module.exports = function(Categories) {
+module.exports = function (Categories) {
- Categories.getCategoryTopics = function(data, callback) {
+ Categories.getCategoryTopics = function (data, callback) {
async.waterfall([
function (next) {
plugins.fireHook('filter:category.topics.prepare', data, next);
@@ -36,12 +36,12 @@ module.exports = function(Categories) {
], callback);
};
- Categories.modifyTopicsByPrivilege = function(topics, privileges) {
+ Categories.modifyTopicsByPrivilege = function (topics, privileges) {
if (!Array.isArray(topics) || !topics.length || privileges.isAdminOrMod) {
return;
}
- topics.forEach(function(topic) {
+ topics.forEach(function (topic) {
if (topic.deleted && !topic.isOwner) {
topic.title = '[[topic:topic_is_deleted]]';
topic.slug = topic.tid;
@@ -52,7 +52,7 @@ module.exports = function(Categories) {
});
};
- Categories.getTopicIds = function(set, reverse, start, stop, callback) {
+ Categories.getTopicIds = function (set, reverse, start, stop, callback) {
if (Array.isArray(set)) {
db[reverse ? 'getSortedSetRevIntersect' : 'getSortedSetIntersect']({sets: set, start: start, stop: stop}, callback);
} else {
@@ -60,8 +60,8 @@ module.exports = function(Categories) {
}
};
- Categories.getTopicIndex = function(tid, callback) {
- topics.getTopicField(tid, 'cid', function(err, cid) {
+ Categories.getTopicIndex = function (tid, callback) {
+ topics.getTopicField(tid, 'cid', function (err, cid) {
if (err) {
return callback(err);
}
@@ -70,29 +70,29 @@ module.exports = function(Categories) {
});
};
- Categories.onNewPostMade = function(cid, pinned, postData, callback) {
+ Categories.onNewPostMade = function (cid, pinned, postData, callback) {
if (!cid || !postData) {
return callback();
}
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, postData.pid, next);
},
- function(next) {
+ function (next) {
db.incrObjectField('category:' + cid, 'post_count', next);
},
- function(next) {
+ function (next) {
if (parseInt(pinned, 10) === 1) {
next();
} else {
db.sortedSetAdd('cid:' + cid + ':tids', postData.timestamp, postData.tid, next);
}
},
- function(next){
+ function (next){
Categories.updateRecentTid(cid, postData.tid, next);
},
- function(next) {
+ function (next) {
db.sortedSetIncrBy('cid:' + cid + ':tids:posts', 1, postData.tid, next);
}
], callback);
diff --git a/src/categories/unread.js b/src/categories/unread.js
index 37496e09b7..3805e1e78f 100644
--- a/src/categories/unread.js
+++ b/src/categories/unread.js
@@ -4,23 +4,23 @@
var async = require('async');
var db = require('../database');
-module.exports = function(Categories) {
+module.exports = function (Categories) {
- Categories.markAsRead = function(cids, uid, callback) {
- callback = callback || function() {};
+ Categories.markAsRead = function (cids, uid, callback) {
+ callback = callback || function () {};
if (!Array.isArray(cids) || !cids.length) {
return callback();
}
- var keys = cids.map(function(cid) {
+ var keys = cids.map(function (cid) {
return 'cid:' + cid + ':read_by_uid';
});
- db.isMemberOfSets(keys, uid, function(err, hasRead) {
+ db.isMemberOfSets(keys, uid, function (err, hasRead) {
if (err) {
return callback(err);
}
- keys = keys.filter(function(key, index) {
+ keys = keys.filter(function (key, index) {
return !hasRead[index];
});
@@ -32,12 +32,12 @@ module.exports = function(Categories) {
});
};
- Categories.markAsUnreadForAll = function(cid, callback) {
- callback = callback || function() {};
+ Categories.markAsUnreadForAll = function (cid, callback) {
+ callback = callback || function () {};
db.delete('cid:' + cid + ':read_by_uid', callback);
};
- Categories.hasReadCategories = function(cids, uid, callback) {
+ Categories.hasReadCategories = function (cids, uid, callback) {
var sets = [];
for (var i = 0, ii = cids.length; i < ii; i++) {
@@ -47,7 +47,7 @@ module.exports = function(Categories) {
db.isMemberOfSets(sets, uid, callback);
};
- Categories.hasReadCategory = function(cid, uid, callback) {
+ Categories.hasReadCategory = function (cid, uid, callback) {
db.isSetMember('cid:' + cid + ':read_by_uid', uid, callback);
};
diff --git a/src/categories/update.js b/src/categories/update.js
index 7c45663073..4f4229b5fc 100644
--- a/src/categories/update.js
+++ b/src/categories/update.js
@@ -7,33 +7,33 @@ var utils = require('../../public/src/utils');
var translator = require('../../public/src/modules/translator');
var plugins = require('../plugins');
-module.exports = function(Categories) {
+module.exports = function (Categories) {
- Categories.update = function(modified, callback) {
+ Categories.update = function (modified, callback) {
var cids = Object.keys(modified);
- async.each(cids, function(cid, next) {
+ async.each(cids, function (cid, next) {
updateCategory(cid, modified[cid], next);
- }, function(err) {
+ }, function (err) {
callback(err, cids);
});
};
function updateCategory(cid, modifiedFields, callback) {
- Categories.exists(cid, function(err, exists) {
+ Categories.exists(cid, function (err, exists) {
if (err || !exists) {
return callback(err);
}
if (modifiedFields.hasOwnProperty('name')) {
- translator.translate(modifiedFields.name, function(translated) {
+ translator.translate(modifiedFields.name, function (translated) {
modifiedFields.slug = cid + '/' + utils.slugify(translated);
});
}
- plugins.fireHook('filter:category.update', {category: modifiedFields}, function(err, categoryData) {
+ plugins.fireHook('filter:category.update', {category: modifiedFields}, function (err, categoryData) {
if (err) {
return callback(err);
}
@@ -46,9 +46,9 @@ module.exports = function(Categories) {
fields.splice(0, 0, fields.splice(parentCidIndex, 1)[0]);
}
- async.eachSeries(fields, function(key, next) {
+ async.eachSeries(fields, function (key, next) {
updateCategoryField(cid, key, category[key], next);
- }, function(err) {
+ }, function (err) {
if (err) {
return callback(err);
}
@@ -64,7 +64,7 @@ module.exports = function(Categories) {
return updateParent(cid, value, callback);
}
- db.setObjectField('category:' + cid, key, value, function(err) {
+ db.setObjectField('category:' + cid, key, value, function (err) {
if (err) {
return callback(err);
}
@@ -83,7 +83,7 @@ module.exports = function(Categories) {
if (parseInt(cid, 10) === parseInt(newParent, 10)) {
return callback(new Error('[[error:cant-set-self-as-parent]]'));
}
- Categories.getCategoryField(cid, 'parentCid', function(err, oldParent) {
+ Categories.getCategoryField(cid, 'parentCid', function (err, oldParent) {
if (err) {
return callback(err);
}
@@ -100,14 +100,14 @@ module.exports = function(Categories) {
function (next) {
db.setObjectField('category:' + cid, 'parentCid', newParent, next);
}
- ], function(err) {
+ ], function (err) {
callback(err);
});
});
}
function updateOrder(cid, order, callback) {
- Categories.getCategoryField(cid, 'parentCid', function(err, parentCid) {
+ Categories.getCategoryField(cid, 'parentCid', function (err, parentCid) {
if (err) {
return callback(err);
}
@@ -124,8 +124,8 @@ module.exports = function(Categories) {
});
}
- Categories.parseDescription = function(cid, description, callback) {
- plugins.fireHook('filter:parse.raw', description, function(err, parsedDescription) {
+ Categories.parseDescription = function (cid, description, callback) {
+ plugins.fireHook('filter:parse.raw', description, function (err, parsedDescription) {
if (err) {
return callback(err);
}
diff --git a/src/controllers/accounts/chats.js b/src/controllers/accounts/chats.js
index ddde8efb5e..2175708581 100644
--- a/src/controllers/accounts/chats.js
+++ b/src/controllers/accounts/chats.js
@@ -9,7 +9,7 @@ var helpers = require('../helpers');
var chatsController = {};
-chatsController.get = function(req, res, callback) {
+chatsController.get = function (req, res, callback) {
if (parseInt(meta.config.disableChat, 10) === 1) {
return callback();
}
@@ -18,13 +18,13 @@ chatsController.get = function(req, res, callback) {
var recentChats;
async.waterfall([
- function(next) {
+ function (next) {
async.parallel({
uid: async.apply(user.getUidByUserslug, req.params.userslug),
username: async.apply(user.getUsernameByUserslug, req.params.userslug)
}, next);
},
- function(results, next) {
+ function (results, next) {
uid = results.uid;
username = results.username;
if (!uid) {
@@ -32,7 +32,7 @@ chatsController.get = function(req, res, callback) {
}
messaging.getRecentChats(req.uid, uid, 0, 19, next);
},
- function(_recentChats, next) {
+ function (_recentChats, next) {
recentChats = _recentChats;
if (!recentChats) {
return callback();
@@ -50,7 +50,7 @@ chatsController.get = function(req, res, callback) {
}
messaging.isUserInRoom(req.uid, req.params.roomid, next);
},
- function(inRoom, next) {
+ function (inRoom, next) {
if (!inRoom) {
return callback();
}
@@ -65,7 +65,7 @@ chatsController.get = function(req, res, callback) {
room: async.apply(messaging.getRoomData, req.params.roomid)
}, next);
}
- ], function(err, data) {
+ ], function (err, data) {
if (err) {
return callback(err);
}
@@ -73,7 +73,7 @@ chatsController.get = function(req, res, callback) {
room.messages = data.messages;
room.isOwner = parseInt(room.owner, 10) === parseInt(req.uid, 10);
- room.users = data.users.filter(function(user) {
+ room.users = data.users.filter(function (user) {
return user && parseInt(user.uid, 10) && parseInt(user.uid, 10) !== req.uid;
});
@@ -96,12 +96,12 @@ chatsController.get = function(req, res, callback) {
});
};
-chatsController.redirectToChat = function(req, res, next) {
+chatsController.redirectToChat = function (req, res, next) {
var roomid = parseInt(req.params.roomid, 10);
if (!req.uid) {
return next();
}
- user.getUserField(req.uid, 'userslug', function(err, userslug) {
+ user.getUserField(req.uid, 'userslug', function (err, userslug) {
if (err || !userslug) {
return next(err);
}
diff --git a/src/controllers/accounts/edit.js b/src/controllers/accounts/edit.js
index 9f63df0894..3fe2c57092 100644
--- a/src/controllers/accounts/edit.js
+++ b/src/controllers/accounts/edit.js
@@ -15,8 +15,8 @@ var accountHelpers = require('./helpers');
var editController = {};
-editController.get = function(req, res, callback) {
- accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, function(err, userData) {
+editController.get = function (req, res, callback) {
+ accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, function (err, userData) {
if (err || !userData) {
return callback(err);
}
@@ -27,10 +27,10 @@ editController.get = function(req, res, callback) {
userData.allowProfileImageUploads = parseInt(meta.config.allowProfileImageUploads) === 1;
userData.allowAccountDelete = parseInt(meta.config.allowAccountDelete, 10) === 1;
- userData.groups = userData.groups.filter(function(group) {
+ userData.groups = userData.groups.filter(function (group) {
return group && group.userTitleEnabled && !groups.isPrivilegeGroup(group.name) && group.name !== 'registered-users';
});
- userData.groups.forEach(function(group) {
+ userData.groups.forEach(function (group) {
group.selected = group.name === userData.groupTitle;
});
@@ -38,7 +38,7 @@ editController.get = function(req, res, callback) {
userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: '[[user:edit]]'}]);
userData.editButtons = [];
- plugins.fireHook('filter:user.account.edit', userData, function(err, userData) {
+ plugins.fireHook('filter:user.account.edit', userData, function (err, userData) {
if (err) {
return callback(err);
}
@@ -48,20 +48,20 @@ editController.get = function(req, res, callback) {
});
};
-editController.password = function(req, res, next) {
+editController.password = function (req, res, next) {
renderRoute('password', req, res, next);
};
-editController.username = function(req, res, next) {
+editController.username = function (req, res, next) {
renderRoute('username', req, res, next);
};
-editController.email = function(req, res, next) {
+editController.email = function (req, res, next) {
renderRoute('email', req, res, next);
};
function renderRoute(name, req, res, next) {
- getUserData(req, next, function(err, userData) {
+ getUserData(req, next, function (err, userData) {
if (err) {
return next(err);
}
@@ -87,17 +87,17 @@ function renderRoute(name, req, res, next) {
function getUserData(req, next, callback) {
var userData;
async.waterfall([
- function(next) {
+ function (next) {
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
},
- function(data, next) {
+ function (data, next) {
userData = data;
if (!userData) {
return next();
}
db.getObjectField('user:' + userData.uid, 'password', next);
}
- ], function(err, password) {
+ ], function (err, password) {
if (err) {
return callback(err);
}
@@ -113,10 +113,10 @@ editController.uploadPicture = function (req, res, next) {
var updateUid;
async.waterfall([
- function(next) {
+ function (next) {
user.getUidByUserslug(req.params.userslug, next);
},
- function(uid, next) {
+ function (uid, next) {
updateUid = uid;
if (parseInt(req.uid, 10) === parseInt(uid, 10)) {
return next(null, true);
@@ -124,15 +124,15 @@ editController.uploadPicture = function (req, res, next) {
user.isAdminOrGlobalMod(req.uid, next);
},
- function(isAllowed, next) {
+ function (isAllowed, next) {
if (!isAllowed) {
return helpers.notAllowed(req, res);
}
user.uploadPicture(updateUid, userPhoto, next);
}
- ], function(err, image) {
- fs.unlink(userPhoto.path, function(err) {
+ ], function (err, image) {
+ fs.unlink(userPhoto.path, function (err) {
if (err) {
winston.warn('[user/picture] Unable to delete picture ' + userPhoto.path, err);
}
@@ -145,13 +145,13 @@ editController.uploadPicture = function (req, res, next) {
});
};
-editController.uploadCoverPicture = function(req, res, next) {
+editController.uploadCoverPicture = function (req, res, next) {
var params = JSON.parse(req.body.params);
user.updateCoverPicture({
file: req.files.files[0],
uid: params.uid
- }, function(err, image) {
+ }, function (err, image) {
if (err) {
return next(err);
}
diff --git a/src/controllers/accounts/follow.js b/src/controllers/accounts/follow.js
index f54d825081..7d1e91b5e2 100644
--- a/src/controllers/accounts/follow.js
+++ b/src/controllers/accounts/follow.js
@@ -9,11 +9,11 @@ var pagination = require('../../pagination');
var followController = {};
-followController.getFollowing = function(req, res, next) {
+followController.getFollowing = function (req, res, next) {
getFollow('account/following', 'following', req, res, next);
};
-followController.getFollowers = function(req, res, next) {
+followController.getFollowers = function (req, res, next) {
getFollow('account/followers', 'followers', req, res, next);
};
@@ -26,10 +26,10 @@ function getFollow(tpl, name, req, res, callback) {
var stop = start + resultsPerPage - 1;
async.waterfall([
- function(next) {
+ function (next) {
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
},
- function(data, next) {
+ function (data, next) {
userData = data;
if (!userData) {
return callback();
@@ -37,7 +37,7 @@ function getFollow(tpl, name, req, res, callback) {
var method = name === 'following' ? 'getFollowing' : 'getFollowers';
user[method](userData.uid, start, stop, next);
}
- ], function(err, users) {
+ ], function (err, users) {
if (err) {
return callback(err);
}
diff --git a/src/controllers/accounts/groups.js b/src/controllers/accounts/groups.js
index 7957b3c251..038d63de1d 100644
--- a/src/controllers/accounts/groups.js
+++ b/src/controllers/accounts/groups.js
@@ -10,7 +10,7 @@ var accountHelpers = require('./helpers');
var groupsController = {};
-groupsController.get = function(req, res, callback) {
+groupsController.get = function (req, res, callback) {
var userData;
var groupsData;
async.waterfall([
@@ -27,19 +27,19 @@ groupsController.get = function(req, res, callback) {
},
function (_groupsData, next) {
groupsData = _groupsData[0];
- var groupNames = groupsData.filter(Boolean).map(function(group) {
+ var groupNames = groupsData.filter(Boolean).map(function (group) {
return group.name;
});
groups.getMemberUsers(groupNames, 0, 3, next);
},
function (members, next) {
- groupsData.forEach(function(group, index) {
+ groupsData.forEach(function (group, index) {
group.members = members[index];
});
next();
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
diff --git a/src/controllers/accounts/helpers.js b/src/controllers/accounts/helpers.js
index 70b58c9d65..1046529442 100644
--- a/src/controllers/accounts/helpers.js
+++ b/src/controllers/accounts/helpers.js
@@ -13,7 +13,7 @@ var utils = require('../../../public/src/utils');
var helpers = {};
-helpers.getUserDataByUserSlug = function(userslug, callerUID, callback) {
+helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
async.waterfall([
function (next) {
user.getUidByUserslug(userslug, next);
@@ -24,34 +24,34 @@ helpers.getUserDataByUserSlug = function(userslug, callerUID, callback) {
}
async.parallel({
- userData : function(next) {
+ userData : function (next) {
user.getUserData(uid, next);
},
- userSettings : function(next) {
+ userSettings : function (next) {
user.getSettings(uid, next);
},
- isAdmin : function(next) {
+ isAdmin : function (next) {
user.isAdministrator(callerUID, next);
},
- isGlobalModerator: function(next) {
+ isGlobalModerator: function (next) {
user.isGlobalModerator(callerUID, next);
},
- isFollowing: function(next) {
+ isFollowing: function (next) {
user.isFollowing(callerUID, uid, next);
},
- ips: function(next) {
+ ips: function (next) {
user.getIPs(uid, 4, next);
},
- profile_links: function(next) {
+ profile_links: function (next) {
plugins.fireHook('filter:user.profileLinks', [], next);
},
- profile_menu: function(next) {
+ profile_menu: function (next) {
plugins.fireHook('filter:user.profileMenu', {uid: uid, callerUID: callerUID, links: []}, next);
},
- groups: function(next) {
+ groups: function (next) {
groups.getUserGroups([uid], next);
},
- sso: function(next) {
+ sso: function (next) {
plugins.fireHook('filter:auth.list', {uid: uid, associations: []}, next);
}
}, next);
@@ -137,13 +137,13 @@ helpers.getUserDataByUserSlug = function(userslug, callerUID, callback) {
};
-helpers.getBaseUser = function(userslug, callerUID, callback) {
+helpers.getBaseUser = function (userslug, callerUID, callback) {
winston.warn('helpers.getBaseUser deprecated please use helpers.getUserDataByUserSlug');
helpers.getUserDataByUserSlug(userslug, callerUID, callback);
};
function filterLinks(links, self) {
- return links.filter(function(link) {
+ return links.filter(function (link) {
return link && (link.public || self);
});
}
diff --git a/src/controllers/accounts/info.js b/src/controllers/accounts/info.js
index 63dea030ec..77ab2f275e 100644
--- a/src/controllers/accounts/info.js
+++ b/src/controllers/accounts/info.js
@@ -8,13 +8,13 @@ var accountHelpers = require('./helpers');
var infoController = {};
-infoController.get = function(req, res, callback) {
+infoController.get = function (req, res, callback) {
var userData;
async.waterfall([
- function(next) {
+ function (next) {
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
},
- function(_userData, next) {
+ function (_userData, next) {
userData = _userData;
if (!userData) {
return callback();
@@ -26,7 +26,7 @@ infoController.get = function(req, res, callback) {
emails: async.apply(user.getHistory, 'user:' + userData.uid + ':emails')
}, next);
}
- ], function(err, data) {
+ ], function (err, data) {
if (err) {
return callback(err);
}
diff --git a/src/controllers/accounts/notifications.js b/src/controllers/accounts/notifications.js
index aa60892f47..91b9eb1d07 100644
--- a/src/controllers/accounts/notifications.js
+++ b/src/controllers/accounts/notifications.js
@@ -6,8 +6,8 @@ var user = require('../../user'),
var notificationsController = {};
-notificationsController.get = function(req, res, next) {
- user.notifications.getAll(req.uid, 0, 39, function(err, notifications) {
+notificationsController.get = function (req, res, next) {
+ user.notifications.getAll(req.uid, 0, 39, function (err, notifications) {
if (err) {
return next(err);
}
diff --git a/src/controllers/accounts/posts.js b/src/controllers/accounts/posts.js
index 53450c9673..53ff073dad 100644
--- a/src/controllers/accounts/posts.js
+++ b/src/controllers/accounts/posts.js
@@ -13,7 +13,7 @@ var accountHelpers = require('./helpers');
var postsController = {};
-postsController.getBookmarks = function(req, res, next) {
+postsController.getBookmarks = function (req, res, next) {
var data = {
template: 'account/bookmarks',
set: 'bookmarks',
@@ -25,7 +25,7 @@ postsController.getBookmarks = function(req, res, next) {
getFromUserSet(data, req, res, next);
};
-postsController.getPosts = function(req, res, next) {
+postsController.getPosts = function (req, res, next) {
var data = {
template: 'account/posts',
set: 'posts',
@@ -37,7 +37,7 @@ postsController.getPosts = function(req, res, next) {
getFromUserSet(data, req, res, next);
};
-postsController.getUpVotedPosts = function(req, res, next) {
+postsController.getUpVotedPosts = function (req, res, next) {
var data = {
template: 'account/upvoted',
set: 'upvote',
@@ -49,7 +49,7 @@ postsController.getUpVotedPosts = function(req, res, next) {
getFromUserSet(data, req, res, next);
};
-postsController.getDownVotedPosts = function(req, res, next) {
+postsController.getDownVotedPosts = function (req, res, next) {
var data = {
template: 'account/downvoted',
set: 'downvote',
@@ -61,7 +61,7 @@ postsController.getDownVotedPosts = function(req, res, next) {
getFromUserSet(data, req, res, next);
};
-postsController.getBestPosts = function(req, res, next) {
+postsController.getBestPosts = function (req, res, next) {
var data = {
template: 'account/best',
set: 'posts:votes',
@@ -73,7 +73,7 @@ postsController.getBestPosts = function(req, res, next) {
getFromUserSet(data, req, res, next);
};
-postsController.getWatchedTopics = function(req, res, next) {
+postsController.getWatchedTopics = function (req, res, next) {
var data = {
template: 'account/watched',
set: 'followed_tids',
@@ -85,7 +85,7 @@ postsController.getWatchedTopics = function(req, res, next) {
getFromUserSet(data, req, res, next);
};
-postsController.getTopics = function(req, res, next) {
+postsController.getTopics = function (req, res, next) {
var data = {
template: 'account/topics',
set: 'topics',
@@ -99,13 +99,13 @@ postsController.getTopics = function(req, res, next) {
function getFromUserSet(data, req, res, next) {
async.parallel({
- settings: function(next) {
+ settings: function (next) {
user.getSettings(req.uid, next);
},
- userData: function(next) {
+ userData: function (next) {
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err || !results.userData) {
return next(err);
}
@@ -118,19 +118,19 @@ function getFromUserSet(data, req, res, next) {
var itemsPerPage = (data.template === 'account/topics' || data.template === 'account/watched') ? results.settings.topicsPerPage : results.settings.postsPerPage;
async.parallel({
- itemCount: function(next) {
+ itemCount: function (next) {
if (results.settings.usePagination) {
db.sortedSetCard(setName, next);
} else {
next(null, 0);
}
},
- data: function(next) {
+ data: function (next) {
var start = (page - 1) * itemsPerPage;
var stop = start + itemsPerPage - 1;
data.method(setName, req.uid, start, stop, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return next(err);
}
diff --git a/src/controllers/accounts/profile.js b/src/controllers/accounts/profile.js
index ee66a1a4d7..f0fa1e1378 100644
--- a/src/controllers/accounts/profile.js
+++ b/src/controllers/accounts/profile.js
@@ -14,7 +14,7 @@ var helpers = require('../helpers');
var profileController = {};
-profileController.get = function(req, res, callback) {
+profileController.get = function (req, res, callback) {
var lowercaseSlug = req.params.userslug.toLowerCase();
if (req.params.userslug !== lowercaseSlug) {
@@ -43,16 +43,16 @@ profileController.get = function(req, res, callback) {
}
async.parallel({
- isFollowing: function(next) {
+ isFollowing: function (next) {
user.isFollowing(req.uid, userData.theirid, next);
},
- posts: function(next) {
+ posts: function (next) {
posts.getPostSummariesFromSet('uid:' + userData.theirid + ':posts', req.uid, 0, 9, next);
},
- signature: function(next) {
+ signature: function (next) {
posts.parseSignature(userData, req.uid, next);
},
- aboutme: function(next) {
+ aboutme: function (next) {
if (userData.aboutme) {
plugins.fireHook('filter:parse.aboutme', userData.aboutme, next);
} else {
@@ -118,13 +118,13 @@ profileController.get = function(req, res, callback) {
}
);
}
- userData.selectedGroup = userData.groups.find(function(group) {
+ userData.selectedGroup = userData.groups.find(function (group) {
return group && group.name === userData.groupTitle;
});
plugins.fireHook('filter:user.account', {userData: userData, uid: req.uid}, next);
}
- ], function(err, results) {
+ ], function (err, results) {
if (err) {
return callback(err);
}
diff --git a/src/controllers/accounts/session.js b/src/controllers/accounts/session.js
index 20c32909df..7e31906f26 100644
--- a/src/controllers/accounts/session.js
+++ b/src/controllers/accounts/session.js
@@ -7,7 +7,7 @@ var user = require('../../user');
var sessionController = {};
-sessionController.revoke = function(req, res, next) {
+sessionController.revoke = function (req, res, next) {
if (!req.params.hasOwnProperty('uuid')) {
return next();
}
@@ -26,8 +26,8 @@ sessionController.revoke = function(req, res, next) {
db.getSortedSetRange('uid:' + uid + ':sessions', 0, -1, next);
},
function (sids, done) {
- async.eachSeries(sids, function(sid, next) {
- db.sessionStore.get(sid, function(err, sessionObj) {
+ async.eachSeries(sids, function (sid, next) {
+ db.sessionStore.get(sid, function (err, sessionObj) {
if (err) {
return next(err);
}
@@ -47,7 +47,7 @@ sessionController.revoke = function(req, res, next) {
user.auth.revokeSession(_id, uid, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return res.status(500).send(err.message);
} else {
diff --git a/src/controllers/accounts/settings.js b/src/controllers/accounts/settings.js
index 9b16050934..44499e7e68 100644
--- a/src/controllers/accounts/settings.js
+++ b/src/controllers/accounts/settings.js
@@ -16,36 +16,36 @@ var accountHelpers = require('./helpers');
var settingsController = {};
-settingsController.get = function(req, res, callback) {
+settingsController.get = function (req, res, callback) {
var userData;
async.waterfall([
- function(next) {
+ function (next) {
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
},
- function(_userData, next) {
+ function (_userData, next) {
userData = _userData;
if (!userData) {
return callback();
}
async.parallel({
- settings: function(next) {
+ settings: function (next) {
user.getSettings(userData.uid, next);
},
- languages: function(next) {
+ languages: function (next) {
languages.list(next);
},
- homePageRoutes: function(next) {
+ homePageRoutes: function (next) {
getHomePageRoutes(next);
},
- sounds: function(next) {
+ sounds: function (next) {
meta.sounds.getFiles(next);
},
- soundsMapping: function(next) {
+ soundsMapping: function (next) {
meta.sounds.getMapping(userData.uid, next);
}
}, next);
},
- function(results, next) {
+ function (results, next) {
userData.settings = results.settings;
userData.languages = results.languages;
userData.homePageRoutes = results.homePageRoutes;
@@ -56,20 +56,20 @@ settingsController.get = function(req, res, callback) {
'outgoingChatSound': 'chat-outgoing'
};
- Object.keys(soundSettings).forEach(function(setting) {
- userData[setting] = Object.keys(results.sounds).map(function(name) {
+ Object.keys(soundSettings).forEach(function (setting) {
+ userData[setting] = Object.keys(results.sounds).map(function (name) {
return {name: name, selected: name === results.soundsMapping[soundSettings[setting]]};
});
});
plugins.fireHook('filter:user.customSettings', {settings: results.settings, customSettings: [], uid: req.uid}, next);
},
- function(data, next) {
+ function (data, next) {
userData.customSettings = data.customSettings;
userData.disableEmailSubscriptions = parseInt(meta.config.disableEmailSubscriptions, 10) === 1;
next();
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
@@ -103,7 +103,7 @@ settingsController.get = function(req, res, callback) {
];
var isCustom = true;
- userData.homePageRoutes.forEach(function(route) {
+ userData.homePageRoutes.forEach(function (route) {
route.selected = route.route === userData.settings.homePageRoute;
if (route.selected) {
isCustom = false;
@@ -120,11 +120,11 @@ settingsController.get = function(req, res, callback) {
selected: isCustom
});
- userData.bootswatchSkinOptions.forEach(function(skin) {
+ userData.bootswatchSkinOptions.forEach(function (skin) {
skin.selected = skin.value === userData.settings.bootswatchSkin;
});
- userData.languages.forEach(function(language) {
+ userData.languages.forEach(function (language) {
language.selected = language.code === userData.settings.userLang;
});
@@ -154,7 +154,7 @@ function getHomePageRoutes(callback) {
categories.getCategoriesFields(cids, ['name', 'slug'], next);
},
function (categoryData, next) {
- categoryData = categoryData.map(function(category) {
+ categoryData = categoryData.map(function (category) {
return {
route: 'category/' + category.slug,
name: 'Category: ' + category.name
diff --git a/src/controllers/admin/appearance.js b/src/controllers/admin/appearance.js
index 8d60efda23..8956bd175d 100644
--- a/src/controllers/admin/appearance.js
+++ b/src/controllers/admin/appearance.js
@@ -2,7 +2,7 @@
var appearanceController = {};
-appearanceController.get = function(req, res, next) {
+appearanceController.get = function (req, res, next) {
var term = req.params.term ? req.params.term : 'themes';
res.render('admin/appearance/' + term, {});
diff --git a/src/controllers/admin/blacklist.js b/src/controllers/admin/blacklist.js
index 2c0104f742..d70b1d1d79 100644
--- a/src/controllers/admin/blacklist.js
+++ b/src/controllers/admin/blacklist.js
@@ -4,8 +4,8 @@ var meta = require('../../meta');
var blacklistController = {};
-blacklistController.get = function(req, res, next) {
- meta.blacklist.get(function(err, rules) {
+blacklistController.get = function (req, res, next) {
+ meta.blacklist.get(function (err, rules) {
if (err) {
return next(err);
}
diff --git a/src/controllers/admin/cache.js b/src/controllers/admin/cache.js
index 116c928020..21ef6ff086 100644
--- a/src/controllers/admin/cache.js
+++ b/src/controllers/admin/cache.js
@@ -2,7 +2,7 @@
var cacheController = {};
-cacheController.get = function(req, res, next) {
+cacheController.get = function (req, res, next) {
var postCache = require('../../posts/cache');
var groupCache = require('../../groups').cache;
diff --git a/src/controllers/admin/categories.js b/src/controllers/admin/categories.js
index c33dde5c7c..8a59bb0b4e 100644
--- a/src/controllers/admin/categories.js
+++ b/src/controllers/admin/categories.js
@@ -11,11 +11,11 @@ var translator = require('../../../public/src/modules/translator');
var categoriesController = {};
-categoriesController.get = function(req, res, next) {
+categoriesController.get = function (req, res, next) {
async.parallel({
category: async.apply(categories.getCategories, [req.params.category_id], req.user.uid),
privileges: async.apply(privileges.categories.list, req.params.category_id)
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return next(err);
}
@@ -25,7 +25,7 @@ categoriesController.get = function(req, res, next) {
return next();
}
- plugins.fireHook('filter:admin.category.get', { req: req, res: res, category: category, privileges: data.privileges }, function(err, data) {
+ plugins.fireHook('filter:admin.category.get', { req: req, res: res, category: category, privileges: data.privileges }, function (err, data) {
if (err) {
return next(err);
}
@@ -38,16 +38,16 @@ categoriesController.get = function(req, res, next) {
});
};
-categoriesController.getAll = function(req, res, next) {
+categoriesController.getAll = function (req, res, next) {
// Categories list will be rendered on client side with recursion, etc.
res.render('admin/manage/categories', {});
};
-categoriesController.getAnalytics = function(req, res, next) {
+categoriesController.getAnalytics = function (req, res, next) {
async.parallel({
name: async.apply(categories.getCategoryField, req.params.category_id, 'name'),
analytics: async.apply(analytics.getCategoryAnalytics, req.params.category_id)
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return next(err);
}
diff --git a/src/controllers/admin/dashboard.js b/src/controllers/admin/dashboard.js
index 84ee4fd3d0..22105b6652 100644
--- a/src/controllers/admin/dashboard.js
+++ b/src/controllers/admin/dashboard.js
@@ -10,12 +10,12 @@ var plugins = require('../../plugins');
var dashboardController = {};
-dashboardController.get = function(req, res, next) {
+dashboardController.get = function (req, res, next) {
async.parallel({
- stats: function(next) {
+ stats: function (next) {
getStats(next);
},
- notices: function(next) {
+ notices: function (next) {
var notices = [
{
done: !meta.reloadRequired,
@@ -32,7 +32,7 @@ dashboardController.get = function(req, res, next) {
];
plugins.fireHook('filter:admin.notices', notices, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return next(err);
}
@@ -46,19 +46,19 @@ dashboardController.get = function(req, res, next) {
function getStats(callback) {
async.parallel([
- function(next) {
+ function (next) {
getStatsForSet('ip:recent', 'uniqueIPCount', next);
},
- function(next) {
+ function (next) {
getStatsForSet('users:joindate', 'userCount', next);
},
- function(next) {
+ function (next) {
getStatsForSet('posts:pid', 'postCount', next);
},
- function(next) {
+ function (next) {
getStatsForSet('topics:tid', 'topicCount', next);
}
- ], function(err, results) {
+ ], function (err, results) {
if (err) {
return callback(err);
}
@@ -80,23 +80,23 @@ function getStatsForSet(set, field, callback) {
var now = Date.now();
async.parallel({
- day: function(next) {
+ day: function (next) {
db.sortedSetCount(set, now - terms.day, '+inf', next);
},
- week: function(next) {
+ week: function (next) {
db.sortedSetCount(set, now - terms.week, '+inf', next);
},
- month: function(next) {
+ month: function (next) {
db.sortedSetCount(set, now - terms.month, '+inf', next);
},
- alltime: function(next) {
+ alltime: function (next) {
getGlobalField(field, next);
}
}, callback);
}
function getGlobalField(field, callback) {
- db.getObjectField('global', field, function(err, count) {
+ db.getObjectField('global', field, function (err, count) {
callback(err, parseInt(count, 10) || 0);
});
}
diff --git a/src/controllers/admin/database.js b/src/controllers/admin/database.js
index 8d6bf62fb8..5a28b95ec4 100644
--- a/src/controllers/admin/database.js
+++ b/src/controllers/admin/database.js
@@ -7,9 +7,9 @@ var databaseController = {};
-databaseController.get = function(req, res, next) {
+databaseController.get = function (req, res, next) {
async.parallel({
- redis: function(next) {
+ redis: function (next) {
if (nconf.get('redis')) {
var rdb = require('../../database/redis');
rdb.info(rdb.client, next);
@@ -17,7 +17,7 @@ databaseController.get = function(req, res, next) {
next();
}
},
- mongo: function(next) {
+ mongo: function (next) {
if (nconf.get('mongo')) {
var mdb = require('../../database/mongo');
mdb.info(mdb.client, next);
@@ -25,7 +25,7 @@ databaseController.get = function(req, res, next) {
next();
}
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return next(err);
}
diff --git a/src/controllers/admin/errors.js b/src/controllers/admin/errors.js
index b41d6bdab4..4cacd425c9 100644
--- a/src/controllers/admin/errors.js
+++ b/src/controllers/admin/errors.js
@@ -8,11 +8,11 @@ var analytics = require('../../analytics');
var errorsController = {};
-errorsController.get = function(req, res, next) {
+errorsController.get = function (req, res, next) {
async.parallel({
'not-found': async.apply(meta.errors.get, true),
analytics: async.apply(analytics.getErrorAnalytics)
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return next(err);
}
@@ -21,11 +21,11 @@ errorsController.get = function(req, res, next) {
});
};
-errorsController.export = function(req, res, next) {
+errorsController.export = function (req, res, next) {
async.waterfall([
async.apply(meta.errors.get, false),
async.apply(json2csv)
- ], function(err, csv) {
+ ], function (err, csv) {
if (err) {
return next(err);
}
diff --git a/src/controllers/admin/events.js b/src/controllers/admin/events.js
index 9f7bd9a2f2..8a4d63bad1 100644
--- a/src/controllers/admin/events.js
+++ b/src/controllers/admin/events.js
@@ -9,7 +9,7 @@ var pagination = require('../../pagination');
var eventsController = {};
-eventsController.get = function(req, res, next) {
+eventsController.get = function (req, res, next) {
var page = parseInt(req.query.page, 10) || 1;
var itemsPerPage = 20;
@@ -17,13 +17,13 @@ eventsController.get = function(req, res, next) {
var stop = start + itemsPerPage - 1;
async.parallel({
- eventCount: function(next) {
+ eventCount: function (next) {
db.sortedSetCard('events:time', next);
},
- events: function(next) {
+ events: function (next) {
events.getEvents(start, stop, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return next(err);
}
diff --git a/src/controllers/admin/flags.js b/src/controllers/admin/flags.js
index b5edc7b5be..a0ead7e807 100644
--- a/src/controllers/admin/flags.js
+++ b/src/controllers/admin/flags.js
@@ -13,23 +13,23 @@ var flagsController = {};
var itemsPerPage = 20;
-flagsController.get = function(req, res, next) {
+flagsController.get = function (req, res, next) {
var byUsername = req.query.byUsername || '';
var cid = req.query.cid || 0;
var sortBy = req.query.sortBy || 'count';
var page = parseInt(req.query.page, 10) || 1;
async.parallel({
- categories: function(next) {
+ categories: function (next) {
categories.buildForSelect(req.uid, next);
},
- flagData: function(next) {
+ flagData: function (next) {
getFlagData(req, next);
},
- analytics: function(next) {
+ analytics: function (next) {
analytics.getDailyStatsForSet('analytics:flags', Date.now(), 30, next);
},
- assignees: function(next) {
+ assignees: function (next) {
user.getAdminsandGlobalMods(next);
}
}, function (err, results) {
@@ -38,7 +38,7 @@ flagsController.get = function(req, res, next) {
}
// Minimise data set for assignees so tjs does less work
- results.assignees = results.assignees.map(function(userObj) {
+ results.assignees = results.assignees.map(function (userObj) {
return {
uid: userObj.uid,
username: userObj.username
@@ -47,7 +47,7 @@ flagsController.get = function(req, res, next) {
var pageCount = Math.max(1, Math.ceil(results.flagData.count / itemsPerPage));
- results.categories.forEach(function(category) {
+ results.categories.forEach(function (category) {
category.selected = parseInt(category.cid, 10) === parseInt(cid, 10);
});
@@ -77,14 +77,14 @@ function getFlagData(req, callback) {
var sets = [sortBy === 'count' ? 'posts:flags:count' : 'posts:flagged'];
async.waterfall([
- function(next) {
+ function (next) {
if (byUsername) {
user.getUidByUsername(byUsername, next);
} else {
process.nextTick(next, null, 0);
}
},
- function(uid, next) {
+ function (uid, next) {
if (uid) {
sets.push('uid:' + uid + ':flag:pids');
}
diff --git a/src/controllers/admin/groups.js b/src/controllers/admin/groups.js
index 03b3514327..19aeb4f2f4 100644
--- a/src/controllers/admin/groups.js
+++ b/src/controllers/admin/groups.js
@@ -12,17 +12,17 @@ var async = require('async'),
var groupsController = {};
-groupsController.list = function(req, res, next) {
+groupsController.list = function (req, res, next) {
var page = parseInt(req.query.page, 10) || 1;
var groupsPerPage = 20;
var pageCount = 0;
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRevRange('groups:createtime', 0, -1, next);
},
- function(groupNames, next) {
- groupNames = groupNames.filter(function(name) {
+ function (groupNames, next) {
+ groupNames = groupNames.filter(function (name) {
return name.indexOf(':privileges:') === -1 && name !== 'registered-users';
});
pageCount = Math.ceil(groupNames.length / groupsPerPage);
@@ -33,10 +33,10 @@ groupsController.list = function(req, res, next) {
groupNames = groupNames.slice(start, stop + 1);
groups.getGroupsData(groupNames, next);
},
- function(groupData, next) {
+ function (groupData, next) {
next(null, {groups: groupData, pagination: pagination.create(page, pageCount)});
}
- ], function(err, data) {
+ ], function (err, data) {
if (err) {
return next(err);
}
@@ -49,19 +49,19 @@ groupsController.list = function(req, res, next) {
});
};
-groupsController.get = function(req, res, callback) {
+groupsController.get = function (req, res, callback) {
var groupName = req.params.name;
async.waterfall([
- function(next){
+ function (next){
groups.exists(groupName, next);
},
- function(exists, next) {
+ function (exists, next) {
if (!exists) {
return callback();
}
groups.get(groupName, {uid: req.uid, truncateUserList: true, userListCount: 20}, next);
}
- ], function(err, group) {
+ ], function (err, group) {
if (err) {
return callback(err);
}
diff --git a/src/controllers/admin/homepage.js b/src/controllers/admin/homepage.js
index 89ef0db928..9fdf3a2371 100644
--- a/src/controllers/admin/homepage.js
+++ b/src/controllers/admin/homepage.js
@@ -10,19 +10,19 @@ var plugins = require('../../plugins');
var homePageController = {};
-homePageController.get = function(req, res, next) {
+homePageController.get = function (req, res, next) {
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRange('categories:cid', 0, -1, next);
},
- function(cids, next) {
+ function (cids, next) {
privileges.categories.filterCids('find', cids, 0, next);
},
- function(cids, next) {
+ function (cids, next) {
categories.getCategoriesFields(cids, ['name', 'slug'], next);
},
- function(categoryData, next) {
- categoryData = categoryData.map(function(category) {
+ function (categoryData, next) {
+ categoryData = categoryData.map(function (category) {
return {
route: 'category/' + category.slug,
name: 'Category: ' + category.name
@@ -30,7 +30,7 @@ homePageController.get = function(req, res, next) {
});
next(null, categoryData);
}
- ], function(err, categoryData) {
+ ], function (err, categoryData) {
if (err || !categoryData) {
categoryData = [];
}
@@ -48,7 +48,7 @@ homePageController.get = function(req, res, next) {
route: 'popular',
name: 'Popular'
}
- ].concat(categoryData)}, function(err, data) {
+ ].concat(categoryData)}, function (err, data) {
if (err) {
return next(err);
}
diff --git a/src/controllers/admin/info.js b/src/controllers/admin/info.js
index 80b0829487..6c60d6a048 100644
--- a/src/controllers/admin/info.js
+++ b/src/controllers/admin/info.js
@@ -13,23 +13,23 @@ var infoController = {};
var info = {};
-infoController.get = function(req, res, next) {
+infoController.get = function (req, res, next) {
info = {};
pubsub.publish('sync:node:info:start');
- setTimeout(function() {
+ setTimeout(function () {
var data = [];
- Object.keys(info).forEach(function(key) {
+ Object.keys(info).forEach(function (key) {
data.push(info[key]);
});
- data.sort(function(a, b) {
+ data.sort(function (a, b) {
return (a.os.hostname < b.os.hostname) ? -1 : (a.os.hostname > b.os.hostname) ? 1 : 0;
});
res.render('admin/development/info', {info: data, infoJSON: JSON.stringify(data, null, 4), host: os.hostname(), port: nconf.get('port')});
}, 500);
};
-pubsub.on('sync:node:info:start', function() {
- getNodeInfo(function(err, data) {
+pubsub.on('sync:node:info:start', function () {
+ getNodeInfo(function (err, data) {
if (err) {
return winston.error(err);
}
@@ -37,7 +37,7 @@ pubsub.on('sync:node:info:start', function() {
});
});
-pubsub.on('sync:node:info:end', function(data) {
+pubsub.on('sync:node:info:end', function (data) {
info[data.id] = data.data;
});
@@ -57,18 +57,18 @@ function getNodeInfo(callback) {
platform: os.platform(),
arch: os.arch(),
release: os.release(),
- load: os.loadavg().map(function(load){ return load.toFixed(2); }).join(', ')
+ load: os.loadavg().map(function (load){ return load.toFixed(2); }).join(', ')
}
};
async.parallel({
- stats: function(next) {
+ stats: function (next) {
rooms.getLocalStats(next);
},
- gitInfo: function(next) {
+ gitInfo: function (next) {
getGitInfo(next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -80,15 +80,15 @@ function getNodeInfo(callback) {
function getGitInfo(callback) {
function get(cmd, callback) {
- exec(cmd, function(err, stdout) {
+ exec(cmd, function (err, stdout) {
callback(err, stdout ? stdout.replace(/\n$/, '') : '');
});
}
async.parallel({
- hash: function(next) {
+ hash: function (next) {
get('git rev-parse HEAD', next);
},
- branch: function(next) {
+ branch: function (next) {
get('git rev-parse --abbrev-ref HEAD', next);
}
}, callback);
diff --git a/src/controllers/admin/languages.js b/src/controllers/admin/languages.js
index 85c6d60484..292cd2a3b4 100644
--- a/src/controllers/admin/languages.js
+++ b/src/controllers/admin/languages.js
@@ -6,13 +6,13 @@ var meta = require('../../meta');
var languagesController = {};
-languagesController.get = function(req, res, next) {
- languages.list(function(err, languages) {
+languagesController.get = function (req, res, next) {
+ languages.list(function (err, languages) {
if (err) {
return next(err);
}
- languages.forEach(function(language) {
+ languages.forEach(function (language) {
language.selected = language.code === (meta.config.defaultLang || 'en_GB');
});
diff --git a/src/controllers/admin/logger.js b/src/controllers/admin/logger.js
index 45c9f246c9..7ae327a858 100644
--- a/src/controllers/admin/logger.js
+++ b/src/controllers/admin/logger.js
@@ -2,7 +2,7 @@
var loggerController = {};
-loggerController.get = function(req, res) {
+loggerController.get = function (req, res) {
res.render('admin/development/logger', {});
};
diff --git a/src/controllers/admin/logs.js b/src/controllers/admin/logs.js
index f3ae601dd4..6723d3795f 100644
--- a/src/controllers/admin/logs.js
+++ b/src/controllers/admin/logs.js
@@ -6,8 +6,8 @@ var meta = require('../../meta');
var logsController = {};
-logsController.get = function(req, res, next) {
- meta.logs.get(function(err, logs) {
+logsController.get = function (req, res, next) {
+ meta.logs.get(function (err, logs) {
if (err) {
return next(err);
}
diff --git a/src/controllers/admin/navigation.js b/src/controllers/admin/navigation.js
index 463c525eff..423f21721c 100644
--- a/src/controllers/admin/navigation.js
+++ b/src/controllers/admin/navigation.js
@@ -2,14 +2,14 @@
var navigationController = {};
-navigationController.get = function(req, res, next) {
- require('../../navigation/admin').getAdmin(function(err, data) {
+navigationController.get = function (req, res, next) {
+ require('../../navigation/admin').getAdmin(function (err, data) {
if (err) {
return next(err);
}
- data.enabled.forEach(function(enabled, index) {
+ data.enabled.forEach(function (enabled, index) {
enabled.index = index;
enabled.selected = index === 0;
});
diff --git a/src/controllers/admin/plugins.js b/src/controllers/admin/plugins.js
index 8cc06a5e63..f1a72720ac 100644
--- a/src/controllers/admin/plugins.js
+++ b/src/controllers/admin/plugins.js
@@ -5,10 +5,10 @@ var plugins = require('../../plugins');
var pluginsController = {};
-pluginsController.get = function(req, res, next) {
+pluginsController.get = function (req, res, next) {
async.parallel({
- compatible: function(next) {
- plugins.list(function(err, plugins) {
+ compatible: function (next) {
+ plugins.list(function (err, plugins) {
if (err || !Array.isArray(plugins)) {
plugins = [];
}
@@ -16,8 +16,8 @@ pluginsController.get = function(req, res, next) {
next(null, plugins);
});
},
- all: function(next) {
- plugins.list(false, function(err, plugins) {
+ all: function (next) {
+ plugins.list(false, function (err, plugins) {
if (err || !Array.isArray(plugins)) {
plugins = [];
}
@@ -25,28 +25,28 @@ pluginsController.get = function(req, res, next) {
next(null, plugins);
});
}
- }, function(err, payload) {
+ }, function (err, payload) {
if (err) {
return next(err);
}
- var compatiblePkgNames = payload.compatible.map(function(pkgData) {
+ var compatiblePkgNames = payload.compatible.map(function (pkgData) {
return pkgData.name;
});
res.render('admin/extend/plugins' , {
- installed: payload.compatible.filter(function(plugin) {
+ installed: payload.compatible.filter(function (plugin) {
return plugin.installed;
}),
- upgradeCount: payload.compatible.reduce(function(count, current) {
+ upgradeCount: payload.compatible.reduce(function (count, current) {
if (current.installed && current.outdated) {
++count;
}
return count;
}, 0),
- download: payload.compatible.filter(function(plugin) {
+ download: payload.compatible.filter(function (plugin) {
return !plugin.installed;
}),
- incompatible: payload.all.filter(function(plugin) {
+ incompatible: payload.all.filter(function (plugin) {
return compatiblePkgNames.indexOf(plugin.name) === -1;
})
});
diff --git a/src/controllers/admin/rewards.js b/src/controllers/admin/rewards.js
index 063abb6807..8ff05c75b3 100644
--- a/src/controllers/admin/rewards.js
+++ b/src/controllers/admin/rewards.js
@@ -2,8 +2,8 @@
var rewardsController = {};
-rewardsController.get = function(req, res, next) {
- require('../../rewards/admin').get(function(err, data) {
+rewardsController.get = function (req, res, next) {
+ require('../../rewards/admin').get(function (err, data) {
if (err) {
return next(err);
}
diff --git a/src/controllers/admin/settings.js b/src/controllers/admin/settings.js
index 13e7b42722..a6afb80cfc 100644
--- a/src/controllers/admin/settings.js
+++ b/src/controllers/admin/settings.js
@@ -4,7 +4,7 @@ var settingsController = {};
var async = require('async'),
meta = require('../../meta');
-settingsController.get = function(req, res, next) {
+settingsController.get = function (req, res, next) {
var term = req.params.term ? req.params.term : 'general';
switch (req.params.term) {
@@ -24,15 +24,15 @@ function renderEmail(req, res, next) {
var utils = require('../../../public/src/utils');
var emailsPath = path.join(__dirname, '../../../public/templates/emails');
- utils.walk(emailsPath, function(err, emails) {
+ utils.walk(emailsPath, function (err, emails) {
if (err) {
return next(err);
}
- async.map(emails, function(email, next) {
+ async.map(emails, function (email, next) {
var path = email.replace(emailsPath, '').substr(1).replace('.tpl', '');
- fs.readFile(email, function(err, original) {
+ fs.readFile(email, function (err, original) {
if (err) {
return next(err);
}
@@ -46,14 +46,14 @@ function renderEmail(req, res, next) {
original: original.toString()
});
});
- }, function(err, emails) {
+ }, function (err, emails) {
if (err) {
return next(err);
}
res.render('admin/settings/email', {
emails: emails,
- sendable: emails.filter(function(email) {
+ sendable: emails.filter(function (email) {
return email.path.indexOf('_plaintext') === -1 && email.path.indexOf('partials') === -1;
})
});
diff --git a/src/controllers/admin/social.js b/src/controllers/admin/social.js
index d8f87af060..11c7982701 100644
--- a/src/controllers/admin/social.js
+++ b/src/controllers/admin/social.js
@@ -5,8 +5,8 @@ var social = require('../../social');
var socialController = {};
-socialController.get = function(req, res, next) {
- social.getPostSharing(function(err, posts) {
+socialController.get = function (req, res, next) {
+ social.getPostSharing(function (err, posts) {
if (err) {
return next(err);
}
diff --git a/src/controllers/admin/sounds.js b/src/controllers/admin/sounds.js
index b583125c5a..801a2067ac 100644
--- a/src/controllers/admin/sounds.js
+++ b/src/controllers/admin/sounds.js
@@ -4,13 +4,13 @@ var meta = require('../../meta');
var soundsController = {};
-soundsController.get = function(req, res, next) {
- meta.sounds.getFiles(function(err, sounds) {
+soundsController.get = function (req, res, next) {
+ meta.sounds.getFiles(function (err, sounds) {
if (err) {
return next(err);
}
- sounds = Object.keys(sounds).map(function(name) {
+ sounds = Object.keys(sounds).map(function (name) {
return {
name: name
};
diff --git a/src/controllers/admin/tags.js b/src/controllers/admin/tags.js
index 22e3b32d67..a645e2ef11 100644
--- a/src/controllers/admin/tags.js
+++ b/src/controllers/admin/tags.js
@@ -4,8 +4,8 @@ var topics = require('../../topics');
var tagsController = {};
-tagsController.get = function(req, res, next) {
- topics.getTags(0, 199, function(err, tags) {
+tagsController.get = function (req, res, next) {
+ topics.getTags(0, 199, function (err, tags) {
if (err) {
return next(err);
}
diff --git a/src/controllers/admin/themes.js b/src/controllers/admin/themes.js
index e5ef8a9343..4f6f3e1f3b 100644
--- a/src/controllers/admin/themes.js
+++ b/src/controllers/admin/themes.js
@@ -5,9 +5,9 @@ var file = require('../../file');
var themesController = {};
-themesController.get = function(req, res, next) {
+themesController.get = function (req, res, next) {
var themeDir = path.join(__dirname, '../../../node_modules/' + req.params.theme);
- file.exists(themeDir, function(exists) {
+ file.exists(themeDir, function (exists) {
if (!exists) {
return next();
}
diff --git a/src/controllers/admin/uploads.js b/src/controllers/admin/uploads.js
index b507e092cf..d1664cb8f1 100644
--- a/src/controllers/admin/uploads.js
+++ b/src/controllers/admin/uploads.js
@@ -13,14 +13,14 @@ var allowedImageTypes = ['image/png', 'image/jpeg', 'image/pjpeg', 'image/jpg',
var uploadsController = {};
-uploadsController.uploadCategoryPicture = function(req, res, next) {
+uploadsController.uploadCategoryPicture = function (req, res, next) {
var uploadedFile = req.files.files[0];
var params = null;
try {
params = JSON.parse(req.body.params);
} catch (e) {
- fs.unlink(uploadedFile.path, function(err) {
+ fs.unlink(uploadedFile.path, function (err) {
if (err) {
winston.error(err);
}
@@ -34,13 +34,13 @@ uploadsController.uploadCategoryPicture = function(req, res, next) {
}
};
-uploadsController.uploadFavicon = function(req, res, next) {
+uploadsController.uploadFavicon = function (req, res, next) {
var uploadedFile = req.files.files[0];
var allowedTypes = ['image/x-icon', 'image/vnd.microsoft.icon'];
if (validateUpload(req, res, next, uploadedFile, allowedTypes)) {
- file.saveFileToLocal('favicon.ico', 'system', uploadedFile.path, function(err, image) {
- fs.unlink(uploadedFile.path, function(err) {
+ file.saveFileToLocal('favicon.ico', 'system', uploadedFile.path, function (err, image) {
+ fs.unlink(uploadedFile.path, function (err) {
if (err) {
winston.error(err);
}
@@ -54,19 +54,19 @@ uploadsController.uploadFavicon = function(req, res, next) {
}
};
-uploadsController.uploadTouchIcon = function(req, res, next) {
+uploadsController.uploadTouchIcon = function (req, res, next) {
var uploadedFile = req.files.files[0],
allowedTypes = ['image/png'],
sizes = [36, 48, 72, 96, 144, 192];
if (validateUpload(req, res, next, uploadedFile, allowedTypes)) {
- file.saveFileToLocal('touchicon-orig.png', 'system', uploadedFile.path, function(err, imageObj) {
+ file.saveFileToLocal('touchicon-orig.png', 'system', uploadedFile.path, function (err, imageObj) {
if (err) {
return next(err);
}
// Resize the image into squares for use as touch icons at various DPIs
- async.each(sizes, function(size, next) {
+ async.each(sizes, function (size, next) {
async.series([
async.apply(file.saveFileToLocal, 'touchicon-' + size + '.png', 'system', uploadedFile.path),
async.apply(image.resizeImage, {
@@ -76,8 +76,8 @@ uploadsController.uploadTouchIcon = function(req, res, next) {
height: size
})
], next);
- }, function(err) {
- fs.unlink(uploadedFile.path, function(err) {
+ }, function (err) {
+ fs.unlink(uploadedFile.path, function (err) {
if (err) {
winston.error(err);
}
@@ -93,14 +93,14 @@ uploadsController.uploadTouchIcon = function(req, res, next) {
}
};
-uploadsController.uploadLogo = function(req, res, next) {
+uploadsController.uploadLogo = function (req, res, next) {
upload('site-logo', req, res, next);
};
-uploadsController.uploadSound = function(req, res, next) {
+uploadsController.uploadSound = function (req, res, next) {
var uploadedFile = req.files.files[0];
- file.saveFileToLocal(uploadedFile.name, 'sounds', uploadedFile.path, function(err) {
+ file.saveFileToLocal(uploadedFile.name, 'sounds', uploadedFile.path, function (err) {
if (err) {
return next(err);
}
@@ -114,7 +114,7 @@ uploadsController.uploadSound = function(req, res, next) {
fs.symlink(filePath, path.join(soundsPath, path.basename(filePath)), 'file');
}
- fs.unlink(uploadedFile.path, function(err) {
+ fs.unlink(uploadedFile.path, function (err) {
if (err) {
return next(err);
}
@@ -124,11 +124,11 @@ uploadsController.uploadSound = function(req, res, next) {
});
};
-uploadsController.uploadDefaultAvatar = function(req, res, next) {
+uploadsController.uploadDefaultAvatar = function (req, res, next) {
upload('avatar-default', req, res, next);
};
-uploadsController.uploadOgImage = function(req, res, next) {
+uploadsController.uploadOgImage = function (req, res, next) {
upload('og:image', req, res, next);
};
@@ -143,7 +143,7 @@ function upload(name, req, res, next) {
function validateUpload(req, res, next, uploadedFile, allowedTypes) {
if (allowedTypes.indexOf(uploadedFile.type) === -1) {
- fs.unlink(uploadedFile.path, function(err) {
+ fs.unlink(uploadedFile.path, function (err) {
if (err) {
winston.error(err);
}
@@ -158,7 +158,7 @@ function validateUpload(req, res, next, uploadedFile, allowedTypes) {
function uploadImage(filename, folder, uploadedFile, req, res, next) {
function done(err, image) {
- fs.unlink(uploadedFile.path, function(err) {
+ fs.unlink(uploadedFile.path, function (err) {
if (err) {
winston.error(err);
}
diff --git a/src/controllers/admin/users.js b/src/controllers/admin/users.js
index c2e085ada1..426d8b1c19 100644
--- a/src/controllers/admin/users.js
+++ b/src/controllers/admin/users.js
@@ -15,40 +15,40 @@ var usersController = {};
var userFields = ['uid', 'username', 'userslug', 'email', 'postcount', 'joindate', 'banned',
'reputation', 'picture', 'flags', 'lastonline', 'email:confirmed'];
-usersController.search = function(req, res, next) {
+usersController.search = function (req, res, next) {
res.render('admin/manage/users', {
search_display: '',
users: []
});
};
-usersController.sortByJoinDate = function(req, res, next) {
+usersController.sortByJoinDate = function (req, res, next) {
getUsers('users:joindate', 'latest', undefined, undefined, req, res, next);
};
-usersController.notValidated = function(req, res, next) {
+usersController.notValidated = function (req, res, next) {
getUsers('users:notvalidated', 'notvalidated', undefined, undefined, req, res, next);
};
-usersController.noPosts = function(req, res, next) {
+usersController.noPosts = function (req, res, next) {
getUsers('users:postcount', 'noposts', '-inf', 0, req, res, next);
};
-usersController.flagged = function(req, res, next) {
+usersController.flagged = function (req, res, next) {
getUsers('users:flags', 'mostflags', 1, '+inf', req, res, next);
};
-usersController.inactive = function(req, res, next) {
+usersController.inactive = function (req, res, next) {
var timeRange = 1000 * 60 * 60 * 24 * 30 * (parseInt(req.query.months, 10) || 3);
var cutoff = Date.now() - timeRange;
getUsers('users:online', 'inactive', '-inf', cutoff, req, res, next);
};
-usersController.banned = function(req, res, next) {
+usersController.banned = function (req, res, next) {
getUsers('users:banned', 'banned', undefined, undefined, req, res, next);
};
-usersController.registrationQueue = function(req, res, next) {
+usersController.registrationQueue = function (req, res, next) {
var page = parseInt(req.query.page, 10) || 1;
var itemsPerPage = 20;
var start = (page - 1) * 20;
@@ -56,37 +56,37 @@ usersController.registrationQueue = function(req, res, next) {
var invitations;
async.parallel({
- registrationQueueCount: function(next) {
+ registrationQueueCount: function (next) {
db.sortedSetCard('registration:queue', next);
},
- users: function(next) {
+ users: function (next) {
user.getRegistrationQueue(start, stop, next);
},
- customHeaders: function(next) {
+ customHeaders: function (next) {
plugins.fireHook('filter:admin.registrationQueue.customHeaders', {headers: []}, next);
},
- invites: function(next) {
+ invites: function (next) {
async.waterfall([
- function(next) {
+ function (next) {
user.getAllInvites(next);
},
- function(_invitations, next) {
+ function (_invitations, next) {
invitations = _invitations;
- async.map(invitations, function(invites, next) {
+ async.map(invitations, function (invites, next) {
user.getUserField(invites.uid, 'username', next);
}, next);
},
- function(usernames, next) {
- invitations.forEach(function(invites, index) {
+ function (usernames, next) {
+ invitations.forEach(function (invites, index) {
invites.username = usernames[index];
});
- async.map(invitations, function(invites, next) {
+ async.map(invitations, function (invites, next) {
async.map(invites.invitations, user.getUsernameByEmail, next);
}, next);
},
- function(usernames, next) {
- invitations.forEach(function(invites, index) {
- invites.invitations = invites.invitations.map(function(email, i) {
+ function (usernames, next) {
+ invitations.forEach(function (invites, index) {
+ invites.invitations = invites.invitations.map(function (email, i) {
return {
email: email,
username: usernames[index][i] === '[[global:guest]]' ? '' : usernames[index][i]
@@ -97,7 +97,7 @@ usersController.registrationQueue = function(req, res, next) {
}
], next);
}
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return next(err);
}
@@ -116,33 +116,33 @@ function getUsers(set, section, min, max, req, res, next) {
var byScore = min !== undefined && max !== undefined;
async.parallel({
- count: function(next) {
+ count: function (next) {
if (byScore) {
db.sortedSetCount(set, min, max, next);
} else {
db.sortedSetCard(set, next);
}
},
- users: function(next) {
+ users: function (next) {
async.waterfall([
- function(next) {
+ function (next) {
if (byScore) {
db.getSortedSetRevRangeByScore(set, start, resultsPerPage, max, min, next);
} else {
user.getUidsFromSet(set, start, stop, next);
}
},
- function(uids, next) {
+ function (uids, next) {
user.getUsersWithFields(uids, userFields, req.uid, next);
}
], next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return next(err);
}
- results.users = results.users.filter(function(user) {
+ results.users = results.users.filter(function (user) {
user.email = validator.escape(String(user.email || ''));
return user && parseInt(user.uid, 10);
});
@@ -169,14 +169,14 @@ function render(req, res, data) {
res.render('admin/manage/users', data);
}
-usersController.getCSV = function(req, res, next) {
+usersController.getCSV = function (req, res, next) {
events.log({
type: 'getUsersCSV',
uid: req.user.uid,
ip: req.ip
});
- user.getUsersCSV(function(err, data) {
+ user.getUsersCSV(function (err, data) {
if (err) {
return next(err);
}
diff --git a/src/controllers/admin/widgets.js b/src/controllers/admin/widgets.js
index 8dd93fbead..c2d0d1e667 100644
--- a/src/controllers/admin/widgets.js
+++ b/src/controllers/admin/widgets.js
@@ -2,8 +2,8 @@
var widgetsController = {};
-widgetsController.get = function(req, res, next) {
- require('../../widgets/admin').get(function(err, data) {
+widgetsController.get = function (req, res, next) {
+ require('../../widgets/admin').get(function (err, data) {
if (err) {
return next(err);
}
diff --git a/src/controllers/api.js b/src/controllers/api.js
index 42cc74e7e7..36261a23c1 100644
--- a/src/controllers/api.js
+++ b/src/controllers/api.js
@@ -16,7 +16,7 @@ var accountHelpers = require('../controllers/accounts/helpers');
var apiController = {};
-apiController.getConfig = function(req, res, next) {
+apiController.getConfig = function (req, res, next) {
var config = {};
config.environment = process.env.NODE_ENV;
config.relative_path = nconf.get('relative_path');
@@ -82,7 +82,7 @@ apiController.getConfig = function(req, res, next) {
config.bootswatchSkin = settings.bootswatchSkin || config.bootswatchSkin;
plugins.fireHook('filter:config.get', config, next);
}
- ], function(err, config) {
+ ], function (err, config) {
if (err) {
return next(err);
}
@@ -96,7 +96,7 @@ apiController.getConfig = function(req, res, next) {
};
-apiController.renderWidgets = function(req, res, next) {
+apiController.renderWidgets = function (req, res, next) {
var areas = {
template: req.query.template,
locations: req.query.locations,
@@ -116,7 +116,7 @@ apiController.renderWidgets = function(req, res, next) {
},
req,
res,
- function(err, widgets) {
+ function (err, widgets) {
if (err) {
return next(err);
}
@@ -124,15 +124,15 @@ apiController.renderWidgets = function(req, res, next) {
});
};
-apiController.getPostData = function(pid, uid, callback) {
+apiController.getPostData = function (pid, uid, callback) {
async.parallel({
- privileges: function(next) {
+ privileges: function (next) {
privileges.posts.get([pid], uid, next);
},
- post: function(next) {
+ post: function (next) {
posts.getPostData(pid, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err || !results.post) {
return callback(err);
}
@@ -153,15 +153,15 @@ apiController.getPostData = function(pid, uid, callback) {
});
};
-apiController.getTopicData = function(tid, uid, callback) {
+apiController.getTopicData = function (tid, uid, callback) {
async.parallel({
- privileges: function(next) {
+ privileges: function (next) {
privileges.topics.get(tid, uid, next);
},
- topic: function(next) {
+ topic: function (next) {
topics.getTopicData(tid, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err || !results.topic) {
return callback(err);
}
@@ -173,15 +173,15 @@ apiController.getTopicData = function(tid, uid, callback) {
});
};
-apiController.getCategoryData = function(cid, uid, callback) {
+apiController.getCategoryData = function (cid, uid, callback) {
async.parallel({
- privileges: function(next) {
+ privileges: function (next) {
privileges.categories.get(cid, uid, next);
},
- category: function(next) {
+ category: function (next) {
categories.getCategoryData(cid, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err || !results.category) {
return callback(err);
}
@@ -194,7 +194,7 @@ apiController.getCategoryData = function(cid, uid, callback) {
};
-apiController.getObject = function(req, res, next) {
+apiController.getObject = function (req, res, next) {
var methods = {
post: apiController.getPostData,
topic: apiController.getTopicData,
@@ -204,7 +204,7 @@ apiController.getObject = function(req, res, next) {
if (!method) {
return next();
}
- method(req.params.id, req.uid, function(err, result) {
+ method(req.params.id, req.uid, function (err, result) {
if (err || !result) {
return next(err);
}
@@ -213,18 +213,18 @@ apiController.getObject = function(req, res, next) {
});
};
-apiController.getCurrentUser = function(req, res, next) {
+apiController.getCurrentUser = function (req, res, next) {
if (!req.uid) {
return res.status(401).json('not-authorized');
}
async.waterfall([
- function(next) {
+ function (next) {
user.getUserField(req.uid, 'userslug', next);
},
- function(userslug, next) {
+ function (userslug, next) {
accountHelpers.getUserDataByUserSlug(userslug, req.uid, next);
}
- ], function(err, userData) {
+ ], function (err, userData) {
if (err) {
return next(err);
}
@@ -232,20 +232,20 @@ apiController.getCurrentUser = function(req, res, next) {
});
};
-apiController.getUserByUID = function(req, res, next) {
+apiController.getUserByUID = function (req, res, next) {
byType('uid', req, res, next);
};
-apiController.getUserByUsername = function(req, res, next) {
+apiController.getUserByUsername = function (req, res, next) {
byType('username', req, res, next);
};
-apiController.getUserByEmail = function(req, res, next) {
+apiController.getUserByEmail = function (req, res, next) {
byType('email', req, res, next);
};
function byType(type, req, res, next) {
- apiController.getUserDataByField(req.uid, type, req.params[type], function(err, data) {
+ apiController.getUserDataByField(req.uid, type, req.params[type], function (err, data) {
if (err || !data) {
return next(err);
}
@@ -253,7 +253,7 @@ function byType(type, req, res, next) {
});
}
-apiController.getUserDataByField = function(callerUid, field, fieldValue, callback) {
+apiController.getUserDataByField = function (callerUid, field, fieldValue, callback) {
async.waterfall([
function (next) {
if (field === 'uid') {
@@ -275,7 +275,7 @@ apiController.getUserDataByField = function(callerUid, field, fieldValue, callba
], callback);
};
-apiController.getUserDataByUID = function(callerUid, uid, callback) {
+apiController.getUserDataByUID = function (callerUid, uid, callback) {
if (!parseInt(callerUid, 10) && parseInt(meta.config.privateUserInfo, 10) === 1) {
return callback(new Error('[[error:no-privileges]]'));
}
@@ -287,7 +287,7 @@ apiController.getUserDataByUID = function(callerUid, uid, callback) {
async.parallel({
userData: async.apply(user.getUserData, uid),
settings: async.apply(user.getSettings, uid)
- }, function(err, results) {
+ }, function (err, results) {
if (err || !results.userData) {
return callback(err || new Error('[[error:no-user]]'));
}
@@ -299,8 +299,8 @@ apiController.getUserDataByUID = function(callerUid, uid, callback) {
});
};
-apiController.getModerators = function(req, res, next) {
- categories.getModerators(req.params.cid, function(err, moderators) {
+apiController.getModerators = function (req, res, next) {
+ categories.getModerators(req.params.cid, function (err, moderators) {
if (err) {
return next(err);
}
@@ -309,7 +309,7 @@ apiController.getModerators = function(req, res, next) {
};
-apiController.getRecentPosts = function(req, res, next) {
+apiController.getRecentPosts = function (req, res, next) {
posts.getRecentPosts(req.uid, 0, 19, req.params.term, function (err, data) {
if (err) {
return next(err);
diff --git a/src/controllers/authentication.js b/src/controllers/authentication.js
index 43707bfccd..0111f62573 100644
--- a/src/controllers/authentication.js
+++ b/src/controllers/authentication.js
@@ -17,7 +17,7 @@ var Password = require('../password');
var authenticationController = {};
-authenticationController.register = function(req, res, next) {
+authenticationController.register = function (req, res, next) {
var registrationType = meta.config.registrationType || 'normal';
if (registrationType === 'disabled') {
@@ -33,14 +33,14 @@ authenticationController.register = function(req, res, next) {
}
async.waterfall([
- function(next) {
+ function (next) {
if (registrationType === 'invite-only' || registrationType === 'admin-invite-only') {
user.verifyInvitation(userData, next);
} else {
next();
}
},
- function(next) {
+ function (next) {
if (!userData.email) {
return next(new Error('[[error:invalid-email]]'));
}
@@ -55,17 +55,17 @@ authenticationController.register = function(req, res, next) {
user.isPasswordValid(userData.password, next);
},
- function(next) {
+ function (next) {
res.locals.processLogin = true; // set it to false in plugin if you wish to just register only
plugins.fireHook('filter:register.check', {req: req, res: res, userData: userData}, next);
},
- function(data, next) {
+ function (data, next) {
if (registrationType === 'normal' || registrationType === 'invite-only' || registrationType === 'admin-invite-only') {
registerAndLoginUser(req, res, userData, next);
} else if (registrationType === 'admin-approval') {
addToApprovalQueue(req, userData, next);
} else if (registrationType === 'admin-approval-ip') {
- db.sortedSetCard('ip:' + req.ip + ':uid', function(err, count) {
+ db.sortedSetCard('ip:' + req.ip + ':uid', function (err, count) {
if (err) {
next(err);
} else if (count) {
@@ -76,7 +76,7 @@ authenticationController.register = function(req, res, next) {
});
}
}
- ], function(err, data) {
+ ], function (err, data) {
if (err) {
return res.status(400).send(err.message);
}
@@ -92,11 +92,11 @@ authenticationController.register = function(req, res, next) {
function registerAndLoginUser(req, res, userData, callback) {
var uid;
async.waterfall([
- function(next) {
+ function (next) {
plugins.fireHook('filter:register.interstitial', {
userData: userData,
interstitials: []
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return next(err);
}
@@ -113,10 +113,10 @@ function registerAndLoginUser(req, res, userData, callback) {
}
});
},
- function(next) {
+ function (next) {
user.create(userData, next);
},
- function(_uid, next) {
+ function (_uid, next) {
uid = _uid;
if (res.locals.processLogin) {
authenticationController.doLogin(req, uid, next);
@@ -124,7 +124,7 @@ function registerAndLoginUser(req, res, userData, callback) {
next();
}
},
- function(next) {
+ function (next) {
user.deleteInvitationKey(userData.email);
plugins.fireHook('filter:register.complete', {uid: uid, referrer: req.body.referrer || nconf.get('relative_path') + '/'}, next);
}
@@ -133,27 +133,27 @@ function registerAndLoginUser(req, res, userData, callback) {
function addToApprovalQueue(req, userData, callback) {
async.waterfall([
- function(next) {
+ function (next) {
userData.ip = req.ip;
user.addToApprovalQueue(userData, next);
},
- function(next) {
+ function (next) {
next(null, {message: '[[register:registration-added-to-queue]]'});
}
], callback);
}
-authenticationController.registerComplete = function(req, res, next) {
+authenticationController.registerComplete = function (req, res, next) {
// For the interstitials that respond, execute the callback with the form body
plugins.fireHook('filter:register.interstitial', {
userData: req.session.registration,
interstitials: []
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return next(err);
}
- var callbacks = data.interstitials.reduce(function(memo, cur) {
+ var callbacks = data.interstitials.reduce(function (memo, cur) {
if (cur.hasOwnProperty('callback') && typeof cur.callback === 'function') {
memo.push(async.apply(cur.callback, req.session.registration, req.body));
}
@@ -161,7 +161,7 @@ authenticationController.registerComplete = function(req, res, next) {
return memo;
}, []);
- var done = function() {
+ var done = function () {
delete req.session.registration;
if (req.session.returnTo) {
@@ -171,7 +171,7 @@ authenticationController.registerComplete = function(req, res, next) {
}
};
- async.parallel(callbacks, function(err) {
+ async.parallel(callbacks, function (err) {
if (err) {
req.flash('error', err.message);
return res.redirect(nconf.get('relative_path') + '/register/complete');
@@ -188,14 +188,14 @@ authenticationController.registerComplete = function(req, res, next) {
});
};
-authenticationController.registerAbort = function(req, res) {
+authenticationController.registerAbort = function (req, res) {
// End the session and redirect to home
- req.session.destroy(function() {
+ req.session.destroy(function () {
res.redirect(nconf.get('relative_path') + '/');
});
};
-authenticationController.login = function(req, res, next) {
+authenticationController.login = function (req, res, next) {
// Handle returnTo data
if (req.body.hasOwnProperty('returnTo') && !req.session.returnTo) {
// As req.body is data obtained via userland, it is untrusted, restrict to internal links only
@@ -212,7 +212,7 @@ authenticationController.login = function(req, res, next) {
var loginWith = meta.config.allowLoginWith || 'username-email';
if (req.body.username && utils.isEmailValid(req.body.username) && loginWith.indexOf('email') !== -1) {
- user.getUsernameByEmail(req.body.username, function(err, username) {
+ user.getUsernameByEmail(req.body.username, function (err, username) {
if (err) {
return next(err);
}
@@ -227,7 +227,7 @@ authenticationController.login = function(req, res, next) {
};
function continueLogin(req, res, next) {
- passport.authenticate('local', function(err, userData, info) {
+ passport.authenticate('local', function (err, userData, info) {
if (err) {
return res.status(403).send(err.message);
}
@@ -255,7 +255,7 @@ function continueLogin(req, res, next) {
if (passwordExpiry && passwordExpiry < Date.now()) {
winston.verbose('[auth] Triggering password reset for uid ' + userData.uid + ' due to password policy');
req.session.passwordExpired = true;
- user.reset.generate(userData.uid, function(err, code) {
+ user.reset.generate(userData.uid, function (err, code) {
if (err) {
return res.status(403).send(err.message);
}
@@ -263,7 +263,7 @@ function continueLogin(req, res, next) {
res.status(200).send(nconf.get('relative_path') + '/reset/' + code);
});
} else {
- authenticationController.doLogin(req, userData.uid, function(err) {
+ authenticationController.doLogin(req, userData.uid, function (err) {
if (err) {
return res.status(403).send(err.message);
}
@@ -281,12 +281,12 @@ function continueLogin(req, res, next) {
})(req, res, next);
}
-authenticationController.doLogin = function(req, uid, callback) {
+authenticationController.doLogin = function (req, uid, callback) {
if (!uid) {
return callback();
}
- req.login({uid: uid}, function(err) {
+ req.login({uid: uid}, function (err) {
if (err) {
return callback(err);
}
@@ -295,8 +295,8 @@ authenticationController.doLogin = function(req, uid, callback) {
});
};
-authenticationController.onSuccessfulLogin = function(req, uid, callback) {
- callback = callback || function() {};
+authenticationController.onSuccessfulLogin = function (req, uid, callback) {
+ callback = callback || function () {};
var uuid = utils.generateUUID();
req.session.meta = {};
@@ -326,7 +326,7 @@ authenticationController.onSuccessfulLogin = function(req, uid, callback) {
function (next) {
user.updateLastOnlineTime(uid, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
@@ -335,7 +335,7 @@ authenticationController.onSuccessfulLogin = function(req, uid, callback) {
});
};
-authenticationController.localLogin = function(req, username, password, next) {
+authenticationController.localLogin = function (req, username, password, next) {
if (!username) {
return next(new Error('[[error:invalid-username]]'));
}
@@ -359,13 +359,13 @@ authenticationController.localLogin = function(req, username, password, next) {
},
function (next) {
async.parallel({
- userData: function(next) {
+ userData: function (next) {
db.getObjectFields('user:' + uid, ['password', 'passwordExpiry'], next);
},
- isAdmin: function(next) {
+ isAdmin: function (next) {
user.isAdministrator(uid, next);
},
- banned: function(next) {
+ banned: function (next) {
user.isBanned(uid, next);
}
}, next);
@@ -383,7 +383,7 @@ authenticationController.localLogin = function(req, username, password, next) {
}
if (result.banned) {
// Retrieve ban reason and show error
- return user.getLatestBanInfo(uid, function(err, banInfo) {
+ return user.getLatestBanInfo(uid, function (err, banInfo) {
if (err) {
next(err);
} else if (banInfo.reason) {
@@ -406,10 +406,10 @@ authenticationController.localLogin = function(req, username, password, next) {
], next);
};
-authenticationController.logout = function(req, res, next) {
+authenticationController.logout = function (req, res, next) {
if (req.user && parseInt(req.user.uid, 10) > 0 && req.sessionID) {
var uid = parseInt(req.user.uid, 10);
- user.auth.revokeSession(req.sessionID, uid, function(err) {
+ user.auth.revokeSession(req.sessionID, uid, function (err) {
if (err) {
return next(err);
}
@@ -418,7 +418,7 @@ authenticationController.logout = function(req, res, next) {
user.setUserField(uid, 'lastonline', Date.now() - 300000);
- plugins.fireHook('static:user.loggedOut', {req: req, res: res, uid: uid}, function() {
+ plugins.fireHook('static:user.loggedOut', {req: req, res: res, uid: uid}, function () {
res.status(200).send('');
});
});
diff --git a/src/controllers/categories.js b/src/controllers/categories.js
index fa685e3705..9a18e7f1dd 100644
--- a/src/controllers/categories.js
+++ b/src/controllers/categories.js
@@ -10,7 +10,7 @@ var helpers = require('./helpers');
var categoriesController = {};
-categoriesController.list = function(req, res, next) {
+categoriesController.list = function (req, res, next) {
res.locals.metaTags = [{
name: "title",
content: validator.escape(String(meta.config.title || 'NodeBB'))
@@ -49,7 +49,7 @@ categoriesController.list = function(req, res, next) {
categories.getRecentTopicReplies(allCategories, req.uid, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return next(err);
}
@@ -63,7 +63,7 @@ categoriesController.list = function(req, res, next) {
data.breadcrumbs = helpers.buildBreadcrumbs([{text: data.title}]);
}
- data.categories.forEach(function(category) {
+ data.categories.forEach(function (category) {
if (category && Array.isArray(category.posts) && category.posts.length) {
category.teaser = {
url: nconf.get('relative_path') + '/topic/' + category.posts[0].topic.slug + '/' + category.posts[0].index,
diff --git a/src/controllers/category.js b/src/controllers/category.js
index bf76c8e09f..2a660ee63c 100644
--- a/src/controllers/category.js
+++ b/src/controllers/category.js
@@ -15,7 +15,7 @@ var utils = require('../../public/src/utils');
var categoryController = {};
-categoryController.get = function(req, res, callback) {
+categoryController.get = function (req, res, callback) {
var cid = req.params.category_id;
var currentPage = parseInt(req.query.page, 10) || 1;
var pageCount = 1;
@@ -29,13 +29,13 @@ categoryController.get = function(req, res, callback) {
async.waterfall([
function (next) {
async.parallel({
- categoryData: function(next) {
+ categoryData: function (next) {
categories.getCategoryFields(cid, ['slug', 'disabled', 'topic_count'], next);
},
- privileges: function(next) {
+ privileges: function (next) {
privileges.categories.get(cid, req.uid, next);
},
- userSettings: function(next) {
+ userSettings: function (next) {
user.getSettings(req.uid, next);
}
}, next);
@@ -101,10 +101,10 @@ categoryController.get = function(req, res, callback) {
};
async.waterfall([
- function(next) {
+ function (next) {
user.getUidByUserslug(req.query.author, next);
},
- function(uid, next) {
+ function (uid, next) {
payload.targetUid = uid;
if (uid) {
payload.set = 'cid:' + cid + ':uid:' + uid + ':tids';
@@ -132,7 +132,7 @@ categoryController.get = function(req, res, callback) {
url: nconf.get('relative_path') + '/category/' + categoryData.slug
}
];
- helpers.buildCategoryBreadcrumbs(categoryData.parentCid, function(err, crumbs) {
+ helpers.buildCategoryBreadcrumbs(categoryData.parentCid, function (err, crumbs) {
if (err) {
return next(err);
}
@@ -146,7 +146,7 @@ categoryController.get = function(req, res, callback) {
}
var allCategories = [];
categories.flattenCategories(allCategories, categoryData.children);
- categories.getRecentTopicReplies(allCategories, req.uid, function(err) {
+ categories.getRecentTopicReplies(allCategories, req.uid, function (err) {
next(err, categoryData);
});
}
@@ -205,7 +205,7 @@ categoryController.get = function(req, res, callback) {
categoryData.title = categoryData.name;
pageCount = Math.max(1, Math.ceil(categoryData.topic_count / settings.topicsPerPage));
categoryData.pagination = pagination.create(currentPage, pageCount, req.query);
- categoryData.pagination.rel.forEach(function(rel) {
+ categoryData.pagination.rel.forEach(function (rel) {
rel.href = nconf.get('url') + '/category/' + categoryData.slug + rel.href;
res.locals.linkTags.push(rel);
});
diff --git a/src/controllers/globalmods.js b/src/controllers/globalmods.js
index 3275c7929e..b45c6ffbf4 100644
--- a/src/controllers/globalmods.js
+++ b/src/controllers/globalmods.js
@@ -6,8 +6,8 @@ var adminBlacklistController = require('./admin/blacklist');
var globalModsController = {};
-globalModsController.flagged = function(req, res, next) {
- user.isAdminOrGlobalMod(req.uid, function(err, isAdminOrGlobalMod) {
+globalModsController.flagged = function (req, res, next) {
+ user.isAdminOrGlobalMod(req.uid, function (err, isAdminOrGlobalMod) {
if (err || !isAdminOrGlobalMod) {
return next(err);
}
@@ -16,8 +16,8 @@ globalModsController.flagged = function(req, res, next) {
});
};
-globalModsController.ipBlacklist = function(req, res, next) {
- user.isAdminOrGlobalMod(req.uid, function(err, isAdminOrGlobalMod) {
+globalModsController.ipBlacklist = function (req, res, next) {
+ user.isAdminOrGlobalMod(req.uid, function (err, isAdminOrGlobalMod) {
if (err || !isAdminOrGlobalMod) {
return next(err);
}
diff --git a/src/controllers/groups.js b/src/controllers/groups.js
index 55b408183a..53b7064f59 100644
--- a/src/controllers/groups.js
+++ b/src/controllers/groups.js
@@ -11,10 +11,10 @@ var helpers = require('./helpers');
var groupsController = {};
-groupsController.list = function(req, res, next) {
+groupsController.list = function (req, res, next) {
var sort = req.query.sort || 'alpha';
- groupsController.getGroupsFromSet(req.uid, sort, 0, 14, function(err, data) {
+ groupsController.getGroupsFromSet(req.uid, sort, 0, 14, function (err, data) {
if (err) {
return next(err);
}
@@ -24,7 +24,7 @@ groupsController.list = function(req, res, next) {
});
};
-groupsController.getGroupsFromSet = function(uid, sort, start, stop, callback) {
+groupsController.getGroupsFromSet = function (uid, sort, start, stop, callback) {
var set = 'groups:visible:name';
if (sort === 'count') {
set = 'groups:visible:memberCount';
@@ -32,7 +32,7 @@ groupsController.getGroupsFromSet = function(uid, sort, start, stop, callback) {
set = 'groups:visible:createtime';
}
- groups.getGroupsFromSet(set, uid, start, stop, function(err, groups) {
+ groups.getGroupsFromSet(set, uid, start, stop, function (err, groups) {
if (err) {
return callback(err);
}
@@ -45,13 +45,13 @@ groupsController.getGroupsFromSet = function(uid, sort, start, stop, callback) {
});
};
-groupsController.details = function(req, res, callback) {
+groupsController.details = function (req, res, callback) {
var groupName;
async.waterfall([
- function(next) {
+ function (next) {
groups.getGroupNameByGroupSlug(req.params.slug, next);
},
- function(_groupName, next) {
+ function (_groupName, next) {
groupName = _groupName;
if (!groupName) {
return callback();
@@ -71,7 +71,7 @@ groupsController.details = function(req, res, callback) {
async.parallel({
isMember: async.apply(groups.isMember, req.uid, groupName),
isInvited: async.apply(groups.isInvited, req.uid, groupName)
- }, function(err, checks) {
+ }, function (err, checks) {
if (err || checks.isMember || checks.isInvited) {
return next(err);
}
@@ -80,25 +80,25 @@ groupsController.details = function(req, res, callback) {
},
function (next) {
async.parallel({
- group: function(next) {
+ group: function (next) {
groups.get(groupName, {
uid: req.uid,
truncateUserList: true,
userListCount: 20
}, next);
},
- posts: function(next) {
+ posts: function (next) {
groups.getLatestMemberPosts(groupName, 10, req.uid, next);
},
- isAdmin:function(next) {
+ isAdmin:function (next) {
user.isAdministrator(req.uid, next);
},
- isGlobalMod: function(next) {
+ isGlobalMod: function (next) {
user.isGlobalModerator(req.uid, next);
}
}, next);
}
- ], function(err, results) {
+ ], function (err, results) {
if (err) {
return callback(err);
}
@@ -115,17 +115,17 @@ groupsController.details = function(req, res, callback) {
});
};
-groupsController.members = function(req, res, next) {
+groupsController.members = function (req, res, next) {
var groupName;
async.waterfall([
- function(next) {
+ function (next) {
groups.getGroupNameByGroupSlug(req.params.slug, next);
},
- function(_groupName, next) {
+ function (_groupName, next) {
groupName = _groupName;
user.getUsersFromSet('group:' + groupName + ':members', req.uid, 0, 49, next);
},
- ], function(err, users) {
+ ], function (err, users) {
if (err || !groupName) {
return next(err);
}
@@ -145,13 +145,13 @@ groupsController.members = function(req, res, next) {
});
};
-groupsController.uploadCover = function(req, res, next) {
+groupsController.uploadCover = function (req, res, next) {
var params = JSON.parse(req.body.params);
groups.updateCover(req.uid, {
file: req.files.files[0].path,
groupName: params.groupName
- }, function(err, image) {
+ }, function (err, image) {
if (err) {
return next(err);
}
diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js
index 2010fbc922..13a91aaa4c 100644
--- a/src/controllers/helpers.js
+++ b/src/controllers/helpers.js
@@ -11,12 +11,12 @@ var meta = require('../meta');
var helpers = {};
-helpers.notAllowed = function(req, res, error) {
+helpers.notAllowed = function (req, res, error) {
plugins.fireHook('filter:helpers.notAllowed', {
req: req,
res: res,
error: error
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return winston.error(err);
}
@@ -46,7 +46,7 @@ helpers.notAllowed = function(req, res, error) {
});
};
-helpers.redirect = function(res, url) {
+helpers.redirect = function (res, url) {
if (res.locals.isAPI) {
res.status(308).json(url);
} else {
@@ -54,13 +54,13 @@ helpers.redirect = function(res, url) {
}
};
-helpers.buildCategoryBreadcrumbs = function(cid, callback) {
+helpers.buildCategoryBreadcrumbs = function (cid, callback) {
var breadcrumbs = [];
- async.whilst(function() {
+ async.whilst(function () {
return parseInt(cid, 10);
- }, function(next) {
- categories.getCategoryFields(cid, ['name', 'slug', 'parentCid', 'disabled'], function(err, data) {
+ }, function (next) {
+ categories.getCategoryFields(cid, ['name', 'slug', 'parentCid', 'disabled'], function (err, data) {
if (err) {
return next(err);
}
@@ -75,7 +75,7 @@ helpers.buildCategoryBreadcrumbs = function(cid, callback) {
cid = data.parentCid;
next();
});
- }, function(err) {
+ }, function (err) {
if (err) {
return callback(err);
}
@@ -96,7 +96,7 @@ helpers.buildCategoryBreadcrumbs = function(cid, callback) {
});
};
-helpers.buildBreadcrumbs = function(crumbs) {
+helpers.buildBreadcrumbs = function (crumbs) {
var breadcrumbs = [
{
text: '[[global:home]]',
@@ -104,7 +104,7 @@ helpers.buildBreadcrumbs = function(crumbs) {
}
];
- crumbs.forEach(function(crumb) {
+ crumbs.forEach(function (crumb) {
if (crumb) {
if (crumb.url) {
crumb.url = nconf.get('relative_path') + crumb.url;
@@ -116,14 +116,14 @@ helpers.buildBreadcrumbs = function(crumbs) {
return breadcrumbs;
};
-helpers.buildTitle = function(pageTitle) {
+helpers.buildTitle = function (pageTitle) {
var titleLayout = meta.config.titleLayout || '{pageTitle} | {browserTitle}';
var browserTitle = validator.escape(String(meta.config.browserTitle || meta.config.title || 'NodeBB'));
pageTitle = pageTitle || '';
- var title = titleLayout.replace('{pageTitle}', function() {
+ var title = titleLayout.replace('{pageTitle}', function () {
return pageTitle;
- }).replace('{browserTitle}', function() {
+ }).replace('{browserTitle}', function () {
return browserTitle;
});
return title;
diff --git a/src/controllers/index.js b/src/controllers/index.js
index 103dbf70f3..98b6215dd8 100644
--- a/src/controllers/index.js
+++ b/src/controllers/index.js
@@ -31,10 +31,10 @@ var Controllers = {
};
-Controllers.home = function(req, res, next) {
+Controllers.home = function (req, res, next) {
var route = meta.config.homePageRoute || (meta.config.homePageCustom || '').replace(/^\/+/, '') || 'categories';
- user.getSettings(req.uid, function(err, settings) {
+ user.getSettings(req.uid, function (err, settings) {
if (err) {
return next(err);
}
@@ -71,9 +71,9 @@ Controllers.home = function(req, res, next) {
});
};
-Controllers.reset = function(req, res, next) {
+Controllers.reset = function (req, res, next) {
if (req.params.code) {
- user.reset.validate(req.params.code, function(err, valid) {
+ user.reset.validate(req.params.code, function (err, valid) {
if (err) {
return next(err);
}
@@ -98,7 +98,7 @@ Controllers.reset = function(req, res, next) {
};
-Controllers.login = function(req, res, next) {
+Controllers.login = function (req, res, next) {
var data = {};
var loginStrategies = require('../routes/authentication').getLoginStrategies();
var registrationType = meta.config.registrationType || 'normal';
@@ -131,7 +131,7 @@ Controllers.login = function(req, res, next) {
}
}
if (req.uid) {
- user.getUserFields(req.uid, ['username', 'email'], function(err, user) {
+ user.getUserFields(req.uid, ['username', 'email'], function (err, user) {
if (err) {
return next(err);
}
@@ -145,7 +145,7 @@ Controllers.login = function(req, res, next) {
};
-Controllers.register = function(req, res, next) {
+Controllers.register = function (req, res, next) {
var registrationType = meta.config.registrationType || 'normal';
if (registrationType === 'disabled') {
@@ -158,17 +158,17 @@ Controllers.register = function(req, res, next) {
}
async.waterfall([
- function(next) {
+ function (next) {
if (registrationType === 'invite-only' || registrationType === 'admin-invite-only') {
user.verifyInvitation(req.query, next);
} else {
next();
}
},
- function(next) {
+ function (next) {
plugins.fireHook('filter:parse.post', {postData: {content: meta.config.termsOfUse || ''}}, next);
}
- ], function(err, termsOfUse) {
+ ], function (err, termsOfUse) {
if (err) {
return next(err);
}
@@ -193,7 +193,7 @@ Controllers.register = function(req, res, next) {
});
};
-Controllers.registerInterstitial = function(req, res, next) {
+Controllers.registerInterstitial = function (req, res, next) {
if (!req.session.hasOwnProperty('registration')) {
return res.redirect(nconf.get('relative_path') + '/register');
}
@@ -201,7 +201,7 @@ Controllers.registerInterstitial = function(req, res, next) {
plugins.fireHook('filter:register.interstitial', {
userData: req.session.registration,
interstitials: []
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return next(err);
}
@@ -210,12 +210,12 @@ Controllers.registerInterstitial = function(req, res, next) {
return next();
}
- var renders = data.interstitials.map(function(interstitial) {
+ var renders = data.interstitials.map(function (interstitial) {
return async.apply(req.app.render.bind(req.app), interstitial.template, interstitial.data || {});
});
var errors = req.flash('error');
- async.parallel(renders, function(err, sections) {
+ async.parallel(renders, function (err, sections) {
if (err) {
return next(err);
}
@@ -229,13 +229,13 @@ Controllers.registerInterstitial = function(req, res, next) {
});
};
-Controllers.compose = function(req, res, next) {
+Controllers.compose = function (req, res, next) {
plugins.fireHook('filter:composer.build', {
req: req,
res: res,
next: next,
templateData: {}
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return next(err);
}
@@ -251,7 +251,7 @@ Controllers.compose = function(req, res, next) {
});
};
-Controllers.confirmEmail = function(req, res) {
+Controllers.confirmEmail = function (req, res) {
user.email.confirm(req.params.code, function (err) {
res.render('confirm', {
error: err ? err.message : '',
@@ -272,7 +272,7 @@ Controllers.robots = function (req, res) {
}
};
-Controllers.manifest = function(req, res) {
+Controllers.manifest = function (req, res) {
var manifest = {
name: meta.config.title || 'NodeBB',
start_url: nconf.get('relative_path') + '/',
@@ -318,7 +318,7 @@ Controllers.manifest = function(req, res) {
res.status(200).json(manifest);
};
-Controllers.outgoing = function(req, res) {
+Controllers.outgoing = function (req, res) {
var url = req.query.url || '';
var data = {
outgoing: validator.escape(String(url)),
@@ -333,18 +333,18 @@ Controllers.outgoing = function(req, res) {
}
};
-Controllers.termsOfUse = function(req, res, next) {
+Controllers.termsOfUse = function (req, res, next) {
if (!meta.config.termsOfUse) {
return next();
}
res.render('tos', {termsOfUse: meta.config.termsOfUse});
};
-Controllers.ping = function(req, res) {
+Controllers.ping = function (req, res) {
res.status(200).send(req.path === '/sping' ? 'healthy' : '200');
};
-Controllers.handle404 = function(req, res) {
+Controllers.handle404 = function (req, res) {
var relativePath = nconf.get('relative_path');
var isLanguage = new RegExp('^' + relativePath + '/language/.*/.*.json');
var isClientScript = new RegExp('^' + relativePath + '\\/src\\/.+\\.js');
@@ -378,7 +378,7 @@ Controllers.handle404 = function(req, res) {
return res.json({path: validator.escape(path.replace(/^\/api/, '')), title: '[[global:404.title]]'});
}
var middleware = require('../middleware');
- middleware.buildHeader(req, res, function() {
+ middleware.buildHeader(req, res, function () {
res.render('404', {path: validator.escape(path), title: '[[global:404.title]]'});
});
} else {
@@ -386,7 +386,7 @@ Controllers.handle404 = function(req, res) {
}
};
-Controllers.handleURIErrors = function(err, req, res, next) {
+Controllers.handleURIErrors = function (err, req, res, next) {
// Handle cases where malformed URIs are passed in
if (err instanceof URIError) {
var tidMatch = req.path.match(/^\/topic\/(\d+)\//);
@@ -404,7 +404,7 @@ Controllers.handleURIErrors = function(err, req, res, next) {
});
} else {
var middleware = require('../middleware');
- middleware.buildHeader(req, res, function() {
+ middleware.buildHeader(req, res, function () {
res.render('400', { error: validator.escape(String(err.message)) });
});
}
@@ -416,7 +416,7 @@ Controllers.handleURIErrors = function(err, req, res, next) {
}
};
-Controllers.handleErrors = function(err, req, res, next) {
+Controllers.handleErrors = function (err, req, res, next) {
switch (err.code) {
case 'EBADCSRFTOKEN':
winston.error(req.path + '\n', err.message);
@@ -438,7 +438,7 @@ Controllers.handleErrors = function(err, req, res, next) {
res.json({path: validator.escape(path), error: err.message});
} else {
var middleware = require('../middleware');
- middleware.buildHeader(req, res, function() {
+ middleware.buildHeader(req, res, function () {
res.render('500', { path: validator.escape(path), error: validator.escape(String(err.message)) });
});
}
diff --git a/src/controllers/popular.js b/src/controllers/popular.js
index 353fd9e33c..f38edd594c 100644
--- a/src/controllers/popular.js
+++ b/src/controllers/popular.js
@@ -17,7 +17,7 @@ var terms = {
monthly: 'month'
};
-popularController.get = function(req, res, next) {
+popularController.get = function (req, res, next) {
var term = terms[req.params.term];
@@ -39,7 +39,7 @@ popularController.get = function(req, res, next) {
}
}
- topics.getPopular(term, req.uid, meta.config.topicsPerList, function(err, topics) {
+ topics.getPopular(term, req.uid, meta.config.topicsPerList, function (err, topics) {
if (err) {
return next(err);
}
diff --git a/src/controllers/posts.js b/src/controllers/posts.js
index be96fa7e43..dae990e171 100644
--- a/src/controllers/posts.js
+++ b/src/controllers/posts.js
@@ -5,13 +5,13 @@ var helpers = require('./helpers');
var postsController = {};
-postsController.redirectToPost = function(req, res, callback) {
+postsController.redirectToPost = function (req, res, callback) {
var pid = parseInt(req.params.pid, 10);
if (!pid) {
return callback();
}
- posts.generatePostPath(pid, req.uid, function(err, path) {
+ posts.generatePostPath(pid, req.uid, function (err, path) {
if (err || !path) {
return callback(err);
}
diff --git a/src/controllers/recent.js b/src/controllers/recent.js
index 512a034512..72c0f45721 100644
--- a/src/controllers/recent.js
+++ b/src/controllers/recent.js
@@ -14,7 +14,7 @@ var pagination = require('../pagination');
var recentController = {};
-recentController.get = function(req, res, next) {
+recentController.get = function (req, res, next) {
var page = parseInt(req.query.page, 10) || 1;
var pageCount = 1;
var stop = 0;
@@ -24,7 +24,7 @@ recentController.get = function(req, res, next) {
async.waterfall([
function (next) {
async.parallel({
- settings: function(next) {
+ settings: function (next) {
user.getSettings(req.uid, next);
},
tids: function (next) {
@@ -46,7 +46,7 @@ recentController.get = function(req, res, next) {
topics.getTopicsByTids(tids, req.uid, next);
}
- ], function(err, topics) {
+ ], function (err, topics) {
if (err) {
return next(err);
}
diff --git a/src/controllers/search.js b/src/controllers/search.js
index 8c016c759c..5967cfc88e 100644
--- a/src/controllers/search.js
+++ b/src/controllers/search.js
@@ -13,7 +13,7 @@ var helpers = require('./helpers');
var searchController = {};
-searchController.search = function(req, res, next) {
+searchController.search = function (req, res, next) {
if (!plugins.hasListeners('filter:search.query')) {
return next();
}
@@ -47,7 +47,7 @@ searchController.search = function(req, res, next) {
async.parallel({
categories: async.apply(categories.buildForSelect, req.uid),
search: async.apply(search.search, data)
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return next(err);
}
diff --git a/src/controllers/sitemap.js b/src/controllers/sitemap.js
index 8ba41ede77..42b0ae1076 100644
--- a/src/controllers/sitemap.js
+++ b/src/controllers/sitemap.js
@@ -4,13 +4,13 @@ var sitemap = require('../sitemap');
var meta = require('../meta');
var sitemapController = {};
-sitemapController.render = function(req, res, next) {
- sitemap.render(function(err, tplData) {
+sitemapController.render = function (req, res, next) {
+ sitemap.render(function (err, tplData) {
if (err) {
return next(err);
}
- req.app.render('sitemap', tplData, function(err, xml) {
+ req.app.render('sitemap', tplData, function (err, xml) {
if (err) {
return next(err);
}
@@ -20,12 +20,12 @@ sitemapController.render = function(req, res, next) {
});
};
-sitemapController.getPages = function(req, res, next) {
+sitemapController.getPages = function (req, res, next) {
if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) {
return next();
}
- sitemap.getPages(function(err, xml) {
+ sitemap.getPages(function (err, xml) {
if (err) {
return next(err);
}
@@ -34,12 +34,12 @@ sitemapController.getPages = function(req, res, next) {
});
};
-sitemapController.getCategories = function(req, res, next) {
+sitemapController.getCategories = function (req, res, next) {
if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) {
return next();
}
- sitemap.getCategories(function(err, xml) {
+ sitemap.getCategories(function (err, xml) {
if (err) {
return next(err);
}
@@ -48,12 +48,12 @@ sitemapController.getCategories = function(req, res, next) {
});
};
-sitemapController.getTopicPage = function(req, res, next) {
+sitemapController.getTopicPage = function (req, res, next) {
if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) {
return next();
}
- sitemap.getTopicPage(parseInt(req.params[0], 10), function(err, xml) {
+ sitemap.getTopicPage(parseInt(req.params[0], 10), function (err, xml) {
if (err) {
return next(err);
} else if (!xml) {
diff --git a/src/controllers/tags.js b/src/controllers/tags.js
index ba1ec919b2..a433694220 100644
--- a/src/controllers/tags.js
+++ b/src/controllers/tags.js
@@ -12,7 +12,7 @@ var helpers = require('./helpers');
var tagsController = {};
-tagsController.getTag = function(req, res, next) {
+tagsController.getTag = function (req, res, next) {
var tag = validator.escape(String(req.params.tag));
var page = parseInt(req.query.page, 10) || 1;
@@ -34,10 +34,10 @@ tagsController.getTag = function(req, res, next) {
var stop = start + settings.topicsPerPage - 1;
templateData.nextStart = stop + 1;
async.parallel({
- topicCount: function(next) {
+ topicCount: function (next) {
topics.getTagTopicCount(tag, next);
},
- tids: function(next) {
+ tids: function (next) {
topics.getTagTids(req.params.tag, start, stop, next);
}
}, next);
@@ -49,7 +49,7 @@ tagsController.getTag = function(req, res, next) {
topicCount = results.topicCount;
topics.getTopics(results.tids, req.uid, next);
}
- ], function(err, topics) {
+ ], function (err, topics) {
if (err) {
return next(err);
}
@@ -77,8 +77,8 @@ tagsController.getTag = function(req, res, next) {
});
};
-tagsController.getTags = function(req, res, next) {
- topics.getTags(0, 99, function(err, tags) {
+tagsController.getTags = function (req, res, next) {
+ topics.getTags(0, 99, function (err, tags) {
if (err) {
return next(err);
}
diff --git a/src/controllers/topics.js b/src/controllers/topics.js
index 56b0763408..c739052937 100644
--- a/src/controllers/topics.js
+++ b/src/controllers/topics.js
@@ -17,7 +17,7 @@ var utils = require('../../public/src/utils');
var topicsController = {};
-topicsController.get = function(req, res, callback) {
+topicsController.get = function (req, res, callback) {
var tid = req.params.topic_id;
var currentPage = parseInt(req.query.page, 10) || 1;
var pageCount = 1;
@@ -31,13 +31,13 @@ topicsController.get = function(req, res, callback) {
async.waterfall([
function (next) {
async.parallel({
- privileges: function(next) {
+ privileges: function (next) {
privileges.topics.get(tid, req.uid, next);
},
- settings: function(next) {
+ settings: function (next) {
user.getSettings(req.uid, next);
},
- topic: function(next) {
+ topic: function (next) {
topics.getTopicData(tid, next);
}
}, next);
@@ -139,7 +139,7 @@ topicsController.get = function(req, res, callback) {
}
];
- helpers.buildCategoryBreadcrumbs(data.topicData.category.parentCid, function(err, crumbs) {
+ helpers.buildCategoryBreadcrumbs(data.topicData.category.parentCid, function (err, crumbs) {
if (err) {
return next(err);
}
@@ -268,7 +268,7 @@ topicsController.get = function(req, res, callback) {
data.scrollToMyPost = settings.scrollToMyPost;
data.rssFeedUrl = nconf.get('relative_path') + '/topic/' + data.tid + '.rss';
data.pagination = pagination.create(currentPage, pageCount, req.query);
- data.pagination.rel.forEach(function(rel) {
+ data.pagination.rel.forEach(function (rel) {
rel.href = nconf.get('url') + '/topic/' + data.slug + rel.href;
res.locals.linkTags.push(rel);
});
@@ -280,7 +280,7 @@ topicsController.get = function(req, res, callback) {
}
if (req.uid) {
- topics.markAsRead([tid], req.uid, function(err, markedRead) {
+ topics.markAsRead([tid], req.uid, function (err, markedRead) {
if (err) {
return callback(err);
}
@@ -295,7 +295,7 @@ topicsController.get = function(req, res, callback) {
});
};
-topicsController.teaser = function(req, res, next) {
+topicsController.teaser = function (req, res, next) {
var tid = req.params.topic_id;
if (!utils.isNumber(tid)) {
@@ -303,22 +303,22 @@ topicsController.teaser = function(req, res, next) {
}
async.waterfall([
- function(next) {
+ function (next) {
privileges.topics.can('read', tid, req.uid, next);
},
- function(canRead, next) {
+ function (canRead, next) {
if (!canRead) {
return res.status(403).json('[[error:no-privileges]]');
}
topics.getLatestUndeletedPid(tid, next);
},
- function(pid, next) {
+ function (pid, next) {
if (!pid) {
return res.status(404).json('not-found');
}
posts.getPostSummaryByPids([pid], req.uid, {stripTags: false}, next);
}
- ], function(err, posts) {
+ ], function (err, posts) {
if (err) {
return next(err);
}
@@ -330,7 +330,7 @@ topicsController.teaser = function(req, res, next) {
});
};
-topicsController.pagination = function(req, res, callback) {
+topicsController.pagination = function (req, res, callback) {
var tid = req.params.topic_id;
var currentPage = parseInt(req.query.page, 10) || 1;
@@ -355,7 +355,7 @@ topicsController.pagination = function(req, res, callback) {
var pageCount = Math.max(1, Math.ceil((postCount - 1) / results.settings.postsPerPage));
var paginationData = pagination.create(currentPage, pageCount);
- paginationData.rel.forEach(function(rel) {
+ paginationData.rel.forEach(function (rel) {
rel.href = nconf.get('url') + '/topic/' + results.topic.slug + rel.href;
});
diff --git a/src/controllers/unread.js b/src/controllers/unread.js
index 8860f541d9..1c5bafcbae 100644
--- a/src/controllers/unread.js
+++ b/src/controllers/unread.js
@@ -16,7 +16,7 @@ var unreadController = {};
var validFilter = {'': true, 'new': true, 'watched': true};
-unreadController.get = function(req, res, next) {
+unreadController.get = function (req, res, next) {
var page = parseInt(req.query.page, 10) || 1;
var results;
var cid = req.query.cid;
@@ -27,24 +27,24 @@ unreadController.get = function(req, res, next) {
}
var settings;
async.waterfall([
- function(next) {
+ function (next) {
async.parallel({
- watchedCategories: function(next) {
+ watchedCategories: function (next) {
getWatchedCategories(req.uid, cid, next);
},
- settings: function(next) {
+ settings: function (next) {
user.getSettings(req.uid, next);
}
}, next);
},
- function(_results, next) {
+ function (_results, next) {
results = _results;
settings = results.settings;
var start = Math.max(0, (page - 1) * settings.topicsPerPage);
var stop = start + settings.topicsPerPage - 1;
topics.getUnreadTopics(cid, req.uid, start, stop, filter, next);
}
- ], function(err, data) {
+ ], function (err, data) {
if (err) {
return next(err);
}
@@ -82,7 +82,7 @@ unreadController.get = function(req, res, next) {
filter: 'watched'
}];
- data.selectedFilter = data.filters.filter(function(filter) {
+ data.selectedFilter = data.filters.filter(function (filter) {
return filter && filter.selected;
})[0];
@@ -104,12 +104,12 @@ function getWatchedCategories(uid, selectedCid, callback) {
categories.getCategoriesFields(cids, ['cid', 'name', 'slug', 'icon', 'link', 'color', 'bgColor', 'parentCid'], next);
},
function (categoryData, next) {
- categoryData = categoryData.filter(function(category) {
+ categoryData = categoryData.filter(function (category) {
return category && !category.link;
});
var selectedCategory;
- categoryData.forEach(function(category) {
+ categoryData.forEach(function (category) {
category.selected = parseInt(category.cid, 10) === parseInt(selectedCid, 10);
if (category.selected) {
selectedCategory = category;
@@ -119,7 +119,7 @@ function getWatchedCategories(uid, selectedCid, callback) {
var categoriesData = [];
var tree = categories.getTree(categoryData, 0);
- tree.forEach(function(category) {
+ tree.forEach(function (category) {
recursive(category, categoriesData, '');
});
@@ -132,12 +132,12 @@ function recursive(category, categoriesData, level) {
category.level = level;
categoriesData.push(category);
- category.children.forEach(function(child) {
+ category.children.forEach(function (child) {
recursive(child, categoriesData, ' ' + level);
});
}
-unreadController.unreadTotal = function(req, res, next) {
+unreadController.unreadTotal = function (req, res, next) {
var filter = req.params.filter || '';
if (!validFilter[filter]) {
diff --git a/src/controllers/uploads.js b/src/controllers/uploads.js
index 468e211f9f..f2896ec8f6 100644
--- a/src/controllers/uploads.js
+++ b/src/controllers/uploads.js
@@ -16,7 +16,7 @@ var privileges = require('../privileges');
var uploadsController = {};
-uploadsController.upload = function(req, res, filesIterator) {
+uploadsController.upload = function (req, res, filesIterator) {
var files = req.files.files;
if (!Array.isArray(files)) {
@@ -27,7 +27,7 @@ uploadsController.upload = function(req, res, filesIterator) {
files = files[0];
}
- async.map(files, filesIterator, function(err, images) {
+ async.map(files, filesIterator, function (err, images) {
deleteTempFiles(files);
if (err) {
@@ -40,8 +40,8 @@ uploadsController.upload = function(req, res, filesIterator) {
});
};
-uploadsController.uploadPost = function(req, res, next) {
- uploadsController.upload(req, res, function(uploadedFile, next) {
+uploadsController.uploadPost = function (req, res, next) {
+ uploadsController.upload(req, res, function (uploadedFile, next) {
var isImage = uploadedFile.type.match(/image./);
if (isImage) {
uploadAsImage(req, uploadedFile, next);
@@ -53,10 +53,10 @@ uploadsController.uploadPost = function(req, res, next) {
function uploadAsImage(req, uploadedFile, callback) {
async.waterfall([
- function(next) {
+ function (next) {
privileges.categories.can('upload:post:image', req.body.cid, req.uid, next);
},
- function(canUpload, next) {
+ function (canUpload, next) {
if (!canUpload) {
return next(new Error('[[error:no-privileges]]'));
}
@@ -65,10 +65,10 @@ function uploadAsImage(req, uploadedFile, callback) {
}
file.isFileTypeAllowed(uploadedFile.path, next);
},
- function(next) {
+ function (next) {
uploadFile(req.uid, uploadedFile, next);
},
- function(fileObj, next) {
+ function (fileObj, next) {
if (parseInt(meta.config.maximumImageWidth, 10) === 0) {
return next(null, fileObj);
}
@@ -80,10 +80,10 @@ function uploadAsImage(req, uploadedFile, callback) {
function uploadAsFile(req, uploadedFile, callback) {
async.waterfall([
- function(next) {
+ function (next) {
privileges.categories.can('upload:post:file', req.body.cid, req.uid, next);
},
- function(canUpload, next) {
+ function (canUpload, next) {
if (!canUpload) {
return next(new Error('[[error:no-privileges]]'));
}
@@ -97,7 +97,7 @@ function uploadAsFile(req, uploadedFile, callback) {
function resizeImage(fileObj, callback) {
async.waterfall([
- function(next) {
+ function (next) {
image.size(fileObj.path, next);
},
function (imageData, next) {
@@ -130,14 +130,14 @@ function resizeImage(fileObj, callback) {
], callback);
}
-uploadsController.uploadThumb = function(req, res, next) {
+uploadsController.uploadThumb = function (req, res, next) {
if (parseInt(meta.config.allowTopicsThumbnail, 10) !== 1) {
deleteTempFiles(req.files.files);
return next(new Error('[[error:topic-thumbnails-are-disabled]]'));
}
- uploadsController.upload(req, res, function(uploadedFile, next) {
- file.isFileTypeAllowed(uploadedFile.path, function(err) {
+ uploadsController.upload(req, res, function (uploadedFile, next) {
+ file.isFileTypeAllowed(uploadedFile.path, function (err) {
if (err) {
return next(err);
}
@@ -152,7 +152,7 @@ uploadsController.uploadThumb = function(req, res, next) {
extension: path.extname(uploadedFile.name),
width: size,
height: size
- }, function(err) {
+ }, function (err) {
if (err) {
return next(err);
}
@@ -167,7 +167,7 @@ uploadsController.uploadThumb = function(req, res, next) {
}, next);
};
-uploadsController.uploadGroupCover = function(uid, uploadedFile, callback) {
+uploadsController.uploadGroupCover = function (uid, uploadedFile, callback) {
if (plugins.hasListeners('filter:uploadImage')) {
return plugins.fireHook('filter:uploadImage', {image: uploadedFile, uid: uid}, callback);
}
@@ -176,7 +176,7 @@ uploadsController.uploadGroupCover = function(uid, uploadedFile, callback) {
return plugins.fireHook('filter:uploadFile', {file: uploadedFile, uid: uid}, callback);
}
- file.isFileTypeAllowed(uploadedFile.path, function(err) {
+ file.isFileTypeAllowed(uploadedFile.path, function (err) {
if (err) {
return callback(err);
}
@@ -221,7 +221,7 @@ function saveFileToLocal(uploadedFile, callback) {
filename = Date.now() + '-' + validator.escape(filename.replace(extension, '')).substr(0, 255) + extension;
- file.saveFileToLocal(filename, 'files', uploadedFile.path, function(err, upload) {
+ file.saveFileToLocal(filename, 'files', uploadedFile.path, function (err, upload) {
if (err) {
return callback(err);
}
@@ -235,8 +235,8 @@ function saveFileToLocal(uploadedFile, callback) {
}
function deleteTempFiles(files) {
- async.each(files, function(file, next) {
- fs.unlink(file.path, function(err) {
+ async.each(files, function (file, next) {
+ fs.unlink(file.path, function (err) {
if (err) {
winston.error(err);
}
diff --git a/src/controllers/users.js b/src/controllers/users.js
index 4f503bb6a3..baf18a5b64 100644
--- a/src/controllers/users.js
+++ b/src/controllers/users.js
@@ -12,7 +12,7 @@ var helpers = require('./helpers');
var usersController = {};
-usersController.index = function(req, res, next) {
+usersController.index = function (req, res, next) {
var section = req.query.section || 'joindate';
var sectionToController = {
joindate: usersController.getUsersSortedByJoinDate,
@@ -32,9 +32,9 @@ usersController.index = function(req, res, next) {
}
};
-usersController.search = function(req, res, next) {
+usersController.search = function (req, res, next) {
async.parallel({
- search: function(next) {
+ search: function (next) {
user.search({
query: req.query.term,
searchBy: req.query.searchBy || 'username',
@@ -45,10 +45,10 @@ usersController.search = function(req, res, next) {
flaggedOnly: req.query.flaggedOnly === 'true'
}, next);
},
- isAdminOrGlobalMod: function(next) {
+ isAdminOrGlobalMod: function (next) {
user.isAdminOrGlobalMod(req.uid, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return next(err);
}
@@ -62,22 +62,22 @@ usersController.search = function(req, res, next) {
});
};
-usersController.getOnlineUsers = function(req, res, next) {
+usersController.getOnlineUsers = function (req, res, next) {
async.parallel({
- users: function(next) {
+ users: function (next) {
usersController.getUsers('users:online', req.uid, req.query, next);
},
- guests: function(next) {
+ guests: function (next) {
require('../socket.io/admin/rooms').getTotalGuestCount(next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return next(err);
}
var userData = results.users;
var hiddenCount = 0;
if (!userData.isAdminOrGlobalMod) {
- userData.users = userData.users.filter(function(user) {
+ userData.users = userData.users.filter(function (user) {
if (user && user.status === 'offline') {
hiddenCount ++;
}
@@ -91,23 +91,23 @@ usersController.getOnlineUsers = function(req, res, next) {
});
};
-usersController.getUsersSortedByPosts = function(req, res, next) {
+usersController.getUsersSortedByPosts = function (req, res, next) {
usersController.renderUsersPage('users:postcount', req, res, next);
};
-usersController.getUsersSortedByReputation = function(req, res, next) {
+usersController.getUsersSortedByReputation = function (req, res, next) {
if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
return next();
}
usersController.renderUsersPage('users:reputation', req, res, next);
};
-usersController.getUsersSortedByJoinDate = function(req, res, next) {
+usersController.getUsersSortedByJoinDate = function (req, res, next) {
usersController.renderUsersPage('users:joindate', req, res, next);
};
-usersController.getBannedUsers = function(req, res, next) {
- usersController.getUsers('users:banned', req.uid, req.query, function(err, userData) {
+usersController.getBannedUsers = function (req, res, next) {
+ usersController.getUsers('users:banned', req.uid, req.query, function (err, userData) {
if (err) {
return next(err);
}
@@ -120,8 +120,8 @@ usersController.getBannedUsers = function(req, res, next) {
});
};
-usersController.getFlaggedUsers = function(req, res, next) {
- usersController.getUsers('users:flags', req.uid, req.query, function(err, userData) {
+usersController.getFlaggedUsers = function (req, res, next) {
+ usersController.getUsers('users:flags', req.uid, req.query, function (err, userData) {
if (err) {
return next(err);
}
@@ -134,8 +134,8 @@ usersController.getFlaggedUsers = function(req, res, next) {
});
};
-usersController.renderUsersPage = function(set, req, res, next) {
- usersController.getUsers(set, req.uid, req.query, function(err, userData) {
+usersController.renderUsersPage = function (set, req, res, next) {
+ usersController.getUsers(set, req.uid, req.query, function (err, userData) {
if (err) {
return next(err);
}
@@ -144,7 +144,7 @@ usersController.renderUsersPage = function(set, req, res, next) {
});
};
-usersController.getUsers = function(set, uid, query, callback) {
+usersController.getUsers = function (set, uid, query, callback) {
var setToData = {
'users:postcount': {title: '[[pages:users/sort-posts]]', crumb: '[[users:top_posters]]'},
'users:reputation': {title: '[[pages:users/sort-reputation]]', crumb: '[[users:most_reputation]]'},
@@ -170,13 +170,13 @@ usersController.getUsers = function(set, uid, query, callback) {
var stop = start + resultsPerPage - 1;
async.parallel({
- isAdminOrGlobalMod: function(next) {
+ isAdminOrGlobalMod: function (next) {
user.isAdminOrGlobalMod(uid, next);
},
- usersData: function(next) {
+ usersData: function (next) {
usersController.getUsersAndCount(set, uid, start, stop, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -195,12 +195,12 @@ usersController.getUsers = function(set, uid, query, callback) {
});
};
-usersController.getUsersAndCount = function(set, uid, start, stop, callback) {
+usersController.getUsersAndCount = function (set, uid, start, stop, callback) {
async.parallel({
- users: function(next) {
+ users: function (next) {
user.getUsersFromSet(set, uid, start, stop, next);
},
- count: function(next) {
+ count: function (next) {
if (set === 'users:online') {
var now = Date.now();
db.sortedSetCount('users:online', now - 300000, '+inf', next);
@@ -212,11 +212,11 @@ usersController.getUsersAndCount = function(set, uid, start, stop, callback) {
db.getObjectField('global', 'userCount', next);
}
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
- results.users = results.users.filter(function(user) {
+ results.users = results.users.filter(function (user) {
return user && parseInt(user.uid, 10);
});
@@ -232,7 +232,7 @@ function render(req, res, data, next) {
data.adminInviteOnly = registrationType === 'admin-invite-only';
data['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
- user.getInvitesNumber(req.uid, function(err, numInvites) {
+ user.getInvitesNumber(req.uid, function (err, numInvites) {
if (err) {
return next(err);
}
diff --git a/src/coverPhoto.js b/src/coverPhoto.js
index d699ace785..699e4ee374 100644
--- a/src/coverPhoto.js
+++ b/src/coverPhoto.js
@@ -5,11 +5,11 @@ var meta = require('./meta');
var nconf = require('nconf');
-coverPhoto.getDefaultGroupCover = function(groupName) {
+coverPhoto.getDefaultGroupCover = function (groupName) {
return getCover('groups', groupName);
};
-coverPhoto.getDefaultProfileCover = function(uid) {
+coverPhoto.getDefaultProfileCover = function (uid) {
return getCover('profile', parseInt(uid, 10));
};
diff --git a/src/database/mongo.js b/src/database/mongo.js
index 1746bbb19f..92bfd264dc 100644
--- a/src/database/mongo.js
+++ b/src/database/mongo.js
@@ -1,7 +1,7 @@
'use strict';
-(function(module) {
+(function (module) {
var winston = require('winston'),
async = require('async'),
@@ -34,7 +34,7 @@
description: 'Password of your MongoDB database',
hidden: true,
default: nconf.get('mongo:password') || '',
- before: function(value) { value = value || nconf.get('mongo:password') || ''; return value; }
+ before: function (value) { value = value || nconf.get('mongo:password') || ''; return value; }
},
{
name: "mongo:database",
@@ -46,8 +46,8 @@
module.helpers = module.helpers || {};
module.helpers.mongo = require('./mongo/helpers');
- module.init = function(callback) {
- callback = callback || function() {};
+ module.init = function (callback) {
+ callback = callback || function () {};
try {
var sessionStore;
mongoClient = require('mongodb').MongoClient;
@@ -96,7 +96,7 @@
connOptions = _.deepExtend((nconf.get('mongo:options') || {}), connOptions);
- mongoClient.connect(connString, connOptions, function(err, _db) {
+ mongoClient.connect(connString, connOptions, function (err, _db) {
if (err) {
winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message);
return callback(err);
@@ -147,7 +147,7 @@
async.apply(createIndex, 'objects', {_key: 1, score: -1}, {background: true}),
async.apply(createIndex, 'objects', {_key: 1, value: -1}, {background: true, unique: true, sparse: true}),
async.apply(createIndex, 'objects', {expireAt: 1}, {expireAfterSeconds: 0, background: true})
- ], function(err) {
+ ], function (err) {
if (err) {
winston.error('Error creating index ' + err.message);
}
@@ -161,7 +161,7 @@
});
};
- module.checkCompatibility = function(callback) {
+ module.checkCompatibility = function (callback) {
var mongoPkg = require.main.require('./node_modules/mongodb/package.json'),
err = semver.lt(mongoPkg.version, '2.0.0') ? new Error('The `mongodb` package is out-of-date, please run `./nodebb setup` again.') : null;
@@ -171,32 +171,32 @@
callback(err);
};
- module.info = function(db, callback) {
+ module.info = function (db, callback) {
async.parallel({
- serverStatus: function(next) {
+ serverStatus: function (next) {
db.command({'serverStatus': 1}, next);
},
- stats: function(next) {
+ stats: function (next) {
db.command({'dbStats': 1}, next);
},
- listCollections: function(next) {
- db.listCollections().toArray(function(err, items) {
+ listCollections: function (next) {
+ db.listCollections().toArray(function (err, items) {
if (err) {
return next(err);
}
- async.map(items, function(collection, next) {
+ async.map(items, function (collection, next) {
db.collection(collection.name).stats(next);
}, next);
});
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
var stats = results.stats;
var scale = 1024 * 1024;
- results.listCollections = results.listCollections.map(function(collectionInfo) {
+ results.listCollections = results.listCollections.map(function (collectionInfo) {
return {
name: collectionInfo.ns,
count: collectionInfo.count,
@@ -228,7 +228,7 @@
});
};
- module.close = function() {
+ module.close = function () {
db.close();
};
diff --git a/src/database/mongo/hash.js b/src/database/mongo/hash.js
index cd2ecda54e..7baf70b401 100644
--- a/src/database/mongo/hash.js
+++ b/src/database/mongo/hash.js
@@ -1,20 +1,20 @@
"use strict";
-module.exports = function(db, module) {
+module.exports = function (db, module) {
var helpers = module.helpers.mongo;
- module.setObject = function(key, data, callback) {
+ module.setObject = function (key, data, callback) {
callback = callback || helpers.noop;
if (!key) {
return callback();
}
- db.collection('objects').update({_key: key}, {$set: data}, {upsert: true, w: 1}, function(err) {
+ db.collection('objects').update({_key: key}, {$set: data}, {upsert: true, w: 1}, function (err) {
callback(err);
});
};
- module.setObjectField = function(key, field, value, callback) {
+ module.setObjectField = function (key, field, value, callback) {
callback = callback || helpers.noop;
if (!field) {
return callback();
@@ -25,18 +25,18 @@ module.exports = function(db, module) {
module.setObject(key, data, callback);
};
- module.getObject = function(key, callback) {
+ module.getObject = function (key, callback) {
if (!key) {
return callback();
}
db.collection('objects').findOne({_key: key}, {_id: 0, _key: 0}, callback);
};
- module.getObjects = function(keys, callback) {
+ module.getObjects = function (keys, callback) {
if (!Array.isArray(keys) || !keys.length) {
return callback(null, []);
}
- db.collection('objects').find({_key: {$in: keys}}, {_id: 0}).toArray(function(err, data) {
+ db.collection('objects').find({_key: {$in: keys}}, {_id: 0}).toArray(function (err, data) {
if (err) {
return callback(err);
}
@@ -52,7 +52,7 @@ module.exports = function(db, module) {
});
};
- module.getObjectField = function(key, field, callback) {
+ module.getObjectField = function (key, field, callback) {
if (!key) {
return callback();
}
@@ -61,7 +61,7 @@ module.exports = function(db, module) {
_id: 0
};
_fields[field] = 1;
- db.collection('objects').findOne({_key: key}, {fields: _fields}, function(err, item) {
+ db.collection('objects').findOne({_key: key}, {fields: _fields}, function (err, item) {
if (err || !item) {
return callback(err, null);
}
@@ -70,7 +70,7 @@ module.exports = function(db, module) {
});
};
- module.getObjectFields = function(key, fields, callback) {
+ module.getObjectFields = function (key, fields, callback) {
if (!key) {
return callback();
}
@@ -82,7 +82,7 @@ module.exports = function(db, module) {
fields[i] = helpers.fieldToString(fields[i]);
_fields[fields[i]] = 1;
}
- db.collection('objects').findOne({_key: key}, {fields: _fields}, function(err, item) {
+ db.collection('objects').findOne({_key: key}, {fields: _fields}, function (err, item) {
if (err) {
return callback(err);
}
@@ -95,7 +95,7 @@ module.exports = function(db, module) {
});
};
- module.getObjectsFields = function(keys, fields, callback) {
+ module.getObjectsFields = function (keys, fields, callback) {
if (!Array.isArray(keys) || !keys.length) {
return callback(null, []);
}
@@ -109,7 +109,7 @@ module.exports = function(db, module) {
_fields[fields[i]] = 1;
}
- db.collection('objects').find({_key: {$in: keys}}, {fields: _fields}).toArray(function(err, items) {
+ db.collection('objects').find({_key: {$in: keys}}, {fields: _fields}).toArray(function (err, items) {
if (err) {
return callback(err);
}
@@ -137,14 +137,14 @@ module.exports = function(db, module) {
});
};
- module.getObjectKeys = function(key, callback) {
- module.getObject(key, function(err, data) {
+ module.getObjectKeys = function (key, callback) {
+ module.getObject(key, function (err, data) {
callback(err, data ? Object.keys(data) : []);
});
};
- module.getObjectValues = function(key, callback) {
- module.getObject(key, function(err, data) {
+ module.getObjectValues = function (key, callback) {
+ module.getObject(key, function (err, data) {
if(err) {
return callback(err);
}
@@ -159,36 +159,36 @@ module.exports = function(db, module) {
});
};
- module.isObjectField = function(key, field, callback) {
+ module.isObjectField = function (key, field, callback) {
if (!key) {
return callback();
}
var data = {};
field = helpers.fieldToString(field);
data[field] = '';
- db.collection('objects').findOne({_key: key}, {fields: data}, function(err, item) {
+ db.collection('objects').findOne({_key: key}, {fields: data}, function (err, item) {
callback(err, !!item && item[field] !== undefined && item[field] !== null);
});
};
- module.isObjectFields = function(key, fields, callback) {
+ module.isObjectFields = function (key, fields, callback) {
if (!key) {
return callback();
}
var data = {};
- fields.forEach(function(field) {
+ fields.forEach(function (field) {
field = helpers.fieldToString(field);
data[field] = '';
});
- db.collection('objects').findOne({_key: key}, {fields: data}, function(err, item) {
+ db.collection('objects').findOne({_key: key}, {fields: data}, function (err, item) {
if (err) {
return callback(err);
}
var results = [];
- fields.forEach(function(field, index) {
+ fields.forEach(function (field, index) {
results[index] = !!item && item[field] !== undefined && item[field] !== null;
});
@@ -196,11 +196,11 @@ module.exports = function(db, module) {
});
};
- module.deleteObjectField = function(key, field, callback) {
+ module.deleteObjectField = function (key, field, callback) {
module.deleteObjectFields(key, [field], callback);
};
- module.deleteObjectFields = function(key, fields, callback) {
+ module.deleteObjectFields = function (key, fields, callback) {
callback = callback || helpers.noop;
if (!key || !Array.isArray(fields) || !fields.length) {
return callback();
@@ -211,25 +211,25 @@ module.exports = function(db, module) {
}
var data = {};
- fields.forEach(function(field) {
+ fields.forEach(function (field) {
field = helpers.fieldToString(field);
data[field] = '';
});
- db.collection('objects').update({_key: key}, {$unset : data}, function(err) {
+ db.collection('objects').update({_key: key}, {$unset : data}, function (err) {
callback(err);
});
};
- module.incrObjectField = function(key, field, callback) {
+ module.incrObjectField = function (key, field, callback) {
module.incrObjectFieldBy(key, field, 1, callback);
};
- module.decrObjectField = function(key, field, callback) {
+ module.decrObjectField = function (key, field, callback) {
module.incrObjectFieldBy(key, field, -1, callback);
};
- module.incrObjectFieldBy = function(key, field, value, callback) {
+ module.incrObjectFieldBy = function (key, field, value, callback) {
callback = callback || helpers.noop;
value = parseInt(value, 10);
if (!key || isNaN(value)) {
@@ -240,7 +240,7 @@ module.exports = function(db, module) {
field = helpers.fieldToString(field);
data[field] = value;
- db.collection('objects').findAndModify({_key: key}, {}, {$inc: data}, {new: true, upsert: true}, function(err, result) {
+ db.collection('objects').findAndModify({_key: key}, {}, {$inc: data}, {new: true, upsert: true}, function (err, result) {
callback(err, result && result.value ? result.value[field] : null);
});
};
diff --git a/src/database/mongo/helpers.js b/src/database/mongo/helpers.js
index 47fd22c7ea..0985e62617 100644
--- a/src/database/mongo/helpers.js
+++ b/src/database/mongo/helpers.js
@@ -2,7 +2,7 @@
var helpers = {};
-helpers.toMap = function(data) {
+helpers.toMap = function (data) {
var map = {};
for (var i = 0; i < data.length; ++i) {
map[data[i]._key] = data[i];
@@ -11,7 +11,7 @@ helpers.toMap = function(data) {
return map;
};
-helpers.fieldToString = function(field) {
+helpers.fieldToString = function (field) {
if(field === null || field === undefined) {
return field;
}
@@ -24,7 +24,7 @@ helpers.fieldToString = function(field) {
return field;
};
-helpers.valueToString = function(value) {
+helpers.valueToString = function (value) {
if(value === null || value === undefined) {
return value;
}
@@ -32,6 +32,6 @@ helpers.valueToString = function(value) {
return value.toString();
};
-helpers.noop = function() {};
+helpers.noop = function () {};
module.exports = helpers;
\ No newline at end of file
diff --git a/src/database/mongo/list.js b/src/database/mongo/list.js
index 40e294a488..c4b4ffbb6c 100644
--- a/src/database/mongo/list.js
+++ b/src/database/mongo/list.js
@@ -1,9 +1,9 @@
"use strict";
-module.exports = function(db, module) {
+module.exports = function (db, module) {
var helpers = module.helpers.mongo;
- module.listPrepend = function(key, value, callback) {
+ module.listPrepend = function (key, value, callback) {
callback = callback || helpers.noop;
if (!key) {
@@ -12,13 +12,13 @@ module.exports = function(db, module) {
value = helpers.valueToString(value);
- module.isObjectField(key, 'array', function(err, exists) {
+ module.isObjectField(key, 'array', function (err, exists) {
if (err) {
return callback(err);
}
if (exists) {
- db.collection('objects').update({_key:key}, {$push: {array: {$each: [value], $position: 0}}}, {upsert:true, w:1 }, function(err, res) {
+ db.collection('objects').update({_key:key}, {$push: {array: {$each: [value], $position: 0}}}, {upsert:true, w:1 }, function (err, res) {
callback(err);
});
} else {
@@ -27,67 +27,67 @@ module.exports = function(db, module) {
});
};
- module.listAppend = function(key, value, callback) {
+ module.listAppend = function (key, value, callback) {
callback = callback || helpers.noop;
if (!key) {
return callback();
}
value = helpers.valueToString(value);
- db.collection('objects').update({ _key: key }, { $push: { array: value } }, {upsert:true, w:1}, function(err, res) {
+ db.collection('objects').update({ _key: key }, { $push: { array: value } }, {upsert:true, w:1}, function (err, res) {
callback(err);
});
};
- module.listRemoveLast = function(key, callback) {
+ module.listRemoveLast = function (key, callback) {
callback = callback || helpers.noop;
if (!key) {
return callback();
}
- module.getListRange(key, -1, -1, function(err, value) {
+ module.getListRange(key, -1, -1, function (err, value) {
if (err) {
return callback(err);
}
- db.collection('objects').update({_key: key }, { $pop: { array: 1 } }, function(err, result) {
+ db.collection('objects').update({_key: key }, { $pop: { array: 1 } }, function (err, result) {
callback(err, (value && value.length) ? value[0] : null);
});
});
};
- module.listRemoveAll = function(key, value, callback) {
+ module.listRemoveAll = function (key, value, callback) {
callback = callback || helpers.noop;
if (!key) {
return callback();
}
value = helpers.valueToString(value);
- db.collection('objects').update({_key: key }, { $pull: { array: value } }, function(err, res) {
+ db.collection('objects').update({_key: key }, { $pull: { array: value } }, function (err, res) {
callback(err);
});
};
- module.listTrim = function(key, start, stop, callback) {
+ module.listTrim = function (key, start, stop, callback) {
callback = callback || helpers.noop;
if (!key) {
return callback();
}
- module.getListRange(key, start, stop, function(err, value) {
+ module.getListRange(key, start, stop, function (err, value) {
if (err) {
return callback(err);
}
- db.collection('objects').update({_key: key}, {$set: {array: value}}, function(err, res) {
+ db.collection('objects').update({_key: key}, {$set: {array: value}}, function (err, res) {
callback(err);
});
});
};
- module.getListRange = function(key, start, stop, callback) {
+ module.getListRange = function (key, start, stop, callback) {
if (!key) {
return callback();
}
- db.collection('objects').findOne({_key:key}, { array: 1}, function(err, data) {
+ db.collection('objects').findOne({_key:key}, { array: 1}, function (err, data) {
if(err || !(data && data.array)) {
return callback(err, []);
}
diff --git a/src/database/mongo/main.js b/src/database/mongo/main.js
index 777565df06..ea76836065 100644
--- a/src/database/mongo/main.js
+++ b/src/database/mongo/main.js
@@ -2,51 +2,51 @@
var winston = require('winston');
-module.exports = function(db, module) {
+module.exports = function (db, module) {
var helpers = module.helpers.mongo;
- module.flushdb = function(callback) {
+ module.flushdb = function (callback) {
callback = callback || helpers.noop;
db.dropDatabase(callback);
};
- module.exists = function(key, callback) {
+ module.exists = function (key, callback) {
if (!key) {
return callback();
}
- db.collection('objects').findOne({_key: key}, function(err, item) {
+ db.collection('objects').findOne({_key: key}, function (err, item) {
callback(err, item !== undefined && item !== null);
});
};
- module.delete = function(key, callback) {
+ module.delete = function (key, callback) {
callback = callback || helpers.noop;
if (!key) {
return callback();
}
- db.collection('objects').remove({_key: key}, function(err, res) {
+ db.collection('objects').remove({_key: key}, function (err, res) {
callback(err);
});
};
- module.deleteAll = function(keys, callback) {
+ module.deleteAll = function (keys, callback) {
callback = callback || helpers.noop;
if (!Array.isArray(keys) || !keys.length) {
return callback();
}
- db.collection('objects').remove({_key: {$in: keys}}, function(err, res) {
+ db.collection('objects').remove({_key: {$in: keys}}, function (err, res) {
callback(err);
});
};
- module.get = function(key, callback) {
+ module.get = function (key, callback) {
if (!key) {
return callback();
}
module.getObjectField(key, 'value', callback);
};
- module.set = function(key, value, callback) {
+ module.set = function (key, value, callback) {
callback = callback || helpers.noop;
if (!key) {
return callback();
@@ -55,36 +55,36 @@ module.exports = function(db, module) {
module.setObject(key, data, callback);
};
- module.increment = function(key, callback) {
+ module.increment = function (key, callback) {
callback = callback || helpers.noop;
if (!key) {
return callback();
}
- db.collection('objects').findAndModify({_key: key}, {}, {$inc: {value: 1}}, {new: true, upsert: true}, function(err, result) {
+ db.collection('objects').findAndModify({_key: key}, {}, {$inc: {value: 1}}, {new: true, upsert: true}, function (err, result) {
callback(err, result && result.value ? result.value.value : null);
});
};
- module.rename = function(oldKey, newKey, callback) {
+ module.rename = function (oldKey, newKey, callback) {
callback = callback || helpers.noop;
- db.collection('objects').update({_key: oldKey}, {$set:{_key: newKey}}, {multi: true}, function(err, res) {
+ db.collection('objects').update({_key: oldKey}, {$set:{_key: newKey}}, {multi: true}, function (err, res) {
callback(err);
});
};
- module.expire = function(key, seconds, callback) {
+ module.expire = function (key, seconds, callback) {
module.expireAt(key, Math.round(Date.now() / 1000) + seconds, callback);
};
- module.expireAt = function(key, timestamp, callback) {
+ module.expireAt = function (key, timestamp, callback) {
module.setObjectField(key, 'expireAt', new Date(timestamp * 1000), callback);
};
- module.pexpire = function(key, ms, callback) {
+ module.pexpire = function (key, ms, callback) {
module.pexpireAt(key, Date.now() + parseInt(ms, 10), callback);
};
- module.pexpireAt = function(key, timestamp, callback) {
+ module.pexpireAt = function (key, timestamp, callback) {
module.setObjectField(key, 'expireAt', new Date(timestamp), callback);
};
};
\ No newline at end of file
diff --git a/src/database/mongo/sets.js b/src/database/mongo/sets.js
index b72a13ff20..0a035a3398 100644
--- a/src/database/mongo/sets.js
+++ b/src/database/mongo/sets.js
@@ -1,15 +1,15 @@
"use strict";
-module.exports = function(db, module) {
+module.exports = function (db, module) {
var helpers = module.helpers.mongo;
- module.setAdd = function(key, value, callback) {
+ module.setAdd = function (key, value, callback) {
callback = callback || helpers.noop;
if(!Array.isArray(value)) {
value = [value];
}
- value.forEach(function(element, index, array) {
+ value.forEach(function (element, index, array) {
array[index] = helpers.valueToString(element);
});
@@ -24,12 +24,12 @@ module.exports = function(db, module) {
}, {
upsert: true,
w: 1
- }, function(err, res) {
+ }, function (err, res) {
callback(err);
});
};
- module.setsAdd = function(keys, value, callback) {
+ module.setsAdd = function (keys, value, callback) {
callback = callback || helpers.noop;
if (!Array.isArray(keys) || !keys.length) {
@@ -40,7 +40,7 @@ module.exports = function(db, module) {
value = [value];
}
- value.forEach(function(element, index, array) {
+ value.forEach(function (element, index, array) {
array[index] = helpers.valueToString(element);
});
@@ -54,27 +54,27 @@ module.exports = function(db, module) {
}});
}
- bulk.execute(function(err, res) {
+ bulk.execute(function (err, res) {
callback(err);
});
};
- module.setRemove = function(key, value, callback) {
+ module.setRemove = function (key, value, callback) {
callback = callback || helpers.noop;
if(!Array.isArray(value)) {
value = [value];
}
- value.forEach(function(element, index, array) {
+ value.forEach(function (element, index, array) {
array[index] = helpers.valueToString(element);
});
- db.collection('objects').update({_key: key}, {$pullAll: {members: value}}, function(err, res) {
+ db.collection('objects').update({_key: key}, {$pullAll: {members: value}}, function (err, res) {
callback(err);
});
};
- module.setsRemove = function(keys, value, callback) {
+ module.setsRemove = function (keys, value, callback) {
callback = callback || helpers.noop;
if (!Array.isArray(keys) || !keys.length) {
return callback();
@@ -89,23 +89,23 @@ module.exports = function(db, module) {
}});
}
- bulk.execute(function(err, res) {
+ bulk.execute(function (err, res) {
callback(err);
});
};
- module.isSetMember = function(key, value, callback) {
+ module.isSetMember = function (key, value, callback) {
if (!key) {
return callback(null, false);
}
value = helpers.valueToString(value);
- db.collection('objects').findOne({_key: key, members: value}, {_id: 0, members: 0},function(err, item) {
+ db.collection('objects').findOne({_key: key, members: value}, {_id: 0, members: 0},function (err, item) {
callback(err, item !== null && item !== undefined);
});
};
- module.isSetMembers = function(key, values, callback) {
+ module.isSetMembers = function (key, values, callback) {
if (!key || !Array.isArray(values) || !values.length) {
return callback(null, []);
}
@@ -114,12 +114,12 @@ module.exports = function(db, module) {
values[i] = helpers.valueToString(values[i]);
}
- db.collection('objects').findOne({_key: key}, {_id: 0, _key: 0}, function(err, items) {
+ db.collection('objects').findOne({_key: key}, {_id: 0, _key: 0}, function (err, items) {
if (err) {
return callback(err);
}
- values = values.map(function(value) {
+ values = values.map(function (value) {
return !!(items && Array.isArray(items.members) && items.members.indexOf(value) !== -1);
});
@@ -127,22 +127,22 @@ module.exports = function(db, module) {
});
};
- module.isMemberOfSets = function(sets, value, callback) {
+ module.isMemberOfSets = function (sets, value, callback) {
if (!Array.isArray(sets) || !sets.length) {
return callback(null, []);
}
value = helpers.valueToString(value);
- db.collection('objects').find({_key: {$in : sets}, members: value}, {_id:0, members: 0}).toArray(function(err, result) {
+ db.collection('objects').find({_key: {$in : sets}, members: value}, {_id:0, members: 0}).toArray(function (err, result) {
if (err) {
return callback(err);
}
- result = result.map(function(item) {
+ result = result.map(function (item) {
return item._key;
});
- result = sets.map(function(set) {
+ result = sets.map(function (set) {
return result.indexOf(set) !== -1;
});
@@ -150,26 +150,26 @@ module.exports = function(db, module) {
});
};
- module.getSetMembers = function(key, callback) {
+ module.getSetMembers = function (key, callback) {
if (!key) {
return callback(null, []);
}
- db.collection('objects').findOne({_key: key}, {members: 1}, {_id: 0, _key: 0}, function(err, data) {
+ db.collection('objects').findOne({_key: key}, {members: 1}, {_id: 0, _key: 0}, function (err, data) {
callback(err, data ? data.members : []);
});
};
- module.getSetsMembers = function(keys, callback) {
+ module.getSetsMembers = function (keys, callback) {
if (!Array.isArray(keys) || !keys.length) {
return callback(null, []);
}
- db.collection('objects').find({_key: {$in: keys}}, {_id: 0, _key: 1, members: 1}).toArray(function(err, data) {
+ db.collection('objects').find({_key: {$in: keys}}, {_id: 0, _key: 1, members: 1}).toArray(function (err, data) {
if (err) {
return callback(err);
}
var sets = {};
- data.forEach(function(set) {
+ data.forEach(function (set) {
sets[set._key] = set.members || [];
});
@@ -181,38 +181,38 @@ module.exports = function(db, module) {
});
};
- module.setCount = function(key, callback) {
+ module.setCount = function (key, callback) {
if (!key) {
return callback(null, 0);
}
- db.collection('objects').findOne({_key: key}, {_id: 0}, function(err, data) {
+ db.collection('objects').findOne({_key: key}, {_id: 0}, function (err, data) {
callback(err, data ? data.members.length : 0);
});
};
- module.setsCount = function(keys, callback) {
- module.getSetsMembers(keys, function(err, setsMembers) {
+ module.setsCount = function (keys, callback) {
+ module.getSetsMembers(keys, function (err, setsMembers) {
if (err) {
return callback(err);
}
- var counts = setsMembers.map(function(members) {
+ var counts = setsMembers.map(function (members) {
return (members && members.length) || 0;
});
callback(null, counts);
});
};
- module.setRemoveRandom = function(key, callback) {
- callback = callback || function() {};
- db.collection('objects').findOne({_key:key}, function(err, data) {
+ module.setRemoveRandom = function (key, callback) {
+ callback = callback || function () {};
+ db.collection('objects').findOne({_key:key}, function (err, data) {
if(err || !data) {
return callback(err);
}
var randomIndex = Math.floor(Math.random() * data.members.length);
var value = data.members[randomIndex];
- module.setRemove(data._key, value, function(err) {
+ module.setRemove(data._key, value, function (err) {
callback(err, value);
});
});
diff --git a/src/database/mongo/sorted.js b/src/database/mongo/sorted.js
index aa878d58fa..1a36f6eeb0 100644
--- a/src/database/mongo/sorted.js
+++ b/src/database/mongo/sorted.js
@@ -3,10 +3,10 @@
var async = require('async');
var utils = require('../../../public/src/utils');
-module.exports = function(db, module) {
+module.exports = function (db, module) {
var helpers = module.helpers.mongo;
- module.sortedSetAdd = function(key, score, value, callback) {
+ module.sortedSetAdd = function (key, score, value, callback) {
callback = callback || helpers.noop;
if (!key) {
return callback();
@@ -17,7 +17,7 @@ module.exports = function(db, module) {
value = helpers.valueToString(value);
- db.collection('objects').update({_key: key, value: value}, {$set: {score: parseInt(score, 10)}}, {upsert:true, w: 1}, function(err) {
+ db.collection('objects').update({_key: key, value: value}, {$set: {score: parseInt(score, 10)}}, {upsert:true, w: 1}, function (err) {
if (err && err.message.startsWith('E11000 duplicate key error')) {
return module.sortedSetAdd(key, score, value, callback);
}
@@ -41,12 +41,12 @@ module.exports = function(db, module) {
bulk.find({_key: key, value: values[i]}).upsert().updateOne({$set: {score: parseInt(scores[i], 10)}});
}
- bulk.execute(function(err) {
+ bulk.execute(function (err) {
callback(err);
});
}
- module.sortedSetsAdd = function(keys, score, value, callback) {
+ module.sortedSetsAdd = function (keys, score, value, callback) {
callback = callback || helpers.noop;
if (!Array.isArray(keys) || !keys.length) {
return callback();
@@ -59,12 +59,12 @@ module.exports = function(db, module) {
bulk.find({_key: keys[i], value: value}).upsert().updateOne({$set: {score: parseInt(score, 10)}});
}
- bulk.execute(function(err) {
+ bulk.execute(function (err) {
callback(err);
});
};
- module.sortedSetRemove = function(key, value, callback) {
+ module.sortedSetRemove = function (key, value, callback) {
function done(err) {
callback(err);
}
@@ -82,19 +82,19 @@ module.exports = function(db, module) {
}
};
- module.sortedSetsRemove = function(keys, value, callback) {
+ module.sortedSetsRemove = function (keys, value, callback) {
callback = callback || helpers.noop;
if (!Array.isArray(keys) || !keys.length) {
return callback();
}
value = helpers.valueToString(value);
- db.collection('objects').remove({_key: {$in: keys}, value: value}, function(err) {
+ db.collection('objects').remove({_key: {$in: keys}, value: value}, function (err) {
callback(err);
});
};
- module.sortedSetsRemoveRangeByScore = function(keys, min, max, callback) {
+ module.sortedSetsRemoveRangeByScore = function (keys, min, max, callback) {
callback = callback || helpers.noop;
if (!Array.isArray(keys) || !keys.length) {
return callback();
@@ -109,24 +109,24 @@ module.exports = function(db, module) {
query.score.$lte = max;
}
- db.collection('objects').remove(query, function(err) {
+ db.collection('objects').remove(query, function (err) {
callback(err);
});
};
- module.getSortedSetRange = function(key, start, stop, callback) {
+ module.getSortedSetRange = function (key, start, stop, callback) {
getSortedSetRange(key, start, stop, 1, false, callback);
};
- module.getSortedSetRevRange = function(key, start, stop, callback) {
+ module.getSortedSetRevRange = function (key, start, stop, callback) {
getSortedSetRange(key, start, stop, -1, false, callback);
};
- module.getSortedSetRangeWithScores = function(key, start, stop, callback) {
+ module.getSortedSetRangeWithScores = function (key, start, stop, callback) {
getSortedSetRange(key, start, stop, 1, true, callback);
};
- module.getSortedSetRevRangeWithScores = function(key, start, stop, callback) {
+ module.getSortedSetRevRangeWithScores = function (key, start, stop, callback) {
getSortedSetRange(key, start, stop, -1, true, callback);
};
@@ -153,13 +153,13 @@ module.exports = function(db, module) {
.limit(limit)
.skip(start)
.sort({score: sort})
- .toArray(function(err, data) {
+ .toArray(function (err, data) {
if (err || !data) {
return callback(err);
}
if (!withScores) {
- data = data.map(function(item) {
+ data = data.map(function (item) {
return item.value;
});
}
@@ -168,19 +168,19 @@ module.exports = function(db, module) {
});
}
- module.getSortedSetRangeByScore = function(key, start, count, min, max, callback) {
+ module.getSortedSetRangeByScore = function (key, start, count, min, max, callback) {
getSortedSetRangeByScore(key, start, count, min, max, 1, false, callback);
};
- module.getSortedSetRevRangeByScore = function(key, start, count, max, min, callback) {
+ module.getSortedSetRevRangeByScore = function (key, start, count, max, min, callback) {
getSortedSetRangeByScore(key, start, count, min, max, -1, false, callback);
};
- module.getSortedSetRangeByScoreWithScores = function(key, start, count, min, max, callback) {
+ module.getSortedSetRangeByScoreWithScores = function (key, start, count, min, max, callback) {
getSortedSetRangeByScore(key, start, count, min, max, 1, true, callback);
};
- module.getSortedSetRevRangeByScoreWithScores = function(key, start, count, max, min, callback) {
+ module.getSortedSetRevRangeByScoreWithScores = function (key, start, count, max, min, callback) {
getSortedSetRangeByScore(key, start, count, min, max, -1, true, callback);
};
@@ -211,13 +211,13 @@ module.exports = function(db, module) {
.limit(count)
.skip(start)
.sort({score: sort})
- .toArray(function(err, data) {
+ .toArray(function (err, data) {
if(err) {
return callback(err);
}
if (!withScores) {
- data = data.map(function(item) {
+ data = data.map(function (item) {
return item.value;
});
}
@@ -226,7 +226,7 @@ module.exports = function(db, module) {
});
}
- module.sortedSetCount = function(key, min, max, callback) {
+ module.sortedSetCount = function (key, min, max, callback) {
if (!key) {
return callback();
}
@@ -240,22 +240,22 @@ module.exports = function(db, module) {
query.score.$lte = max;
}
- db.collection('objects').count(query, function(err, count) {
+ db.collection('objects').count(query, function (err, count) {
callback(err, count ? count : 0);
});
};
- module.sortedSetCard = function(key, callback) {
+ module.sortedSetCard = function (key, callback) {
if (!key) {
return callback(null, 0);
}
- db.collection('objects').count({_key: key}, function(err, count) {
+ db.collection('objects').count({_key: key}, function (err, count) {
count = parseInt(count, 10);
callback(err, count ? count : 0);
});
};
- module.sortedSetsCard = function(keys, callback) {
+ module.sortedSetsCard = function (keys, callback) {
if (!Array.isArray(keys) || !keys.length) {
return callback();
}
@@ -264,7 +264,7 @@ module.exports = function(db, module) {
{ $group: { _id: {_key: '$_key'}, count: { $sum: 1 } } },
{ $project: { _id: 1, count: '$count' } }
];
- db.collection('objects').aggregate(pipeline, function(err, results) {
+ db.collection('objects').aggregate(pipeline, function (err, results) {
if (err) {
return callback(err);
}
@@ -274,24 +274,24 @@ module.exports = function(db, module) {
}
var map = {};
- results.forEach(function(item) {
+ results.forEach(function (item) {
if (item && item._id._key) {
map[item._id._key] = item.count;
}
});
- results = keys.map(function(key) {
+ results = keys.map(function (key) {
return map[key] || 0;
});
callback(null, results);
});
};
- module.sortedSetRank = function(key, value, callback) {
+ module.sortedSetRank = function (key, value, callback) {
getSortedSetRank(module.getSortedSetRange, key, value, callback);
};
- module.sortedSetRevRank = function(key, value, callback) {
+ module.sortedSetRevRank = function (key, value, callback) {
getSortedSetRank(module.getSortedSetRevRange, key, value, callback);
};
@@ -300,7 +300,7 @@ module.exports = function(db, module) {
return callback();
}
value = helpers.valueToString(value);
- method(key, 0, -1, function(err, result) {
+ method(key, 0, -1, function (err, result) {
if(err) {
return callback(err);
}
@@ -310,7 +310,7 @@ module.exports = function(db, module) {
});
}
- module.sortedSetsRanks = function(keys, values, callback) {
+ module.sortedSetsRanks = function (keys, values, callback) {
if (!Array.isArray(keys) || !keys.length) {
return callback(null, []);
}
@@ -319,18 +319,18 @@ module.exports = function(db, module) {
data[i] = {key: keys[i], value: values[i]};
}
- async.map(data, function(item, next) {
+ async.map(data, function (item, next) {
getSortedSetRank(module.getSortedSetRange, item.key, item.value, next);
}, callback);
};
- module.sortedSetRanks = function(key, values, callback) {
- module.getSortedSetRange(key, 0, -1, function(err, sortedSet) {
+ module.sortedSetRanks = function (key, values, callback) {
+ module.getSortedSetRange(key, 0, -1, function (err, sortedSet) {
if (err) {
return callback(err);
}
- var result = values.map(function(value) {
+ var result = values.map(function (value) {
if (!value) {
return null;
}
@@ -342,22 +342,22 @@ module.exports = function(db, module) {
});
};
- module.sortedSetScore = function(key, value, callback) {
+ module.sortedSetScore = function (key, value, callback) {
if (!key) {
return callback();
}
value = helpers.valueToString(value);
- db.collection('objects').findOne({_key: key, value: value}, {fields:{_id: 0, score: 1}}, function(err, result) {
+ db.collection('objects').findOne({_key: key, value: value}, {fields:{_id: 0, score: 1}}, function (err, result) {
callback(err, result ? result.score : null);
});
};
- module.sortedSetsScore = function(keys, value, callback) {
+ module.sortedSetsScore = function (keys, value, callback) {
if (!Array.isArray(keys) || !keys.length) {
return callback();
}
value = helpers.valueToString(value);
- db.collection('objects').find({_key:{$in:keys}, value: value}, {_id:0, _key:1, score: 1}).toArray(function(err, result) {
+ db.collection('objects').find({_key:{$in:keys}, value: value}, {_id:0, _key:1, score: 1}).toArray(function (err, result) {
if (err) {
return callback(err);
}
@@ -375,18 +375,18 @@ module.exports = function(db, module) {
});
};
- module.sortedSetScores = function(key, values, callback) {
+ module.sortedSetScores = function (key, values, callback) {
if (!key) {
return callback();
}
values = values.map(helpers.valueToString);
- db.collection('objects').find({_key: key, value: {$in: values}}, {_id: 0, value: 1, score: 1}).toArray(function(err, result) {
+ db.collection('objects').find({_key: key, value: {$in: values}}, {_id: 0, value: 1, score: 1}).toArray(function (err, result) {
if (err) {
return callback(err);
}
var map = {};
- result.forEach(function(item) {
+ result.forEach(function (item) {
map[item.value] = item.score;
});
@@ -402,69 +402,69 @@ module.exports = function(db, module) {
});
};
- module.isSortedSetMember = function(key, value, callback) {
+ module.isSortedSetMember = function (key, value, callback) {
if (!key) {
return callback();
}
value = helpers.valueToString(value);
- db.collection('objects').findOne({_key: key, value: value}, {_id: 0, value: 1}, function(err, result) {
+ db.collection('objects').findOne({_key: key, value: value}, {_id: 0, value: 1}, function (err, result) {
callback(err, !!result);
});
};
- module.isSortedSetMembers = function(key, values, callback) {
+ module.isSortedSetMembers = function (key, values, callback) {
if (!key) {
return callback();
}
values = values.map(helpers.valueToString);
- db.collection('objects').find({_key: key, value: {$in: values}}, {fields: {_id: 0, value: 1}}).toArray(function(err, results) {
+ db.collection('objects').find({_key: key, value: {$in: values}}, {fields: {_id: 0, value: 1}}).toArray(function (err, results) {
if (err) {
return callback(err);
}
- results = results.map(function(item) {
+ results = results.map(function (item) {
return item.value;
});
- values = values.map(function(value) {
+ values = values.map(function (value) {
return results.indexOf(value) !== -1;
});
callback(null, values);
});
};
- module.isMemberOfSortedSets = function(keys, value, callback) {
+ module.isMemberOfSortedSets = function (keys, value, callback) {
if (!Array.isArray(keys)) {
return callback();
}
value = helpers.valueToString(value);
- db.collection('objects').find({_key: {$in: keys}, value: value}, {fields: {_id: 0, _key: 1, value: 1}}).toArray(function(err, results) {
+ db.collection('objects').find({_key: {$in: keys}, value: value}, {fields: {_id: 0, _key: 1, value: 1}}).toArray(function (err, results) {
if (err) {
return callback(err);
}
- results = results.map(function(item) {
+ results = results.map(function (item) {
return item._key;
});
- results = keys.map(function(key) {
+ results = keys.map(function (key) {
return results.indexOf(key) !== -1;
});
callback(null, results);
});
};
- module.getSortedSetsMembers = function(keys, callback) {
+ module.getSortedSetsMembers = function (keys, callback) {
if (!Array.isArray(keys) || !keys.length) {
return callback(null, []);
}
- db.collection('objects').find({_key: {$in: keys}}, {_id: 0, _key: 1, value: 1}).toArray(function(err, data) {
+ db.collection('objects').find({_key: {$in: keys}}, {_id: 0, _key: 1, value: 1}).toArray(function (err, data) {
if (err) {
return callback(err);
}
var sets = {};
- data.forEach(function(set) {
+ data.forEach(function (set) {
sets[set._key] = sets[set._key] || [];
sets[set._key].push(set.value);
});
@@ -477,7 +477,7 @@ module.exports = function(db, module) {
});
};
- module.sortedSetUnionCard = function(keys, callback) {
+ module.sortedSetUnionCard = function (keys, callback) {
if (!Array.isArray(keys) || !keys.length) {
return callback(null, 0);
}
@@ -491,17 +491,17 @@ module.exports = function(db, module) {
var project = { _id: 0, count: '$count' };
pipeline.push({ $project: project });
- db.collection('objects').aggregate(pipeline, function(err, data) {
+ db.collection('objects').aggregate(pipeline, function (err, data) {
callback(err, Array.isArray(data) && data.length ? data[0].count : 0);
});
};
- module.getSortedSetUnion = function(params, callback) {
+ module.getSortedSetUnion = function (params, callback) {
params.sort = 1;
getSortedSetUnion(params, callback);
};
- module.getSortedSetRevUnion = function(params, callback) {
+ module.getSortedSetRevUnion = function (params, callback) {
params.sort = -1;
getSortedSetUnion(params, callback);
};
@@ -542,13 +542,13 @@ module.exports = function(db, module) {
}
pipeline.push({ $project: project });
- db.collection('objects').aggregate(pipeline, function(err, data) {
+ db.collection('objects').aggregate(pipeline, function (err, data) {
if (err || !data) {
return callback(err);
}
if (!params.withScores) {
- data = data.map(function(item) {
+ data = data.map(function (item) {
return item.value;
});
}
@@ -557,7 +557,7 @@ module.exports = function(db, module) {
});
}
- module.sortedSetIncrBy = function(key, increment, value, callback) {
+ module.sortedSetIncrBy = function (key, increment, value, callback) {
callback = callback || helpers.noop;
if (!key) {
return callback();
@@ -566,7 +566,7 @@ module.exports = function(db, module) {
value = helpers.valueToString(value);
data.score = parseInt(increment, 10);
- db.collection('objects').findAndModify({_key: key, value: value}, {}, {$inc: data}, {new: true, upsert: true}, function(err, result) {
+ db.collection('objects').findAndModify({_key: key, value: value}, {}, {$inc: data}, {new: true, upsert: true}, function (err, result) {
// if there is duplicate key error retry the upsert
// https://github.com/NodeBB/NodeBB/issues/4467
// https://jira.mongodb.org/browse/SERVER-14322
@@ -578,7 +578,7 @@ module.exports = function(db, module) {
});
};
- module.getSortedSetRangeByLex = function(key, min, max, start, count, callback) {
+ module.getSortedSetRangeByLex = function (key, min, max, start, count, callback) {
var query = {_key: key};
if (min !== '-') {
query.value = {$gte: min};
@@ -591,18 +591,18 @@ module.exports = function(db, module) {
.sort({value: 1})
.skip(start)
.limit(count === -1 ? 0 : count)
- .toArray(function(err, data) {
+ .toArray(function (err, data) {
if (err) {
return callback(err);
}
- data = data.map(function(item) {
+ data = data.map(function (item) {
return item && item.value;
});
callback(err, data);
});
};
- module.processSortedSet = function(setKey, process, batch, callback) {
+ module.processSortedSet = function (setKey, process, batch, callback) {
var done = false;
var ids = [];
var cursor = db.collection('objects').find({_key: setKey})
@@ -611,11 +611,11 @@ module.exports = function(db, module) {
.batchSize(batch);
async.whilst(
- function() {
+ function () {
return !done;
},
- function(next) {
- cursor.next(function(err, item) {
+ function (next) {
+ cursor.next(function (err, item) {
if (err) {
return next(err);
}
@@ -629,7 +629,7 @@ module.exports = function(db, module) {
return next(null);
}
- process(ids, function(err) {
+ process(ids, function (err) {
ids = [];
return next(err);
});
@@ -640,7 +640,7 @@ module.exports = function(db, module) {
};
- module.sortedSetIntersectCard = function(keys, callback) {
+ module.sortedSetIntersectCard = function (keys, callback) {
if (!Array.isArray(keys) || !keys.length) {
return callback(null, 0);
}
@@ -652,17 +652,17 @@ module.exports = function(db, module) {
{ $group: { _id: null, count: { $sum: 1 } } }
];
- db.collection('objects').aggregate(pipeline, function(err, data) {
+ db.collection('objects').aggregate(pipeline, function (err, data) {
callback(err, Array.isArray(data) && data.length ? data[0].count : 0);
});
};
- module.getSortedSetIntersect = function(params, callback) {
+ module.getSortedSetIntersect = function (params, callback) {
params.sort = 1;
getSortedSetRevIntersect(params, callback);
};
- module.getSortedSetRevIntersect = function(params, callback) {
+ module.getSortedSetRevIntersect = function (params, callback) {
params.sort = -1;
getSortedSetRevIntersect(params, callback);
};
@@ -687,7 +687,7 @@ module.exports = function(db, module) {
var pipeline = [{ $match: { _key: {$in: sets}} }];
- weights.forEach(function(weight, index) {
+ weights.forEach(function (weight, index) {
if (weight !== 1) {
pipeline.push({
$project: {
@@ -718,13 +718,13 @@ module.exports = function(db, module) {
}
pipeline.push({ $project: project });
- db.collection('objects').aggregate(pipeline, function(err, data) {
+ db.collection('objects').aggregate(pipeline, function (err, data) {
if (err || !data) {
return callback(err);
}
if (!params.withScores) {
- data = data.map(function(item) {
+ data = data.map(function (item) {
return item.value;
});
}
diff --git a/src/database/redis.js b/src/database/redis.js
index 214c9ef4a1..3b05148c9e 100644
--- a/src/database/redis.js
+++ b/src/database/redis.js
@@ -1,6 +1,6 @@
'use strict';
-(function(module) {
+(function (module) {
var winston = require('winston'),
nconf = require('nconf'),
@@ -26,7 +26,7 @@
description: 'Password of your Redis database',
hidden: true,
default: nconf.get('redis:password') || '',
- before: function(value) { value = value || nconf.get('redis:password') || ''; return value; }
+ before: function (value) { value = value || nconf.get('redis:password') || ''; return value; }
},
{
name: "redis:database",
@@ -35,7 +35,7 @@
}
];
- module.init = function(callback) {
+ module.init = function (callback) {
try {
redis = require('redis');
connectRedis = require('connect-redis')(session);
@@ -64,7 +64,7 @@
}
};
- module.connect = function(options) {
+ module.connect = function (options) {
var redis_socket_or_host = nconf.get('redis:host');
var cxn;
@@ -96,7 +96,7 @@
var dbIdx = parseInt(nconf.get('redis:database'), 10);
if (dbIdx) {
- cxn.select(dbIdx, function(error) {
+ cxn.select(dbIdx, function (error) {
if(error) {
winston.error("NodeBB could not connect to your Redis database. Redis returned the following error: " + error.message);
process.exit();
@@ -107,8 +107,8 @@
return cxn;
};
- module.checkCompatibility = function(callback) {
- module.info(module.client, function(err, info) {
+ module.checkCompatibility = function (callback) {
+ module.info(module.client, function (err, info) {
if (err) {
return callback(err);
}
@@ -122,11 +122,11 @@
});
};
- module.close = function() {
+ module.close = function () {
redisClient.quit();
};
- module.info = function(cxn, callback) {
+ module.info = function (cxn, callback) {
cxn.info(function (err, data) {
if (err) {
return callback(err);
diff --git a/src/database/redis/hash.js b/src/database/redis/hash.js
index 728b713638..a728852f1a 100644
--- a/src/database/redis/hash.js
+++ b/src/database/redis/hash.js
@@ -1,46 +1,46 @@
"use strict";
-module.exports = function(redisClient, module) {
+module.exports = function (redisClient, module) {
var helpers = module.helpers.redis;
- module.setObject = function(key, data, callback) {
- callback = callback || function() {};
- redisClient.hmset(key, data, function(err) {
+ module.setObject = function (key, data, callback) {
+ callback = callback || function () {};
+ redisClient.hmset(key, data, function (err) {
callback(err);
});
};
- module.setObjectField = function(key, field, value, callback) {
- callback = callback || function() {};
- redisClient.hset(key, field, value, function(err) {
+ module.setObjectField = function (key, field, value, callback) {
+ callback = callback || function () {};
+ redisClient.hset(key, field, value, function (err) {
callback(err);
});
};
- module.getObject = function(key, callback) {
+ module.getObject = function (key, callback) {
redisClient.hgetall(key, callback);
};
- module.getObjects = function(keys, callback) {
+ module.getObjects = function (keys, callback) {
helpers.multiKeys(redisClient, 'hgetall', keys, callback);
};
- module.getObjectField = function(key, field, callback) {
- module.getObjectFields(key, [field], function(err, data) {
+ module.getObjectField = function (key, field, callback) {
+ module.getObjectFields(key, [field], function (err, data) {
callback(err, data ? data[field] : null);
});
};
- module.getObjectFields = function(key, fields, callback) {
- module.getObjectsFields([key], fields, function(err, results) {
+ module.getObjectFields = function (key, fields, callback) {
+ module.getObjectsFields([key], fields, function (err, results) {
callback(err, results ? results[0] : null);
});
};
- module.getObjectsFields = function(keys, fields, callback) {
+ module.getObjectsFields = function (keys, fields, callback) {
if (!Array.isArray(fields) || !fields.length) {
- return callback(null, keys.map(function() { return {}; }));
+ return callback(null, keys.map(function () { return {}; }));
}
var multi = redisClient.multi();
@@ -57,7 +57,7 @@ module.exports = function(redisClient, module) {
return obj;
}
- multi.exec(function(err, results) {
+ multi.exec(function (err, results) {
if (err) {
return callback(err);
}
@@ -67,48 +67,48 @@ module.exports = function(redisClient, module) {
});
};
- module.getObjectKeys = function(key, callback) {
+ module.getObjectKeys = function (key, callback) {
redisClient.hkeys(key, callback);
};
- module.getObjectValues = function(key, callback) {
+ module.getObjectValues = function (key, callback) {
redisClient.hvals(key, callback);
};
- module.isObjectField = function(key, field, callback) {
- redisClient.hexists(key, field, function(err, exists) {
+ module.isObjectField = function (key, field, callback) {
+ redisClient.hexists(key, field, function (err, exists) {
callback(err, exists === 1);
});
};
- module.isObjectFields = function(key, fields, callback) {
- helpers.multiKeyValues(redisClient, 'hexists', key, fields, function(err, results) {
+ module.isObjectFields = function (key, fields, callback) {
+ helpers.multiKeyValues(redisClient, 'hexists', key, fields, function (err, results) {
callback(err, Array.isArray(results) ? helpers.resultsToBool(results) : null);
});
};
- module.deleteObjectField = function(key, field, callback) {
- callback = callback || function() {};
- redisClient.hdel(key, field, function(err, res) {
+ module.deleteObjectField = function (key, field, callback) {
+ callback = callback || function () {};
+ redisClient.hdel(key, field, function (err, res) {
callback(err);
});
};
- module.deleteObjectFields = function(key, fields, callback) {
- helpers.multiKeyValues(redisClient, 'hdel', key, fields, function(err, results) {
+ module.deleteObjectFields = function (key, fields, callback) {
+ helpers.multiKeyValues(redisClient, 'hdel', key, fields, function (err, results) {
callback(err);
});
};
- module.incrObjectField = function(key, field, callback) {
+ module.incrObjectField = function (key, field, callback) {
redisClient.hincrby(key, field, 1, callback);
};
- module.decrObjectField = function(key, field, callback) {
+ module.decrObjectField = function (key, field, callback) {
redisClient.hincrby(key, field, -1, callback);
};
- module.incrObjectFieldBy = function(key, field, value, callback) {
+ module.incrObjectFieldBy = function (key, field, value, callback) {
redisClient.hincrby(key, field, value, callback);
};
};
\ No newline at end of file
diff --git a/src/database/redis/helpers.js b/src/database/redis/helpers.js
index 7dc1e1bba5..a4ca7e116f 100644
--- a/src/database/redis/helpers.js
+++ b/src/database/redis/helpers.js
@@ -2,8 +2,8 @@
var helpers = {};
-helpers.multiKeys = function(redisClient, command, keys, callback) {
- callback = callback || function() {};
+helpers.multiKeys = function (redisClient, command, keys, callback) {
+ callback = callback || function () {};
var multi = redisClient.multi();
for (var i = 0; i < keys.length; ++i) {
multi[command](keys[i]);
@@ -11,8 +11,8 @@ helpers.multiKeys = function(redisClient, command, keys, callback) {
multi.exec(callback);
};
-helpers.multiKeysValue = function(redisClient, command, keys, value, callback) {
- callback = callback || function() {};
+helpers.multiKeysValue = function (redisClient, command, keys, value, callback) {
+ callback = callback || function () {};
var multi = redisClient.multi();
for (var i = 0; i < keys.length; ++i) {
multi[command](keys[i], value);
@@ -20,8 +20,8 @@ helpers.multiKeysValue = function(redisClient, command, keys, value, callback) {
multi.exec(callback);
};
-helpers.multiKeyValues = function(redisClient, command, key, values, callback) {
- callback = callback || function() {};
+helpers.multiKeyValues = function (redisClient, command, key, values, callback) {
+ callback = callback || function () {};
var multi = redisClient.multi();
for (var i = 0; i < values.length; ++i) {
multi[command](key, values[i]);
@@ -29,7 +29,7 @@ helpers.multiKeyValues = function(redisClient, command, key, values, callback) {
multi.exec(callback);
};
-helpers.resultsToBool = function(results) {
+helpers.resultsToBool = function (results) {
for (var i = 0; i < results.length; ++i) {
results[i] = results[i] === 1;
}
diff --git a/src/database/redis/list.js b/src/database/redis/list.js
index 7ebc068d53..c44c23b475 100644
--- a/src/database/redis/list.js
+++ b/src/database/redis/list.js
@@ -1,41 +1,41 @@
"use strict";
-module.exports = function(redisClient, module) {
- module.listPrepend = function(key, value, callback) {
- callback = callback || function() {};
- redisClient.lpush(key, value, function(err, res) {
+module.exports = function (redisClient, module) {
+ module.listPrepend = function (key, value, callback) {
+ callback = callback || function () {};
+ redisClient.lpush(key, value, function (err, res) {
callback(err);
});
};
- module.listAppend = function(key, value, callback) {
- callback = callback || function() {};
- redisClient.rpush(key, value, function(err, res) {
+ module.listAppend = function (key, value, callback) {
+ callback = callback || function () {};
+ redisClient.rpush(key, value, function (err, res) {
callback(err);
});
};
- module.listRemoveLast = function(key, callback) {
- callback = callback || function() {};
+ module.listRemoveLast = function (key, callback) {
+ callback = callback || function () {};
redisClient.rpop(key, callback);
};
- module.listRemoveAll = function(key, value, callback) {
- callback = callback || function() {};
- redisClient.lrem(key, 0, value, function(err, res) {
+ module.listRemoveAll = function (key, value, callback) {
+ callback = callback || function () {};
+ redisClient.lrem(key, 0, value, function (err, res) {
callback(err);
});
};
- module.listTrim = function(key, start, stop, callback) {
- callback = callback || function() {};
- redisClient.ltrim(key, start, stop, function(err, res) {
+ module.listTrim = function (key, start, stop, callback) {
+ callback = callback || function () {};
+ redisClient.ltrim(key, start, stop, function (err, res) {
callback(err);
});
};
- module.getListRange = function(key, start, stop, callback) {
- callback = callback || function() {};
+ module.getListRange = function (key, start, stop, callback) {
+ callback = callback || function () {};
redisClient.lrange(key, start, stop, callback);
};
};
\ No newline at end of file
diff --git a/src/database/redis/main.js b/src/database/redis/main.js
index 0b39c6b2ff..66379f1774 100644
--- a/src/database/redis/main.js
+++ b/src/database/redis/main.js
@@ -1,86 +1,86 @@
"use strict";
-module.exports = function(redisClient, module) {
+module.exports = function (redisClient, module) {
- module.flushdb = function(callback) {
- redisClient.send_command('flushdb', [], function(err) {
+ module.flushdb = function (callback) {
+ redisClient.send_command('flushdb', [], function (err) {
if (typeof callback === 'function') {
callback(err);
}
});
};
- module.exists = function(key, callback) {
- redisClient.exists(key, function(err, exists) {
+ module.exists = function (key, callback) {
+ redisClient.exists(key, function (err, exists) {
callback(err, exists === 1);
});
};
- module.delete = function(key, callback) {
- callback = callback || function() {};
- redisClient.del(key, function(err, res) {
+ module.delete = function (key, callback) {
+ callback = callback || function () {};
+ redisClient.del(key, function (err, res) {
callback(err);
});
};
- module.deleteAll = function(keys, callback) {
- callback = callback || function() {};
+ module.deleteAll = function (keys, callback) {
+ callback = callback || function () {};
var multi = redisClient.multi();
for(var i = 0; i < keys.length; ++i) {
multi.del(keys[i]);
}
- multi.exec(function(err, res) {
+ multi.exec(function (err, res) {
callback(err);
});
};
- module.get = function(key, callback) {
+ module.get = function (key, callback) {
redisClient.get(key, callback);
};
- module.set = function(key, value, callback) {
- callback = callback || function() {};
- redisClient.set(key, value, function(err) {
+ module.set = function (key, value, callback) {
+ callback = callback || function () {};
+ redisClient.set(key, value, function (err) {
callback(err);
});
};
- module.increment = function(key, callback) {
- callback = callback || function() {};
+ module.increment = function (key, callback) {
+ callback = callback || function () {};
redisClient.incr(key, callback);
};
- module.rename = function(oldKey, newKey, callback) {
- callback = callback || function() {};
- redisClient.rename(oldKey, newKey, function(err, res) {
+ module.rename = function (oldKey, newKey, callback) {
+ callback = callback || function () {};
+ redisClient.rename(oldKey, newKey, function (err, res) {
callback(err && err.message !== 'ERR no such key' ? err : null);
});
};
- module.expire = function(key, seconds, callback) {
- callback = callback || function() {};
- redisClient.expire(key, seconds, function(err) {
+ module.expire = function (key, seconds, callback) {
+ callback = callback || function () {};
+ redisClient.expire(key, seconds, function (err) {
callback(err);
});
};
- module.expireAt = function(key, timestamp, callback) {
- callback = callback || function() {};
- redisClient.expireat(key, timestamp, function(err) {
+ module.expireAt = function (key, timestamp, callback) {
+ callback = callback || function () {};
+ redisClient.expireat(key, timestamp, function (err) {
callback(err);
});
};
- module.pexpire = function(key, ms, callback) {
- callback = callback || function() {};
- redisClient.pexpire(key, ms, function(err) {
+ module.pexpire = function (key, ms, callback) {
+ callback = callback || function () {};
+ redisClient.pexpire(key, ms, function (err) {
callback(err);
});
};
- module.pexpireAt = function(key, timestamp, callback) {
- callback = callback || function() {};
- redisClient.pexpireat(key, timestamp, function(err) {
+ module.pexpireAt = function (key, timestamp, callback) {
+ callback = callback || function () {};
+ redisClient.pexpireat(key, timestamp, function (err) {
callback(err);
});
};
diff --git a/src/database/redis/sets.js b/src/database/redis/sets.js
index 1eaab00cc5..5b2b803868 100644
--- a/src/database/redis/sets.js
+++ b/src/database/redis/sets.js
@@ -1,78 +1,78 @@
"use strict";
-module.exports = function(redisClient, module) {
+module.exports = function (redisClient, module) {
var helpers = module.helpers.redis;
- module.setAdd = function(key, value, callback) {
- callback = callback || function() {};
+ module.setAdd = function (key, value, callback) {
+ callback = callback || function () {};
if (!Array.isArray(value)) {
value = [value];
}
if (!value.length) {
return callback();
}
- redisClient.sadd(key, value, function(err, res) {
+ redisClient.sadd(key, value, function (err, res) {
callback(err);
});
};
- module.setsAdd = function(keys, value, callback) {
- callback = callback || function() {};
- helpers.multiKeysValue(redisClient, 'sadd', keys, value, function(err, res) {
+ module.setsAdd = function (keys, value, callback) {
+ callback = callback || function () {};
+ helpers.multiKeysValue(redisClient, 'sadd', keys, value, function (err, res) {
callback(err);
});
};
- module.setRemove = function(key, value, callback) {
- callback = callback || function() {};
- redisClient.srem(key, value, function(err, res) {
+ module.setRemove = function (key, value, callback) {
+ callback = callback || function () {};
+ redisClient.srem(key, value, function (err, res) {
callback(err);
});
};
- module.setsRemove = function(keys, value, callback) {
- callback = callback || function() {};
- helpers.multiKeysValue(redisClient, 'srem', keys, value, function(err, res) {
+ module.setsRemove = function (keys, value, callback) {
+ callback = callback || function () {};
+ helpers.multiKeysValue(redisClient, 'srem', keys, value, function (err, res) {
callback(err);
});
};
- module.isSetMember = function(key, value, callback) {
- redisClient.sismember(key, value, function(err, result) {
+ module.isSetMember = function (key, value, callback) {
+ redisClient.sismember(key, value, function (err, result) {
callback(err, result === 1);
});
};
- module.isSetMembers = function(key, values, callback) {
- helpers.multiKeyValues(redisClient, 'sismember', key, values, function(err, results) {
+ module.isSetMembers = function (key, values, callback) {
+ helpers.multiKeyValues(redisClient, 'sismember', key, values, function (err, results) {
callback(err, results ? helpers.resultsToBool(results) : null);
});
};
- module.isMemberOfSets = function(sets, value, callback) {
- helpers.multiKeysValue(redisClient, 'sismember', sets, value, function(err, results) {
+ module.isMemberOfSets = function (sets, value, callback) {
+ helpers.multiKeysValue(redisClient, 'sismember', sets, value, function (err, results) {
callback(err, results ? helpers.resultsToBool(results) : null);
});
};
- module.getSetMembers = function(key, callback) {
+ module.getSetMembers = function (key, callback) {
redisClient.smembers(key, callback);
};
- module.getSetsMembers = function(keys, callback) {
+ module.getSetsMembers = function (keys, callback) {
helpers.multiKeys(redisClient, 'smembers', keys, callback);
};
- module.setCount = function(key, callback) {
+ module.setCount = function (key, callback) {
redisClient.scard(key, callback);
};
- module.setsCount = function(keys, callback) {
+ module.setsCount = function (keys, callback) {
helpers.multiKeys(redisClient, 'scard', keys, callback);
};
- module.setRemoveRandom = function(key, callback) {
- callback = callback || function() {};
+ module.setRemoveRandom = function (key, callback) {
+ callback = callback || function () {};
redisClient.spop(key, callback);
};
diff --git a/src/database/redis/sorted.js b/src/database/redis/sorted.js
index f63323716d..e02366c08f 100644
--- a/src/database/redis/sorted.js
+++ b/src/database/redis/sorted.js
@@ -1,15 +1,15 @@
"use strict";
-module.exports = function(redisClient, module) {
+module.exports = function (redisClient, module) {
var helpers = module.helpers.redis;
- module.sortedSetAdd = function(key, score, value, callback) {
- callback = callback || function() {};
+ module.sortedSetAdd = function (key, score, value, callback) {
+ callback = callback || function () {};
if (Array.isArray(score) && Array.isArray(value)) {
return sortedSetAddMulti(key, score, value, callback);
}
- redisClient.zadd(key, score, value, function(err) {
+ redisClient.zadd(key, score, value, function (err) {
callback(err);
});
};
@@ -29,65 +29,65 @@ module.exports = function(redisClient, module) {
args.push(scores[i], values[i]);
}
- redisClient.zadd(args, function(err) {
+ redisClient.zadd(args, function (err) {
callback(err);
});
}
- module.sortedSetsAdd = function(keys, score, value, callback) {
- callback = callback || function() {};
+ module.sortedSetsAdd = function (keys, score, value, callback) {
+ callback = callback || function () {};
var multi = redisClient.multi();
for(var i = 0; i < keys.length; ++i) {
multi.zadd(keys[i], score, value);
}
- multi.exec(function(err) {
+ multi.exec(function (err) {
callback(err);
});
};
- module.sortedSetRemove = function(key, value, callback) {
- callback = callback || function() {};
+ module.sortedSetRemove = function (key, value, callback) {
+ callback = callback || function () {};
if (!Array.isArray(value)) {
value = [value];
}
- helpers.multiKeyValues(redisClient, 'zrem', key, value, function(err) {
+ helpers.multiKeyValues(redisClient, 'zrem', key, value, function (err) {
callback(err);
});
};
- module.sortedSetsRemove = function(keys, value, callback) {
- helpers.multiKeysValue(redisClient, 'zrem', keys, value, function(err) {
+ module.sortedSetsRemove = function (keys, value, callback) {
+ helpers.multiKeysValue(redisClient, 'zrem', keys, value, function (err) {
callback(err);
});
};
- module.sortedSetsRemoveRangeByScore = function(keys, min, max, callback) {
- callback = callback || function() {};
+ module.sortedSetsRemoveRangeByScore = function (keys, min, max, callback) {
+ callback = callback || function () {};
var multi = redisClient.multi();
for(var i = 0; i < keys.length; ++i) {
multi.zremrangebyscore(keys[i], min, max);
}
- multi.exec(function(err) {
+ multi.exec(function (err) {
callback(err);
});
};
- module.getSortedSetRange = function(key, start, stop, callback) {
+ module.getSortedSetRange = function (key, start, stop, callback) {
sortedSetRange('zrange', key, start, stop, false, callback);
};
- module.getSortedSetRevRange = function(key, start, stop, callback) {
+ module.getSortedSetRevRange = function (key, start, stop, callback) {
sortedSetRange('zrevrange', key, start, stop, false, callback);
};
- module.getSortedSetRangeWithScores = function(key, start, stop, callback) {
+ module.getSortedSetRangeWithScores = function (key, start, stop, callback) {
sortedSetRange('zrange', key, start, stop, true, callback);
};
- module.getSortedSetRevRangeWithScores = function(key, start, stop, callback) {
+ module.getSortedSetRevRangeWithScores = function (key, start, stop, callback) {
sortedSetRange('zrevrange', key, start, stop, true, callback);
};
@@ -101,7 +101,7 @@ module.exports = function(redisClient, module) {
params.push('WITHSCORES');
}
- redisClient[method](params, function(err, data) {
+ redisClient[method](params, function (err, data) {
if (err) {
return callback(err);
}
@@ -116,24 +116,24 @@ module.exports = function(redisClient, module) {
});
}
- module.getSortedSetRangeByScore = function(key, start, count, min, max, callback) {
+ module.getSortedSetRangeByScore = function (key, start, count, min, max, callback) {
redisClient.zrangebyscore([key, min, max, 'LIMIT', start, count], callback);
};
- module.getSortedSetRevRangeByScore = function(key, start, count, max, min, callback) {
+ module.getSortedSetRevRangeByScore = function (key, start, count, max, min, callback) {
redisClient.zrevrangebyscore([key, max, min, 'LIMIT', start, count], callback);
};
- module.getSortedSetRangeByScoreWithScores = function(key, start, count, min, max, callback) {
+ module.getSortedSetRangeByScoreWithScores = function (key, start, count, min, max, callback) {
sortedSetRangeByScoreWithScores('zrangebyscore', key, start, count, min, max, callback);
};
- module.getSortedSetRevRangeByScoreWithScores = function(key, start, count, max, min, callback) {
+ module.getSortedSetRevRangeByScoreWithScores = function (key, start, count, max, min, callback) {
sortedSetRangeByScoreWithScores('zrevrangebyscore', key, start, count, max, min, callback);
};
function sortedSetRangeByScoreWithScores(method, key, start, count, min, max, callback) {
- redisClient[method]([key, min, max, 'WITHSCORES', 'LIMIT', start, count], function(err, data) {
+ redisClient[method]([key, min, max, 'WITHSCORES', 'LIMIT', start, count], function (err, data) {
if (err) {
return callback(err);
}
@@ -145,15 +145,15 @@ module.exports = function(redisClient, module) {
});
}
- module.sortedSetCount = function(key, min, max, callback) {
+ module.sortedSetCount = function (key, min, max, callback) {
redisClient.zcount(key, min, max, callback);
};
- module.sortedSetCard = function(key, callback) {
+ module.sortedSetCard = function (key, callback) {
redisClient.zcard(key, callback);
};
- module.sortedSetsCard = function(keys, callback) {
+ module.sortedSetsCard = function (keys, callback) {
if (Array.isArray(keys) && !keys.length) {
return callback(null, []);
}
@@ -164,11 +164,11 @@ module.exports = function(redisClient, module) {
multi.exec(callback);
};
- module.sortedSetRank = function(key, value, callback) {
+ module.sortedSetRank = function (key, value, callback) {
redisClient.zrank(key, value, callback);
};
- module.sortedSetsRanks = function(keys, values, callback) {
+ module.sortedSetsRanks = function (keys, values, callback) {
var multi = redisClient.multi();
for(var i = 0; i < values.length; ++i) {
multi.zrank(keys[i], values[i]);
@@ -176,7 +176,7 @@ module.exports = function(redisClient, module) {
multi.exec(callback);
};
- module.sortedSetRanks = function(key, values, callback) {
+ module.sortedSetRanks = function (key, values, callback) {
var multi = redisClient.multi();
for(var i = 0; i < values.length; ++i) {
multi.zrank(key, values[i]);
@@ -184,30 +184,30 @@ module.exports = function(redisClient, module) {
multi.exec(callback);
};
- module.sortedSetRevRank = function(key, value, callback) {
+ module.sortedSetRevRank = function (key, value, callback) {
redisClient.zrevrank(key, value, callback);
};
- module.sortedSetScore = function(key, value, callback) {
+ module.sortedSetScore = function (key, value, callback) {
redisClient.zscore(key, value, callback);
};
- module.sortedSetsScore = function(keys, value, callback) {
+ module.sortedSetsScore = function (keys, value, callback) {
helpers.multiKeysValue(redisClient, 'zscore', keys, value, callback);
};
- module.sortedSetScores = function(key, values, callback) {
+ module.sortedSetScores = function (key, values, callback) {
helpers.multiKeyValues(redisClient, 'zscore', key, values, callback);
};
- module.isSortedSetMember = function(key, value, callback) {
- module.sortedSetScore(key, value, function(err, score) {
+ module.isSortedSetMember = function (key, value, callback) {
+ module.sortedSetScore(key, value, function (err, score) {
callback(err, !!score);
});
};
- module.isSortedSetMembers = function(key, values, callback) {
- helpers.multiKeyValues(redisClient, 'zscore', key, values, function(err, results) {
+ module.isSortedSetMembers = function (key, values, callback) {
+ helpers.multiKeyValues(redisClient, 'zscore', key, values, function (err, results) {
if (err) {
return callback(err);
}
@@ -215,8 +215,8 @@ module.exports = function(redisClient, module) {
});
};
- module.isMemberOfSortedSets = function(keys, value, callback) {
- helpers.multiKeysValue(redisClient, 'zscore', keys, value, function(err, results) {
+ module.isMemberOfSortedSets = function (keys, value, callback) {
+ helpers.multiKeysValue(redisClient, 'zscore', keys, value, function (err, results) {
if (err) {
return callback(err);
}
@@ -224,7 +224,7 @@ module.exports = function(redisClient, module) {
});
};
- module.getSortedSetsMembers = function(keys, callback) {
+ module.getSortedSetsMembers = function (keys, callback) {
var multi = redisClient.multi();
for (var i = 0; i < keys.length; ++i) {
multi.zrange(keys[i], 0, -1);
@@ -233,14 +233,14 @@ module.exports = function(redisClient, module) {
};
- module.sortedSetUnionCard = function(keys, callback) {
+ module.sortedSetUnionCard = function (keys, callback) {
var tempSetName = 'temp_' + Date.now();
var multi = redisClient.multi();
multi.zunionstore([tempSetName, keys.length].concat(keys));
multi.zcard(tempSetName);
multi.del(tempSetName);
- multi.exec(function(err, results) {
+ multi.exec(function (err, results) {
if (err) {
return callback(err);
}
@@ -249,12 +249,12 @@ module.exports = function(redisClient, module) {
});
};
- module.getSortedSetUnion = function(params, callback) {
+ module.getSortedSetUnion = function (params, callback) {
params.method = 'zrange';
sortedSetUnion(params, callback);
};
- module.getSortedSetRevUnion = function(params, callback) {
+ module.getSortedSetRevUnion = function (params, callback) {
params.method = 'zrevrange';
sortedSetUnion(params, callback);
};
@@ -272,7 +272,7 @@ module.exports = function(redisClient, module) {
multi.zunionstore([tempSetName, params.sets.length].concat(params.sets));
multi[params.method](rangeParams);
multi.del(tempSetName);
- multi.exec(function(err, results) {
+ multi.exec(function (err, results) {
if (err) {
return callback(err);
}
@@ -288,11 +288,11 @@ module.exports = function(redisClient, module) {
});
}
- module.sortedSetIncrBy = function(key, increment, value, callback) {
+ module.sortedSetIncrBy = function (key, increment, value, callback) {
redisClient.zincrby(key, increment, value, callback);
};
- module.getSortedSetRangeByLex = function(key, min, max, start, count, callback) {
+ module.getSortedSetRangeByLex = function (key, min, max, start, count, callback) {
if (min !== '-') {
min = '[' + min;
}
@@ -302,7 +302,7 @@ module.exports = function(redisClient, module) {
redisClient.zrangebylex([key, min, max, 'LIMIT', start, count], callback);
};
- module.sortedSetIntersectCard = function(keys, callback) {
+ module.sortedSetIntersectCard = function (keys, callback) {
if (!Array.isArray(keys) || !keys.length) {
return callback(null, 0);
}
@@ -314,7 +314,7 @@ module.exports = function(redisClient, module) {
multi.zinterstore(interParams);
multi.zcard(tempSetName);
multi.del(tempSetName);
- multi.exec(function(err, results) {
+ multi.exec(function (err, results) {
if (err) {
return callback(err);
}
@@ -323,12 +323,12 @@ module.exports = function(redisClient, module) {
});
};
- module.getSortedSetIntersect = function(params, callback) {
+ module.getSortedSetIntersect = function (params, callback) {
params.method = 'zrange';
getSortedSetRevIntersect(params, callback);
};
- module.getSortedSetRevIntersect = function(params, callback) {
+ module.getSortedSetRevIntersect = function (params, callback) {
params.method = 'zrevrange';
getSortedSetRevIntersect(params, callback);
};
@@ -359,7 +359,7 @@ module.exports = function(redisClient, module) {
multi.zinterstore(interParams);
multi[params.method](rangeParams);
multi.del(tempSetName);
- multi.exec(function(err, results) {
+ multi.exec(function (err, results) {
if (err) {
return callback(err);
}
diff --git a/src/emailer.js b/src/emailer.js
index 27c64c4986..4196fbb333 100644
--- a/src/emailer.js
+++ b/src/emailer.js
@@ -23,8 +23,8 @@ var transports = {
var app;
var fallbackTransport;
-(function(Emailer) {
- Emailer.registerApp = function(expressApp) {
+(function (Emailer) {
+ Emailer.registerApp = function (expressApp) {
app = expressApp;
// Enable Gmail transport if enabled in ACP
@@ -45,21 +45,21 @@ var fallbackTransport;
return Emailer;
};
- Emailer.send = function(template, uid, params, callback) {
- callback = callback || function() {};
+ Emailer.send = function (template, uid, params, callback) {
+ callback = callback || function () {};
if (!app) {
winston.warn('[emailer] App not ready!');
return callback();
}
async.waterfall([
- function(next) {
+ function (next) {
async.parallel({
email: async.apply(User.getUserField, uid, 'email'),
settings: async.apply(User.getSettings, uid)
}, next);
},
- function(results, next) {
+ function (results, next) {
if (!results.email) {
winston.warn('uid : ' + uid + ' has no email, not sending.');
return next();
@@ -70,19 +70,19 @@ var fallbackTransport;
], callback);
};
- Emailer.sendToEmail = function(template, email, language, params, callback) {
- callback = callback || function() {};
+ Emailer.sendToEmail = function (template, email, language, params, callback) {
+ callback = callback || function () {};
var lang = language || meta.config.defaultLang || 'en_GB';
async.waterfall([
function (next) {
async.parallel({
- html: function(next) {
+ html: function (next) {
renderAndTranslate('emails/' + template, params, lang, next);
},
- subject: function(next) {
- translator.translate(params.subject, lang, function(translated) {
+ subject: function (next) {
+ translator.translate(params.subject, lang, function (translated) {
next(null, translated);
});
}
@@ -122,7 +122,7 @@ var fallbackTransport;
});
};
- Emailer.sendViaFallback = function(data, callback) {
+ Emailer.sendViaFallback = function (data, callback) {
// Some minor alterations to the data to conform to nodemailer standard
data.text = data.plaintext;
delete data.plaintext;
@@ -145,8 +145,8 @@ var fallbackTransport;
}
function renderAndTranslate(tpl, params, lang, callback) {
- render(tpl, params, function(err, html) {
- translator.translate(html, lang, function(translated) {
+ render(tpl, params, function (err, html) {
+ translator.translate(html, lang, function (translated) {
callback(err, translated);
});
});
diff --git a/src/emitter.js b/src/emitter.js
index 468f604aaf..ca262257b7 100644
--- a/src/emitter.js
+++ b/src/emitter.js
@@ -3,11 +3,11 @@
var eventEmitter = new (require('events')).EventEmitter();
-eventEmitter.all = function(events, callback) {
+eventEmitter.all = function (events, callback) {
var eventList = events.slice(0);
events.forEach(function onEvent(event) {
- eventEmitter.on(event, function() {
+ eventEmitter.on(event, function () {
var index = eventList.indexOf(event);
if (index === -1) {
return;
@@ -20,9 +20,9 @@ eventEmitter.all = function(events, callback) {
});
};
-eventEmitter.any = function(events, callback) {
+eventEmitter.any = function (events, callback) {
events.forEach(function onEvent(event) {
- eventEmitter.on(event, function() {
+ eventEmitter.on(event, function () {
if (events !== null) {
callback();
}
diff --git a/src/events.js b/src/events.js
index 9767f9093a..cc1260bcef 100644
--- a/src/events.js
+++ b/src/events.js
@@ -9,52 +9,52 @@ var batch = require('./batch');
var user = require('./user');
var utils = require('../public/src/utils');
-(function(events) {
- events.log = function(data, callback) {
- callback = callback || function() {};
+(function (events) {
+ events.log = function (data, callback) {
+ callback = callback || function () {};
async.waterfall([
- function(next) {
+ function (next) {
db.incrObjectField('global', 'nextEid', next);
},
- function(eid, next) {
+ function (eid, next) {
data.timestamp = Date.now();
data.eid = eid;
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetAdd('events:time', data.timestamp, eid, next);
},
- function(next) {
+ function (next) {
db.setObject('event:' + eid, data, next);
}
], next);
}
- ], function(err, result) {
+ ], function (err, result) {
callback(err);
});
};
- events.getEvents = function(start, stop, callback) {
+ events.getEvents = function (start, stop, callback) {
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRevRange('events:time', start, stop, next);
},
- function(eids, next) {
- var keys = eids.map(function(eid) {
+ function (eids, next) {
+ var keys = eids.map(function (eid) {
return 'event:' + eid;
});
db.getObjects(keys, next);
},
- function(eventsData, next) {
+ function (eventsData, next) {
addUserData(eventsData, 'uid', 'user', next);
},
- function(eventsData, next) {
+ function (eventsData, next) {
addUserData(eventsData, 'targetUid', 'targetUser', next);
},
- function(eventsData, next) {
- eventsData.forEach(function(event) {
- Object.keys(event).forEach(function(key) {
+ function (eventsData, next) {
+ eventsData.forEach(function (event) {
+ Object.keys(event).forEach(function (key) {
if (typeof event[key] === 'string') {
event[key] = validator.escape(String(event[key] || ''));
}
@@ -70,9 +70,9 @@ var utils = require('../public/src/utils');
};
function addUserData(eventsData, field, objectName, callback) {
- var uids = eventsData.map(function(event) {
+ var uids = eventsData.map(function (event) {
return event && event[field];
- }).filter(function(uid, index, array) {
+ }).filter(function (uid, index, array) {
return uid && array.indexOf(uid) === index;
});
@@ -81,13 +81,13 @@ var utils = require('../public/src/utils');
}
async.parallel({
- isAdmin: function(next) {
+ isAdmin: function (next) {
user.isAdministrator(uids, next);
},
- userData: function(next) {
+ userData: function (next) {
user.getUsersFields(uids, ['username', 'userslug', 'picture'], next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -95,12 +95,12 @@ var utils = require('../public/src/utils');
var userData = results.userData;
var map = {};
- userData.forEach(function(user, index) {
+ userData.forEach(function (user, index) {
user.isAdmin = results.isAdmin[index];
map[user.uid] = user;
});
- eventsData.forEach(function(event) {
+ eventsData.forEach(function (event) {
if (map[event[field]]) {
event[objectName] = map[event[field]];
}
@@ -109,25 +109,25 @@ var utils = require('../public/src/utils');
});
}
- events.deleteEvents = function(eids, callback) {
- callback = callback || function() {};
+ events.deleteEvents = function (eids, callback) {
+ callback = callback || function () {};
async.parallel([
- function(next) {
- var keys = eids.map(function(eid) {
+ function (next) {
+ var keys = eids.map(function (eid) {
return 'event:' + eid;
});
db.deleteAll(keys, next);
},
- function(next) {
+ function (next) {
db.sortedSetRemove('events:time', eids, next);
}
], callback);
};
- events.deleteAll = function(callback) {
- callback = callback || function() {};
+ events.deleteAll = function (callback) {
+ callback = callback || function () {};
- batch.processSortedSet('events:time', function(eids, next) {
+ batch.processSortedSet('events:time', function (eids, next) {
events.deleteEvents(eids, next);
}, {alwaysStartAt: 0}, callback);
};
diff --git a/src/file.js b/src/file.js
index c744d56035..df820cc47f 100644
--- a/src/file.js
+++ b/src/file.js
@@ -10,12 +10,12 @@ var utils = require('../public/src/utils');
var file = {};
-file.saveFileToLocal = function(filename, folder, tempPath, callback) {
+file.saveFileToLocal = function (filename, folder, tempPath, callback) {
/*
* remarkable doesn't allow spaces in hyperlinks, once that's fixed, remove this.
*/
filename = filename.split('.');
- filename.forEach(function(name, idx) {
+ filename.forEach(function (name, idx) {
filename[idx] = utils.slugify(name);
});
filename = filename.join('.');
@@ -38,39 +38,39 @@ file.saveFileToLocal = function(filename, folder, tempPath, callback) {
is.pipe(os);
};
-file.base64ToLocal = function(imageData, uploadPath, callback) {
+file.base64ToLocal = function (imageData, uploadPath, callback) {
var buffer = new Buffer(imageData.slice(imageData.indexOf('base64') + 7), 'base64');
uploadPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), uploadPath);
fs.writeFile(uploadPath, buffer, {
encoding: 'base64'
- }, function(err) {
+ }, function (err) {
callback(err, uploadPath);
});
};
-file.isFileTypeAllowed = function(path, callback) {
+file.isFileTypeAllowed = function (path, callback) {
var plugins = require('./plugins');
if (plugins.hasListeners('filter:file.isFileTypeAllowed')) {
- return plugins.fireHook('filter:file.isFileTypeAllowed', path, function(err) {
+ return plugins.fireHook('filter:file.isFileTypeAllowed', path, function (err) {
callback(err);
});
}
// Attempt to read the file, if it passes, file type is allowed
- jimp.read(path, function(err) {
+ jimp.read(path, function (err) {
callback(err);
});
};
-file.allowedExtensions = function() {
+file.allowedExtensions = function () {
var meta = require('./meta');
var allowedExtensions = (meta.config.allowedFileExtensions || '').trim();
if (!allowedExtensions) {
return [];
}
allowedExtensions = allowedExtensions.split(',');
- allowedExtensions = allowedExtensions.filter(Boolean).map(function(extension) {
+ allowedExtensions = allowedExtensions.filter(Boolean).map(function (extension) {
extension = extension.trim();
if (!extension.startsWith('.')) {
extension = '.' + extension;
@@ -85,13 +85,13 @@ file.allowedExtensions = function() {
return allowedExtensions;
};
-file.exists = function(path, callback) {
- fs.stat(path, function(err, stat) {
+file.exists = function (path, callback) {
+ fs.stat(path, function (err, stat) {
callback(!err && stat);
});
};
-file.existsSync = function(path) {
+file.existsSync = function (path) {
var exists = false;
try {
exists = fs.statSync(path);
diff --git a/src/groups.js b/src/groups.js
index 0c3319d8c6..7d71a6e0fa 100644
--- a/src/groups.js
+++ b/src/groups.js
@@ -10,7 +10,7 @@ var posts = require('./posts');
var privileges = require('./privileges');
var utils = require('../public/src/utils');
-(function(Groups) {
+(function (Groups) {
require('./groups/create')(Groups);
require('./groups/delete')(Groups);
@@ -23,7 +23,7 @@ var utils = require('../public/src/utils');
var ephemeralGroups = ['guests'],
internals = {
- getEphemeralGroup: function(groupName) {
+ getEphemeralGroup: function (groupName) {
return {
name: groupName,
slug: utils.slugify(groupName),
@@ -33,7 +33,7 @@ var utils = require('../public/src/utils');
system: '1'
};
},
- removeEphemeralGroups: function(groups) {
+ removeEphemeralGroups: function (groups) {
var x = groups.length;
while(x--) {
if (ephemeralGroups.indexOf(groups[x]) !== -1) {
@@ -48,15 +48,15 @@ var utils = require('../public/src/utils');
Groups.internals = internals;
var isPrivilegeGroupRegex = /^cid:\d+:privileges:[\w:]+$/;
- Groups.isPrivilegeGroup = function(groupName) {
+ Groups.isPrivilegeGroup = function (groupName) {
return isPrivilegeGroupRegex.test(groupName);
};
- Groups.getEphemeralGroups = function() {
+ Groups.getEphemeralGroups = function () {
return ephemeralGroups;
};
- Groups.getGroupsFromSet = function(set, uid, start, stop, callback) {
+ Groups.getGroupsFromSet = function (set, uid, start, stop, callback) {
var method;
var args;
if (set === 'groups:visible:name') {
@@ -74,7 +74,7 @@ var utils = require('../public/src/utils');
}
if (set === 'groups:visible:name') {
- groupNames = groupNames.map(function(name) {
+ groupNames = groupNames.map(function (name) {
return name.split(':')[1];
});
}
@@ -83,16 +83,16 @@ var utils = require('../public/src/utils');
}
};
- Groups.getGroups = function(set, start, stop, callback) {
+ Groups.getGroups = function (set, start, stop, callback) {
db.getSortedSetRevRange(set, start, stop, callback);
};
- Groups.getGroupsAndMembers = function(groupNames, callback) {
+ Groups.getGroupsAndMembers = function (groupNames, callback) {
async.parallel({
- groups: function(next) {
+ groups: function (next) {
Groups.getGroupsData(groupNames, next);
},
- members: function(next) {
+ members: function (next) {
Groups.getMemberUsers(groupNames, 0, 3, next);
}
}, function (err, data) {
@@ -100,7 +100,7 @@ var utils = require('../public/src/utils');
return callback(err);
}
- data.groups.forEach(function(group, index) {
+ data.groups.forEach(function (group, index) {
if (!group) {
return;
}
@@ -113,7 +113,7 @@ var utils = require('../public/src/utils');
});
};
- Groups.get = function(groupName, options, callback) {
+ Groups.get = function (groupName, options, callback) {
if (!groupName) {
return callback(new Error('[[error:invalid-group]]'));
}
@@ -133,20 +133,20 @@ var utils = require('../public/src/utils');
},
pending: function (next) {
async.waterfall([
- function(next) {
+ function (next) {
db.getSetMembers('group:' + groupName + ':pending', next);
},
- function(uids, next) {
+ function (uids, next) {
user.getUsersData(uids, next);
}
], next);
},
invited: function (next) {
async.waterfall([
- function(next) {
+ function (next) {
db.getSetMembers('group:' + groupName + ':invited', next);
},
- function(uids, next) {
+ function (uids, next) {
user.getUsersData(uids, next);
}
], next);
@@ -165,7 +165,7 @@ var utils = require('../public/src/utils');
results.base['cover:url'] = results.base['cover:url'] || require('./coverPhoto').getDefaultGroupCover(groupName);
results.base['cover:position'] = results.base['cover:position'] || '50% 50%';
- plugins.fireHook('filter:parse.raw', results.base.description, function(err, descriptionParsed) {
+ plugins.fireHook('filter:parse.raw', results.base.description, function (err, descriptionParsed) {
if (err) {
return callback(err);
}
@@ -190,25 +190,25 @@ var utils = require('../public/src/utils');
results.base.isInvited = results.isInvited;
results.base.isOwner = results.isOwner;
- plugins.fireHook('filter:group.get', {group: results.base}, function(err, data) {
+ plugins.fireHook('filter:group.get', {group: results.base}, function (err, data) {
callback(err, data ? data.group : null);
});
});
});
};
- Groups.getOwners = function(groupName, callback) {
+ Groups.getOwners = function (groupName, callback) {
db.getSetMembers('group:' + groupName + ':owners', callback);
};
- Groups.getOwnersAndMembers = function(groupName, uid, start, stop, callback) {
+ Groups.getOwnersAndMembers = function (groupName, uid, start, stop, callback) {
async.parallel({
owners: function (next) {
async.waterfall([
- function(next) {
+ function (next) {
db.getSetMembers('group:' + groupName + ':owners', next);
},
- function(uids, next) {
+ function (uids, next) {
user.getUsers(uids, uid, next);
}
], next);
@@ -216,20 +216,20 @@ var utils = require('../public/src/utils');
members: function (next) {
user.getUsersFromSet('group:' + groupName + ':members', uid, start, stop, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
var ownerUids = [];
- results.owners.forEach(function(user) {
+ results.owners.forEach(function (user) {
if (user) {
user.isOwner = true;
ownerUids.push(user.uid.toString());
}
});
- results.members = results.members.filter(function(user) {
+ results.members = results.members.filter(function (user) {
return user && user.uid && ownerUids.indexOf(user.uid.toString()) === -1;
});
results.members = results.owners.concat(results.members);
@@ -238,7 +238,7 @@ var utils = require('../public/src/utils');
});
};
- Groups.escapeGroupData = function(group) {
+ Groups.escapeGroupData = function (group) {
if (group) {
group.nameEncoded = encodeURIComponent(group.name);
group.displayName = validator.escape(String(group.name));
@@ -247,8 +247,8 @@ var utils = require('../public/src/utils');
}
};
- Groups.getByGroupslug = function(slug, options, callback) {
- db.getObjectField('groupslug:groupname', slug, function(err, groupName) {
+ Groups.getByGroupslug = function (slug, options, callback) {
+ db.getObjectField('groupslug:groupname', slug, function (err, groupName) {
if (err) {
return callback(err);
} else if (!groupName) {
@@ -259,24 +259,24 @@ var utils = require('../public/src/utils');
});
};
- Groups.getGroupNameByGroupSlug = function(slug, callback) {
+ Groups.getGroupNameByGroupSlug = function (slug, callback) {
db.getObjectField('groupslug:groupname', slug, callback);
};
- Groups.getGroupFields = function(groupName, fields, callback) {
- Groups.getMultipleGroupFields([groupName], fields, function(err, groups) {
+ Groups.getGroupFields = function (groupName, fields, callback) {
+ Groups.getMultipleGroupFields([groupName], fields, function (err, groups) {
callback(err, groups ? groups[0] : null);
});
};
- Groups.getMultipleGroupFields = function(groups, fields, callback) {
- db.getObjectsFields(groups.map(function(group) {
+ Groups.getMultipleGroupFields = function (groups, fields, callback) {
+ db.getObjectsFields(groups.map(function (group) {
return 'group:' + group;
}), fields, callback);
};
- Groups.setGroupField = function(groupName, field, value, callback) {
- db.setObjectField('group:' + groupName, field, value, function(err) {
+ Groups.setGroupField = function (groupName, field, value, callback) {
+ db.setObjectField('group:' + groupName, field, value, function (err) {
if (err) {
return callback(err);
}
@@ -285,8 +285,8 @@ var utils = require('../public/src/utils');
});
};
- Groups.isPrivate = function(groupName, callback) {
- db.getObjectField('group:' + groupName, 'private', function(err, isPrivate) {
+ Groups.isPrivate = function (groupName, callback) {
+ db.getObjectField('group:' + groupName, 'private', function (err, isPrivate) {
if (err) {
return callback(err);
}
@@ -295,8 +295,8 @@ var utils = require('../public/src/utils');
});
};
- Groups.isHidden = function(groupName, callback) {
- db.getObjectField(groupName, 'hidden', function(err, isHidden) {
+ Groups.isHidden = function (groupName, callback) {
+ db.getObjectField(groupName, 'hidden', function (err, isHidden) {
if (err) {
return callback(err);
}
@@ -305,23 +305,23 @@ var utils = require('../public/src/utils');
});
};
- Groups.exists = function(name, callback) {
+ Groups.exists = function (name, callback) {
if (Array.isArray(name)) {
- var slugs = name.map(function(groupName) {
+ var slugs = name.map(function (groupName) {
return utils.slugify(groupName);
});
async.parallel([
function (next) {
- next(null, slugs.map(function(slug) {
+ next(null, slugs.map(function (slug) {
return ephemeralGroups.indexOf(slug) !== -1;
}));
},
async.apply(db.isSortedSetMembers, 'groups:createtime', name)
- ], function(err, results) {
+ ], function (err, results) {
if (err) {
return callback(err);
}
- callback(null, name.map(function(n, index) {
+ callback(null, name.map(function (n, index) {
return results[0][index] || results[1][index];
}));
});
@@ -332,13 +332,13 @@ var utils = require('../public/src/utils');
next(null, ephemeralGroups.indexOf(slug) !== -1);
},
async.apply(db.isSortedSetMember, 'groups:createtime', name)
- ], function(err, results) {
+ ], function (err, results) {
callback(err, !err ? (results[0] || results[1]) : null);
});
}
};
- Groups.existsBySlug = function(slug, callback) {
+ Groups.existsBySlug = function (slug, callback) {
if (Array.isArray(slug)) {
db.isObjectFields('groupslug:groupname', slug, callback);
} else {
@@ -346,63 +346,63 @@ var utils = require('../public/src/utils');
}
};
- Groups.getLatestMemberPosts = function(groupName, max, uid, callback) {
+ Groups.getLatestMemberPosts = function (groupName, max, uid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
Groups.getMembers(groupName, 0, -1, next);
},
- function(uids, next) {
+ function (uids, next) {
if (!Array.isArray(uids) || !uids.length) {
return callback(null, []);
}
- var keys = uids.map(function(uid) {
+ var keys = uids.map(function (uid) {
return 'uid:' + uid + ':posts';
});
db.getSortedSetRevRange(keys, 0, max - 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: false}, next);
}
], callback);
};
- Groups.getGroupData = function(groupName, callback) {
- Groups.getGroupsData([groupName], function(err, groupsData) {
+ Groups.getGroupData = function (groupName, callback) {
+ Groups.getGroupsData([groupName], function (err, groupsData) {
callback(err, Array.isArray(groupsData) && groupsData[0] ? groupsData[0] : null);
});
};
- Groups.getGroupsData = function(groupNames, callback) {
+ Groups.getGroupsData = function (groupNames, callback) {
if (!Array.isArray(groupNames) || !groupNames.length) {
return callback(null, []);
}
- var keys = groupNames.map(function(groupName) {
+ var keys = groupNames.map(function (groupName) {
return 'group:' + groupName;
});
- var ephemeralIdx = groupNames.reduce(function(memo, cur, idx) {
+ var ephemeralIdx = groupNames.reduce(function (memo, cur, idx) {
if (ephemeralGroups.indexOf(cur) !== -1) {
memo.push(idx);
}
return memo;
}, []);
- db.getObjects(keys, function(err, groupData) {
+ db.getObjects(keys, function (err, groupData) {
if (err) {
return callback(err);
}
if (ephemeralIdx.length) {
- ephemeralIdx.forEach(function(idx) {
+ ephemeralIdx.forEach(function (idx) {
groupData[idx] = internals.getEphemeralGroup(groupNames[idx]);
});
}
- groupData.forEach(function(group) {
+ groupData.forEach(function (group) {
if (group) {
Groups.escapeGroupData(group);
group.userTitleEnabled = group.userTitleEnabled ? parseInt(group.userTitleEnabled, 10) === 1 : true;
@@ -419,34 +419,34 @@ var utils = require('../public/src/utils');
}
});
- plugins.fireHook('filter:groups.get', {groups: groupData}, function(err, data) {
+ plugins.fireHook('filter:groups.get', {groups: groupData}, function (err, data) {
callback(err, data ? data.groups : null);
});
});
};
- Groups.getUserGroups = function(uids, callback) {
+ Groups.getUserGroups = function (uids, callback) {
Groups.getUserGroupsFromSet('groups:visible:createtime', uids, callback);
};
Groups.getUserGroupsFromSet = function (set, uids, callback) {
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRevRange(set, 0, -1, next);
},
- function(groupNames, next) {
- var groupSets = groupNames.map(function(name) {
+ function (groupNames, next) {
+ var groupSets = groupNames.map(function (name) {
return 'group:' + name + ':members';
});
- async.map(uids, function(uid, next) {
- db.isMemberOfSortedSets(groupSets, uid, function(err, isMembers) {
+ async.map(uids, function (uid, next) {
+ db.isMemberOfSortedSets(groupSets, uid, function (err, isMembers) {
if (err) {
return next(err);
}
var memberOf = [];
- isMembers.forEach(function(isMember, index) {
+ isMembers.forEach(function (isMember, index) {
if (isMember) {
memberOf.push(groupNames[index]);
}
diff --git a/src/groups/cover.js b/src/groups/cover.js
index a8a771130d..f2ed4e05ea 100644
--- a/src/groups/cover.js
+++ b/src/groups/cover.js
@@ -13,16 +13,16 @@ var db = require('../database');
var file = require('../file');
var uploadsController = require('../controllers/uploads');
-module.exports = function(Groups) {
+module.exports = function (Groups) {
- Groups.updateCoverPosition = function(groupName, position, callback) {
+ Groups.updateCoverPosition = function (groupName, position, callback) {
if (!groupName) {
return callback(new Error('[[error:invalid-data]]'));
}
Groups.setGroupField(groupName, 'cover:position', position, callback);
};
- Groups.updateCover = function(uid, data, callback) {
+ Groups.updateCover = function (uid, data, callback) {
// Position only? That's fine
if (!data.imageData && data.position) {
@@ -70,7 +70,7 @@ module.exports = function(Groups) {
}
], function (err) {
if (err) {
- return fs.unlink(tempPath, function(unlinkErr) {
+ return fs.unlink(tempPath, function (unlinkErr) {
if (unlinkErr) {
winston.error(unlinkErr);
}
@@ -80,7 +80,7 @@ module.exports = function(Groups) {
}
if (data.position) {
- Groups.updateCoverPosition(data.groupName, data.position, function(err) {
+ Groups.updateCoverPosition(data.groupName, data.position, function (err) {
callback(err, {url: url});
});
} else {
@@ -118,12 +118,12 @@ module.exports = function(Groups) {
fs.writeFile(tempPath, buffer, {
encoding: 'base64'
- }, function(err) {
+ }, function (err) {
callback(err, tempPath);
});
}
- Groups.removeCover = function(data, callback) {
+ Groups.removeCover = function (data, callback) {
db.deleteObjectFields('group:' + data.groupName, ['cover:url', 'cover:thumb:url'], callback);
};
diff --git a/src/groups/create.js b/src/groups/create.js
index ffbaf97448..b5864e5c44 100644
--- a/src/groups/create.js
+++ b/src/groups/create.js
@@ -6,9 +6,9 @@ var plugins = require('../plugins');
var utils = require('../../public/src/utils');
var db = require('../database');
-module.exports = function(Groups) {
+module.exports = function (Groups) {
- Groups.create = function(data, callback) {
+ Groups.create = function (data, callback) {
var system = data.system === true || parseInt(data.system, 10) === 1 ||
data.name === 'administrators' || data.name === 'registered-users' || data.name === 'Global Moderators' ||
Groups.isPrivilegeGroup(data.name);
diff --git a/src/groups/delete.js b/src/groups/delete.js
index af79757e9c..0838dd2407 100644
--- a/src/groups/delete.js
+++ b/src/groups/delete.js
@@ -5,10 +5,10 @@ var plugins = require('../plugins');
var utils = require('../../public/src/utils');
var db = require('./../database');
-module.exports = function(Groups) {
+module.exports = function (Groups) {
- Groups.destroy = function(groupName, callback) {
- Groups.getGroupsData([groupName], function(err, groupsData) {
+ Groups.destroy = function (groupName, callback) {
+ Groups.getGroupsData([groupName], function (err, groupsData) {
if (err) {
return callback(err);
}
@@ -30,17 +30,17 @@ module.exports = function(Groups) {
async.apply(db.delete, 'group:' + groupName + ':invited'),
async.apply(db.delete, 'group:' + groupName + ':owners'),
async.apply(db.deleteObjectField, 'groupslug:groupname', utils.slugify(groupName)),
- function(next) {
- db.getSortedSetRange('groups:createtime', 0, -1, function(err, groups) {
+ function (next) {
+ db.getSortedSetRange('groups:createtime', 0, -1, function (err, groups) {
if (err) {
return next(err);
}
- async.each(groups, function(group, next) {
+ async.each(groups, function (group, next) {
db.sortedSetRemove('group:' + group + ':members', groupName, next);
}, next);
});
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
diff --git a/src/groups/membership.js b/src/groups/membership.js
index d558b63004..d03dba3e59 100644
--- a/src/groups/membership.js
+++ b/src/groups/membership.js
@@ -18,28 +18,28 @@ var cache = LRU({
maxAge: 1000 * 60 * 60
});
-module.exports = function(Groups) {
+module.exports = function (Groups) {
Groups.cache = cache;
- Groups.join = function(groupName, uid, callback) {
- callback = callback || function() {};
+ Groups.join = function (groupName, uid, callback) {
+ callback = callback || function () {};
if (!groupName) {
return callback(new Error('[[error:invalid-data]]'));
}
async.waterfall([
- function(next) {
+ function (next) {
Groups.isMember(uid, groupName, next);
},
- function(isMember, next) {
+ function (isMember, next) {
if (isMember) {
return callback();
}
Groups.exists(groupName, next);
},
- function(exists, next) {
+ function (exists, next) {
if (exists) {
return next();
}
@@ -47,7 +47,7 @@ module.exports = function(Groups) {
name: groupName,
description: '',
hidden: 1
- }, function(err) {
+ }, function (err) {
if (err && err.message !== '[[error:group-already-exists]]') {
winston.error('[groups.join] Could not create new hidden group: ' + err.message);
return callback(err);
@@ -55,17 +55,17 @@ module.exports = function(Groups) {
next();
});
},
- function(next) {
+ function (next) {
async.parallel({
- isAdmin: function(next) {
+ isAdmin: function (next) {
user.isAdministrator(uid, next);
},
- isHidden: function(next) {
+ isHidden: function (next) {
Groups.isHidden(groupName, next);
}
}, next);
},
- function(results, next) {
+ function (results, next) {
var tasks = [
async.apply(db.sortedSetAdd, 'group:' + groupName + ':members', Date.now(), uid),
async.apply(db.incrObjectField, 'group:' + groupName, 'memberCount')
@@ -78,11 +78,11 @@ module.exports = function(Groups) {
}
async.parallel(tasks, next);
},
- function(results, next) {
+ function (results, next) {
clearCache(uid, groupName);
setGroupTitleIfNotSet(groupName, uid, next);
},
- function(next) {
+ function (next) {
plugins.fireHook('action:group.join', {
groupName: groupName,
uid: uid
@@ -97,7 +97,7 @@ module.exports = function(Groups) {
return callback();
}
- db.getObjectField('user:' + uid, 'groupTitle', function(err, currentTitle) {
+ db.getObjectField('user:' + uid, 'groupTitle', function (err, currentTitle) {
if (err || (currentTitle || currentTitle === '')) {
return callback(err);
}
@@ -106,7 +106,7 @@ module.exports = function(Groups) {
});
}
- Groups.requestMembership = function(groupName, uid, callback) {
+ Groups.requestMembership = function (groupName, uid, callback) {
async.waterfall([
async.apply(inviteOrRequestMembership, groupName, uid, 'request'),
function (next) {
@@ -114,7 +114,7 @@ module.exports = function(Groups) {
},
function (username, next) {
async.parallel({
- notification: function(next) {
+ notification: function (next) {
notifications.create({
bodyShort: '[[groups:request.notification_title, ' + username + ']]',
bodyLong: '[[groups:request.notification_text, ' + username + ', ' + groupName + ']]',
@@ -123,7 +123,7 @@ module.exports = function(Groups) {
from: uid
}, next);
},
- owners: function(next) {
+ owners: function (next) {
Groups.getOwners(groupName, next);
}
}, next);
@@ -137,7 +137,7 @@ module.exports = function(Groups) {
], callback);
};
- Groups.acceptMembership = function(groupName, uid, callback) {
+ Groups.acceptMembership = function (groupName, uid, callback) {
// Note: For simplicity, this method intentially doesn't check the caller uid for ownership!
async.waterfall([
async.apply(db.setRemove, 'group:' + groupName + ':pending', uid),
@@ -146,7 +146,7 @@ module.exports = function(Groups) {
], callback);
};
- Groups.rejectMembership = function(groupName, uid, callback) {
+ Groups.rejectMembership = function (groupName, uid, callback) {
// Note: For simplicity, this method intentially doesn't check the caller uid for ownership!
async.parallel([
async.apply(db.setRemove, 'group:' + groupName + ':pending', uid),
@@ -154,7 +154,7 @@ module.exports = function(Groups) {
], callback);
};
- Groups.invite = function(groupName, uid, callback) {
+ Groups.invite = function (groupName, uid, callback) {
async.waterfall([
async.apply(inviteOrRequestMembership, groupName, uid, 'invite'),
async.apply(notifications.create, {
@@ -177,7 +177,7 @@ module.exports = function(Groups) {
var set = type === 'invite' ? 'group:' + groupName + ':invited' : 'group:' + groupName + ':pending';
async.waterfall([
- function(next) {
+ function (next) {
async.parallel({
exists: async.apply(Groups.exists, groupName),
isMember: async.apply(Groups.isMember, uid, groupName),
@@ -185,7 +185,7 @@ module.exports = function(Groups) {
isInvited: async.apply(Groups.isInvited, uid, groupName)
}, next);
},
- function(checks, next) {
+ function (checks, next) {
if (!checks.exists) {
return next(new Error('[[error:no-group]]'));
} else if (checks.isMember) {
@@ -198,7 +198,7 @@ module.exports = function(Groups) {
db.setAdd(set, uid, next);
},
- function(next) {
+ function (next) {
plugins.fireHook(hookName, {
groupName: groupName,
uid: uid
@@ -208,21 +208,21 @@ module.exports = function(Groups) {
], callback);
}
- Groups.leave = function(groupName, uid, callback) {
- callback = callback || function() {};
+ Groups.leave = function (groupName, uid, callback) {
+ callback = callback || function () {};
async.waterfall([
- function(next) {
+ function (next) {
Groups.isMember(uid, groupName, next);
},
- function(isMember, next) {
+ function (isMember, next) {
if (!isMember) {
return callback();
}
Groups.exists(groupName, next);
},
- function(exists, next) {
+ function (exists, next) {
if (!exists) {
return callback();
}
@@ -232,11 +232,11 @@ module.exports = function(Groups) {
async.apply(db.decrObjectField, 'group:' + groupName, 'memberCount')
], next);
},
- function(results, next) {
+ function (results, next) {
clearCache(uid, groupName);
Groups.getGroupFields(groupName, ['hidden', 'memberCount'], next);
},
- function(groupData, next) {
+ function (groupData, next) {
if (!groupData) {
return callback();
}
@@ -250,7 +250,7 @@ module.exports = function(Groups) {
}
}
},
- function(next) {
+ function (next) {
plugins.fireHook('action:group.leave', {
groupName: groupName,
uid: uid
@@ -260,16 +260,16 @@ module.exports = function(Groups) {
], callback);
};
- Groups.leaveAllGroups = function(uid, callback) {
+ Groups.leaveAllGroups = function (uid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRange('groups:createtime', 0, -1, next);
},
- function(groups, next) {
- async.each(groups, function(groupName, next) {
+ function (groups, next) {
+ async.each(groups, function (groupName, next) {
async.parallel([
- function(next) {
- Groups.isMember(uid, groupName, function(err, isMember) {
+ function (next) {
+ Groups.isMember(uid, groupName, function (err, isMember) {
if (!err && isMember) {
Groups.leave(groupName, uid, next);
} else {
@@ -277,7 +277,7 @@ module.exports = function(Groups) {
}
});
},
- function(next) {
+ function (next) {
Groups.rejectMembership(groupName, uid, next);
}
], next);
@@ -286,13 +286,13 @@ module.exports = function(Groups) {
], callback);
};
- Groups.getMembers = function(groupName, start, stop, callback) {
+ Groups.getMembers = function (groupName, start, stop, callback) {
db.getSortedSetRevRange('group:' + groupName + ':members', start, stop, callback);
};
- Groups.getMemberUsers = function(groupNames, start, stop, callback) {
- async.map(groupNames, function(groupName, next) {
- Groups.getMembers(groupName, start, stop, function(err, uids) {
+ Groups.getMemberUsers = function (groupNames, start, stop, callback) {
+ async.map(groupNames, function (groupName, next) {
+ Groups.getMembers(groupName, start, stop, function (err, uids) {
if (err) {
return next(err);
}
@@ -302,18 +302,18 @@ module.exports = function(Groups) {
}, callback);
};
- Groups.getMembersOfGroups = function(groupNames, callback) {
- db.getSortedSetsMembers(groupNames.map(function(name) {
+ Groups.getMembersOfGroups = function (groupNames, callback) {
+ db.getSortedSetsMembers(groupNames.map(function (name) {
return 'group:' + name + ':members';
}), callback);
};
- Groups.resetCache = function() {
+ Groups.resetCache = function () {
pubsub.publish('group:cache:reset');
cache.reset();
};
- pubsub.on('group:cache:reset', function() {
+ pubsub.on('group:cache:reset', function () {
cache.reset();
});
@@ -322,11 +322,11 @@ module.exports = function(Groups) {
cache.del(uid + ':' + groupName);
}
- pubsub.on('group:cache:del', function(data) {
+ pubsub.on('group:cache:del', function (data) {
cache.del(data.uid + ':' + data.groupName);
});
- Groups.isMember = function(uid, groupName, callback) {
+ Groups.isMember = function (uid, groupName, callback) {
if (!uid || parseInt(uid, 10) <= 0) {
return callback(null, false);
}
@@ -336,7 +336,7 @@ module.exports = function(Groups) {
return process.nextTick(callback, null, cache.get(cacheKey));
}
- db.isSortedSetMember('group:' + groupName + ':members', uid, function(err, isMember) {
+ db.isSortedSetMember('group:' + groupName + ':members', uid, function (err, isMember) {
if (err) {
return callback(err);
}
@@ -346,35 +346,35 @@ module.exports = function(Groups) {
});
};
- Groups.isMembers = function(uids, groupName, callback) {
+ Groups.isMembers = function (uids, groupName, callback) {
if (!groupName || !uids.length) {
- return callback(null, uids.map(function() {return false;}));
+ return callback(null, uids.map(function () {return false;}));
}
var nonCachedUids = [];
- uids.forEach(function(uid) {
+ uids.forEach(function (uid) {
if (!cache.has(uid + ':' + groupName)) {
nonCachedUids.push(uid);
}
});
if (!nonCachedUids.length) {
- var result = uids.map(function(uid) {
+ var result = uids.map(function (uid) {
return cache.get(uid + ':' + groupName);
});
return process.nextTick(callback, null, result);
}
- db.isSortedSetMembers('group:' + groupName + ':members', nonCachedUids, function(err, isMembers) {
+ db.isSortedSetMembers('group:' + groupName + ':members', nonCachedUids, function (err, isMembers) {
if (err) {
return callback(err);
}
- nonCachedUids.forEach(function(uid, index) {
+ nonCachedUids.forEach(function (uid, index) {
cache.set(uid + ':' + groupName, isMembers[index]);
});
- var result = uids.map(function(uid) {
+ var result = uids.map(function (uid) {
return cache.get(uid + ':' + groupName);
});
@@ -382,14 +382,14 @@ module.exports = function(Groups) {
});
};
- Groups.isMemberOfGroups = function(uid, groups, callback) {
+ Groups.isMemberOfGroups = function (uid, groups, callback) {
if (!uid || parseInt(uid, 10) <= 0 || !groups.length) {
- return callback(null, groups.map(function() {return false;}));
+ return callback(null, groups.map(function () {return false;}));
}
var nonCachedGroups = [];
- groups.forEach(function(groupName) {
+ groups.forEach(function (groupName) {
if (!cache.has(uid + ':' + groupName)) {
nonCachedGroups.push(groupName);
}
@@ -397,34 +397,34 @@ module.exports = function(Groups) {
// are they all cached?
if (!nonCachedGroups.length) {
- var result = groups.map(function(groupName) {
+ var result = groups.map(function (groupName) {
return cache.get(uid + ':' + groupName);
});
return process.nextTick(callback, null, result);
}
- var nonCachedGroupsMemberSets = nonCachedGroups.map(function(groupName) {
+ var nonCachedGroupsMemberSets = nonCachedGroups.map(function (groupName) {
return 'group:' + groupName + ':members';
});
- db.isMemberOfSortedSets(nonCachedGroupsMemberSets, uid, function(err, isMembers) {
+ db.isMemberOfSortedSets(nonCachedGroupsMemberSets, uid, function (err, isMembers) {
if (err) {
return callback(err);
}
- nonCachedGroups.forEach(function(groupName, index) {
+ nonCachedGroups.forEach(function (groupName, index) {
cache.set(uid + ':' + groupName, isMembers[index]);
});
- var result = groups.map(function(groupName) {
+ var result = groups.map(function (groupName) {
return cache.get(uid + ':' + groupName);
});
callback(null, result);
});
};
- Groups.getMemberCount = function(groupName, callback) {
- db.getObjectField('group:' + groupName, 'memberCount', function(err, count) {
+ Groups.getMemberCount = function (groupName, callback) {
+ db.getObjectField('group:' + groupName, 'memberCount', function (err, count) {
if (err) {
return callback(err);
}
@@ -432,8 +432,8 @@ module.exports = function(Groups) {
});
};
- Groups.isMemberOfGroupList = function(uid, groupListKey, callback) {
- db.getSortedSetRange('group:' + groupListKey + ':members', 0, -1, function(err, groupNames) {
+ Groups.isMemberOfGroupList = function (uid, groupListKey, callback) {
+ db.getSortedSetRange('group:' + groupListKey + ':members', 0, -1, function (err, groupNames) {
if (err) {
return callback(err);
}
@@ -442,7 +442,7 @@ module.exports = function(Groups) {
return callback(null, false);
}
- Groups.isMemberOfGroups(uid, groupNames, function(err, isMembers) {
+ Groups.isMemberOfGroups(uid, groupNames, function (err, isMembers) {
if (err) {
return callback(err);
}
@@ -452,12 +452,12 @@ module.exports = function(Groups) {
});
};
- Groups.isMemberOfGroupsList = function(uid, groupListKeys, callback) {
- var sets = groupListKeys.map(function(groupName) {
+ Groups.isMemberOfGroupsList = function (uid, groupListKeys, callback) {
+ var sets = groupListKeys.map(function (groupName) {
return 'group:' + groupName + ':members';
});
- db.getSortedSetsMembers(sets, function(err, members) {
+ db.getSortedSetsMembers(sets, function (err, members) {
if (err) {
return callback(err);
}
@@ -465,18 +465,18 @@ module.exports = function(Groups) {
var uniqueGroups = _.unique(_.flatten(members));
uniqueGroups = Groups.internals.removeEphemeralGroups(uniqueGroups);
- Groups.isMemberOfGroups(uid, uniqueGroups, function(err, isMembers) {
+ Groups.isMemberOfGroups(uid, uniqueGroups, function (err, isMembers) {
if (err) {
return callback(err);
}
var map = {};
- uniqueGroups.forEach(function(groupName, index) {
+ uniqueGroups.forEach(function (groupName, index) {
map[groupName] = isMembers[index];
});
- var result = members.map(function(groupNames) {
+ var result = members.map(function (groupNames) {
for (var i = 0; i < groupNames.length; ++i) {
if (map[groupNames[i]]) {
return true;
@@ -490,14 +490,14 @@ module.exports = function(Groups) {
});
};
- Groups.isMembersOfGroupList = function(uids, groupListKey, callback) {
- db.getSortedSetRange('group:' + groupListKey + ':members', 0, -1, function(err, groupNames) {
+ Groups.isMembersOfGroupList = function (uids, groupListKey, callback) {
+ db.getSortedSetRange('group:' + groupListKey + ':members', 0, -1, function (err, groupNames) {
if (err) {
return callback(err);
}
var results = [];
- uids.forEach(function() {
+ uids.forEach(function () {
results.push(false);
});
@@ -506,46 +506,46 @@ module.exports = function(Groups) {
return callback(null, results);
}
- async.each(groupNames, function(groupName, next) {
- Groups.isMembers(uids, groupName, function(err, isMembers) {
+ async.each(groupNames, function (groupName, next) {
+ Groups.isMembers(uids, groupName, function (err, isMembers) {
if (err) {
return next(err);
}
- results.forEach(function(isMember, index) {
+ results.forEach(function (isMember, index) {
if (!isMember && isMembers[index]) {
results[index] = true;
}
});
next();
});
- }, function(err) {
+ }, function (err) {
callback(err, results);
});
});
};
- Groups.isInvited = function(uid, groupName, callback) {
+ Groups.isInvited = function (uid, groupName, callback) {
if (!uid) {
return callback(null, false);
}
db.isSetMember('group:' + groupName + ':invited', uid, callback);
};
- Groups.isPending = function(uid, groupName, callback) {
+ Groups.isPending = function (uid, groupName, callback) {
if (!uid) {
return callback(null, false);
}
db.isSetMember('group:' + groupName + ':pending', uid, callback);
};
- Groups.getPending = function(groupName, callback) {
+ Groups.getPending = function (groupName, callback) {
if (!groupName) {
return callback(null, []);
}
db.getSetMembers('group:' + groupName + ':pending', callback);
};
- Groups.kick = function(uid, groupName, isOwner, callback) {
+ Groups.kick = function (uid, groupName, isOwner, callback) {
if (isOwner) {
// If the owners set only contains one member, error out!
async.waterfall([
diff --git a/src/groups/ownership.js b/src/groups/ownership.js
index aa085f8213..f397abe5e7 100644
--- a/src/groups/ownership.js
+++ b/src/groups/ownership.js
@@ -4,18 +4,18 @@ var async = require('async'),
db = require('../database'),
plugins = require('../plugins');
-module.exports = function(Groups) {
+module.exports = function (Groups) {
Groups.ownership = {};
- Groups.ownership.isOwner = function(uid, groupName, callback) {
+ Groups.ownership.isOwner = function (uid, groupName, callback) {
if (!uid) {
return callback(null, false);
}
db.isSetMember('group:' + groupName + ':owners', uid, callback);
};
- Groups.ownership.isOwners = function(uids, groupName, callback) {
+ Groups.ownership.isOwners = function (uids, groupName, callback) {
if (!Array.isArray(uids)) {
return callback(null, []);
}
@@ -23,20 +23,20 @@ module.exports = function(Groups) {
db.isSetMembers('group:' + groupName + ':owners', uids, callback);
};
- Groups.ownership.grant = function(toUid, groupName, callback) {
+ Groups.ownership.grant = function (toUid, groupName, callback) {
// Note: No ownership checking is done here on purpose!
async.waterfall([
- function(next) {
+ function (next) {
db.setAdd('group:' + groupName + ':owners', toUid, next);
},
- function(next) {
+ function (next) {
plugins.fireHook('action:group.grantOwnership', {uid: toUid, groupName: groupName});
next();
}
], callback);
};
- Groups.ownership.rescind = function(toUid, groupName, callback) {
+ Groups.ownership.rescind = function (toUid, groupName, callback) {
// Note: No ownership checking is done here on purpose!
// If the owners set only contains one member, error out!
diff --git a/src/groups/search.js b/src/groups/search.js
index 3d2a186d26..74b30c3188 100644
--- a/src/groups/search.js
+++ b/src/groups/search.js
@@ -6,28 +6,28 @@ var async = require('async'),
db = require('./../database'),
groups = module.parent.exports;
-module.exports = function(Groups) {
+module.exports = function (Groups) {
- Groups.search = function(query, options, callback) {
+ Groups.search = function (query, options, callback) {
if (!query) {
return callback(null, []);
}
query = query.toLowerCase();
async.waterfall([
async.apply(db.getObjectValues, 'groupslug:groupname'),
- function(groupNames, next) {
+ function (groupNames, next) {
// Ephemeral groups and the registered-users groups are searchable
groupNames = groups.getEphemeralGroups().concat(groupNames).concat('registered-users');
- groupNames = groupNames.filter(function(name) {
+ groupNames = groupNames.filter(function (name) {
return name.toLowerCase().indexOf(query) !== -1 && name !== 'administrators' && !Groups.isPrivilegeGroup(name);
});
groupNames = groupNames.slice(0, 100);
Groups.getGroupsData(groupNames, next);
},
- function(groupsData, next) {
+ function (groupsData, next) {
groupsData = groupsData.filter(Boolean);
if (options.filterHidden) {
- groupsData = groupsData.filter(function(group) {
+ groupsData = groupsData.filter(function (group) {
return !group.hidden;
});
}
@@ -37,25 +37,25 @@ module.exports = function(Groups) {
], callback);
};
- Groups.sort = function(strategy, groups, next) {
+ Groups.sort = function (strategy, groups, next) {
switch(strategy) {
case 'count':
- groups = groups.sort(function(a, b) {
+ groups = groups.sort(function (a, b) {
return a.slug > b.slug;
- }).sort(function(a, b) {
+ }).sort(function (a, b) {
return b.memberCount - a.memberCount;
});
break;
case 'date':
- groups = groups.sort(function(a, b) {
+ groups = groups.sort(function (a, b) {
return b.createtime - a.createtime;
});
break;
case 'alpha': // intentional fall-through
default:
- groups = groups.sort(function(a, b) {
+ groups = groups.sort(function (a, b) {
return a.slug > b.slug ? 1 : -1;
});
}
@@ -63,7 +63,7 @@ module.exports = function(Groups) {
next(null, groups);
};
- Groups.searchMembers = function(data, callback) {
+ Groups.searchMembers = function (data, callback) {
function findUids(query, searchBy, callback) {
if (!query) {
@@ -73,13 +73,13 @@ module.exports = function(Groups) {
query = query.toLowerCase();
async.waterfall([
- function(next) {
+ function (next) {
Groups.getMembers(data.groupName, 0, -1, next);
},
- function(members, next) {
+ function (members, next) {
user.getUsersFields(members, ['uid'].concat([searchBy]), next);
},
- function(users, next) {
+ function (users, next) {
var uids = [];
for(var i = 0; i < users.length; ++i) {
var field = users[i][searchBy];
@@ -93,7 +93,7 @@ module.exports = function(Groups) {
}
if (!data.query) {
- Groups.getOwnersAndMembers(data.groupName, data.uid, 0, 19, function(err, users) {
+ Groups.getOwnersAndMembers(data.groupName, data.uid, 0, 19, function (err, users) {
if (err) {
return callback(err);
}
@@ -105,25 +105,25 @@ module.exports = function(Groups) {
data.findUids = findUids;
var results;
async.waterfall([
- function(next) {
+ function (next) {
user.search(data, next);
},
- function(_results, next) {
+ function (_results, next) {
results = _results;
- var uids = results.users.map(function(user) {
+ var uids = results.users.map(function (user) {
return user && user.uid;
});
Groups.ownership.isOwners(uids, data.groupName, next);
},
- function(isOwners, next) {
+ function (isOwners, next) {
- results.users.forEach(function(user, index) {
+ results.users.forEach(function (user, index) {
if (user) {
user.isOwner = isOwners[index];
}
});
- results.users.sort(function(a,b) {
+ results.users.sort(function (a,b) {
if (a.isOwner && !b.isOwner) {
return -1;
} else if (!a.isOwner && b.isOwner) {
diff --git a/src/groups/update.js b/src/groups/update.js
index f30addc42f..fa998bafe6 100644
--- a/src/groups/update.js
+++ b/src/groups/update.js
@@ -8,10 +8,10 @@ var utils = require('../../public/src/utils');
var db = require('../database');
-module.exports = function(Groups) {
+module.exports = function (Groups) {
- Groups.update = function(groupName, values, callback) {
- callback = callback || function() {};
+ Groups.update = function (groupName, values, callback) {
+ callback = callback || function () {};
db.exists('group:' + groupName, function (err, exists) {
if (err || !exists) {
return callback(err || new Error('[[error:no-group]]'));
@@ -20,7 +20,7 @@ module.exports = function(Groups) {
plugins.fireHook('filter:group.update', {
groupName: groupName,
values: values
- }, function(err) {
+ }, function (err) {
if (err) {
return callback(err);
}
@@ -54,7 +54,7 @@ module.exports = function(Groups) {
async.series([
async.apply(checkNameChange, groupName, values.name),
async.apply(updatePrivacy, groupName, values.private),
- function(next) {
+ function (next) {
if (values.hasOwnProperty('hidden')) {
updateVisibility(groupName, values.hidden, next);
} else {
@@ -63,7 +63,7 @@ module.exports = function(Groups) {
},
async.apply(db.setObject, 'group:' + groupName, payload),
async.apply(renameGroup, groupName, values.name)
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
@@ -86,7 +86,7 @@ module.exports = function(Groups) {
async.apply(db.sortedSetRemove, 'groups:visible:name', groupName.toLowerCase() + ':' + groupName),
], callback);
} else {
- db.getObjectFields('group:' + groupName, ['createtime', 'memberCount'], function(err, groupData) {
+ db.getObjectFields('group:' + groupName, ['createtime', 'memberCount'], function (err, groupData) {
if (err) {
return callback(err);
}
@@ -99,21 +99,21 @@ module.exports = function(Groups) {
}
}
- Groups.hide = function(groupName, callback) {
+ Groups.hide = function (groupName, callback) {
showHide(groupName, 'hidden', callback);
};
- Groups.show = function(groupName, callback) {
+ Groups.show = function (groupName, callback) {
showHide(groupName, 'show', callback);
};
function showHide(groupName, hidden, callback) {
hidden = hidden === 'hidden';
- callback = callback || function() {};
+ callback = callback || function () {};
async.parallel([
async.apply(db.setObjectField, 'group:' + groupName, 'hidden', hidden ? 1 : 0),
async.apply(updateVisibility, groupName, hidden)
- ], function(err) {
+ ], function (err) {
callback(err);
});
}
@@ -123,7 +123,7 @@ module.exports = function(Groups) {
return callback();
}
- Groups.getGroupFields(groupName, ['private'], function(err, currentValue) {
+ Groups.getGroupFields(groupName, ['private'], function (err, currentValue) {
if (err) {
return callback(err);
}
@@ -131,12 +131,12 @@ module.exports = function(Groups) {
if (currentValue !== newValue && currentValue === true) {
// Group is now public, so all pending users are automatically considered members
- db.getSetMembers('group:' + groupName + ':pending', function(err, uids) {
+ db.getSetMembers('group:' + groupName + ':pending', function (err, uids) {
if (err) { return callback(err); }
else if (!uids) { return callback(); } // No pending users, we're good to go
var now = Date.now(),
- scores = uids.map(function() { return now; }); // There's probably a better way to initialise an Array of size x with the same value...
+ scores = uids.map(function () { return now; }); // There's probably a better way to initialise an Array of size x with the same value...
winston.verbose('[groups.update] Group is now public, automatically adding ' + uids.length + ' new members, who were pending prior.');
async.series([
@@ -159,7 +159,7 @@ module.exports = function(Groups) {
if (currentSlug === newSlug) {
return callback();
}
- Groups.existsBySlug(newSlug, function(err, exists) {
+ Groups.existsBySlug(newSlug, function (err, exists) {
if (err || exists) {
return callback(err || new Error('[[error:group-already-exists]]'));
}
@@ -172,7 +172,7 @@ module.exports = function(Groups) {
return callback();
}
- db.getObject('group:' + oldName, function(err, group) {
+ db.getObject('group:' + oldName, function (err, group) {
if (err || !group) {
return callback(err);
}
@@ -181,7 +181,7 @@ module.exports = function(Groups) {
return callback();
}
- Groups.exists(newName, function(err, exists) {
+ Groups.exists(newName, function (err, exists) {
if (err || exists) {
return callback(err || new Error('[[error:group-already-exists]]'));
}
@@ -191,12 +191,12 @@ module.exports = function(Groups) {
async.apply(db.setObjectField, 'group:' + oldName, 'slug', utils.slugify(newName)),
async.apply(db.deleteObjectField, 'groupslug:groupname', group.slug),
async.apply(db.setObjectField, 'groupslug:groupname', utils.slugify(newName), newName),
- function(next) {
- db.getSortedSetRange('groups:createtime', 0, -1, function(err, groups) {
+ function (next) {
+ db.getSortedSetRange('groups:createtime', 0, -1, function (err, groups) {
if (err) {
return next(err);
}
- async.each(groups, function(group, next) {
+ async.each(groups, function (group, next) {
renameGroupMember('group:' + group + ':members', oldName, newName, next);
}, next);
});
@@ -211,7 +211,7 @@ module.exports = function(Groups) {
async.apply(renameGroupMember, 'groups:visible:createtime', oldName, newName),
async.apply(renameGroupMember, 'groups:visible:memberCount', oldName, newName),
async.apply(renameGroupMember, 'groups:visible:name', oldName.toLowerCase() + ':' + oldName, newName.toLowerCase() + ':' + newName),
- function(next) {
+ function (next) {
plugins.fireHook('action:group.rename', {
old: oldName,
new: newName
@@ -225,7 +225,7 @@ module.exports = function(Groups) {
}
function renameGroupMember(group, oldName, newName, callback) {
- db.isSortedSetMember(group, oldName, function(err, isMember) {
+ db.isSortedSetMember(group, oldName, function (err, isMember) {
if (err || !isMember) {
return callback(err);
}
diff --git a/src/hotswap.js b/src/hotswap.js
index 1b95381082..d5d3749b7b 100644
--- a/src/hotswap.js
+++ b/src/hotswap.js
@@ -4,11 +4,11 @@ var HotSwap = {},
winston = require('winston'),
stack;
-HotSwap.prepare = function(app) {
+HotSwap.prepare = function (app) {
stack = app._router.stack;
};
-HotSwap.find = function(id) {
+HotSwap.find = function (id) {
if (stack) {
for(var x = 0,numEntries = stack.length;x < numEntries;x++) {
if (stack[x].handle.hotswapId === id) {
@@ -20,7 +20,7 @@ HotSwap.find = function(id) {
}
};
-HotSwap.replace = function(id, router) {
+HotSwap.replace = function (id, router) {
var idx = HotSwap.find(id);
if (idx) {
delete stack[idx].handle; // Destroy the old router
diff --git a/src/image.js b/src/image.js
index cfa09d6e38..1cfbdccbe3 100644
--- a/src/image.js
+++ b/src/image.js
@@ -7,7 +7,7 @@ var plugins = require('./plugins');
var image = module.exports;
-image.resizeImage = function(data, callback) {
+image.resizeImage = function (data, callback) {
if (plugins.hasListeners('filter:image.resize')) {
plugins.fireHook('filter:image.resize', {
path: data.path,
@@ -15,11 +15,11 @@ image.resizeImage = function(data, callback) {
extension: data.extension,
width: data.width,
height: data.height
- }, function(err) {
+ }, function (err) {
callback(err);
});
} else {
- new Jimp(data.path, function(err, image) {
+ new Jimp(data.path, function (err, image) {
if (err) {
return callback(err);
}
@@ -52,7 +52,7 @@ image.resizeImage = function(data, callback) {
async.waterfall([
crop,
- function(_image, next) {
+ function (_image, next) {
if (typeof _image === 'function' && !next) {
next = _image;
_image = image;
@@ -64,52 +64,52 @@ image.resizeImage = function(data, callback) {
next(null, image);
}
},
- function(image, next) {
+ function (image, next) {
image.write(data.target || data.path, next);
}
- ], function(err) {
+ ], function (err) {
callback(err);
});
});
}
};
-image.normalise = function(path, extension, callback) {
+image.normalise = function (path, extension, callback) {
if (plugins.hasListeners('filter:image.normalise')) {
plugins.fireHook('filter:image.normalise', {
path: path,
extension: extension
- }, function(err) {
+ }, function (err) {
callback(err);
});
} else {
- new Jimp(path, function(err, image) {
+ new Jimp(path, function (err, image) {
if (err) {
return callback(err);
}
- image.write(path + '.png', function(err) {
+ image.write(path + '.png', function (err) {
callback(err);
});
});
}
};
-image.size = function(path, callback) {
+image.size = function (path, callback) {
if (plugins.hasListeners('filter:image.size')) {
plugins.fireHook('filter:image.size', {
path: path,
- }, function(err, image) {
+ }, function (err, image) {
callback(err, image);
});
} else {
- new Jimp(path, function(err, data) {
+ new Jimp(path, function (err, data) {
callback(err, data ? data.bitmap : null);
});
}
};
-image.convertImageToBase64 = function(path, callback) {
- fs.readFile(path, function(err, data) {
+image.convertImageToBase64 = function (path, callback) {
+ fs.readFile(path, function (err, data) {
callback(err, data ? data.toString('base64') : null);
});
};
diff --git a/src/install.js b/src/install.js
index 5e642d0177..711932bb00 100644
--- a/src/install.js
+++ b/src/install.js
@@ -125,14 +125,14 @@ function setupConfig(next) {
prompt.colors = false;
if (!install.values) {
- prompt.get(questions.main, function(err, config) {
+ prompt.get(questions.main, function (err, config) {
if (err) {
process.stdout.write('\n\n');
winston.warn('NodeBB setup ' + err.message);
process.exit();
}
- configureDatabases(config, function(err, config) {
+ configureDatabases(config, function (err, config) {
completeConfigSetup(err, config, next);
});
});
@@ -147,7 +147,7 @@ function setupConfig(next) {
config[question.name] = install.values[question.name] || question['default'] || undefined;
});
- configureDatabases(config, function(err, config) {
+ configureDatabases(config, function (err, config) {
completeConfigSetup(err, config, next);
});
}
@@ -168,7 +168,7 @@ function completeConfigSetup(err, config, next) {
}
}
- install.save(config, function(err) {
+ install.save(config, function (err) {
if (err) {
return next(err);
}
@@ -194,7 +194,7 @@ function setupDefaultConfigs(next) {
function enableDefaultTheme(next) {
var meta = require('./meta');
- meta.configs.get('theme:id', function(err, id) {
+ meta.configs.get('theme:id', function (err, id) {
if (err || id) {
process.stdout.write('Previous theme detected, skipping enabling default theme\n');
return next(err);
@@ -254,7 +254,7 @@ function createAdmin(callback) {
hidden: true,
type: 'string'
}],
- success = function(err, results) {
+ success = function (err, results) {
if (err) {
return callback(err);
}
@@ -268,20 +268,20 @@ function createAdmin(callback) {
}
var adminUid;
async.waterfall([
- function(next) {
+ function (next) {
User.create({username: results.username, password: results.password, email: results.email}, next);
},
- function(uid, next) {
+ function (uid, next) {
adminUid = uid;
Groups.join('administrators', uid, next);
},
- function(next) {
+ function (next) {
Groups.show('administrators', next);
},
- function(next) {
+ function (next) {
Groups.ownership.grant(adminUid, 'administrators', next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
@@ -382,7 +382,7 @@ function createCategories(next) {
function createMenuItems(next) {
var db = require('./database');
- db.exists('navigation:enabled', function(err, exists) {
+ db.exists('navigation:enabled', function (err, exists) {
if (err || exists) {
return next(err);
}
@@ -398,13 +398,13 @@ function createWelcomePost(next) {
Topics = require('./topics');
async.parallel([
- function(next) {
+ function (next) {
fs.readFile(path.join(__dirname, '../', 'install/data/welcome.md'), next);
},
- function(next) {
+ function (next) {
db.getObjectField('global', 'topicCount', next);
}
- ], function(err, results) {
+ ], function (err, results) {
if (err) {
return next(err);
}
@@ -454,14 +454,14 @@ function enableDefaultPlugins(next) {
}
}
- defaultEnabled = defaultEnabled.filter(function(plugin, index, array) {
+ defaultEnabled = defaultEnabled.filter(function (plugin, index, array) {
return array.indexOf(plugin) === index;
});
winston.info('[install/enableDefaultPlugins] activating default plugins', defaultEnabled);
var db = require('./database');
- var order = defaultEnabled.map(function(plugin, index) {
+ var order = defaultEnabled.map(function (plugin, index) {
return index;
});
db.sortedSetAdd('plugins:active', order, defaultEnabled, next);
@@ -470,13 +470,13 @@ function enableDefaultPlugins(next) {
function setCopyrightWidget(next) {
var db = require('./database');
async.parallel({
- footerJSON: function(next) {
+ footerJSON: function (next) {
fs.readFile(path.join(__dirname, '../', 'install/data/footer.json'), next);
},
- footer: function(next) {
+ footer: function (next) {
db.getObjectField('widgets:global', 'footer', next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return next(err);
}
@@ -507,7 +507,7 @@ install.setup = function (callback) {
setCopyrightWidget,
function (next) {
var upgrade = require('./upgrade');
- upgrade.check(function(err, uptodate) {
+ upgrade.check(function (err, uptodate) {
if (err) {
return next(err);
}
diff --git a/src/languages.js b/src/languages.js
index 70dbf4f4ae..2513f4ec57 100644
--- a/src/languages.js
+++ b/src/languages.js
@@ -10,7 +10,7 @@ var plugins = require('./plugins');
var Languages = {};
-Languages.init = function(next) {
+Languages.init = function (next) {
if (Languages.hasOwnProperty('_cache')) {
Languages._cache.reset();
} else {
@@ -20,7 +20,7 @@ Languages.init = function(next) {
next();
};
-Languages.get = function(code, key, callback) {
+Languages.get = function (code, key, callback) {
var combined = [code, key].join('/');
if (Languages._cache.has(combined)) {
@@ -29,7 +29,7 @@ Languages.get = function(code, key, callback) {
var languageData;
- fs.readFile(path.join(__dirname, '../public/language/', code, key), { encoding: 'utf-8' }, function(err, data) {
+ fs.readFile(path.join(__dirname, '../public/language/', code, key), { encoding: 'utf-8' }, function (err, data) {
if (err && err.code !== 'ENOENT') {
return callback(err);
}
@@ -50,17 +50,17 @@ Languages.get = function(code, key, callback) {
});
};
-Languages.list = function(callback) {
+Languages.list = function (callback) {
var languagesPath = path.join(__dirname, '../public/language'),
languages = [];
- fs.readdir(languagesPath, function(err, files) {
+ fs.readdir(languagesPath, function (err, files) {
if (err) {
return callback(err);
}
- async.each(files, function(folder, next) {
- fs.stat(path.join(languagesPath, folder), function(err, stat) {
+ async.each(files, function (folder, next) {
+ fs.stat(path.join(languagesPath, folder), function (err, stat) {
if (err) {
return next(err);
}
@@ -71,7 +71,7 @@ Languages.list = function(callback) {
var configPath = path.join(languagesPath, folder, 'language.json');
- fs.readFile(configPath, function(err, stream) {
+ fs.readFile(configPath, function (err, stream) {
if (err) {
next();
}
@@ -79,12 +79,12 @@ Languages.list = function(callback) {
next();
});
});
- }, function(err) {
+ }, function (err) {
if (err) {
return callback(err);
}
// Sort alphabetically
- languages = languages.sort(function(a, b) {
+ languages = languages.sort(function (a, b) {
return a.code > b.code ? 1 : -1;
});
diff --git a/src/logger.js b/src/logger.js
index b99fbfbb91..4d6b8f717c 100644
--- a/src/logger.js
+++ b/src/logger.js
@@ -30,20 +30,20 @@ var opts = {
/* -- Logger -- */
-(function(Logger) {
+(function (Logger) {
- Logger.init = function(app) {
+ Logger.init = function (app) {
opts.express.app = app;
/* Open log file stream & initialize express logging if meta.config.logger* variables are set */
Logger.setup();
};
- Logger.setup = function() {
+ Logger.setup = function () {
Logger.setup_one('loggerPath', meta.config.loggerPath);
};
- Logger.setup_one = function(key, value) {
+ Logger.setup_one = function (key, value) {
/*
* 1. Open the logger stream: stdout or file
* 2. Re-initialize the express logger hijack
@@ -54,7 +54,7 @@ var opts = {
}
};
- Logger.setup_one_log = function(value) {
+ Logger.setup_one_log = function (value) {
/*
* If logging is currently enabled, create a stream.
* Otherwise, close the current stream
@@ -72,7 +72,7 @@ var opts = {
}
};
- Logger.open = function(value) {
+ Logger.open = function (value) {
/* Open the streams to log to: either a path or stdout */
var stream;
if(value) {
@@ -91,7 +91,7 @@ var opts = {
}
if(stream) {
- stream.on('error', function(err) {
+ stream.on('error', function (err) {
winston.error(err.message);
});
}
@@ -101,14 +101,14 @@ var opts = {
return stream;
};
- Logger.close = function(stream) {
+ Logger.close = function (stream) {
if(stream.f !== process.stdout && stream.f) {
stream.end();
}
stream.f = null;
};
- Logger.monitorConfig = function(socket, data) {
+ Logger.monitorConfig = function (socket, data) {
/*
* This monitor's when a user clicks "save" in the Logger section of the admin panel
*/
@@ -117,7 +117,7 @@ var opts = {
Logger.io(socket);
};
- Logger.express_open = function() {
+ Logger.express_open = function () {
if(opts.express.set !== 1) {
opts.express.set = 1;
opts.express.app.use(Logger.expressLogger);
@@ -128,7 +128,7 @@ var opts = {
opts.express.ofn = morgan('combined', {stream : opts.streams.log.f});
};
- Logger.expressLogger = function(req,res,next) {
+ Logger.expressLogger = function (req,res,next) {
/*
* The new express.logger
*
@@ -141,7 +141,7 @@ var opts = {
}
};
- Logger.prepare_io_string = function(_type, _uid, _args) {
+ Logger.prepare_io_string = function (_type, _uid, _args) {
/*
* This prepares the output string for intercepted socket.io events
*
@@ -155,7 +155,7 @@ var opts = {
}
};
- Logger.io_close = function(socket) {
+ Logger.io_close = function (socket) {
/*
* Restore all hijacked sockets to their original emit/on functions
*/
@@ -177,7 +177,7 @@ var opts = {
}
};
- Logger.io = function(socket) {
+ Logger.io = function (socket) {
/*
* Go through all of the currently established sockets & hook their .emit/.on
*/
@@ -194,12 +194,12 @@ var opts = {
}
};
- Logger.io_one = function(socket, uid) {
+ Logger.io_one = function (socket, uid) {
/*
* This function replaces a socket's .emit/.on functions in order to intercept events
*/
function override(method, name, errorMsg) {
- return function() {
+ return function () {
if(opts.streams.log.f) {
opts.streams.log.f.write(Logger.prepare_io_string(name, uid, arguments));
}
diff --git a/src/messaging.js b/src/messaging.js
index cdf5f77ce4..d179c14cbe 100644
--- a/src/messaging.js
+++ b/src/messaging.js
@@ -13,7 +13,7 @@ var utils = require('../public/src/utils');
var notifications = require('./notifications');
var userNotifications = require('./user/notifications');
-(function(Messaging) {
+(function (Messaging) {
require('./messaging/create')(Messaging);
require('./messaging/delete')(Messaging);
@@ -22,25 +22,25 @@ var userNotifications = require('./user/notifications');
require('./messaging/unread')(Messaging);
require('./messaging/notifications')(Messaging);
- Messaging.getMessageField = function(mid, field, callback) {
- Messaging.getMessageFields(mid, [field], function(err, fields) {
+ Messaging.getMessageField = function (mid, field, callback) {
+ Messaging.getMessageFields(mid, [field], function (err, fields) {
callback(err, fields ? fields[field] : null);
});
};
- Messaging.getMessageFields = function(mid, fields, callback) {
+ Messaging.getMessageFields = function (mid, fields, callback) {
db.getObjectFields('message:' + mid, fields, callback);
};
- Messaging.setMessageField = function(mid, field, content, callback) {
+ Messaging.setMessageField = function (mid, field, content, callback) {
db.setObjectField('message:' + mid, field, content, callback);
};
- Messaging.setMessageFields = function(mid, data, callback) {
+ Messaging.setMessageFields = function (mid, data, callback) {
db.setObject('message:' + mid, data, callback);
};
- Messaging.getMessages = function(params, callback) {
+ Messaging.getMessages = function (params, callback) {
var uid = params.uid;
var roomId = params.roomId;
var isNew = params.isNew || false;
@@ -50,21 +50,21 @@ var userNotifications = require('./user/notifications');
var indices = {};
async.waterfall([
- function(next) {
+ function (next) {
canGetMessages(params.callerUid, params.uid, next);
},
- function(canGet, next) {
+ function (canGet, next) {
if (!canGet) {
return callback(null, null);
}
db.getSortedSetRevRange('uid:' + uid + ':chat:room:' + roomId + ':mids', start, stop, next);
},
- function(mids, next) {
+ function (mids, next) {
if (!Array.isArray(mids) || !mids.length) {
return callback(null, []);
}
- mids.forEach(function(mid, index) {
+ mids.forEach(function (mid, index) {
indices[mid] = start + index;
});
@@ -72,8 +72,8 @@ var userNotifications = require('./user/notifications');
Messaging.getMessagesData(mids, uid, roomId, isNew, next);
},
- function(messageData, next) {
- messageData.forEach(function(messageData) {
+ function (messageData, next) {
+ messageData.forEach(function (messageData) {
messageData.index = indices[messageData.messageId.toString()];
});
next(null, messageData);
@@ -81,7 +81,7 @@ var userNotifications = require('./user/notifications');
], callback);
if (markRead) {
- notifications.markRead('chat_' + roomId + '_' + uid, uid, function(err) {
+ notifications.markRead('chat_' + roomId + '_' + uid, uid, function (err) {
if (err) {
winston.error('[messaging] Could not mark notifications related to this chat as read: ' + err.message);
}
@@ -96,14 +96,14 @@ var userNotifications = require('./user/notifications');
callerUid: callerUid,
uid: uid,
canGet: parseInt(callerUid, 10) === parseInt(uid, 10)
- }, function(err, data) {
+ }, function (err, data) {
callback(err, data ? data.canGet : false);
});
}
- Messaging.getMessagesData = function(mids, uid, roomId, isNew, callback) {
+ Messaging.getMessagesData = function (mids, uid, roomId, isNew, callback) {
- var keys = mids.map(function(mid) {
+ var keys = mids.map(function (mid) {
return 'message:' + mid;
});
@@ -114,21 +114,21 @@ var userNotifications = require('./user/notifications');
db.getObjects(keys, next);
},
function (_messages, next) {
- messages = _messages.map(function(msg, idx) {
+ messages = _messages.map(function (msg, idx) {
if (msg) {
msg.messageId = parseInt(mids[idx], 10);
}
return msg;
}).filter(Boolean);
- var uids = messages.map(function(msg) {
+ var uids = messages.map(function (msg) {
return msg && msg.fromuid;
});
user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture', 'status'], next);
},
function (users, next) {
- messages.forEach(function(message, index) {
+ messages.forEach(function (message, index) {
message.fromUser = users[index];
var self = parseInt(message.fromuid, 10) === parseInt(uid, 10);
message.self = self ? 1 : 0;
@@ -140,8 +140,8 @@ var userNotifications = require('./user/notifications');
}
});
- async.map(messages, function(message, next) {
- Messaging.parse(message.content, message.fromuid, uid, roomId, isNew, function(err, result) {
+ async.map(messages, function (message, next) {
+ Messaging.parse(message.content, message.fromuid, uid, roomId, isNew, function (err, result) {
if (err) {
return next(err);
}
@@ -151,10 +151,10 @@ var userNotifications = require('./user/notifications');
});
}, next);
},
- function(messages, next) {
+ function (messages, next) {
if (messages.length > 1) {
// Add a spacer in between messages with time gaps between them
- messages = messages.map(function(message, index) {
+ messages = messages.map(function (message, index) {
// Compare timestamps with the previous message, and check if a spacer needs to be added
if (index > 0 && parseInt(message.timestamp, 10) > parseInt(messages[index - 1].timestamp, 10) + (1000 * 60 * 5)) {
// If it's been 5 minutes, this is a new set of messages
@@ -173,7 +173,7 @@ var userNotifications = require('./user/notifications');
var key = 'uid:' + uid + ':chat:room:' + roomId + ':mids';
async.waterfall([
async.apply(db.sortedSetRank, key, messages[0].messageId),
- function(index, next) {
+ function (index, next) {
// Continue only if this isn't the first message in sorted set
if (index > 0) {
db.getSortedSetRange(key, index - 1, index - 1, next);
@@ -182,10 +182,10 @@ var userNotifications = require('./user/notifications');
return next(undefined, messages);
}
},
- function(mid, next) {
+ function (mid, next) {
Messaging.getMessageFields(mid, ['fromuid', 'timestamp'], next);
}
- ], function(err, fields) {
+ ], function (err, fields) {
if (err) {
return next(err);
}
@@ -209,7 +209,7 @@ var userNotifications = require('./user/notifications');
};
Messaging.parse = function (message, fromuid, uid, roomId, isNew, callback) {
- plugins.fireHook('filter:parse.raw', message, function(err, parsed) {
+ plugins.fireHook('filter:parse.raw', message, function (err, parsed) {
if (err) {
return callback(err);
}
@@ -224,20 +224,20 @@ var userNotifications = require('./user/notifications');
parsedMessage: parsed
};
- plugins.fireHook('filter:messaging.parse', messageData, function(err, messageData) {
+ plugins.fireHook('filter:messaging.parse', messageData, function (err, messageData) {
callback(err, messageData ? messageData.parsedMessage : '');
});
});
};
- Messaging.isNewSet = function(uid, roomId, timestamp, callback) {
+ Messaging.isNewSet = function (uid, roomId, timestamp, callback) {
var setKey = 'uid:' + uid + ':chat:room:' + roomId + ':mids';
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRevRangeWithScores(setKey, 0, 0, next);
},
- function(messages, next) {
+ function (messages, next) {
if (messages && messages.length) {
next(null, parseInt(timestamp, 10) > parseInt(messages[0].score, 10) + (1000 * 60 * 5));
} else {
@@ -248,63 +248,63 @@ var userNotifications = require('./user/notifications');
};
- Messaging.getRecentChats = function(callerUid, uid, start, stop, callback) {
+ Messaging.getRecentChats = function (callerUid, uid, start, stop, callback) {
async.waterfall([
- function(next) {
+ function (next) {
canGetRecentChats(callerUid, uid, next);
},
- function(canGet, next) {
+ function (canGet, next) {
if (!canGet) {
return callback(null, null);
}
db.getSortedSetRevRange('uid:' + uid + ':chat:rooms', start, stop, next);
},
- function(roomIds, next) {
+ function (roomIds, next) {
async.parallel({
- roomData: function(next) {
+ roomData: function (next) {
Messaging.getRoomsData(roomIds, next);
},
- unread: function(next) {
+ unread: function (next) {
db.isSortedSetMembers('uid:' + uid + ':chat:rooms:unread', roomIds, next);
},
- users: function(next) {
- async.map(roomIds, function(roomId, next) {
- db.getSortedSetRevRange('chat:room:' + roomId + ':uids', 0, 9, function(err, uids) {
+ users: function (next) {
+ async.map(roomIds, function (roomId, next) {
+ db.getSortedSetRevRange('chat:room:' + roomId + ':uids', 0, 9, function (err, uids) {
if (err) {
return next(err);
}
- uids = uids.filter(function(value) {
+ uids = uids.filter(function (value) {
return value && parseInt(value, 10) !== parseInt(uid, 10);
});
user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture', 'status', 'lastonline'] , next);
});
}, next);
},
- teasers: function(next) {
- async.map(roomIds, function(roomId, next) {
+ teasers: function (next) {
+ async.map(roomIds, function (roomId, next) {
Messaging.getTeaser(uid, roomId, next);
}, next);
}
}, next);
},
- function(results, next) {
- results.roomData.forEach(function(room, index) {
+ function (results, next) {
+ results.roomData.forEach(function (room, index) {
room.users = results.users[index];
room.groupChat = room.hasOwnProperty('groupChat') ? room.groupChat : room.users.length > 2;
room.unread = results.unread[index];
room.teaser = results.teasers[index];
- room.users.forEach(function(userData) {
+ room.users.forEach(function (userData) {
if (userData && parseInt(userData.uid, 10)) {
userData.status = user.getStatus(userData);
}
});
- room.users = room.users.filter(function(user) {
+ room.users = room.users.filter(function (user) {
return user && parseInt(user.uid, 10);
});
room.lastUser = room.users[0];
- room.usernames = room.users.map(function(user) {
+ room.usernames = room.users.map(function (user) {
return user.username;
}).join(', ');
});
@@ -319,7 +319,7 @@ var userNotifications = require('./user/notifications');
callerUid: callerUid,
uid: uid,
canGet: parseInt(callerUid, 10) === parseInt(uid, 10)
- }, function(err, data) {
+ }, function (err, data) {
callback(err, data ? data.canGet : false);
});
}
@@ -348,14 +348,14 @@ var userNotifications = require('./user/notifications');
teaser.timestampISO = utils.toISOString(teaser.timestamp);
user.getUserFields(teaser.fromuid, ['uid', 'username', 'userslug', 'picture', 'status', 'lastonline'] , next);
},
- function(user, next) {
+ function (user, next) {
teaser.user = user;
next(null, teaser);
}
], callback);
};
- Messaging.canMessageUser = function(uid, toUid, callback) {
+ Messaging.canMessageUser = function (uid, toUid, callback) {
if (parseInt(meta.config.disableChat) === 1 || !uid || uid === toUid) {
return callback(new Error('[[error:chat-disabled]]'));
}
@@ -385,7 +385,7 @@ var userNotifications = require('./user/notifications');
isFollowing: async.apply(user.isFollowing, toUid, uid)
}, next);
},
- function(results, next) {
+ function (results, next) {
if (!results.settings.restrictChat || results.isAdmin || results.isFollowing) {
return next();
}
@@ -395,7 +395,7 @@ var userNotifications = require('./user/notifications');
], callback);
};
- Messaging.canMessageRoom = function(uid, roomId, callback) {
+ Messaging.canMessageRoom = function (uid, roomId, callback) {
if (parseInt(meta.config.disableChat) === 1 || !uid) {
return callback(new Error('[[error:chat-disabled]]'));
}
@@ -411,7 +411,7 @@ var userNotifications = require('./user/notifications');
Messaging.getUserCountInRoom(roomId, next);
},
- function(count, next) {
+ function (count, next) {
if (count < 2) {
return next(new Error('[[error:no-users-in-room]]'));
}
@@ -432,7 +432,7 @@ var userNotifications = require('./user/notifications');
], callback);
};
- Messaging.hasPrivateChat = function(uid, withUid, callback) {
+ Messaging.hasPrivateChat = function (uid, withUid, callback) {
async.waterfall([
function (next) {
async.parallel({
@@ -441,7 +441,7 @@ var userNotifications = require('./user/notifications');
}, next);
},
function (results, next) {
- var roomIds = results.myRooms.filter(function(roomId) {
+ var roomIds = results.myRooms.filter(function (roomId) {
return roomId && results.theirRooms.indexOf(roomId) !== -1;
});
@@ -451,10 +451,10 @@ var userNotifications = require('./user/notifications');
var index = 0;
var roomId = 0;
- async.whilst(function() {
+ async.whilst(function () {
return index < roomIds.length && !roomId;
- }, function(next) {
- Messaging.getUserCountInRoom(roomIds[index], function(err, count) {
+ }, function (next) {
+ Messaging.getUserCountInRoom(roomIds[index], function (err, count) {
if (err) {
return next(err);
}
@@ -466,7 +466,7 @@ var userNotifications = require('./user/notifications');
next();
}
});
- }, function(err) {
+ }, function (err) {
next(err, roomId);
});
}
diff --git a/src/messaging/create.js b/src/messaging/create.js
index cf78affb64..face15f589 100644
--- a/src/messaging/create.js
+++ b/src/messaging/create.js
@@ -7,9 +7,9 @@ var plugins = require('../plugins');
var db = require('../database');
-module.exports = function(Messaging) {
+module.exports = function (Messaging) {
- Messaging.sendMessage = function(uid, roomId, content, timestamp, callback) {
+ Messaging.sendMessage = function (uid, roomId, content, timestamp, callback) {
async.waterfall([
function (next) {
Messaging.checkContent(content, next);
@@ -27,7 +27,7 @@ module.exports = function(Messaging) {
], callback);
};
- Messaging.checkContent = function(content, callback) {
+ Messaging.checkContent = function (content, callback) {
if (!content) {
return callback(new Error('[[error:invalid-chat-message]]'));
}
@@ -38,7 +38,7 @@ module.exports = function(Messaging) {
callback();
};
- Messaging.addMessage = function(fromuid, roomId, content, timestamp, callback) {
+ Messaging.addMessage = function (fromuid, roomId, content, timestamp, callback) {
var mid;
var message;
var isNewSet;
@@ -98,21 +98,21 @@ module.exports = function(Messaging) {
], callback);
};
- Messaging.addRoomToUsers = function(roomId, uids, timestamp, callback) {
+ Messaging.addRoomToUsers = function (roomId, uids, timestamp, callback) {
if (!uids.length) {
return callback();
}
- var keys = uids.map(function(uid) {
+ var keys = uids.map(function (uid) {
return 'uid:' + uid + ':chat:rooms';
});
db.sortedSetsAdd(keys, timestamp, roomId, callback);
};
- Messaging.addMessageToUsers = function(roomId, uids, mid, timestamp, callback) {
+ Messaging.addMessageToUsers = function (roomId, uids, mid, timestamp, callback) {
if (!uids.length) {
return callback();
}
- var keys = uids.map(function(uid) {
+ var keys = uids.map(function (uid) {
return 'uid:' + uid + ':chat:room:' + roomId + ':mids';
});
db.sortedSetsAdd(keys, timestamp, mid, callback);
diff --git a/src/messaging/delete.js b/src/messaging/delete.js
index 518ab9fafb..e9f48232d1 100644
--- a/src/messaging/delete.js
+++ b/src/messaging/delete.js
@@ -3,9 +3,9 @@
var async = require('async');
var db = require('../database');
-module.exports = function(Messaging) {
+module.exports = function (Messaging) {
- Messaging.deleteMessage = function(mid, roomId, callback) {
+ Messaging.deleteMessage = function (mid, roomId, callback) {
async.waterfall([
function (next) {
Messaging.getUidsInRoom(roomId, 0, -1, next);
@@ -14,12 +14,12 @@ module.exports = function(Messaging) {
if (!uids.length) {
return next();
}
- var keys = uids.map(function(uid) {
+ var keys = uids.map(function (uid) {
return 'uid:' + uid + ':chat:room:' + roomId + 'mids';
});
db.sortedSetsRemove(keys, roomId, next);
},
- function(next) {
+ function (next) {
db.delete('message:' + mid, next);
}
], callback);
diff --git a/src/messaging/edit.js b/src/messaging/edit.js
index 5b2472c4e4..c60e264cbf 100644
--- a/src/messaging/edit.js
+++ b/src/messaging/edit.js
@@ -8,12 +8,12 @@ var user = require('../user');
var sockets = require('../socket.io');
-module.exports = function(Messaging) {
+module.exports = function (Messaging) {
- Messaging.editMessage = function(uid, mid, roomId, content, callback) {
+ Messaging.editMessage = function (uid, mid, roomId, content, callback) {
var uids;
async.waterfall([
- function(next) {
+ function (next) {
Messaging.getMessageField(mid, 'content', next);
},
function (raw, next) {
@@ -34,7 +34,7 @@ module.exports = function(Messaging) {
Messaging.getMessagesData([mid], uid, roomId, true, next);
},
function (messages, next) {
- uids.forEach(function(uid) {
+ uids.forEach(function (uid) {
sockets.in('uid_' + uid).emit('event:chats.edit', {
messages: messages
});
@@ -44,7 +44,7 @@ module.exports = function(Messaging) {
], callback);
};
- Messaging.canEdit = function(messageId, uid, callback) {
+ Messaging.canEdit = function (messageId, uid, callback) {
if (parseInt(meta.config.disableChat) === 1) {
return callback(null, false);
}
@@ -64,14 +64,14 @@ module.exports = function(Messaging) {
Messaging.getMessageField(messageId, 'fromuid', next);
},
- function(fromUid, next) {
+ function (fromUid, next) {
if (parseInt(fromUid, 10) === parseInt(uid, 10)) {
return callback(null, true);
}
user.isAdministrator(uid, next);
},
- function(isAdmin, next) {
+ function (isAdmin, next) {
next(null, isAdmin);
}
], callback);
diff --git a/src/messaging/notifications.js b/src/messaging/notifications.js
index 6747192b6e..6d9500c4ba 100644
--- a/src/messaging/notifications.js
+++ b/src/messaging/notifications.js
@@ -10,12 +10,12 @@ var notifications = require('../notifications');
var meta = require('../meta');
var sockets = require('../socket.io');
-module.exports = function(Messaging) {
+module.exports = function (Messaging) {
Messaging.notifyQueue = {}; // Only used to notify a user of a new chat message, see Messaging.notifyUser
- Messaging.notifyUsersInRoom = function(fromUid, roomId, messageObj) {
- Messaging.getUidsInRoom(roomId, 0, -1, function(err, uids) {
+ Messaging.notifyUsersInRoom = function (fromUid, roomId, messageObj) {
+ Messaging.getUidsInRoom(roomId, 0, -1, function (err, uids) {
if (err) {
return;
}
@@ -25,7 +25,7 @@ module.exports = function(Messaging) {
fromUid: fromUid,
message: messageObj
};
- uids.forEach(function(uid) {
+ uids.forEach(function (uid) {
data.self = parseInt(uid, 10) === parseInt(fromUid) ? 1 : 0;
Messaging.pushUnreadCount(uid);
sockets.in('uid_' + uid).emit('event:chats.receive', data);
@@ -42,8 +42,8 @@ module.exports = function(Messaging) {
};
}
- queueObj.timeout = setTimeout(function() {
- sendNotifications(fromUid, uids, roomId, queueObj.message, function(err) {
+ queueObj.timeout = setTimeout(function () {
+ sendNotifications(fromUid, uids, roomId, queueObj.message, function (err) {
if (!err) {
delete Messaging.notifyQueue[fromUid + ':' + roomId];
}
@@ -53,12 +53,12 @@ module.exports = function(Messaging) {
};
function sendNotifications(fromuid, uids, roomId, messageObj, callback) {
- user.isOnline(uids, function(err, isOnline) {
+ user.isOnline(uids, function (err, isOnline) {
if (err) {
return callback(err);
}
- uids = uids.filter(function(uid, index) {
+ uids = uids.filter(function (uid, index) {
return !isOnline[index] && parseInt(fromuid, 10) !== parseInt(uid, 10);
});
@@ -72,7 +72,7 @@ module.exports = function(Messaging) {
nid: 'chat_' + fromuid + '_' + roomId,
from: fromuid,
path: '/chats/' + messageObj.roomId
- }, function(err, notification) {
+ }, function (err, notification) {
if (!err && notification) {
notifications.push(notification, uids, callback);
}
@@ -88,22 +88,22 @@ module.exports = function(Messaging) {
}
async.parallel({
- userData: function(next) {
+ userData: function (next) {
user.getUsersFields(uids, ['uid', 'username', 'userslug'], next);
},
- userSettings: function(next) {
+ userSettings: function (next) {
user.getMultipleUserSettings(uids, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return winston.error(err);
}
- results.userData = results.userData.filter(function(userData, index) {
+ results.userData = results.userData.filter(function (userData, index) {
return userData && results.userSettings[index] && results.userSettings[index].sendChatNotifications;
});
- async.each(results.userData, function(userData, next) {
+ async.each(results.userData, function (userData, next) {
emailer.send('notif_chat', userData.uid, {
subject: '[[email:notif.chat.subject, ' + messageObj.fromUser.username + ']]',
summary: '[[notifications:new_message_from, ' + messageObj.fromUser.username + ']]',
@@ -114,7 +114,7 @@ module.exports = function(Messaging) {
username: userData.username,
userslug: userData.userslug
}, next);
- }, function(err) {
+ }, function (err) {
if (err) {
winston.error(err);
}
diff --git a/src/messaging/rooms.js b/src/messaging/rooms.js
index 5318f926b2..b20369cb8a 100644
--- a/src/messaging/rooms.js
+++ b/src/messaging/rooms.js
@@ -7,10 +7,10 @@ var db = require('../database');
var user = require('../user');
var plugins = require('../plugins');
-module.exports = function(Messaging) {
+module.exports = function (Messaging) {
- Messaging.getRoomData = function(roomId, callback) {
- db.getObject('chat:room:' + roomId, function(err, data) {
+ Messaging.getRoomData = function (roomId, callback) {
+ db.getObject('chat:room:' + roomId, function (err, data) {
if (err || !data) {
return callback(err || new Error('[[error:no-chat-room]]'));
}
@@ -19,11 +19,11 @@ module.exports = function(Messaging) {
});
};
- Messaging.getRoomsData = function(roomIds, callback) {
- var keys = roomIds.map(function(roomId) {
+ Messaging.getRoomsData = function (roomIds, callback) {
+ var keys = roomIds.map(function (roomId) {
return 'chat:room:' + roomId;
});
- db.getObjects(keys, function(err, roomData) {
+ db.getObjects(keys, function (err, roomData) {
if (err) {
return callback(err);
}
@@ -33,7 +33,7 @@ module.exports = function(Messaging) {
};
function modifyRoomData(rooms) {
- rooms.forEach(function(data) {
+ rooms.forEach(function (data) {
if (data) {
data.roomName = data.roomName || '';
data.roomName = validator.escape(String(data.roomName));
@@ -44,7 +44,7 @@ module.exports = function(Messaging) {
});
}
- Messaging.newRoom = function(uid, toUids, callback) {
+ Messaging.newRoom = function (uid, toUids, callback) {
var roomId;
var now = Date.now();
async.waterfall([
@@ -74,30 +74,30 @@ module.exports = function(Messaging) {
], callback);
};
- Messaging.isUserInRoom = function(uid, roomId, callback) {
+ Messaging.isUserInRoom = function (uid, roomId, callback) {
async.waterfall([
- function(next) {
+ function (next) {
db.isSortedSetMember('chat:room:' + roomId + ':uids', uid, next);
},
- function(inRoom, next) {
+ function (inRoom, next) {
plugins.fireHook('filter:messaging.isUserInRoom', {uid: uid, roomId: roomId, inRoom: inRoom}, next);
},
- function(data, next) {
+ function (data, next) {
next(null, data.inRoom);
}
], callback);
};
- Messaging.roomExists = function(roomId, callback) {
+ Messaging.roomExists = function (roomId, callback) {
db.exists('chat:room:' + roomId + ':uids', callback);
};
- Messaging.getUserCountInRoom = function(roomId, callback) {
+ Messaging.getUserCountInRoom = function (roomId, callback) {
db.sortedSetCard('chat:room:' + roomId + ':uids', callback);
};
- Messaging.isRoomOwner = function(uid, roomId, callback) {
- db.getObjectField('chat:room:' + roomId, 'owner', function(err, owner) {
+ Messaging.isRoomOwner = function (uid, roomId, callback) {
+ db.getObjectField('chat:room:' + roomId, 'owner', function (err, owner) {
if (err) {
return callback(err);
}
@@ -106,7 +106,7 @@ module.exports = function(Messaging) {
});
};
- Messaging.addUsersToRoom = function(uid, uids, roomId, callback) {
+ Messaging.addUsersToRoom = function (uid, uids, roomId, callback) {
async.waterfall([
function (next) {
Messaging.isUserInRoom(uid, roomId, next);
@@ -116,18 +116,18 @@ module.exports = function(Messaging) {
return next(new Error('[[error:cant-add-users-to-chat-room]]'));
}
var now = Date.now();
- var timestamps = uids.map(function() {
+ var timestamps = uids.map(function () {
return now;
});
db.sortedSetAdd('chat:room:' + roomId + ':uids', timestamps, uids, next);
},
- function(next) {
+ function (next) {
async.parallel({
userCount: async.apply(db.sortedSetCard, 'chat:room:' + roomId + ':uids'),
roomData: async.apply(db.getObject, 'chat:room:' + roomId)
}, next);
},
- function(results, next) {
+ function (results, next) {
if (!results.roomData.hasOwnProperty('groupChat') && results.userCount > 2) {
return db.setObjectField('chat:room:' + roomId, 'groupChat', 1, next);
}
@@ -136,7 +136,7 @@ module.exports = function(Messaging) {
], callback);
};
- Messaging.removeUsersFromRoom = function(uid, uids, roomId, callback) {
+ Messaging.removeUsersFromRoom = function (uid, uids, roomId, callback) {
async.waterfall([
function (next) {
async.parallel({
@@ -156,16 +156,16 @@ module.exports = function(Messaging) {
], callback);
};
- Messaging.leaveRoom = function(uids, roomId, callback) {
+ Messaging.leaveRoom = function (uids, roomId, callback) {
async.waterfall([
function (next) {
db.sortedSetRemove('chat:room:' + roomId + ':uids', uids, next);
},
function (next) {
- var keys = uids.map(function(uid) {
+ var keys = uids.map(function (uid) {
return 'uid:' + uid + ':chat:rooms';
});
- keys.concat(uids.map(function(uid) {
+ keys.concat(uids.map(function (uid) {
return 'uid:' + uid + ':chat:rooms:unread';
}));
db.sortedSetsRemove(keys, roomId, next);
@@ -173,11 +173,11 @@ module.exports = function(Messaging) {
], callback);
};
- Messaging.getUidsInRoom = function(roomId, start, stop, callback) {
+ Messaging.getUidsInRoom = function (roomId, start, stop, callback) {
db.getSortedSetRevRange('chat:room:' + roomId + ':uids', start, stop, callback);
};
- Messaging.getUsersInRoom = function(roomId, start, stop, callback) {
+ Messaging.getUsersInRoom = function (roomId, start, stop, callback) {
async.waterfall([
function (next) {
Messaging.getUidsInRoom(roomId, start, stop, next);
@@ -188,7 +188,7 @@ module.exports = function(Messaging) {
], callback);
};
- Messaging.renameRoom = function(uid, roomId, newName, callback) {
+ Messaging.renameRoom = function (uid, roomId, newName, callback) {
if (!newName) {
return callback(new Error('[[error:invalid-name]]'));
}
diff --git a/src/messaging/unread.js b/src/messaging/unread.js
index 0562551540..91c9a364ac 100644
--- a/src/messaging/unread.js
+++ b/src/messaging/unread.js
@@ -5,20 +5,20 @@ var async = require('async');
var db = require('../database');
var sockets = require('../socket.io');
-module.exports = function(Messaging) {
+module.exports = function (Messaging) {
- Messaging.getUnreadCount = function(uid, callback) {
+ Messaging.getUnreadCount = function (uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null, 0);
}
db.sortedSetCard('uid:' + uid + ':chat:rooms:unread', callback);
};
- Messaging.pushUnreadCount = function(uid) {
+ Messaging.pushUnreadCount = function (uid) {
if (!parseInt(uid, 10)) {
return callback(null, 0);
}
- Messaging.getUnreadCount(uid, function(err, unreadCount) {
+ Messaging.getUnreadCount(uid, function (err, unreadCount) {
if (err) {
return;
}
@@ -26,15 +26,15 @@ module.exports = function(Messaging) {
});
};
- Messaging.markRead = function(uid, roomId, callback) {
+ Messaging.markRead = function (uid, roomId, callback) {
db.sortedSetRemove('uid:' + uid + ':chat:rooms:unread', roomId, callback);
};
- Messaging.markAllRead = function(uid, callback) {
+ Messaging.markAllRead = function (uid, callback) {
db.delete('uid:' + uid + ':chat:rooms:unread', callback);
};
- Messaging.markUnread = function(uids, roomId, callback) {
+ Messaging.markUnread = function (uids, roomId, callback) {
async.waterfall([
function (next) {
Messaging.roomExists(roomId, next);
@@ -43,7 +43,7 @@ module.exports = function(Messaging) {
if (!exists) {
return next(new Error('[[error:chat-room-does-not-exist]]'));
}
- var keys = uids.map(function(uid) {
+ var keys = uids.map(function (uid) {
return 'uid:' + uid + ':chat:rooms:unread';
});
diff --git a/src/meta.js b/src/meta.js
index 948d2aaf70..c732de15f4 100644
--- a/src/meta.js
+++ b/src/meta.js
@@ -25,33 +25,33 @@ var utils = require('../public/src/utils');
Meta.blacklist = require('./meta/blacklist');
/* Assorted */
- Meta.userOrGroupExists = function(slug, callback) {
+ Meta.userOrGroupExists = function (slug, callback) {
var user = require('./user');
var groups = require('./groups');
slug = utils.slugify(slug);
async.parallel([
async.apply(user.existsBySlug, slug),
async.apply(groups.existsBySlug, slug)
- ], function(err, results) {
- callback(err, results ? results.some(function(result) { return result; }) : false);
+ ], function (err, results) {
+ callback(err, results ? results.some(function (result) { return result; }) : false);
});
};
/**
* Reload deprecated as of v1.1.2+, remove in v2.x
*/
- Meta.reload = function(callback) {
+ Meta.reload = function (callback) {
restart();
callback();
};
- Meta.restart = function() {
+ Meta.restart = function () {
pubsub.publish('meta:restart', {hostname: os.hostname()});
restart();
};
if (nconf.get('isPrimary') === 'true') {
- pubsub.on('meta:restart', function(data) {
+ pubsub.on('meta:restart', function (data) {
if (data.hostname !== os.hostname()) {
restart();
}
diff --git a/src/meta/blacklist.js b/src/meta/blacklist.js
index 47381e487b..679dc3cec9 100644
--- a/src/meta/blacklist.js
+++ b/src/meta/blacklist.js
@@ -9,11 +9,11 @@ var Blacklist = {
_rules: []
};
-Blacklist.load = function(callback) {
+Blacklist.load = function (callback) {
async.waterfall([
async.apply(db.get, 'ip-blacklist-rules'),
async.apply(Blacklist.validate)
- ], function(err, rules) {
+ ], function (err, rules) {
if (err) {
return callback(err);
}
@@ -33,8 +33,8 @@ Blacklist.load = function(callback) {
});
};
-Blacklist.save = function(rules, callback) {
- db.set('ip-blacklist-rules', rules, function(err) {
+Blacklist.save = function (rules, callback) {
+ db.set('ip-blacklist-rules', rules, function (err) {
if (err) {
return callback(err);
}
@@ -42,15 +42,15 @@ Blacklist.save = function(rules, callback) {
});
};
-Blacklist.get = function(callback) {
+Blacklist.get = function (callback) {
db.get('ip-blacklist-rules', callback);
};
-Blacklist.test = function(clientIp, callback) {
+Blacklist.test = function (clientIp, callback) {
if (
Blacklist._rules.ipv4.indexOf(clientIp) === -1 // not explicitly specified in ipv4 list
&& Blacklist._rules.ipv6.indexOf(clientIp) === -1 // not explicitly specified in ipv6 list
- && !Blacklist._rules.cidr.some(function(subnet) {
+ && !Blacklist._rules.cidr.some(function (subnet) {
return ip.cidrSubnet(subnet).contains(clientIp);
}) // not in a blacklisted cidr range
) {
@@ -71,7 +71,7 @@ Blacklist.test = function(clientIp, callback) {
}
};
-Blacklist.validate = function(rules, callback) {
+Blacklist.validate = function (rules, callback) {
rules = (rules || '').split('\n');
var ipv4 = [];
var ipv6 = [];
@@ -84,13 +84,13 @@ Blacklist.validate = function(rules, callback) {
// Filter out blank lines and lines starting with the hash character (comments)
// Also trim inputs and remove inline comments
- rules = rules.map(function(rule) {
+ rules = rules.map(function (rule) {
rule = rule.replace(inlineCommentMatch, '').trim();
return rule.length && !rule.startsWith('#') ? rule : null;
}).filter(Boolean);
// Filter out invalid rules
- rules = rules.filter(function(rule) {
+ rules = rules.filter(function (rule) {
if (whitelist.indexOf(rule) !== -1) {
invalid.push(rule);
return false;
diff --git a/src/meta/configs.js b/src/meta/configs.js
index 723e58083d..0a8435e531 100644
--- a/src/meta/configs.js
+++ b/src/meta/configs.js
@@ -8,7 +8,7 @@ var db = require('../database');
var pubsub = require('../pubsub');
var utils = require('../../public/src/utils');
-module.exports = function(Meta) {
+module.exports = function (Meta) {
Meta.config = {};
Meta.configs = {};
@@ -47,12 +47,12 @@ module.exports = function(Meta) {
};
Meta.configs.set = function (field, value, callback) {
- callback = callback || function() {};
+ callback = callback || function () {};
if (!field) {
return callback(new Error('invalid config field'));
}
- db.setObjectField('config', field, value, function(err) {
+ db.setObjectField('config', field, value, function (err) {
if (err) {
return callback(err);
}
@@ -64,12 +64,12 @@ module.exports = function(Meta) {
});
};
- Meta.configs.setMultiple = function(data, callback) {
- processConfig(data, function(err) {
+ Meta.configs.setMultiple = function (data, callback) {
+ processConfig(data, function (err) {
if (err) {
return callback(err);
}
- db.setObject('config', data, function(err) {
+ db.setObject('config', data, function (err) {
if (err) {
return callback(err);
}
@@ -92,7 +92,7 @@ module.exports = function(Meta) {
var less = require('less');
less.render(data.customCSS, {
compress: true
- }, function(err, lessObject) {
+ }, function (err, lessObject) {
if (err) {
winston.error('[less] Could not convert custom LESS to CSS! Please check your syntax.');
return callback(null, '');
@@ -119,13 +119,13 @@ module.exports = function(Meta) {
});
Meta.configs.setOnEmpty = function (values, callback) {
- db.getObject('config', function(err, data) {
+ db.getObject('config', function (err, data) {
if (err) {
return callback(err);
}
data = data || {};
var empty = {};
- Object.keys(values).forEach(function(key) {
+ Object.keys(values).forEach(function (key) {
if (!data.hasOwnProperty(key)) {
empty[key] = values[key];
}
diff --git a/src/meta/css.js b/src/meta/css.js
index 03779c1af6..ce31ea1f13 100644
--- a/src/meta/css.js
+++ b/src/meta/css.js
@@ -15,21 +15,21 @@ var db = require('../database');
var file = require('../file');
var utils = require('../../public/src/utils');
-module.exports = function(Meta) {
+module.exports = function (Meta) {
Meta.css = {};
Meta.css.cache = undefined;
Meta.css.acpCache = undefined;
- Meta.css.minify = function(callback) {
- callback = callback || function() {};
+ Meta.css.minify = function (callback) {
+ callback = callback || function () {};
if (nconf.get('isPrimary') !== 'true') {
winston.verbose('[meta/css] Cluster worker ' + process.pid + ' skipping LESS/CSS compilation');
return callback();
}
winston.verbose('[meta/css] Minifying LESS/CSS');
- db.getObjectFields('config', ['theme:type', 'theme:id'], function(err, themeData) {
+ db.getObjectFields('config', ['theme:type', 'theme:id'], function (err, themeData) {
if (err) {
return callback(err);
}
@@ -47,18 +47,18 @@ module.exports = function(Meta) {
plugins.cssFiles = filterMissingFiles(plugins.cssFiles);
async.waterfall([
- function(next) {
+ function (next) {
getStyleSource(plugins.lessFiles, '\n@import ".', '.less', next);
},
- function(src, next) {
+ function (src, next) {
source += src;
getStyleSource(plugins.cssFiles, '\n@import (inline) ".', '.css', next);
},
- function(src, next) {
+ function (src, next) {
source += src;
next();
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
@@ -84,7 +84,7 @@ module.exports = function(Meta) {
var fromFile = nconf.get('from-file') || '';
async.series([
- function(next) {
+ function (next) {
if (fromFile.match('clientLess')) {
winston.info('[minifier] Compiling front-end LESS files skipped');
return Meta.css.getFromFile(path.join(__dirname, '../../public/stylesheet.css'), 'cache', next);
@@ -92,7 +92,7 @@ module.exports = function(Meta) {
minify(source, paths, 'cache', next);
},
- function(next) {
+ function (next) {
if (fromFile.match('acpLess')) {
winston.info('[minifier] Compiling ACP LESS files skipped');
return Meta.css.getFromFile(path.join(__dirname, '../../public/admin.css'), 'acpCache', next);
@@ -100,7 +100,7 @@ module.exports = function(Meta) {
minify(acpSource, paths, 'acpCache', next);
}
- ], function(err, minified) {
+ ], function (err, minified) {
if (err) {
return callback(err);
}
@@ -126,7 +126,7 @@ module.exports = function(Meta) {
var pluginDirectories = [],
source = '';
- files.forEach(function(styleFile) {
+ files.forEach(function (styleFile) {
if (styleFile.endsWith(extension)) {
source += prefix + path.sep + styleFile + '";';
} else {
@@ -134,27 +134,27 @@ module.exports = function(Meta) {
}
});
- async.each(pluginDirectories, function(directory, next) {
- utils.walk(directory, function(err, styleFiles) {
+ async.each(pluginDirectories, function (directory, next) {
+ utils.walk(directory, function (err, styleFiles) {
if (err) {
return next(err);
}
- styleFiles.forEach(function(styleFile) {
+ styleFiles.forEach(function (styleFile) {
source += prefix + path.sep + styleFile + '";';
});
next();
});
- }, function(err) {
+ }, function (err) {
callback(err, source);
});
}
- Meta.css.commitToFile = function(filename, callback) {
+ Meta.css.commitToFile = function (filename, callback) {
var file = (filename === 'acpCache' ? 'admin' : 'stylesheet') + '.css';
- fs.writeFile(path.join(__dirname, '../../public/' + file), Meta.css[filename], function(err) {
+ fs.writeFile(path.join(__dirname, '../../public/' + file), Meta.css[filename], function (err) {
if (!err) {
winston.verbose('[meta/css] ' + file + ' committed to disk.');
} else {
@@ -166,10 +166,10 @@ module.exports = function(Meta) {
});
};
- Meta.css.getFromFile = function(filePath, filename, callback) {
+ Meta.css.getFromFile = function (filePath, filename, callback) {
winston.verbose('[meta/css] Reading stylesheet ' + filePath.split('/').pop() + ' from file');
- fs.readFile(filePath, function(err, file) {
+ fs.readFile(filePath, function (err, file) {
if (err) {
return callback(err);
}
@@ -183,7 +183,7 @@ module.exports = function(Meta) {
less.render(source, {
paths: paths,
compress: true
- }, function(err, lessOutput) {
+ }, function (err, lessOutput) {
if (err) {
winston.error('[meta/css] Could not minify LESS/CSS: ' + err.message);
if (typeof callback === 'function') {
@@ -201,7 +201,7 @@ module.exports = function(Meta) {
// Save the compiled CSS in public/ so things like nginx can serve it
if (nconf.get('isPrimary') === 'true' && (nconf.get('local-assets') === undefined || nconf.get('local-assets') !== false)) {
- return Meta.css.commitToFile(destination, function() {
+ return Meta.css.commitToFile(destination, function () {
if (typeof callback === 'function') {
callback(null, result.css);
}
@@ -217,7 +217,7 @@ module.exports = function(Meta) {
}
function filterMissingFiles(files) {
- return files.filter(function(filePath) {
+ return files.filter(function (filePath) {
var exists = file.existsSync(path.join(__dirname, '../../node_modules', filePath));
if (!exists) {
winston.warn('[meta/css] File not found! ' + filePath);
diff --git a/src/meta/dependencies.js b/src/meta/dependencies.js
index a1d9b418a7..f115ff6bfc 100644
--- a/src/meta/dependencies.js
+++ b/src/meta/dependencies.js
@@ -8,20 +8,20 @@ var winston = require('winston');
var pkg = require('../../package.json');
-module.exports = function(Meta) {
+module.exports = function (Meta) {
Meta.dependencies = {};
- Meta.dependencies.check = function(callback) {
+ Meta.dependencies.check = function (callback) {
var modules = Object.keys(pkg.dependencies);
var depsOutdated = false;
var depsMissing = false;
winston.verbose('Checking dependencies for outdated modules');
- async.every(modules, function(module, next) {
+ async.every(modules, function (module, next) {
fs.readFile(path.join(__dirname, '../../node_modules/', module, 'package.json'), {
encoding: 'utf-8'
- }, function(err, pkgData) {
+ }, function (err, pkgData) {
// If a bundled plugin/theme is not present, skip the dep check (#3384)
if (err && err.code === 'ENOENT' && (module === 'nodebb-rewards-essentials' || module.startsWith('nodebb-plugin') || module.startsWith('nodebb-theme'))) {
winston.warn('[meta/dependencies] Bundled plugin ' + module + ' not found, skipping dependency check.');
@@ -45,7 +45,7 @@ module.exports = function(Meta) {
next(true);
}
});
- }, function(ok) {
+ }, function (ok) {
if (depsMissing) {
callback(new Error('dependencies-missing'));
} else if (depsOutdated) {
diff --git a/src/meta/errors.js b/src/meta/errors.js
index 7cc5bdade5..58e381e270 100644
--- a/src/meta/errors.js
+++ b/src/meta/errors.js
@@ -5,24 +5,24 @@ var validator = require('validator');
var db = require('../database');
var analytics = require('../analytics');
-module.exports = function(Meta) {
+module.exports = function (Meta) {
Meta.errors = {};
- Meta.errors.log404 = function(route, callback) {
- callback = callback || function() {};
+ Meta.errors.log404 = function (route, callback) {
+ callback = callback || function () {};
route = route.replace(/\/$/, ''); // remove trailing slashes
analytics.increment('errors:404');
db.sortedSetIncrBy('errors:404', 1, route, callback);
};
- Meta.errors.get = function(escape, callback) {
- db.getSortedSetRevRangeWithScores('errors:404', 0, -1, function(err, data) {
+ Meta.errors.get = function (escape, callback) {
+ db.getSortedSetRevRangeWithScores('errors:404', 0, -1, function (err, data) {
if (err) {
return callback(err);
}
- data = data.map(function(nfObject) {
+ data = data.map(function (nfObject) {
nfObject.value = escape ? validator.escape(String(nfObject.value || '')) : nfObject.value;
return nfObject;
});
@@ -31,7 +31,7 @@ module.exports = function(Meta) {
});
};
- Meta.errors.clear = function(callback) {
+ Meta.errors.clear = function (callback) {
db.delete('errors:404', callback);
};
};
diff --git a/src/meta/js.js b/src/meta/js.js
index 33a51a4ab1..cfb588125d 100644
--- a/src/meta/js.js
+++ b/src/meta/js.js
@@ -11,7 +11,7 @@ var plugins = require('../plugins');
var emitter = require('../emitter');
var utils = require('../../public/src/utils');
-module.exports = function(Meta) {
+module.exports = function (Meta) {
Meta.js = {
target: {},
@@ -87,13 +87,13 @@ module.exports = function(Meta) {
}
};
- Meta.js.bridgeModules = function(app, callback) {
+ Meta.js.bridgeModules = function (app, callback) {
// Add routes for AMD-type modules to serve those files
var numBridged = 0,
- addRoute = function(relPath) {
+ addRoute = function (relPath) {
var relativePath = nconf.get('relative_path');
- app.get(relativePath + '/src/modules/' + relPath, function(req, res) {
+ app.get(relativePath + '/src/modules/' + relPath, function (req, res) {
return res.sendFile(path.join(__dirname, '../../', Meta.js.scripts.modules[relPath]), {
maxAge: app.enabled('cache') ? 5184000000 : 0
});
@@ -101,7 +101,7 @@ module.exports = function(Meta) {
};
async.series([
- function(next) {
+ function (next) {
for(var relPath in Meta.js.scripts.modules) {
if (Meta.js.scripts.modules.hasOwnProperty(relPath)) {
addRoute(relPath);
@@ -111,7 +111,7 @@ module.exports = function(Meta) {
next();
}
- ], function(err) {
+ ], function (err) {
if (err) {
winston.error('[meta/js] Encountered error while bridging modules:' + err.message);
}
@@ -121,7 +121,7 @@ module.exports = function(Meta) {
});
};
- Meta.js.minify = function(target, callback) {
+ Meta.js.minify = function (target, callback) {
if (nconf.get('isPrimary') !== 'true') {
if (typeof callback === 'function') {
callback();
@@ -137,7 +137,7 @@ module.exports = function(Meta) {
Meta.js.target[target] = {};
- Meta.js.prepare(target, function() {
+ Meta.js.prepare(target, function () {
minifier.send({
action: 'js',
minify: global.env !== 'development',
@@ -145,7 +145,7 @@ module.exports = function(Meta) {
});
});
- minifier.on('message', function(message) {
+ minifier.on('message', function (message) {
switch(message.type) {
case 'end':
Meta.js.target[target].cache = message.minified;
@@ -161,7 +161,7 @@ module.exports = function(Meta) {
}
if (nconf.get('local-assets') === undefined || nconf.get('local-assets') !== false) {
- return Meta.js.commitToFile(target, function() {
+ return Meta.js.commitToFile(target, function () {
if (typeof callback === 'function') {
callback();
}
@@ -188,12 +188,12 @@ module.exports = function(Meta) {
});
};
- Meta.js.prepare = function(target, callback) {
+ Meta.js.prepare = function (target, callback) {
var pluginsScripts = [];
var pluginDirectories = [];
- pluginsScripts = plugins[target === 'nodebb.min.js' ? 'clientScripts' : 'acpScripts'].filter(function(path) {
+ pluginsScripts = plugins[target === 'nodebb.min.js' ? 'clientScripts' : 'acpScripts'].filter(function (path) {
if (path.endsWith('.js')) {
return true;
}
@@ -202,12 +202,12 @@ module.exports = function(Meta) {
return false;
});
- async.each(pluginDirectories, function(directory, next) {
- utils.walk(directory, function(err, scripts) {
+ async.each(pluginDirectories, function (directory, next) {
+ utils.walk(directory, function (err, scripts) {
pluginsScripts = pluginsScripts.concat(scripts);
next(err);
});
- }, function(err) {
+ }, function (err) {
if (err) {
return callback(err);
}
@@ -220,7 +220,7 @@ module.exports = function(Meta) {
Meta.js.target[target].scripts = Meta.js.target[target].scripts.concat(Meta.js.scripts.rjs);
}
- Meta.js.target[target].scripts = Meta.js.target[target].scripts.map(function(script) {
+ Meta.js.target[target].scripts = Meta.js.target[target].scripts.map(function (script) {
return path.relative(basePath, script).replace(/\\/g, '/');
});
@@ -228,13 +228,13 @@ module.exports = function(Meta) {
});
};
- Meta.js.killMinifier = function() {
+ Meta.js.killMinifier = function () {
if (Meta.js.minifierProc) {
Meta.js.minifierProc.kill('SIGTERM');
}
};
- Meta.js.commitToFile = function(target, callback) {
+ Meta.js.commitToFile = function (target, callback) {
fs.writeFile(path.join(__dirname, '../../public/' + target), Meta.js.target[target].cache, function (err) {
if (err) {
winston.error('[meta/js] ' + err.message);
@@ -246,12 +246,12 @@ module.exports = function(Meta) {
});
};
- Meta.js.getFromFile = function(target, callback) {
+ Meta.js.getFromFile = function (target, callback) {
var scriptPath = path.join(__dirname, '../../public/' + target),
mapPath = path.join(__dirname, '../../public/' + target + '.map'),
paths = [scriptPath];
- file.exists(scriptPath, function(exists) {
+ file.exists(scriptPath, function (exists) {
if (!exists) {
winston.warn('[meta/js] ' + target + ' not found on disk, re-minifying');
Meta.js.minify(target, callback);
@@ -262,12 +262,12 @@ module.exports = function(Meta) {
return callback();
}
- file.exists(mapPath, function(exists) {
+ file.exists(mapPath, function (exists) {
if (exists) {
paths.push(mapPath);
}
- async.map(paths, fs.readFile, function(err, files) {
+ async.map(paths, fs.readFile, function (err, files) {
if (err) {
return callback(err);
}
diff --git a/src/meta/logs.js b/src/meta/logs.js
index 4e99406175..b335ff281e 100644
--- a/src/meta/logs.js
+++ b/src/meta/logs.js
@@ -4,16 +4,16 @@ var path = require('path');
var fs = require('fs');
var winston = require('winston');
-module.exports = function(Meta) {
+module.exports = function (Meta) {
Meta.logs = {
path: path.join('logs', path.sep, 'output.log')
};
- Meta.logs.get = function(callback) {
+ Meta.logs.get = function (callback) {
fs.readFile(this.path, {
encoding: 'utf-8'
- }, function(err, logs) {
+ }, function (err, logs) {
if (err) {
winston.error('[meta/logs] Could not retrieve logs: ' + err.message);
}
@@ -22,7 +22,7 @@ module.exports = function(Meta) {
});
};
- Meta.logs.clear = function(callback) {
+ Meta.logs.clear = function (callback) {
fs.truncate(this.path, 0, callback);
};
};
\ No newline at end of file
diff --git a/src/meta/settings.js b/src/meta/settings.js
index 5604800f6d..299286abdd 100644
--- a/src/meta/settings.js
+++ b/src/meta/settings.js
@@ -3,23 +3,23 @@
var db = require('../database');
var plugins = require('../plugins');
-module.exports = function(Meta) {
+module.exports = function (Meta) {
Meta.settings = {};
- Meta.settings.get = function(hash, callback) {
- db.getObject('settings:' + hash, function(err, settings) {
+ Meta.settings.get = function (hash, callback) {
+ db.getObject('settings:' + hash, function (err, settings) {
callback(err, settings || {});
});
};
- Meta.settings.getOne = function(hash, field, callback) {
+ Meta.settings.getOne = function (hash, field, callback) {
db.getObjectField('settings:' + hash, field, callback);
};
- Meta.settings.set = function(hash, values, callback) {
+ Meta.settings.set = function (hash, values, callback) {
var key = 'settings:' + hash;
- db.setObject(key, values, function(err) {
+ db.setObject(key, values, function (err) {
if (err) {
return callback(err);
}
@@ -34,18 +34,18 @@ module.exports = function(Meta) {
});
};
- Meta.settings.setOne = function(hash, field, value, callback) {
+ Meta.settings.setOne = function (hash, field, value, callback) {
db.setObjectField('settings:' + hash, field, value, callback);
};
Meta.settings.setOnEmpty = function (hash, values, callback) {
- db.getObject('settings:' + hash, function(err, settings) {
+ db.getObject('settings:' + hash, function (err, settings) {
if (err) {
return callback(err);
}
settings = settings || {};
var empty = {};
- Object.keys(values).forEach(function(key) {
+ Object.keys(values).forEach(function (key) {
if (!settings.hasOwnProperty(key)) {
empty[key] = values[key];
}
diff --git a/src/meta/sounds.js b/src/meta/sounds.js
index 7e901c69c7..6068f16f5f 100644
--- a/src/meta/sounds.js
+++ b/src/meta/sounds.js
@@ -11,11 +11,11 @@ var async = require('async');
var plugins = require('../plugins');
var db = require('../database');
-module.exports = function(Meta) {
+module.exports = function (Meta) {
Meta.sounds = {};
- Meta.sounds.init = function(callback) {
+ Meta.sounds.init = function (callback) {
if (nconf.get('isPrimary') === 'true') {
setupSounds(callback);
} else {
@@ -25,21 +25,21 @@ module.exports = function(Meta) {
}
};
- Meta.sounds.getFiles = function(callback) {
+ Meta.sounds.getFiles = function (callback) {
async.waterfall([
- function(next) {
+ function (next) {
fs.readdir(path.join(__dirname, '../../public/sounds'), next);
},
- function(sounds, next) {
- fs.readdir(path.join(__dirname, '../../public/uploads/sounds'), function(err, uploaded) {
+ function (sounds, next) {
+ fs.readdir(path.join(__dirname, '../../public/uploads/sounds'), function (err, uploaded) {
next(err, sounds.concat(uploaded));
});
}
- ], function(err, files) {
+ ], function (err, files) {
var localList = {};
// Filter out hidden files
- files = files.filter(function(filename) {
+ files = files.filter(function (filename) {
return !filename.startsWith('.');
});
@@ -50,7 +50,7 @@ module.exports = function(Meta) {
}
// Return proper paths
- files.forEach(function(filename) {
+ files.forEach(function (filename) {
localList[filename] = nconf.get('relative_path') + '/sounds/' + filename;
});
@@ -58,16 +58,16 @@ module.exports = function(Meta) {
});
};
- Meta.sounds.getMapping = function(uid, callback) {
+ Meta.sounds.getMapping = function (uid, callback) {
var user = require('../user');
async.parallel({
- defaultMapping: function(next) {
+ defaultMapping: function (next) {
db.getObject('settings:sounds', next);
},
- userSettings: function(next) {
+ userSettings: function (next) {
user.getSettings(uid, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -91,17 +91,17 @@ module.exports = function(Meta) {
var soundsPath = path.join(__dirname, '../../public/sounds');
async.waterfall([
- function(next) {
+ function (next) {
fs.readdir(path.join(__dirname, '../../public/uploads/sounds'), next);
},
- function(uploaded, next) {
- uploaded = uploaded.filter(function(filename) {
+ function (uploaded, next) {
+ uploaded = uploaded.filter(function (filename) {
return !filename.startsWith('.');
- }).map(function(filename) {
+ }).map(function (filename) {
return path.join(__dirname, '../../public/uploads/sounds', filename);
});
- plugins.fireHook('filter:sounds.get', uploaded, function(err, filePaths) {
+ plugins.fireHook('filter:sounds.get', uploaded, function (err, filePaths) {
if (err) {
winston.error('Could not initialise sound files:' + err.message);
return;
@@ -109,7 +109,7 @@ module.exports = function(Meta) {
if (nconf.get('local-assets') === false) {
// Don't regenerate the public/sounds/ directory. Instead, create a mapping for the router to use
- Meta.sounds._filePathHash = filePaths.reduce(function(hash, filePath) {
+ Meta.sounds._filePathHash = filePaths.reduce(function (hash, filePath) {
hash[path.basename(filePath)] = filePath;
return hash;
}, {});
@@ -124,26 +124,26 @@ module.exports = function(Meta) {
// Clear the sounds directory
async.series([
- function(next) {
+ function (next) {
rimraf(soundsPath, next);
},
- function(next) {
+ function (next) {
mkdirp(soundsPath, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
winston.error('Could not initialise sound files:' + err.message);
return;
}
// Link paths
- async.each(filePaths, function(filePath, next) {
+ async.each(filePaths, function (filePath, next) {
if (process.platform === 'win32') {
fs.link(filePath, path.join(soundsPath, path.basename(filePath)), next);
} else {
fs.symlink(filePath, path.join(soundsPath, path.basename(filePath)), 'file', next);
}
- }, function(err) {
+ }, function (err) {
if (!err) {
winston.verbose('[sounds] Sounds OK');
} else {
diff --git a/src/meta/tags.js b/src/meta/tags.js
index 1b0f0cfd52..1d64a7f93d 100644
--- a/src/meta/tags.js
+++ b/src/meta/tags.js
@@ -6,12 +6,12 @@ var async = require('async');
var winston = require('winston');
var plugins = require('../plugins');
-module.exports = function(Meta) {
+module.exports = function (Meta) {
Meta.tags = {};
- Meta.tags.parse = function(meta, link, callback) {
+ Meta.tags.parse = function (meta, link, callback) {
async.parallel({
- tags: function(next) {
+ tags: function (next) {
var defaultTags = [{
name: 'viewport',
content: 'width=device-width, initial-scale=1.0'
@@ -42,7 +42,7 @@ module.exports = function(Meta) {
}];
plugins.fireHook('filter:meta.getMetaTags', defaultTags, next);
},
- links: function(next) {
+ links: function (next) {
var defaultLinks = [{
rel: "icon",
type: "image/x-icon",
@@ -85,12 +85,12 @@ module.exports = function(Meta) {
}
plugins.fireHook('filter:meta.getLinkTags', defaultLinks, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
- meta = results.tags.concat(meta || []).map(function(tag) {
+ meta = results.tags.concat(meta || []).map(function (tag) {
if (!tag || typeof tag.content !== 'string') {
winston.warn('Invalid meta tag. ', tag);
return tag;
@@ -116,7 +116,7 @@ module.exports = function(Meta) {
function addDescription(meta) {
var hasDescription = false;
- meta.forEach(function(tag) {
+ meta.forEach(function (tag) {
if (tag.name === 'description') {
hasDescription = true;
}
diff --git a/src/meta/templates.js b/src/meta/templates.js
index d1d1ef7fab..d335709461 100644
--- a/src/meta/templates.js
+++ b/src/meta/templates.js
@@ -15,8 +15,8 @@ var utils = require('../../public/src/utils');
var Templates = {};
var searchIndex = {};
-Templates.compile = function(callback) {
- callback = callback || function() {};
+Templates.compile = function (callback) {
+ callback = callback || function () {};
var fromFile = nconf.get('from-file') || '';
if (nconf.get('isPrimary') === 'false' || fromFile.match('tpl')) {
@@ -58,13 +58,13 @@ function preparePaths(baseTemplatesPaths, callback) {
function (next) {
mkdirp(viewsPath, next);
},
- function(viewsPath, next) {
+ function (viewsPath, next) {
plugins.fireHook('static:templates.precompile', {}, next);
},
- function(next) {
+ function (next) {
plugins.getTemplates(next);
}
- ], function(err, pluginTemplates) {
+ ], function (err, pluginTemplates) {
if (err) {
return callback(err);
}
@@ -72,13 +72,13 @@ function preparePaths(baseTemplatesPaths, callback) {
winston.verbose('[meta/templates] Compiling templates');
async.parallel({
- coreTpls: function(next) {
+ coreTpls: function (next) {
utils.walk(coreTemplatesPath, next);
},
- baseThemes: function(next) {
- async.map(baseTemplatesPaths, function(baseTemplatePath, next) {
- utils.walk(baseTemplatePath, function(err, paths) {
- paths = paths.map(function(tpl) {
+ baseThemes: function (next) {
+ async.map(baseTemplatesPaths, function (baseTemplatePath, next) {
+ utils.walk(baseTemplatePath, function (err, paths) {
+ paths = paths.map(function (tpl) {
return {
base: baseTemplatePath,
path: tpl.replace(baseTemplatePath, '')
@@ -89,17 +89,17 @@ function preparePaths(baseTemplatesPaths, callback) {
});
}, next);
}
- }, function(err, data) {
+ }, function (err, data) {
var baseThemes = data.baseThemes,
coreTpls = data.coreTpls,
paths = {};
- coreTpls.forEach(function(el, i) {
+ coreTpls.forEach(function (el, i) {
paths[coreTpls[i].replace(coreTemplatesPath, '')] = coreTpls[i];
});
- baseThemes.forEach(function(baseTpls) {
- baseTpls.forEach(function(el, i) {
+ baseThemes.forEach(function (baseTpls) {
+ baseTpls.forEach(function (el, i) {
paths[baseTpls[i].path] = path.join(baseTpls[i].base, baseTpls[i].path);
});
});
@@ -121,12 +121,12 @@ function compile(callback) {
viewsPath = nconf.get('views_dir');
- preparePaths(baseTemplatesPaths, function(err, paths) {
+ preparePaths(baseTemplatesPaths, function (err, paths) {
if (err) {
return callback(err);
}
- async.each(Object.keys(paths), function(relativePath, next) {
+ async.each(Object.keys(paths), function (relativePath, next) {
var file = fs.readFileSync(paths[relativePath]).toString(),
matches = null,
regex = /[ \t]*[ \t]*/;
@@ -148,13 +148,13 @@ function compile(callback) {
mkdirp.sync(path.join(viewsPath, relativePath.split('/').slice(0, -1).join('/')));
fs.writeFile(path.join(viewsPath, relativePath), file, next);
- }, function(err) {
+ }, function (err) {
if (err) {
winston.error('[meta/templates] ' + err.stack);
return callback(err);
}
- compileIndex(viewsPath, function() {
+ compileIndex(viewsPath, function () {
winston.verbose('[meta/templates] Successfully compiled templates.');
emitter.emit('templates:compiled');
diff --git a/src/meta/themes.js b/src/meta/themes.js
index 27cbdc92e7..416b9cb00d 100644
--- a/src/meta/themes.js
+++ b/src/meta/themes.js
@@ -10,7 +10,7 @@ var async = require('async');
var file = require('../file');
var db = require('../database');
-module.exports = function(Meta) {
+module.exports = function (Meta) {
Meta.themes = {};
Meta.themes.get = function (callback) {
@@ -68,7 +68,7 @@ module.exports = function(Meta) {
});
};
- Meta.themes.set = function(data, callback) {
+ Meta.themes.set = function (data, callback) {
var themeData = {
'theme:type': data.type,
'theme:id': data.id,
@@ -81,16 +81,16 @@ module.exports = function(Meta) {
case 'local':
async.waterfall([
async.apply(Meta.configs.get, 'theme:id'),
- function(current, next) {
+ function (current, next) {
async.series([
async.apply(db.sortedSetRemove, 'plugins:active', current),
async.apply(db.sortedSetAdd, 'plugins:active', 0, data.id)
- ], function(err) {
+ ], function (err) {
next(err);
});
},
- function(next) {
- fs.readFile(path.join(nconf.get('themes_path'), data.id, 'theme.json'), function(err, config) {
+ function (next) {
+ fs.readFile(path.join(nconf.get('themes_path'), data.id, 'theme.json'), function (err, config) {
if (!err) {
config = JSON.parse(config.toString());
next(null, config);
@@ -99,7 +99,7 @@ module.exports = function(Meta) {
}
});
},
- function(config, next) {
+ function (config, next) {
themeData['theme:staticDir'] = config.staticDir ? config.staticDir : '';
themeData['theme:templates'] = config.templates ? config.templates : '';
themeData['theme:src'] = '';
@@ -120,20 +120,20 @@ module.exports = function(Meta) {
}
};
- Meta.themes.setupPaths = function(callback) {
+ Meta.themes.setupPaths = function (callback) {
async.parallel({
themesData: Meta.themes.get,
- currentThemeId: function(next) {
+ currentThemeId: function (next) {
db.getObjectField('config', 'theme:id', next);
}
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return callback(err);
}
var themeId = data.currentThemeId || 'nodebb-theme-persona';
- var themeObj = data.themesData.filter(function(themeObj) {
+ var themeObj = data.themesData.filter(function (themeObj) {
return themeObj.id === themeId;
})[0];
@@ -150,7 +150,7 @@ module.exports = function(Meta) {
});
};
- Meta.themes.setPath = function(themeObj) {
+ Meta.themes.setPath = function (themeObj) {
// Theme's templates path
var themePath = nconf.get('base_templates_path'),
fallback = path.join(nconf.get('themes_path'), themeObj.id, 'templates');
diff --git a/src/middleware/admin.js b/src/middleware/admin.js
index 139bb2b83f..3240eaf0af 100644
--- a/src/middleware/admin.js
+++ b/src/middleware/admin.js
@@ -11,9 +11,9 @@ var controllers = {
helpers: require('../controllers/helpers')
};
-module.exports = function(middleware) {
+module.exports = function (middleware) {
middleware.admin = {};
- middleware.admin.isAdmin = function(req, res, next) {
+ middleware.admin.isAdmin = function (req, res, next) {
winston.warn('[middleware.admin.isAdmin] deprecation warning, no need to use this from plugins!');
if (!req.user) {
@@ -29,10 +29,10 @@ module.exports = function(middleware) {
});
};
- middleware.admin.buildHeader = function(req, res, next) {
+ middleware.admin.buildHeader = function (req, res, next) {
res.locals.renderAdminHeader = true;
- controllers.api.getConfig(req, res, function(err, config) {
+ controllers.api.getConfig(req, res, function (err, config) {
if (err) {
return next(err);
}
@@ -42,13 +42,13 @@ module.exports = function(middleware) {
});
};
- middleware.admin.renderHeader = function(req, res, data, next) {
+ middleware.admin.renderHeader = function (req, res, data, next) {
var custom_header = {
'plugins': [],
'authentication': []
};
- user.getUserFields(req.uid, ['username', 'userslug', 'email', 'picture', 'email:confirmed'], function(err, userData) {
+ user.getUserFields(req.uid, ['username', 'userslug', 'email', 'picture', 'email:confirmed'], function (err, userData) {
if (err) {
return next(err);
}
@@ -57,36 +57,36 @@ module.exports = function(middleware) {
userData['email:confirmed'] = parseInt(userData['email:confirmed'], 10) === 1;
async.parallel({
- scripts: function(next) {
- plugins.fireHook('filter:admin.scripts.get', [], function(err, scripts) {
+ scripts: function (next) {
+ plugins.fireHook('filter:admin.scripts.get', [], function (err, scripts) {
if (err) {
return next(err);
}
var arr = [];
- scripts.forEach(function(script) {
+ scripts.forEach(function (script) {
arr.push({src: script});
});
next(null, arr);
});
},
- custom_header: function(next) {
+ custom_header: function (next) {
plugins.fireHook('filter:admin.header.build', custom_header, next);
},
- config: function(next) {
+ config: function (next) {
controllers.api.getConfig(req, res, next);
},
- configs: function(next) {
+ configs: function (next) {
meta.configs.list(next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return next(err);
}
res.locals.config = results.config;
var acpPath = req.path.slice(1).split('/');
- acpPath.forEach(function(path, i) {
+ acpPath.forEach(function (path, i) {
acpPath[i] = path.charAt(0).toUpperCase() + path.slice(1);
});
acpPath = acpPath.join(' > ');
@@ -116,7 +116,7 @@ module.exports = function(middleware) {
};
- middleware.admin.renderFooter = function(req, res, data, next) {
+ middleware.admin.renderFooter = function (req, res, data, next) {
req.app.render('admin/footer', data, next);
};
};
diff --git a/src/middleware/header.js b/src/middleware/header.js
index 3386e35856..124bcacee7 100644
--- a/src/middleware/header.js
+++ b/src/middleware/header.js
@@ -14,33 +14,33 @@ var controllers = {
helpers: require('../controllers/helpers')
};
-module.exports = function(middleware) {
+module.exports = function (middleware) {
- middleware.buildHeader = function(req, res, next) {
+ middleware.buildHeader = function (req, res, next) {
res.locals.renderHeader = true;
res.locals.isAPI = false;
async.waterfall([
- function(next) {
+ function (next) {
middleware.applyCSRF(req, res, next);
},
- function(next) {
+ function (next) {
async.parallel({
- config: function(next) {
+ config: function (next) {
controllers.api.getConfig(req, res, next);
},
- plugins: function(next) {
+ plugins: function (next) {
plugins.fireHook('filter:middleware.buildHeader', {req: req, locals: res.locals}, next);
}
}, next);
},
- function(results, next) {
+ function (results, next) {
res.locals.config = results.config;
next();
}
], next);
};
- middleware.renderHeader = function(req, res, data, callback) {
+ middleware.renderHeader = function (req, res, data, callback) {
var registrationType = meta.config.registrationType || 'normal';
var templateValues = {
bootswatchCSS: meta.config['theme:src'],
@@ -61,16 +61,16 @@ module.exports = function(middleware) {
templateValues.configJSON = JSON.stringify(res.locals.config);
async.parallel({
- scripts: function(next) {
+ scripts: function (next) {
plugins.fireHook('filter:scripts.get', [], next);
},
- isAdmin: function(next) {
+ isAdmin: function (next) {
user.isAdministrator(req.uid, next);
},
- isGlobalMod: function(next) {
+ isGlobalMod: function (next) {
user.isGlobalModerator(req.uid, next);
},
- user: function(next) {
+ user: function (next) {
var userData = {
uid: 0,
username: '[[global:guest]]',
@@ -88,7 +88,7 @@ module.exports = function(middleware) {
next(null, userData);
}
},
- isEmailConfirmSent: function(next) {
+ isEmailConfirmSent: function (next) {
if (!meta.config.requireEmailConfirmation || !req.uid) {
return next(null, false);
}
@@ -96,7 +96,7 @@ module.exports = function(middleware) {
},
navigation: async.apply(navigation.get),
tags: async.apply(meta.tags.parse, res.locals.metaTags, res.locals.linkTags)
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -137,7 +137,7 @@ module.exports = function(middleware) {
templateValues.template = {name: res.locals.template};
templateValues.template[res.locals.template] = true;
- templateValues.scripts = results.scripts.map(function(script) {
+ templateValues.scripts = results.scripts.map(function (script) {
return {src: script};
});
@@ -145,7 +145,7 @@ module.exports = function(middleware) {
modifyTitle(templateValues);
}
- plugins.fireHook('filter:middleware.renderHeader', {templateValues: templateValues, req: req, res: res}, function(err, data) {
+ plugins.fireHook('filter:middleware.renderHeader', {templateValues: templateValues, req: req, res: res}, function (err, data) {
if (err) {
return callback(err);
}
@@ -155,8 +155,8 @@ module.exports = function(middleware) {
});
};
- middleware.renderFooter = function(req, res, data, callback) {
- plugins.fireHook('filter:middleware.renderFooter', {templateValues: data, req: req, res: res}, function(err, data) {
+ middleware.renderFooter = function (req, res, data, callback) {
+ plugins.fireHook('filter:middleware.renderFooter', {templateValues: data, req: req, res: res}, function (err, data) {
if (err) {
return callback(err);
}
@@ -169,7 +169,7 @@ module.exports = function(middleware) {
obj.browserTitle = title;
if (obj.metaTags) {
- obj.metaTags.forEach(function(tag, i) {
+ obj.metaTags.forEach(function (tag, i) {
if (tag.property === 'og:title') {
obj.metaTags[i].content = title;
}
diff --git a/src/middleware/headers.js b/src/middleware/headers.js
index 39c9520e59..f6e0a22562 100644
--- a/src/middleware/headers.js
+++ b/src/middleware/headers.js
@@ -5,7 +5,7 @@ var meta = require('../meta');
var _ = require('underscore');
-module.exports = function(middleware) {
+module.exports = function (middleware) {
middleware.addHeaders = function (req, res, next) {
var defaults = {
@@ -33,7 +33,7 @@ module.exports = function(middleware) {
next();
};
- middleware.addExpiresHeaders = function(req, res, next) {
+ middleware.addExpiresHeaders = function (req, res, next) {
if (req.app.enabled('cache')) {
res.setHeader("Cache-Control", "public, max-age=5184000");
res.setHeader("Expires", new Date(Date.now() + 5184000000).toUTCString());
diff --git a/src/middleware/index.js b/src/middleware/index.js
index 7d5b5a4e80..fdef19db32 100644
--- a/src/middleware/index.js
+++ b/src/middleware/index.js
@@ -35,7 +35,7 @@ require('./maintenance')(middleware);
require('./user')(middleware);
require('./headers')(middleware);
-middleware.authenticate = function(req, res, next) {
+middleware.authenticate = function (req, res, next) {
if (req.user) {
return next();
} else if (plugins.hasListeners('action:middleware.authenticate')) {
@@ -49,7 +49,7 @@ middleware.authenticate = function(req, res, next) {
controllers.helpers.notAllowed(req, res);
};
-middleware.pageView = function(req, res, next) {
+middleware.pageView = function (req, res, next) {
analytics.pageView({
ip: req.ip,
path: req.path,
@@ -72,16 +72,16 @@ middleware.pageView = function(req, res, next) {
};
-middleware.pluginHooks = function(req, res, next) {
- async.each(plugins.loadedHooks['filter:router.page'] || [], function(hookObj, next) {
+middleware.pluginHooks = function (req, res, next) {
+ async.each(plugins.loadedHooks['filter:router.page'] || [], function (hookObj, next) {
hookObj.method(req, res, next);
- }, function() {
+ }, function () {
// If it got here, then none of the subscribed hooks did anything, or there were no hooks
next();
});
};
-middleware.validateFiles = function(req, res, next) {
+middleware.validateFiles = function (req, res, next) {
if (!Array.isArray(req.files.files) || !req.files.files.length) {
return next(new Error(['[[error:invalid-files]]']));
}
@@ -89,12 +89,12 @@ middleware.validateFiles = function(req, res, next) {
next();
};
-middleware.prepareAPI = function(req, res, next) {
+middleware.prepareAPI = function (req, res, next) {
res.locals.isAPI = true;
next();
};
-middleware.routeTouchIcon = function(req, res) {
+middleware.routeTouchIcon = function (req, res) {
if (meta.config['brand:touchIcon'] && validator.isURL(meta.config['brand:touchIcon'])) {
return res.redirect(meta.config['brand:touchIcon']);
} else {
@@ -104,7 +104,7 @@ middleware.routeTouchIcon = function(req, res) {
}
};
-middleware.privateTagListing = function(req, res, next) {
+middleware.privateTagListing = function (req, res, next) {
if (!req.user && parseInt(meta.config.privateTagListing, 10) === 1) {
controllers.helpers.notAllowed(req, res);
} else {
@@ -112,11 +112,11 @@ middleware.privateTagListing = function(req, res, next) {
}
};
-middleware.exposeGroupName = function(req, res, next) {
+middleware.exposeGroupName = function (req, res, next) {
expose('groupName', groups.getGroupNameByGroupSlug, 'slug', req, res, next);
};
-middleware.exposeUid = function(req, res, next) {
+middleware.exposeUid = function (req, res, next) {
expose('uid', user.getUidByUserslug, 'userslug', req, res, next);
};
@@ -124,7 +124,7 @@ function expose(exposedField, method, field, req, res, next) {
if (!req.params.hasOwnProperty(field)) {
return next();
}
- method(req.params[field], function(err, id) {
+ method(req.params[field], function (err, id) {
if (err) {
return next(err);
}
@@ -134,7 +134,7 @@ function expose(exposedField, method, field, req, res, next) {
});
}
-middleware.privateUploads = function(req, res, next) {
+middleware.privateUploads = function (req, res, next) {
if (req.user || parseInt(meta.config.privateUploads, 10) !== 1) {
return next();
}
@@ -144,7 +144,7 @@ middleware.privateUploads = function(req, res, next) {
next();
};
-middleware.busyCheck = function(req, res, next) {
+middleware.busyCheck = function (req, res, next) {
if (global.env === 'production' && (!meta.config.hasOwnProperty('eventLoopCheckEnabled') || parseInt(meta.config.eventLoopCheckEnabled, 10) === 1) && toobusy()) {
analytics.increment('errors:503');
res.status(503).type('text/html').sendFile(path.join(__dirname, '../../public/503.html'));
@@ -153,18 +153,18 @@ middleware.busyCheck = function(req, res, next) {
}
};
-middleware.applyBlacklist = function(req, res, next) {
- meta.blacklist.test(req.ip, function(err) {
+middleware.applyBlacklist = function (req, res, next) {
+ meta.blacklist.test(req.ip, function (err) {
next(err);
});
};
-middleware.processLanguages = function(req, res, next) {
+middleware.processLanguages = function (req, res, next) {
var code = req.params.code;
var key = req.path.match(/[\w]+\.json/);
if (code && key) {
- languages.get(code, key[0], function(err, language) {
+ languages.get(code, key[0], function (err, language) {
if (err) {
return next(err);
}
@@ -176,7 +176,7 @@ middleware.processLanguages = function(req, res, next) {
}
};
-middleware.processTimeagoLocales = function(req, res, next) {
+middleware.processTimeagoLocales = function (req, res, next) {
var fallback = req.path.indexOf('-short') === -1 ? 'jquery.timeago.en.js' : 'jquery.timeago.en-short.js',
localPath = path.join(__dirname, '../../public/vendor/jquery/timeago/locales', req.path),
exists;
diff --git a/src/middleware/maintenance.js b/src/middleware/maintenance.js
index 2c8d30305b..3abe15f6f8 100644
--- a/src/middleware/maintenance.js
+++ b/src/middleware/maintenance.js
@@ -4,9 +4,9 @@ var nconf = require('nconf');
var meta = require('../meta');
var user = require('../user');
-module.exports = function(middleware) {
+module.exports = function (middleware) {
- middleware.maintenanceMode = function(req, res, next) {
+ middleware.maintenanceMode = function (req, res, next) {
if (parseInt(meta.config.maintenanceMode, 10) !== 1) {
return next();
}
@@ -27,14 +27,14 @@ module.exports = function(middleware) {
'^/language/.+',
'^/uploads/system/site-logo.png'
];
- var render = function() {
+ var render = function () {
res.status(503);
var data = {
site_title: meta.config.title || 'NodeBB',
message: meta.config.maintenanceModeMessage
};
if (!isApiRoute.test(url)) {
- middleware.buildHeader(req, res, function() {
+ middleware.buildHeader(req, res, function () {
res.render('503', data);
});
} else {
@@ -42,7 +42,7 @@ module.exports = function(middleware) {
}
};
- var isAllowed = function(url) {
+ var isAllowed = function (url) {
for(var x = 0,numAllowed = allowedRoutes.length,route;x < numAllowed;x++) {
route = new RegExp(allowedRoutes[x]);
if (route.test(url)) {
@@ -62,7 +62,7 @@ module.exports = function(middleware) {
return render();
}
- user.isAdministrator(req.user.uid, function(err, isAdmin) {
+ user.isAdministrator(req.user.uid, function (err, isAdmin) {
if (err) {
return next(err);
}
diff --git a/src/middleware/ratelimit.js b/src/middleware/ratelimit.js
index 7c244a6cd9..818fe99c12 100644
--- a/src/middleware/ratelimit.js
+++ b/src/middleware/ratelimit.js
@@ -8,7 +8,7 @@ var ratelimit = {};
var allowedCalls = 100;
var timeframe = 10000;
-ratelimit.isFlooding = function(socket) {
+ratelimit.isFlooding = function (socket) {
socket.callsPerSecond = socket.callsPerSecond || 0;
socket.elapsedTime = socket.elapsedTime || 0;
socket.lastCallTime = socket.lastCallTime || Date.now();
diff --git a/src/middleware/render.js b/src/middleware/render.js
index 545aff6e4b..f9124971c0 100644
--- a/src/middleware/render.js
+++ b/src/middleware/render.js
@@ -7,15 +7,15 @@ var validator = require('validator');
var plugins = require('../plugins');
var translator = require('../../public/src/modules/translator');
-module.exports = function(middleware) {
+module.exports = function (middleware) {
- middleware.processRender = function(req, res, next) {
+ middleware.processRender = function (req, res, next) {
// res.render post-processing, modified from here: https://gist.github.com/mrlannigan/5051687
var render = res.render;
- res.render = function(template, options, fn) {
+ res.render = function (template, options, fn) {
var self = this;
var req = this.req;
- var defaultFn = function(err, str) {
+ var defaultFn = function (err, str) {
if (err) {
return next(err);
}
@@ -33,10 +33,10 @@ module.exports = function(middleware) {
var ajaxifyData;
async.waterfall([
- function(next) {
+ function (next) {
plugins.fireHook('filter:' + template + '.build', {req: req, res: res, templateData: options}, next);
},
- function(data, next) {
+ function (data, next) {
options = data.templateData;
options.loggedIn = !!req.uid;
@@ -60,18 +60,18 @@ module.exports = function(middleware) {
ajaxifyData = JSON.stringify(options).replace(/<\//g, '<\\/');
async.parallel({
- header: function(next) {
+ header: function (next) {
renderHeaderFooter('renderHeader', req, res, options, next);
},
- content: function(next) {
+ content: function (next) {
render.call(self, template, options, next);
},
- footer: function(next) {
+ footer: function (next) {
renderHeaderFooter('renderFooter', req, res, options, next);
}
}, next);
},
- function(results, next) {
+ function (results, next) {
var str = results.header +
(res.locals.postHeader || '') +
results.content +
@@ -80,7 +80,7 @@ module.exports = function(middleware) {
translate(str, req, res, next);
},
- function(translated, next) {
+ function (translated, next) {
next(null, translated + '');
}
], fn);
@@ -102,7 +102,7 @@ module.exports = function(middleware) {
function translate(str, req, res, next) {
var language = res.locals.config ? res.locals.config.userLang || 'en_GB' : 'en_GB';
language = req.query.lang ? validator.escape(String(req.query.lang)) : language;
- translator.translate(str, language, function(translated) {
+ translator.translate(str, language, function (translated) {
next(null, translator.unescape(translated));
});
}
@@ -110,7 +110,7 @@ module.exports = function(middleware) {
function buildBodyClass(req) {
var clean = req.path.replace(/^\/api/, '').replace(/^\/|\/$/g, '');
var parts = clean.split('/').slice(0, 3);
- parts.forEach(function(p, index) {
+ parts.forEach(function (p, index) {
parts[index] = index ? parts[0] + '-' + p : 'page-' + (p || 'home');
});
return parts.join(' ');
diff --git a/src/middleware/user.js b/src/middleware/user.js
index b70f7639d7..a9dc90eb94 100644
--- a/src/middleware/user.js
+++ b/src/middleware/user.js
@@ -9,9 +9,9 @@ var controllers = {
helpers: require('../controllers/helpers')
};
-module.exports = function(middleware) {
+module.exports = function (middleware) {
- middleware.checkGlobalPrivacySettings = function(req, res, next) {
+ middleware.checkGlobalPrivacySettings = function (req, res, next) {
if (!req.user && !!parseInt(meta.config.privateUserInfo, 10)) {
return controllers.helpers.notAllowed(req, res);
}
@@ -19,7 +19,7 @@ module.exports = function(middleware) {
next();
};
- middleware.checkAccountPermissions = function(req, res, next) {
+ middleware.checkAccountPermissions = function (req, res, next) {
// This middleware ensures that only the requested user and admins can pass
async.waterfall([
function (next) {
@@ -43,7 +43,7 @@ module.exports = function(middleware) {
});
};
- middleware.redirectToAccountIfLoggedIn = function(req, res, next) {
+ middleware.redirectToAccountIfLoggedIn = function (req, res, next) {
if (req.session.forceLogin) {
return next();
}
@@ -59,24 +59,24 @@ module.exports = function(middleware) {
});
};
- middleware.redirectUidToUserslug = function(req, res, next) {
+ middleware.redirectUidToUserslug = function (req, res, next) {
var uid = parseInt(req.params.uid, 10);
if (!uid) {
return next();
}
- user.getUserField(uid, 'userslug', function(err, userslug) {
+ user.getUserField(uid, 'userslug', function (err, userslug) {
if (err || !userslug) {
return next(err);
}
var path = req.path.replace(/^\/api/, '')
.replace('uid', 'user')
- .replace(uid, function() { return userslug; });
+ .replace(uid, function () { return userslug; });
controllers.helpers.redirect(res, path);
});
};
- middleware.isAdmin = function(req, res, next) {
+ middleware.isAdmin = function (req, res, next) {
if (!req.uid) {
return controllers.helpers.notAllowed(req, res);
}
@@ -87,7 +87,7 @@ module.exports = function(middleware) {
}
if (isAdmin) {
- user.hasPassword(req.uid, function(err, hasPassword) {
+ user.hasPassword(req.uid, function (err, hasPassword) {
if (err) {
return next(err);
}
@@ -121,13 +121,13 @@ module.exports = function(middleware) {
return controllers.helpers.notAllowed(req, res);
}
- middleware.buildHeader(req, res, function() {
+ middleware.buildHeader(req, res, function () {
controllers.helpers.notAllowed(req, res);
});
});
};
- middleware.requireUser = function(req, res, next) {
+ middleware.requireUser = function (req, res, next) {
if (req.user) {
return next();
}
@@ -135,7 +135,7 @@ module.exports = function(middleware) {
res.status(403).render('403', {title: '[[global:403.title]]'});
};
- middleware.registrationComplete = function(req, res, next) {
+ 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();
diff --git a/src/navigation/admin.js b/src/navigation/admin.js
index 7db567b90b..a7caee97e0 100644
--- a/src/navigation/admin.js
+++ b/src/navigation/admin.js
@@ -9,9 +9,9 @@ var admin = {},
admin.cache = null;
-admin.save = function(data, callback) {
+admin.save = function (data, callback) {
var order = Object.keys(data),
- items = data.map(function(item, idx) {
+ items = data.map(function (item, idx) {
var data = {};
for (var i in item) {
@@ -26,29 +26,29 @@ admin.save = function(data, callback) {
admin.cache = null;
async.waterfall([
- function(next) {
+ function (next) {
db.delete('navigation:enabled', next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('navigation:enabled', order, items, next);
}
], callback);
};
-admin.getAdmin = function(callback) {
+admin.getAdmin = function (callback) {
async.parallel({
enabled: admin.get,
available: getAvailable
}, callback);
};
-admin.get = function(callback) {
- db.getSortedSetRange('navigation:enabled', 0, -1, function(err, data) {
+admin.get = function (callback) {
+ db.getSortedSetRange('navigation:enabled', 0, -1, function (err, data) {
if (err) {
return callback(err);
}
- data = data.map(function(item, idx) {
+ data = data.map(function (item, idx) {
return JSON.parse(item)[idx];
});
@@ -57,7 +57,7 @@ admin.get = function(callback) {
};
function getAvailable(callback) {
- var core = require('../../install/data/navigation.json').map(function(item) {
+ var core = require('../../install/data/navigation.json').map(function (item) {
item.core = true;
return item;
});
diff --git a/src/navigation/index.js b/src/navigation/index.js
index ad4627fd5b..5563c44c4b 100644
--- a/src/navigation/index.js
+++ b/src/navigation/index.js
@@ -6,19 +6,19 @@ var translator = require('../../public/src/modules/translator');
var navigation = {};
-navigation.get = function(callback) {
+navigation.get = function (callback) {
if (admin.cache) {
return callback(null, admin.cache);
}
- admin.get(function(err, data) {
+ admin.get(function (err, data) {
if (err) {
return callback(err);
}
- data = data.filter(function(item) {
+ data = data.filter(function (item) {
return item && item.enabled;
- }).map(function(item) {
+ }).map(function (item) {
if (!item.route.startsWith('http')) {
item.route = nconf.get('relative_path') + item.route;
}
diff --git a/src/notifications.js b/src/notifications.js
index ff3ee5385c..c70c0cbb0a 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -15,25 +15,25 @@ var batch = require('./batch');
var plugins = require('./plugins');
var utils = require('../public/src/utils');
-(function(Notifications) {
+(function (Notifications) {
- Notifications.init = function() {
+ Notifications.init = function () {
winston.verbose('[notifications.init] Registering jobs.');
new cron('*/30 * * * *', Notifications.prune, null, true);
};
- Notifications.get = function(nid, callback) {
- Notifications.getMultiple([nid], function(err, notifications) {
+ Notifications.get = function (nid, callback) {
+ Notifications.getMultiple([nid], function (err, notifications) {
callback(err, Array.isArray(notifications) && notifications.length ? notifications[0] : null);
});
};
- Notifications.getMultiple = function(nids, callback) {
- var keys = nids.map(function(nid) {
+ Notifications.getMultiple = function (nids, callback) {
+ var keys = nids.map(function (nid) {
return 'notifications:' + nid;
});
- db.getObjects(keys, function(err, notifications) {
+ db.getObjects(keys, function (err, notifications) {
if (err) {
return callback(err);
}
@@ -43,15 +43,15 @@ var utils = require('../public/src/utils');
return callback(null, []);
}
- var userKeys = notifications.map(function(notification) {
+ var userKeys = notifications.map(function (notification) {
return notification.from;
});
- User.getUsersFields(userKeys, ['username', 'userslug', 'picture'], function(err, usersData) {
+ User.getUsersFields(userKeys, ['username', 'userslug', 'picture'], function (err, usersData) {
if (err) {
return callback(err);
}
- notifications.forEach(function(notification, index) {
+ notifications.forEach(function (notification, index) {
notification.datetimeISO = utils.toISOString(notification.datetime);
if (notification.bodyLong) {
@@ -74,14 +74,14 @@ var utils = require('../public/src/utils');
});
};
- Notifications.filterExists = function(nids, callback) {
+ Notifications.filterExists = function (nids, callback) {
// Removes nids that have been pruned
- db.isSortedSetMembers('notifications', nids, function(err, exists) {
+ db.isSortedSetMembers('notifications', nids, function (err, exists) {
if (err) {
return callback(err);
}
- nids = nids.filter(function(notifId, idx) {
+ nids = nids.filter(function (notifId, idx) {
return exists[idx];
});
@@ -89,42 +89,42 @@ var utils = require('../public/src/utils');
});
};
- Notifications.findRelated = function(mergeIds, set, callback) {
+ Notifications.findRelated = function (mergeIds, set, callback) {
// A related notification is one in a zset that has the same mergeId
var _nids;
async.waterfall([
async.apply(db.getSortedSetRevRange, set, 0, -1),
- function(nids, next) {
+ function (nids, next) {
_nids = nids;
- var keys = nids.map(function(nid) {
+ var keys = nids.map(function (nid) {
return 'notifications:' + nid;
});
db.getObjectsFields(keys, ['mergeId'], next);
},
- ], function(err, sets) {
+ ], function (err, sets) {
if (err) {
return callback(err);
}
- sets = sets.map(function(set) {
+ sets = sets.map(function (set) {
return set.mergeId;
});
- callback(null, _nids.filter(function(nid, idx) {
+ callback(null, _nids.filter(function (nid, idx) {
return mergeIds.indexOf(sets[idx]) !== -1;
}));
});
};
- Notifications.create = function(data, callback) {
+ Notifications.create = function (data, callback) {
if (!data.nid) {
return callback(new Error('no-notification-id'));
}
data.importance = data.importance || 5;
- db.getObject('notifications:' + data.nid, function(err, oldNotification) {
+ db.getObject('notifications:' + data.nid, function (err, oldNotification) {
if (err) {
return callback(err);
}
@@ -138,20 +138,20 @@ var utils = require('../public/src/utils');
var now = Date.now();
data.datetime = now;
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetAdd('notifications', now, data.nid, next);
},
- function(next) {
+ function (next) {
db.setObject('notifications:' + data.nid, data, next);
}
- ], function(err) {
+ ], function (err) {
callback(err, data);
});
});
};
- Notifications.push = function(notification, uids, callback) {
- callback = callback || function() {};
+ Notifications.push = function (notification, uids, callback) {
+ callback = callback || function () {};
if (!notification || !notification.nid) {
return callback();
@@ -161,7 +161,7 @@ var utils = require('../public/src/utils');
uids = [uids];
}
- uids = uids.filter(function(uid, index, array) {
+ uids = uids.filter(function (uid, index, array) {
return parseInt(uid, 10) && array.indexOf(uid) === index;
});
@@ -169,10 +169,10 @@ var utils = require('../public/src/utils');
return callback();
}
- setTimeout(function() {
- batch.processArray(uids, function(uids, next) {
+ setTimeout(function () {
+ batch.processArray(uids, function (uids, next) {
pushToUids(uids, notification, next);
- }, {interval: 1000}, function(err) {
+ }, {interval: 1000}, function (err) {
if (err) {
winston.error(err.stack);
}
@@ -195,7 +195,7 @@ var utils = require('../public/src/utils');
uids = data.uids;
notification = data.notification;
- uids.forEach(function(uid) {
+ uids.forEach(function (uid) {
unreadKeys.push('uid:' + uid + ':notifications:unread');
readKeys.push('uid:' + uid + ':notifications:read');
});
@@ -214,7 +214,7 @@ var utils = require('../public/src/utils');
function (next) {
var websockets = require('./socket.io');
if (websockets.server) {
- uids.forEach(function(uid) {
+ uids.forEach(function (uid) {
websockets.in('uid_' + uid).emit('event:new_notification', notification);
});
}
@@ -225,9 +225,9 @@ var utils = require('../public/src/utils');
], callback);
}
- Notifications.pushGroup = function(notification, groupName, callback) {
- callback = callback || function() {};
- groups.getMembers(groupName, 0, -1, function(err, members) {
+ Notifications.pushGroup = function (notification, groupName, callback) {
+ callback = callback || function () {};
+ groups.getMembers(groupName, 0, -1, function (err, members) {
if (err || !Array.isArray(members) || !members.length) {
return callback(err);
}
@@ -236,13 +236,13 @@ var utils = require('../public/src/utils');
});
};
- Notifications.rescind = function(nid, callback) {
- callback = callback || function() {};
+ Notifications.rescind = function (nid, callback) {
+ callback = callback || function () {};
async.parallel([
async.apply(db.sortedSetRemove, 'notifications', nid),
async.apply(db.delete, 'notifications:' + nid)
- ], function(err) {
+ ], function (err) {
if (err) {
winston.error('Encountered error rescinding notification (' + nid + '): ' + err.message);
} else {
@@ -253,21 +253,21 @@ var utils = require('../public/src/utils');
});
};
- Notifications.markRead = function(nid, uid, callback) {
- callback = callback || function() {};
+ Notifications.markRead = function (nid, uid, callback) {
+ callback = callback || function () {};
if (!parseInt(uid, 10) || !nid) {
return callback();
}
Notifications.markReadMultiple([nid], uid, callback);
};
- Notifications.markUnread = function(nid, uid, callback) {
- callback = callback || function() {};
+ Notifications.markUnread = function (nid, uid, callback) {
+ callback = callback || function () {};
if (!parseInt(uid, 10) || !nid) {
return callback();
}
- db.getObject('notifications:' + nid, function(err, notification) {
+ db.getObject('notifications:' + nid, function (err, notification) {
if (err || !notification) {
return callback(err || new Error('[[error:no-notification]]'));
}
@@ -280,24 +280,24 @@ var utils = require('../public/src/utils');
});
};
- Notifications.markReadMultiple = function(nids, uid, callback) {
- callback = callback || function() {};
+ Notifications.markReadMultiple = function (nids, uid, callback) {
+ callback = callback || function () {};
nids = nids.filter(Boolean);
if (!Array.isArray(nids) || !nids.length) {
return callback();
}
- var notificationKeys = nids.map(function(nid) {
+ var notificationKeys = nids.map(function (nid) {
return 'notifications:' + nid;
});
async.waterfall([
async.apply(db.getObjectsFields, notificationKeys, ['mergeId']),
- function(mergeIds, next) {
+ function (mergeIds, next) {
// Isolate mergeIds and find related notifications
- mergeIds = mergeIds.map(function(set) {
+ mergeIds = mergeIds.map(function (set) {
return set.mergeId;
- }).reduce(function(memo, mergeId, idx, arr) {
+ }).reduce(function (memo, mergeId, idx, arr) {
if (mergeId && idx === arr.indexOf(mergeId)) {
memo.push(mergeId);
}
@@ -306,45 +306,45 @@ var utils = require('../public/src/utils');
Notifications.findRelated(mergeIds, 'uid:' + uid + ':notifications:unread', next);
},
- function(relatedNids, next) {
- notificationKeys = _.union(nids, relatedNids).map(function(nid) {
+ function (relatedNids, next) {
+ notificationKeys = _.union(nids, relatedNids).map(function (nid) {
return 'notifications:' + nid;
});
db.getObjectsFields(notificationKeys, ['nid', 'datetime'], next);
}
- ], function(err, notificationData) {
+ ], function (err, notificationData) {
if (err) {
return callback(err);
}
// Filter out notifications that didn't exist
- notificationData = notificationData.filter(function(notification) {
+ notificationData = notificationData.filter(function (notification) {
return notification && notification.nid;
});
// Extract nid
- nids = notificationData.map(function(notification) {
+ nids = notificationData.map(function (notification) {
return notification.nid;
});
- var datetimes = notificationData.map(function(notification) {
+ var datetimes = notificationData.map(function (notification) {
return (notification && notification.datetime) || Date.now();
});
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetRemove('uid:' + uid + ':notifications:unread', nids, next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('uid:' + uid + ':notifications:read', datetimes, nids, next);
}
], callback);
});
};
- Notifications.markAllRead = function(uid, callback) {
- db.getSortedSetRevRange('uid:' + uid + ':notifications:unread', 0, 99, function(err, nids) {
+ Notifications.markAllRead = function (uid, callback) {
+ db.getSortedSetRevRange('uid:' + uid + ':notifications:unread', 0, 99, function (err, nids) {
if (err) {
return callback(err);
}
@@ -357,13 +357,13 @@ var utils = require('../public/src/utils');
});
};
- Notifications.prune = function() {
+ Notifications.prune = function () {
var week = 604800000,
numPruned = 0;
var cutoffTime = Date.now() - week;
- db.getSortedSetRangeByScore('notifications', 0, 500, '-inf', cutoffTime, function(err, nids) {
+ db.getSortedSetRangeByScore('notifications', 0, 500, '-inf', cutoffTime, function (err, nids) {
if (err) {
return winston.error(err.message);
}
@@ -372,20 +372,20 @@ var utils = require('../public/src/utils');
return;
}
- var keys = nids.map(function(nid) {
+ var keys = nids.map(function (nid) {
return 'notifications:' + nid;
});
numPruned = nids.length;
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetRemove('notifications', nids, next);
},
- function(next) {
+ function (next) {
db.deleteAll(keys, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return winston.error('Encountered error pruning notifications: ' + err.message);
}
@@ -393,7 +393,7 @@ var utils = require('../public/src/utils');
});
};
- Notifications.merge = function(notifications, callback) {
+ Notifications.merge = function (notifications, callback) {
// When passed a set of notification objects, merge any that can be merged
var mergeIds = [
'notifications:upvoted_your_post_in',
@@ -404,8 +404,8 @@ var utils = require('../public/src/utils');
],
isolated, differentiators, differentiator, modifyIndex, set;
- notifications = mergeIds.reduce(function(notifications, mergeId) {
- isolated = notifications.filter(function(notifObj) {
+ notifications = mergeIds.reduce(function (notifications, mergeId) {
+ isolated = notifications.filter(function (notifObj) {
if (!notifObj || !notifObj.hasOwnProperty('mergeId')) {
return false;
}
@@ -418,7 +418,7 @@ var utils = require('../public/src/utils');
}
// Each isolated mergeId may have multiple differentiators, so process each separately
- differentiators = isolated.reduce(function(cur, next) {
+ differentiators = isolated.reduce(function (cur, next) {
differentiator = next.mergeId.split('|')[1] || 0;
if (cur.indexOf(differentiator) === -1) {
cur.push(differentiator);
@@ -427,11 +427,11 @@ var utils = require('../public/src/utils');
return cur;
}, []);
- differentiators.forEach(function(differentiator) {
+ differentiators.forEach(function (differentiator) {
if (differentiator === 0 && differentiators.length === 1) {
set = isolated;
} else {
- set = isolated.filter(function(notifObj) {
+ set = isolated.filter(function (notifObj) {
return notifObj.mergeId === (mergeId + '|' + differentiator);
});
}
@@ -447,9 +447,9 @@ var utils = require('../public/src/utils');
case 'notifications:user_started_following_you':
case 'notifications:user_posted_to':
case 'notifications:user_flagged_post_in':
- var usernames = set.map(function(notifObj) {
+ var usernames = set.map(function (notifObj) {
return notifObj && notifObj.user && notifObj.user.username;
- }).filter(function(username, idx, array) {
+ }).filter(function (username, idx, array) {
return array.indexOf(username) === idx;
});
var numUsers = usernames.length;
@@ -473,7 +473,7 @@ var utils = require('../public/src/utils');
}
// Filter out duplicates
- notifications = notifications.filter(function(notifObj, idx) {
+ notifications = notifications.filter(function (notifObj, idx) {
if (!notifObj || !notifObj.mergeId) {
return true;
}
@@ -487,7 +487,7 @@ var utils = require('../public/src/utils');
plugins.fireHook('filter:notifications.merge', {
notifications: notifications
- }, function(err, data) {
+ }, function (err, data) {
callback(err, data.notifications);
});
};
diff --git a/src/pagination.js b/src/pagination.js
index 4a28894936..347c71ae5c 100644
--- a/src/pagination.js
+++ b/src/pagination.js
@@ -4,7 +4,7 @@ var qs = require('querystring');
var pagination = {};
-pagination.create = function(currentPage, pageCount, queryObj) {
+pagination.create = function (currentPage, pageCount, queryObj) {
if (pageCount <= 1) {
return {
prev: {page: 1, active: currentPage > 1},
@@ -27,9 +27,9 @@ pagination.create = function(currentPage, pageCount, queryObj) {
pagesToShow.push(startPage + i);
}
- pagesToShow = pagesToShow.filter(function(page, index, array) {
+ pagesToShow = pagesToShow.filter(function (page, index, array) {
return page > 0 && page <= pageCount && array.indexOf(page) === index;
- }).sort(function(a, b) {
+ }).sort(function (a, b) {
return a - b;
});
@@ -37,7 +37,7 @@ pagination.create = function(currentPage, pageCount, queryObj) {
delete queryObj._;
- var pages = pagesToShow.map(function(page) {
+ var pages = pagesToShow.map(function (page) {
queryObj.page = page;
return {page: page, active: page === currentPage, qs: qs.stringify(queryObj)};
});
diff --git a/src/password.js b/src/password.js
index 8b9fbb33a6..2744cbefba 100644
--- a/src/password.js
+++ b/src/password.js
@@ -1,13 +1,13 @@
'use strict';
-(function(module) {
+(function (module) {
var fork = require('child_process').fork;
- module.hash = function(rounds, password, callback) {
+ module.hash = function (rounds, password, callback) {
forkChild({type: 'hash', rounds: rounds, password: password}, callback);
};
- module.compare = function(password, hash, callback) {
+ module.compare = function (password, hash, callback) {
forkChild({type: 'compare', password: password, hash: hash}, callback);
};
@@ -18,7 +18,7 @@
}
var child = fork('./bcrypt', [], forkProcessParams);
- child.on('message', function(msg) {
+ child.on('message', function (msg) {
if (msg.err) {
return callback(new Error(msg.err));
}
diff --git a/src/plugins.js b/src/plugins.js
index 74cb39d034..1274b829ef 100644
--- a/src/plugins.js
+++ b/src/plugins.js
@@ -17,7 +17,7 @@ var file = require('./file');
var app;
var middleware;
-(function(Plugins) {
+(function (Plugins) {
require('./plugins/install')(Plugins);
require('./plugins/load')(Plugins);
require('./plugins/hooks')(Plugins);
@@ -36,13 +36,13 @@ var middleware;
Plugins.initialized = false;
- Plugins.requireLibrary = function(pluginID, libraryPath) {
+ Plugins.requireLibrary = function (pluginID, libraryPath) {
Plugins.libraries[pluginID] = require(libraryPath);
Plugins.libraryPaths.push(libraryPath);
};
- Plugins.init = function(nbbApp, nbbMiddleware, callback) {
- callback = callback || function() {};
+ Plugins.init = function (nbbApp, nbbMiddleware, callback) {
+ callback = callback || function () {};
if (Plugins.initialized) {
return callback();
}
@@ -55,7 +55,7 @@ var middleware;
winston.verbose('[plugins] Initializing plugins system');
}
- Plugins.reload(function(err) {
+ Plugins.reload(function (err) {
if (err) {
winston.error('[plugins] NodeBB encountered a problem while loading plugins', err.message);
return callback(err);
@@ -71,7 +71,7 @@ var middleware;
});
};
- Plugins.reload = function(callback) {
+ Plugins.reload = function (callback) {
// Resetting all local plugin data
Plugins.libraries = {};
Plugins.loadedHooks = {};
@@ -89,39 +89,39 @@ var middleware;
// });
async.waterfall([
- function(next) {
+ function (next) {
// Build language code list
- fs.readdir(path.join(__dirname, '../public/language'), function(err, directories) {
+ fs.readdir(path.join(__dirname, '../public/language'), function (err, directories) {
if (err) {
return next(err);
}
- Plugins.languageCodes = directories.filter(function(code) {
+ Plugins.languageCodes = directories.filter(function (code) {
return code !== 'TODO';
});
next();
});
},
- function(next) {
+ function (next) {
db.getSortedSetRange('plugins:active', 0, -1, next);
},
- function(plugins, next) {
+ function (plugins, next) {
if (!Array.isArray(plugins)) {
return next();
}
- plugins = plugins.filter(function(plugin){
+ plugins = plugins.filter(function (plugin){
return plugin && typeof plugin === 'string';
- }).map(function(plugin){
+ }).map(function (plugin){
return path.join(__dirname, '../node_modules/', plugin);
});
- async.filter(plugins, file.exists, function(plugins) {
+ async.filter(plugins, file.exists, function (plugins) {
async.eachSeries(plugins, Plugins.loadPlugin, next);
});
},
- function(next) {
+ function (next) {
// If some plugins are incompatible, throw the warning here
if (Plugins.versionWarning.length && nconf.get('isPrimary') === 'true') {
process.stdout.write('\n');
@@ -132,9 +132,9 @@ var middleware;
process.stdout.write('\n');
}
- Object.keys(Plugins.loadedHooks).forEach(function(hook) {
+ Object.keys(Plugins.loadedHooks).forEach(function (hook) {
var hooks = Plugins.loadedHooks[hook];
- hooks = hooks.sort(function(a, b) {
+ hooks = hooks.sort(function (a, b) {
return a.priority - b.priority;
});
});
@@ -144,17 +144,17 @@ var middleware;
], callback);
};
- Plugins.reloadRoutes = function(callback) {
- callback = callback || function() {};
+ Plugins.reloadRoutes = function (callback) {
+ callback = callback || function () {};
var router = express.Router();
router.hotswapId = 'plugins';
- router.render = function() {
+ router.render = function () {
app.render.apply(app, arguments);
};
var controllers = require('./controllers');
- Plugins.fireHook('static:app.load', {app: app, router: router, middleware: middleware, controllers: controllers}, function(err) {
+ Plugins.fireHook('static:app.load', {app: app, router: router, middleware: middleware, controllers: controllers}, function (err) {
if (err) {
return winston.error('[plugins] Encountered error while executing post-router plugins hooks: ' + err.message);
}
@@ -165,38 +165,38 @@ var middleware;
});
};
- Plugins.getTemplates = function(callback) {
+ Plugins.getTemplates = function (callback) {
var templates = {},
tplName;
async.waterfall([
async.apply(db.getSortedSetRange, 'plugins:active', 0, -1),
- function(plugins, next) {
+ function (plugins, next) {
var pluginBasePath = path.join(__dirname, '../node_modules');
- var paths = plugins.map(function(plugin) {
+ var paths = plugins.map(function (plugin) {
return path.join(pluginBasePath, plugin);
});
// Filter out plugins with invalid paths
- async.filter(paths, file.exists, function(paths) {
+ async.filter(paths, file.exists, function (paths) {
next(null, paths);
});
},
- function(paths, next) {
+ function (paths, next) {
async.map(paths, Plugins.loadPluginInfo, next);
}
- ], function(err, plugins) {
+ ], function (err, plugins) {
if (err) {
return callback(err);
}
- async.eachSeries(plugins, function(plugin, next) {
+ async.eachSeries(plugins, function (plugin, next) {
if (plugin.templates || plugin.id.startsWith('nodebb-theme-')) {
winston.verbose('[plugins] Loading templates (' + plugin.id + ')');
var templatesPath = path.join(__dirname, '../node_modules', plugin.id, plugin.templates || 'templates');
- utils.walk(templatesPath, function(err, pluginTemplates) {
+ utils.walk(templatesPath, function (err, pluginTemplates) {
if (pluginTemplates) {
- pluginTemplates.forEach(function(pluginTemplate) {
+ pluginTemplates.forEach(function (pluginTemplate) {
if (pluginTemplate.endsWith('.tpl')) {
tplName = "/" + pluginTemplate.replace(templatesPath, '').substring(1);
@@ -222,24 +222,24 @@ var middleware;
} else {
next(false);
}
- }, function(err) {
+ }, function (err) {
callback(err, templates);
});
});
};
- Plugins.get = function(id, callback) {
+ Plugins.get = function (id, callback) {
var url = (nconf.get('registry') || 'https://packages.nodebb.org') + '/api/v1/plugins/' + id;
require('request')(url, {
json: true
- }, function(err, res, body) {
+ }, function (err, res, body) {
if (res.statusCode === 404 || !body.payload) {
return callback(err, {});
}
- Plugins.normalise([body.payload], function(err, normalised) {
- normalised = normalised.filter(function(plugin) {
+ Plugins.normalise([body.payload], function (err, normalised) {
+ normalised = normalised.filter(function (plugin) {
return plugin.id === id;
});
return callback(err, !err ? normalised[0] : undefined);
@@ -247,7 +247,7 @@ var middleware;
});
};
- Plugins.list = function(matching, callback) {
+ Plugins.list = function (matching, callback) {
if (arguments.length === 1 && typeof matching === 'function') {
callback = matching;
matching = true;
@@ -257,7 +257,7 @@ var middleware;
require('request')(url, {
json: true
- }, function(err, res, body) {
+ }, function (err, res, body) {
if (err) {
winston.error('Error parsing plugins : ' + err.message);
return callback(err);
@@ -267,7 +267,7 @@ var middleware;
});
};
- Plugins.normalise = function(apiReturn, callback) {
+ Plugins.normalise = function (apiReturn, callback) {
var pluginMap = {};
var dependencies = require.main.require('./package.json').dependencies;
apiReturn = apiReturn || [];
@@ -280,16 +280,16 @@ var middleware;
pluginMap[apiReturn[i].name] = apiReturn[i];
}
- Plugins.showInstalled(function(err, installedPlugins) {
+ Plugins.showInstalled(function (err, installedPlugins) {
if (err) {
return callback(err);
}
- installedPlugins = installedPlugins.filter(function(plugin) {
+ installedPlugins = installedPlugins.filter(function (plugin) {
return plugin && !plugin.system;
});
- async.each(installedPlugins, function(plugin, next) {
+ async.each(installedPlugins, function (plugin, next) {
// If it errored out because a package.json or plugin.json couldn't be read, no need to do this stuff
if (plugin.error) {
pluginMap[plugin.id] = pluginMap[plugin.id] || {};
@@ -317,7 +317,7 @@ var middleware;
}
pluginMap[plugin.id].outdated = semver.gt(pluginMap[plugin.id].latest, pluginMap[plugin.id].version);
next();
- }, function(err) {
+ }, function (err) {
if (err) {
return callback(err);
}
@@ -330,7 +330,7 @@ var middleware;
}
}
- pluginArray.sort(function(a, b) {
+ pluginArray.sort(function (a, b) {
if (a.name > b.name ) {
return 1;
} else if (a.name < b.name ){
@@ -345,41 +345,41 @@ var middleware;
});
};
- Plugins.showInstalled = function(callback) {
+ Plugins.showInstalled = function (callback) {
var npmPluginPath = path.join(__dirname, '../node_modules');
async.waterfall([
async.apply(fs.readdir, npmPluginPath),
- function(dirs, next) {
- dirs = dirs.filter(function(dir){
+ function (dirs, next) {
+ dirs = dirs.filter(function (dir){
return dir.startsWith('nodebb-plugin-') ||
dir.startsWith('nodebb-widget-') ||
dir.startsWith('nodebb-rewards-') ||
dir.startsWith('nodebb-theme-');
- }).map(function(dir){
+ }).map(function (dir){
return path.join(npmPluginPath, dir);
});
- async.filter(dirs, function(dir, callback){
- fs.stat(dir, function(err, stats){
+ async.filter(dirs, function (dir, callback){
+ fs.stat(dir, function (err, stats){
callback(!err && stats.isDirectory());
});
- }, function(plugins){
+ }, function (plugins){
next(null, plugins);
});
},
- function(files, next) {
+ function (files, next) {
var plugins = [];
- async.each(files, function(file, next) {
+ async.each(files, function (file, next) {
async.waterfall([
- function(next) {
+ function (next) {
Plugins.loadPluginInfo(file, next);
},
- function(pluginData, next) {
- Plugins.isActive(pluginData.name, function(err, active) {
+ function (pluginData, next) {
+ Plugins.isActive(pluginData.name, function (err, active) {
if (err) {
return next(new Error('no-active-state'));
}
@@ -392,7 +392,7 @@ var middleware;
next(null, pluginData);
});
}
- ], function(err, pluginData) {
+ ], function (err, pluginData) {
if (err) {
return next(); // Silently fail
}
@@ -400,7 +400,7 @@ var middleware;
plugins.push(pluginData);
next();
});
- }, function(err) {
+ }, function (err) {
next(err, plugins);
});
}
diff --git a/src/plugins/hooks.js b/src/plugins/hooks.js
index e7cf97b5fc..9e08acde78 100644
--- a/src/plugins/hooks.js
+++ b/src/plugins/hooks.js
@@ -3,7 +3,7 @@
var winston = require('winston'),
async = require('async');
-module.exports = function(Plugins) {
+module.exports = function (Plugins) {
Plugins.deprecatedHooks = {
'filter:user.custom_fields': null, // remove in v1.1.0
'filter:post.save': 'filter:post.create',
@@ -15,8 +15,8 @@ module.exports = function(Plugins) {
`data.method`*, the method called in that plugin
`data.priority`, the relative priority of the method when it is eventually called (default: 10)
*/
- Plugins.registerHook = function(id, data, callback) {
- callback = callback || function() {};
+ Plugins.registerHook = function (id, data, callback) {
+ callback = callback || function () {};
function register() {
Plugins.loadedHooks[data.hook] = Plugins.loadedHooks[data.hook] || [];
Plugins.loadedHooks[data.hook].push(data);
@@ -54,7 +54,7 @@ module.exports = function(Plugins) {
}
if (typeof data.method === 'string' && data.method.length > 0) {
- method = data.method.split('.').reduce(function(memo, prop) {
+ method = data.method.split('.').reduce(function (memo, prop) {
if (memo && memo[prop]) {
return memo[prop];
} else {
@@ -76,8 +76,8 @@ module.exports = function(Plugins) {
}
};
- Plugins.fireHook = function(hook, params, callback) {
- callback = typeof callback === 'function' ? callback : function() {};
+ Plugins.fireHook = function (hook, params, callback) {
+ callback = typeof callback === 'function' ? callback : function () {};
var hookList = Plugins.loadedHooks[hook];
var hookType = hook.split(':')[0];
@@ -103,7 +103,7 @@ module.exports = function(Plugins) {
return callback(null, params);
}
- async.reduce(hookList, params, function(params, hookObj, next) {
+ async.reduce(hookList, params, function (params, hookObj, next) {
if (typeof hookObj.method !== 'function') {
if (global.env === 'development') {
winston.warn('[plugins] Expected method for hook \'' + hook + '\' in plugin \'' + hookObj.id + '\' not found, skipping.');
@@ -113,7 +113,7 @@ module.exports = function(Plugins) {
hookObj.method(params, next);
- }, function(err, values) {
+ }, function (err, values) {
if (err) {
winston.error('[plugins] ' + hook + ', ' + err.message);
}
@@ -126,7 +126,7 @@ module.exports = function(Plugins) {
if (!Array.isArray(hookList) || !hookList.length) {
return callback();
}
- async.each(hookList, function(hookObj, next) {
+ async.each(hookList, function (hookObj, next) {
if (typeof hookObj.method !== 'function') {
if (global.env === 'development') {
@@ -144,18 +144,18 @@ module.exports = function(Plugins) {
if (!Array.isArray(hookList) || !hookList.length) {
return callback();
}
- async.each(hookList, function(hookObj, next) {
+ async.each(hookList, function (hookObj, next) {
if (typeof hookObj.method === 'function') {
var timedOut = false;
- var timeoutId = setTimeout(function() {
+ var timeoutId = setTimeout(function () {
winston.warn('[plugins] Callback timed out, hook \'' + hook + '\' in plugin \'' + hookObj.id + '\'');
timedOut = true;
next();
}, 5000);
try {
- hookObj.method(params, function() {
+ hookObj.method(params, function () {
clearTimeout(timeoutId);
if (!timedOut) {
next.apply(null, arguments);
@@ -173,7 +173,7 @@ module.exports = function(Plugins) {
}, callback);
}
- Plugins.hasListeners = function(hook) {
+ Plugins.hasListeners = function (hook) {
return !!(Plugins.loadedHooks[hook] && Plugins.loadedHooks[hook].length > 0);
};
};
diff --git a/src/plugins/install.js b/src/plugins/install.js
index 3e3ee42ff3..acde7a22e7 100644
--- a/src/plugins/install.js
+++ b/src/plugins/install.js
@@ -12,35 +12,35 @@ var winston = require('winston'),
pubsub = require('../pubsub');
-module.exports = function(Plugins) {
+module.exports = function (Plugins) {
if (nconf.get('isPrimary') === 'true') {
- pubsub.on('plugins:toggleInstall', function(data) {
+ pubsub.on('plugins:toggleInstall', function (data) {
if (data.hostname !== os.hostname()) {
toggleInstall(data.id, data.version);
}
});
- pubsub.on('plugins:upgrade', function(data) {
+ pubsub.on('plugins:upgrade', function (data) {
if (data.hostname !== os.hostname()) {
upgrade(data.id, data.version);
}
});
}
- Plugins.toggleActive = function(id, callback) {
- callback = callback || function() {};
+ Plugins.toggleActive = function (id, callback) {
+ callback = callback || function () {};
var isActive;
async.waterfall([
- function(next) {
+ function (next) {
Plugins.isActive(id, next);
},
- function(_isActive, next) {
+ function (_isActive, next) {
isActive = _isActive;
if (isActive) {
db.sortedSetRemove('plugins:active', id, next);
} else {
- db.sortedSetCard('plugins:active', function(err, count) {
+ db.sortedSetCard('plugins:active', function (err, count) {
if (err) {
return next(err);
}
@@ -48,12 +48,12 @@ module.exports = function(Plugins) {
});
}
},
- function(next) {
+ function (next) {
meta.reloadRequired = true;
Plugins.fireHook(isActive ? 'action:plugin.deactivate' : 'action:plugin.activate', id);
next();
}
- ], function(err) {
+ ], function (err) {
if (err) {
winston.warn('[plugins] Could not toggle active state on plugin \'' + id + '\'');
return callback(err);
@@ -62,40 +62,40 @@ module.exports = function(Plugins) {
});
};
- Plugins.toggleInstall = function(id, version, callback) {
+ Plugins.toggleInstall = function (id, version, callback) {
pubsub.publish('plugins:toggleInstall', {hostname: os.hostname(), id: id, version: version});
toggleInstall(id, version, callback);
};
function toggleInstall(id, version, callback) {
- Plugins.isInstalled(id, function(err, installed) {
+ Plugins.isInstalled(id, function (err, installed) {
if (err) {
return callback(err);
}
var type = installed ? 'uninstall' : 'install';
async.waterfall([
- function(next) {
+ function (next) {
Plugins.isActive(id, next);
},
- function(active, next) {
+ function (active, next) {
if (active) {
- Plugins.toggleActive(id, function(err, status) {
+ Plugins.toggleActive(id, function (err, status) {
next(err);
});
return;
}
next();
},
- function(next) {
+ function (next) {
var command = installed ? ('npm uninstall ' + id) : ('npm install ' + id + '@' + (version || 'latest'));
runNpmCommand(command, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
- Plugins.get(id, function(err, pluginData) {
+ Plugins.get(id, function (err, pluginData) {
if (err) {
return callback(err);
}
@@ -117,39 +117,39 @@ module.exports = function(Plugins) {
});
}
- Plugins.upgrade = function(id, version, callback) {
+ Plugins.upgrade = function (id, version, callback) {
pubsub.publish('plugins:upgrade', {hostname: os.hostname(), id: id, version: version});
upgrade(id, version, callback);
};
function upgrade(id, version, callback) {
async.waterfall([
- function(next) {
+ function (next) {
runNpmCommand('npm install ' + id + '@' + (version || 'latest'), next);
},
- function(next) {
+ function (next) {
Plugins.isActive(id, next);
},
- function(isActive, next) {
+ function (isActive, next) {
meta.reloadRequired = isActive;
next(null, isActive);
}
], callback);
}
- Plugins.isInstalled = function(id, callback) {
+ Plugins.isInstalled = function (id, callback) {
var pluginDir = path.join(__dirname, '../../node_modules', id);
- fs.stat(pluginDir, function(err, stats) {
+ fs.stat(pluginDir, function (err, stats) {
callback(null, err ? false : stats.isDirectory());
});
};
- Plugins.isActive = function(id, callback) {
+ Plugins.isActive = function (id, callback) {
db.isSortedSetMember('plugins:active', id, callback);
};
- Plugins.getActive = function(callback) {
+ Plugins.getActive = function (callback) {
db.getSortedSetRange('plugins:active', 0, -1, callback);
};
};
\ No newline at end of file
diff --git a/src/plugins/load.js b/src/plugins/load.js
index c19e55d7e4..836e0d2c4a 100644
--- a/src/plugins/load.js
+++ b/src/plugins/load.js
@@ -13,10 +13,10 @@ var utils = require('../../public/src/utils'),
meta = require('../meta');
-module.exports = function(Plugins) {
+module.exports = function (Plugins) {
- Plugins.loadPlugin = function(pluginPath, callback) {
- Plugins.loadPluginInfo(pluginPath, function(err, pluginData) {
+ Plugins.loadPlugin = function (pluginPath, callback) {
+ Plugins.loadPluginInfo(pluginPath, function (err, pluginData) {
if (err) {
if (err.message === '[[error:parse-error]]') {
return callback();
@@ -27,28 +27,28 @@ module.exports = function(Plugins) {
checkVersion(pluginData);
async.parallel([
- function(next) {
+ function (next) {
registerHooks(pluginData, pluginPath, next);
},
- function(next) {
+ function (next) {
mapStaticDirectories(pluginData, pluginPath, next);
},
- function(next) {
+ function (next) {
mapFiles(pluginData, 'css', 'cssFiles', next);
},
- function(next) {
+ function (next) {
mapFiles(pluginData, 'less', 'lessFiles', next);
},
- function(next) {
+ function (next) {
mapClientSideScripts(pluginData, next);
},
- function(next) {
+ function (next) {
mapClientModules(pluginData, next);
},
- function(next) {
+ function (next) {
loadLanguages(pluginData, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
winston.verbose('[plugins] Could not load plugin : ' + pluginData.id);
return callback(err);
@@ -89,7 +89,7 @@ module.exports = function(Plugins) {
}
if (Array.isArray(pluginData.hooks) && pluginData.hooks.length > 0) {
- async.each(pluginData.hooks, function(hook, next) {
+ async.each(pluginData.hooks, function (hook, next) {
Plugins.registerHook(pluginData.id, hook, next);
}, callback);
} else {
@@ -114,7 +114,7 @@ module.exports = function(Plugins) {
var realPath = pluginData.staticDirs[mappedPath];
var staticDir = path.join(pluginPath, realPath);
- file.exists(staticDir, function(exists) {
+ file.exists(staticDir, function (exists) {
if (exists) {
Plugins.staticDirs[pluginData.id + '/' + mappedPath] = staticDir;
} else {
@@ -139,7 +139,7 @@ module.exports = function(Plugins) {
winston.verbose('[plugins] Found ' + pluginData[type].length + ' ' + type + ' file(s) for plugin ' + pluginData.id);
}
- Plugins[globalArray] = Plugins[globalArray].concat(pluginData[type].map(function(file) {
+ Plugins[globalArray] = Plugins[globalArray].concat(pluginData[type].map(function (file) {
return path.join(pluginData.id, file);
}));
}
@@ -152,7 +152,7 @@ module.exports = function(Plugins) {
winston.verbose('[plugins] Found ' + pluginData.scripts.length + ' js file(s) for plugin ' + pluginData.id);
}
- Plugins.clientScripts = Plugins.clientScripts.concat(pluginData.scripts.map(function(file) {
+ Plugins.clientScripts = Plugins.clientScripts.concat(pluginData.scripts.map(function (file) {
return resolveModulePath(path.join(__dirname, '../../node_modules/', pluginData.id, file), file);
})).filter(Boolean);
}
@@ -162,7 +162,7 @@ module.exports = function(Plugins) {
winston.verbose('[plugins] Found ' + pluginData.acpScripts.length + ' ACP js file(s) for plugin ' + pluginData.id);
}
- Plugins.acpScripts = Plugins.acpScripts.concat(pluginData.acpScripts.map(function(file) {
+ Plugins.acpScripts = Plugins.acpScripts.concat(pluginData.acpScripts.map(function (file) {
return resolveModulePath(path.join(__dirname, '../../node_modules/', pluginData.id, file), file);
})).filter(Boolean);
}
@@ -184,7 +184,7 @@ module.exports = function(Plugins) {
var strip = pluginData.hasOwnProperty('modulesStrip') ? parseInt(pluginData.modulesStrip, 10) : 0;
- pluginData.modules.forEach(function(file) {
+ pluginData.modules.forEach(function (file) {
if (strip) {
modules[file.replace(new RegExp('\.?(\/[^\/]+){' + strip + '}\/'), '')] = path.join('./node_modules/', pluginData.id, file);
} else {
@@ -220,13 +220,13 @@ module.exports = function(Plugins) {
var pathToFolder = path.join(__dirname, '../../node_modules/', pluginData.id, pluginData.languages),
fallbackMap = {};
- utils.walk(pathToFolder, function(err, languages) {
+ utils.walk(pathToFolder, function (err, languages) {
if (err) {
return callback(err);
}
- async.each(languages, function(pathToLang, next) {
- fs.readFile(pathToLang, function(err, file) {
+ async.each(languages, function (pathToLang, next) {
+ fs.readFile(pathToLang, function (err, file) {
if (err) {
return next(err);
}
@@ -244,20 +244,20 @@ module.exports = function(Plugins) {
_.extendOwn(Plugins.customLanguages[route], data);
if (pluginData.defaultLang && pathToLang.endsWith(pluginData.defaultLang + '/' + path.basename(pathToLang))) {
- Plugins.languageCodes.map(function(code) {
+ Plugins.languageCodes.map(function (code) {
if (pluginData.defaultLang !== code) {
return code + '/' + path.basename(pathToLang);
} else {
return null;
}
- }).filter(Boolean).forEach(function(key) {
+ }).filter(Boolean).forEach(function (key) {
Plugins.customLanguages[key] = _.defaults(Plugins.customLanguages[key] || {}, data);
});
}
next();
});
- }, function(err) {
+ }, function (err) {
if (err) {
return callback(err);
}
@@ -292,15 +292,15 @@ module.exports = function(Plugins) {
}
}
- Plugins.loadPluginInfo = function(pluginPath, callback) {
+ Plugins.loadPluginInfo = function (pluginPath, callback) {
async.parallel({
- package: function(next) {
+ package: function (next) {
fs.readFile(path.join(pluginPath, 'package.json'), next);
},
- plugin: function(next) {
+ plugin: function (next) {
fs.readFile(path.join(pluginPath, 'plugin.json'), next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
diff --git a/src/posts.js b/src/posts.js
index 410afd959d..975846859b 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -10,7 +10,7 @@ var topics = require('./topics');
var privileges = require('./privileges');
var plugins = require('./plugins');
-(function(Posts) {
+(function (Posts) {
require('./posts/create')(Posts);
require('./posts/delete')(Posts);
@@ -26,18 +26,18 @@ var plugins = require('./plugins');
require('./posts/votes')(Posts);
require('./posts/bookmarks')(Posts);
- Posts.exists = function(pid, callback) {
+ Posts.exists = function (pid, callback) {
db.isSortedSetMember('posts:pid', pid, callback);
};
- Posts.getPidsFromSet = function(set, start, stop, reverse, callback) {
+ Posts.getPidsFromSet = function (set, start, stop, reverse, callback) {
if (isNaN(start) || isNaN(stop)) {
return callback(null, []);
}
db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, stop, callback);
};
- Posts.getPostsByPids = function(pids, uid, callback) {
+ Posts.getPostsByPids = function (pids, uid, callback) {
if (!Array.isArray(pids) || !pids.length) {
return callback(null, []);
}
@@ -49,11 +49,11 @@ var plugins = require('./plugins');
}
async.waterfall([
- function(next) {
+ function (next) {
db.getObjects(keys, next);
},
- function(posts, next) {
- async.map(posts, function(post, next) {
+ function (posts, next) {
+ async.map(posts, function (post, next) {
if (!post) {
return next();
}
@@ -65,10 +65,10 @@ var plugins = require('./plugins');
Posts.parsePost(post, next);
}, next);
},
- function(posts, next) {
+ function (posts, next) {
plugins.fireHook('filter:post.getPosts', {posts: posts, uid: uid}, next);
},
- function(data, next) {
+ function (data, next) {
if (!data || !Array.isArray(data.posts)) {
return next(null, []);
}
@@ -78,25 +78,25 @@ var plugins = require('./plugins');
], callback);
};
- Posts.getPostSummariesFromSet = function(set, uid, start, stop, callback) {
+ Posts.getPostSummariesFromSet = function (set, uid, start, stop, callback) {
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRevRange(set, start, stop, 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: false}, next);
},
- function(posts, next) {
+ function (posts, next) {
next(null, {posts: posts, nextStart: stop + 1});
}
], callback);
};
- Posts.getPostData = function(pid, callback) {
- db.getObject('post:' + pid, function(err, data) {
+ Posts.getPostData = function (pid, callback) {
+ db.getObject('post:' + pid, function (err, data) {
if (err) {
return callback(err);
}
@@ -105,8 +105,8 @@ var plugins = require('./plugins');
});
};
- Posts.getPostField = function(pid, field, callback) {
- Posts.getPostFields(pid, [field], function(err, data) {
+ Posts.getPostField = function (pid, field, callback) {
+ Posts.getPostFields(pid, [field], function (err, data) {
if (err) {
return callback(err);
}
@@ -115,41 +115,41 @@ var plugins = require('./plugins');
});
};
- Posts.getPostFields = function(pid, fields, callback) {
- db.getObjectFields('post:' + pid, fields, function(err, data) {
+ Posts.getPostFields = function (pid, fields, callback) {
+ db.getObjectFields('post:' + pid, fields, function (err, data) {
if (err) {
return callback(err);
}
data.pid = pid;
- plugins.fireHook('filter:post.getFields', {posts: [data], fields: fields}, function(err, data) {
+ plugins.fireHook('filter:post.getFields', {posts: [data], fields: fields}, function (err, data) {
callback(err, (data && Array.isArray(data.posts) && data.posts.length) ? data.posts[0] : null);
});
});
};
- Posts.getPostsFields = function(pids, fields, callback) {
+ Posts.getPostsFields = function (pids, fields, callback) {
if (!Array.isArray(pids) || !pids.length) {
return callback(null, []);
}
- var keys = pids.map(function(pid) {
+ var keys = pids.map(function (pid) {
return 'post:' + pid;
});
- db.getObjectsFields(keys, fields, function(err, posts) {
+ db.getObjectsFields(keys, fields, function (err, posts) {
if (err) {
return callback(err);
}
- plugins.fireHook('filter:post.getFields', {posts: posts, fields: fields}, function(err, data) {
+ plugins.fireHook('filter:post.getFields', {posts: posts, fields: fields}, function (err, data) {
callback(err, (data && Array.isArray(data.posts)) ? data.posts : null);
});
});
};
- Posts.setPostField = function(pid, field, value, callback) {
- db.setObjectField('post:' + pid, field, value, function(err) {
+ Posts.setPostField = function (pid, field, value, callback) {
+ db.setObjectField('post:' + pid, field, value, function (err) {
if (err) {
return callback(err);
}
@@ -162,8 +162,8 @@ var plugins = require('./plugins');
});
};
- Posts.setPostFields = function(pid, data, callback) {
- db.setObject('post:' + pid, data, function(err) {
+ Posts.setPostFields = function (pid, data, callback) {
+ db.setObject('post:' + pid, data, function (err) {
if (err) {
return callback(err);
}
@@ -173,9 +173,9 @@ var plugins = require('./plugins');
});
};
- Posts.getPidIndex = function(pid, tid, topicPostSort, callback) {
+ Posts.getPidIndex = function (pid, tid, topicPostSort, callback) {
var set = topicPostSort === 'most_votes' ? 'tid:' + tid + ':posts:votes' : 'tid:' + tid + ':posts';
- db.sortedSetRank(set, pid, function(err, index) {
+ db.sortedSetRank(set, pid, function (err, index) {
if (!utils.isNumber(index)) {
return callback(err, 0);
}
@@ -183,18 +183,18 @@ var plugins = require('./plugins');
});
};
- Posts.getPostIndices = function(posts, uid, callback) {
+ Posts.getPostIndices = function (posts, uid, callback) {
if (!Array.isArray(posts) || !posts.length) {
return callback(null, []);
}
- user.getSettings(uid, function(err, settings) {
+ user.getSettings(uid, function (err, settings) {
if (err) {
return callback(err);
}
var byVotes = settings.topicPostSort === 'most_votes';
- var sets = posts.map(function(post) {
+ var sets = posts.map(function (post) {
return byVotes ? 'tid:' + post.tid + ':posts:votes' : 'tid:' + post.tid + ':posts';
});
@@ -205,11 +205,11 @@ var plugins = require('./plugins');
sets = uniqueSets[0];
}
- var pids = posts.map(function(post) {
+ var pids = posts.map(function (post) {
return post.pid;
});
- db[method](sets, pids, function(err, indices) {
+ db[method](sets, pids, function (err, indices) {
if (err) {
return callback(err);
}
@@ -223,7 +223,7 @@ var plugins = require('./plugins');
});
};
- Posts.updatePostVoteCount = function(postData, callback) {
+ Posts.updatePostVoteCount = function (postData, callback) {
if (!postData || !postData.pid || !postData.tid) {
return callback();
}
@@ -255,7 +255,7 @@ var plugins = require('./plugins');
function (next) {
Posts.setPostFields(postData.pid, {upvotes: postData.upvotes, downvotes: postData.downvotes}, next);
}
- ], function(err) {
+ ], function (err) {
callback(err);
});
};
diff --git a/src/posts/bookmarks.js b/src/posts/bookmarks.js
index 14bf585647..b60da91c77 100644
--- a/src/posts/bookmarks.js
+++ b/src/posts/bookmarks.js
@@ -5,13 +5,13 @@ var async = require('async');
var db = require('../database');
var plugins = require('../plugins');
-module.exports = function(Posts) {
+module.exports = function (Posts) {
Posts.bookmark = function (pid, uid, callback) {
toggleBookmark('bookmark', pid, uid, callback);
};
- Posts.unbookmark = function(pid, uid, callback) {
+ Posts.unbookmark = function (pid, uid, callback) {
toggleBookmark('unbookmark', pid, uid, callback);
};
@@ -22,16 +22,16 @@ module.exports = function(Posts) {
var isBookmarking = type === 'bookmark';
async.parallel({
- owner: function(next) {
+ owner: function (next) {
Posts.getPostField(pid, 'uid', next);
},
- postData: function(next) {
+ postData: function (next) {
Posts.getPostFields(pid, ['pid', 'uid'], next);
},
- hasBookmarked: function(next) {
+ hasBookmarked: function (next) {
Posts.hasBookmarked(pid, uid, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -45,24 +45,24 @@ module.exports = function(Posts) {
}
async.waterfall([
- function(next) {
+ function (next) {
if (isBookmarking) {
db.sortedSetAdd('uid:' + uid + ':bookmarks', Date.now(), pid, next);
} else {
db.sortedSetRemove('uid:' + uid + ':bookmarks', pid, next);
}
},
- function(next) {
+ function (next) {
db[isBookmarking ? 'setAdd' : 'setRemove']('pid:' + pid + ':users_bookmarked', uid, next);
},
- function(next) {
+ function (next) {
db.setCount('pid:' + pid + ':users_bookmarked', next);
},
- function(count, next) {
+ function (count, next) {
results.postData.bookmarks = count;
Posts.setPostField(pid, 'bookmarks', count, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
@@ -84,10 +84,10 @@ module.exports = function(Posts) {
});
}
- Posts.hasBookmarked = function(pid, uid, callback) {
+ Posts.hasBookmarked = function (pid, uid, callback) {
if (!parseInt(uid, 10)) {
if (Array.isArray(pid)) {
- callback(null, pid.map(function() { return false; }));
+ callback(null, pid.map(function () { return false; }));
} else {
callback(null, false);
}
@@ -95,7 +95,7 @@ module.exports = function(Posts) {
}
if (Array.isArray(pid)) {
- var sets = pid.map(function(pid) {
+ var sets = pid.map(function (pid) {
return 'pid:' + pid + ':users_bookmarked';
});
diff --git a/src/posts/category.js b/src/posts/category.js
index 0f9ee7fd67..28444ce2a7 100644
--- a/src/posts/category.js
+++ b/src/posts/category.js
@@ -6,44 +6,44 @@ var async = require('async');
var db = require('../database');
var topics = require('../topics');
-module.exports = function(Posts) {
+module.exports = function (Posts) {
- Posts.getCidByPid = function(pid, callback) {
+ Posts.getCidByPid = function (pid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
Posts.getPostField(pid, 'tid', next);
},
- function(tid, next) {
+ function (tid, next) {
topics.getTopicField(tid, 'cid', next);
}
], callback);
};
- Posts.getCidsByPids = function(pids, callback) {
- Posts.getPostsFields(pids, ['tid'], function(err, posts) {
+ Posts.getCidsByPids = function (pids, callback) {
+ Posts.getPostsFields(pids, ['tid'], function (err, posts) {
if (err) {
return callback(err);
}
- var tids = posts.map(function(post) {
+ var tids = posts.map(function (post) {
return post.tid;
- }).filter(function(tid, index, array) {
+ }).filter(function (tid, index, array) {
return tid && array.indexOf(tid) === index;
});
- topics.getTopicsFields(tids, ['cid'], function(err, topics) {
+ topics.getTopicsFields(tids, ['cid'], function (err, topics) {
if (err) {
return callback(err);
}
var map = {};
- topics.forEach(function(topic, index) {
+ topics.forEach(function (topic, index) {
if (topic) {
map[tids[index]] = topic.cid;
}
});
- var cids = posts.map(function(post) {
+ var cids = posts.map(function (post) {
return map[post.tid];
});
@@ -52,15 +52,15 @@ module.exports = function(Posts) {
});
};
- Posts.filterPidsByCid = function(pids, cid, callback) {
+ Posts.filterPidsByCid = function (pids, cid, callback) {
if (!cid) {
return callback(null, pids);
}
- db.isSortedSetMembers('cid:' + cid + ':pids', pids, function(err, isMembers) {
+ db.isSortedSetMembers('cid:' + cid + ':pids', pids, function (err, isMembers) {
if (err) {
return callback(err);
}
- pids = pids.filter(function(pid, index) {
+ pids = pids.filter(function (pid, index) {
return pid && isMembers[index];
});
callback(null, pids);
diff --git a/src/posts/create.js b/src/posts/create.js
index c80dc1d9f9..1054c6d694 100644
--- a/src/posts/create.js
+++ b/src/posts/create.js
@@ -11,9 +11,9 @@ var topics = require('../topics');
var categories = require('../categories');
-module.exports = function(Posts) {
+module.exports = function (Posts) {
- Posts.create = function(data, callback) {
+ Posts.create = function (data, callback) {
// This is an internal method, consider using Topics.reply instead
var uid = data.uid;
var tid = data.tid;
@@ -27,10 +27,10 @@ module.exports = function(Posts) {
var postData;
async.waterfall([
- function(next) {
+ function (next) {
db.incrObjectField('global', 'nextPid', next);
},
- function(pid, next) {
+ function (pid, next) {
postData = {
'pid': pid,
@@ -55,23 +55,23 @@ module.exports = function(Posts) {
plugins.fireHook('filter:post.save', postData, next);
},
- function(postData, next) {
+ function (postData, next) {
plugins.fireHook('filter:post.create', {post: postData, data: data}, next);
},
- function(data, next) {
+ function (data, next) {
postData = data.post;
db.setObject('post:' + postData.pid, postData, next);
},
- function(next) {
+ function (next) {
async.parallel([
- function(next) {
+ function (next) {
user.onNewPostMade(postData, next);
},
- function(next) {
+ function (next) {
topics.onNewPostMade(postData, next);
},
- function(next) {
- topics.getTopicFields(tid, ['cid', 'pinned'], function(err, topicData) {
+ function (next) {
+ topics.getTopicFields(tid, ['cid', 'pinned'], function (err, topicData) {
if (err) {
return next(err);
}
@@ -79,20 +79,20 @@ module.exports = function(Posts) {
categories.onNewPostMade(topicData.cid, topicData.pinned, postData, next);
});
},
- function(next) {
+ function (next) {
db.sortedSetAdd('posts:pid', timestamp, postData.pid, next);
},
- function(next) {
+ function (next) {
db.incrObjectField('global', 'postCount', next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return next(err);
}
plugins.fireHook('filter:post.get', postData, next);
});
},
- function(postData, next) {
+ function (postData, next) {
plugins.fireHook('action:post.save', _.clone(postData));
next(null, postData);
}
diff --git a/src/posts/delete.js b/src/posts/delete.js
index 522f6855ab..bdaae4a70c 100644
--- a/src/posts/delete.js
+++ b/src/posts/delete.js
@@ -8,9 +8,9 @@ var topics = require('../topics');
var user = require('../user');
var plugins = require('../plugins');
-module.exports = function(Posts) {
+module.exports = function (Posts) {
- Posts.delete = function(pid, uid, callback) {
+ Posts.delete = function (pid, uid, callback) {
var postData;
async.waterfall([
function (next) {
@@ -28,13 +28,13 @@ module.exports = function(Posts) {
},
function (topicData, next) {
async.parallel([
- function(next) {
+ function (next) {
updateTopicTimestamp(topicData, next);
},
- function(next) {
+ function (next) {
db.sortedSetRemove('cid:' + topicData.cid + ':pids', pid, next);
},
- function(next) {
+ function (next) {
topics.updateTeaser(postData.tid, next);
}
], next);
@@ -46,7 +46,7 @@ module.exports = function(Posts) {
], callback);
};
- Posts.restore = function(pid, uid, callback) {
+ Posts.restore = function (pid, uid, callback) {
var postData;
async.waterfall([
function (next) {
@@ -65,13 +65,13 @@ module.exports = function(Posts) {
function (topicData, next) {
postData.cid = topicData.cid;
async.parallel([
- function(next) {
+ function (next) {
updateTopicTimestamp(topicData, next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('cid:' + topicData.cid + ':pids', postData.timestamp, pid, next);
},
- function(next) {
+ function (next) {
topics.updateTeaser(postData.tid, next);
}
], next);
@@ -112,7 +112,7 @@ module.exports = function(Posts) {
], callback);
}
- Posts.purge = function(pid, uid, callback) {
+ Posts.purge = function (pid, uid, callback) {
async.waterfall([
function (next) {
Posts.exists(pid, next);
@@ -143,7 +143,7 @@ module.exports = function(Posts) {
function (next) {
Posts.dismissFlag(pid, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return next(err);
}
@@ -155,7 +155,7 @@ module.exports = function(Posts) {
};
function deletePostFromTopicAndUser(pid, callback) {
- Posts.getPostFields(pid, ['tid', 'uid'], function(err, postData) {
+ Posts.getPostFields(pid, ['tid', 'uid'], function (err, postData) {
if (err) {
return callback(err);
}
@@ -164,12 +164,12 @@ module.exports = function(Posts) {
'tid:' + postData.tid + ':posts',
'tid:' + postData.tid + ':posts:votes',
'uid:' + postData.uid + ':posts'
- ], pid, function(err) {
+ ], pid, function (err) {
if (err) {
return callback(err);
}
- topics.getTopicFields(postData.tid, ['tid', 'cid', 'pinned'], function(err, topicData) {
+ topics.getTopicFields(postData.tid, ['tid', 'cid', 'pinned'], function (err, topicData) {
if (err) {
return callback(err);
}
@@ -184,19 +184,19 @@ module.exports = function(Posts) {
function (next) {
topics.decreasePostCount(postData.tid, next);
},
- function(next) {
+ function (next) {
topics.updateTeaser(postData.tid, next);
},
function (next) {
updateTopicTimestamp(topicData, next);
},
- function(next) {
+ function (next) {
db.sortedSetIncrBy('cid:' + topicData.cid + ':tids:posts', -1, postData.tid, next);
},
- function(next) {
+ function (next) {
db.sortedSetIncrBy('tid:' + postData.tid + ':posters', -1, postData.uid, next);
},
- function(next) {
+ function (next) {
user.incrementUserPostCountBy(postData.uid, -1, next);
}
], callback);
@@ -206,12 +206,12 @@ module.exports = function(Posts) {
}
function deletePostFromCategoryRecentPosts(pid, callback) {
- db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
+ db.getSortedSetRange('categories:cid', 0, -1, function (err, cids) {
if (err) {
return callback(err);
}
- var sets = cids.map(function(cid) {
+ var sets = cids.map(function (cid) {
return 'cid:' + cid + ':pids';
});
@@ -220,16 +220,16 @@ module.exports = function(Posts) {
}
function deletePostFromUsersBookmarks(pid, callback) {
- db.getSetMembers('pid:' + pid + ':users_bookmarked', function(err, uids) {
+ db.getSetMembers('pid:' + pid + ':users_bookmarked', function (err, uids) {
if (err) {
return callback(err);
}
- var sets = uids.map(function(uid) {
+ var sets = uids.map(function (uid) {
return 'uid:' + uid + ':bookmarks';
});
- db.sortedSetsRemove(sets, pid, function(err) {
+ db.sortedSetsRemove(sets, pid, function (err) {
if (err) {
return callback(err);
}
@@ -241,33 +241,33 @@ module.exports = function(Posts) {
function deletePostFromUsersVotes(pid, callback) {
async.parallel({
- upvoters: function(next) {
+ upvoters: function (next) {
db.getSetMembers('pid:' + pid + ':upvote', next);
},
- downvoters: function(next) {
+ downvoters: function (next) {
db.getSetMembers('pid:' + pid + ':downvote', next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
- var upvoterSets = results.upvoters.map(function(uid) {
+ var upvoterSets = results.upvoters.map(function (uid) {
return 'uid:' + uid + ':upvote';
});
- var downvoterSets = results.downvoters.map(function(uid) {
+ var downvoterSets = results.downvoters.map(function (uid) {
return 'uid:' + uid + ':downvote';
});
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetsRemove(upvoterSets, pid, next);
},
- function(next) {
+ function (next) {
db.sortedSetsRemove(downvoterSets, pid, next);
},
- function(next) {
+ function (next) {
db.deleteAll(['pid:' + pid + ':upvote', 'pid:' + pid + ':downvote'], next);
}
], callback);
diff --git a/src/posts/edit.js b/src/posts/edit.js
index 5bb76ec019..e8a5ea8395 100644
--- a/src/posts/edit.js
+++ b/src/posts/edit.js
@@ -13,13 +13,13 @@ var cache = require('./cache');
var pubsub = require('../pubsub');
var utils = require('../../public/src/utils');
-module.exports = function(Posts) {
+module.exports = function (Posts) {
- pubsub.on('post:edit', function(pid) {
+ pubsub.on('post:edit', function (pid) {
cache.del(pid);
});
- Posts.edit = function(data, callback) {
+ Posts.edit = function (data, callback) {
var postData;
var results;
@@ -53,10 +53,10 @@ module.exports = function(Posts) {
},
function (next) {
async.parallel({
- editor: function(next) {
+ editor: function (next) {
user.getUserFields(data.uid, ['username', 'userslug'], next);
},
- topic: function(next) {
+ topic: function (next) {
editMainPost(data, postData, next);
}
}, next);
@@ -85,13 +85,13 @@ module.exports = function(Posts) {
var title = data.title ? data.title.trim() : '';
async.parallel({
- topic: function(next) {
+ topic: function (next) {
topics.getTopicFields(tid, ['cid', 'title'], next);
},
- isMain: function(next) {
+ isMain: function (next) {
Posts.isMain(data.pid, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -122,19 +122,19 @@ module.exports = function(Posts) {
data.tags = data.tags || [];
async.waterfall([
- function(next) {
+ function (next) {
plugins.fireHook('filter:topic.edit', {req: data.req, topic: topicData, data: data}, next);
},
- function(results, next) {
+ function (results, next) {
db.setObject('topic:' + tid, results.topic, next);
},
- function(next) {
+ function (next) {
topics.updateTags(tid, data.tags, next);
},
- function(next) {
+ function (next) {
topics.getTopicTagsObjects(tid, next);
},
- function(tags, next) {
+ function (tags, next) {
topicData.tags = data.tags;
plugins.fireHook('action:topic.edit', topicData);
next(null, {
diff --git a/src/posts/flags.js b/src/posts/flags.js
index c5df336c16..ee0e974d24 100644
--- a/src/posts/flags.js
+++ b/src/posts/flags.js
@@ -8,21 +8,21 @@ var db = require('../database');
var user = require('../user');
var analytics = require('../analytics');
-module.exports = function(Posts) {
+module.exports = function (Posts) {
- Posts.flag = function(post, uid, reason, callback) {
+ Posts.flag = function (post, uid, reason, callback) {
if (!parseInt(uid, 10) || !reason) {
return callback();
}
async.waterfall([
- function(next) {
+ function (next) {
async.parallel({
hasFlagged: async.apply(hasFlagged, post.pid, uid),
exists: async.apply(Posts.exists, post.pid)
}, next);
},
- function(results, next) {
+ function (results, next) {
if (!results.exists) {
return next(new Error('[[error:no-post]]'));
}
@@ -33,22 +33,22 @@ module.exports = function(Posts) {
var now = Date.now();
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetAdd('posts:flagged', now, post.pid, next);
},
- function(next) {
+ function (next) {
db.sortedSetIncrBy('posts:flags:count', 1, post.pid, next);
},
- function(next) {
+ function (next) {
db.incrObjectField('post:' + post.pid, 'flags', next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('pid:' + post.pid + ':flag:uids', now, uid, next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('pid:' + post.pid + ':flag:uid:reason', 0, uid + ':' + reason, next);
},
- function(next) {
+ function (next) {
if (parseInt(post.uid, 10)) {
async.parallel([
async.apply(db.sortedSetIncrBy, 'users:flags', 1, post.uid),
@@ -61,14 +61,14 @@ module.exports = function(Posts) {
}
], next);
},
- function(data, next) {
+ function (data, next) {
if (data[1] === 1) { // Only update state on new flag
Posts.updateFlagData(uid, post.pid, {
state: 'open'
}, next);
}
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
@@ -81,17 +81,17 @@ module.exports = function(Posts) {
db.isSortedSetMember('pid:' + pid + ':flag:uids', uid, callback);
}
- Posts.dismissFlag = function(pid, callback) {
+ Posts.dismissFlag = function (pid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
db.getObjectFields('post:' + pid, ['pid', 'uid', 'flags'], next);
},
- function(postData, next) {
+ function (postData, next) {
if (!postData.pid) {
return callback();
}
async.parallel([
- function(next) {
+ function (next) {
if (parseInt(postData.uid, 10)) {
if (parseInt(postData.flags, 10) > 0) {
async.parallel([
@@ -105,22 +105,22 @@ module.exports = function(Posts) {
next();
}
},
- function(next) {
+ function (next) {
db.sortedSetsRemove([
'posts:flagged',
'posts:flags:count',
'uid:' + postData.uid + ':flag:pids'
], pid, next);
},
- function(next) {
+ function (next) {
async.series([
- function(next) {
- db.getSortedSetRange('pid:' + pid + ':flag:uids', 0, -1, function(err, uids) {
+ function (next) {
+ db.getSortedSetRange('pid:' + pid + ':flag:uids', 0, -1, function (err, uids) {
if (err) {
return next(err);
}
- async.each(uids, function(uid, next) {
+ async.each(uids, function (uid, next) {
var nid = 'post_flag:' + pid + ':uid:' + uid;
async.parallel([
async.apply(db.delete, 'notifications:' + nid),
@@ -137,14 +137,14 @@ module.exports = function(Posts) {
async.apply(db.deleteObjectFields, 'post:' + pid, ['flag:state', 'flag:assignee', 'flag:notes', 'flag:history'])
], next);
},
- function(results, next) {
+ function (results, next) {
db.sortedSetsRemoveRangeByScore(['users:flags'], '-inf', 0, next);
}
], callback);
};
- Posts.dismissAllFlags = function(callback) {
- db.getSortedSetRange('posts:flagged', 0, -1, function(err, pids) {
+ Posts.dismissAllFlags = function (callback) {
+ db.getSortedSetRange('posts:flagged', 0, -1, function (err, pids) {
if (err) {
return callback(err);
}
@@ -152,8 +152,8 @@ module.exports = function(Posts) {
});
};
- Posts.dismissUserFlags = function(uid, callback) {
- db.getSortedSetRange('uid:' + uid + ':flag:pids', 0, -1, function(err, pids) {
+ Posts.dismissUserFlags = function (uid, callback) {
+ db.getSortedSetRange('uid:' + uid + ':flag:pids', 0, -1, function (err, pids) {
if (err) {
return callback(err);
}
@@ -161,7 +161,7 @@ module.exports = function(Posts) {
});
};
- Posts.getFlags = function(set, cid, uid, start, stop, callback) {
+ Posts.getFlags = function (set, cid, uid, start, stop, callback) {
async.waterfall([
function (next) {
if (Array.isArray(set)) {
@@ -192,31 +192,31 @@ module.exports = function(Posts) {
async.waterfall([
function (next) {
async.parallel({
- uidsReasons: function(next) {
- async.map(pids, function(pid, next) {
+ uidsReasons: function (next) {
+ async.map(pids, function (pid, next) {
db.getSortedSetRange('pid:' + pid + ':flag:uid:reason', 0, -1, next);
}, next);
},
- posts: function(next) {
+ posts: function (next) {
Posts.getPostSummaryByPids(pids, uid, {stripTags: false, extraFields: ['flags', 'flag:assignee', 'flag:state', 'flag:notes', 'flag:history']}, next);
}
}, next);
},
function (results, next) {
- async.map(results.uidsReasons, function(uidReasons, next) {
- async.map(uidReasons, function(uidReason, next) {
+ async.map(results.uidsReasons, function (uidReasons, next) {
+ async.map(uidReasons, function (uidReason, next) {
var uid = uidReason.split(':')[0];
var reason = uidReason.substr(uidReason.indexOf(':') + 1);
- user.getUserFields(uid, ['username', 'userslug', 'picture'], function(err, userData) {
+ user.getUserFields(uid, ['username', 'userslug', 'picture'], function (err, userData) {
next(err, {user: userData, reason: reason});
});
}, next);
- }, function(err, reasons) {
+ }, function (err, reasons) {
if (err) {
return callback(err);
}
- results.posts.forEach(function(post, index) {
+ results.posts.forEach(function (post, index) {
if (post) {
post.flagReasons = reasons[index];
}
@@ -226,9 +226,9 @@ module.exports = function(Posts) {
});
},
async.apply(Posts.expandFlagHistory),
- function(posts, next) {
+ function (posts, next) {
// Parse out flag data into its own object inside each post hash
- posts = posts.map(function(postObj) {
+ posts = posts.map(function (postObj) {
for(var prop in postObj) {
postObj.flagData = postObj.flagData || {};
@@ -264,13 +264,13 @@ module.exports = function(Posts) {
], callback);
}
- Posts.updateFlagData = function(uid, pid, flagObj, callback) {
+ Posts.updateFlagData = function (uid, pid, flagObj, callback) {
// Retrieve existing flag data to compare for history-saving purposes
var changes = [];
var changeset = {};
var prop;
- Posts.getPostData(pid, function(err, postData) {
+ Posts.getPostData(pid, function (err, postData) {
if (err) {
return callback(err);
}
@@ -293,7 +293,7 @@ module.exports = function(Posts) {
}
}
- changeset = changes.reduce(function(memo, prop) {
+ changeset = changes.reduce(function (memo, prop) {
memo['flag:' + prop] = flagObj[prop];
return memo;
}, {});
@@ -303,7 +303,7 @@ module.exports = function(Posts) {
try {
var history = JSON.parse(postData['flag:history'] || '[]');
- changes.forEach(function(property) {
+ changes.forEach(function (property) {
switch(property) {
case 'assignee': // intentional fall-through
case 'state':
@@ -339,9 +339,9 @@ module.exports = function(Posts) {
});
};
- Posts.expandFlagHistory = function(posts, callback) {
+ Posts.expandFlagHistory = function (posts, callback) {
// Expand flag history
- async.map(posts, function(post, next) {
+ async.map(posts, function (post, next) {
var history;
try {
history = JSON.parse(post['flag:history'] || '[]');
@@ -350,12 +350,12 @@ module.exports = function(Posts) {
return callback(e);
}
- async.map(history, function(event, next) {
+ async.map(history, function (event, next) {
event.timestampISO = new Date(event.timestamp).toISOString();
async.parallel([
- function(next) {
- user.getUserFields(event.uid, ['username', 'picture'], function(err, userData) {
+ function (next) {
+ user.getUserFields(event.uid, ['username', 'picture'], function (err, userData) {
if (err) {
return next(err);
}
@@ -364,9 +364,9 @@ module.exports = function(Posts) {
next();
});
},
- function(next) {
+ function (next) {
if (event.type === 'assignee') {
- user.getUserField(parseInt(event.value, 10), 'username', function(err, username) {
+ user.getUserField(parseInt(event.value, 10), 'username', function (err, username) {
if (err) {
return next(err);
}
@@ -381,10 +381,10 @@ module.exports = function(Posts) {
setImmediate(next);
}
}
- ], function(err) {
+ ], function (err) {
next(err, event);
});
- }, function(err, history) {
+ }, function (err, history) {
if (err) {
return next(err);
}
diff --git a/src/posts/parse.js b/src/posts/parse.js
index 88fa5f8c22..28af97c5e6 100644
--- a/src/posts/parse.js
+++ b/src/posts/parse.js
@@ -10,9 +10,9 @@ var translator = require('../../public/src/modules/translator');
var urlRegex = /href="([^"]+)"/g;
-module.exports = function(Posts) {
+module.exports = function (Posts) {
- Posts.parsePost = function(postData, callback) {
+ Posts.parsePost = function (postData, callback) {
postData.content = postData.content || '';
if (postData.pid && cache.has(String(postData.pid))) {
@@ -25,7 +25,7 @@ module.exports = function(Posts) {
postData.content = postData.content.toString();
}
- plugins.fireHook('filter:parse.post', {postData: postData}, function(err, data) {
+ plugins.fireHook('filter:parse.post', {postData: postData}, function (err, data) {
if (err) {
return callback(err);
}
@@ -40,13 +40,13 @@ module.exports = function(Posts) {
});
};
- Posts.parseSignature = function(userData, uid, callback) {
+ Posts.parseSignature = function (userData, uid, callback) {
userData.signature = userData.signature || '';
plugins.fireHook('filter:parse.signature', {userData: userData, uid: uid}, callback);
};
- Posts.relativeToAbsolute = function(content) {
+ Posts.relativeToAbsolute = function (content) {
// Turns relative links in post body to absolute urls
var parsed, current, absolute;
diff --git a/src/posts/recent.js b/src/posts/recent.js
index f7d588acff..aec0ea4637 100644
--- a/src/posts/recent.js
+++ b/src/posts/recent.js
@@ -5,14 +5,14 @@ var async = require('async'),
privileges = require('../privileges');
-module.exports = function(Posts) {
+module.exports = function (Posts) {
var terms = {
day: 86400000,
week: 604800000,
month: 2592000000
};
- Posts.getRecentPosts = function(uid, start, stop, term, callback) {
+ Posts.getRecentPosts = function (uid, start, stop, term, callback) {
var min = 0;
if (terms[term]) {
min = Date.now() - terms[term];
@@ -21,30 +21,30 @@ module.exports = function(Posts) {
var count = parseInt(stop, 10) === -1 ? stop : stop - start + 1;
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRevRangeByScore('posts:pid', start, count, '+inf', min, 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);
};
- Posts.getRecentPosterUids = function(start, stop, callback) {
+ Posts.getRecentPosterUids = function (start, stop, callback) {
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRevRange('posts:pid', start, stop, next);
},
- function(pids, next) {
+ function (pids, next) {
Posts.getPostsFields(pids, ['uid'], next);
},
- function(postData, next) {
- postData = postData.map(function(post) {
+ function (postData, next) {
+ postData = postData.map(function (post) {
return post && post.uid;
- }).filter(function(value, index, array) {
+ }).filter(function (value, index, array) {
return value && array.indexOf(value) === index;
});
next(null, postData);
diff --git a/src/posts/summary.js b/src/posts/summary.js
index 2234863925..11ccb24381 100644
--- a/src/posts/summary.js
+++ b/src/posts/summary.js
@@ -12,9 +12,9 @@ var categories = require('../categories');
var utils = require('../../public/src/utils');
-module.exports = function(Posts) {
+module.exports = function (Posts) {
- Posts.getPostSummaryByPids = function(pids, uid, options, callback) {
+ Posts.getPostSummaryByPids = function (pids, uid, options, callback) {
if (!Array.isArray(pids) || !pids.length) {
return callback(null, []);
}
@@ -27,16 +27,16 @@ module.exports = function(Posts) {
var posts;
async.waterfall([
- function(next) {
+ function (next) {
Posts.getPostsFields(pids, fields, next);
},
- function(_posts, next) {
+ function (_posts, next) {
posts = _posts.filter(Boolean);
var uids = [];
var topicKeys = [];
- posts.forEach(function(post, i) {
+ posts.forEach(function (post, i) {
if (uids.indexOf(posts[i].uid) === -1) {
uids.push(posts[i].uid);
}
@@ -45,23 +45,23 @@ module.exports = function(Posts) {
}
});
async.parallel({
- users: function(next) {
+ users: function (next) {
user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], next);
},
- topicsAndCategories: function(next) {
+ topicsAndCategories: function (next) {
getTopicAndCategories(topicKeys, next);
},
- indices: function(next) {
+ indices: function (next) {
Posts.getPostIndices(posts, uid, next);
}
}, next);
},
- function(results, next) {
+ function (results, next) {
results.users = toObject('uid', results.users);
results.topics = toObject('tid', results.topicsAndCategories.topics);
results.categories = toObject('cid', results.topicsAndCategories.categories);
- posts.forEach(function(post, i) {
+ posts.forEach(function (post, i) {
post.index = utils.isNumber(results.indices[i]) ? parseInt(results.indices[i], 10) + 1 : 1;
post.isMainPost = post.index - 1 === 0;
post.deleted = parseInt(post.deleted, 10) === 1;
@@ -78,23 +78,23 @@ module.exports = function(Posts) {
post.timestampISO = utils.toISOString(post.timestamp);
});
- posts = posts.filter(function(post) {
+ posts = posts.filter(function (post) {
return results.topics[post.tid];
});
parsePosts(posts, options, next);
},
- function(posts, next) {
+ function (posts, next) {
plugins.fireHook('filter:post.getPostSummaryByPids', {posts: posts, uid: uid}, next);
},
- function(data, next) {
+ function (data, next) {
next(null, data.posts);
}
], callback);
};
function parsePosts(posts, options, callback) {
- async.map(posts, function(post, next) {
+ async.map(posts, function (post, next) {
if (!post.content || !options.parse) {
if (options.stripTags) {
post.content = stripTags(post.content);
@@ -103,7 +103,7 @@ module.exports = function(Posts) {
return next(null, post);
}
- Posts.parsePost(post, function(err, post) {
+ Posts.parsePost(post, function (err, post) {
if (err) {
return next(err);
}
@@ -117,22 +117,22 @@ module.exports = function(Posts) {
}
function getTopicAndCategories(topicKeys, callback) {
- db.getObjectsFields(topicKeys, ['uid', 'tid', 'title', 'cid', 'slug', 'deleted', 'postcount'], function(err, topics) {
+ db.getObjectsFields(topicKeys, ['uid', 'tid', 'title', 'cid', 'slug', 'deleted', 'postcount'], function (err, topics) {
if (err) {
return callback(err);
}
- var cids = topics.map(function(topic) {
+ var cids = topics.map(function (topic) {
if (topic) {
topic.title = validator.escape(String(topic.title));
topic.deleted = parseInt(topic.deleted, 10) === 1;
}
return topic && topic.cid;
- }).filter(function(topic, index, array) {
+ }).filter(function (topic, index, array) {
return topic && array.indexOf(topic) === index;
});
- categories.getCategoriesFields(cids, ['cid', 'name', 'icon', 'slug', 'parentCid', 'bgColor', 'color'], function(err, categories) {
+ categories.getCategoriesFields(cids, ['cid', 'name', 'icon', 'slug', 'parentCid', 'bgColor', 'color'], function (err, categories) {
callback(err, {topics: topics, categories: categories});
});
});
diff --git a/src/posts/tools.js b/src/posts/tools.js
index e2573554e8..82d55b1192 100644
--- a/src/posts/tools.js
+++ b/src/posts/tools.js
@@ -5,14 +5,14 @@ var async = require('async');
var privileges = require('../privileges');
var cache = require('./cache');
-module.exports = function(Posts) {
+module.exports = function (Posts) {
Posts.tools = {};
- Posts.tools.delete = function(uid, pid, callback) {
+ Posts.tools.delete = function (uid, pid, callback) {
togglePostDelete(uid, pid, true, callback);
};
- Posts.tools.restore = function(uid, pid, callback) {
+ Posts.tools.restore = function (uid, pid, callback) {
togglePostDelete(uid, pid, false, callback);
};
@@ -45,7 +45,7 @@ module.exports = function(Posts) {
cache.del(pid);
Posts.delete(pid, uid, next);
} else {
- Posts.restore(pid, uid, function(err, postData) {
+ Posts.restore(pid, uid, function (err, postData) {
if (err) {
return next(err);
}
@@ -56,7 +56,7 @@ module.exports = function(Posts) {
], callback);
}
- Posts.tools.purge = function(uid, pid, callback) {
+ Posts.tools.purge = function (uid, pid, callback) {
async.waterfall([
function (next) {
privileges.posts.canPurge(pid, uid, next);
diff --git a/src/posts/topics.js b/src/posts/topics.js
index a653e69b03..0653c880e6 100644
--- a/src/posts/topics.js
+++ b/src/posts/topics.js
@@ -6,46 +6,46 @@ var async = require('async');
var topics = require('../topics');
var utils = require('../../public/src/utils');
-module.exports = function(Posts) {
+module.exports = function (Posts) {
- Posts.getPostsFromSet = function(set, start, stop, uid, reverse, callback) {
+ Posts.getPostsFromSet = function (set, start, stop, uid, reverse, callback) {
async.waterfall([
- function(next) {
+ function (next) {
Posts.getPidsFromSet(set, start, stop, reverse, next);
},
- function(pids, next) {
+ function (pids, next) {
Posts.getPostsByPids(pids, uid, next);
}
], callback);
};
- Posts.isMain = function(pid, callback) {
+ Posts.isMain = function (pid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
Posts.getPostField(pid, 'tid', next);
},
- function(tid, next) {
+ function (tid, next) {
topics.getTopicField(tid, 'mainPid', next);
},
- function(mainPid, next) {
+ function (mainPid, next) {
next(null, parseInt(pid, 10) === parseInt(mainPid, 10));
}
], callback);
};
- Posts.getTopicFields = function(pid, fields, callback) {
+ Posts.getTopicFields = function (pid, fields, callback) {
async.waterfall([
- function(next) {
+ function (next) {
Posts.getPostField(pid, 'tid', next);
},
- function(tid, next) {
+ function (tid, next) {
topics.getTopicFields(tid, fields, next);
}
], callback);
};
Posts.generatePostPath = function (pid, uid, callback) {
- Posts.generatePostPaths([pid], uid, function(err, paths) {
+ Posts.generatePostPaths([pid], uid, function (err, paths) {
callback(err, Array.isArray(paths) && paths.length ? paths[0] : null);
});
};
@@ -57,11 +57,11 @@ module.exports = function(Posts) {
},
function (postData, next) {
async.parallel({
- indices: function(next) {
+ indices: function (next) {
Posts.getPostIndices(postData, uid, next);
},
- topics: function(next) {
- var tids = postData.map(function(post) {
+ topics: function (next) {
+ var tids = postData.map(function (post) {
return post ? post.tid : null;
});
@@ -70,7 +70,7 @@ module.exports = function(Posts) {
}, next);
},
function (results, next) {
- var paths = pids.map(function(pid, index) {
+ var paths = pids.map(function (pid, index) {
var slug = results.topics[index] ? results.topics[index].slug : null;
var postIndex = utils.isNumber(results.indices[index]) ? parseInt(results.indices[index], 10) + 1 : null;
diff --git a/src/posts/user.js b/src/posts/user.js
index db280cb187..9a7fe38893 100644
--- a/src/posts/user.js
+++ b/src/posts/user.js
@@ -8,30 +8,30 @@ var groups = require('../groups');
var meta = require('../meta');
var plugins = require('../plugins');
-module.exports = function(Posts) {
+module.exports = function (Posts) {
- Posts.getUserInfoForPosts = function(uids, uid, callback) {
+ Posts.getUserInfoForPosts = function (uids, uid, callback) {
var groupsMap = {};
var userData;
async.waterfall([
- function(next) {
+ function (next) {
user.getUsersFields(uids, ['uid', 'username', 'fullname', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned', 'status', 'lastonline', 'groupTitle'], next);
},
- function(_userData, next) {
+ function (_userData, next) {
userData = _userData;
- var groupTitles = userData.map(function(userData) {
+ var groupTitles = userData.map(function (userData) {
return userData && userData.groupTitle;
- }).filter(function(groupTitle, index, array) {
+ }).filter(function (groupTitle, index, array) {
return groupTitle && array.indexOf(groupTitle) === index;
});
groups.getGroupsData(groupTitles, next);
}
- ], function(err, groupsData) {
+ ], function (err, groupsData) {
if (err) {
return callback(err);
}
- groupsData.forEach(function(group) {
+ groupsData.forEach(function (group) {
if (group && group.userTitleEnabled) {
groupsMap[group.name] = {
name: group.name,
@@ -43,7 +43,7 @@ module.exports = function(Posts) {
}
});
- userData.forEach(function(userData) {
+ userData.forEach(function (userData) {
userData.uid = userData.uid || 0;
userData.username = userData.username || '[[global:guest]]';
userData.userslug = userData.userslug || '';
@@ -56,7 +56,7 @@ module.exports = function(Posts) {
userData.fullname = validator.escape(String(userData.fullname || ''));
});
- async.map(userData, function(userData, next) {
+ async.map(userData, function (userData, next) {
async.parallel({
isMemberOfGroup: function (next) {
if (!userData.groupTitle || !groupsMap[userData.groupTitle]) {
@@ -64,17 +64,17 @@ module.exports = function(Posts) {
}
groups.isMember(userData.uid, userData.groupTitle, next);
},
- signature: function(next) {
+ signature: function (next) {
if (!userData.signature || parseInt(meta.config.disableSignatures, 10) === 1) {
userData.signature = '';
return next();
}
Posts.parseSignature(userData, uid, next);
},
- customProfileInfo: function(next) {
+ customProfileInfo: function (next) {
plugins.fireHook('filter:posts.custom_profile_info', {profile: [], uid: userData.uid}, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return next(err);
}
@@ -92,17 +92,17 @@ module.exports = function(Posts) {
});
};
- Posts.isOwner = function(pid, uid, callback) {
+ Posts.isOwner = function (pid, uid, callback) {
uid = parseInt(uid, 10);
if (Array.isArray(pid)) {
if (!uid) {
- return callback(null, pid.map(function() {return false;}));
+ return callback(null, pid.map(function () {return false;}));
}
- Posts.getPostsFields(pid, ['uid'], function(err, posts) {
+ Posts.getPostsFields(pid, ['uid'], function (err, posts) {
if (err) {
return callback(err);
}
- posts = posts.map(function(post) {
+ posts = posts.map(function (post) {
return post && parseInt(post.uid, 10) === uid;
});
callback(null, posts);
@@ -111,17 +111,17 @@ module.exports = function(Posts) {
if (!uid) {
return callback(null, false);
}
- Posts.getPostField(pid, 'uid', function(err, author) {
+ Posts.getPostField(pid, 'uid', function (err, author) {
callback(err, parseInt(author, 10) === uid);
});
}
};
- Posts.isModerator = function(pids, uid, callback) {
+ Posts.isModerator = function (pids, uid, callback) {
if (!parseInt(uid, 10)) {
- return callback(null, pids.map(function() {return false;}));
+ return callback(null, pids.map(function () {return false;}));
}
- Posts.getCidsByPids(pids, function(err, cids) {
+ Posts.getCidsByPids(pids, function (err, cids) {
if (err) {
return callback(err);
}
diff --git a/src/posts/votes.js b/src/posts/votes.js
index 30b31fe758..428685257a 100644
--- a/src/posts/votes.js
+++ b/src/posts/votes.js
@@ -7,11 +7,11 @@ var db = require('../database');
var user = require('../user');
var plugins = require('../plugins');
-module.exports = function(Posts) {
+module.exports = function (Posts) {
var votesInProgress = {};
- Posts.upvote = function(pid, uid, callback) {
+ Posts.upvote = function (pid, uid, callback) {
if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
return callback(new Error('[[error:reputation-system-disabled]]'));
}
@@ -22,13 +22,13 @@ module.exports = function(Posts) {
putVoteInProgress(pid, uid);
- toggleVote('upvote', pid, uid, function(err, data) {
+ toggleVote('upvote', pid, uid, function (err, data) {
clearVoteProgress(pid, uid);
callback(err, data);
});
};
- Posts.downvote = function(pid, uid, callback) {
+ Posts.downvote = function (pid, uid, callback) {
if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
return callback(new Error('[[error:reputation-system-disabled]]'));
}
@@ -43,31 +43,31 @@ module.exports = function(Posts) {
putVoteInProgress(pid, uid);
- toggleVote('downvote', pid, uid, function(err, data) {
+ toggleVote('downvote', pid, uid, function (err, data) {
clearVoteProgress(pid, uid);
callback(err, data);
});
};
- Posts.unvote = function(pid, uid, callback) {
+ Posts.unvote = function (pid, uid, callback) {
if (voteInProgress(pid, uid)) {
return callback(new Error('[[error:already-voting-for-this-post]]'));
}
putVoteInProgress(pid, uid);
- unvote(pid, uid, 'unvote', function(err, data) {
+ unvote(pid, uid, 'unvote', function (err, data) {
clearVoteProgress(pid, uid);
callback(err, data);
});
};
- Posts.hasVoted = function(pid, uid, callback) {
+ Posts.hasVoted = function (pid, uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null, {upvoted: false, downvoted: false});
}
- db.isMemberOfSets(['pid:' + pid + ':upvote', 'pid:' + pid + ':downvote'], uid, function(err, hasVoted) {
+ db.isMemberOfSets(['pid:' + pid + ':upvote', 'pid:' + pid + ':downvote'], uid, function (err, hasVoted) {
if (err) {
return callback(err);
}
@@ -76,9 +76,9 @@ module.exports = function(Posts) {
});
};
- Posts.getVoteStatusByPostIDs = function(pids, uid, callback) {
+ Posts.getVoteStatusByPostIDs = function (pids, uid, callback) {
if (!parseInt(uid, 10)) {
- var data = pids.map(function() { return false; });
+ var data = pids.map(function () { return false; });
return callback(null, {upvotes: data, downvotes: data});
}
var upvoteSets = [];
@@ -90,17 +90,17 @@ module.exports = function(Posts) {
}
async.parallel({
- upvotes: function(next) {
+ upvotes: function (next) {
db.isMemberOfSets(upvoteSets, uid, next);
},
- downvotes: function(next) {
+ downvotes: function (next) {
db.isMemberOfSets(downvoteSets, uid, next);
}
}, callback);
};
- Posts.getUpvotedUidsByPids = function(pids, callback) {
- var sets = pids.map(function(pid) {
+ Posts.getUpvotedUidsByPids = function (pids, callback) {
+ var sets = pids.map(function (pid) {
return 'pid:' + pid + ':upvote';
});
db.getSetsMembers(sets, callback);
@@ -125,7 +125,7 @@ module.exports = function(Posts) {
}
function toggleVote(type, pid, uid, callback) {
- unvote(pid, uid, type, function(err) {
+ unvote(pid, uid, type, function (err) {
if (err) {
return callback(err);
}
@@ -136,16 +136,16 @@ module.exports = function(Posts) {
function unvote(pid, uid, command, callback) {
async.parallel({
- owner: function(next) {
+ owner: function (next) {
Posts.getPostField(pid, 'uid', next);
},
- voteStatus: function(next) {
+ voteStatus: function (next) {
Posts.hasVoted(pid, uid, next);
},
- reputation: function(next) {
+ reputation: function (next) {
user.getUserField(uid, 'reputation', next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -221,7 +221,7 @@ module.exports = function(Posts) {
db.sortedSetAdd('users:reputation', newreputation, postData.uid);
}
- adjustPostVotes(postData, uid, type, unvote, function(err) {
+ adjustPostVotes(postData, uid, type, unvote, function (err) {
callback(err, {
user: {
reputation: newreputation
@@ -239,29 +239,29 @@ module.exports = function(Posts) {
var notType = (type === 'upvote' ? 'downvote' : 'upvote');
async.series([
- function(next) {
+ function (next) {
if (unvote) {
db.setRemove('pid:' + postData.pid + ':' + type, uid, next);
} else {
db.setAdd('pid:' + postData.pid + ':' + type, uid, next);
}
},
- function(next) {
+ function (next) {
db.setRemove('pid:' + postData.pid + ':' + notType, uid, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
async.parallel({
- upvotes: function(next) {
+ upvotes: function (next) {
db.setCount('pid:' + postData.pid + ':upvote', next);
},
- downvotes: function(next) {
+ downvotes: function (next) {
db.setCount('pid:' + postData.pid + ':downvote', next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
diff --git a/src/privileges/categories.js b/src/privileges/categories.js
index 7b02a685e4..717551e99f 100644
--- a/src/privileges/categories.js
+++ b/src/privileges/categories.js
@@ -10,11 +10,11 @@ var groups = require('../groups');
var helpers = require('./helpers');
var plugins = require('../plugins');
-module.exports = function(privileges) {
+module.exports = function (privileges) {
privileges.categories = {};
- privileges.categories.list = function(cid, callback) {
+ privileges.categories.list = function (cid, callback) {
// Method used in admin/category controller to show all users/groups with privs in that given cid
var privilegeLabels = [
@@ -33,38 +33,38 @@ module.exports = function(privileges) {
];
async.parallel({
- labels: function(next) {
+ labels: function (next) {
async.parallel({
users: async.apply(plugins.fireHook, 'filter:privileges.list_human', privilegeLabels),
groups: async.apply(plugins.fireHook, 'filter:privileges.groups.list_human', privilegeLabels)
}, next);
},
- users: function(next) {
+ users: function (next) {
var userPrivileges;
async.waterfall([
async.apply(plugins.fireHook, 'filter:privileges.list', privileges.userPrivilegeList),
- function(_privs, next) {
+ function (_privs, next) {
userPrivileges = _privs;
- groups.getMembersOfGroups(userPrivileges.map(function(privilege) {
+ groups.getMembersOfGroups(userPrivileges.map(function (privilege) {
return 'cid:' + cid + ':privileges:' + privilege;
}), next);
},
- function(memberSets, next) {
+ function (memberSets, next) {
- memberSets = memberSets.map(function(set) {
- return set.map(function(uid) {
+ memberSets = memberSets.map(function (set) {
+ return set.map(function (uid) {
return parseInt(uid, 10);
});
});
var members = _.unique(_.flatten(memberSets));
- user.getUsersFields(members, ['picture', 'username'], function(err, memberData) {
+ user.getUsersFields(members, ['picture', 'username'], function (err, memberData) {
if (err) {
return next(err);
}
- memberData.forEach(function(member) {
+ memberData.forEach(function (member) {
member.privileges = {};
for(var x = 0,numPrivs = userPrivileges.length;x < numPrivs;x++) {
member.privileges[userPrivileges[x]] = memberSets[x].indexOf(parseInt(member.uid, 10)) !== -1;
@@ -76,26 +76,26 @@ module.exports = function(privileges) {
}
], next);
},
- groups: function(next) {
+ groups: function (next) {
var groupPrivileges;
async.waterfall([
async.apply(plugins.fireHook, 'filter:privileges.groups.list', privileges.groupPrivilegeList),
- function(_privs, next) {
+ function (_privs, next) {
groupPrivileges = _privs;
- groups.getMembersOfGroups(groupPrivileges.map(function(privilege) {
+ groups.getMembersOfGroups(groupPrivileges.map(function (privilege) {
return 'cid:' + cid + ':privileges:' + privilege;
}), next);
},
- function(memberSets, next) {
+ function (memberSets, next) {
var uniqueGroups = _.unique(_.flatten(memberSets));
- groups.getGroups('groups:createtime', 0, -1, function(err, groupNames) {
+ groups.getGroups('groups:createtime', 0, -1, function (err, groupNames) {
if (err) {
return next(err);
}
- groupNames = groupNames.filter(function(groupName) {
+ groupNames = groupNames.filter(function (groupName) {
return groupName.indexOf(':privileges:') === -1 && uniqueGroups.indexOf(groupName) !== -1;
});
@@ -114,7 +114,7 @@ module.exports = function(privileges) {
var memberPrivs;
- var memberData = groupNames.map(function(member) {
+ var memberData = groupNames.map(function (member) {
memberPrivs = {};
for(var x = 0,numPrivs = groupPrivileges.length;x < numPrivs;x++) {
@@ -129,10 +129,10 @@ module.exports = function(privileges) {
next(null, memberData);
});
},
- function(memberData, next) {
+ function (memberData, next) {
// Grab privacy info for the groups as well
- async.map(memberData, function(member, next) {
- groups.isPrivate(member.name, function(err, isPrivate) {
+ async.map(memberData, function (member, next) {
+ groups.isPrivate(member.name, function (err, isPrivate) {
if (err) {
return next(err);
}
@@ -144,7 +144,7 @@ module.exports = function(privileges) {
}
], next);
}
- }, function(err, payload) {
+ }, function (err, payload) {
if (err) {
return callback(err);
}
@@ -156,19 +156,19 @@ module.exports = function(privileges) {
});
};
- privileges.categories.get = function(cid, uid, callback) {
+ privileges.categories.get = function (cid, uid, callback) {
var privs = ['topics:create', 'topics:read', 'read'];
async.parallel({
- privileges: function(next) {
+ privileges: function (next) {
helpers.isUserAllowedTo(privs, uid, cid, next);
},
- isAdministrator: function(next) {
+ isAdministrator: function (next) {
user.isAdministrator(uid, next);
},
- isModerator: function(next) {
+ isModerator: function (next) {
user.isModerator(uid, cid, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -188,7 +188,7 @@ module.exports = function(privileges) {
});
};
- privileges.categories.isAdminOrMod = function(cid, uid, callback) {
+ privileges.categories.isAdminOrMod = function (cid, uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null, false);
}
@@ -202,21 +202,21 @@ module.exports = function(privileges) {
], callback);
};
- privileges.categories.isUserAllowedTo = function(privilege, cid, uid, callback) {
+ privileges.categories.isUserAllowedTo = function (privilege, cid, uid, callback) {
if (!cid) {
return callback(null, false);
}
- helpers.isUserAllowedTo(privilege, uid, [cid], function(err, results) {
+ helpers.isUserAllowedTo(privilege, uid, [cid], function (err, results) {
callback(err, Array.isArray(results) && results.length ? results[0] : false);
});
};
- privileges.categories.can = function(privilege, cid, uid, callback) {
+ privileges.categories.can = function (privilege, cid, uid, callback) {
if (!cid) {
return callback(null, false);
}
- categories.getCategoryField(cid, 'disabled', function(err, disabled) {
+ categories.getCategoryField(cid, 'disabled', function (err, disabled) {
if (err) {
return callback(err);
}
@@ -226,36 +226,36 @@ module.exports = function(privileges) {
}
helpers.some([
- function(next) {
- helpers.isUserAllowedTo(privilege, uid, [cid], function(err, results) {
+ function (next) {
+ helpers.isUserAllowedTo(privilege, uid, [cid], function (err, results) {
next(err, Array.isArray(results) && results.length ? results[0] : false);
});
},
- function(next) {
+ function (next) {
user.isModerator(uid, cid, next);
},
- function(next) {
+ function (next) {
user.isAdministrator(uid, next);
}
], callback);
});
};
- privileges.categories.filterCids = function(privilege, cids, uid, callback) {
+ privileges.categories.filterCids = function (privilege, cids, uid, callback) {
if (!Array.isArray(cids) || !cids.length) {
return callback(null, []);
}
- cids = cids.filter(function(cid, index, array) {
+ cids = cids.filter(function (cid, index, array) {
return array.indexOf(cid) === index;
});
- privileges.categories.getBase(privilege, cids, uid, function(err, results) {
+ privileges.categories.getBase(privilege, cids, uid, function (err, results) {
if (err) {
return callback(err);
}
- cids = cids.filter(function(cid, index) {
+ cids = cids.filter(function (cid, index) {
return !results.categories[index].disabled &&
(results.allowedTo[index] || results.isAdmin || results.isModerators[index]);
});
@@ -264,80 +264,80 @@ module.exports = function(privileges) {
});
};
- privileges.categories.getBase = function(privilege, cids, uid, callback) {
+ privileges.categories.getBase = function (privilege, cids, uid, callback) {
async.parallel({
- categories: function(next) {
+ categories: function (next) {
categories.getCategoriesFields(cids, ['disabled'], next);
},
- allowedTo: function(next) {
+ allowedTo: function (next) {
helpers.isUserAllowedTo(privilege, uid, cids, next);
},
- isModerators: function(next) {
+ isModerators: function (next) {
user.isModerator(uid, cids, next);
},
- isAdmin: function(next) {
+ isAdmin: function (next) {
user.isAdministrator(uid, next);
}
}, callback);
};
- privileges.categories.filterUids = function(privilege, cid, uids, callback) {
+ privileges.categories.filterUids = function (privilege, cid, uids, callback) {
if (!uids.length) {
return callback(null, []);
}
- uids = uids.filter(function(uid, index, array) {
+ uids = uids.filter(function (uid, index, array) {
return array.indexOf(uid) === index;
});
async.parallel({
- allowedTo: function(next) {
+ allowedTo: function (next) {
helpers.isUsersAllowedTo(privilege, uids, cid, next);
},
- isModerators: function(next) {
+ isModerators: function (next) {
user.isModerator(uids, cid, next);
},
- isAdmin: function(next) {
+ isAdmin: function (next) {
user.isAdministrator(uids, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
- uids = uids.filter(function(uid, index) {
+ uids = uids.filter(function (uid, index) {
return results.allowedTo[index] || results.isModerators[index] || results.isAdmin[index];
});
callback(null, uids);
});
};
- privileges.categories.give = function(privileges, cid, groupName, callback) {
+ privileges.categories.give = function (privileges, cid, groupName, callback) {
giveOrRescind(groups.join, privileges, cid, groupName, callback);
};
- privileges.categories.rescind = function(privileges, cid, groupName, callback) {
+ privileges.categories.rescind = function (privileges, cid, groupName, callback) {
giveOrRescind(groups.leave, privileges, cid, groupName, callback);
};
function giveOrRescind(method, privileges, cid, groupName, callback) {
- async.each(privileges, function(privilege, next) {
+ async.each(privileges, function (privilege, next) {
method('cid:' + cid + ':privileges:groups:' + privilege, groupName, next);
}, callback);
}
- privileges.categories.canMoveAllTopics = function(currentCid, targetCid, uid, callback) {
+ privileges.categories.canMoveAllTopics = function (currentCid, targetCid, uid, callback) {
async.parallel({
- isAdministrator: function(next) {
+ isAdministrator: function (next) {
user.isAdministrator(uid, next);
},
- moderatorOfCurrent: function(next) {
+ moderatorOfCurrent: function (next) {
user.isModerator(uid, currentCid, next);
},
- moderatorOfTarget: function(next) {
+ moderatorOfTarget: function (next) {
user.isModerator(uid, targetCid, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -346,58 +346,58 @@ module.exports = function(privileges) {
});
};
- privileges.categories.userPrivileges = function(cid, uid, callback) {
+ privileges.categories.userPrivileges = function (cid, uid, callback) {
async.parallel({
find: async.apply(groups.isMember, uid, 'cid:' + cid + ':privileges:find'),
- read: function(next) {
+ read: function (next) {
groups.isMember(uid, 'cid:' + cid + ':privileges:read', next);
},
- 'topics:create': function(next) {
+ 'topics:create': function (next) {
groups.isMember(uid, 'cid:' + cid + ':privileges:topics:create', next);
},
- 'topics:read': function(next) {
+ 'topics:read': function (next) {
groups.isMember(uid, 'cid:' + cid + ':privileges:topics:read', next);
},
- 'topics:reply': function(next) {
+ 'topics:reply': function (next) {
groups.isMember(uid, 'cid:' + cid + ':privileges:topics:reply', next);
},
- 'posts:edit': function(next) {
+ 'posts:edit': function (next) {
groups.isMember(uid, 'cid:' + cid + ':privileges:posts:edit', next);
},
- 'posts:delete': function(next) {
+ 'posts:delete': function (next) {
groups.isMember(uid, 'cid:' + cid + ':privileges:posts:delete', next);
},
- 'topics:delete': function(next) {
+ 'topics:delete': function (next) {
groups.isMember(uid, 'cid:' + cid + ':privileges:topics:delete', next);
},
- mods: function(next) {
+ mods: function (next) {
user.isModerator(uid, cid, next);
}
}, callback);
};
- privileges.categories.groupPrivileges = function(cid, groupName, callback) {
+ privileges.categories.groupPrivileges = function (cid, groupName, callback) {
async.parallel({
'groups:find': async.apply(groups.isMember, groupName, 'cid:' + cid + ':privileges:groups:find'),
- 'groups:read': function(next) {
+ 'groups:read': function (next) {
groups.isMember(groupName, 'cid:' + cid + ':privileges:groups:read', next);
},
- 'groups:topics:create': function(next) {
+ 'groups:topics:create': function (next) {
groups.isMember(groupName, 'cid:' + cid + ':privileges:groups:topics:create', next);
},
- 'groups:topics:reply': function(next) {
+ 'groups:topics:reply': function (next) {
groups.isMember(groupName, 'cid:' + cid + ':privileges:groups:topics:reply', next);
},
- 'groups:posts:edit': function(next) {
+ 'groups:posts:edit': function (next) {
groups.isMember(groupName, 'cid:' + cid + ':privileges:groups:posts:edit', next);
},
- 'groups:posts:delete': function(next) {
+ 'groups:posts:delete': function (next) {
groups.isMember(groupName, 'cid:' + cid + ':privileges:groups:posts:delete', next);
},
- 'groups:topics:delete': function(next) {
+ 'groups:topics:delete': function (next) {
groups.isMember(groupName, 'cid:' + cid + ':privileges:groups:topics:delete', next);
},
- 'groups:topics:read': function(next) {
+ 'groups:topics:read': function (next) {
groups.isMember(groupName, 'cid:' + cid + ':privileges:groups:topics:read', next);
}
}, callback);
diff --git a/src/privileges/helpers.js b/src/privileges/helpers.js
index 76e2147ebe..9df9d8cd7b 100644
--- a/src/privileges/helpers.js
+++ b/src/privileges/helpers.js
@@ -6,17 +6,17 @@ var groups = require('../groups');
var helpers = {};
-helpers.some = function(tasks, callback) {
- async.some(tasks, function(task, next) {
- task(function(err, result) {
+helpers.some = function (tasks, callback) {
+ async.some(tasks, function (task, next) {
+ task(function (err, result) {
next(!err && result);
});
- }, function(result) {
+ }, function (result) {
callback(null, result);
});
};
-helpers.isUserAllowedTo = function(privilege, uid, cid, callback) {
+helpers.isUserAllowedTo = function (privilege, uid, cid, callback) {
if (Array.isArray(privilege) && !Array.isArray(cid)) {
isUserAllowedToPrivileges(privilege, uid, cid, callback);
} else if (Array.isArray(cid) && !Array.isArray(privilege)) {
@@ -38,13 +38,13 @@ function isUserAllowedToCids(privilege, uid, cids, callback) {
}
async.parallel({
- hasUserPrivilege: function(next) {
+ hasUserPrivilege: function (next) {
groups.isMemberOfGroups(uid, userKeys, next);
},
- hasGroupPrivilege: function(next) {
+ hasGroupPrivilege: function (next) {
groups.isMemberOfGroupsList(uid, groupKeys, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -70,13 +70,13 @@ function isUserAllowedToPrivileges(privileges, uid, cid, callback) {
}
async.parallel({
- hasUserPrivilege: function(next) {
+ hasUserPrivilege: function (next) {
groups.isMemberOfGroups(uid, userKeys, next);
},
- hasGroupPrivilege: function(next) {
+ hasGroupPrivilege: function (next) {
groups.isMemberOfGroupsList(uid, groupKeys, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -91,15 +91,15 @@ function isUserAllowedToPrivileges(privileges, uid, cid, callback) {
}
-helpers.isUsersAllowedTo = function(privilege, uids, cid, callback) {
+helpers.isUsersAllowedTo = function (privilege, uids, cid, callback) {
async.parallel({
- hasUserPrivilege: function(next) {
+ hasUserPrivilege: function (next) {
groups.isMembers(uids, 'cid:' + cid + ':privileges:' + privilege, next);
},
- hasGroupPrivilege: function(next) {
+ hasGroupPrivilege: function (next) {
groups.isMembersOfGroupList(uids, 'cid:' + cid + ':privileges:groups:' + privilege, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
diff --git a/src/privileges/posts.js b/src/privileges/posts.js
index 371575619d..99a193e01d 100644
--- a/src/privileges/posts.js
+++ b/src/privileges/posts.js
@@ -10,20 +10,20 @@ var user = require('../user');
var helpers = require('./helpers');
var plugins = require('../plugins');
-module.exports = function(privileges) {
+module.exports = function (privileges) {
privileges.posts = {};
- privileges.posts.get = function(pids, uid, callback) {
+ privileges.posts.get = function (pids, uid, callback) {
if (!Array.isArray(pids) || !pids.length) {
return callback(null, []);
}
async.waterfall([
- function(next) {
+ function (next) {
posts.getCidsByPids(pids, next);
},
- function(cids, next) {
+ function (cids, next) {
async.parallel({
isAdmin: async.apply(user.isAdministrator, uid),
isModerator: async.apply(posts.isModerator, pids, uid),
@@ -33,7 +33,7 @@ module.exports = function(privileges) {
'posts:edit': async.apply(helpers.isUserAllowedTo, 'posts:edit', uid, cids),
}, next);
}
- ], function(err, results) {
+ ], function (err, results) {
if (err) {
return callback(err);
}
@@ -58,8 +58,8 @@ module.exports = function(privileges) {
});
};
- privileges.posts.can = function(privilege, pid, uid, callback) {
- posts.getCidByPid(pid, function(err, cid) {
+ privileges.posts.can = function (privilege, pid, uid, callback) {
+ posts.getCidByPid(pid, function (err, cid) {
if (err) {
return callback(err);
}
@@ -68,7 +68,7 @@ module.exports = function(privileges) {
});
};
- privileges.posts.filter = function(privilege, pids, uid, callback) {
+ privileges.posts.filter = function (privilege, pids, uid, callback) {
if (!Array.isArray(pids) || !pids.length) {
return callback(null, []);
}
@@ -83,28 +83,28 @@ module.exports = function(privileges) {
},
function (_posts, next) {
postData = _posts;
- tids = _posts.map(function(post) {
+ tids = _posts.map(function (post) {
return post && post.tid;
- }).filter(function(tid, index, array) {
+ }).filter(function (tid, index, array) {
return tid && array.indexOf(tid) === index;
});
topics.getTopicsFields(tids, ['deleted', 'cid'], next);
},
function (topicData, next) {
- topicData.forEach(function(topic, index) {
+ topicData.forEach(function (topic, index) {
if (topic) {
tidToTopic[tids[index]] = topic;
}
});
- cids = postData.map(function(post, index) {
+ cids = postData.map(function (post, index) {
if (post) {
post.pid = pids[index];
post.topic = tidToTopic[post.tid];
}
return tidToTopic[post.tid] && tidToTopic[post.tid].cid;
- }).filter(function(cid, index, array) {
+ }).filter(function (cid, index, array) {
return cid && array.indexOf(cid) === index;
});
@@ -113,17 +113,17 @@ module.exports = function(privileges) {
function (results, next) {
var isModOf = {};
- cids = cids.filter(function(cid, index) {
+ cids = cids.filter(function (cid, index) {
isModOf[cid] = results.isModerators[index];
return !results.categories[index].disabled &&
(results.allowedTo[index] || results.isAdmin || results.isModerators[index]);
});
- pids = postData.filter(function(post) {
+ pids = postData.filter(function (post) {
return post.topic && cids.indexOf(post.topic.cid) !== -1 &&
((parseInt(post.topic.deleted, 10) !== 1 && parseInt(post.deleted, 10) !== 1) || results.isAdmin || isModOf[post.cid]);
- }).map(function(post) {
+ }).map(function (post) {
return post.pid;
});
@@ -131,18 +131,18 @@ module.exports = function(privileges) {
privilege: privilege,
uid: uid,
pids: pids
- }, function(err, data) {
+ }, function (err, data) {
next(err, data ? data.pids : null);
});
}
], callback);
};
- privileges.posts.canEdit = function(pid, uid, callback) {
+ privileges.posts.canEdit = function (pid, uid, callback) {
async.parallel({
isEditable: async.apply(isPostEditable, pid, uid),
isAdminOrMod: async.apply(isAdminOrMod, pid, uid)
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -154,13 +154,13 @@ module.exports = function(privileges) {
});
};
- privileges.posts.canDelete = function(pid, uid, callback) {
+ privileges.posts.canDelete = function (pid, uid, callback) {
var postData;
async.waterfall([
- function(next) {
+ function (next) {
posts.getPostFields(pid, ['tid', 'timestamp'], next);
},
- function(_postData, next) {
+ function (_postData, next) {
postData = _postData;
async.parallel({
isAdminOrMod: async.apply(isAdminOrMod, pid, uid),
@@ -169,7 +169,7 @@ module.exports = function(privileges) {
'posts:delete': async.apply(privileges.posts.can, 'posts:delete', pid, uid)
}, next);
}
- ], function(err, results) {
+ ], function (err, results) {
if (err) {
return callback(err);
}
@@ -195,8 +195,8 @@ module.exports = function(privileges) {
});
};
- privileges.posts.canMove = function(pid, uid, callback) {
- posts.isMain(pid, function(err, isMain) {
+ privileges.posts.canMove = function (pid, uid, callback) {
+ posts.isMain(pid, function (err, isMain) {
if (err || isMain) {
return callback(err || new Error('[[error:cant-move-mainpost]]'));
}
@@ -204,7 +204,7 @@ module.exports = function(privileges) {
});
};
- privileges.posts.canPurge = function(pid, uid, callback) {
+ privileges.posts.canPurge = function (pid, uid, callback) {
async.waterfall([
function (next) {
posts.getCidByPid(pid, next);
@@ -225,10 +225,10 @@ module.exports = function(privileges) {
function isPostEditable(pid, uid, callback) {
var tid;
async.waterfall([
- function(next) {
+ function (next) {
posts.getPostFields(pid, ['tid', 'timestamp'], next);
},
- function(postData, next) {
+ function (postData, next) {
tid = postData.tid;
var postEditDuration = parseInt(meta.config.postEditDuration, 10);
if (postEditDuration && Date.now() - parseInt(postData.timestamp, 10) > postEditDuration * 1000) {
@@ -236,7 +236,7 @@ module.exports = function(privileges) {
}
topics.isLocked(postData.tid, next);
},
- function(isLocked, next) {
+ function (isLocked, next) {
if (isLocked) {
return callback(null, {flag: false, message: '[[error:topic-locked]]'});
}
@@ -246,7 +246,7 @@ module.exports = function(privileges) {
edit: async.apply(privileges.posts.can, 'posts:edit', pid, uid)
}, next);
},
- function(result, next) {
+ function (result, next) {
next(null, {flag: result.owner && result.edit, message: '[[error:no-privileges]]'});
}
], callback);
@@ -254,8 +254,8 @@ module.exports = function(privileges) {
function isAdminOrMod(pid, uid, callback) {
helpers.some([
- function(next) {
- posts.getCidByPid(pid, function(err, cid) {
+ function (next) {
+ posts.getCidByPid(pid, function (err, cid) {
if (err || !cid) {
return next(err, false);
}
@@ -263,7 +263,7 @@ module.exports = function(privileges) {
user.isModerator(uid, cid, next);
});
},
- function(next) {
+ function (next) {
user.isAdministrator(uid, next);
}
], callback);
diff --git a/src/privileges/topics.js b/src/privileges/topics.js
index 6530db1dd0..39ad054462 100644
--- a/src/privileges/topics.js
+++ b/src/privileges/topics.js
@@ -11,16 +11,16 @@ var helpers = require('./helpers');
var categories = require('../categories');
var plugins = require('../plugins');
-module.exports = function(privileges) {
+module.exports = function (privileges) {
privileges.topics = {};
- privileges.topics.get = function(tid, uid, callback) {
+ privileges.topics.get = function (tid, uid, callback) {
var topic;
var privs = ['topics:reply', 'topics:read', 'topics:delete', 'posts:edit', 'posts:delete', 'read'];
async.waterfall([
async.apply(topics.getTopicFields, tid, ['cid', 'uid', 'locked', 'deleted']),
- function(_topic, next) {
+ function (_topic, next) {
topic = _topic;
async.parallel({
privileges: async.apply(helpers.isUserAllowedTo, privs, uid, topic.cid),
@@ -29,7 +29,7 @@ module.exports = function(privileges) {
disabled: async.apply(categories.getCategoryField, topic.cid, 'disabled')
}, next);
}
- ], function(err, results) {
+ ], function (err, results) {
if (err) {
return callback(err);
}
@@ -62,8 +62,8 @@ module.exports = function(privileges) {
});
};
- privileges.topics.can = function(privilege, tid, uid, callback) {
- topics.getTopicField(tid, 'cid', function(err, cid) {
+ privileges.topics.can = function (privilege, tid, uid, callback) {
+ topics.getTopicField(tid, 'cid', function (err, cid) {
if (err) {
return callback(err);
}
@@ -72,39 +72,39 @@ module.exports = function(privileges) {
});
};
- privileges.topics.filterTids = function(privilege, tids, uid, callback) {
+ privileges.topics.filterTids = function (privilege, tids, uid, callback) {
if (!Array.isArray(tids) || !tids.length) {
return callback(null, []);
}
var cids;
var topicsData;
async.waterfall([
- function(next) {
+ function (next) {
topics.getTopicsFields(tids, ['tid', 'cid', 'deleted'], next);
},
- function(_topicsData, next) {
+ function (_topicsData, next) {
topicsData = _topicsData;
- cids = topicsData.map(function(topic) {
+ cids = topicsData.map(function (topic) {
return topic.cid;
- }).filter(function(cid, index, array) {
+ }).filter(function (cid, index, array) {
return cid && array.indexOf(cid) === index;
});
privileges.categories.getBase(privilege, cids, uid, next);
},
- function(results, next) {
+ function (results, next) {
var isModOf = {};
- cids = cids.filter(function(cid, index) {
+ cids = cids.filter(function (cid, index) {
isModOf[cid] = results.isModerators[index];
return !results.categories[index].disabled &&
(results.allowedTo[index] || results.isAdmin || results.isModerators[index]);
});
- tids = topicsData.filter(function(topic) {
+ tids = topicsData.filter(function (topic) {
return cids.indexOf(topic.cid) !== -1 &&
(parseInt(topic.deleted, 10) !== 1 || results.isAdmin || isModOf[topic.cid]);
- }).map(function(topic) {
+ }).map(function (topic) {
return topic.tid;
});
@@ -112,46 +112,46 @@ module.exports = function(privileges) {
privilege: privilege,
uid: uid,
tids: tids
- }, function(err, data) {
+ }, function (err, data) {
next(err, data ? data.tids : null);
});
}
], callback);
};
- privileges.topics.filterUids = function(privilege, tid, uids, callback) {
+ privileges.topics.filterUids = function (privilege, tid, uids, callback) {
if (!Array.isArray(uids) || !uids.length) {
return callback(null, []);
}
- uids = uids.filter(function(uid, index, array) {
+ uids = uids.filter(function (uid, index, array) {
return array.indexOf(uid) === index;
});
async.waterfall([
- function(next) {
+ function (next) {
topics.getTopicFields(tid, ['tid', 'cid', 'deleted'], next);
},
- function(topicData, next) {
+ function (topicData, next) {
async.parallel({
- disabled: function(next) {
+ disabled: function (next) {
categories.getCategoryField(topicData.cid, 'disabled', next);
},
- allowedTo: function(next) {
+ allowedTo: function (next) {
helpers.isUsersAllowedTo(privilege, uids, topicData.cid, next);
},
- isModerators: function(next) {
+ isModerators: function (next) {
user.isModerator(uids, topicData.cid, next);
},
- isAdmins: function(next) {
+ isAdmins: function (next) {
user.isAdministrator(uids, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return next(err);
}
- uids = uids.filter(function(uid, index) {
+ uids = uids.filter(function (uid, index) {
return parseInt(results.disabled, 10) !== 1 &&
((results.allowedTo[index] && parseInt(topicData.deleted, 10) !== 1) || results.isAdmins[index] || results.isModerators[index]);
});
@@ -162,7 +162,7 @@ module.exports = function(privileges) {
], callback);
};
- privileges.topics.canPurge = function(tid, uid, callback) {
+ privileges.topics.canPurge = function (tid, uid, callback) {
async.waterfall([
function (next) {
topics.getTopicField(tid, 'cid', next);
@@ -180,13 +180,13 @@ module.exports = function(privileges) {
], callback);
};
- privileges.topics.canDelete = function(tid, uid, callback) {
+ privileges.topics.canDelete = function (tid, uid, callback) {
var topicData;
async.waterfall([
- function(next) {
+ function (next) {
topics.getTopicFields(tid, ['cid', 'postcount'], next);
},
- function(_topicData, next) {
+ function (_topicData, next) {
topicData = _topicData;
async.parallel({
isModerator: async.apply(user.isModerator, uid, topicData.cid),
@@ -195,7 +195,7 @@ module.exports = function(privileges) {
'topics:delete': async.apply(helpers.isUserAllowedTo, 'topics:delete', uid, [topicData.cid])
}, next);
}
- ], function(err, results) {
+ ], function (err, results) {
if (err) {
return callback(err);
}
@@ -220,33 +220,33 @@ module.exports = function(privileges) {
});
};
- privileges.topics.canEdit = function(tid, uid, callback) {
+ privileges.topics.canEdit = function (tid, uid, callback) {
privileges.topics.isOwnerOrAdminOrMod(tid, uid, callback);
};
- privileges.topics.isOwnerOrAdminOrMod = function(tid, uid, callback) {
+ privileges.topics.isOwnerOrAdminOrMod = function (tid, uid, callback) {
helpers.some([
- function(next) {
+ function (next) {
topics.isOwner(tid, uid, next);
},
- function(next) {
+ function (next) {
privileges.topics.isAdminOrMod(tid, uid, next);
}
], callback);
};
- privileges.topics.isAdminOrMod = function(tid, uid, callback) {
+ privileges.topics.isAdminOrMod = function (tid, uid, callback) {
helpers.some([
- function(next) {
- topics.getTopicField(tid, 'cid', function(err, cid) {
+ function (next) {
+ topics.getTopicField(tid, 'cid', function (err, cid) {
if (err) {
return next(err);
}
user.isModerator(uid, cid, next);
});
},
- function(next) {
+ function (next) {
user.isAdministrator(uid, next);
}
], callback);
diff --git a/src/privileges/users.js b/src/privileges/users.js
index e49ca793ae..4f6341be9f 100644
--- a/src/privileges/users.js
+++ b/src/privileges/users.js
@@ -6,11 +6,11 @@ var async = require('async');
var groups = require('../groups');
var plugins = require('../plugins');
-module.exports = function(privileges) {
+module.exports = function (privileges) {
privileges.users = {};
- privileges.users.isAdministrator = function(uid, callback) {
+ privileges.users.isAdministrator = function (uid, callback) {
if (Array.isArray(uid)) {
groups.isMembers(uid, 'administrators', callback);
} else {
@@ -18,7 +18,7 @@ module.exports = function(privileges) {
}
};
- privileges.users.isGlobalModerator = function(uid, callback) {
+ privileges.users.isGlobalModerator = function (uid, callback) {
if (Array.isArray(uid)) {
groups.isMembers(uid, 'Global Moderators', callback);
} else {
@@ -26,7 +26,7 @@ module.exports = function(privileges) {
}
};
- privileges.users.isModerator = function(uid, cid, callback) {
+ privileges.users.isModerator = function (uid, cid, callback) {
if (Array.isArray(cid)) {
isModeratorOfCategories(cid, uid, callback);
} else {
@@ -40,48 +40,48 @@ module.exports = function(privileges) {
function isModeratorOfCategories(cids, uid, callback) {
if (!parseInt(uid, 10)) {
- return filterIsModerator(cids, uid, cids.map(function() {return false;}), callback);
+ return filterIsModerator(cids, uid, cids.map(function () {return false;}), callback);
}
- privileges.users.isGlobalModerator(uid, function(err, isGlobalModerator) {
+ privileges.users.isGlobalModerator(uid, function (err, isGlobalModerator) {
if (err) {
return callback(err);
}
if (isGlobalModerator) {
- return filterIsModerator(cids, uid, cids.map(function() {return true;}), callback);
+ return filterIsModerator(cids, uid, cids.map(function () {return true;}), callback);
}
- var uniqueCids = cids.filter(function(cid, index, array) {
+ var uniqueCids = cids.filter(function (cid, index, array) {
return array.indexOf(cid) === index;
});
- var groupNames = uniqueCids.map(function(cid) {
+ var groupNames = uniqueCids.map(function (cid) {
return 'cid:' + cid + ':privileges:mods'; // At some point we should *probably* change this to "moderate" as well
});
- var groupListNames = uniqueCids.map(function(cid) {
+ var groupListNames = uniqueCids.map(function (cid) {
return 'cid:' + cid + ':privileges:groups:moderate';
});
async.parallel({
user: async.apply(groups.isMemberOfGroups, uid, groupNames),
group: async.apply(groups.isMemberOfGroupsList, uid, groupListNames)
- }, function(err, checks) {
+ }, function (err, checks) {
if (err) {
return callback(err);
}
- var isMembers = checks.user.map(function(isMember, idx) {
+ var isMembers = checks.user.map(function (isMember, idx) {
return isMember || checks.group[idx];
}),
map = {};
- uniqueCids.forEach(function(cid, index) {
+ uniqueCids.forEach(function (cid, index) {
map[cid] = isMembers[index];
});
- var isModerator = cids.map(function(cid) {
+ var isModerator = cids.map(function (cid) {
return map[cid];
});
@@ -95,12 +95,12 @@ module.exports = function(privileges) {
async.apply(privileges.users.isGlobalModerator, uids),
async.apply(groups.isMembers, uids, 'cid:' + cid + ':privileges:mods'),
async.apply(groups.isMembersOfGroupList, uids, 'cid:' + cid + ':privileges:groups:moderate')
- ], function(err, checks) {
+ ], function (err, checks) {
if (err) {
return callback(err);
}
- var isModerator = checks[0].map(function(isMember, idx) {
+ var isModerator = checks[0].map(function (isMember, idx) {
return isMember || checks[1][idx] || checks[2][idx];
});
@@ -113,7 +113,7 @@ module.exports = function(privileges) {
async.apply(privileges.users.isGlobalModerator, uid),
async.apply(groups.isMember, uid, 'cid:' + cid + ':privileges:mods'),
async.apply(groups.isMemberOfGroupList, uid, 'cid:' + cid + ':privileges:groups:moderate')
- ], function(err, checks) {
+ ], function (err, checks) {
if (err) {
return callback(err);
}
@@ -124,7 +124,7 @@ module.exports = function(privileges) {
}
function filterIsModerator(cid, uid, isModerator, callback) {
- plugins.fireHook('filter:user.isModerator', {uid: uid, cid: cid, isModerator: isModerator}, function(err, data) {
+ plugins.fireHook('filter:user.isModerator', {uid: uid, cid: cid, isModerator: isModerator}, function (err, data) {
if (err) {
return callback(err);
}
diff --git a/src/pubsub.js b/src/pubsub.js
index 82414a5c31..a2e11746e1 100644
--- a/src/pubsub.js
+++ b/src/pubsub.js
@@ -8,7 +8,7 @@ var nconf = require('nconf'),
var channelName;
-var PubSub = function() {
+var PubSub = function () {
var self = this;
if (nconf.get('redis')) {
var redis = require('./database/redis');
@@ -18,7 +18,7 @@ var PubSub = function() {
channelName = 'db:' + nconf.get('redis:database') + 'pubsub_channel';
subClient.subscribe(channelName);
- subClient.on('message', function(channel, message) {
+ subClient.on('message', function (channel, message) {
if (channel !== channelName) {
return;
}
@@ -35,7 +35,7 @@ var PubSub = function() {
util.inherits(PubSub, EventEmitter);
-PubSub.prototype.publish = function(event, data) {
+PubSub.prototype.publish = function (event, data) {
if (this.pubClient) {
this.pubClient.publish(channelName, JSON.stringify({event: event, data: data}));
} else {
diff --git a/src/reset.js b/src/reset.js
index 56669b6e2d..f38a2be4fd 100644
--- a/src/reset.js
+++ b/src/reset.js
@@ -8,8 +8,8 @@ var db = require('./database');
var Reset = {};
-Reset.reset = function() {
- db.init(function(err) {
+Reset.reset = function () {
+ db.init(function (err) {
if (err) {
winston.error(err.message);
process.exit();
@@ -32,7 +32,7 @@ Reset.reset = function() {
} else if (nconf.get('s')) {
resetSettings();
} else if (nconf.get('a')) {
- require('async').series([resetWidgets, resetThemes, resetPlugins, resetSettings], function(err) {
+ require('async').series([resetWidgets, resetThemes, resetPlugins, resetSettings], function (err) {
if (!err) {
winston.info('[reset] Reset complete.');
} else {
@@ -59,7 +59,7 @@ Reset.reset = function() {
function resetSettings(callback) {
var meta = require('./meta');
- meta.configs.set('allowLocalLogin', 1, function(err) {
+ meta.configs.set('allowLocalLogin', 1, function (err) {
winston.info('[reset] Settings reset to default');
if (typeof callback === 'function') {
callback(err);
@@ -73,7 +73,7 @@ function resetTheme(themeId) {
var meta = require('./meta');
var fs = require('fs');
- fs.access('node_modules/' + themeId + '/package.json', function(err, fd) {
+ fs.access('node_modules/' + themeId + '/package.json', function (err, fd) {
if (err) {
winston.warn('[reset] Theme `%s` is not installed on this forum', themeId);
process.exit();
@@ -81,7 +81,7 @@ function resetTheme(themeId) {
meta.themes.set({
type: 'local',
id: themeId
- }, function(err) {
+ }, function (err) {
if (err) {
winston.warn('[reset] Failed to reset theme to ' + themeId);
} else {
@@ -100,7 +100,7 @@ function resetThemes(callback) {
meta.themes.set({
type: 'local',
id: 'nodebb-theme-persona'
- }, function(err) {
+ }, function (err) {
winston.info('[reset] Theme reset to Persona');
if (typeof callback === 'function') {
callback(err);
@@ -115,7 +115,7 @@ function resetPlugin(pluginId) {
async.waterfall([
async.apply(db.isSortedSetMember, 'plugins:active', pluginId),
- function(isMember, next) {
+ function (isMember, next) {
active = isMember;
if (isMember) {
@@ -124,7 +124,7 @@ function resetPlugin(pluginId) {
next();
}
}
- ], function(err) {
+ ], function (err) {
if (err) {
winston.error('[reset] Could not disable plugin: %s encountered error %s', pluginId, err.message);
} else {
@@ -141,7 +141,7 @@ function resetPlugin(pluginId) {
}
function resetPlugins(callback) {
- db.delete('plugins:active', function(err) {
+ db.delete('plugins:active', function (err) {
winston.info('[reset] All Plugins De-activated');
if (typeof callback === 'function') {
callback(err);
@@ -152,7 +152,7 @@ function resetPlugins(callback) {
}
function resetWidgets(callback) {
- require('./widgets').reset(function(err) {
+ require('./widgets').reset(function (err) {
winston.info('[reset] All Widgets moved to Draft Zone');
if (typeof callback === 'function') {
callback(err);
diff --git a/src/rewards/admin.js b/src/rewards/admin.js
index 0bde13ac00..fcfacf5877 100644
--- a/src/rewards/admin.js
+++ b/src/rewards/admin.js
@@ -6,7 +6,7 @@ var rewards = {},
db = require('../database');
-rewards.save = function(data, callback) {
+rewards.save = function (data, callback) {
function save(data, next) {
function commit(err, id) {
if (err) {
@@ -16,16 +16,16 @@ rewards.save = function(data, callback) {
data.id = id;
async.series([
- function(next) {
+ function (next) {
rewards.delete(data, next);
},
- function(next) {
+ function (next) {
db.setAdd('rewards:list', data.id, next);
},
- function(next) {
+ function (next) {
db.setObject('rewards:id:' + data.id, data, next);
},
- function(next) {
+ function (next) {
db.setObject('rewards:id:' + data.id + ':rewards', rewardsData, next);
}
], next);
@@ -45,7 +45,7 @@ rewards.save = function(data, callback) {
}
}
- async.each(data, save, function(err) {
+ async.each(data, save, function (err) {
if (err) {
return callback(err);
}
@@ -54,37 +54,37 @@ rewards.save = function(data, callback) {
});
};
-rewards.delete = function(data, callback) {
+rewards.delete = function (data, callback) {
async.parallel([
- function(next) {
+ function (next) {
db.setRemove('rewards:list', data.id, next);
},
- function(next) {
+ function (next) {
db.delete('rewards:id:' + data.id, next);
},
- function(next) {
+ function (next) {
db.delete('rewards:id:' + data.id + ':rewards', next);
}
], callback);
};
-rewards.get = function(callback) {
+rewards.get = function (callback) {
async.parallel({
active: getActiveRewards,
- conditions: function(next) {
+ conditions: function (next) {
plugins.fireHook('filter:rewards.conditions', [], next);
},
- conditionals: function(next) {
+ conditionals: function (next) {
plugins.fireHook('filter:rewards.conditionals', [], next);
},
- rewards: function(next) {
+ rewards: function (next) {
plugins.fireHook('filter:rewards.rewards', [], next);
}
}, callback);
};
function saveConditions(data, callback) {
- db.delete('conditions:active', function(err) {
+ db.delete('conditions:active', function (err) {
if (err) {
return callback(err);
}
@@ -92,7 +92,7 @@ function saveConditions(data, callback) {
var conditions = [],
rewardsPerCondition = {};
- data.forEach(function(reward) {
+ data.forEach(function (reward) {
conditions.push(reward.condition);
rewardsPerCondition[reward.condition] = rewardsPerCondition[reward.condition] || [];
rewardsPerCondition[reward.condition].push(reward.id);
@@ -100,7 +100,7 @@ function saveConditions(data, callback) {
db.setAdd('conditions:active', conditions, callback);
- async.each(Object.keys(rewardsPerCondition), function(condition, next) {
+ async.each(Object.keys(rewardsPerCondition), function (condition, next) {
db.setAdd('condition:' + condition + ':rewards', rewardsPerCondition[condition], next);
}, callback);
});
@@ -111,13 +111,13 @@ function getActiveRewards(callback) {
function load(id, next) {
async.parallel({
- main: function(next) {
+ main: function (next) {
db.getObject('rewards:id:' + id, next);
},
- rewards: function(next) {
+ rewards: function (next) {
db.getObject('rewards:id:' + id + ':rewards', next);
}
- }, function(err, data) {
+ }, function (err, data) {
if (data.main) {
data.main.disabled = data.main.disabled === 'true';
data.main.rewards = data.rewards;
@@ -128,12 +128,12 @@ function getActiveRewards(callback) {
});
}
- db.getSetMembers('rewards:list', function(err, rewards) {
+ db.getSetMembers('rewards:list', function (err, rewards) {
if (err) {
return callback(err);
}
- async.eachSeries(rewards, load, function(err) {
+ async.eachSeries(rewards, load, function (err) {
callback(err, activeRewards);
});
});
diff --git a/src/rewards/index.js b/src/rewards/index.js
index bbccab69f3..4ba403fce8 100644
--- a/src/rewards/index.js
+++ b/src/rewards/index.js
@@ -6,10 +6,10 @@ var rewards = {},
async = require('async');
-rewards.checkConditionAndRewardUser = function(uid, condition, method, callback) {
+rewards.checkConditionAndRewardUser = function (uid, condition, method, callback) {
async.waterfall([
- function(next) {
- isConditionActive(condition, function(err, isActive) {
+ function (next) {
+ isConditionActive(condition, function (err, isActive) {
if (!isActive) {
return back(err);
}
@@ -17,16 +17,16 @@ rewards.checkConditionAndRewardUser = function(uid, condition, method, callback)
next(err);
});
},
- function(next) {
- getIDsByCondition(condition, function(err, ids) {
+ function (next) {
+ getIDsByCondition(condition, function (err, ids) {
next(err, ids);
});
},
- function(ids, next) {
+ function (ids, next) {
getRewardDataByIDs(ids, next);
},
- function(rewards, next) {
- filterCompletedRewards(uid, rewards, function(err, filtered) {
+ function (rewards, next) {
+ filterCompletedRewards(uid, rewards, function (err, filtered) {
if (!filtered || !filtered.length) {
return back(err);
}
@@ -34,14 +34,14 @@ rewards.checkConditionAndRewardUser = function(uid, condition, method, callback)
next(err, filtered);
});
},
- function(rewards, next) {
- async.filter(rewards, function(reward, next) {
+ function (rewards, next) {
+ async.filter(rewards, function (reward, next) {
if (!reward) {
return next(false);
}
checkCondition(reward, method, next);
- }, function(eligible) {
+ }, function (eligible) {
if (!eligible) {
return next(false);
}
@@ -68,18 +68,18 @@ function getIDsByCondition(condition, callback) {
}
function filterCompletedRewards(uid, rewards, callback) {
- db.getSortedSetRangeByScoreWithScores('uid:' + uid + ':rewards', 0, -1, 1, '+inf', function(err, data) {
+ db.getSortedSetRangeByScoreWithScores('uid:' + uid + ':rewards', 0, -1, 1, '+inf', function (err, data) {
if (err) {
return callback(err);
}
var userRewards = {};
- data.forEach(function(obj) {
+ data.forEach(function (obj) {
userRewards[obj.value] = parseInt(obj.score, 10);
});
- rewards = rewards.filter(function(reward) {
+ rewards = rewards.filter(function (reward) {
if (!reward) {
return false;
}
@@ -98,36 +98,36 @@ function filterCompletedRewards(uid, rewards, callback) {
}
function getRewardDataByIDs(ids, callback) {
- db.getObjects(ids.map(function(id) {
+ db.getObjects(ids.map(function (id) {
return 'rewards:id:' + id;
}), callback);
}
function getRewardsByRewardData(rewards, callback) {
- db.getObjects(rewards.map(function(reward) {
+ db.getObjects(rewards.map(function (reward) {
return 'rewards:id:' + reward.id + ':rewards';
}), callback);
}
function checkCondition(reward, method, callback) {
- method(function(err, value) {
+ method(function (err, value) {
if (err) {
return callback(err);
}
- plugins.fireHook('filter:rewards.checkConditional:' + reward.conditional, {left: value, right: reward.value}, function(err, bool) {
+ plugins.fireHook('filter:rewards.checkConditional:' + reward.conditional, {left: value, right: reward.value}, function (err, bool) {
callback(err || bool);
});
});
}
function giveRewards(uid, rewards, callback) {
- getRewardsByRewardData(rewards, function(err, rewardData) {
+ getRewardsByRewardData(rewards, function (err, rewardData) {
if (err) {
return callback(err);
}
- async.each(rewards, function(reward, next) {
+ async.each(rewards, function (reward, next) {
plugins.fireHook('action:rewards.award:' + reward.rid, {uid: uid, reward: rewardData[rewards.indexOf(reward)]});
db.sortedSetIncrBy('uid:' + uid + ':rewards', 1, reward.id, next);
}, callback);
diff --git a/src/routes/admin.js b/src/routes/admin.js
index b84e744685..7d7029482c 100644
--- a/src/routes/admin.js
+++ b/src/routes/admin.js
@@ -91,7 +91,7 @@ function addRoutes(router, middleware, controllers) {
router.get('/development/info', middlewares, controllers.admin.info.get);
}
-module.exports = function(app, middleware, controllers) {
+module.exports = function (app, middleware, controllers) {
app.use('/admin/', adminRouter(middleware, controllers));
app.use('/api/admin/', apiRouter(middleware, controllers));
};
diff --git a/src/routes/api.js b/src/routes/api.js
index 3313edbe57..be76336c77 100644
--- a/src/routes/api.js
+++ b/src/routes/api.js
@@ -4,7 +4,7 @@ var express = require('express');
var uploadsController = require('../controllers/uploads');
-module.exports = function(app, middleware, controllers) {
+module.exports = function (app, middleware, controllers) {
var router = express.Router();
app.use('/api', router);
diff --git a/src/routes/authentication.js b/src/routes/authentication.js
index d8561f2528..c6f1359fc2 100644
--- a/src/routes/authentication.js
+++ b/src/routes/authentication.js
@@ -1,4 +1,4 @@
-(function(Auth) {
+(function (Auth) {
"use strict";
var passport = require('passport'),
@@ -13,11 +13,11 @@
loginStrategies = [];
- Auth.initialize = function(app, middleware) {
+ Auth.initialize = function (app, middleware) {
app.use(passport.initialize());
app.use(passport.session());
- app.use(function(req, res, next) {
+ app.use(function (req, res, next) {
req.uid = req.user ? parseInt(req.user.uid, 10) : 0;
next();
});
@@ -26,11 +26,11 @@
Auth.middleware = middleware;
};
- Auth.getLoginStrategies = function() {
+ Auth.getLoginStrategies = function () {
return loginStrategies;
};
- Auth.reloadRoutes = function(callback) {
+ Auth.reloadRoutes = function (callback) {
var router = express.Router();
router.hotswapId = 'auth';
@@ -43,13 +43,13 @@
passport.use(new passportLocal({passReqToCallback: true}, controllers.authentication.localLogin));
}
- plugins.fireHook('filter:auth.init', loginStrategies, function(err) {
+ plugins.fireHook('filter:auth.init', loginStrategies, function (err) {
if (err) {
winston.error('filter:auth.init - plugin failure');
return callback(err);
}
- loginStrategies.forEach(function(strategy) {
+ loginStrategies.forEach(function (strategy) {
if (strategy.url) {
router.get(strategy.url, passport.authenticate(strategy.name, {
scope: strategy.scope,
@@ -76,11 +76,11 @@
});
};
- passport.serializeUser(function(user, done) {
+ passport.serializeUser(function (user, done) {
done(null, user.uid);
});
- passport.deserializeUser(function(uid, done) {
+ passport.deserializeUser(function (uid, done) {
done(null, {
uid: uid
});
diff --git a/src/routes/debug.js b/src/routes/debug.js
index 87c536c4c6..9c5efe6c93 100644
--- a/src/routes/debug.js
+++ b/src/routes/debug.js
@@ -9,7 +9,7 @@ var topics = require('../topics');
var posts = require('../posts');
var db = require('../database');
-module.exports = function(app, middleware, controllers) {
+module.exports = function (app, middleware, controllers) {
var router = express.Router();
router.get('/uid/:uid', function (req, res) {
@@ -74,7 +74,7 @@ module.exports = function(app, middleware, controllers) {
});
});
- router.get('/test', function(req, res) {
+ router.get('/test', function (req, res) {
res.redirect(404);
});
diff --git a/src/routes/feeds.js b/src/routes/feeds.js
index 721a34cffc..259898fdd2 100644
--- a/src/routes/feeds.js
+++ b/src/routes/feeds.js
@@ -23,10 +23,10 @@ function generateForTopic(req, res, callback) {
async.waterfall([
function (next) {
async.parallel({
- privileges: function(next) {
+ privileges: function (next) {
privileges.topics.get(tid, req.uid, next);
},
- topic: function(next) {
+ topic: function (next) {
topics.getTopicData(tid, next);
}
}, next);
@@ -44,7 +44,7 @@ function generateForTopic(req, res, callback) {
userPrivileges = results.privileges;
topics.getTopicWithPosts(results.topic, 'tid:' + tid + ':posts', req.uid, 0, 25, false, next);
}
- ], function(err, topicData) {
+ ], function (err, topicData) {
if (err) {
return callback(err);
}
@@ -70,7 +70,7 @@ function generateForTopic(req, res, callback) {
feed.pubDate = new Date(parseInt(topicData.posts[0].timestamp, 10)).toUTCString();
}
- topicData.posts.forEach(function(postData) {
+ topicData.posts.forEach(function (postData) {
if (!postData.deleted) {
dateStamp = new Date(parseInt(parseInt(postData.edited, 10) === 0 ? postData.timestamp : postData.edited, 10)).toUTCString();
@@ -105,7 +105,7 @@ function generateForUserTopics(req, res, callback) {
}
user.getUserFields(uid, ['uid', 'username'], next);
}
- ], function(err, userData) {
+ ], function (err, userData) {
if (err) {
return callback(err);
}
@@ -129,10 +129,10 @@ function generateForCategory(req, res, next) {
async.waterfall([
function (next) {
async.parallel({
- privileges: function(next) {
+ privileges: function (next) {
privileges.categories.get(cid, req.uid, next);
},
- category: function(next) {
+ category: function (next) {
categories.getCategoryById({
cid: cid,
set: 'cid:' + cid + ':tids',
@@ -156,7 +156,7 @@ function generateForCategory(req, res, next) {
site_url: '/category/' + results.category.cid,
}, results.category.topics, next);
}
- ], function(err, feed) {
+ ], function (err, feed) {
if (err) {
return next(err);
}
@@ -189,7 +189,7 @@ function generateForPopular(req, res, next) {
};
var term = terms[req.params.term] || 'day';
- topics.getPopular(term, req.uid, 19, function(err, topics) {
+ topics.getPopular(term, req.uid, 19, function (err, topics) {
if (err) {
return next(err);
}
@@ -200,7 +200,7 @@ function generateForPopular(req, res, next) {
description: 'A list of topics that are sorted by post count',
feed_url: '/popular/' + (req.params.term || 'daily') + '.rss',
site_url: '/popular/' + (req.params.term || 'daily')
- }, topics, function(err, feed) {
+ }, topics, function (err, feed) {
if (err) {
return next(err);
}
@@ -215,7 +215,7 @@ function generateForTopics(options, set, req, res, next) {
return next(err);
}
- generateTopicsFeed(options, data.topics, function(err, feed) {
+ generateTopicsFeed(options, data.topics, function (err, feed) {
if (err) {
return next(err);
}
@@ -238,7 +238,7 @@ function generateTopicsFeed(feedOptions, feedTopics, callback) {
feed.pubDate = new Date(parseInt(feedTopics[0].lastposttime, 10)).toUTCString();
}
- async.map(feedTopics, function(topicData, next) {
+ async.map(feedTopics, function (topicData, next) {
var feedItem = {
title: topicData.title,
url: nconf.get('url') + '/topic/' + topicData.slug,
@@ -251,7 +251,7 @@ function generateTopicsFeed(feedOptions, feedTopics, callback) {
return next(null, feedItem);
}
- topics.getMainPost(topicData.tid, feedOptions.uid, function(err, mainPost) {
+ topics.getMainPost(topicData.tid, feedOptions.uid, function (err, mainPost) {
if (err) {
return next(err);
}
@@ -262,11 +262,11 @@ function generateTopicsFeed(feedOptions, feedTopics, callback) {
feedItem.author = mainPost.user.username;
next(null, feedItem);
});
- }, function(err, feedItems) {
+ }, function (err, feedItems) {
if (err) {
return callback(err);
}
- feedItems.forEach(function(feedItem) {
+ feedItems.forEach(function (feedItem) {
if (feedItem) {
feed.item(feedItem);
}
@@ -280,7 +280,7 @@ function generateForRecentPosts(req, res, next) {
return next();
}
- posts.getRecentPosts(req.uid, 0, 19, 'month', function(err, posts) {
+ posts.getRecentPosts(req.uid, 0, 19, 'month', function (err, posts) {
if (err) {
return next(err);
}
@@ -303,16 +303,16 @@ function generateForCategoryRecentPosts(req, res, next) {
var cid = req.params.category_id;
async.parallel({
- privileges: function(next) {
+ privileges: function (next) {
privileges.categories.get(cid, req.uid, next);
},
- category: function(next) {
+ category: function (next) {
categories.getCategoryData(cid, next);
},
- posts: function(next) {
+ posts: function (next) {
categories.getRecentReplies(cid, req.uid, 20, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return next(err);
}
@@ -346,7 +346,7 @@ function generateForPostsFeed(feedOptions, posts) {
feed.pubDate = new Date(parseInt(posts[0].timestamp, 10)).toUTCString();
}
- posts.forEach(function(postData) {
+ posts.forEach(function (postData) {
feed.item({
title: postData.topic ? postData.topic.title : '',
description: postData.content,
@@ -364,7 +364,7 @@ function sendFeed(feed, res) {
res.type('xml').set('Content-Length', Buffer.byteLength(xml)).send(xml);
}
-module.exports = function(app, middleware, controllers){
+module.exports = function (app, middleware, controllers){
app.get('/topic/:topic_id.rss', generateForTopic);
app.get('/category/:category_id.rss', generateForCategory);
app.get('/recent.rss', generateForRecent);
diff --git a/src/routes/helpers.js b/src/routes/helpers.js
index 378e2bdbc8..052d99292c 100644
--- a/src/routes/helpers.js
+++ b/src/routes/helpers.js
@@ -2,7 +2,7 @@
var helpers = {};
-helpers.setupPageRoute = function(router, name, middleware, middlewares, controller) {
+helpers.setupPageRoute = function (router, name, middleware, middlewares, controller) {
middlewares = middlewares.concat([middleware.registrationComplete, middleware.pageView, middleware.pluginHooks]);
router.get(name, middleware.busyCheck, middleware.buildHeader, middlewares, controller);
diff --git a/src/routes/index.js b/src/routes/index.js
index 3ef899d4df..218cf75693 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -81,7 +81,7 @@ function groupRoutes(app, middleware, controllers) {
setupPageRoute(app, '/groups/:slug/members', middleware, middlewares, controllers.groups.members);
}
-module.exports = function(app, middleware, hotswapIds) {
+module.exports = function (app, middleware, hotswapIds) {
var routers = [
express.Router(), // plugin router
express.Router(), // main app router
@@ -100,7 +100,7 @@ module.exports = function(app, middleware, hotswapIds) {
}
}
- pluginRouter.render = function() {
+ pluginRouter.render = function () {
app.render.apply(app, arguments);
};
diff --git a/src/routes/meta.js b/src/routes/meta.js
index b459db2972..c62465c8d0 100644
--- a/src/routes/meta.js
+++ b/src/routes/meta.js
@@ -40,7 +40,7 @@ function sendSoundFile(req, res, next) {
}
}
-module.exports = function(app, middleware, controllers) {
+module.exports = function (app, middleware, controllers) {
app.get('/stylesheet.css', middleware.addExpiresHeaders, sendStylesheet);
app.get('/admin.css', middleware.addExpiresHeaders, sendACPStylesheet);
app.get('/nodebb.min.js', middleware.addExpiresHeaders, sendMinifiedJS);
diff --git a/src/routes/plugins.js b/src/routes/plugins.js
index 18c928e3af..37e23c5ee6 100644
--- a/src/routes/plugins.js
+++ b/src/routes/plugins.js
@@ -5,13 +5,13 @@ var path = require('path');
var plugins = require('../plugins');
-module.exports = function(app, middleware, controllers) {
+module.exports = function (app, middleware, controllers) {
// Static Assets
- app.get('/plugins/:id/*', middleware.addExpiresHeaders, function(req, res, next) {
+ app.get('/plugins/:id/*', middleware.addExpiresHeaders, function (req, res, next) {
var relPath = req._parsedUrl.pathname.replace('/plugins/', '');
- var matches = _.map(plugins.staticDirs, function(realPath, mappedPath) {
+ var matches = _.map(plugins.staticDirs, function (realPath, mappedPath) {
if (relPath.match(mappedPath)) {
var pathToFile = path.join(plugins.staticDirs[mappedPath], decodeURIComponent(relPath.slice(mappedPath.length)));
if (pathToFile.startsWith(plugins.staticDirs[mappedPath])) {
@@ -26,7 +26,7 @@ module.exports = function(app, middleware, controllers) {
return next();
}
- res.sendFile(matches[0], {}, function(err) {
+ res.sendFile(matches[0], {}, function (err) {
if (err) {
if (err.code === 'ENOENT') {
// File doesn't exist, this isn't an error, to send to 404 handler
diff --git a/src/search.js b/src/search.js
index 0d1a3b2103..7f03634625 100644
--- a/src/search.js
+++ b/src/search.js
@@ -16,7 +16,7 @@ var search = {};
module.exports = search;
-search.search = function(data, callback) {
+search.search = function (data, callback) {
var start = process.hrtime();
var searchIn = data.searchIn || 'titlesposts';
@@ -44,26 +44,26 @@ search.search = function(data, callback) {
function searchInContent(data, callback) {
data.uid = data.uid || 0;
async.parallel({
- searchCids: function(next) {
+ searchCids: function (next) {
getSearchCids(data, next);
},
- searchUids: function(next) {
+ searchUids: function (next) {
getSearchUids(data, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
async.parallel({
- pids: function(next) {
+ pids: function (next) {
if (data.searchIn === 'posts' || data.searchIn === 'titlesposts') {
search.searchQuery('post', data.query, results.searchCids, results.searchUids, next);
} else {
next(null, []);
}
},
- tids: function(next) {
+ tids: function (next) {
if (data.searchIn === 'titles' || data.searchIn === 'titlesposts') {
search.searchQuery('topic', data.query, results.searchCids, results.searchUids, next);
} else {
@@ -81,22 +81,22 @@ function searchInContent(data, callback) {
}
async.waterfall([
- function(next) {
+ function (next) {
topics.getMainPids(results.tids, next);
},
- function(mainPids, next) {
- results.pids = mainPids.concat(results.pids).map(function(pid) {
+ function (mainPids, next) {
+ results.pids = mainPids.concat(results.pids).map(function (pid) {
return pid && pid.toString();
- }).filter(function(pid, index, array) {
+ }).filter(function (pid, index, array) {
return pid && array.indexOf(pid) === index;
});
privileges.posts.filter('read', results.pids, data.uid, next);
},
- function(pids, next) {
+ function (pids, next) {
filterAndSort(pids, data, next);
},
- function(pids, next) {
+ function (pids, next) {
matchCount = pids.length;
if (data.page) {
var start = Math.max(0, (data.page - 1)) * 10;
@@ -105,7 +105,7 @@ function searchInContent(data, callback) {
posts.getPostSummaryByPids(pids, data.uid, {}, next);
},
- function(posts, next) {
+ function (posts, next) {
next(null, {posts: posts, matchCount: matchCount, pageCount: Math.max(1, Math.ceil(parseInt(matchCount, 10) / 10))});
}
], callback);
@@ -114,7 +114,7 @@ function searchInContent(data, callback) {
}
function filterAndSort(pids, data, callback) {
- getMatchedPosts(pids, data, function(err, posts) {
+ getMatchedPosts(pids, data, function (err, posts) {
if (err) {
return callback(err);
}
@@ -129,7 +129,7 @@ function filterAndSort(pids, data, callback) {
sortPosts(posts, data);
- pids = posts.map(function(post) {
+ pids = posts.map(function (post) {
return post && post.pid;
});
@@ -162,21 +162,21 @@ function getMatchedPosts(pids, data, callback) {
var posts;
async.waterfall([
- function(next) {
- var keys = pids.map(function(pid) {
+ function (next) {
+ var keys = pids.map(function (pid) {
return 'post:' + pid;
});
db.getObjectsFields(keys, postFields, next);
},
- function(_posts, next) {
- posts = _posts.filter(function(post) {
+ function (_posts, next) {
+ posts = _posts.filter(function (post) {
return post && parseInt(post.deleted, 10) !== 1;
});
async.parallel({
- users: function(next) {
+ users: function (next) {
if (data.sortBy && data.sortBy.startsWith('user')) {
- var uids = posts.map(function(post) {
+ var uids = posts.map(function (post) {
return post.uid;
});
user.getUsersFields(uids, ['username'], next);
@@ -184,22 +184,22 @@ function getMatchedPosts(pids, data, callback) {
next();
}
},
- topics: function(next) {
+ topics: function (next) {
var topics;
async.waterfall([
- function(next) {
- var topicKeys = posts.map(function(post) {
+ function (next) {
+ var topicKeys = posts.map(function (post) {
return 'topic:' + post.tid;
});
db.getObjectsFields(topicKeys, topicFields, next);
},
- function(_topics, next) {
+ function (_topics, next) {
topics = _topics;
async.parallel({
- teasers: function(next) {
+ teasers: function (next) {
if (topicFields.indexOf('teaserPid') !== -1) {
- var teaserKeys = topics.map(function(topic) {
+ var teaserKeys = topics.map(function (topic) {
return 'post:' + topic.teaserPid;
});
db.getObjectsFields(teaserKeys, ['timestamp'], next);
@@ -207,23 +207,23 @@ function getMatchedPosts(pids, data, callback) {
next();
}
},
- categories: function(next) {
+ categories: function (next) {
if (!categoryFields.length) {
return next();
}
- var cids = topics.map(function(topic) {
+ var cids = topics.map(function (topic) {
return 'category:' + topic.cid;
});
db.getObjectsFields(cids, categoryFields, next);
}
}, next);
}
- ], function(err, results) {
+ ], function (err, results) {
if (err) {
return next(err);
}
- topics.forEach(function(topic, index) {
+ topics.forEach(function (topic, index) {
if (topic && results.categories && results.categories[index]) {
topic.category = results.categories[index];
}
@@ -237,9 +237,9 @@ function getMatchedPosts(pids, data, callback) {
}
}, next);
},
- function(results, next) {
+ function (results, next) {
- posts.forEach(function(post, index) {
+ posts.forEach(function (post, index) {
if (results.topics && results.topics[index]) {
post.topic = results.topics[index];
if (results.topics[index].category) {
@@ -255,7 +255,7 @@ function getMatchedPosts(pids, data, callback) {
}
});
- posts = posts.filter(function(post) {
+ posts = posts.filter(function (post) {
return post && post.topic && parseInt(post.topic.deleted, 10) !== 1;
});
@@ -268,11 +268,11 @@ function filterByPostcount(posts, postCount, repliesFilter) {
postCount = parseInt(postCount, 10);
if (postCount) {
if (repliesFilter === 'atleast') {
- posts = posts.filter(function(post) {
+ posts = posts.filter(function (post) {
return post.topic && post.topic.postcount >= postCount;
});
} else {
- posts = posts.filter(function(post) {
+ posts = posts.filter(function (post) {
return post.topic && post.topic.postcount <= postCount;
});
}
@@ -285,11 +285,11 @@ function filterByTimerange(posts, timeRange, timeFilter) {
if (timeRange) {
var time = Date.now() - timeRange;
if (timeFilter === 'newer') {
- posts = posts.filter(function(post) {
+ posts = posts.filter(function (post) {
return post.timestamp >= time;
});
} else {
- posts = posts.filter(function(post) {
+ posts = posts.filter(function (post) {
return post.timestamp <= time;
});
}
@@ -306,7 +306,7 @@ function sortPosts(posts, data) {
var direction = data.sortDirection === 'desc' ? 1 : -1;
if (data.sortBy === 'timestamp') {
- posts.sort(function(p1, p2) {
+ posts.sort(function (p1, p2) {
return direction * (p2.timestamp - p1.timestamp);
});
@@ -323,11 +323,11 @@ function sortPosts(posts, data) {
var isNumeric = utils.isNumber(firstPost[fields[0]][fields[1]]);
if (isNumeric) {
- posts.sort(function(p1, p2) {
+ posts.sort(function (p1, p2) {
return direction * (p2[fields[0]][fields[1]] - p1[fields[0]][fields[1]]);
});
} else {
- posts.sort(function(p1, p2) {
+ posts.sort(function (p1, p2) {
if (p1[fields[0]][fields[1]] > p2[fields[0]][fields[1]]) {
return direction;
} else if (p1[fields[0]][fields[1]] < p2[fields[0]][fields[1]]) {
@@ -345,10 +345,10 @@ function getSearchCids(data, callback) {
if (data.categories.indexOf('all') !== -1) {
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRange('categories:cid', 0, -1, next);
},
- function(cids, next) {
+ function (cids, next) {
privileges.categories.filterCids('read', cids, data.uid, next);
}
], callback);
@@ -356,26 +356,26 @@ function getSearchCids(data, callback) {
}
async.parallel({
- watchedCids: function(next) {
+ watchedCids: function (next) {
if (data.categories.indexOf('watched') !== -1) {
user.getWatchedCategories(data.uid, next);
} else {
next(null, []);
}
},
- childrenCids: function(next) {
+ childrenCids: function (next) {
if (data.searchChildren) {
getChildrenCids(data.categories, data.uid, next);
} else {
next(null, []);
}
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
- var cids = results.watchedCids.concat(results.childrenCids).concat(data.categories).filter(function(cid, index, array) {
+ var cids = results.watchedCids.concat(results.childrenCids).concat(data.categories).filter(function (cid, index, array) {
return cid && array.indexOf(cid) === index;
});
@@ -384,7 +384,7 @@ function getSearchCids(data, callback) {
}
function getChildrenCids(cids, uid, callback) {
- categories.getChildren(cids, uid, function(err, childrenCategories) {
+ categories.getChildren(cids, uid, function (err, childrenCategories) {
if (err) {
return callback(err);
}
@@ -392,9 +392,9 @@ function getChildrenCids(cids, uid, callback) {
var childrenCids = [];
var allCategories = [];
- childrenCategories.forEach(function(childrens) {
+ childrenCategories.forEach(function (childrens) {
categories.flattenCategories(allCategories, childrens);
- childrenCids = childrenCids.concat(allCategories.map(function(category) {
+ childrenCids = childrenCids.concat(allCategories.map(function (category) {
return category && category.cid;
}));
});
@@ -411,7 +411,7 @@ function getSearchUids(data, callback) {
}
}
-search.searchQuery = function(index, content, cids, uids, callback) {
+search.searchQuery = function (index, content, cids, uids, callback) {
plugins.fireHook('filter:search.query', {
index: index,
content: content,
diff --git a/src/sitemap.js b/src/sitemap.js
index 68db00d027..d21bb96241 100644
--- a/src/sitemap.js
+++ b/src/sitemap.js
@@ -17,7 +17,7 @@ var sitemap = {
}
};
-sitemap.render = function(callback) {
+sitemap.render = function (callback) {
var numTopics = parseInt(meta.config.sitemapTopics, 10) || 500;
var returnData = {
url: nconf.get('url'),
@@ -27,10 +27,10 @@ sitemap.render = function(callback) {
async.waterfall([
async.apply(db.getSortedSetRange, 'topics:recent', 0, -1),
- function(tids, next) {
+ function (tids, next) {
privileges.topics.filterTids('read', tids, 0, next);
}
- ], function(err, tids) {
+ ], function (err, tids) {
if (err) {
numPages = 1;
} else {
@@ -45,7 +45,7 @@ sitemap.render = function(callback) {
});
};
-sitemap.getPages = function(callback) {
+sitemap.getPages = function (callback) {
if (
sitemap.maps.pages &&
Date.now() < parseInt(sitemap.maps.pages.cacheSetTimestamp, 10) + parseInt(sitemap.maps.pages.cacheResetPeriod, 10)
@@ -80,7 +80,7 @@ sitemap.getPages = function(callback) {
sitemap.maps.pages.toXML(callback);
};
-sitemap.getCategories = function(callback) {
+sitemap.getCategories = function (callback) {
if (
sitemap.maps.categories &&
Date.now() < parseInt(sitemap.maps.categories.cacheSetTimestamp, 10) + parseInt(sitemap.maps.categories.cacheResetPeriod, 10)
@@ -89,12 +89,12 @@ sitemap.getCategories = function(callback) {
}
var categoryUrls = [];
- categories.getCategoriesByPrivilege('categories:cid', 0, 'find', function(err, categoriesData) {
+ categories.getCategoriesByPrivilege('categories:cid', 0, 'find', function (err, categoriesData) {
if (err) {
return callback(err);
}
- categoriesData.forEach(function(category) {
+ categoriesData.forEach(function (category) {
if (category) {
categoryUrls.push({
url: '/category/' + category.slug,
@@ -114,7 +114,7 @@ sitemap.getCategories = function(callback) {
});
};
-sitemap.getTopicPage = function(page, callback) {
+sitemap.getTopicPage = function (page, callback) {
if (parseInt(page, 10) <= 0) {
return callback();
}
@@ -133,21 +133,21 @@ sitemap.getTopicPage = function(page, callback) {
var topicUrls = [];
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRevRange('topics:recent', min, max, next);
},
- function(tids, next) {
+ function (tids, next) {
privileges.topics.filterTids('read', tids, 0, next);
},
- function(tids, next) {
+ function (tids, next) {
topics.getTopicsFields(tids, ['tid', 'title', 'slug', 'lastposttime'], next);
}
- ], function(err, topics) {
+ ], function (err, topics) {
if (err) {
return callback(err);
}
- topics.forEach(function(topic) {
+ topics.forEach(function (topic) {
if (topic) {
topicUrls.push({
url: '/topic/' + topic.slug,
@@ -168,7 +168,7 @@ sitemap.getTopicPage = function(page, callback) {
});
};
-sitemap.clearCache = function() {
+sitemap.clearCache = function () {
if (sitemap.obj) {
sitemap.obj.clearCache();
}
diff --git a/src/social.js b/src/social.js
index fec8fb036c..0c71daadba 100644
--- a/src/social.js
+++ b/src/social.js
@@ -8,7 +8,7 @@ var social = {};
social.postSharing = null;
-social.getPostSharing = function(callback) {
+social.getPostSharing = function (callback) {
if (social.postSharing) {
return callback(null, social.postSharing);
}
@@ -32,16 +32,16 @@ social.getPostSharing = function(callback) {
];
async.waterfall([
- function(next) {
+ function (next) {
plugins.fireHook('filter:social.posts', networks, next);
},
- function(networks, next) {
- db.getSetMembers('social:posts.activated', function(err, activated) {
+ function (networks, next) {
+ db.getSetMembers('social:posts.activated', function (err, activated) {
if (err) {
return next(err);
}
- networks.forEach(function(network, i) {
+ networks.forEach(function (network, i) {
networks[i].activated = (activated.indexOf(network.id) !== -1);
});
@@ -52,19 +52,19 @@ social.getPostSharing = function(callback) {
], callback);
};
-social.getActivePostSharing = function(callback) {
- social.getPostSharing(function(err, networks) {
+social.getActivePostSharing = function (callback) {
+ social.getPostSharing(function (err, networks) {
if (err) {
return callback(err);
}
- networks = networks.filter(function(network) {
+ networks = networks.filter(function (network) {
return network && network.activated;
});
callback(null, networks);
});
};
-social.setActivePostSharingNetworks = function(networkIDs, callback) {
+social.setActivePostSharingNetworks = function (networkIDs, callback) {
async.waterfall([
function (next) {
db.delete('social:posts.activated', next);
diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js
index 4f224f48fd..e59e15d55c 100644
--- a/src/socket.io/admin.js
+++ b/src/socket.io/admin.js
@@ -35,12 +35,12 @@ var SocketAdmin = {
errors: {}
};
-SocketAdmin.before = function(socket, method, data, next) {
+SocketAdmin.before = function (socket, method, data, next) {
if (!socket.uid) {
return;
}
- user.isAdministrator(socket.uid, function(err, isAdmin) {
+ user.isAdministrator(socket.uid, function (err, isAdmin) {
if (err || isAdmin) {
return next(err);
}
@@ -49,7 +49,7 @@ SocketAdmin.before = function(socket, method, data, next) {
});
};
-SocketAdmin.restart = function(socket, data, callback) {
+SocketAdmin.restart = function (socket, data, callback) {
events.log({
type: 'restart',
uid: socket.uid,
@@ -64,21 +64,21 @@ SocketAdmin.restart = function(socket, data, callback) {
*/
SocketAdmin.reload = SocketAdmin.restart;
-SocketAdmin.fireEvent = function(socket, data, callback) {
+SocketAdmin.fireEvent = function (socket, data, callback) {
index.server.emit(data.name, data.payload || {});
callback();
};
-SocketAdmin.themes.getInstalled = function(socket, data, callback) {
+SocketAdmin.themes.getInstalled = function (socket, data, callback) {
meta.themes.get(callback);
};
-SocketAdmin.themes.set = function(socket, data, callback) {
+SocketAdmin.themes.set = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
- var wrappedCallback = function(err) {
+ var wrappedCallback = function (err) {
if (err) {
return callback(err);
}
@@ -91,22 +91,22 @@ SocketAdmin.themes.set = function(socket, data, callback) {
}
};
-SocketAdmin.plugins.toggleActive = function(socket, plugin_id, callback) {
+SocketAdmin.plugins.toggleActive = function (socket, plugin_id, callback) {
require('../posts/cache').reset();
plugins.toggleActive(plugin_id, callback);
};
-SocketAdmin.plugins.toggleInstall = function(socket, data, callback) {
+SocketAdmin.plugins.toggleInstall = function (socket, data, callback) {
require('../posts/cache').reset();
plugins.toggleInstall(data.id, data.version, callback);
};
-SocketAdmin.plugins.getActive = function(socket, data, callback) {
+SocketAdmin.plugins.getActive = function (socket, data, callback) {
plugins.getActive(callback);
};
-SocketAdmin.plugins.orderActivePlugins = function(socket, data, callback) {
- async.each(data, function(plugin, next) {
+SocketAdmin.plugins.orderActivePlugins = function (socket, data, callback) {
+ async.each(data, function (plugin, next) {
if (plugin && plugin.name) {
db.sortedSetAdd('plugins:active', plugin.order || 0, plugin.name, next);
} else {
@@ -115,11 +115,11 @@ SocketAdmin.plugins.orderActivePlugins = function(socket, data, callback) {
}, callback);
};
-SocketAdmin.plugins.upgrade = function(socket, data, callback) {
+SocketAdmin.plugins.upgrade = function (socket, data, callback) {
plugins.upgrade(data.id, data.version, callback);
};
-SocketAdmin.widgets.set = function(socket, data, callback) {
+SocketAdmin.widgets.set = function (socket, data, callback) {
if(!data) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -127,12 +127,12 @@ SocketAdmin.widgets.set = function(socket, data, callback) {
widgets.setArea(data, callback);
};
-SocketAdmin.config.set = function(socket, data, callback) {
+SocketAdmin.config.set = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
- meta.configs.set(data.key, data.value, function(err) {
+ meta.configs.set(data.key, data.value, function (err) {
if (err) {
return callback(err);
}
@@ -148,12 +148,12 @@ SocketAdmin.config.set = function(socket, data, callback) {
});
};
-SocketAdmin.config.setMultiple = function(socket, data, callback) {
+SocketAdmin.config.setMultiple = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
- meta.configs.setMultiple(data, function(err) {
+ meta.configs.setMultiple(data, function (err) {
if(err) {
return callback(err);
}
@@ -173,25 +173,25 @@ SocketAdmin.config.setMultiple = function(socket, data, callback) {
});
};
-SocketAdmin.config.remove = function(socket, key, callback) {
+SocketAdmin.config.remove = function (socket, key, callback) {
meta.configs.remove(key);
callback();
};
-SocketAdmin.settings.get = function(socket, data, callback) {
+SocketAdmin.settings.get = function (socket, data, callback) {
meta.settings.get(data.hash, callback);
};
-SocketAdmin.settings.set = function(socket, data, callback) {
+SocketAdmin.settings.set = function (socket, data, callback) {
meta.settings.set(data.hash, data.values, callback);
};
-SocketAdmin.settings.clearSitemapCache = function(socket, data, callback) {
+SocketAdmin.settings.clearSitemapCache = function (socket, data, callback) {
require('../sitemap').clearCache();
callback();
};
-SocketAdmin.email.test = function(socket, data, callback) {
+SocketAdmin.email.test = function (socket, data, callback) {
var site_title = meta.config.title || 'NodeBB';
emailer.send(data.template, socket.uid, {
subject: '[' + site_title + '] Test Email',
@@ -200,7 +200,7 @@ SocketAdmin.email.test = function(socket, data, callback) {
}, callback);
};
-SocketAdmin.analytics.get = function(socket, data, callback) {
+SocketAdmin.analytics.get = function (socket, data, callback) {
// Default returns views from past 24 hours, by hour
if (data.units === 'days') {
data.amount = 30;
@@ -211,25 +211,25 @@ SocketAdmin.analytics.get = function(socket, data, callback) {
if (data && data.graph && data.units && data.amount) {
if (data.graph === 'traffic') {
async.parallel({
- uniqueVisitors: function(next) {
+ uniqueVisitors: function (next) {
if (data.units === 'days') {
analytics.getDailyStatsForSet('analytics:uniquevisitors', data.until || Date.now(), data.amount, next);
} else {
analytics.getHourlyStatsForSet('analytics:uniquevisitors', data.until || Date.now(), data.amount, next);
}
},
- pageviews: function(next) {
+ pageviews: function (next) {
if (data.units === 'days') {
analytics.getDailyStatsForSet('analytics:pageviews', data.until || Date.now(), data.amount, next);
} else {
analytics.getHourlyStatsForSet('analytics:pageviews', data.until || Date.now(), data.amount, next);
}
},
- monthlyPageViews: function(next) {
+ monthlyPageViews: function (next) {
analytics.getMonthlyPageViews(next);
}
- }, function(err, data) {
- data.pastDay = data.pageviews.reduce(function(a, b) {return parseInt(a, 10) + parseInt(b, 10);});
+ }, function (err, data) {
+ data.pastDay = data.pageviews.reduce(function (a, b) {return parseInt(a, 10) + parseInt(b, 10);});
data.pageviews[data.pageviews.length - 1] = parseInt(data.pageviews[data.pageviews.length - 1], 10) + analytics.getUnwrittenPageviews();
callback(err, data);
});
@@ -239,19 +239,19 @@ SocketAdmin.analytics.get = function(socket, data, callback) {
}
};
-SocketAdmin.logs.get = function(socket, data, callback) {
+SocketAdmin.logs.get = function (socket, data, callback) {
meta.logs.get(callback);
};
-SocketAdmin.logs.clear = function(socket, data, callback) {
+SocketAdmin.logs.clear = function (socket, data, callback) {
meta.logs.clear(callback);
};
-SocketAdmin.errors.clear = function(socket, data, callback) {
+SocketAdmin.errors.clear = function (socket, data, callback) {
meta.errors.clear(callback);
};
-SocketAdmin.deleteAllEvents = function(socket, data, callback) {
+SocketAdmin.deleteAllEvents = function (socket, data, callback) {
events.deleteAll(callback);
};
diff --git a/src/socket.io/admin/categories.js b/src/socket.io/admin/categories.js
index ff2f8400b0..b90ec3e4b6 100644
--- a/src/socket.io/admin/categories.js
+++ b/src/socket.io/admin/categories.js
@@ -9,7 +9,7 @@ var privileges = require('../../privileges');
var plugins = require('../../plugins');
var Categories = {};
-Categories.create = function(socket, data, callback) {
+Categories.create = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -17,18 +17,18 @@ Categories.create = function(socket, data, callback) {
categories.create(data, callback);
};
-Categories.getAll = function(socket, data, callback) {
+Categories.getAll = function (socket, data, callback) {
async.waterfall([
async.apply(db.getSortedSetRange, 'categories:cid', 0, -1),
async.apply(categories.getCategoriesData),
- function(categories, next) {
+ function (categories, next) {
//Hook changes, there is no req, and res
plugins.fireHook('filter:admin.categories.get', {categories: categories}, next);
},
- function(result, next){
+ function (result, next){
next(null, categories.getTree(result.categories, 0));
}
- ], function(err, categoriesTree) {
+ ], function (err, categoriesTree) {
if (err) {
return callback(err);
}
@@ -37,15 +37,15 @@ Categories.getAll = function(socket, data, callback) {
});
};
-Categories.getNames = function(socket, data, callback) {
+Categories.getNames = function (socket, data, callback) {
categories.getAllCategoryFields(['cid', 'name'], callback);
};
-Categories.purge = function(socket, cid, callback) {
+Categories.purge = function (socket, cid, callback) {
categories.purge(cid, socket.uid, callback);
};
-Categories.update = function(socket, data, callback) {
+Categories.update = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -53,13 +53,13 @@ Categories.update = function(socket, data, callback) {
categories.update(data, callback);
};
-Categories.setPrivilege = function(socket, data, callback) {
+Categories.setPrivilege = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
if (Array.isArray(data.privilege)) {
- async.each(data.privilege, function(privilege, next) {
+ async.each(data.privilege, function (privilege, next) {
groups[data.set ? 'join' : 'leave']('cid:' + data.cid + ':privileges:' + privilege, data.member, next);
}, callback);
} else {
@@ -67,39 +67,39 @@ Categories.setPrivilege = function(socket, data, callback) {
}
};
-Categories.getPrivilegeSettings = function(socket, cid, callback) {
+Categories.getPrivilegeSettings = function (socket, cid, callback) {
privileges.categories.list(cid, callback);
};
-Categories.copyPrivilegesToChildren = function(socket, cid, callback) {
- categories.getCategories([cid], socket.uid, function(err, categories) {
+Categories.copyPrivilegesToChildren = function (socket, cid, callback) {
+ categories.getCategories([cid], socket.uid, function (err, categories) {
if (err) {
return callback(err);
}
var category = categories[0];
- async.eachSeries(category.children, function(child, next) {
+ async.eachSeries(category.children, function (child, next) {
copyPrivilegesToChildrenRecursive(cid, child, next);
}, callback);
});
};
function copyPrivilegesToChildrenRecursive(parentCid, category, callback) {
- categories.copyPrivilegesFrom(parentCid, category.cid, function(err) {
+ categories.copyPrivilegesFrom(parentCid, category.cid, function (err) {
if (err) {
return callback(err);
}
- async.eachSeries(category.children, function(child, next) {
+ async.eachSeries(category.children, function (child, next) {
copyPrivilegesToChildrenRecursive(parentCid, child, next);
}, callback);
});
}
-Categories.copySettingsFrom = function(socket, data, callback) {
+Categories.copySettingsFrom = function (socket, data, callback) {
categories.copySettingsFrom(data.fromCid, data.toCid, true, callback);
};
-Categories.copyPrivilegesFrom = function(socket, data, callback) {
+Categories.copyPrivilegesFrom = function (socket, data, callback) {
categories.copyPrivilegesFrom(data.fromCid, data.toCid, callback);
};
diff --git a/src/socket.io/admin/groups.js b/src/socket.io/admin/groups.js
index 0088fbc5c8..6b9e404ae1 100644
--- a/src/socket.io/admin/groups.js
+++ b/src/socket.io/admin/groups.js
@@ -5,7 +5,7 @@ var groups = require('../../groups');
var Groups = {};
-Groups.create = function(socket, data, callback) {
+Groups.create = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
} else if (groups.isPrivilegeGroup(data.name)) {
@@ -19,7 +19,7 @@ Groups.create = function(socket, data, callback) {
}, callback);
};
-Groups.join = function(socket, data, callback) {
+Groups.join = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -37,7 +37,7 @@ Groups.join = function(socket, data, callback) {
], callback);
};
-Groups.leave = function(socket, data, callback) {
+Groups.leave = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -59,7 +59,7 @@ Groups.leave = function(socket, data, callback) {
], callback);
};
-Groups.update = function(socket, data, callback) {
+Groups.update = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
diff --git a/src/socket.io/admin/navigation.js b/src/socket.io/admin/navigation.js
index 0f3f7c168e..2f4d9817b4 100644
--- a/src/socket.io/admin/navigation.js
+++ b/src/socket.io/admin/navigation.js
@@ -3,7 +3,7 @@
var navigationAdmin = require('../../navigation/admin'),
SocketNavigation = {};
-SocketNavigation.save = function(socket, data, callback) {
+SocketNavigation.save = function (socket, data, callback) {
navigationAdmin.save(data, callback);
};
diff --git a/src/socket.io/admin/rewards.js b/src/socket.io/admin/rewards.js
index b130a25455..266d5f532f 100644
--- a/src/socket.io/admin/rewards.js
+++ b/src/socket.io/admin/rewards.js
@@ -3,11 +3,11 @@
var rewardsAdmin = require('../../rewards/admin'),
SocketRewards = {};
-SocketRewards.save = function(socket, data, callback) {
+SocketRewards.save = function (socket, data, callback) {
rewardsAdmin.save(data, callback);
};
-SocketRewards.delete = function(socket, data, callback) {
+SocketRewards.delete = function (socket, data, callback) {
rewardsAdmin.delete(data, callback);
};
diff --git a/src/socket.io/admin/rooms.js b/src/socket.io/admin/rooms.js
index d682cdfeba..a4ebfeb44e 100644
--- a/src/socket.io/admin/rooms.js
+++ b/src/socket.io/admin/rooms.js
@@ -16,8 +16,8 @@ var SocketRooms = {
};
-pubsub.on('sync:stats:start', function() {
- SocketRooms.getLocalStats(function(err, stats) {
+pubsub.on('sync:stats:start', function () {
+ SocketRooms.getLocalStats(function (err, stats) {
if (err) {
return winston.error(err);
}
@@ -25,11 +25,11 @@ pubsub.on('sync:stats:start', function() {
});
});
-pubsub.on('sync:stats:end', function(data) {
+pubsub.on('sync:stats:end', function (data) {
stats[data.id] = data.stats;
});
-pubsub.on('sync:stats:guests', function() {
+pubsub.on('sync:stats:guests', function () {
var io = require('../index').server;
var roomClients = io.sockets.adapter.rooms;
@@ -37,23 +37,23 @@ pubsub.on('sync:stats:guests', function() {
pubsub.publish('sync:stats:guests:end', guestCount);
});
-SocketRooms.getTotalGuestCount = function(callback) {
+SocketRooms.getTotalGuestCount = function (callback) {
var count = 0;
- pubsub.on('sync:stats:guests:end', function(guestCount) {
+ pubsub.on('sync:stats:guests:end', function (guestCount) {
count += guestCount;
});
pubsub.publish('sync:stats:guests');
- setTimeout(function() {
+ setTimeout(function () {
pubsub.removeAllListeners('sync:stats:guests:end');
callback(null, count);
}, 100);
};
-SocketRooms.getAll = function(socket, data, callback) {
+SocketRooms.getAll = function (socket, data, callback) {
pubsub.publish('sync:stats:start');
totals.onlineGuestCount = 0;
@@ -79,7 +79,7 @@ SocketRooms.getAll = function(socket, data, callback) {
totals.users.topics += stats[instance].users.topics;
totals.users.category += stats[instance].users.category;
- stats[instance].topics.forEach(function(topic) {
+ stats[instance].topics.forEach(function (topic) {
totals.topics[topic.tid] = totals.topics[topic.tid] || {count: 0, tid: topic.tid};
totals.topics[topic.tid].count += topic.count;
});
@@ -87,24 +87,24 @@ SocketRooms.getAll = function(socket, data, callback) {
}
var topTenTopics = [];
- Object.keys(totals.topics).forEach(function(tid) {
+ Object.keys(totals.topics).forEach(function (tid) {
topTenTopics.push({tid: tid, count: totals.topics[tid].count});
});
- topTenTopics = topTenTopics.sort(function(a, b) {
+ topTenTopics = topTenTopics.sort(function (a, b) {
return b.count - a.count;
}).slice(0, 10);
- var topTenTids = topTenTopics.map(function(topic) {
+ var topTenTids = topTenTopics.map(function (topic) {
return topic.tid;
});
- topics.getTopicsFields(topTenTids, ['title'], function(err, titles) {
+ topics.getTopicsFields(topTenTids, ['title'], function (err, titles) {
if (err) {
return callback(err);
}
totals.topics = {};
- topTenTopics.forEach(function(topic, index) {
+ topTenTopics.forEach(function (topic, index) {
totals.topics[topic.tid] = {
value: topic.count || 0,
title: validator.escape(String(titles[index].title))
@@ -115,7 +115,7 @@ SocketRooms.getAll = function(socket, data, callback) {
});
};
-SocketRooms.getOnlineUserCount = function(io) {
+SocketRooms.getOnlineUserCount = function (io) {
if (!io) {
return 0;
}
@@ -129,7 +129,7 @@ SocketRooms.getOnlineUserCount = function(io) {
return count;
};
-SocketRooms.getLocalStats = function(callback) {
+SocketRooms.getLocalStats = function (callback) {
var io = require('../index').server;
if (!io) {
@@ -166,7 +166,7 @@ SocketRooms.getLocalStats = function(callback) {
}
}
- topTenTopics = topTenTopics.sort(function(a, b) {
+ topTenTopics = topTenTopics.sort(function (a, b) {
return b.count - a.count;
}).slice(0, 10);
diff --git a/src/socket.io/admin/social.js b/src/socket.io/admin/social.js
index 68b3241c64..77227ea760 100644
--- a/src/socket.io/admin/social.js
+++ b/src/socket.io/admin/social.js
@@ -3,7 +3,7 @@
var social = require('../../social'),
SocketSocial = {};
-SocketSocial.savePostSharingNetworks = function(socket, data, callback) {
+SocketSocial.savePostSharingNetworks = function (socket, data, callback) {
social.setActivePostSharingNetworks(data, callback);
};
diff --git a/src/socket.io/admin/tags.js b/src/socket.io/admin/tags.js
index cbe25fabcb..c00740d9d5 100644
--- a/src/socket.io/admin/tags.js
+++ b/src/socket.io/admin/tags.js
@@ -3,7 +3,7 @@
var topics = require('../../topics');
var Tags = {};
-Tags.create = function(socket, data, callback) {
+Tags.create = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -11,7 +11,7 @@ Tags.create = function(socket, data, callback) {
topics.createEmptyTag(data.tag, callback);
};
-Tags.update = function(socket, data, callback) {
+Tags.update = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -19,7 +19,7 @@ Tags.update = function(socket, data, callback) {
topics.updateTag(data.tag, data, callback);
};
-Tags.deleteTags = function(socket, data, callback) {
+Tags.deleteTags = function (socket, data, callback) {
topics.deleteTags(data.tags, callback);
};
diff --git a/src/socket.io/admin/user.js b/src/socket.io/admin/user.js
index 0efd1929d3..3d0a114695 100644
--- a/src/socket.io/admin/user.js
+++ b/src/socket.io/admin/user.js
@@ -11,12 +11,12 @@ var meta = require('../../meta');
var User = {};
-User.makeAdmins = function(socket, uids, callback) {
+User.makeAdmins = function (socket, uids, callback) {
if(!Array.isArray(uids)) {
return callback(new Error('[[error:invalid-data]]'));
}
- user.getUsersFields(uids, ['banned'], function(err, userData) {
+ user.getUsersFields(uids, ['banned'], function (err, userData) {
if (err) {
return callback(err);
}
@@ -27,19 +27,19 @@ User.makeAdmins = function(socket, uids, callback) {
}
}
- async.each(uids, function(uid, next) {
+ async.each(uids, function (uid, next) {
groups.join('administrators', uid, next);
}, callback);
});
};
-User.removeAdmins = function(socket, uids, callback) {
+User.removeAdmins = function (socket, uids, callback) {
if(!Array.isArray(uids)) {
return callback(new Error('[[error:invalid-data]]'));
}
- async.eachSeries(uids, function(uid, next) {
- groups.getMemberCount('administrators', function(err, count) {
+ async.eachSeries(uids, function (uid, next) {
+ groups.getMemberCount('administrators', function (err, count) {
if (err) {
return next(err);
}
@@ -53,7 +53,7 @@ User.removeAdmins = function(socket, uids, callback) {
}, callback);
};
-User.createUser = function(socket, userData, callback) {
+User.createUser = function (socket, userData, callback) {
if (!userData) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -61,7 +61,7 @@ User.createUser = function(socket, userData, callback) {
};
-User.resetLockouts = function(socket, uids, callback) {
+User.resetLockouts = function (socket, uids, callback) {
if (!Array.isArray(uids)) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -69,7 +69,7 @@ User.resetLockouts = function(socket, uids, callback) {
async.each(uids, user.auth.resetLockout, callback);
};
-User.resetFlags = function(socket, uids, callback) {
+User.resetFlags = function (socket, uids, callback) {
if (!Array.isArray(uids)) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -77,18 +77,18 @@ User.resetFlags = function(socket, uids, callback) {
user.resetFlags(uids, callback);
};
-User.validateEmail = function(socket, uids, callback) {
+User.validateEmail = function (socket, uids, callback) {
if (!Array.isArray(uids)) {
return callback(new Error('[[error:invalid-data]]'));
}
- uids = uids.filter(function(uid) {
+ uids = uids.filter(function (uid) {
return parseInt(uid, 10);
});
- async.each(uids, function(uid, next) {
+ async.each(uids, function (uid, next) {
user.setUserField(uid, 'email:confirmed', 1, next);
- }, function(err) {
+ }, function (err) {
if (err) {
return callback(err);
}
@@ -96,7 +96,7 @@ User.validateEmail = function(socket, uids, callback) {
});
};
-User.sendValidationEmail = function(socket, uids, callback) {
+User.sendValidationEmail = function (socket, uids, callback) {
if (!Array.isArray(uids)) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -105,12 +105,12 @@ User.sendValidationEmail = function(socket, uids, callback) {
return callback(new Error('[[error:email-confirmations-are-disabled]]'));
}
- user.getUsersFields(uids, ['uid', 'email'], function(err, usersData) {
+ user.getUsersFields(uids, ['uid', 'email'], function (err, usersData) {
if (err) {
return callback(err);
}
- async.eachLimit(usersData, 50, function(userData, next) {
+ async.eachLimit(usersData, 50, function (userData, next) {
if (userData.email && userData.uid) {
user.email.sendValidationEmail(userData.uid, userData.email, next);
} else {
@@ -120,17 +120,17 @@ User.sendValidationEmail = function(socket, uids, callback) {
});
};
-User.sendPasswordResetEmail = function(socket, uids, callback) {
+User.sendPasswordResetEmail = function (socket, uids, callback) {
if (!Array.isArray(uids)) {
return callback(new Error('[[error:invalid-data]]'));
}
- uids = uids.filter(function(uid) {
+ uids = uids.filter(function (uid) {
return parseInt(uid, 10);
});
- async.each(uids, function(uid, next) {
- user.getUserFields(uid, ['email', 'username'], function(err, userData) {
+ async.each(uids, function (uid, next) {
+ user.getUserFields(uid, ['email', 'username'], function (err, userData) {
if (err) {
return next(err);
}
@@ -142,14 +142,14 @@ User.sendPasswordResetEmail = function(socket, uids, callback) {
}, callback);
};
-User.deleteUsers = function(socket, uids, callback) {
- deleteUsers(socket, uids, function(uid, next) {
+User.deleteUsers = function (socket, uids, callback) {
+ deleteUsers(socket, uids, function (uid, next) {
user.deleteAccount(uid, next);
}, callback);
};
-User.deleteUsersAndContent = function(socket, uids, callback) {
- deleteUsers(socket, uids, function(uid, next) {
+User.deleteUsersAndContent = function (socket, uids, callback) {
+ deleteUsers(socket, uids, function (uid, next) {
user.delete(socket.uid, uid, next);
}, callback);
};
@@ -159,7 +159,7 @@ function deleteUsers(socket, uids, method, callback) {
return callback(new Error('[[error:invalid-data]]'));
}
- async.each(uids, function(uid, next) {
+ async.each(uids, function (uid, next) {
async.waterfall([
function (next) {
user.isAdministrator(uid, next);
@@ -184,8 +184,8 @@ function deleteUsers(socket, uids, method, callback) {
}, callback);
}
-User.search = function(socket, data, callback) {
- user.search({query: data.query, searchBy: data.searchBy, uid: socket.uid}, function(err, searchData) {
+User.search = function (socket, data, callback) {
+ user.search({query: data.query, searchBy: data.searchBy, uid: socket.uid}, function (err, searchData) {
if (err) {
return callback(err);
}
@@ -194,16 +194,16 @@ User.search = function(socket, data, callback) {
}
var userData = searchData.users;
- var uids = userData.map(function(user) {
+ var uids = userData.map(function (user) {
return user && user.uid;
});
- user.getUsersFields(uids, ['email', 'flags', 'lastonline', 'joindate'], function(err, userInfo) {
+ user.getUsersFields(uids, ['email', 'flags', 'lastonline', 'joindate'], function (err, userInfo) {
if (err) {
return callback(err);
}
- userData.forEach(function(user, index) {
+ userData.forEach(function (user, index) {
if (user && userInfo[index]) {
user.email = validator.escape(String(userInfo[index].email || ''));
user.flags = userInfo[index].flags || 0;
@@ -217,19 +217,19 @@ User.search = function(socket, data, callback) {
});
};
-User.deleteInvitation = function(socket, data, callback) {
+User.deleteInvitation = function (socket, data, callback) {
user.deleteInvitation(data.invitedBy, data.email, callback);
};
-User.acceptRegistration = function(socket, data, callback) {
+User.acceptRegistration = function (socket, data, callback) {
user.acceptRegistration(data.username, callback);
};
-User.rejectRegistration = function(socket, data, callback) {
+User.rejectRegistration = function (socket, data, callback) {
user.rejectRegistration(data.username, callback);
};
-User.restartJobs = function(socket, data, callback) {
+User.restartJobs = function (socket, data, callback) {
user.startJobs(callback);
};
diff --git a/src/socket.io/blacklist.js b/src/socket.io/blacklist.js
index f4158dc94b..a05d632f3f 100644
--- a/src/socket.io/blacklist.js
+++ b/src/socket.io/blacklist.js
@@ -9,12 +9,12 @@ var meta = require('../meta');
var SocketBlacklist = {};
-SocketBlacklist.validate = function(socket, data, callback) {
+SocketBlacklist.validate = function (socket, data, callback) {
meta.blacklist.validate(data.rules, callback);
};
-SocketBlacklist.save = function(socket, rules, callback) {
- user.isAdminOrGlobalMod(socket.uid, function(err, isAdminOrGlobalMod) {
+SocketBlacklist.save = function (socket, rules, callback) {
+ user.isAdminOrGlobalMod(socket.uid, function (err, isAdminOrGlobalMod) {
if (err || !isAdminOrGlobalMod) {
return callback(err || new Error('[[error:no-privileges]]'));
}
diff --git a/src/socket.io/categories.js b/src/socket.io/categories.js
index 0b43398f4b..acc8652057 100644
--- a/src/socket.io/categories.js
+++ b/src/socket.io/categories.js
@@ -10,25 +10,25 @@ var apiController = require('../controllers/api');
var SocketCategories = {};
-SocketCategories.getRecentReplies = function(socket, cid, callback) {
+SocketCategories.getRecentReplies = function (socket, cid, callback) {
categories.getRecentReplies(cid, socket.uid, 4, callback);
};
-SocketCategories.get = function(socket, data, callback) {
+SocketCategories.get = function (socket, data, callback) {
async.parallel({
isAdmin: async.apply(user.isAdministrator, socket.uid),
- categories: function(next) {
+ categories: function (next) {
async.waterfall([
async.apply(db.getSortedSetRange, 'categories:cid', 0, -1),
async.apply(categories.getCategoriesData),
], next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
- results.categories = results.categories.filter(function(category) {
+ results.categories = results.categories.filter(function (category) {
return category && (!category.disabled || results.isAdmin);
});
@@ -36,41 +36,41 @@ SocketCategories.get = function(socket, data, callback) {
});
};
-SocketCategories.getWatchedCategories = function(socket, data, callback) {
+SocketCategories.getWatchedCategories = function (socket, data, callback) {
async.parallel({
categories: async.apply(categories.getCategoriesByPrivilege, socket.uid, 'find'),
ignoredCids: async.apply(user.getIgnoredCategories, socket.uid)
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
- var watchedCategories = results.categories.filter(function(category) {
+ var watchedCategories = results.categories.filter(function (category) {
return category && results.ignoredCids.indexOf(category.cid.toString()) === -1;
});
callback(null, watchedCategories);
});
};
-SocketCategories.loadMore = function(socket, data, callback) {
+SocketCategories.loadMore = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
async.parallel({
- privileges: function(next) {
+ privileges: function (next) {
privileges.categories.get(data.cid, socket.uid, next);
},
- settings: function(next) {
+ settings: function (next) {
user.getSettings(socket.uid, next);
},
- targetUid: function(next) {
+ targetUid: function (next) {
if (data.author) {
user.getUidByUserslug(data.author, next);
} else {
next();
}
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -118,7 +118,7 @@ SocketCategories.loadMore = function(socket, data, callback) {
uid: socket.uid,
targetUid: results.targetUid,
settings: results.settings
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return callback(err);
}
@@ -136,22 +136,22 @@ SocketCategories.loadMore = function(socket, data, callback) {
});
};
-SocketCategories.getPageCount = function(socket, cid, callback) {
+SocketCategories.getPageCount = function (socket, cid, callback) {
categories.getPageCount(cid, socket.uid, callback);
};
-SocketCategories.getTopicCount = function(socket, cid, callback) {
+SocketCategories.getTopicCount = function (socket, cid, callback) {
categories.getCategoryField(cid, 'topic_count', callback);
};
-SocketCategories.getCategoriesByPrivilege = function(socket, privilege, callback) {
+SocketCategories.getCategoriesByPrivilege = function (socket, privilege, callback) {
categories.getCategoriesByPrivilege('categories:cid', socket.uid, privilege, callback);
};
-SocketCategories.getMoveCategories = function(socket, data, callback) {
+SocketCategories.getMoveCategories = function (socket, data, callback) {
async.parallel({
isAdmin: async.apply(user.isAdministrator, socket.uid),
- categories: function(next) {
+ categories: function (next) {
async.waterfall([
function (next) {
db.getSortedSetRange('cid:0:children', 0, -1, next);
@@ -161,12 +161,12 @@ SocketCategories.getMoveCategories = function(socket, data, callback) {
}
], next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
- results.categories = results.categories.filter(function(category) {
+ results.categories = results.categories.filter(function (category) {
return category && (!category.disabled || results.isAdmin) && !category.link;
});
@@ -174,24 +174,24 @@ SocketCategories.getMoveCategories = function(socket, data, callback) {
});
};
-SocketCategories.watch = function(socket, cid, callback) {
+SocketCategories.watch = function (socket, cid, callback) {
ignoreOrWatch(user.watchCategory, socket, cid, callback);
};
-SocketCategories.ignore = function(socket, cid, callback) {
+SocketCategories.ignore = function (socket, cid, callback) {
ignoreOrWatch(user.ignoreCategory, socket, cid, callback);
};
function ignoreOrWatch(fn, socket, cid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRange('categories:cid', 0, -1, next);
},
- function(cids, next) {
+ function (cids, next) {
categories.getCategoriesFields(cids, ['cid', 'parentCid'], next);
},
- function(categoryData, next) {
- categoryData.forEach(function(c) {
+ function (categoryData, next) {
+ categoryData.forEach(function (c) {
c.cid = parseInt(c.cid, 10);
c.parentCid = parseInt(c.parentCid, 10);
});
@@ -203,7 +203,7 @@ function ignoreOrWatch(fn, socket, cid, callback) {
var any = true;
while (any) {
any = false;
- categoryData.forEach(function(c) {
+ categoryData.forEach(function (c) {
if (cids.indexOf(c.cid) === -1 && cids.indexOf(c.parentCid) !== -1) {
cids.push(c.cid);
any = true;
@@ -211,21 +211,21 @@ function ignoreOrWatch(fn, socket, cid, callback) {
});
}
- async.each(cids, function(cid, next) {
+ async.each(cids, function (cid, next) {
fn(socket.uid, cid, next);
}, next);
},
- function(next) {
+ function (next) {
topics.pushUnreadCount(socket.uid, next);
}
], callback);
}
-SocketCategories.isModerator = function(socket, cid, callback) {
+SocketCategories.isModerator = function (socket, cid, callback) {
user.isModerator(socket.uid, cid, callback);
};
-SocketCategories.getCategory = function(socket, cid, callback) {
+SocketCategories.getCategory = function (socket, cid, callback) {
apiController.getCategoryData(cid, socket.uid, callback);
};
diff --git a/src/socket.io/groups.js b/src/socket.io/groups.js
index a8eb6b7ae9..25d92003e9 100644
--- a/src/socket.io/groups.js
+++ b/src/socket.io/groups.js
@@ -11,14 +11,14 @@ var async = require('async'),
SocketGroups = {};
-SocketGroups.before = function(socket, method, data, next) {
+SocketGroups.before = function (socket, method, data, next) {
if (!data) {
return next(new Error('[[error:invalid-data]]'));
}
next();
};
-SocketGroups.join = function(socket, data, callback) {
+SocketGroups.join = function (socket, data, callback) {
if (!parseInt(socket.uid, 10)) {
return callback(new Error('[[error:invalid-uid]]'));
}
@@ -27,7 +27,7 @@ SocketGroups.join = function(socket, data, callback) {
return callback(new Error('[[error:not-allowed]]'));
}
- groups.exists(data.groupName, function(err, exists) {
+ groups.exists(data.groupName, function (err, exists) {
if (err || !exists) {
return callback(err || new Error('[[error:no-group]]'));
}
@@ -39,7 +39,7 @@ SocketGroups.join = function(socket, data, callback) {
async.parallel({
isAdmin: async.apply(user.isAdministrator, socket.uid),
groupData: async.apply(groups.getGroupData, data.groupName)
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -57,7 +57,7 @@ SocketGroups.join = function(socket, data, callback) {
});
};
-SocketGroups.leave = function(socket, data, callback) {
+SocketGroups.leave = function (socket, data, callback) {
if (!parseInt(socket.uid, 10)) {
return callback(new Error('[[error:invalid-uid]]'));
}
@@ -74,7 +74,7 @@ function isOwner(next) {
async.parallel({
isAdmin: async.apply(user.isAdministrator, socket.uid),
isOwner: async.apply(groups.ownership.isOwner, socket.uid, data.groupName)
- }, function(err, results) {
+ }, function (err, results) {
if (err || (!isOwner && !results.isAdmin)) {
return callback(err || new Error('[[error:no-privileges]]'));
}
@@ -85,7 +85,7 @@ function isOwner(next) {
function isInvited(next) {
return function (socket, data, callback) {
- groups.isInvited(socket.uid, data.groupName, function(err, invited) {
+ groups.isInvited(socket.uid, data.groupName, function (err, invited) {
if (err || !invited) {
return callback(err || new Error('[[error:not-invited]]'));
}
@@ -94,92 +94,92 @@ function isInvited(next) {
};
}
-SocketGroups.grant = isOwner(function(socket, data, callback) {
+SocketGroups.grant = isOwner(function (socket, data, callback) {
groups.ownership.grant(data.toUid, data.groupName, callback);
});
-SocketGroups.rescind = isOwner(function(socket, data, callback) {
+SocketGroups.rescind = isOwner(function (socket, data, callback) {
groups.ownership.rescind(data.toUid, data.groupName, callback);
});
-SocketGroups.accept = isOwner(function(socket, data, callback) {
+SocketGroups.accept = isOwner(function (socket, data, callback) {
groups.acceptMembership(data.groupName, data.toUid, callback);
});
-SocketGroups.reject = isOwner(function(socket, data, callback) {
+SocketGroups.reject = isOwner(function (socket, data, callback) {
groups.rejectMembership(data.groupName, data.toUid, callback);
});
-SocketGroups.acceptAll = isOwner(function(socket, data, callback) {
+SocketGroups.acceptAll = isOwner(function (socket, data, callback) {
acceptRejectAll(groups.acceptMembership, socket, data, callback);
});
-SocketGroups.rejectAll = isOwner(function(socket, data, callback) {
+SocketGroups.rejectAll = isOwner(function (socket, data, callback) {
acceptRejectAll(groups.rejectMembership, socket, data, callback);
});
function acceptRejectAll(method, socket, data, callback) {
async.waterfall([
- function(next) {
+ function (next) {
groups.getPending(data.groupName, next);
},
- function(uids, next) {
- async.each(uids, function(uid, next) {
+ function (uids, next) {
+ async.each(uids, function (uid, next) {
method(data.groupName, uid, next);
}, next);
}
], callback);
}
-SocketGroups.issueInvite = isOwner(function(socket, data, callback) {
+SocketGroups.issueInvite = isOwner(function (socket, data, callback) {
groups.invite(data.groupName, data.toUid, callback);
});
-SocketGroups.issueMassInvite = isOwner(function(socket, data, callback) {
+SocketGroups.issueMassInvite = isOwner(function (socket, data, callback) {
if (!data || !data.usernames || !data.groupName) {
return callback(new Error('[[error:invalid-data]]'));
}
var usernames = data.usernames.split(',');
- usernames = usernames.map(function(username) {
+ usernames = usernames.map(function (username) {
return username && username.trim();
});
- user.getUidsByUsernames(usernames, function(err, uids) {
+ user.getUidsByUsernames(usernames, function (err, uids) {
if (err) {
return callback(err);
}
- uids = uids.filter(function(uid) {
+ uids = uids.filter(function (uid) {
return !!uid && parseInt(uid, 10);
});
- async.eachSeries(uids, function(uid, next) {
+ async.eachSeries(uids, function (uid, next) {
groups.invite(data.groupName, uid, next);
}, callback);
});
});
-SocketGroups.rescindInvite = isOwner(function(socket, data, callback) {
+SocketGroups.rescindInvite = isOwner(function (socket, data, callback) {
groups.rejectMembership(data.groupName, data.toUid, callback);
});
-SocketGroups.acceptInvite = isInvited(function(socket, data, callback) {
+SocketGroups.acceptInvite = isInvited(function (socket, data, callback) {
groups.acceptMembership(data.groupName, socket.uid, callback);
});
-SocketGroups.rejectInvite = isInvited(function(socket, data, callback) {
+SocketGroups.rejectInvite = isInvited(function (socket, data, callback) {
groups.rejectMembership(data.groupName, socket.uid, callback);
});
-SocketGroups.update = isOwner(function(socket, data, callback) {
+SocketGroups.update = isOwner(function (socket, data, callback) {
groups.update(data.groupName, data.values, callback);
});
-SocketGroups.kick = isOwner(function(socket, data, callback) {
+SocketGroups.kick = isOwner(function (socket, data, callback) {
if (socket.uid === parseInt(data.uid, 10)) {
return callback(new Error('[[error:cant-kick-self]]'));
}
- groups.ownership.isOwner(data.uid, data.groupName, function(err, isOwner) {
+ groups.ownership.isOwner(data.uid, data.groupName, function (err, isOwner) {
if (err) {
return callback(err);
}
@@ -188,7 +188,7 @@ SocketGroups.kick = isOwner(function(socket, data, callback) {
});
-SocketGroups.create = function(socket, data, callback) {
+SocketGroups.create = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
} else if (parseInt(meta.config.allowGroupCreation, 10) !== 1) {
@@ -202,7 +202,7 @@ SocketGroups.create = function(socket, data, callback) {
groups.create(data, callback);
};
-SocketGroups.delete = function(socket, data, callback) {
+SocketGroups.delete = function (socket, data, callback) {
if (data.groupName === 'administrators' ||
data.groupName === 'registered-users' ||
data.groupName === 'Global Moderators') {
@@ -212,7 +212,7 @@ SocketGroups.delete = function(socket, data, callback) {
async.parallel({
isOwner: async.apply(groups.ownership.isOwner, socket.uid, data.groupName),
isAdmin: async.apply(user.isAdministrator, socket.uid)
- }, function(err, checks) {
+ }, function (err, checks) {
if (err) {
return callback(err);
}
@@ -224,12 +224,12 @@ SocketGroups.delete = function(socket, data, callback) {
});
};
-SocketGroups.search = function(socket, data, callback) {
+SocketGroups.search = function (socket, data, callback) {
data.options = data.options || {};
if (!data.query) {
var groupsPerPage = 15;
- groupsController.getGroupsFromSet(socket.uid, data.options.sort, 0, groupsPerPage - 1, function(err, data) {
+ groupsController.getGroupsFromSet(socket.uid, data.options.sort, 0, groupsPerPage - 1, function (err, data) {
callback(err, !err ? data.groups : null);
});
return;
@@ -238,7 +238,7 @@ SocketGroups.search = function(socket, data, callback) {
groups.search(data.query, data.options || {}, callback);
};
-SocketGroups.loadMore = function(socket, data, callback) {
+SocketGroups.loadMore = function (socket, data, callback) {
if (!data.sort || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0) {
return callback();
}
@@ -249,17 +249,17 @@ SocketGroups.loadMore = function(socket, data, callback) {
groupsController.getGroupsFromSet(socket.uid, data.sort, start, stop, callback);
};
-SocketGroups.searchMembers = function(socket, data, callback) {
+SocketGroups.searchMembers = function (socket, data, callback) {
data.uid = socket.uid;
groups.searchMembers(data, callback);
};
-SocketGroups.loadMoreMembers = function(socket, data, callback) {
+SocketGroups.loadMoreMembers = function (socket, data, callback) {
if (!data.groupName || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0) {
return callback(new Error('[[error:invalid-data]]'));
}
data.after = parseInt(data.after, 10);
- user.getUsersFromSet('group:' + data.groupName + ':members', socket.uid, data.after, data.after + 9, function(err, users) {
+ user.getUsersFromSet('group:' + data.groupName + ':members', socket.uid, data.after, data.after + 9, function (err, users) {
if (err) {
return callback(err);
}
@@ -270,12 +270,12 @@ SocketGroups.loadMoreMembers = function(socket, data, callback) {
SocketGroups.cover = {};
-SocketGroups.cover.update = function(socket, data, callback) {
+SocketGroups.cover.update = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
}
- groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {
+ groups.ownership.isOwner(socket.uid, data.groupName, function (err, isOwner) {
if (err || !isOwner) {
return callback(err || new Error('[[error:no-privileges]]'));
}
@@ -284,12 +284,12 @@ SocketGroups.cover.update = function(socket, data, callback) {
});
};
-SocketGroups.cover.remove = function(socket, data, callback) {
+SocketGroups.cover.remove = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
}
- groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {
+ groups.ownership.isOwner(socket.uid, data.groupName, function (err, isOwner) {
if (err || !isOwner) {
return callback(err || new Error('[[error:no-privileges]]'));
}
diff --git a/src/socket.io/helpers.js b/src/socket.io/helpers.js
index 46617c2889..54c8152199 100644
--- a/src/socket.io/helpers.js
+++ b/src/socket.io/helpers.js
@@ -15,33 +15,33 @@ var plugins = require('../plugins');
var SocketHelpers = {};
-SocketHelpers.notifyOnlineUsers = function(uid, result) {
+SocketHelpers.notifyOnlineUsers = function (uid, result) {
winston.warn('[deprecated] SocketHelpers.notifyOnlineUsers, consider using socketHelpers.notifyNew(uid, \'newPost\', result);');
SocketHelpers.notifyNew(uid, 'newPost', result);
};
-SocketHelpers.notifyNew = function(uid, type, result) {
+SocketHelpers.notifyNew = function (uid, type, result) {
async.waterfall([
- function(next) {
+ function (next) {
user.getUidsFromSet('users:online', 0, -1, next);
},
- function(uids, next) {
+ function (uids, next) {
privileges.topics.filterUids('read', result.posts[0].topic.tid, uids, next);
},
- function(uids, next) {
+ function (uids, next) {
filterTidCidIgnorers(uids, result.posts[0].topic.tid, result.posts[0].topic.cid, next);
},
- function(uids, next) {
+ function (uids, next) {
plugins.fireHook('filter:sockets.sendNewPostToUids', {uidsTo: uids, uidFrom: uid, type: type}, next);
}
- ], function(err, data) {
+ ], function (err, data) {
if (err) {
return winston.error(err.stack);
}
result.posts[0].ip = undefined;
- data.uidsTo.forEach(function(toUid) {
+ data.uidsTo.forEach(function (toUid) {
if (parseInt(toUid, 10) !== uid) {
websockets.in('uid_' + toUid).emit('event:new_post', result);
if (result.topic && type === 'newTopic') {
@@ -56,19 +56,19 @@ function filterTidCidIgnorers(uids, tid, cid, callback) {
async.waterfall([
function (next) {
async.parallel({
- topicFollowed: function(next) {
+ topicFollowed: function (next) {
db.isSetMembers('tid:' + tid + ':followers', uids, next);
},
- topicIgnored: function(next) {
+ topicIgnored: function (next) {
db.isSetMembers('tid:' + tid + ':ignorers', uids, next);
},
- categoryIgnored: function(next) {
+ categoryIgnored: function (next) {
db.sortedSetScores('cid:' + cid + ':ignorers', uids, next);
}
}, next);
},
function (results, next) {
- uids = uids.filter(function(uid, index) {
+ uids = uids.filter(function (uid, index) {
return results.topicFollowed[index] ||
(!results.topicFollowed[index] && !results.topicIgnored[index] && !results.categoryIgnored[index]);
});
@@ -77,7 +77,7 @@ function filterTidCidIgnorers(uids, tid, cid, callback) {
], callback);
}
-SocketHelpers.sendNotificationToPostOwner = function(pid, fromuid, command, notification) {
+SocketHelpers.sendNotificationToPostOwner = function (pid, fromuid, command, notification) {
if (!pid || !fromuid || !notification) {
return;
}
@@ -116,7 +116,7 @@ SocketHelpers.sendNotificationToPostOwner = function(pid, fromuid, command, noti
topicTitle: results.topicTitle
}, next);
}
- ], function(err, notification) {
+ ], function (err, notification) {
if (err) {
return winston.error(err);
}
@@ -127,7 +127,7 @@ SocketHelpers.sendNotificationToPostOwner = function(pid, fromuid, command, noti
};
-SocketHelpers.sendNotificationToTopicOwner = function(tid, fromuid, command, notification) {
+SocketHelpers.sendNotificationToTopicOwner = function (tid, fromuid, command, notification) {
if (!tid || !fromuid || !notification) {
return;
}
@@ -157,7 +157,7 @@ SocketHelpers.sendNotificationToTopicOwner = function(tid, fromuid, command, not
from: fromuid
}, next);
}
- ], function(err, notification) {
+ ], function (err, notification) {
if (err) {
return winston.error(err);
}
@@ -167,16 +167,16 @@ SocketHelpers.sendNotificationToTopicOwner = function(tid, fromuid, command, not
});
};
-SocketHelpers.rescindUpvoteNotification = function(pid, fromuid) {
+SocketHelpers.rescindUpvoteNotification = function (pid, fromuid) {
var nid = 'upvote:post:' + pid + ':uid:' + fromuid;
notifications.rescind(nid);
- posts.getPostField(pid, 'uid', function(err, uid) {
+ posts.getPostField(pid, 'uid', function (err, uid) {
if (err) {
return winston.error(err);
}
- user.notifications.getUnreadCount(uid, function(err, count) {
+ user.notifications.getUnreadCount(uid, function (err, count) {
if (err) {
return winston.error(err);
}
@@ -186,7 +186,7 @@ SocketHelpers.rescindUpvoteNotification = function(pid, fromuid) {
});
};
-SocketHelpers.emitToTopicAndCategory = function(event, data) {
+SocketHelpers.emitToTopicAndCategory = function (event, data) {
websockets.in('topic_' + data.tid).emit(event, data);
websockets.in('category_' + data.cid).emit(event, data);
};
diff --git a/src/socket.io/index.js b/src/socket.io/index.js
index dedf6aab8e..7df8684d3d 100644
--- a/src/socket.io/index.js
+++ b/src/socket.io/index.js
@@ -12,7 +12,7 @@ var db = require('../database');
var logger = require('../logger');
var ratelimit = require('../middleware/ratelimit');
-(function(Sockets) {
+(function (Sockets) {
var Namespaces = {};
var io;
diff --git a/src/socket.io/meta.js b/src/socket.io/meta.js
index e5c114f372..13fe018654 100644
--- a/src/socket.io/meta.js
+++ b/src/socket.io/meta.js
@@ -11,14 +11,14 @@ var meta = require('../meta'),
rooms: {}
};
-SocketMeta.reconnected = function(socket, data, callback) {
+SocketMeta.reconnected = function (socket, data, callback) {
if (socket.uid) {
topics.pushUnreadCount(socket.uid);
user.notifications.pushCount(socket.uid);
}
};
-emitter.on('nodebb:ready', function() {
+emitter.on('nodebb:ready', function () {
websockets.server.emit('event:nodebb.ready', {
'cache-buster': meta.config['cache-buster']
});
@@ -27,7 +27,7 @@ emitter.on('nodebb:ready', function() {
/* Rooms */
-SocketMeta.rooms.enter = function(socket, data, callback) {
+SocketMeta.rooms.enter = function (socket, data, callback) {
if (!socket.uid) {
return callback();
}
@@ -53,7 +53,7 @@ SocketMeta.rooms.enter = function(socket, data, callback) {
callback();
};
-SocketMeta.rooms.leaveCurrent = function(socket, data, callback) {
+SocketMeta.rooms.leaveCurrent = function (socket, data, callback) {
if (!socket.uid || !socket.currentRoom) {
return callback();
}
@@ -68,7 +68,7 @@ function leaveCurrentRoom(socket) {
}
}
-SocketMeta.getServerTime = function(socket, data, callback) {
+SocketMeta.getServerTime = function (socket, data, callback) {
// Returns server time in milliseconds
callback(null, Date.now());
};
diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js
index d2097ff800..f47ba0f5d7 100644
--- a/src/socket.io/modules.js
+++ b/src/socket.io/modules.js
@@ -19,7 +19,7 @@ var SocketModules = {
/* Chat */
-SocketModules.chats.getRaw = function(socket, data, callback) {
+SocketModules.chats.getRaw = function (socket, data, callback) {
if (!data || !data.hasOwnProperty('mid')) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -36,7 +36,7 @@ SocketModules.chats.getRaw = function(socket, data, callback) {
], callback);
};
-SocketModules.chats.newRoom = function(socket, data, callback) {
+SocketModules.chats.newRoom = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -45,7 +45,7 @@ SocketModules.chats.newRoom = function(socket, data, callback) {
return callback(new Error('[[error:too-many-messages]]'));
}
- Messaging.canMessageUser(socket.uid, data.touid, function(err) {
+ Messaging.canMessageUser(socket.uid, data.touid, function (err) {
if (err) {
return callback(err);
}
@@ -54,7 +54,7 @@ SocketModules.chats.newRoom = function(socket, data, callback) {
});
};
-SocketModules.chats.send = function(socket, data, callback) {
+SocketModules.chats.send = function (socket, data, callback) {
if (!data || !data.roomId || !socket.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -68,7 +68,7 @@ SocketModules.chats.send = function(socket, data, callback) {
plugins.fireHook('filter:messaging.send', {
data: data,
uid: socket.uid
- }, function(err, results) {
+ }, function (err, results) {
data = results.data;
next(err);
});
@@ -99,7 +99,7 @@ function rateLimitExceeded(socket) {
return false;
}
-SocketModules.chats.loadRoom = function(socket, data, callback) {
+SocketModules.chats.loadRoom = function (socket, data, callback) {
if (!data || !data.roomId) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -136,7 +136,7 @@ SocketModules.chats.loadRoom = function(socket, data, callback) {
], callback);
};
-SocketModules.chats.addUserToRoom = function(socket, data, callback) {
+SocketModules.chats.addUserToRoom = function (socket, data, callback) {
if (!data || !data.roomId || !data.username) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -166,7 +166,7 @@ SocketModules.chats.addUserToRoom = function(socket, data, callback) {
], callback);
};
-SocketModules.chats.removeUserFromRoom = function(socket, data, callback) {
+SocketModules.chats.removeUserFromRoom = function (socket, data, callback) {
if (!data || !data.roomId) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -184,7 +184,7 @@ SocketModules.chats.removeUserFromRoom = function(socket, data, callback) {
], callback);
};
-SocketModules.chats.leave = function(socket, roomid, callback) {
+SocketModules.chats.leave = function (socket, roomid, callback) {
if (!socket.uid || !roomid) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -193,12 +193,12 @@ SocketModules.chats.leave = function(socket, roomid, callback) {
};
-SocketModules.chats.edit = function(socket, data, callback) {
+SocketModules.chats.edit = function (socket, data, callback) {
if (!data || !data.roomId) {
return callback(new Error('[[error:invalid-data]]'));
}
- Messaging.canEdit(data.mid, socket.uid, function(err, allowed) {
+ Messaging.canEdit(data.mid, socket.uid, function (err, allowed) {
if (err || !allowed) {
return callback(err || new Error('[[error:cant-edit-chat-message]]'));
}
@@ -207,12 +207,12 @@ SocketModules.chats.edit = function(socket, data, callback) {
});
};
-SocketModules.chats.delete = function(socket, data, callback) {
+SocketModules.chats.delete = function (socket, data, callback) {
if (!data || !data.roomId || !data.messageId) {
return callback(new Error('[[error:invalid-data]]'));
}
- Messaging.canEdit(data.messageId, socket.uid, function(err, allowed) {
+ Messaging.canEdit(data.messageId, socket.uid, function (err, allowed) {
if (err || !allowed) {
return callback(err || new Error('[[error:cant-delete-chat-message]]'));
}
@@ -221,18 +221,18 @@ SocketModules.chats.delete = function(socket, data, callback) {
});
};
-SocketModules.chats.canMessage = function(socket, roomId, callback) {
+SocketModules.chats.canMessage = function (socket, roomId, callback) {
Messaging.canMessageRoom(socket.uid, roomId, callback);
};
-SocketModules.chats.markRead = function(socket, roomId, callback) {
+SocketModules.chats.markRead = function (socket, roomId, callback) {
if (!socket.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
async.parallel({
usersInRoom: async.apply(Messaging.getUidsInRoom, roomId, 0, -1),
markRead: async.apply(Messaging.markRead, socket.uid, roomId)
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -240,13 +240,13 @@ SocketModules.chats.markRead = function(socket, roomId, callback) {
Messaging.pushUnreadCount(socket.uid);
// Mark notification read
- var nids = results.usersInRoom.filter(function(uid) {
+ var nids = results.usersInRoom.filter(function (uid) {
return parseInt(uid, 10) !== socket.uid;
- }).map(function(uid) {
+ }).map(function (uid) {
return 'chat_' + uid + '_' + roomId;
});
- notifications.markReadMultiple(nids, socket.uid, function() {
+ notifications.markReadMultiple(nids, socket.uid, function () {
user.notifications.pushCount(socket.uid);
});
@@ -255,7 +255,7 @@ SocketModules.chats.markRead = function(socket, roomId, callback) {
});
};
-SocketModules.chats.markAllRead = function(socket, data, callback) {
+SocketModules.chats.markAllRead = function (socket, data, callback) {
async.waterfall([
function (next) {
Messaging.markAllRead(socket.uid, next);
@@ -267,7 +267,7 @@ SocketModules.chats.markAllRead = function(socket, data, callback) {
], callback);
};
-SocketModules.chats.renameRoom = function(socket, data, callback) {
+SocketModules.chats.renameRoom = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-name]]'));
}
@@ -281,7 +281,7 @@ SocketModules.chats.renameRoom = function(socket, data, callback) {
},
function (uids, next) {
var eventData = {roomId: data.roomId, newName: validator.escape(String(data.newName))};
- uids.forEach(function(uid) {
+ uids.forEach(function (uid) {
server.in('uid_' + uid).emit('event:chats.roomRename', eventData);
});
next();
@@ -289,7 +289,7 @@ SocketModules.chats.renameRoom = function(socket, data, callback) {
], callback);
};
-SocketModules.chats.getRecentChats = function(socket, data, callback) {
+SocketModules.chats.getRecentChats = function (socket, data, callback) {
if (!data || !utils.isNumber(data.after) || !utils.isNumber(data.uid)) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -298,14 +298,14 @@ SocketModules.chats.getRecentChats = function(socket, data, callback) {
Messaging.getRecentChats(socket.uid, data.uid, start, stop, callback);
};
-SocketModules.chats.hasPrivateChat = function(socket, uid, callback) {
+SocketModules.chats.hasPrivateChat = function (socket, uid, callback) {
if (!socket.uid || !uid) {
return callback(null, new Error('[[error:invalid-data]]'));
}
Messaging.hasPrivateChat(socket.uid, uid, callback);
};
-SocketModules.chats.getMessages = function(socket, data, callback) {
+SocketModules.chats.getMessages = function (socket, data, callback) {
if (!socket.uid || !data.uid || !data.roomId) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -327,16 +327,16 @@ SocketModules.chats.getMessages = function(socket, data, callback) {
};
/* Sounds */
-SocketModules.sounds.getSounds = function(socket, data, callback) {
+SocketModules.sounds.getSounds = function (socket, data, callback) {
// Read sounds from local directory
meta.sounds.getFiles(callback);
};
-SocketModules.sounds.getMapping = function(socket, data, callback) {
+SocketModules.sounds.getMapping = function (socket, data, callback) {
meta.sounds.getMapping(socket.uid, callback);
};
-SocketModules.sounds.getData = function(socket, data, callback) {
+SocketModules.sounds.getData = function (socket, data, callback) {
async.parallel({
mapping: async.apply(meta.sounds.getMapping, socket.uid),
files: async.apply(meta.sounds.getFiles)
diff --git a/src/socket.io/notifications.js b/src/socket.io/notifications.js
index db6753bc40..ea32cd7394 100644
--- a/src/socket.io/notifications.js
+++ b/src/socket.io/notifications.js
@@ -7,7 +7,7 @@ var utils = require('../../public/src/utils');
var SocketNotifs = {};
-SocketNotifs.get = function(socket, data, callback) {
+SocketNotifs.get = function (socket, data, callback) {
if (data && Array.isArray(data.nids) && socket.uid) {
user.notifications.getNotifications(data.nids, socket.uid, callback);
} else {
@@ -15,7 +15,7 @@ SocketNotifs.get = function(socket, data, callback) {
}
};
-SocketNotifs.loadMore = function(socket, data, callback) {
+SocketNotifs.loadMore = function (socket, data, callback) {
if (!data || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -24,7 +24,7 @@ SocketNotifs.loadMore = function(socket, data, callback) {
}
var start = parseInt(data.after, 10);
var stop = start + 20;
- user.notifications.getAll(socket.uid, start, stop, function(err, notifications) {
+ user.notifications.getAll(socket.uid, start, stop, function (err, notifications) {
if (err) {
return callback(err);
}
@@ -32,11 +32,11 @@ SocketNotifs.loadMore = function(socket, data, callback) {
});
};
-SocketNotifs.getCount = function(socket, data, callback) {
+SocketNotifs.getCount = function (socket, data, callback) {
user.notifications.getUnreadCount(socket.uid, callback);
};
-SocketNotifs.deleteAll = function(socket, data, callback) {
+SocketNotifs.deleteAll = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
}
@@ -44,15 +44,15 @@ SocketNotifs.deleteAll = function(socket, data, callback) {
user.notifications.deleteAll(socket.uid, callback);
};
-SocketNotifs.markRead = function(socket, nid, callback) {
+SocketNotifs.markRead = function (socket, nid, callback) {
notifications.markRead(nid, socket.uid, callback);
};
-SocketNotifs.markUnread = function(socket, nid, callback) {
+SocketNotifs.markUnread = function (socket, nid, callback) {
notifications.markUnread(nid, socket.uid, callback);
};
-SocketNotifs.markAllRead = function(socket, data, callback) {
+SocketNotifs.markAllRead = function (socket, data, callback) {
notifications.markAllRead(socket.uid, callback);
};
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index fbb39a5776..379f2315ae 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -22,7 +22,7 @@ require('./posts/bookmarks')(SocketPosts);
require('./posts/tools')(SocketPosts);
require('./posts/flag')(SocketPosts);
-SocketPosts.reply = function(socket, data, callback) {
+SocketPosts.reply = function (socket, data, callback) {
if (!data || !data.tid || !data.content) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -31,7 +31,7 @@ SocketPosts.reply = function(socket, data, callback) {
data.req = websockets.reqFromSocket(socket);
data.timestamp = Date.now();
- topics.reply(data, function(err, postData) {
+ topics.reply(data, function (err, postData) {
if (err) {
return callback(err);
}
@@ -52,18 +52,18 @@ SocketPosts.reply = function(socket, data, callback) {
});
};
-SocketPosts.getRawPost = function(socket, pid, callback) {
+SocketPosts.getRawPost = function (socket, pid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
privileges.posts.can('read', pid, socket.uid, next);
},
- function(canRead, next) {
+ function (canRead, next) {
if (!canRead) {
return next(new Error('[[error:no-privileges]]'));
}
posts.getPostFields(pid, ['content', 'deleted'], next);
},
- function(postData, next) {
+ function (postData, next) {
if (parseInt(postData.deleted, 10) === 1) {
return next(new Error('[[error:no-post]]'));
}
@@ -72,27 +72,27 @@ SocketPosts.getRawPost = function(socket, pid, callback) {
], callback);
};
-SocketPosts.getPost = function(socket, pid, callback) {
+SocketPosts.getPost = function (socket, pid, callback) {
apiController.getPostData(pid, socket.uid, callback);
};
-SocketPosts.loadMoreBookmarks = function(socket, data, callback) {
+SocketPosts.loadMoreBookmarks = function (socket, data, callback) {
loadMorePosts('uid:' + data.uid + ':bookmarks', socket.uid, data, callback);
};
-SocketPosts.loadMoreUserPosts = function(socket, data, callback) {
+SocketPosts.loadMoreUserPosts = function (socket, data, callback) {
loadMorePosts('uid:' + data.uid + ':posts', socket.uid, data, callback);
};
-SocketPosts.loadMoreBestPosts = function(socket, data, callback) {
+SocketPosts.loadMoreBestPosts = function (socket, data, callback) {
loadMorePosts('uid:' + data.uid + ':posts:votes', socket.uid, data, callback);
};
-SocketPosts.loadMoreUpVotedPosts = function(socket, data, callback) {
+SocketPosts.loadMoreUpVotedPosts = function (socket, data, callback) {
loadMorePosts('uid:' + data.uid + ':upvote', socket.uid, data, callback);
};
-SocketPosts.loadMoreDownVotedPosts = function(socket, data, callback) {
+SocketPosts.loadMoreDownVotedPosts = function (socket, data, callback) {
loadMorePosts('uid:' + data.uid + ':downvote', socket.uid, data, callback);
};
@@ -107,11 +107,11 @@ function loadMorePosts(set, uid, data, callback) {
posts.getPostSummariesFromSet(set, uid, start, stop, callback);
}
-SocketPosts.getCategory = function(socket, pid, callback) {
+SocketPosts.getCategory = function (socket, pid, callback) {
posts.getCidByPid(pid, callback);
};
-SocketPosts.getPidIndex = function(socket, data, callback) {
+SocketPosts.getPidIndex = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
diff --git a/src/socket.io/posts/bookmarks.js b/src/socket.io/posts/bookmarks.js
index 3f78af335a..d0bb84256c 100644
--- a/src/socket.io/posts/bookmarks.js
+++ b/src/socket.io/posts/bookmarks.js
@@ -3,13 +3,13 @@
var helpers = require('./helpers');
-module.exports = function(SocketPosts) {
+module.exports = function (SocketPosts) {
- SocketPosts.bookmark = function(socket, data, callback) {
+ SocketPosts.bookmark = function (socket, data, callback) {
helpers.postCommand(socket, 'bookmark', 'bookmarked', '', data, callback);
};
- SocketPosts.unbookmark = function(socket, data, callback) {
+ SocketPosts.unbookmark = function (socket, data, callback) {
helpers.postCommand(socket, 'unbookmark', 'bookmarked', '', data, callback);
};
diff --git a/src/socket.io/posts/edit.js b/src/socket.io/posts/edit.js
index 22b7aa0ea2..63333eac29 100644
--- a/src/socket.io/posts/edit.js
+++ b/src/socket.io/posts/edit.js
@@ -10,9 +10,9 @@ var events = require('../../events');
var meta = require('../../meta');
var websockets = require('../index');
-module.exports = function(SocketPosts) {
+module.exports = function (SocketPosts) {
- SocketPosts.edit = function(socket, data, callback) {
+ SocketPosts.edit = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:not-logged-in]]'));
} else if (!data || !data.pid || !data.content) {
@@ -33,7 +33,7 @@ module.exports = function(SocketPosts) {
data.uid = socket.uid;
data.req = websockets.reqFromSocket(socket);
- posts.edit(data, function(err, result) {
+ posts.edit(data, function (err, result) {
if (err) {
return callback(err);
}
@@ -59,16 +59,16 @@ module.exports = function(SocketPosts) {
async.parallel({
admins: async.apply(groups.getMembers, 'administrators', 0, -1),
moderators: async.apply(groups.getMembers, 'cid:' + result.topic.cid + ':privileges:mods', 0, -1)
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return winston.error(err);
}
- var uids = results.admins.concat(results.moderators).filter(function(uid, index, array) {
+ var uids = results.admins.concat(results.moderators).filter(function (uid, index, array) {
return uid && array.indexOf(uid) === index;
});
- uids.forEach(function(uid) {
+ uids.forEach(function (uid) {
websockets.in('uid_' + uid).emit('event:post_edited', result);
});
});
diff --git a/src/socket.io/posts/flag.js b/src/socket.io/posts/flag.js
index 583de733fb..fd50d4834a 100644
--- a/src/socket.io/posts/flag.js
+++ b/src/socket.io/posts/flag.js
@@ -12,9 +12,9 @@ var notifications = require('../../notifications');
var plugins = require('../../plugins');
var meta = require('../../meta');
-module.exports = function(SocketPosts) {
+module.exports = function (SocketPosts) {
- SocketPosts.flag = function(socket, data, callback) {
+ SocketPosts.flag = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:not-logged-in]]'));
}
@@ -42,10 +42,10 @@ module.exports = function(SocketPosts) {
post.topic = topicData;
async.parallel({
- isAdminOrMod: function(next) {
+ isAdminOrMod: function (next) {
privileges.categories.isAdminOrMod(post.topic.cid, socket.uid, next);
},
- userData: function(next) {
+ userData: function (next) {
user.getUserFields(socket.uid, ['username', 'reputation', 'banned'], next);
}
}, next);
@@ -66,16 +66,16 @@ module.exports = function(SocketPosts) {
},
function (next) {
async.parallel({
- post: function(next) {
+ post: function (next) {
posts.parsePost(post, next);
},
- admins: function(next) {
+ admins: function (next) {
groups.getMembers('administrators', 0, -1, next);
},
globalMods: function (next) {
groups.getMembers('Global Moderators', 0, -1, next);
},
- moderators: function(next) {
+ moderators: function (next) {
groups.getMembers('cid:' + post.topic.cid + ':privileges:mods', 0, -1, next);
}
}, next);
@@ -93,7 +93,7 @@ module.exports = function(SocketPosts) {
from: socket.uid,
mergeId: 'notifications:user_flagged_post_in|' + data.pid,
topicTitle: post.topic.title
- }, function(err, notification) {
+ }, function (err, notification) {
if (err || !notification) {
return next(err);
}
@@ -105,7 +105,7 @@ module.exports = function(SocketPosts) {
], callback);
};
- SocketPosts.dismissFlag = function(socket, pid, callback) {
+ SocketPosts.dismissFlag = function (socket, pid, callback) {
if (!pid || !socket.uid) {
return callback('[[error:invalid-data]]');
}
@@ -122,7 +122,7 @@ module.exports = function(SocketPosts) {
], callback);
};
- SocketPosts.dismissAllFlags = function(socket, data, callback) {
+ SocketPosts.dismissAllFlags = function (socket, data, callback) {
async.waterfall([
function (next) {
user.isAdminOrGlobalMod(socket.uid, next);
@@ -136,7 +136,7 @@ module.exports = function(SocketPosts) {
], callback);
};
- SocketPosts.updateFlag = function(socket, data, callback) {
+ SocketPosts.updateFlag = function (socket, data, callback) {
if (!data || !(data.pid && data.data)) {
return callback('[[error:invalid-data]]');
}
@@ -153,7 +153,7 @@ module.exports = function(SocketPosts) {
}
// Translate form data into object
- payload = data.data.reduce(function(memo, cur) {
+ payload = data.data.reduce(function (memo, cur) {
memo[cur.name] = cur.value;
return memo;
}, payload);
diff --git a/src/socket.io/posts/helpers.js b/src/socket.io/posts/helpers.js
index ad5d46c906..657ab0f64a 100644
--- a/src/socket.io/posts/helpers.js
+++ b/src/socket.io/posts/helpers.js
@@ -9,7 +9,7 @@ var socketHelpers = require('../helpers');
var helpers = module.exports;
-helpers.postCommand = function(socket, command, eventName, notification, data, callback) {
+helpers.postCommand = function (socket, command, eventName, notification, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:not-logged-in]]'));
}
@@ -17,13 +17,13 @@ helpers.postCommand = function(socket, command, eventName, notification, data, c
return callback(new Error('[[error:invalid-data]]'));
}
async.parallel({
- exists: function(next) {
+ exists: function (next) {
posts.exists(data.pid, next);
},
- deleted: function(next) {
+ deleted: function (next) {
posts.getPostField(data.pid, 'deleted', next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err || !results.exists) {
return callback(err || new Error('[[error:invalid-pid]]'));
}
@@ -40,7 +40,7 @@ helpers.postCommand = function(socket, command, eventName, notification, data, c
filter:post.bookmark
filter:post.unbookmark
*/
- plugins.fireHook('filter:post.' + command, {data: data, uid: socket.uid}, function(err, filteredData) {
+ plugins.fireHook('filter:post.' + command, {data: data, uid: socket.uid}, function (err, filteredData) {
if (err) {
return callback(err);
}
@@ -51,7 +51,7 @@ helpers.postCommand = function(socket, command, eventName, notification, data, c
};
function executeCommand(socket, command, eventName, notification, data, callback) {
- posts[command](data.pid, socket.uid, function(err, result) {
+ posts[command](data.pid, socket.uid, function (err, result) {
if (err) {
return callback(err);
}
diff --git a/src/socket.io/posts/move.js b/src/socket.io/posts/move.js
index e73ad58a9a..dc830566eb 100644
--- a/src/socket.io/posts/move.js
+++ b/src/socket.io/posts/move.js
@@ -5,9 +5,9 @@ var privileges = require('../../privileges');
var topics = require('../../topics');
var socketHelpers = require('../helpers');
-module.exports = function(SocketPosts) {
+module.exports = function (SocketPosts) {
- SocketPosts.movePost = function(socket, data, callback) {
+ SocketPosts.movePost = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:not-logged-in]]'));
}
diff --git a/src/socket.io/posts/tools.js b/src/socket.io/posts/tools.js
index e67819965e..ae04ed6c6d 100644
--- a/src/socket.io/posts/tools.js
+++ b/src/socket.io/posts/tools.js
@@ -13,36 +13,36 @@ var privileges = require('../../privileges');
var plugins = require('../../plugins');
var social = require('../../social');
-module.exports = function(SocketPosts) {
+module.exports = function (SocketPosts) {
- SocketPosts.loadPostTools = function(socket, data, callback) {
+ SocketPosts.loadPostTools = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
async.parallel({
- posts: function(next) {
+ posts: function (next) {
posts.getPostFields(data.pid, ['deleted', 'bookmarks', 'uid'], next);
},
- isAdminOrMod: function(next) {
+ isAdminOrMod: function (next) {
privileges.categories.isAdminOrMod(data.cid, socket.uid, next);
},
- canEdit: function(next) {
+ canEdit: function (next) {
privileges.posts.canEdit(data.pid, socket.uid, next);
},
- canDelete: function(next) {
+ canDelete: function (next) {
privileges.posts.canDelete(data.pid, socket.uid, next);
},
- bookmarked: function(next) {
+ bookmarked: function (next) {
posts.hasBookmarked(data.pid, socket.uid, next);
},
- tools: function(next) {
+ tools: function (next) {
plugins.fireHook('filter:post.tools', {pid: data.pid, uid: socket.uid, tools: []}, next);
},
- postSharing: function(next) {
+ postSharing: function (next) {
social.getActivePostSharing(next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -59,27 +59,27 @@ module.exports = function(SocketPosts) {
});
};
- SocketPosts.delete = function(socket, data, callback) {
+ SocketPosts.delete = function (socket, data, callback) {
if (!data || !data.pid) {
return callback(new Error('[[error:invalid-data]]'));
}
var postData;
async.waterfall([
- function(next) {
+ function (next) {
posts.tools.delete(socket.uid, data.pid, next);
},
- function(_postData, next) {
+ function (_postData, next) {
postData = _postData;
isMainAndLastPost(data.pid, next);
},
- function(results, next) {
+ function (results, next) {
if (results.isMain && results.isLast) {
deleteTopicOf(data.pid, socket, next);
} else {
next();
}
},
- function(next) {
+ function (next) {
websockets.in('topic_' + data.tid).emit('event:post_deleted', postData);
events.log({
@@ -94,12 +94,12 @@ module.exports = function(SocketPosts) {
], callback);
};
- SocketPosts.restore = function(socket, data, callback) {
+ SocketPosts.restore = function (socket, data, callback) {
if (!data || !data.pid) {
return callback(new Error('[[error:invalid-data]]'));
}
- posts.tools.restore(socket.uid, data.pid, function(err, postData) {
+ posts.tools.restore(socket.uid, data.pid, function (err, postData) {
if (err) {
return callback(err);
}
@@ -117,34 +117,34 @@ module.exports = function(SocketPosts) {
});
};
- SocketPosts.deletePosts = function(socket, data, callback) {
+ SocketPosts.deletePosts = function (socket, data, callback) {
if (!data || !Array.isArray(data.pids)) {
return callback(new Error('[[error:invalid-data]]'));
}
- async.each(data.pids, function(pid, next) {
+ async.each(data.pids, function (pid, next) {
SocketPosts.delete(socket, {pid: pid, tid: data.tid}, next);
}, callback);
};
- SocketPosts.purgePosts = function(socket, data, callback) {
+ SocketPosts.purgePosts = function (socket, data, callback) {
if (!data || !Array.isArray(data.pids)) {
return callback(new Error('[[error:invalid-data]]'));
}
- async.each(data.pids, function(pid, next) {
+ async.each(data.pids, function (pid, next) {
SocketPosts.purge(socket, {pid: pid, tid: data.tid}, next);
}, callback);
};
- SocketPosts.purge = function(socket, data, callback) {
+ SocketPosts.purge = function (socket, data, callback) {
function purgePost() {
- posts.tools.purge(socket.uid, data.pid, function(err) {
+ posts.tools.purge(socket.uid, data.pid, function (err) {
if (err) {
return callback(err);
}
websockets.in('topic_' + data.tid).emit('event:post_purged', data.pid);
- topics.getTopicField(data.tid, 'title', function(err, title) {
+ topics.getTopicField(data.tid, 'title', function (err, title) {
if (err) {
return winston.error(err);
}
@@ -165,7 +165,7 @@ module.exports = function(SocketPosts) {
return callback(new Error('[[error:invalid-data]]'));
}
- isMainAndLastPost(data.pid, function(err, results) {
+ isMainAndLastPost(data.pid, function (err, results) {
if (err) {
return callback(err);
}
@@ -183,7 +183,7 @@ module.exports = function(SocketPosts) {
};
function deleteTopicOf(pid, socket, callback) {
- posts.getTopicFields(pid, ['tid', 'cid'], function(err, topic) {
+ posts.getTopicFields(pid, ['tid', 'cid'], function (err, topic) {
if (err) {
return callback(err);
}
@@ -193,11 +193,11 @@ module.exports = function(SocketPosts) {
function isMainAndLastPost(pid, callback) {
async.parallel({
- isMain: function(next) {
+ isMain: function (next) {
posts.isMain(pid, next);
},
- isLast: function(next) {
- posts.getTopicFields(pid, ['postcount'], function(err, topic) {
+ isLast: function (next) {
+ posts.getTopicFields(pid, ['postcount'], function (err, topic) {
next(err, topic ? parseInt(topic.postcount, 10) === 1 : false);
});
}
diff --git a/src/socket.io/posts/votes.js b/src/socket.io/posts/votes.js
index 2a31ce87a5..e3a9510aaa 100644
--- a/src/socket.io/posts/votes.js
+++ b/src/socket.io/posts/votes.js
@@ -8,9 +8,9 @@ var posts = require('../../posts');
var privileges = require('../../privileges');
var helpers = require('./helpers');
-module.exports = function(SocketPosts) {
+module.exports = function (SocketPosts) {
- SocketPosts.getVoters = function(socket, data, callback) {
+ SocketPosts.getVoters = function (socket, data, callback) {
if (!data || !data.pid || !data.cid) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -25,26 +25,26 @@ module.exports = function(SocketPosts) {
}
async.parallel({
- upvoteUids: function(next) {
+ upvoteUids: function (next) {
db.getSetMembers('pid:' + data.pid + ':upvote', next);
},
- downvoteUids: function(next) {
+ downvoteUids: function (next) {
db.getSetMembers('pid:' + data.pid + ':downvote', next);
}
}, next);
},
function (results, next) {
async.parallel({
- upvoters: function(next) {
+ upvoters: function (next) {
user.getUsersFields(results.upvoteUids, ['username', 'userslug', 'picture'], next);
},
- upvoteCount: function(next) {
+ upvoteCount: function (next) {
next(null, results.upvoteUids.length);
},
- downvoters: function(next) {
+ downvoters: function (next) {
user.getUsersFields(results.downvoteUids, ['username', 'userslug', 'picture'], next);
},
- downvoteCount: function(next) {
+ downvoteCount: function (next) {
next(null, results.downvoteUids.length);
}
}, next);
@@ -52,23 +52,23 @@ module.exports = function(SocketPosts) {
], callback);
};
- SocketPosts.getUpvoters = function(socket, pids, callback) {
+ SocketPosts.getUpvoters = function (socket, pids, callback) {
if (!Array.isArray(pids)) {
return callback(new Error('[[error:invalid-data]]'));
}
- posts.getUpvotedUidsByPids(pids, function(err, data) {
+ posts.getUpvotedUidsByPids(pids, function (err, data) {
if (err || !Array.isArray(data) || !data.length) {
return callback(err, []);
}
- async.map(data, function(uids, next) {
+ async.map(data, function (uids, next) {
var otherCount = 0;
if (uids.length > 6) {
otherCount = uids.length - 5;
uids = uids.slice(0, 5);
}
- user.getUsernamesByUids(uids, function(err, usernames) {
+ user.getUsernamesByUids(uids, function (err, usernames) {
next(err, {
otherCount: otherCount,
usernames: usernames
@@ -78,15 +78,15 @@ module.exports = function(SocketPosts) {
});
};
- SocketPosts.upvote = function(socket, data, callback) {
+ SocketPosts.upvote = function (socket, data, callback) {
helpers.postCommand(socket, 'upvote', 'voted', 'notifications:upvoted_your_post_in', data, callback);
};
- SocketPosts.downvote = function(socket, data, callback) {
+ SocketPosts.downvote = function (socket, data, callback) {
helpers.postCommand(socket, 'downvote', 'voted', '', data, callback);
};
- SocketPosts.unvote = function(socket, data, callback) {
+ SocketPosts.unvote = function (socket, data, callback) {
helpers.postCommand(socket, 'unvote', 'voted', '', data, callback);
};
};
\ No newline at end of file
diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js
index 5887483242..2fdecf550f 100644
--- a/src/socket.io/topics.js
+++ b/src/socket.io/topics.js
@@ -17,7 +17,7 @@ require('./topics/tools')(SocketTopics);
require('./topics/infinitescroll')(SocketTopics);
require('./topics/tags')(SocketTopics);
-SocketTopics.post = function(socket, data, callback) {
+SocketTopics.post = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -26,7 +26,7 @@ SocketTopics.post = function(socket, data, callback) {
data.req = websockets.reqFromSocket(socket);
data.timestamp = Date.now();
- topics.post(data, function(err, result) {
+ topics.post(data, function (err, result) {
if (err) {
return callback(err);
}
@@ -40,18 +40,18 @@ SocketTopics.post = function(socket, data, callback) {
});
};
-SocketTopics.postcount = function(socket, tid, callback) {
+SocketTopics.postcount = function (socket, tid, callback) {
topics.getTopicField(tid, 'postcount', callback);
};
-SocketTopics.bookmark = function(socket, data, callback) {
+SocketTopics.bookmark = function (socket, data, callback) {
if (!socket.uid || !data) {
return callback(new Error('[[error:invalid-data]]'));
}
topics.setUserBookmark(data.tid, socket.uid, data.index, callback);
};
-SocketTopics.createTopicFromPosts = function(socket, data, callback) {
+SocketTopics.createTopicFromPosts = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:not-logged-in]]'));
}
@@ -63,7 +63,7 @@ SocketTopics.createTopicFromPosts = function(socket, data, callback) {
topics.createTopicFromPosts(socket.uid, data.title, data.pids, data.fromTid, callback);
};
-SocketTopics.changeWatching = function(socket, data, callback) {
+SocketTopics.changeWatching = function (socket, data, callback) {
if (!data.tid || !data.type) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -74,7 +74,7 @@ SocketTopics.changeWatching = function(socket, data, callback) {
followCommand(topics[data.type], socket, data.tid, callback);
};
-SocketTopics.follow = function(socket, tid, callback) {
+SocketTopics.follow = function (socket, tid, callback) {
followCommand(topics.follow, socket, tid, callback);
};
@@ -86,18 +86,18 @@ function followCommand(method, socket, tid, callback) {
method(tid, socket.uid, callback);
}
-SocketTopics.isFollowed = function(socket, tid, callback) {
- topics.isFollowing([tid], socket.uid, function(err, isFollowing) {
+SocketTopics.isFollowed = function (socket, tid, callback) {
+ topics.isFollowing([tid], socket.uid, function (err, isFollowing) {
callback(err, Array.isArray(isFollowing) && isFollowing.length ? isFollowing[0] : false);
});
};
-SocketTopics.search = function(socket, data, callback) {
+SocketTopics.search = function (socket, data, callback) {
topics.search(data.tid, data.term, callback);
};
-SocketTopics.isModerator = function(socket, tid, callback) {
- topics.getTopicField(tid, 'cid', function(err, cid) {
+SocketTopics.isModerator = function (socket, tid, callback) {
+ topics.getTopicField(tid, 'cid', function (err, cid) {
if (err) {
return callback(err);
}
diff --git a/src/socket.io/topics/infinitescroll.js b/src/socket.io/topics/infinitescroll.js
index 7401c60e1f..45c354620a 100644
--- a/src/socket.io/topics/infinitescroll.js
+++ b/src/socket.io/topics/infinitescroll.js
@@ -8,21 +8,21 @@ var meta = require('../../meta');
var utils = require('../../../public/src/utils');
var social = require('../../social');
-module.exports = function(SocketTopics) {
+module.exports = function (SocketTopics) {
- SocketTopics.loadMore = function(socket, data, callback) {
+ SocketTopics.loadMore = function (socket, data, callback) {
if (!data || !data.tid || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0) {
return callback(new Error('[[error:invalid-data]]'));
}
async.parallel({
- privileges: function(next) {
+ privileges: function (next) {
privileges.topics.get(data.tid, socket.uid, next);
},
- topic: function(next) {
+ topic: function (next) {
topics.getTopicFields(data.tid, ['postcount', 'deleted'], next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -58,19 +58,19 @@ module.exports = function(SocketTopics) {
stop = Math.max(0, stop);
async.parallel({
- mainPost: function(next) {
+ mainPost: function (next) {
if (start > 0) {
return next();
}
topics.getMainPost(data.tid, socket.uid, next);
},
- posts: function(next) {
+ posts: function (next) {
topics.getTopicPosts(data.tid, set, start, stop, socket.uid, reverse, next);
},
postSharing: function (next) {
social.getActivePostSharing(next);
}
- }, function(err, topicData) {
+ }, function (err, topicData) {
if (err) {
return callback(err);
}
@@ -88,7 +88,7 @@ module.exports = function(SocketTopics) {
});
};
- SocketTopics.loadMoreUnreadTopics = function(socket, data, callback) {
+ SocketTopics.loadMoreUnreadTopics = function (socket, data, callback) {
if (!data || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -99,7 +99,7 @@ module.exports = function(SocketTopics) {
topics.getUnreadTopics(data.cid, socket.uid, start, stop, data.filter, callback);
};
- SocketTopics.loadMoreFromSet = function(socket, data, callback) {
+ SocketTopics.loadMoreFromSet = function (socket, data, callback) {
if (!data || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0 || !data.set) {
return callback(new Error('[[error:invalid-data]]'));
}
diff --git a/src/socket.io/topics/move.js b/src/socket.io/topics/move.js
index a25947aab5..699c5e5d35 100644
--- a/src/socket.io/topics/move.js
+++ b/src/socket.io/topics/move.js
@@ -6,34 +6,34 @@ var categories = require('../../categories');
var privileges = require('../../privileges');
var socketHelpers = require('../helpers');
-module.exports = function(SocketTopics) {
+module.exports = function (SocketTopics) {
- SocketTopics.move = function(socket, data, callback) {
+ SocketTopics.move = function (socket, data, callback) {
if (!data || !Array.isArray(data.tids) || !data.cid) {
return callback(new Error('[[error:invalid-data]]'));
}
- async.eachLimit(data.tids, 10, function(tid, next) {
+ async.eachLimit(data.tids, 10, function (tid, next) {
var topicData;
async.waterfall([
- function(next) {
+ function (next) {
privileges.topics.isAdminOrMod(tid, socket.uid, next);
},
- function(canMove, next) {
+ function (canMove, next) {
if (!canMove) {
return next(new Error('[[error:no-privileges]]'));
}
next();
},
- function(next) {
+ function (next) {
topics.getTopicFields(tid, ['cid', 'slug'], next);
},
- function(_topicData, next) {
+ function (_topicData, next) {
topicData = _topicData;
topicData.tid = tid;
topics.tools.move(tid, data.cid, socket.uid, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return next(err);
}
@@ -48,7 +48,7 @@ module.exports = function(SocketTopics) {
};
- SocketTopics.moveAll = function(socket, data, callback) {
+ SocketTopics.moveAll = function (socket, data, callback) {
if (!data || !data.cid || !data.currentCid) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -65,7 +65,7 @@ module.exports = function(SocketTopics) {
categories.getTopicIds('cid:' + data.currentCid + ':tids', true, 0, -1, next);
},
function (tids, next) {
- async.eachLimit(tids, 50, function(tid, next) {
+ async.eachLimit(tids, 50, function (tid, next) {
topics.tools.move(tid, data.cid, socket.uid, next);
}, next);
}
diff --git a/src/socket.io/topics/tags.js b/src/socket.io/topics/tags.js
index dc604a450a..ab0a0221ea 100644
--- a/src/socket.io/topics/tags.js
+++ b/src/socket.io/topics/tags.js
@@ -3,23 +3,23 @@
var topics = require('../../topics');
var utils = require('../../../public/src/utils');
-module.exports = function(SocketTopics) {
- SocketTopics.autocompleteTags = function(socket, data, callback) {
+module.exports = function (SocketTopics) {
+ SocketTopics.autocompleteTags = function (socket, data, callback) {
topics.autocompleteTags(data, callback);
};
- SocketTopics.searchTags = function(socket, data, callback) {
+ SocketTopics.searchTags = function (socket, data, callback) {
topics.searchTags(data, callback);
};
- SocketTopics.searchAndLoadTags = function(socket, data, callback) {
+ SocketTopics.searchAndLoadTags = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
topics.searchAndLoadTags(data, callback);
};
- SocketTopics.loadMoreTags = function(socket, data, callback) {
+ SocketTopics.loadMoreTags = function (socket, data, callback) {
if (!data || !utils.isNumber(data.after)) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -27,7 +27,7 @@ module.exports = function(SocketTopics) {
var start = parseInt(data.after, 10);
var stop = start + 99;
- topics.getTags(start, stop, function(err, tags) {
+ topics.getTags(start, stop, function (err, tags) {
if (err) {
return callback(err);
}
diff --git a/src/socket.io/topics/tools.js b/src/socket.io/topics/tools.js
index 2ba98271ae..62e159f9fd 100644
--- a/src/socket.io/topics/tools.js
+++ b/src/socket.io/topics/tools.js
@@ -10,9 +10,9 @@ var privileges = require('../../privileges');
var plugins = require('../../plugins');
var socketHelpers = require('../helpers');
-module.exports = function(SocketTopics) {
+module.exports = function (SocketTopics) {
- SocketTopics.loadTopicTools = function(socket, data, callback) {
+ SocketTopics.loadTopicTools = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
}
@@ -23,10 +23,10 @@ module.exports = function(SocketTopics) {
async.waterfall([
function (next) {
async.parallel({
- topic: function(next) {
+ topic: function (next) {
topics.getTopicData(data.tid, next);
},
- privileges: function(next) {
+ privileges: function (next) {
privileges.topics.get(data.tid, socket.uid, next);
}
}, next);
@@ -46,36 +46,36 @@ module.exports = function(SocketTopics) {
], callback);
};
- SocketTopics.delete = function(socket, data, callback) {
+ SocketTopics.delete = function (socket, data, callback) {
SocketTopics.doTopicAction('delete', 'event:topic_deleted', socket, data, callback);
};
- SocketTopics.restore = function(socket, data, callback) {
+ SocketTopics.restore = function (socket, data, callback) {
SocketTopics.doTopicAction('restore', 'event:topic_restored', socket, data, callback);
};
- SocketTopics.purge = function(socket, data, callback) {
+ SocketTopics.purge = function (socket, data, callback) {
SocketTopics.doTopicAction('purge', 'event:topic_purged', socket, data, callback);
};
- SocketTopics.lock = function(socket, data, callback) {
+ SocketTopics.lock = function (socket, data, callback) {
SocketTopics.doTopicAction('lock', 'event:topic_locked', socket, data, callback);
};
- SocketTopics.unlock = function(socket, data, callback) {
+ SocketTopics.unlock = function (socket, data, callback) {
SocketTopics.doTopicAction('unlock', 'event:topic_unlocked', socket, data, callback);
};
- SocketTopics.pin = function(socket, data, callback) {
+ SocketTopics.pin = function (socket, data, callback) {
SocketTopics.doTopicAction('pin', 'event:topic_pinned', socket, data, callback);
};
- SocketTopics.unpin = function(socket, data, callback) {
+ SocketTopics.unpin = function (socket, data, callback) {
SocketTopics.doTopicAction('unpin', 'event:topic_unpinned', socket, data, callback);
};
- SocketTopics.doTopicAction = function(action, event, socket, data, callback) {
- callback = callback || function() {};
+ SocketTopics.doTopicAction = function (action, event, socket, data, callback) {
+ callback = callback || function () {};
if (!socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
}
@@ -88,8 +88,8 @@ module.exports = function(SocketTopics) {
return callback();
}
- async.each(data.tids, function(tid, next) {
- topics.tools[action](tid, socket.uid, function(err, data) {
+ async.each(data.tids, function (tid, next) {
+ topics.tools[action](tid, socket.uid, function (err, data) {
if (err) {
return next(err);
}
@@ -97,7 +97,7 @@ module.exports = function(SocketTopics) {
socketHelpers.emitToTopicAndCategory(event, data);
if (action === 'delete' || action === 'restore' || action === 'purge') {
- topics.getTopicField(tid, 'title', function(err, title) {
+ topics.getTopicField(tid, 'title', function (err, title) {
if (err) {
return winston.error(err);
}
diff --git a/src/socket.io/topics/unread.js b/src/socket.io/topics/unread.js
index e9279d3f4a..029a0c9e74 100644
--- a/src/socket.io/topics/unread.js
+++ b/src/socket.io/topics/unread.js
@@ -5,14 +5,14 @@ var async = require('async');
var user = require('../../user');
var topics = require('../../topics');
-module.exports = function(SocketTopics) {
+module.exports = function (SocketTopics) {
- SocketTopics.markAsRead = function(socket, tids, callback) {
+ SocketTopics.markAsRead = function (socket, tids, callback) {
if (!Array.isArray(tids) || !socket.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
- topics.markAsRead(tids, socket.uid, function(err) {
+ topics.markAsRead(tids, socket.uid, function (err) {
if (err) {
return callback(err);
}
@@ -25,15 +25,15 @@ module.exports = function(SocketTopics) {
});
};
- SocketTopics.markTopicNotificationsRead = function(socket, tids, callback) {
+ SocketTopics.markTopicNotificationsRead = function (socket, tids, callback) {
if (!Array.isArray(tids) || !socket.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
topics.markTopicNotificationsRead(tids, socket.uid);
};
- SocketTopics.markAllRead = function(socket, data, callback) {
- topics.markAllRead(socket.uid, function(err) {
+ SocketTopics.markAllRead = function (socket, data, callback) {
+ topics.markAllRead(socket.uid, function (err) {
if (err) {
return callback(err);
}
@@ -44,8 +44,8 @@ module.exports = function(SocketTopics) {
});
};
- SocketTopics.markCategoryTopicsRead = function(socket, cid, callback) {
- topics.getUnreadTids(cid, socket.uid, '', function(err, tids) {
+ SocketTopics.markCategoryTopicsRead = function (socket, cid, callback) {
+ topics.getUnreadTids(cid, socket.uid, '', function (err, tids) {
if (err) {
return callback(err);
}
@@ -54,11 +54,11 @@ module.exports = function(SocketTopics) {
});
};
- SocketTopics.markUnread = function(socket, tid, callback) {
+ SocketTopics.markUnread = function (socket, tid, callback) {
if (!tid || !socket.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
- topics.markUnread(tid, socket.uid, function(err) {
+ topics.markUnread(tid, socket.uid, function (err) {
if (err) {
return callback(err);
}
@@ -68,7 +68,7 @@ module.exports = function(SocketTopics) {
});
};
- SocketTopics.markAsUnreadForAll = function(socket, tids, callback) {
+ SocketTopics.markAsUnreadForAll = function (socket, tids, callback) {
if (!Array.isArray(tids)) {
return callback(new Error('[[error:invalid-tid]]'));
}
@@ -77,36 +77,36 @@ module.exports = function(SocketTopics) {
return callback(new Error('[[error:no-privileges]]'));
}
- user.isAdministrator(socket.uid, function(err, isAdmin) {
+ user.isAdministrator(socket.uid, function (err, isAdmin) {
if (err) {
return callback(err);
}
- async.each(tids, function(tid, next) {
+ async.each(tids, function (tid, next) {
async.waterfall([
- function(next) {
+ function (next) {
topics.exists(tid, next);
},
- function(exists, next) {
+ function (exists, next) {
if (!exists) {
return next(new Error('[[error:invalid-tid]]'));
}
topics.getTopicField(tid, 'cid', next);
},
- function(cid, next) {
+ function (cid, next) {
user.isModerator(socket.uid, cid, next);
},
- function(isMod, next) {
+ function (isMod, next) {
if (!isAdmin && !isMod) {
return next(new Error('[[error:no-privileges]]'));
}
topics.markAsUnreadForAll(tid, next);
},
- function(next) {
+ function (next) {
topics.updateRecent(tid, Date.now(), next);
}
], next);
- }, function(err) {
+ }, function (err) {
if (err) {
return callback(err);
}
diff --git a/src/socket.io/user.js b/src/socket.io/user.js
index 0b997d4a66..47d3f6f762 100644
--- a/src/socket.io/user.js
+++ b/src/socket.io/user.js
@@ -22,14 +22,14 @@ require('./user/status')(SocketUser);
require('./user/picture')(SocketUser);
require('./user/ban')(SocketUser);
-SocketUser.exists = function(socket, data, callback) {
+SocketUser.exists = function (socket, data, callback) {
if (!data || !data.username) {
return callback(new Error('[[error:invalid-data]]'));
}
meta.userOrGroupExists(data.username, callback);
};
-SocketUser.deleteAccount = function(socket, data, callback) {
+SocketUser.deleteAccount = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
}
@@ -58,14 +58,14 @@ SocketUser.deleteAccount = function(socket, data, callback) {
], callback);
};
-SocketUser.emailExists = function(socket, data, callback) {
+SocketUser.emailExists = function (socket, data, callback) {
if (!data || !data.email) {
return callback(new Error('[[error:invalid-data]]'));
}
user.email.exists(data.email, callback);
};
-SocketUser.emailConfirm = function(socket, data, callback) {
+SocketUser.emailConfirm = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
}
@@ -73,7 +73,7 @@ SocketUser.emailConfirm = function(socket, data, callback) {
if (parseInt(meta.config.requireEmailConfirmation, 10) !== 1) {
callback();
}
- user.getUserField(socket.uid, 'email', function(err, email) {
+ user.getUserField(socket.uid, 'email', function (err, email) {
if (err || !email) {
return callback(err);
}
@@ -86,12 +86,12 @@ SocketUser.emailConfirm = function(socket, data, callback) {
// Password Reset
SocketUser.reset = {};
-SocketUser.reset.send = function(socket, email, callback) {
+SocketUser.reset.send = function (socket, email, callback) {
if (!email) {
return callback(new Error('[[error:invalid-data]]'));
}
- user.reset.send(email, function(err) {
+ user.reset.send(email, function (err) {
if (err && err.message !== '[[error:invalid-email]]') {
return callback(err);
}
@@ -104,7 +104,7 @@ SocketUser.reset.send = function(socket, email, callback) {
});
};
-SocketUser.reset.commit = function(socket, data, callback) {
+SocketUser.reset.commit = function (socket, data, callback) {
if (!data || !data.code || !data.password) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -112,7 +112,7 @@ SocketUser.reset.commit = function(socket, data, callback) {
async.parallel({
uid: async.apply(db.getObjectField, 'reset:uid', data.code),
reset: async.apply(user.reset.commit, data.code, data.password)
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -121,7 +121,7 @@ SocketUser.reset.commit = function(socket, data, callback) {
var now = new Date();
var parsedDate = now.getFullYear() + '/' + (now.getMonth() + 1) + '/' + now.getDate();
- user.getUserField(uid, 'username', function(err, username) {
+ user.getUserField(uid, 'username', function (err, username) {
if (err) {
return callback(err);
}
@@ -143,7 +143,7 @@ SocketUser.reset.commit = function(socket, data, callback) {
});
};
-SocketUser.isFollowing = function(socket, data, callback) {
+SocketUser.isFollowing = function (socket, data, callback) {
if (!socket.uid || !data.uid) {
return callback(null, false);
}
@@ -151,7 +151,7 @@ SocketUser.isFollowing = function(socket, data, callback) {
user.isFollowing(socket.uid, data.uid, callback);
};
-SocketUser.follow = function(socket, data, callback) {
+SocketUser.follow = function (socket, data, callback) {
if (!socket.uid || !data) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -183,7 +183,7 @@ SocketUser.follow = function(socket, data, callback) {
], callback);
};
-SocketUser.unfollow = function(socket, data, callback) {
+SocketUser.unfollow = function (socket, data, callback) {
if (!socket.uid || !data) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -191,7 +191,7 @@ SocketUser.unfollow = function(socket, data, callback) {
};
function toggleFollow(method, uid, theiruid, callback) {
- user[method](uid, theiruid, function(err) {
+ user[method](uid, theiruid, function (err) {
if (err) {
return callback(err);
}
@@ -204,19 +204,19 @@ function toggleFollow(method, uid, theiruid, callback) {
});
}
-SocketUser.saveSettings = function(socket, data, callback) {
+SocketUser.saveSettings = function (socket, data, callback) {
if (!socket.uid || !data) {
return callback(new Error('[[error:invalid-data]]'));
}
async.waterfall([
- function(next) {
+ function (next) {
if (socket.uid === parseInt(data.uid, 10)) {
return next(null, true);
}
user.isAdminOrGlobalMod(socket.uid, next);
},
- function(allowed, next) {
+ function (allowed, next) {
if (!allowed) {
return next(new Error('[[error:no-privileges]]'));
}
@@ -225,35 +225,35 @@ SocketUser.saveSettings = function(socket, data, callback) {
], callback);
};
-SocketUser.setTopicSort = function(socket, sort, callback) {
+SocketUser.setTopicSort = function (socket, sort, callback) {
if (!socket.uid) {
return callback();
}
user.setSetting(socket.uid, 'topicPostSort', sort, callback);
};
-SocketUser.setCategorySort = function(socket, sort, callback) {
+SocketUser.setCategorySort = function (socket, sort, callback) {
if (!socket.uid) {
return callback();
}
user.setSetting(socket.uid, 'categoryTopicSort', sort, callback);
};
-SocketUser.getUnreadCount = function(socket, data, callback) {
+SocketUser.getUnreadCount = function (socket, data, callback) {
if (!socket.uid) {
return callback(null, 0);
}
topics.getTotalUnread(socket.uid, callback);
};
-SocketUser.getUnreadChatCount = function(socket, data, callback) {
+SocketUser.getUnreadChatCount = function (socket, data, callback) {
if (!socket.uid) {
return callback(null, 0);
}
messaging.getUnreadCount(socket.uid, callback);
};
-SocketUser.getUnreadCounts = function(socket, data, callback) {
+SocketUser.getUnreadCounts = function (socket, data, callback) {
if (!socket.uid) {
return callback(null, {});
}
@@ -265,7 +265,7 @@ SocketUser.getUnreadCounts = function(socket, data, callback) {
}, callback);
};
-SocketUser.invite = function(socket, email, callback) {
+SocketUser.invite = function (socket, email, callback) {
if (!email || !socket.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -278,7 +278,7 @@ SocketUser.invite = function(socket, email, callback) {
var max = meta.config.maximumInvites;
- user.isAdministrator(socket.uid, function(err, admin) {
+ user.isAdministrator(socket.uid, function (err, admin) {
if (err) {
return callback(err);
}
@@ -287,16 +287,16 @@ SocketUser.invite = function(socket, email, callback) {
}
if (max) {
async.waterfall([
- function(next) {
+ function (next) {
user.getInvitesNumber(socket.uid, next);
},
- function(invites, next) {
+ function (invites, next) {
if (!admin && invites > max) {
return next(new Error('[[error:invite-maximum-met, ' + invites + ', ' + max + ']]'));
}
next();
},
- function(next) {
+ function (next) {
user.sendInvitationEmail(socket.uid, email, next);
}
], callback);
@@ -307,28 +307,28 @@ SocketUser.invite = function(socket, email, callback) {
};
-SocketUser.getUserByUID = function(socket, uid, callback) {
+SocketUser.getUserByUID = function (socket, uid, callback) {
apiController.getUserDataByField(socket.uid, 'uid', uid, callback);
};
-SocketUser.getUserByUsername = function(socket, username, callback) {
+SocketUser.getUserByUsername = function (socket, username, callback) {
apiController.getUserDataByField(socket.uid, 'username', username, callback);
};
-SocketUser.getUserByEmail = function(socket, email, callback) {
+SocketUser.getUserByEmail = function (socket, email, callback) {
apiController.getUserDataByField(socket.uid, 'email', email, callback);
};
-SocketUser.setModerationNote = function(socket, data, callback) {
+SocketUser.setModerationNote = function (socket, data, callback) {
if (!socket.uid || !data || !data.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
async.waterfall([
- function(next) {
+ function (next) {
user.isAdminOrGlobalMod(socket.uid, next);
},
- function(isAdminOrGlobalMod, next) {
+ function (isAdminOrGlobalMod, next) {
if (!isAdminOrGlobalMod) {
return next(new Error('[[error:no-privileges]]'));
}
diff --git a/src/socket.io/user/ban.js b/src/socket.io/user/ban.js
index 80f701c1a2..cdc1e20e6d 100644
--- a/src/socket.io/user/ban.js
+++ b/src/socket.io/user/ban.js
@@ -5,9 +5,9 @@ var user = require('../../user');
var websockets = require('../index');
var events = require('../../events');
-module.exports = function(SocketUser) {
+module.exports = function (SocketUser) {
- SocketUser.banUsers = function(socket, data, callback) {
+ SocketUser.banUsers = function (socket, data, callback) {
// Backwards compatibility
if (Array.isArray(data)) {
data = {
@@ -17,13 +17,13 @@ module.exports = function(SocketUser) {
};
}
- toggleBan(socket.uid, data.uids, function(uid, next) {
+ toggleBan(socket.uid, data.uids, function (uid, next) {
banUser(uid, data.until || 0, data.reason || '', next);
- }, function(err) {
+ }, function (err) {
if (err) {
return callback(err);
}
- async.each(data.uids, function(uid, next) {
+ async.each(data.uids, function (uid, next) {
events.log({
type: 'user-ban',
uid: socket.uid,
@@ -34,13 +34,13 @@ module.exports = function(SocketUser) {
});
};
- SocketUser.unbanUsers = function(socket, uids, callback) {
- toggleBan(socket.uid, uids, user.unban, function(err) {
+ SocketUser.unbanUsers = function (socket, uids, callback) {
+ toggleBan(socket.uid, uids, user.unban, function (err) {
if (err) {
return callback(err);
}
- async.each(uids, function(uid, next) {
+ async.each(uids, function (uid, next) {
events.log({
type: 'user-unban',
uid: socket.uid,
diff --git a/src/socket.io/user/picture.js b/src/socket.io/user/picture.js
index e71de5f18c..7539d1687e 100644
--- a/src/socket.io/user/picture.js
+++ b/src/socket.io/user/picture.js
@@ -7,9 +7,9 @@ var path = require('path');
var user = require('../../user');
var plugins = require('../../plugins');
-module.exports = function(SocketUser) {
+module.exports = function (SocketUser) {
- SocketUser.changePicture = function(socket, data, callback) {
+ SocketUser.changePicture = function (socket, data, callback) {
if (!socket.uid) {
return callback('[[error:invalid-uid]]');
}
@@ -37,7 +37,7 @@ module.exports = function(SocketUser) {
uid: socket.uid,
type: type,
picture: undefined
- }, function(err, returnData) {
+ }, function (err, returnData) {
if (err) {
return next(err);
}
@@ -53,22 +53,22 @@ module.exports = function(SocketUser) {
], callback);
};
- SocketUser.uploadProfileImageFromUrl = function(socket, data, callback) {
+ SocketUser.uploadProfileImageFromUrl = function (socket, data, callback) {
if (!socket.uid || !data.url || !data.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
- user.isAdminOrSelf(socket.uid, data.uid, function(err) {
+ user.isAdminOrSelf(socket.uid, data.uid, function (err) {
if (err) {
return callback(err);
}
- user.uploadFromUrl(data.uid, data.url, function(err, uploadedImage) {
+ user.uploadFromUrl(data.uid, data.url, function (err, uploadedImage) {
callback(err, uploadedImage ? uploadedImage.url : null);
});
});
};
- SocketUser.removeUploadedPicture = function(socket, data, callback) {
+ SocketUser.removeUploadedPicture = function (socket, data, callback) {
if (!socket.uid || !data.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -80,9 +80,9 @@ module.exports = function(SocketUser) {
function (next) {
user.getUserFields(data.uid, ['uploadedpicture', 'picture'], next);
},
- function(userData, next) {
+ function (userData, next) {
if (!userData.uploadedpicture.startsWith('http')) {
- require('fs').unlink(path.join(__dirname, '../../../public', userData.uploadedpicture), function(err) {
+ require('fs').unlink(path.join(__dirname, '../../../public', userData.uploadedpicture), function (err) {
if (err) {
winston.error(err);
}
@@ -97,7 +97,7 @@ module.exports = function(SocketUser) {
], callback);
};
- SocketUser.getProfilePictures = function(socket, data, callback) {
+ SocketUser.getProfilePictures = function (socket, data, callback) {
if (!data || !data.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -108,7 +108,7 @@ module.exports = function(SocketUser) {
pictures: []
}),
uploaded: async.apply(user.getUserField, data.uid, 'uploadedpicture')
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return callback(err);
}
diff --git a/src/socket.io/user/profile.js b/src/socket.io/user/profile.js
index 48c0f0fa49..63726cb31d 100644
--- a/src/socket.io/user/profile.js
+++ b/src/socket.io/user/profile.js
@@ -6,9 +6,9 @@ var user = require('../../user');
var meta = require('../../meta');
var events = require('../../events');
-module.exports = function(SocketUser) {
+module.exports = function (SocketUser) {
- SocketUser.changeUsernameEmail = function(socket, data, callback) {
+ SocketUser.changeUsernameEmail = function (socket, data, callback) {
if (!data || !data.uid || !socket.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -23,12 +23,12 @@ module.exports = function(SocketUser) {
], callback);
};
- SocketUser.updateCover = function(socket, data, callback) {
+ SocketUser.updateCover = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
}
- user.isAdministrator(socket.uid, function(err, isAdmin) {
+ user.isAdministrator(socket.uid, function (err, isAdmin) {
if (err) {
return callback(err);
}
@@ -41,12 +41,12 @@ module.exports = function(SocketUser) {
});
};
- SocketUser.removeCover = function(socket, data, callback) {
+ SocketUser.removeCover = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
}
- user.isAdminOrSelf(socket.uid, data.uid, function(err) {
+ user.isAdminOrSelf(socket.uid, data.uid, function (err) {
if (err) {
return callback(err);
}
@@ -58,14 +58,14 @@ module.exports = function(SocketUser) {
async.parallel({
isAdmin: async.apply(user.isAdministrator, uid),
hasPassword: async.apply(user.hasPassword, data.uid),
- passwordMatch: function(next) {
+ passwordMatch: function (next) {
if (data.password) {
user.isPasswordCorrect(data.uid, data.password, next);
} else {
next(null, false);
}
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -83,7 +83,7 @@ module.exports = function(SocketUser) {
});
}
- SocketUser.changePassword = function(socket, data, callback) {
+ SocketUser.changePassword = function (socket, data, callback) {
if (!data || !data.uid) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -91,7 +91,7 @@ module.exports = function(SocketUser) {
return callback('[[error:invalid-uid]]');
}
- user.changePassword(socket.uid, data, function(err) {
+ user.changePassword(socket.uid, data, function (err) {
if (err) {
return callback(err);
}
@@ -106,7 +106,7 @@ module.exports = function(SocketUser) {
});
};
- SocketUser.updateProfile = function(socket, data, callback) {
+ SocketUser.updateProfile = function (socket, data, callback) {
if (!socket.uid) {
return callback('[[error:invalid-uid]]');
}
@@ -128,7 +128,7 @@ module.exports = function(SocketUser) {
user.isAdminOrGlobalMod(socket.uid, next);
},
- function(isAdminOrGlobalMod, next) {
+ function (isAdminOrGlobalMod, next) {
if (!isAdminOrGlobalMod && socket.uid !== parseInt(data.uid, 10)) {
return next(new Error('[[error:no-privileges]]'));
}
diff --git a/src/socket.io/user/search.js b/src/socket.io/user/search.js
index 76b1daa3a7..9c3774089d 100644
--- a/src/socket.io/user/search.js
+++ b/src/socket.io/user/search.js
@@ -4,9 +4,9 @@ var user = require('../../user');
var meta = require('../../meta');
var pagination = require('../../pagination');
-module.exports = function(SocketUser) {
+module.exports = function (SocketUser) {
- SocketUser.search = function(socket, data, callback) {
+ SocketUser.search = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -22,7 +22,7 @@ module.exports = function(SocketUser) {
bannedOnly: data.bannedOnly,
flaggedOnly: data.flaggedOnly,
uid: socket.uid
- }, function(err, result) {
+ }, function (err, result) {
if (err) {
return callback(err);
}
diff --git a/src/socket.io/user/status.js b/src/socket.io/user/status.js
index 4bcd2b0bc9..2ed389dacc 100644
--- a/src/socket.io/user/status.js
+++ b/src/socket.io/user/status.js
@@ -3,13 +3,13 @@
var user = require('../../user');
var websockets = require('../index');
-module.exports = function(SocketUser) {
- SocketUser.checkStatus = function(socket, uid, callback) {
+module.exports = function (SocketUser) {
+ SocketUser.checkStatus = function (socket, uid, callback) {
if (!socket.uid) {
return callback(new Error('[[error:invalid-uid]]'));
}
- user.getUserFields(uid, ['lastonline', 'status'], function(err, userData) {
+ user.getUserFields(uid, ['lastonline', 'status'], function (err, userData) {
if (err) {
return callback(err);
}
@@ -18,7 +18,7 @@ module.exports = function(SocketUser) {
});
};
- SocketUser.setStatus = function(socket, status, callback) {
+ SocketUser.setStatus = function (socket, status, callback) {
if (!socket.uid) {
return callback(new Error('[[error:invalid-uid]]'));
}
@@ -32,7 +32,7 @@ module.exports = function(SocketUser) {
if (status !== 'offline') {
data.lastonline = Date.now();
}
- user.setUserFields(socket.uid, data, function(err) {
+ user.setUserFields(socket.uid, data, function (err) {
if (err) {
return callback(err);
}
diff --git a/src/topics.js b/src/topics.js
index 267b7b174c..d7eb658e3b 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -12,7 +12,7 @@ var categories = require('./categories');
var privileges = require('./privileges');
var social = require('./social');
-(function(Topics) {
+(function (Topics) {
require('./topics/data')(Topics);
require('./topics/create')(Topics);
@@ -30,19 +30,19 @@ var social = require('./social');
require('./topics/tools')(Topics);
require('./topics/thumb')(Topics);
- Topics.exists = function(tid, callback) {
+ Topics.exists = function (tid, callback) {
db.isSortedSetMember('topics:tid', tid, callback);
};
- Topics.getPageCount = function(tid, uid, callback) {
- Topics.getTopicField(tid, 'postcount', function(err, postCount) {
+ Topics.getPageCount = function (tid, uid, callback) {
+ Topics.getTopicField(tid, 'postcount', function (err, postCount) {
if (err) {
return callback(err);
}
if (!parseInt(postCount, 10)) {
return callback(null, 1);
}
- user.getSettings(uid, function(err, settings) {
+ user.getSettings(uid, function (err, settings) {
if (err) {
return callback(err);
}
@@ -52,19 +52,19 @@ var social = require('./social');
});
};
- Topics.getTidPage = function(tid, uid, callback) {
+ Topics.getTidPage = function (tid, uid, callback) {
if(!tid) {
return callback(new Error('[[error:invalid-tid]]'));
}
async.parallel({
- index: function(next) {
+ index: function (next) {
categories.getTopicIndex(tid, next);
},
- settings: function(next) {
+ settings: function (next) {
user.getSettings(uid, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -72,32 +72,32 @@ var social = require('./social');
});
};
- Topics.getTopicsFromSet = function(set, uid, start, stop, callback) {
+ Topics.getTopicsFromSet = function (set, uid, start, stop, callback) {
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRevRange(set, start, stop, next);
},
- function(tids, next) {
+ function (tids, next) {
Topics.getTopics(tids, uid, next);
},
- function(topics, next) {
+ function (topics, next) {
next(null, {topics: topics, nextStart: stop + 1});
}
], callback);
};
- Topics.getTopics = function(tids, uid, callback) {
+ Topics.getTopics = function (tids, uid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
privileges.topics.filterTids('read', tids, uid, next);
},
- function(tids, next) {
+ function (tids, next) {
Topics.getTopicsByTids(tids, uid, next);
}
], callback);
};
- Topics.getTopicsByTids = function(tids, uid, callback) {
+ Topics.getTopicsByTids = function (tids, uid, callback) {
if (!Array.isArray(tids) || !tids.length) {
return callback(null, []);
}
@@ -105,14 +105,14 @@ var social = require('./social');
var uids, cids, topics;
async.waterfall([
- function(next) {
+ function (next) {
Topics.getTopicsData(tids, next);
},
- function(_topics, next) {
+ function (_topics, next) {
function mapFilter(array, field) {
- return array.map(function(topic) {
+ return array.map(function (topic) {
return topic && topic[field] && topic[field].toString();
- }).filter(function(value, index, array) {
+ }).filter(function (value, index, array) {
return utils.isNumber(value) && array.indexOf(value) === index;
});
}
@@ -122,30 +122,30 @@ var social = require('./social');
cids = mapFilter(topics, 'cid');
async.parallel({
- users: function(next) {
+ users: function (next) {
user.getUsersFields(uids, ['uid', 'username', 'fullname', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned', 'status'], next);
},
- categories: function(next) {
+ categories: function (next) {
categories.getCategoriesFields(cids, ['cid', 'name', 'slug', 'icon', 'image', 'bgColor', 'color', 'disabled'], next);
},
- hasRead: function(next) {
+ hasRead: function (next) {
Topics.hasReadTopics(tids, uid, next);
},
- isIgnored: function(next) {
+ isIgnored: function (next) {
Topics.isIgnoring(tids, uid, next);
},
- bookmarks: function(next) {
+ bookmarks: function (next) {
Topics.getUserBookmarks(tids, uid, next);
},
- teasers: function(next) {
+ teasers: function (next) {
Topics.getTeasers(topics, next);
},
- tags: function(next) {
+ tags: function (next) {
Topics.getTopicsTagsObjects(tids, next);
}
}, next);
},
- function(results, next) {
+ function (results, next) {
var users = _.object(uids, results.users);
var categories = _.object(cids, results.categories);
@@ -169,19 +169,19 @@ var social = require('./social');
}
}
- topics = topics.filter(function(topic) {
+ topics = topics.filter(function (topic) {
return topic && topic.category && !topic.category.disabled;
});
plugins.fireHook('filter:topics.get', {topics: topics, uid: uid}, next);
},
- function(data, next) {
+ function (data, next) {
next(null, data.topics);
}
], callback);
};
- Topics.getTopicWithPosts = function(topicData, set, uid, start, stop, reverse, callback) {
+ Topics.getTopicWithPosts = function (topicData, set, uid, start, stop, reverse, callback) {
async.waterfall([
function (next) {
async.parallel({
@@ -192,12 +192,12 @@ var social = require('./social');
isIgnoring: async.apply(Topics.isIgnoring, [topicData.tid], uid),
bookmark: async.apply(Topics.getUserBookmark, topicData.tid, uid),
postSharing: async.apply(social.getActivePostSharing),
- related: function(next) {
+ related: function (next) {
async.waterfall([
- function(next) {
+ function (next) {
Topics.getTopicTagsObjects(topicData.tid, next);
},
- function(tags, next) {
+ function (tags, next) {
topicData.tags = tags;
Topics.getRelatedTopics(topicData, uid, next);
}
@@ -233,10 +233,10 @@ var social = require('./social');
function getMainPostAndReplies(topic, set, uid, start, stop, reverse, callback) {
async.waterfall([
- function(next) {
+ function (next) {
posts.getPidsFromSet(set, start, stop, reverse, next);
},
- function(pids, next) {
+ function (pids, next) {
if ((!Array.isArray(pids) || !pids.length) && !topic.mainPid) {
return callback(null, []);
}
@@ -246,7 +246,7 @@ var social = require('./social');
}
posts.getPostsByPids(pids, uid, next);
},
- function(posts, next) {
+ function (posts, next) {
if (!posts.length) {
return next(null, []);
}
@@ -263,31 +263,31 @@ var social = require('./social');
], callback);
}
- Topics.getMainPost = function(tid, uid, callback) {
- Topics.getMainPosts([tid], uid, function(err, mainPosts) {
+ Topics.getMainPost = function (tid, uid, callback) {
+ Topics.getMainPosts([tid], uid, function (err, mainPosts) {
callback(err, Array.isArray(mainPosts) && mainPosts.length ? mainPosts[0] : null);
});
};
- Topics.getMainPids = function(tids, callback) {
+ Topics.getMainPids = function (tids, callback) {
if (!Array.isArray(tids) || !tids.length) {
return callback(null, []);
}
- Topics.getTopicsFields(tids, ['mainPid'], function(err, topicData) {
+ Topics.getTopicsFields(tids, ['mainPid'], function (err, topicData) {
if (err) {
return callback(err);
}
- var mainPids = topicData.map(function(topic) {
+ var mainPids = topicData.map(function (topic) {
return topic && topic.mainPid;
});
callback(null, mainPids);
});
};
- Topics.getMainPosts = function(tids, uid, callback) {
- Topics.getMainPids(tids, function(err, mainPids) {
+ Topics.getMainPosts = function (tids, uid, callback) {
+ Topics.getMainPids(tids, function (err, mainPids) {
if (err) {
return callback(err);
}
@@ -296,11 +296,11 @@ var social = require('./social');
};
function getMainPosts(mainPids, uid, callback) {
- posts.getPostsByPids(mainPids, uid, function(err, postData) {
+ posts.getPostsByPids(mainPids, uid, function (err, postData) {
if (err) {
return callback(err);
}
- postData.forEach(function(post) {
+ postData.forEach(function (post) {
if (post) {
post.index = 0;
}
@@ -313,28 +313,28 @@ var social = require('./social');
db.sortedSetScore('tid:' + tid + ':bookmarks', uid, callback);
};
- Topics.getUserBookmarks = function(tids, uid, callback) {
+ Topics.getUserBookmarks = function (tids, uid, callback) {
if (!parseInt(uid, 10)) {
- return callback(null, tids.map(function() {
+ return callback(null, tids.map(function () {
return null;
}));
}
- db.sortedSetsScore(tids.map(function(tid) {
+ db.sortedSetsScore(tids.map(function (tid) {
return 'tid:' + tid + ':bookmarks';
}), uid, callback);
};
- Topics.setUserBookmark = function(tid, uid, index, callback) {
+ Topics.setUserBookmark = function (tid, uid, index, callback) {
db.sortedSetAdd('tid:' + tid + ':bookmarks', index, uid, callback);
};
- Topics.isLocked = function(tid, callback) {
- Topics.getTopicField(tid, 'locked', function(err, locked) {
+ Topics.isLocked = function (tid, callback) {
+ Topics.getTopicField(tid, 'locked', function (err, locked) {
callback(err, parseInt(locked, 10) === 1);
});
};
- Topics.search = function(tid, term, callback) {
+ Topics.search = function (tid, term, callback) {
if (plugins.hasListeners('filter:topic.search')) {
plugins.fireHook('filter:topic.search', {
tid: tid,
@@ -345,35 +345,35 @@ var social = require('./social');
}
};
- Topics.getTopicBookmarks = function(tid, callback) {
+ Topics.getTopicBookmarks = function (tid, callback) {
db.getSortedSetRangeWithScores(['tid:' + tid + ':bookmarks'], 0, -1, callback);
};
- Topics.updateTopicBookmarks = function(tid, pids, callback) {
+ Topics.updateTopicBookmarks = function (tid, pids, callback) {
var maxIndex;
async.waterfall([
- function(next) {
+ function (next) {
Topics.getPostCount(tid, next);
},
- function(postcount, next) {
+ function (postcount, next) {
maxIndex = postcount;
Topics.getTopicBookmarks(tid, next);
},
- function(bookmarks, next) {
- var forkedPosts = pids.map(function(pid) {
+ function (bookmarks, next) {
+ var forkedPosts = pids.map(function (pid) {
return {pid: pid, tid: tid};
});
- var uidData = bookmarks.map(function(bookmark) {
+ var uidData = bookmarks.map(function (bookmark) {
return {
uid: bookmark.value,
bookmark: bookmark.score
};
});
- async.eachLimit(uidData, 50, function(data, next) {
- posts.getPostIndices(forkedPosts, data.uid, function(err, postIndices) {
+ async.eachLimit(uidData, 50, function (data, next) {
+ posts.getPostIndices(forkedPosts, data.uid, function (err, postIndices) {
if (err) {
return next(err);
}
@@ -393,7 +393,7 @@ var social = require('./social');
});
}, next);
}
- ], function(err){
+ ], function (err){
callback(err);
});
};
diff --git a/src/topics/create.js b/src/topics/create.js
index 8f017c3c7e..99d8eb1d85 100644
--- a/src/topics/create.js
+++ b/src/topics/create.js
@@ -13,21 +13,21 @@ var posts = require('../posts');
var privileges = require('../privileges');
var categories = require('../categories');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
- Topics.create = function(data, callback) {
+ Topics.create = function (data, callback) {
// This is an internal method, consider using Topics.post instead
var timestamp = data.timestamp || Date.now();
var topicData;
async.waterfall([
- function(next) {
+ function (next) {
Topics.resizeAndUploadThumb(data, next);
},
- function(next) {
+ function (next) {
db.incrObjectField('global', 'nextTid', next);
},
- function(tid, next) {
+ function (tid, next) {
topicData = {
'tid': tid,
'uid': data.uid,
@@ -50,71 +50,71 @@ module.exports = function(Topics) {
plugins.fireHook('filter:topic.create', {topic: topicData, data: data}, next);
},
- function(data, next) {
+ function (data, next) {
topicData = data.topic;
db.setObject('topic:' + topicData.tid, topicData, next);
},
- function(next) {
+ function (next) {
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetsAdd([
'topics:tid',
'cid:' + topicData.cid + ':tids',
'cid:' + topicData.cid + ':uid:' + topicData.uid + ':tids'
], timestamp, topicData.tid, next);
},
- function(next) {
+ function (next) {
categories.updateRecentTid(topicData.cid, topicData.tid, next);
},
- function(next) {
+ function (next) {
user.addTopicIdToUser(topicData.uid, topicData.tid, timestamp, next);
},
- function(next) {
+ function (next) {
db.incrObjectField('category:' + topicData.cid, 'topic_count', next);
},
- function(next) {
+ function (next) {
db.incrObjectField('global', 'topicCount', next);
},
- function(next) {
+ function (next) {
Topics.createTags(data.tags, topicData.tid, timestamp, next);
}
], next);
},
- function(results, next) {
+ function (results, next) {
plugins.fireHook('action:topic.save', topicData);
next(null, topicData.tid);
}
], callback);
};
- Topics.post = function(data, callback) {
+ Topics.post = function (data, callback) {
var uid = data.uid;
var title = data.title ? data.title.trim() : data.title;
data.tags = data.tags || [];
async.waterfall([
- function(next) {
+ function (next) {
check(title, meta.config.minimumTitleLength, meta.config.maximumTitleLength, 'title-too-short', 'title-too-long', next);
},
- function(next) {
+ function (next) {
check(data.tags, meta.config.minimumTagsPerTopic, meta.config.maximumTagsPerTopic, 'not-enough-tags', 'too-many-tags', next);
},
- function(next) {
+ function (next) {
if (data.content) {
data.content = data.content.rtrim();
}
check(data.content, meta.config.minimumPostLength, meta.config.maximumPostLength, 'content-too-short', 'content-too-long', next);
},
- function(next) {
+ function (next) {
categories.exists(data.cid, next);
},
- function(categoryExists, next) {
+ function (categoryExists, next) {
if (!categoryExists) {
return next(new Error('[[error:no-category]]'));
}
privileges.categories.can('topics:create', data.cid, data.uid, next);
},
- function(canCreate, next) {
+ function (canCreate, next) {
if (!canCreate) {
return next(new Error('[[error:no-privileges]]'));
}
@@ -123,29 +123,29 @@ module.exports = function(Topics) {
function (next) {
user.isReadyToPost(data.uid, data.cid, next);
},
- function(next) {
+ function (next) {
plugins.fireHook('filter:topic.post', data, next);
},
- function(filteredData, next) {
+ function (filteredData, next) {
data = filteredData;
Topics.create(data, next);
},
- function(tid, next) {
+ function (tid, next) {
var postData = data;
postData.tid = tid;
postData.ip = data.req ? data.req.ip : null;
posts.create(postData, next);
},
- function(postData, next) {
+ function (postData, next) {
onNewPost(postData, data, next);
},
- function(postData, next) {
+ function (postData, next) {
async.parallel({
- postData: function(next) {
+ postData: function (next) {
next(null, postData);
},
- settings: function(next) {
- user.getSettings(uid, function(err, settings) {
+ settings: function (next) {
+ user.getSettings(uid, function (err, settings) {
if (err) {
return next(err);
}
@@ -156,12 +156,12 @@ module.exports = function(Topics) {
}
});
},
- topicData: function(next) {
+ topicData: function (next) {
Topics.getTopicsByTids([postData.tid], uid, next);
}
}, next);
},
- function(data, next) {
+ function (data, next) {
if (!Array.isArray(data.topicData) || !data.topicData.length) {
return next(new Error('[[error:no-topic]]'));
}
@@ -186,7 +186,7 @@ module.exports = function(Topics) {
], callback);
};
- Topics.reply = function(data, callback) {
+ Topics.reply = function (data, callback) {
var tid = data.tid;
var uid = data.uid;
var content = data.content;
@@ -194,10 +194,10 @@ module.exports = function(Topics) {
var cid;
async.waterfall([
- function(next) {
+ function (next) {
Topics.getTopicField(tid, 'cid', next);
},
- function(_cid, next) {
+ function (_cid, next) {
cid = _cid;
async.parallel({
topicData: async.apply(Topics.getTopicData, tid),
@@ -205,7 +205,7 @@ module.exports = function(Topics) {
isAdminOrMod: async.apply(privileges.categories.isAdminOrMod, cid, uid),
}, next);
},
- function(results, next) {
+ function (results, next) {
if (!results.topicData) {
return next(new Error('[[error:no-topic]]'));
}
@@ -224,13 +224,13 @@ module.exports = function(Topics) {
guestHandleValid(data, next);
},
- function(next) {
+ function (next) {
user.isReadyToPost(uid, cid, next);
},
- function(next) {
+ function (next) {
plugins.fireHook('filter:topic.reply', data, next);
},
- function(filteredData, next) {
+ function (filteredData, next) {
content = filteredData.content || data.content;
if (content) {
content = content.rtrim();
@@ -238,7 +238,7 @@ module.exports = function(Topics) {
check(content, meta.config.minimumPostLength, meta.config.maximumPostLength, 'content-too-short', 'content-too-long', next);
},
- function(next) {
+ function (next) {
posts.create({
uid: uid,
tid: tid,
@@ -249,14 +249,14 @@ module.exports = function(Topics) {
ip: data.req ? data.req.ip : null
}, next);
},
- function(_postData, next) {
+ function (_postData, next) {
postData = _postData;
onNewPost(postData, data, next);
},
- function(postData, next) {
+ function (postData, next) {
user.getSettings(uid, next);
},
- function(settings, next) {
+ function (settings, next) {
if (settings.followTopicsOnReply) {
Topics.follow(postData.tid, uid);
}
@@ -286,16 +286,16 @@ module.exports = function(Topics) {
},
function (markedRead, next) {
async.parallel({
- userInfo: function(next) {
+ userInfo: function (next) {
posts.getUserInfoForPosts([postData.uid], uid, next);
},
- topicInfo: function(next) {
+ topicInfo: function (next) {
Topics.getTopicFields(tid, ['tid', 'title', 'slug', 'cid', 'postcount', 'mainPid'], next);
},
- parents: function(next) {
+ parents: function (next) {
Topics.addParentPosts([postData], next);
},
- content: function(next) {
+ content: function (next) {
posts.parsePost(postData, next);
}
}, next);
@@ -339,7 +339,7 @@ module.exports = function(Topics) {
if (data.handle.length > meta.config.maximumUsernameLength) {
return callback(new Error('[[error:guest-handle-invalid]]'));
}
- user.existsBySlug(utils.slugify(data.handle), function(err, exists) {
+ user.existsBySlug(utils.slugify(data.handle), function (err, exists) {
if (err || exists) {
return callback(err || new Error('[[error:username-taken]]'));
}
diff --git a/src/topics/data.js b/src/topics/data.js
index 9a7553f2b0..a0196e1508 100644
--- a/src/topics/data.js
+++ b/src/topics/data.js
@@ -6,28 +6,28 @@ var db = require('../database');
var categories = require('../categories');
var utils = require('../../public/src/utils');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
- Topics.getTopicField = function(tid, field, callback) {
+ Topics.getTopicField = function (tid, field, callback) {
db.getObjectField('topic:' + tid, field, callback);
};
- Topics.getTopicFields = function(tid, fields, callback) {
+ Topics.getTopicFields = function (tid, fields, callback) {
db.getObjectFields('topic:' + tid, fields, callback);
};
- Topics.getTopicsFields = function(tids, fields, callback) {
+ Topics.getTopicsFields = function (tids, fields, callback) {
if (!Array.isArray(tids) || !tids.length) {
return callback(null, []);
}
- var keys = tids.map(function(tid) {
+ var keys = tids.map(function (tid) {
return 'topic:' + tid;
});
db.getObjectsFields(keys, fields, callback);
};
- Topics.getTopicData = function(tid, callback) {
- db.getObject('topic:' + tid, function(err, topic) {
+ Topics.getTopicData = function (tid, callback) {
+ db.getObject('topic:' + tid, function (err, topic) {
if (err || !topic) {
return callback(err);
}
@@ -37,14 +37,14 @@ module.exports = function(Topics) {
});
};
- Topics.getTopicsData = function(tids, callback) {
+ Topics.getTopicsData = function (tids, callback) {
var keys = [];
for (var i = 0; i < tids.length; ++i) {
keys.push('topic:' + tids[i]);
}
- db.getObjects(keys, function(err, topics) {
+ db.getObjects(keys, function (err, topics) {
if (err) {
return callback(err);
}
@@ -64,8 +64,8 @@ module.exports = function(Topics) {
topic.lastposttimeISO = utils.toISOString(topic.lastposttime);
}
- Topics.getCategoryData = function(tid, callback) {
- Topics.getTopicField(tid, 'cid', function(err, cid) {
+ Topics.getCategoryData = function (tid, callback) {
+ Topics.getTopicField(tid, 'cid', function (err, cid) {
if (err) {
return callback(err);
}
@@ -74,17 +74,17 @@ module.exports = function(Topics) {
});
};
- Topics.setTopicField = function(tid, field, value, callback) {
+ Topics.setTopicField = function (tid, field, value, callback) {
db.setObjectField('topic:' + tid, field, value, callback);
};
- Topics.setTopicFields = function(tid, data, callback) {
- callback = callback || function() {};
+ Topics.setTopicFields = function (tid, data, callback) {
+ callback = callback || function () {};
db.setObject('topic:' + tid, data, callback);
};
- Topics.deleteTopicField = function(tid, field, callback) {
+ Topics.deleteTopicField = function (tid, field, callback) {
db.deleteObjectField('topic:' + tid, field, callback);
};
diff --git a/src/topics/delete.js b/src/topics/delete.js
index cf6ae01d8d..df63ebe3bc 100644
--- a/src/topics/delete.js
+++ b/src/topics/delete.js
@@ -9,69 +9,69 @@ var plugins = require('../plugins');
var batch = require('../batch');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
- Topics.delete = function(tid, uid, callback) {
- Topics.getTopicFields(tid, ['cid'], function(err, topicData) {
+ Topics.delete = function (tid, uid, callback) {
+ Topics.getTopicFields(tid, ['cid'], function (err, topicData) {
if (err) {
return callback(err);
}
async.parallel([
- function(next) {
+ function (next) {
Topics.setTopicField(tid, 'deleted', 1, next);
},
- function(next) {
+ function (next) {
db.sortedSetsRemove(['topics:recent', 'topics:posts', 'topics:views'], tid, next);
},
- function(next) {
- Topics.getPids(tid, function(err, pids) {
+ function (next) {
+ Topics.getPids(tid, function (err, pids) {
if (err) {
return next(err);
}
db.sortedSetRemove('cid:' + topicData.cid + ':pids', pids, next);
});
}
- ], function(err) {
+ ], function (err) {
callback(err);
});
});
};
- Topics.restore = function(tid, uid, callback) {
- Topics.getTopicFields(tid, ['cid', 'lastposttime', 'postcount', 'viewcount'], function(err, topicData) {
+ Topics.restore = function (tid, uid, callback) {
+ Topics.getTopicFields(tid, ['cid', 'lastposttime', 'postcount', 'viewcount'], function (err, topicData) {
if (err) {
return callback(err);
}
async.parallel([
- function(next) {
+ function (next) {
Topics.setTopicField(tid, 'deleted', 0, next);
},
- function(next) {
+ function (next) {
Topics.updateRecent(tid, topicData.lastposttime, next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('topics:posts', topicData.postcount, tid, next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('topics:views', topicData.viewcount, tid, next);
},
- function(next) {
- Topics.getPids(tid, function(err, pids) {
+ function (next) {
+ Topics.getPids(tid, function (err, pids) {
if (err) {
return callback(err);
}
- posts.getPostsFields(pids, ['pid', 'timestamp', 'deleted'], function(err, postData) {
+ posts.getPostsFields(pids, ['pid', 'timestamp', 'deleted'], function (err, postData) {
if (err) {
return next(err);
}
- postData = postData.filter(function(post) {
+ postData = postData.filter(function (post) {
return post && parseInt(post.deleted, 10) !== 1;
});
var pidsToAdd = [], scores = [];
- postData.forEach(function(post) {
+ postData.forEach(function (post) {
pidsToAdd.push(post.pid);
scores.push(post.timestamp);
});
@@ -79,13 +79,13 @@ module.exports = function(Topics) {
});
});
}
- ], function(err) {
+ ], function (err) {
callback(err);
});
});
};
- Topics.purgePostsAndTopic = function(tid, uid, callback) {
+ Topics.purgePostsAndTopic = function (tid, uid, callback) {
var mainPid;
async.waterfall([
function (next) {
@@ -93,8 +93,8 @@ module.exports = function(Topics) {
},
function (_mainPid, next) {
mainPid = _mainPid;
- batch.processSortedSet('tid:' + tid + ':posts', function(pids, next) {
- async.eachLimit(pids, 10, function(pid, next) {
+ batch.processSortedSet('tid:' + tid + ':posts', function (pids, next) {
+ async.eachLimit(pids, 10, function (pid, next) {
posts.purge(pid, uid, next);
}, next);
}, {alwaysStartAt: 0}, next);
@@ -108,14 +108,14 @@ module.exports = function(Topics) {
], callback);
};
- Topics.purge = function(tid, uid, callback) {
+ Topics.purge = function (tid, uid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
deleteFromFollowersIgnorers(tid, next);
},
- function(next) {
+ function (next) {
async.parallel([
- function(next) {
+ function (next) {
db.deleteAll([
'tid:' + tid + ':followers',
'tid:' + tid + ':ignorers',
@@ -125,21 +125,21 @@ module.exports = function(Topics) {
'tid:' + tid + ':posters'
], next);
},
- function(next) {
+ function (next) {
db.sortedSetsRemove(['topics:tid', 'topics:recent', 'topics:posts', 'topics:views'], tid, next);
},
- function(next) {
+ function (next) {
deleteTopicFromCategoryAndUser(tid, next);
},
- function(next) {
+ function (next) {
Topics.deleteTopicTags(tid, next);
},
- function(next) {
+ function (next) {
reduceCounters(tid, next);
}
], next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
@@ -150,17 +150,17 @@ module.exports = function(Topics) {
function deleteFromFollowersIgnorers(tid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
async.parallel({
followers: async.apply(db.getSetMembers, 'tid:' + tid + ':followers'),
ignorers: async.apply(db.getSetMembers, 'tid:' + tid + ':ignorers')
}, next);
},
- function(results, next) {
- var followerKeys = results.followers.map(function(uid) {
+ function (results, next) {
+ var followerKeys = results.followers.map(function (uid) {
return 'uid:' + uid + ':followed_tids';
});
- var ignorerKeys = results.ignorers.map(function(uid) {
+ var ignorerKeys = results.ignorers.map(function (uid) {
return 'uid:' + uid + 'ignored_tids';
});
db.sortedSetsRemove(followerKeys.concat(ignorerKeys), tid, next);
@@ -169,12 +169,12 @@ module.exports = function(Topics) {
}
function deleteTopicFromCategoryAndUser(tid, callback) {
- Topics.getTopicFields(tid, ['cid', 'uid'], function(err, topicData) {
+ Topics.getTopicFields(tid, ['cid', 'uid'], function (err, topicData) {
if (err) {
return callback(err);
}
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetsRemove([
'cid:' + topicData.cid + ':tids',
'cid:' + topicData.cid + ':tids:posts',
@@ -182,7 +182,7 @@ module.exports = function(Topics) {
'uid:' + topicData.uid + ':topics'
], tid, next);
},
- function(next) {
+ function (next) {
user.decrementUserFieldBy(topicData.uid, 'topiccount', 1, next);
}
], callback);
@@ -192,11 +192,11 @@ module.exports = function(Topics) {
function reduceCounters(tid, callback) {
var incr = -1;
async.parallel([
- function(next) {
+ function (next) {
db.incrObjectFieldBy('global', 'topicCount', incr, next);
},
- function(next) {
- Topics.getTopicFields(tid, ['cid', 'postcount'], function(err, topicData) {
+ function (next) {
+ Topics.getTopicFields(tid, ['cid', 'postcount'], function (err, topicData) {
if (err) {
return next(err);
}
@@ -205,13 +205,13 @@ module.exports = function(Topics) {
var postCountChange = incr * topicData.postcount;
async.parallel([
- function(next) {
+ function (next) {
db.incrObjectFieldBy('global', 'postCount', postCountChange, next);
},
- function(next) {
+ function (next) {
db.incrObjectFieldBy('category:' + topicData.cid, 'post_count', postCountChange, next);
},
- function(next) {
+ function (next) {
db.incrObjectFieldBy('category:' + topicData.cid, 'topic_count', incr, next);
}
], next);
diff --git a/src/topics/follow.js b/src/topics/follow.js
index 23d2cf14cd..b68e7beb26 100644
--- a/src/topics/follow.js
+++ b/src/topics/follow.js
@@ -15,10 +15,10 @@ var meta = require('../meta');
var emailer = require('../emailer');
var plugins = require('../plugins');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
- Topics.toggleFollow = function(tid, uid, callback) {
- callback = callback || function() {};
+ Topics.toggleFollow = function (tid, uid, callback) {
+ callback = callback || function () {};
var isFollowing;
async.waterfall([
function (next) {
@@ -38,26 +38,26 @@ module.exports = function(Topics) {
Topics.follow(tid, uid, next);
}
},
- function(next) {
+ function (next) {
next(null, !isFollowing);
}
], callback);
};
- Topics.follow = function(tid, uid, callback) {
+ Topics.follow = function (tid, uid, callback) {
setWatching(follow, unignore, 'action:topic.follow', tid, uid, callback);
};
- Topics.unfollow = function(tid, uid, callback) {
+ Topics.unfollow = function (tid, uid, callback) {
setWatching(unfollow, unignore, 'action:topic.unfollow', tid, uid, callback);
};
- Topics.ignore = function(tid, uid, callback) {
+ Topics.ignore = function (tid, uid, callback) {
setWatching(ignore, unfollow, 'action:topic.ignore', tid, uid, callback);
};
function setWatching(method1, method2, hook, tid, uid, callback) {
- callback = callback || function() {};
+ callback = callback || function () {};
if (!parseInt(uid, 10)) {
return callback();
}
@@ -99,7 +99,7 @@ module.exports = function(Topics) {
function (next) {
db.setAdd(set1, uid, next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd(set2, Date.now(), tid, next);
}
], callback);
@@ -110,17 +110,17 @@ module.exports = function(Topics) {
function (next) {
db.setRemove(set1, uid, next);
},
- function(next) {
+ function (next) {
db.sortedSetRemove(set2, tid, next);
}
], callback);
}
- Topics.isFollowing = function(tids, uid, callback) {
+ Topics.isFollowing = function (tids, uid, callback) {
isIgnoringOrFollowing('followers', tids, uid, callback);
};
- Topics.isIgnoring = function(tids, uid, callback) {
+ Topics.isIgnoring = function (tids, uid, callback) {
isIgnoringOrFollowing('ignorers', tids, uid, callback);
};
@@ -129,29 +129,29 @@ module.exports = function(Topics) {
return callback();
}
if (!parseInt(uid, 10)) {
- return callback(null, tids.map(function() { return false; }));
+ return callback(null, tids.map(function () { return false; }));
}
- var keys = tids.map(function(tid) {
+ var keys = tids.map(function (tid) {
return 'tid:' + tid + ':' + set;
});
db.isMemberOfSets(keys, uid, callback);
}
- Topics.getFollowers = function(tid, callback) {
+ Topics.getFollowers = function (tid, callback) {
db.getSetMembers('tid:' + tid + ':followers', callback);
};
- Topics.getIgnorers = function(tid, callback) {
+ Topics.getIgnorers = function (tid, callback) {
db.getSetMembers('tid:' + tid + ':ignorers', callback);
};
- Topics.filterIgnoringUids = function(tid, uids, callback) {
+ Topics.filterIgnoringUids = function (tid, uids, callback) {
async.waterfall([
function (next){
db.isSetMembers('tid:' + tid + ':ignorers', uids, next);
},
function (isMembers, next){
- var readingUids = uids.filter(function(uid, index) {
+ var readingUids = uids.filter(function (uid, index) {
return uid && isMembers[index];
});
next(null, readingUids);
@@ -159,8 +159,8 @@ module.exports = function(Topics) {
], callback);
};
- Topics.notifyFollowers = function(postData, exceptUid, callback) {
- callback = callback || function() {};
+ Topics.notifyFollowers = function (postData, exceptUid, callback) {
+ callback = callback || function () {};
var followers;
var title;
var titleEscaped;
@@ -218,11 +218,11 @@ module.exports = function(Topics) {
return next();
}
- async.eachLimit(followers, 3, function(toUid, next) {
+ async.eachLimit(followers, 3, function (toUid, next) {
async.parallel({
userData: async.apply(user.getUserFields, toUid, ['username', 'userslug']),
userSettings: async.apply(user.getSettings, toUid)
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return next(err);
}
diff --git a/src/topics/fork.js b/src/topics/fork.js
index fbc9cdb54c..c1cd019a90 100644
--- a/src/topics/fork.js
+++ b/src/topics/fork.js
@@ -11,9 +11,9 @@ var plugins = require('../plugins');
var meta = require('../meta');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
- Topics.createTopicFromPosts = function(uid, title, pids, fromTid, callback) {
+ Topics.createTopicFromPosts = function (uid, title, pids, fromTid, callback) {
if (title) {
title = title.trim();
}
@@ -28,39 +28,39 @@ module.exports = function(Topics) {
return callback(new Error('[[error:invalid-pid]]'));
}
- pids.sort(function(a, b) {
+ pids.sort(function (a, b) {
return a - b;
});
var mainPid = pids[0];
var cid;
var tid;
async.waterfall([
- function(next) {
+ function (next) {
posts.getCidByPid(mainPid, next);
},
- function(_cid, next) {
+ function (_cid, next) {
cid = _cid;
async.parallel({
- postData: function(next) {
+ postData: function (next) {
posts.getPostData(mainPid, next);
},
- isAdminOrMod: function(next) {
+ isAdminOrMod: function (next) {
privileges.categories.isAdminOrMod(cid, uid, next);
}
}, next);
},
- function(results, next) {
+ function (results, next) {
if (!results.isAdminOrMod) {
return next(new Error('[[error:no-privileges]]'));
}
Topics.create({uid: results.postData.uid, title: title, cid: cid}, next);
},
- function(results, next) {
- Topics.updateTopicBookmarks(fromTid, pids, function(){ next( null, results );} );
+ function (results, next) {
+ Topics.updateTopicBookmarks(fromTid, pids, function (){ next( null, results );} );
},
- function(_tid, next) {
+ function (_tid, next) {
function move(pid, next) {
- privileges.posts.canEdit(pid, uid, function(err, canEdit) {
+ privileges.posts.canEdit(pid, uid, function (err, canEdit) {
if (err || !canEdit.flag) {
return next(err || new Error(canEdit.message));
}
@@ -71,28 +71,28 @@ module.exports = function(Topics) {
tid = _tid;
async.eachSeries(pids, move, next);
},
- function(next) {
+ function (next) {
Topics.updateTimestamp(tid, Date.now(), next);
},
- function(next) {
+ function (next) {
Topics.getTopicData(tid, next);
}
], callback);
};
- Topics.movePostToTopic = function(pid, tid, callback) {
+ Topics.movePostToTopic = function (pid, tid, callback) {
var postData;
async.waterfall([
- function(next) {
+ function (next) {
Topics.exists(tid, next);
},
- function(exists, next) {
+ function (exists, next) {
if (!exists) {
return next(new Error('[[error:no-topic]]'));
}
posts.getPostFields(pid, ['tid', 'uid', 'timestamp', 'upvotes', 'downvotes'], next);
},
- function(post, next) {
+ function (post, next) {
if (!post || !post.tid) {
return next(new Error('[[error:no-post]]'));
}
@@ -106,32 +106,32 @@ module.exports = function(Topics) {
Topics.removePostFromTopic(postData.tid, postData, next);
},
- function(next) {
+ function (next) {
async.parallel([
- function(next) {
+ function (next) {
updateCategoryPostCount(postData.tid, tid, next);
},
- function(next) {
+ function (next) {
Topics.decreasePostCount(postData.tid, next);
},
- function(next) {
+ function (next) {
Topics.increasePostCount(tid, next);
},
- function(next) {
+ function (next) {
posts.setPostField(pid, 'tid', tid, next);
},
- function(next) {
+ function (next) {
Topics.addPostToTopic(tid, postData, next);
}
], next);
},
- function(results, next) {
+ function (results, next) {
async.parallel([
async.apply(updateRecentTopic, tid),
async.apply(updateRecentTopic, postData.tid)
], next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
@@ -141,7 +141,7 @@ module.exports = function(Topics) {
};
function updateCategoryPostCount(oldTid, tid, callback) {
- Topics.getTopicsFields([oldTid, tid], ['cid'], function(err, topicData) {
+ Topics.getTopicsFields([oldTid, tid], ['cid'], function (err, topicData) {
if (err) {
return callback(err);
}
@@ -160,16 +160,16 @@ module.exports = function(Topics) {
function updateRecentTopic(tid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
Topics.getLatestUndeletedPid(tid, next);
},
- function(pid, next) {
+ function (pid, next) {
if (!pid) {
return callback();
}
posts.getPostField(pid, 'timestamp', next);
},
- function(timestamp, next) {
+ function (timestamp, next) {
Topics.updateTimestamp(tid, timestamp, next);
}
], callback);
diff --git a/src/topics/popular.js b/src/topics/popular.js
index 5ab53ae613..452f897581 100644
--- a/src/topics/popular.js
+++ b/src/topics/popular.js
@@ -4,9 +4,9 @@
var async = require('async');
var privileges = require('../privileges');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
- Topics.getPopular = function(term, uid, count, callback) {
+ Topics.getPopular = function (term, uid, count, callback) {
count = parseInt(count, 10) || 20;
if (term === 'alltime') {
@@ -14,37 +14,37 @@ module.exports = function(Topics) {
}
async.waterfall([
- function(next) {
+ function (next) {
Topics.getLatestTidsFromSet('topics:tid', 0, -1, term, next);
},
- function(tids, next) {
+ function (tids, next) {
getTopics(tids, uid, count, next);
}
], callback);
};
function getAllTimePopular(uid, count, callback) {
- Topics.getTopicsFromSet('topics:posts', uid, 0, count - 1, function(err, data) {
+ Topics.getTopicsFromSet('topics:posts', uid, 0, count - 1, function (err, data) {
callback(err, data ? data.topics : null);
});
}
function getTopics(tids, uid, count, callback) {
async.waterfall([
- function(next) {
+ function (next) {
Topics.getTopicsFields(tids, ['tid', 'postcount', 'deleted'], next);
},
- function(topics, next) {
- tids = topics.filter(function(topic) {
+ function (topics, next) {
+ tids = topics.filter(function (topic) {
return topic && parseInt(topic.deleted, 10) !== 1;
- }).sort(function(a, b) {
+ }).sort(function (a, b) {
return b.postcount - a.postcount;
- }).slice(0, count).map(function(topic) {
+ }).slice(0, count).map(function (topic) {
return topic.tid;
});
privileges.topics.filterTids('read', tids, uid, next);
},
- function(tids, next) {
+ function (tids, next) {
Topics.getTopicsByTids(tids, uid, next);
}
], callback);
diff --git a/src/topics/posts.js b/src/topics/posts.js
index b493a5a7cd..6e15c62b7c 100644
--- a/src/topics/posts.js
+++ b/src/topics/posts.js
@@ -10,32 +10,32 @@ var user = require('../user');
var posts = require('../posts');
var meta = require('../meta');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
- Topics.onNewPostMade = function(postData, callback) {
+ Topics.onNewPostMade = function (postData, callback) {
async.series([
- function(next) {
+ function (next) {
Topics.increasePostCount(postData.tid, next);
},
- function(next) {
+ function (next) {
Topics.updateTimestamp(postData.tid, postData.timestamp, next);
},
- function(next) {
+ function (next) {
Topics.addPostToTopic(postData.tid, postData, next);
}
], callback);
};
- Topics.getTopicPosts = function(tid, set, start, stop, uid, reverse, callback) {
- callback = callback || function() {};
+ Topics.getTopicPosts = function (tid, set, start, stop, uid, reverse, callback) {
+ callback = callback || function () {};
async.parallel({
- posts: function(next) {
+ posts: function (next) {
posts.getPostsFromSet(set, start, stop, uid, reverse, next);
},
- postCount: function(next) {
+ postCount: function (next) {
Topics.getTopicField(tid, 'postcount', next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -46,11 +46,11 @@ module.exports = function(Topics) {
});
};
- Topics.addPostData = function(postData, uid, callback) {
+ Topics.addPostData = function (postData, uid, callback) {
if (!Array.isArray(postData) || !postData.length) {
return callback(null, []);
}
- var pids = postData.map(function(post) {
+ var pids = postData.map(function (post) {
return post && post.pid;
});
@@ -59,13 +59,13 @@ module.exports = function(Topics) {
}
async.parallel({
- bookmarks: function(next) {
+ bookmarks: function (next) {
posts.hasBookmarked(pids, uid, next);
},
- voteData: function(next) {
+ voteData: function (next) {
posts.getVoteStatusByPostIDs(pids, uid, next);
},
- userData: function(next) {
+ userData: function (next) {
var uids = [];
for(var i = 0; i < postData.length; ++i) {
@@ -74,20 +74,20 @@ module.exports = function(Topics) {
}
}
- posts.getUserInfoForPosts(uids, uid, function(err, users) {
+ posts.getUserInfoForPosts(uids, uid, function (err, users) {
if (err) {
return next(err);
}
var userData = {};
- users.forEach(function(user, index) {
+ users.forEach(function (user, index) {
userData[uids[index]] = user;
});
next(null, userData);
});
},
- editors: function(next) {
+ editors: function (next) {
var editors = [];
for(var i = 0; i < postData.length; ++i) {
if (postData[i] && postData[i].editor && editors.indexOf(postData[i].editor) === -1) {
@@ -95,26 +95,26 @@ module.exports = function(Topics) {
}
}
- user.getUsersFields(editors, ['uid', 'username', 'userslug'], function(err, editors) {
+ user.getUsersFields(editors, ['uid', 'username', 'userslug'], function (err, editors) {
if (err) {
return next(err);
}
var editorData = {};
- editors.forEach(function(editor) {
+ editors.forEach(function (editor) {
editorData[editor.uid] = editor;
});
next(null, editorData);
});
},
- parents: function(next) {
+ parents: function (next) {
Topics.addParentPosts(postData, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
- postData.forEach(function(postObj, i) {
+ postData.forEach(function (postObj, i) {
if (postObj) {
postObj.deleted = parseInt(postObj.deleted, 10) === 1;
postObj.user = parseInt(postObj.uid, 10) ? results.userData[postObj.uid] : _.clone(results.userData[postObj.uid]);
@@ -136,9 +136,9 @@ module.exports = function(Topics) {
});
};
- Topics.modifyPostsByPrivilege = function(topicData, topicPrivileges) {
+ Topics.modifyPostsByPrivilege = function (topicData, topicPrivileges) {
var loggedIn = !!parseInt(topicPrivileges.uid, 10);
- topicData.posts.forEach(function(post) {
+ topicData.posts.forEach(function (post) {
if (post) {
post.display_edit_tools = topicPrivileges.isAdminOrMod || (post.selfPost && topicPrivileges['posts:edit']);
post.display_delete_tools = topicPrivileges.isAdminOrMod || (post.selfPost && topicPrivileges['posts:delete']);
@@ -157,8 +157,8 @@ module.exports = function(Topics) {
});
};
- Topics.addParentPosts = function(postData, callback) {
- var parentPids = postData.map(function(postObj) {
+ Topics.addParentPosts = function (postData, callback) {
+ var parentPids = postData.map(function (postObj) {
return postObj && postObj.hasOwnProperty('toPid') ? parseInt(postObj.toPid, 10) : null;
}).filter(Boolean);
@@ -169,9 +169,9 @@ module.exports = function(Topics) {
var parentPosts;
async.waterfall([
async.apply(posts.getPostsFields, parentPids, ['uid']),
- function(_parentPosts, next) {
+ function (_parentPosts, next) {
parentPosts = _parentPosts;
- var parentUids = parentPosts.map(function(postObj) { return parseInt(postObj.uid, 10); }).filter(function(uid, idx, users) {
+ var parentUids = parentPosts.map(function (postObj) { return parseInt(postObj.uid, 10); }).filter(function (uid, idx, users) {
return users.indexOf(uid) === idx;
});
@@ -179,15 +179,15 @@ module.exports = function(Topics) {
},
function (userData, next) {
var usersMap = {};
- userData.forEach(function(user) {
+ userData.forEach(function (user) {
usersMap[user.uid] = user.username;
});
var parents = {};
- parentPosts.forEach(function(post, i) {
+ parentPosts.forEach(function (post, i) {
parents[parentPids[i]] = {username: usersMap[post.uid]};
});
- postData.forEach(function(post) {
+ postData.forEach(function (post) {
post.parent = parents[post.toPid];
});
next();
@@ -195,8 +195,8 @@ module.exports = function(Topics) {
], callback);
};
- Topics.calculatePostIndices = function(posts, start, stop, postCount, reverse) {
- posts.forEach(function(post, index) {
+ Topics.calculatePostIndices = function (posts, start, stop, postCount, reverse) {
+ posts.forEach(function (post, index) {
if (reverse) {
post.index = postCount - (start + index + 1);
} else {
@@ -205,34 +205,34 @@ module.exports = function(Topics) {
});
};
- Topics.getLatestUndeletedPid = function(tid, callback) {
+ Topics.getLatestUndeletedPid = function (tid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
Topics.getLatestUndeletedReply(tid, next);
},
- function(pid, next) {
+ function (pid, next) {
if (parseInt(pid, 10)) {
return callback(null, pid.toString());
}
Topics.getTopicField(tid, 'mainPid', next);
},
- function(mainPid, next) {
+ function (mainPid, next) {
posts.getPostFields(mainPid, ['pid', 'deleted'], next);
},
- function(mainPost, next) {
+ function (mainPost, next) {
next(null, parseInt(mainPost.pid, 10) && parseInt(mainPost.deleted, 10) !== 1 ? mainPost.pid.toString() : null);
}
], callback);
};
- Topics.getLatestUndeletedReply = function(tid, callback) {
+ Topics.getLatestUndeletedReply = function (tid, callback) {
var isDeleted = false;
var done = false;
var latestPid = null;
var index = 0;
async.doWhilst(
- function(next) {
- db.getSortedSetRevRange('tid:' + tid + ':posts', index, index, function(err, pids) {
+ function (next) {
+ db.getSortedSetRevRange('tid:' + tid + ':posts', index, index, function (err, pids) {
if (err) {
return next(err);
}
@@ -242,7 +242,7 @@ module.exports = function(Topics) {
return next();
}
- posts.getPostField(pids[0], 'deleted', function(err, deleted) {
+ posts.getPostField(pids[0], 'deleted', function (err, deleted) {
if (err) {
return next(err);
}
@@ -256,16 +256,16 @@ module.exports = function(Topics) {
});
});
},
- function() {
+ function () {
return isDeleted && !done;
},
- function(err) {
+ function (err) {
callback(err, latestPid);
}
);
};
- Topics.addPostToTopic = function(tid, postData, callback) {
+ Topics.addPostToTopic = function (tid, postData, callback) {
async.waterfall([
function (next) {
Topics.getTopicField(tid, 'mainPid', next);
@@ -275,16 +275,16 @@ module.exports = function(Topics) {
Topics.setTopicField(tid, 'mainPid', postData.pid, next);
} else {
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetAdd('tid:' + tid + ':posts', postData.timestamp, postData.pid, next);
},
- function(next) {
+ function (next) {
var upvotes = parseInt(postData.upvotes, 10) || 0;
var downvotes = parseInt(postData.downvotes, 10) || 0;
var votes = upvotes - downvotes;
db.sortedSetAdd('tid:' + tid + ':posts:votes', votes, postData.pid, next);
}
- ], function(err) {
+ ], function (err) {
next(err);
});
}
@@ -298,7 +298,7 @@ module.exports = function(Topics) {
], callback);
};
- Topics.removePostFromTopic = function(tid, postData, callback) {
+ Topics.removePostFromTopic = function (tid, postData, callback) {
async.waterfall([
function (next) {
db.sortedSetsRemove([
@@ -315,15 +315,15 @@ module.exports = function(Topics) {
], callback);
};
- Topics.getPids = function(tid, callback) {
+ Topics.getPids = function (tid, callback) {
async.parallel({
- mainPid: function(next) {
+ mainPid: function (next) {
Topics.getTopicField(tid, 'mainPid', next);
},
- pids: function(next) {
+ pids: function (next) {
db.getSortedSetRange('tid:' + tid + ':posts', 0, -1, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -334,21 +334,21 @@ module.exports = function(Topics) {
});
};
- Topics.increasePostCount = function(tid, callback) {
+ Topics.increasePostCount = function (tid, callback) {
incrementFieldAndUpdateSortedSet(tid, 'postcount', 1, 'topics:posts', callback);
};
- Topics.decreasePostCount = function(tid, callback) {
+ Topics.decreasePostCount = function (tid, callback) {
incrementFieldAndUpdateSortedSet(tid, 'postcount', -1, 'topics:posts', callback);
};
- Topics.increaseViewCount = function(tid, callback) {
+ Topics.increaseViewCount = function (tid, callback) {
incrementFieldAndUpdateSortedSet(tid, 'viewcount', 1, 'topics:views', callback);
};
function incrementFieldAndUpdateSortedSet(tid, field, by, set, callback) {
- callback = callback || function() {};
- db.incrObjectFieldBy('topic:' + tid, field, by, function(err, value) {
+ callback = callback || function () {};
+ db.incrObjectFieldBy('topic:' + tid, field, by, function (err, value) {
if (err) {
return callback(err);
}
@@ -356,12 +356,12 @@ module.exports = function(Topics) {
});
}
- Topics.getTitleByPid = function(pid, callback) {
+ Topics.getTitleByPid = function (pid, callback) {
Topics.getTopicFieldByPid('title', pid, callback);
};
- Topics.getTopicFieldByPid = function(field, pid, callback) {
- posts.getPostField(pid, 'tid', function(err, tid) {
+ Topics.getTopicFieldByPid = function (field, pid, callback) {
+ posts.getPostField(pid, 'tid', function (err, tid) {
if (err) {
return callback(err);
}
@@ -369,8 +369,8 @@ module.exports = function(Topics) {
});
};
- Topics.getTopicDataByPid = function(pid, callback) {
- posts.getPostField(pid, 'tid', function(err, tid) {
+ Topics.getTopicDataByPid = function (pid, callback) {
+ posts.getPostField(pid, 'tid', function (err, tid) {
if (err) {
return callback(err);
}
@@ -378,7 +378,7 @@ module.exports = function(Topics) {
});
};
- Topics.getPostCount = function(tid, callback) {
+ Topics.getPostCount = function (tid, callback) {
db.getObjectField('topic:' + tid, 'postcount', callback);
};
diff --git a/src/topics/recent.js b/src/topics/recent.js
index c6fa7c7425..653ea372a7 100644
--- a/src/topics/recent.js
+++ b/src/topics/recent.js
@@ -6,7 +6,7 @@ var async = require('async');
var db = require('../database');
var plugins = require('../plugins');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
var terms = {
day: 86400000,
week: 604800000,
@@ -14,21 +14,21 @@ module.exports = function(Topics) {
year: 31104000000
};
- Topics.getLatestTopics = function(uid, start, stop, term, callback) {
+ Topics.getLatestTopics = function (uid, start, stop, term, callback) {
async.waterfall([
function (next) {
Topics.getLatestTidsFromSet('topics:recent', start, stop, term, next);
},
- function(tids, next) {
+ function (tids, next) {
Topics.getTopics(tids, uid, next);
},
- function(topics, next) {
+ function (topics, next) {
next(null, {topics: topics, nextStart: stop + 1});
}
], callback);
};
- Topics.getLatestTidsFromSet = function(set, start, stop, term, callback) {
+ Topics.getLatestTidsFromSet = function (set, start, stop, term, callback) {
var since = terms.day;
if (terms[term]) {
since = terms[term];
@@ -39,9 +39,9 @@ module.exports = function(Topics) {
db.getSortedSetRevRangeByScore(set, start, count, '+inf', Date.now() - since, callback);
};
- Topics.updateTimestamp = function(tid, timestamp, callback) {
+ Topics.updateTimestamp = function (tid, timestamp, callback) {
async.parallel([
- function(next) {
+ function (next) {
async.waterfall([
function (next) {
Topics.getTopicField(tid, 'deleted', next);
@@ -54,18 +54,18 @@ module.exports = function(Topics) {
}
], next);
},
- function(next) {
+ function (next) {
Topics.setTopicField(tid, 'lastposttime', timestamp, next);
}
- ], function(err) {
+ ], function (err) {
callback(err);
});
};
- Topics.updateRecent = function(tid, timestamp, callback) {
- callback = callback || function() {};
+ Topics.updateRecent = function (tid, timestamp, callback) {
+ callback = callback || function () {};
if (plugins.hasListeners('filter:topics.updateRecent')) {
- plugins.fireHook('filter:topics.updateRecent', {tid: tid, timestamp: timestamp}, function(err, data) {
+ plugins.fireHook('filter:topics.updateRecent', {tid: tid, timestamp: timestamp}, function (err, data) {
if (err) {
return callback(err);
}
diff --git a/src/topics/suggested.js b/src/topics/suggested.js
index 0f087ceb4c..a7b1190bf1 100644
--- a/src/topics/suggested.js
+++ b/src/topics/suggested.js
@@ -9,25 +9,25 @@ var async = require('async'),
db = require('../database');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
- Topics.getSuggestedTopics = function(tid, uid, start, stop, callback) {
+ Topics.getSuggestedTopics = function (tid, uid, start, stop, callback) {
async.parallel({
- tagTids: function(next) {
+ tagTids: function (next) {
getTidsWithSameTags(tid, next);
},
- searchTids: function(next) {
+ searchTids: function (next) {
getSearchTids(tid, next);
},
- categoryTids: function(next) {
+ categoryTids: function (next) {
getCategoryTids(tid, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
var tids = results.tagTids.concat(results.searchTids).concat(results.categoryTids);
- tids = tids.filter(function(_tid, index, array) {
+ tids = tids.filter(function (_tid, index, array) {
return parseInt(_tid, 10) !== parseInt(tid, 10) && array.indexOf(_tid) === index;
}).slice(start, stop + 1);
@@ -37,15 +37,15 @@ module.exports = function(Topics) {
function getTidsWithSameTags(tid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
Topics.getTopicTags(tid, next);
},
- function(tags, next) {
- async.map(tags, function(tag, next) {
+ function (tags, next) {
+ async.map(tags, function (tag, next) {
Topics.getTagTids(tag, 0, -1, next);
}, next);
},
- function(data, next) {
+ function (data, next) {
next(null, _.unique(_.flatten(data)));
}
], callback);
@@ -53,17 +53,17 @@ module.exports = function(Topics) {
function getSearchTids(tid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
Topics.getTopicField(tid, 'title', next);
},
- function(title, next) {
+ function (title, next) {
search.searchQuery('topic', title, [], [], next);
}
], callback);
}
function getCategoryTids(tid, callback) {
- Topics.getTopicField(tid, 'cid', function(err, cid) {
+ Topics.getTopicField(tid, 'cid', function (err, cid) {
if (err || !cid) {
return callback(err, []);
}
diff --git a/src/topics/tags.js b/src/topics/tags.js
index 9e5a4c47e8..ee8892b1cf 100644
--- a/src/topics/tags.js
+++ b/src/topics/tags.js
@@ -10,9 +10,9 @@ var plugins = require('../plugins');
var utils = require('../../public/src/utils');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
- Topics.createTags = function(tags, tid, timestamp, callback) {
+ Topics.createTags = function (tags, tid, timestamp, callback) {
callback = callback || function () {};
if (!Array.isArray(tags) || !tags.length) {
@@ -25,20 +25,20 @@ module.exports = function(Topics) {
},
function (data, next) {
tags = data.tags.slice(0, meta.config.maximumTagsPerTopic || 5);
- tags = tags.map(function(tag) {
+ tags = tags.map(function (tag) {
return utils.cleanUpTag(tag, meta.config.maximumTagLength);
- }).filter(function(tag, index, array) {
+ }).filter(function (tag, index, array) {
return tag && tag.length >= (meta.config.minimumTagLength || 3) && array.indexOf(tag) === index;
});
- var keys = tags.map(function(tag) {
+ var keys = tags.map(function (tag) {
return 'tag:' + tag + ':topics';
});
async.parallel([
async.apply(db.setAdd, 'topic:' + tid + ':tags', tags),
async.apply(db.sortedSetsAdd, keys, timestamp, tid)
- ], function(err) {
+ ], function (err) {
if (err) {
return next(err);
}
@@ -48,7 +48,7 @@ module.exports = function(Topics) {
], callback);
};
- Topics.createEmptyTag = function(tag, callback) {
+ Topics.createEmptyTag = function (tag, callback) {
if (!tag) {
return callback(new Error('[[error:invalid-tag]]'));
}
@@ -59,10 +59,10 @@ module.exports = function(Topics) {
}
async.waterfall([
- function(next) {
+ function (next) {
db.isSortedSetMember('tags:topic:count', tag, next);
},
- function(isMember, next) {
+ function (isMember, next) {
if (isMember) {
return next();
}
@@ -71,13 +71,13 @@ module.exports = function(Topics) {
], callback);
};
- Topics.updateTag = function(tag, data, callback) {
+ Topics.updateTag = function (tag, data, callback) {
db.setObject('tag:' + tag, data, callback);
};
function updateTagCount(tag, callback) {
- callback = callback || function() {};
- Topics.getTagTopicCount(tag, function(err, count) {
+ callback = callback || function () {};
+ Topics.getTagTopicCount(tag, function (err, count) {
if (err) {
return callback(err);
}
@@ -87,42 +87,42 @@ module.exports = function(Topics) {
});
}
- Topics.getTagTids = function(tag, start, stop, callback) {
+ Topics.getTagTids = function (tag, start, stop, callback) {
db.getSortedSetRevRange('tag:' + tag + ':topics', start, stop, callback);
};
- Topics.getTagTopicCount = function(tag, callback) {
+ Topics.getTagTopicCount = function (tag, callback) {
db.sortedSetCard('tag:' + tag + ':topics', callback);
};
- Topics.deleteTags = function(tags, callback) {
+ Topics.deleteTags = function (tags, callback) {
if (!Array.isArray(tags) || !tags.length) {
return callback();
}
async.series([
- function(next) {
+ function (next) {
removeTagsFromTopics(tags, next);
},
- function(next) {
- var keys = tags.map(function(tag) {
+ function (next) {
+ var keys = tags.map(function (tag) {
return 'tag:' + tag + ':topics';
});
db.deleteAll(keys, next);
},
- function(next) {
+ function (next) {
db.sortedSetRemove('tags:topic:count', tags, next);
}
], callback);
};
function removeTagsFromTopics(tags, callback) {
- async.eachLimit(tags, 50, function(tag, next) {
- db.getSortedSetRange('tag:' + tag + ':topics', 0, -1, function(err, tids) {
+ async.eachLimit(tags, 50, function (tag, next) {
+ db.getSortedSetRange('tag:' + tag + ':topics', 0, -1, function (err, tids) {
if (err || !tids.length) {
return next(err);
}
- var keys = tids.map(function(tid) {
+ var keys = tids.map(function (tid) {
return 'topic:' + tid + ':tags';
});
@@ -131,13 +131,13 @@ module.exports = function(Topics) {
}, callback);
}
- Topics.deleteTag = function(tag) {
+ Topics.deleteTag = function (tag) {
db.delete('tag:' + tag + ':topics');
db.sortedSetRemove('tags:topic:count', tag);
};
- Topics.getTags = function(start, stop, callback) {
- db.getSortedSetRevRangeWithScores('tags:topic:count', start, stop, function(err, tags) {
+ Topics.getTags = function (start, stop, callback) {
+ db.getSortedSetRevRangeWithScores('tags:topic:count', start, stop, function (err, tags) {
if (err) {
return callback(err);
}
@@ -146,17 +146,17 @@ module.exports = function(Topics) {
});
};
- Topics.getTagData = function(tags, callback) {
- var keys = tags.map(function(tag) {
+ Topics.getTagData = function (tags, callback) {
+ var keys = tags.map(function (tag) {
return 'tag:' + tag.value;
});
- db.getObjects(keys, function(err, tagData) {
+ db.getObjects(keys, function (err, tagData) {
if (err) {
return callback(err);
}
- tags.forEach(function(tag, index) {
+ tags.forEach(function (tag, index) {
tag.color = tagData[index] ? tagData[index].color : '';
tag.bgColor = tagData[index] ? tagData[index].bgColor : '';
});
@@ -164,53 +164,53 @@ module.exports = function(Topics) {
});
};
- Topics.getTopicTags = function(tid, callback) {
+ Topics.getTopicTags = function (tid, callback) {
db.getSetMembers('topic:' + tid + ':tags', callback);
};
- Topics.getTopicTagsObjects = function(tid, callback) {
- Topics.getTopicsTagsObjects([tid], function(err, data) {
+ Topics.getTopicTagsObjects = function (tid, callback) {
+ Topics.getTopicsTagsObjects([tid], function (err, data) {
callback(err, Array.isArray(data) && data.length ? data[0] : []);
});
};
- Topics.getTopicsTagsObjects = function(tids, callback) {
- var sets = tids.map(function(tid) {
+ Topics.getTopicsTagsObjects = function (tids, callback) {
+ var sets = tids.map(function (tid) {
return 'topic:' + tid + ':tags';
});
- db.getSetsMembers(sets, function(err, topicTags) {
+ db.getSetsMembers(sets, function (err, topicTags) {
if (err) {
return callback(err);
}
var uniqueTopicTags = _.uniq(_.flatten(topicTags));
- var tags = uniqueTopicTags.map(function(tag) {
+ var tags = uniqueTopicTags.map(function (tag) {
return {value: tag};
});
async.parallel({
- tagData: function(next) {
+ tagData: function (next) {
Topics.getTagData(tags, next);
},
- counts: function(next) {
+ counts: function (next) {
db.sortedSetScores('tags:topic:count', uniqueTopicTags, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
- results.tagData.forEach(function(tag, index) {
+ results.tagData.forEach(function (tag, index) {
tag.score = results.counts[index] ? results.counts[index] : 0;
});
var tagData = _.object(uniqueTopicTags, results.tagData);
- topicTags.forEach(function(tags, index) {
+ topicTags.forEach(function (tags, index) {
if (Array.isArray(tags)) {
- topicTags[index] = tags.map(function(tag) {return tagData[tag];});
+ topicTags[index] = tags.map(function (tag) {return tagData[tag];});
}
});
@@ -219,52 +219,52 @@ module.exports = function(Topics) {
});
};
- Topics.updateTags = function(tid, tags, callback) {
- callback = callback || function() {};
+ Topics.updateTags = function (tid, tags, callback) {
+ callback = callback || function () {};
async.waterfall([
- function(next) {
+ function (next) {
Topics.deleteTopicTags(tid, next);
},
- function(next) {
+ function (next) {
Topics.getTopicField(tid, 'timestamp', next);
},
- function(timestamp, next) {
+ function (timestamp, next) {
Topics.createTags(tags, tid, timestamp, next);
}
], callback);
};
- Topics.deleteTopicTags = function(tid, callback) {
- Topics.getTopicTags(tid, function(err, tags) {
+ Topics.deleteTopicTags = function (tid, callback) {
+ Topics.getTopicTags(tid, function (err, tags) {
if (err) {
return callback(err);
}
async.series([
- function(next) {
+ function (next) {
db.delete('topic:' + tid + ':tags', next);
},
- function(next) {
- var sets = tags.map(function(tag) {
+ function (next) {
+ var sets = tags.map(function (tag) {
return 'tag:' + tag + ':topics';
});
db.sortedSetsRemove(sets, tid, next);
},
- function(next) {
- async.each(tags, function(tag, next) {
+ function (next) {
+ async.each(tags, function (tag, next) {
updateTagCount(tag, next);
}, next);
}
- ], function(err) {
+ ], function (err) {
callback(err);
});
});
};
- Topics.searchTags = function(data, callback) {
+ Topics.searchTags = function (data, callback) {
function done(matches) {
- plugins.fireHook('filter:tags.search', {data: data, matches: matches}, function(err, data) {
+ plugins.fireHook('filter:tags.search', {data: data, matches: matches}, function (err, data) {
callback(err, data ? data.matches : []);
});
}
@@ -275,7 +275,7 @@ module.exports = function(Topics) {
}
if (plugins.hasListeners('filter:topics.searchTags')) {
- return plugins.fireHook('filter:topics.searchTags', {data: data}, function(err, data) {
+ return plugins.fireHook('filter:topics.searchTags', {data: data}, function (err, data) {
if (err) {
return callback(err);
}
@@ -283,7 +283,7 @@ module.exports = function(Topics) {
});
}
- findMatches(data.query, function(err, matches) {
+ findMatches(data.query, function (err, matches) {
if (err) {
return callback(err);
}
@@ -291,13 +291,13 @@ module.exports = function(Topics) {
});
};
- Topics.autocompleteTags = function(data, callback) {
+ Topics.autocompleteTags = function (data, callback) {
if (!data || !data.query) {
return callback(null, []);
}
if (plugins.hasListeners('filter:topics.autocompleteTags')) {
- return plugins.fireHook('filter:topics.autocompleteTags', {data: data}, function(err, data) {
+ return plugins.fireHook('filter:topics.autocompleteTags', {data: data}, function (err, data) {
if (err) {
return callback(err);
}
@@ -309,7 +309,7 @@ module.exports = function(Topics) {
};
function findMatches(query, callback) {
- db.getSortedSetRevRange('tags:topic:count', 0, -1, function(err, tags) {
+ db.getSortedSetRevRange('tags:topic:count', 0, -1, function (err, tags) {
if (err) {
return callback(err);
}
@@ -326,14 +326,14 @@ module.exports = function(Topics) {
}
}
- matches = matches.sort(function(a, b) {
+ matches = matches.sort(function (a, b) {
return a > b;
});
callback(null, matches);
});
}
- Topics.searchAndLoadTags = function(data, callback) {
+ Topics.searchAndLoadTags = function (data, callback) {
var searchResult = {
tags: [],
matchCount: 0,
@@ -343,29 +343,29 @@ module.exports = function(Topics) {
if (!data.query || !data.query.length) {
return callback(null, searchResult);
}
- Topics.searchTags(data, function(err, tags) {
+ Topics.searchTags(data, function (err, tags) {
if (err) {
return callback(err);
}
async.parallel({
- counts: function(next) {
+ counts: function (next) {
db.sortedSetScores('tags:topic:count', tags, next);
},
- tagData: function(next) {
- tags = tags.map(function(tag) {
+ tagData: function (next) {
+ tags = tags.map(function (tag) {
return {value: tag};
});
Topics.getTagData(tags, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
- results.tagData.forEach(function(tag, index) {
+ results.tagData.forEach(function (tag, index) {
tag.score = results.counts[index];
});
- results.tagData.sort(function(a, b) {
+ results.tagData.sort(function (a, b) {
return b.score - a.score;
});
searchResult.tags = results.tagData;
@@ -376,7 +376,7 @@ module.exports = function(Topics) {
});
};
- Topics.getRelatedTopics = function(topicData, uid, callback) {
+ Topics.getRelatedTopics = function (topicData, uid, callback) {
if (plugins.hasListeners('filter:topic.getRelatedTopics')) {
return plugins.fireHook('filter:topic.getRelatedTopics', {topic: topicData, uid: uid}, callback);
}
@@ -399,7 +399,7 @@ module.exports = function(Topics) {
Topics.getTopics(tids, uid, next);
},
function (topics, next) {
- topics = topics.filter(function(topic) {
+ topics = topics.filter(function (topic) {
return topic && !topic.deleted && parseInt(topic.uid, 10) !== parseInt(uid, 10);
});
next(null, topics);
diff --git a/src/topics/teaser.js b/src/topics/teaser.js
index 9c752946ee..1467dd194f 100644
--- a/src/topics/teaser.js
+++ b/src/topics/teaser.js
@@ -11,9 +11,9 @@ var posts = require('../posts');
var plugins = require('../plugins');
var utils = require('../../public/src/utils');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
- Topics.getTeasers = function(topics, callback) {
+ Topics.getTeasers = function (topics, callback) {
if (!Array.isArray(topics) || !topics.length) {
return callback(null, []);
}
@@ -23,7 +23,7 @@ module.exports = function(Topics) {
var postData;
var tidToPost = {};
- topics.forEach(function(topic) {
+ topics.forEach(function (topic) {
counts.push(topic && (parseInt(topic.postcount, 10) || 0));
if (topic) {
if (topic.teaserPid === 'null') {
@@ -48,27 +48,27 @@ module.exports = function(Topics) {
});
async.waterfall([
- function(next) {
+ function (next) {
posts.getPostsFields(teaserPids, ['pid', 'uid', 'timestamp', 'tid', 'content'], next);
},
- function(_postData, next) {
+ function (_postData, next) {
postData = _postData;
- var uids = postData.map(function(post) {
+ var uids = postData.map(function (post) {
return post.uid;
- }).filter(function(uid, index, array) {
+ }).filter(function (uid, index, array) {
return array.indexOf(uid) === index;
});
user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], next);
},
- function(usersData, next) {
+ function (usersData, next) {
var users = {};
- usersData.forEach(function(user) {
+ usersData.forEach(function (user) {
users[user.uid] = user;
});
- async.each(postData, function(post, next) {
+ async.each(postData, function (post, next) {
// If the post author isn't represented in the retrieved users' data, then it means they were deleted, assume guest.
if (!users.hasOwnProperty(post.uid)) {
post.uid = 0;
@@ -80,8 +80,8 @@ module.exports = function(Topics) {
posts.parsePost(post, next);
}, next);
},
- function(next) {
- var teasers = topics.map(function(topic, index) {
+ function (next) {
+ var teasers = topics.map(function (topic, index) {
if (!topic) {
return null;
}
@@ -97,34 +97,34 @@ module.exports = function(Topics) {
plugins.fireHook('filter:teasers.get', {teasers: teasers}, next);
},
- function(data, next) {
+ function (data, next) {
next(null, data.teasers);
}
], callback);
};
- Topics.getTeasersByTids = function(tids, callback) {
+ Topics.getTeasersByTids = function (tids, callback) {
if (!Array.isArray(tids) || !tids.length) {
return callback(null, []);
}
async.waterfall([
- function(next) {
+ function (next) {
Topics.getTopicsFields(tids, ['tid', 'postcount', 'teaserPid'], next);
},
- function(topics, next) {
+ function (topics, next) {
Topics.getTeasers(topics, next);
}
], callback);
};
- Topics.getTeaser = function(tid, callback) {
- Topics.getTeasersByTids([tid], function(err, teasers) {
+ Topics.getTeaser = function (tid, callback) {
+ Topics.getTeasersByTids([tid], function (err, teasers) {
callback(err, Array.isArray(teasers) && teasers.length ? teasers[0] : null);
});
};
- Topics.updateTeaser = function(tid, callback) {
- Topics.getLatestUndeletedReply(tid, function(err, pid) {
+ Topics.updateTeaser = function (tid, callback) {
+ Topics.getLatestUndeletedReply(tid, function (err, pid) {
if (err) {
return callback(err);
}
diff --git a/src/topics/thumb.js b/src/topics/thumb.js
index 5829e080c4..7d22365293 100644
--- a/src/topics/thumb.js
+++ b/src/topics/thumb.js
@@ -15,9 +15,9 @@ var image = require('../image');
var file = require('../file');
var plugins = require('../plugins');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
- Topics.resizeAndUploadThumb = function(data, callback) {
+ Topics.resizeAndUploadThumb = function (data, callback) {
if (!data.thumb || !validator.isURL(data.thumb)) {
return callback();
}
@@ -26,10 +26,10 @@ module.exports = function(Topics) {
var filename;
async.waterfall([
- function(next) {
+ function (next) {
request.head(data.thumb, next);
},
- function(res, body, next) {
+ function (res, body, next) {
var type = res.headers['content-type'];
if (!type.match(/image./)) {
@@ -45,10 +45,10 @@ module.exports = function(Topics) {
request(data.thumb).pipe(fs.createWriteStream(pathToUpload)).on('close', next);
},
- function(next) {
+ function (next) {
file.isFileTypeAllowed(pathToUpload, next);
},
- function(next) {
+ function (next) {
var size = parseInt(meta.config.topicThumbSize, 10) || 120;
image.resizeImage({
path: pathToUpload,
@@ -57,7 +57,7 @@ module.exports = function(Topics) {
height: size
}, next);
},
- function(next) {
+ function (next) {
if (!plugins.hasListeners('filter:uploadImage')) {
data.thumb = path.join(nconf.get('upload_url'), 'files', filename);
return callback();
@@ -65,12 +65,12 @@ module.exports = function(Topics) {
plugins.fireHook('filter:uploadImage', {image: {path: pathToUpload, name: ''}, uid: data.uid}, next);
},
- function(uploadedFile, next) {
+ function (uploadedFile, next) {
deleteFile(pathToUpload);
data.thumb = uploadedFile.url;
next();
}
- ], function(err) {
+ ], function (err) {
if (err) {
deleteFile(pathToUpload);
}
@@ -80,7 +80,7 @@ module.exports = function(Topics) {
function deleteFile(path) {
if (path) {
- fs.unlink(path, function(err) {
+ fs.unlink(path, function (err) {
if (err) {
winston.error(err);
}
diff --git a/src/topics/tools.js b/src/topics/tools.js
index 3975193f76..6fce256f27 100644
--- a/src/topics/tools.js
+++ b/src/topics/tools.js
@@ -9,17 +9,17 @@ var plugins = require('../plugins');
var privileges = require('../privileges');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
var topicTools = {};
Topics.tools = topicTools;
- topicTools.delete = function(tid, uid, callback) {
+ topicTools.delete = function (tid, uid, callback) {
toggleDelete(tid, uid, true, callback);
};
- topicTools.restore = function(tid, uid, callback) {
+ topicTools.restore = function (tid, uid, callback) {
toggleDelete(tid, uid, false, callback);
};
@@ -73,13 +73,13 @@ module.exports = function(Topics) {
], callback);
}
- topicTools.purge = function(tid, uid, callback) {
+ topicTools.purge = function (tid, uid, callback) {
var cid;
async.waterfall([
- function(next) {
+ function (next) {
Topics.exists(tid, next);
},
- function(exists, next) {
+ function (exists, next) {
if (!exists) {
return callback();
}
@@ -103,16 +103,16 @@ module.exports = function(Topics) {
], callback);
};
- topicTools.lock = function(tid, uid, callback) {
+ topicTools.lock = function (tid, uid, callback) {
toggleLock(tid, uid, true, callback);
};
- topicTools.unlock = function(tid, uid, callback) {
+ topicTools.unlock = function (tid, uid, callback) {
toggleLock(tid, uid, false, callback);
};
function toggleLock(tid, uid, lock, callback) {
- callback = callback || function() {};
+ callback = callback || function () {};
var cid;
@@ -149,11 +149,11 @@ module.exports = function(Topics) {
], callback);
}
- topicTools.pin = function(tid, uid, callback) {
+ topicTools.pin = function (tid, uid, callback) {
togglePin(tid, uid, true, callback);
};
- topicTools.unpin = function(tid, uid, callback) {
+ topicTools.unpin = function (tid, uid, callback) {
togglePin(tid, uid, false, callback);
};
@@ -173,7 +173,7 @@ module.exports = function(Topics) {
topicData = _topicData;
privileges.categories.isAdminOrMod(_topicData.cid, uid, next);
},
- function(isAdminOrMod, next) {
+ function (isAdminOrMod, next) {
if (!isAdminOrMod) {
return next(new Error('[[error:no-privileges]]'));
}
@@ -182,7 +182,7 @@ module.exports = function(Topics) {
async.apply(db.sortedSetAdd, 'cid:' + topicData.cid + ':tids', pin ? Math.pow(2, 53) : topicData.lastposttime, tid)
], next);
},
- function(results, next) {
+ function (results, next) {
var data = {
tid: tid,
isPinned: pin,
@@ -197,7 +197,7 @@ module.exports = function(Topics) {
], callback);
}
- topicTools.move = function(tid, cid, uid, callback) {
+ topicTools.move = function (tid, cid, uid, callback) {
var topic;
async.waterfall([
function (next) {
@@ -219,16 +219,16 @@ module.exports = function(Topics) {
function (next) {
var timestamp = parseInt(topic.pinned, 10) ? Math.pow(2, 53) : topic.lastposttime;
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetAdd('cid:' + cid + ':tids', timestamp, tid, next);
},
- function(next) {
+ function (next) {
topic.postcount = topic.postcount || 0;
db.sortedSetAdd('cid:' + cid + ':tids:posts', topic.postcount, tid, next);
}
], next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
@@ -248,7 +248,7 @@ module.exports = function(Topics) {
oldCid: oldCid
}, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
diff --git a/src/topics/unread.js b/src/topics/unread.js
index d1c2a0bb15..b4a5d07514 100644
--- a/src/topics/unread.js
+++ b/src/topics/unread.js
@@ -12,20 +12,20 @@ var privileges = require('../privileges');
var meta = require('../meta');
var utils = require('../../public/src/utils');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
- Topics.getTotalUnread = function(uid, filter, callback) {
+ Topics.getTotalUnread = function (uid, filter, callback) {
if (!callback) {
callback = filter;
filter = '';
}
- Topics.getUnreadTids(0, uid, filter, function(err, tids) {
+ Topics.getUnreadTids(0, uid, filter, function (err, tids) {
callback(err, Array.isArray(tids) ? tids.length : 0);
});
};
- Topics.getUnreadTopics = function(cid, uid, start, stop, filter, callback) {
+ Topics.getUnreadTopics = function (cid, uid, start, stop, filter, callback) {
var unreadTopics = {
showSelect: true,
@@ -34,10 +34,10 @@ module.exports = function(Topics) {
};
async.waterfall([
- function(next) {
+ function (next) {
Topics.getUnreadTids(cid, uid, filter, next);
},
- function(tids, next) {
+ function (tids, next) {
unreadTopics.topicCount = tids.length;
if (!tids.length) {
@@ -52,7 +52,7 @@ module.exports = function(Topics) {
Topics.getTopicsByTids(tids, uid, next);
},
- function(topicData, next) {
+ function (topicData, next) {
if (!Array.isArray(topicData) || !topicData.length) {
return next(null, unreadTopics);
}
@@ -64,11 +64,11 @@ module.exports = function(Topics) {
], callback);
};
- Topics.unreadCutoff = function() {
+ Topics.unreadCutoff = function () {
return Date.now() - (parseInt(meta.config.unreadCutoff, 10) || 2) * 86400000;
};
- Topics.getUnreadTids = function(cid, uid, filter, callback) {
+ Topics.getUnreadTids = function (cid, uid, filter, callback) {
uid = parseInt(uid, 10);
if (uid === 0) {
return callback(null, []);
@@ -81,22 +81,22 @@ module.exports = function(Topics) {
async.waterfall([
function (next) {
async.parallel({
- ignoredCids: function(next) {
+ ignoredCids: function (next) {
if (filter === 'watched') {
return next(null, []);
}
user.getIgnoredCategories(uid, next);
},
- ignoredTids: function(next) {
+ ignoredTids: function (next) {
user.getIgnoredTids(uid, 0, -1, next);
},
- recentTids: function(next) {
+ recentTids: function (next) {
db.getSortedSetRevRangeByScoreWithScores('topics:recent', 0, -1, '+inf', cutoff, next);
},
- userScores: function(next) {
+ userScores: function (next) {
db.getSortedSetRevRangeByScoreWithScores('uid:' + uid + ':tids_read', 0, -1, '+inf', cutoff, next);
},
- tids_unread: function(next) {
+ tids_unread: function (next) {
db.getSortedSetRevRangeWithScores('uid:' + uid + ':tids_unread', 0, -1, next);
}
}, next);
@@ -109,16 +109,16 @@ module.exports = function(Topics) {
ignoredCids = results.ignoredCids;
var userRead = {};
- results.userScores.forEach(function(userItem) {
+ results.userScores.forEach(function (userItem) {
userRead[userItem.value] = userItem.score;
});
results.recentTids = results.recentTids.concat(results.tids_unread);
- results.recentTids.sort(function(a, b) {
+ results.recentTids.sort(function (a, b) {
return b.score - a.score;
});
- var tids = results.recentTids.filter(function(recentTopic) {
+ var tids = results.recentTids.filter(function (recentTopic) {
if (results.ignoredTids.indexOf(recentTopic.value.toString()) !== -1) {
return false;
}
@@ -128,9 +128,9 @@ module.exports = function(Topics) {
default:
return !userRead[recentTopic.value] || recentTopic.score > userRead[recentTopic.value];
}
- }).map(function(topic) {
+ }).map(function (topic) {
return topic.value;
- }).filter(function(tid, index, array) {
+ }).filter(function (tid, index, array) {
return array.indexOf(tid) === index;
});
@@ -150,11 +150,11 @@ module.exports = function(Topics) {
};
function filterWatchedTids(uid, tids, callback) {
- db.sortedSetScores('uid:' + uid + ':followed_tids', tids, function(err, scores) {
+ db.sortedSetScores('uid:' + uid + ':followed_tids', tids, function (err, scores) {
if (err) {
return callback(err);
}
- tids = tids.filter(function(tid, index) {
+ tids = tids.filter(function (tid, index) {
return tid && !!scores[index];
});
callback(null, tids);
@@ -167,15 +167,15 @@ module.exports = function(Topics) {
}
async.waterfall([
- function(next) {
+ function (next) {
privileges.topics.filterTids('read', tids, uid, next);
},
- function(tids, next) {
+ function (tids, next) {
async.parallel({
- topics: function(next) {
+ topics: function (next) {
Topics.getTopicsFields(tids, ['tid', 'cid'], next);
},
- isTopicsFollowed: function(next) {
+ isTopicsFollowed: function (next) {
if (filter === 'watched' || filter === 'new') {
return next(null, []);
}
@@ -183,13 +183,13 @@ module.exports = function(Topics) {
}
}, next);
},
- function(results, next) {
+ function (results, next) {
var topics = results.topics;
- tids = topics.filter(function(topic, index) {
+ tids = topics.filter(function (topic, index) {
return topic && topic.cid &&
(!!results.isTopicsFollowed[index] || ignoredCids.indexOf(topic.cid.toString()) === -1) &&
(!cid || parseInt(cid, 10) === parseInt(topic.cid, 10));
- }).map(function(topic) {
+ }).map(function (topic) {
return topic.tid;
});
next(null, tids);
@@ -197,13 +197,13 @@ module.exports = function(Topics) {
], callback);
}
- Topics.pushUnreadCount = function(uid, callback) {
- callback = callback || function() {};
+ Topics.pushUnreadCount = function (uid, callback) {
+ callback = callback || function () {};
if (!uid || parseInt(uid, 10) === 0) {
return callback();
}
- Topics.getTotalUnread(uid, function(err, count) {
+ Topics.getTotalUnread(uid, function (err, count) {
if (err) {
return callback(err);
}
@@ -213,17 +213,17 @@ module.exports = function(Topics) {
});
};
- Topics.markAsUnreadForAll = function(tid, callback) {
+ Topics.markAsUnreadForAll = function (tid, callback) {
Topics.markCategoryUnreadForAll(tid, callback);
};
- Topics.markAsRead = function(tids, uid, callback) {
- callback = callback || function() {};
+ Topics.markAsRead = function (tids, uid, callback) {
+ callback = callback || function () {};
if (!Array.isArray(tids) || !tids.length) {
return callback();
}
- tids = tids.filter(function(tid, index, array) {
+ tids = tids.filter(function (tid, index, array) {
return tid && utils.isNumber(tid) && array.indexOf(tid) === index;
});
@@ -239,7 +239,7 @@ module.exports = function(Topics) {
}, next);
},
function (results, next) {
- tids = tids.filter(function(tid, index) {
+ tids = tids.filter(function (tid, index) {
return results.topicScores[index] && (!results.userScores[index] || results.userScores[index] < results.topicScores[index]);
});
@@ -248,7 +248,7 @@ module.exports = function(Topics) {
}
var now = Date.now();
- var scores = tids.map(function() {
+ var scores = tids.map(function () {
return now;
});
@@ -259,9 +259,9 @@ module.exports = function(Topics) {
}, next);
},
function (results, next) {
- var cids = results.topicData.map(function(topic) {
+ var cids = results.topicData.map(function (topic) {
return topic && topic.cid;
- }).filter(function(topic, index, array) {
+ }).filter(function (topic, index, array) {
return topic && array.indexOf(topic) === index;
});
@@ -273,7 +273,7 @@ module.exports = function(Topics) {
], callback);
};
- Topics.markAllRead = function(uid, callback) {
+ Topics.markAllRead = function (uid, callback) {
async.waterfall([
function (next) {
db.getSortedSetRevRangeByScore('topics:recent', 0, -1, '+inf', Topics.unreadCutoff(), next);
@@ -288,19 +288,19 @@ module.exports = function(Topics) {
], callback);
};
- Topics.markTopicNotificationsRead = function(tids, uid) {
+ Topics.markTopicNotificationsRead = function (tids, uid) {
if (!Array.isArray(tids) || !tids.length) {
return;
}
async.waterfall([
- function(next) {
+ function (next) {
user.notifications.getUnreadByField(uid, 'tid', tids, next);
},
- function(nids, next) {
+ function (nids, next) {
notifications.markReadMultiple(nids, uid, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return winston.error(err);
}
@@ -308,8 +308,8 @@ module.exports = function(Topics) {
});
};
- Topics.markCategoryUnreadForAll = function(tid, callback) {
- Topics.getTopicField(tid, 'cid', function(err, cid) {
+ Topics.markCategoryUnreadForAll = function (tid, callback) {
+ Topics.getTopicField(tid, 'cid', function (err, cid) {
if(err) {
return callback(err);
}
@@ -318,30 +318,30 @@ module.exports = function(Topics) {
});
};
- Topics.hasReadTopics = function(tids, uid, callback) {
+ Topics.hasReadTopics = function (tids, uid, callback) {
if (!parseInt(uid, 10)) {
- return callback(null, tids.map(function() {
+ return callback(null, tids.map(function () {
return false;
}));
}
async.parallel({
- recentScores: function(next) {
+ recentScores: function (next) {
db.sortedSetScores('topics:recent', tids, next);
},
- userScores: function(next) {
+ userScores: function (next) {
db.sortedSetScores('uid:' + uid + ':tids_read', tids, next);
},
tids_unread: function (next) {
db.sortedSetScores('uid:' + uid + ':tids_unread', tids, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
var cutoff = Topics.unreadCutoff();
- var result = tids.map(function(tid, index) {
+ var result = tids.map(function (tid, index) {
return !results.tids_unread[index] &&
(results.recentScores[index] < cutoff ||
!!(results.userScores[index] && results.userScores[index] >= results.recentScores[index]));
@@ -351,13 +351,13 @@ module.exports = function(Topics) {
});
};
- Topics.hasReadTopic = function(tid, uid, callback) {
- Topics.hasReadTopics([tid], uid, function(err, hasRead) {
+ Topics.hasReadTopic = function (tid, uid, callback) {
+ Topics.hasReadTopics([tid], uid, function (err, hasRead) {
callback(err, Array.isArray(hasRead) && hasRead.length ? hasRead[0] : false);
});
};
- Topics.markUnread = function(tid, uid, callback) {
+ Topics.markUnread = function (tid, uid, callback) {
async.waterfall([
function (next) {
Topics.exists(tid, next);
diff --git a/src/topics/user.js b/src/topics/user.js
index 09cb4a7e87..ab56a5f778 100644
--- a/src/topics/user.js
+++ b/src/topics/user.js
@@ -6,19 +6,19 @@ var async = require('async');
var db = require('../database');
var posts = require('../posts');
-module.exports = function(Topics) {
+module.exports = function (Topics) {
- Topics.isOwner = function(tid, uid, callback) {
+ Topics.isOwner = function (tid, uid, callback) {
uid = parseInt(uid, 10);
if (!uid) {
return callback(null, false);
}
- Topics.getTopicField(tid, 'uid', function(err, author) {
+ Topics.getTopicField(tid, 'uid', function (err, author) {
callback(err, parseInt(author, 10) === uid);
});
};
- Topics.getUids = function(tid, callback) {
+ Topics.getUids = function (tid, callback) {
db.getSortedSetRevRangeByScore('tid:' + tid + ':posters', 0, -1, '+inf', 1, callback);
};
};
\ No newline at end of file
diff --git a/src/upgrade.js b/src/upgrade.js
index f8177a90d0..03c776dce3 100644
--- a/src/upgrade.js
+++ b/src/upgrade.js
@@ -12,14 +12,14 @@ var db = require('./database'),
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
latestSchema = Date.UTC(2016, 9, 8);
-Upgrade.check = function(callback) {
- db.get('schemaDate', function(err, value) {
+Upgrade.check = function (callback) {
+ db.get('schemaDate', function (err, value) {
if (err) {
return callback(err);
}
if (!value) {
- db.set('schemaDate', latestSchema, function(err) {
+ db.set('schemaDate', latestSchema, function (err) {
if (err) {
return callback(err);
}
@@ -33,25 +33,25 @@ Upgrade.check = function(callback) {
});
};
-Upgrade.update = function(schemaDate, callback) {
+Upgrade.update = function (schemaDate, callback) {
db.set('schemaDate', schemaDate, callback);
};
-Upgrade.upgrade = function(callback) {
+Upgrade.upgrade = function (callback) {
var updatesMade = false;
winston.info('Beginning database schema update');
async.series([
- function(next) {
+ function (next) {
// Prepare for upgrade & check to make sure the upgrade is possible
- db.get('schemaDate', function(err, value) {
+ db.get('schemaDate', function (err, value) {
if (err) {
return next(err);
}
if(!value) {
- db.set('schemaDate', latestSchema, function() {
+ db.set('schemaDate', latestSchema, function () {
next();
});
schemaDate = latestSchema;
@@ -66,14 +66,14 @@ Upgrade.upgrade = function(callback) {
}
});
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2015, 11, 15);
if (schemaDate < thisSchemaDate) {
updatesMade = true;
winston.info('[2015/12/15] Upgrading chats');
- db.getObjectFields('global', ['nextMid', 'nextChatRoomId'], function(err, globalData) {
+ db.getObjectFields('global', ['nextMid', 'nextChatRoomId'], function (err, globalData) {
if (err) {
return next(err);
}
@@ -82,16 +82,16 @@ Upgrade.upgrade = function(callback) {
var roomId = globalData.nextChatRoomId || 1;
var currentMid = 1;
- async.whilst(function() {
+ async.whilst(function () {
return currentMid <= globalData.nextMid;
- }, function(next) {
- db.getObject('message:' + currentMid, function(err, message) {
+ }, function (next) {
+ db.getObject('message:' + currentMid, function (err, message) {
function addMessageToUids(roomId, callback) {
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetAdd('uid:' + message.fromuid + ':chat:room:' + roomId + ':mids', msgTime, currentMid, next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('uid:' + message.touid + ':chat:room:' + roomId + ':mids', msgTime, currentMid, next);
}
], callback);
@@ -108,7 +108,7 @@ Upgrade.upgrade = function(callback) {
if (rooms[pairID]) {
winston.info('adding message ' + currentMid + ' to existing roomID ' + roomId);
- addMessageToUids(rooms[pairID], function(err) {
+ addMessageToUids(rooms[pairID], function (err) {
if (err) {
return next(err);
}
@@ -118,19 +118,19 @@ Upgrade.upgrade = function(callback) {
} else {
winston.info('adding message ' + currentMid + ' to new roomID ' + roomId);
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetAdd('uid:' + message.fromuid + ':chat:rooms', msgTime, roomId, next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('uid:' + message.touid + ':chat:rooms', msgTime, roomId, next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('chat:room:' + roomId + ':uids', [msgTime, msgTime + 1], [message.fromuid, message.touid], next);
},
- function(next) {
+ function (next) {
addMessageToUids(roomId, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return next(err);
}
@@ -141,7 +141,7 @@ Upgrade.upgrade = function(callback) {
});
}
});
- }, function(err) {
+ }, function (err) {
if (err) {
return next(err);
}
@@ -155,22 +155,22 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2015, 11, 23);
if (schemaDate < thisSchemaDate) {
updatesMade = true;
winston.info('[2015/12/23] Upgrading chat room hashes');
- db.getObjectField('global', 'nextChatRoomId', function(err, nextChatRoomId) {
+ db.getObjectField('global', 'nextChatRoomId', function (err, nextChatRoomId) {
if (err) {
return next(err);
}
var currentChatRoomId = 1;
- async.whilst(function() {
+ async.whilst(function () {
return currentChatRoomId <= nextChatRoomId;
- }, function(next) {
- db.getSortedSetRange('chat:room:' + currentChatRoomId + ':uids', 0, 0, function(err, uids) {
+ }, function (next) {
+ db.getSortedSetRange('chat:room:' + currentChatRoomId + ':uids', 0, 0, function (err, uids) {
if (err) {
return next(err);
}
@@ -179,7 +179,7 @@ Upgrade.upgrade = function(callback) {
return next();
}
- db.setObject('chat:room:' + currentChatRoomId, {owner: uids[0], roomId: currentChatRoomId}, function(err) {
+ db.setObject('chat:room:' + currentChatRoomId, {owner: uids[0], roomId: currentChatRoomId}, function (err) {
if (err) {
return next(err);
}
@@ -187,7 +187,7 @@ Upgrade.upgrade = function(callback) {
next();
});
});
- }, function(err) {
+ }, function (err) {
if (err) {
return next(err);
}
@@ -201,7 +201,7 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2016, 0, 11);
if (schemaDate < thisSchemaDate) {
@@ -211,7 +211,7 @@ Upgrade.upgrade = function(callback) {
async.waterfall([
async.apply(db.getObjectField, 'config', 'theme:id'),
async.apply(db.sortedSetAdd, 'plugins:active', 0)
- ], function(err) {
+ ], function (err) {
if (err) {
return next(err);
}
@@ -224,7 +224,7 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2016, 0, 14);
if (schemaDate < thisSchemaDate) {
@@ -233,9 +233,9 @@ Upgrade.upgrade = function(callback) {
var batch = require('./batch');
- batch.processSortedSet('posts:pid', function(ids, next) {
- async.eachSeries(ids, function(id, next) {
- db.getObjectFields('post:' + id, ['pid', 'uid', 'votes'], function(err, postData) {
+ batch.processSortedSet('posts:pid', function (ids, next) {
+ async.eachSeries(ids, function (id, next) {
+ db.getObjectFields('post:' + id, ['pid', 'uid', 'votes'], function (err, postData) {
if (err) {
return next(err);
}
@@ -246,7 +246,7 @@ Upgrade.upgrade = function(callback) {
db.sortedSetAdd('uid:' + postData.uid + ':posts:votes', postData.votes, postData.pid, next);
});
}, next);
- }, {}, function(err) {
+ }, {}, function (err) {
if (err) {
return next(err);
}
@@ -258,7 +258,7 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2016, 0, 20);
if (schemaDate < thisSchemaDate) {
@@ -267,9 +267,9 @@ Upgrade.upgrade = function(callback) {
var batch = require('./batch');
var now = Date.now();
- batch.processSortedSet('users:joindate', function(ids, next) {
- async.eachSeries(ids, function(id, next) {
- db.getObjectFields('user:' + id, ['uid', 'email:confirmed'], function(err, userData) {
+ batch.processSortedSet('users:joindate', function (ids, next) {
+ async.eachSeries(ids, function (id, next) {
+ db.getObjectFields('user:' + id, ['uid', 'email:confirmed'], function (err, userData) {
if (err) {
return next(err);
}
@@ -280,7 +280,7 @@ Upgrade.upgrade = function(callback) {
db.sortedSetAdd('users:notvalidated', now, userData.uid, next);
});
}, next);
- }, {}, function(err) {
+ }, {}, function (err) {
if (err) {
return next(err);
}
@@ -292,7 +292,7 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2016, 0, 23);
if (schemaDate < thisSchemaDate) {
@@ -320,7 +320,7 @@ Upgrade.upgrade = function(callback) {
function (groupData, next) {
groups.show('Global Moderators', next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return next(err);
}
@@ -333,7 +333,7 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2016, 1, 25);
if (schemaDate < thisSchemaDate) {
@@ -348,7 +348,7 @@ Upgrade.upgrade = function(callback) {
function (next) {
db.deleteObjectField('config', 'disableSocialButtons', next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return next(err);
}
@@ -361,7 +361,7 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2016, 3, 14);
if (schemaDate < thisSchemaDate) {
@@ -371,22 +371,22 @@ Upgrade.upgrade = function(callback) {
var user = require('./user');
var batch = require('./batch');
var count = 0;
- batch.processSortedSet('users:joindate', function(uids, next) {
+ batch.processSortedSet('users:joindate', function (uids, next) {
winston.info('upgraded ' + count + ' users');
- user.getMultipleUserSettings(uids, function(err, settings) {
+ user.getMultipleUserSettings(uids, function (err, settings) {
if (err) {
return next(err);
}
count += uids.length;
- settings = settings.filter(function(setting) {
+ settings = settings.filter(function (setting) {
return setting && setting.groupTitle;
});
- async.each(settings, function(setting, next) {
+ async.each(settings, function (setting, next) {
db.setObjectField('user:' + setting.uid, 'groupTitle', setting.groupTitle, next);
}, next);
});
- }, {}, function(err) {
+ }, {}, function (err) {
if (err) {
return next(err);
}
@@ -399,7 +399,7 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2016, 3, 18);
if (schemaDate < thisSchemaDate) {
@@ -409,15 +409,15 @@ Upgrade.upgrade = function(callback) {
var batch = require('./batch');
var topics = require('./topics');
var count = 0;
- batch.processSortedSet('topics:tid', function(tids, next) {
+ batch.processSortedSet('topics:tid', function (tids, next) {
winston.info('upgraded ' + count + ' topics');
count += tids.length;
- async.each(tids, function(tid, next) {
- db.delete('tid:' + tid + ':posters', function(err) {
+ async.each(tids, function (tid, next) {
+ db.delete('tid:' + tid + ':posters', function (err) {
if (err) {
return next(err);
}
- topics.getPids(tid, function(err, pids) {
+ topics.getPids(tid, function (err, pids) {
if (err) {
return next(err);
}
@@ -426,8 +426,8 @@ Upgrade.upgrade = function(callback) {
return next();
}
- async.eachSeries(pids, function(pid, next) {
- db.getObjectField('post:' + pid, 'uid', function(err, uid) {
+ async.eachSeries(pids, function (pid, next) {
+ db.getObjectField('post:' + pid, 'uid', function (err, uid) {
if (err) {
return next(err);
}
@@ -440,7 +440,7 @@ Upgrade.upgrade = function(callback) {
});
});
}, next);
- }, {}, function(err) {
+ }, {}, function (err) {
if (err) {
return next(err);
}
@@ -453,7 +453,7 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2016, 3, 29);
if (schemaDate < thisSchemaDate) {
@@ -467,26 +467,26 @@ Upgrade.upgrade = function(callback) {
async.waterfall([
async.apply(db.getSortedSetRange, 'posts:flagged', 0, -1),
- function(_pids, next) {
+ function (_pids, next) {
pids = _pids;
posts.getPostsFields(pids, ['tid'], next);
},
- function(_tids, next) {
- tids = _tids.map(function(a) {
+ function (_tids, next) {
+ tids = _tids.map(function (a) {
return a.tid;
});
topics.getTopicsFields(tids, ['deleted'], next);
},
- function(state, next) {
- var toDismiss = state.map(function(a, idx) {
+ function (state, next) {
+ var toDismiss = state.map(function (a, idx) {
return parseInt(a.deleted, 10) === 1 ? pids[idx] : null;
}).filter(Boolean);
winston.info('[2016/04/29] ' + toDismiss.length + ' dismissable flags found');
async.each(toDismiss, posts.dismissFlag, next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return next(err);
}
@@ -499,7 +499,7 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2016, 4, 28);
if (schemaDate < thisSchemaDate) {
@@ -509,13 +509,13 @@ Upgrade.upgrade = function(callback) {
var groupsAPI = require('./groups');
var privilegesAPI = require('./privileges');
- db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
+ db.getSortedSetRange('categories:cid', 0, -1, function (err, cids) {
if (err) {
return next(err);
}
- async.eachSeries(cids, function(cid, next) {
- privilegesAPI.categories.list(cid, function(err, data) {
+ async.eachSeries(cids, function (cid, next) {
+ privilegesAPI.categories.list(cid, function (err, data) {
if (err) {
return next(err);
}
@@ -524,10 +524,10 @@ Upgrade.upgrade = function(callback) {
var users = data.users;
async.waterfall([
- function(next) {
- async.eachSeries(groups, function(group, next) {
+ function (next) {
+ async.eachSeries(groups, function (group, next) {
if (group.privileges['groups:read']) {
- return groupsAPI.join('cid:' + cid + ':privileges:groups:topics:read', group.name, function(err) {
+ return groupsAPI.join('cid:' + cid + ':privileges:groups:topics:read', group.name, function (err) {
if (!err) {
winston.info('cid:' + cid + ':privileges:groups:topics:read granted to gid: ' + group.name);
}
@@ -539,10 +539,10 @@ Upgrade.upgrade = function(callback) {
next(null);
}, next);
},
- function(next) {
- async.eachSeries(users, function(user, next) {
+ function (next) {
+ async.eachSeries(users, function (user, next) {
if (user.privileges.read) {
- return groupsAPI.join('cid:' + cid + ':privileges:topics:read', user.uid, function(err) {
+ return groupsAPI.join('cid:' + cid + ':privileges:topics:read', user.uid, function (err) {
if (!err) {
winston.info('cid:' + cid + ':privileges:topics:read granted to uid: ' + user.uid);
}
@@ -554,7 +554,7 @@ Upgrade.upgrade = function(callback) {
next(null);
}, next);
}
- ], function(err) {
+ ], function (err) {
if (!err) {
winston.info('-- cid ' + cid + ' upgraded');
}
@@ -562,7 +562,7 @@ Upgrade.upgrade = function(callback) {
next(err);
});
});
- }, function(err) {
+ }, function (err) {
if (err) {
return next(err);
}
@@ -576,7 +576,7 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2016, 5, 13);
if (schemaDate < thisSchemaDate) {
@@ -586,18 +586,18 @@ Upgrade.upgrade = function(callback) {
var batch = require('./batch');
var posts = require('./posts');
var count = 0;
- batch.processSortedSet('posts:pid', function(pids, next) {
+ batch.processSortedSet('posts:pid', function (pids, next) {
winston.info('upgraded ' + count + ' posts');
count += pids.length;
- async.each(pids, function(pid, next) {
+ async.each(pids, function (pid, next) {
async.parallel({
- upvotes: function(next) {
+ upvotes: function (next) {
db.setCount('pid:' + pid + ':upvote', next);
},
- downvotes: function(next) {
+ downvotes: function (next) {
db.setCount('pid:' + pid + ':downvote', next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return next(err);
}
@@ -617,7 +617,7 @@ Upgrade.upgrade = function(callback) {
}
}, next);
}, next);
- }, {}, function(err) {
+ }, {}, function (err) {
if (err) {
return next(err);
}
@@ -630,7 +630,7 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2016, 6, 12);
if (schemaDate < thisSchemaDate) {
@@ -639,17 +639,17 @@ Upgrade.upgrade = function(callback) {
var privilegesAPI = require('./privileges');
var meta = require('./meta');
- db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
+ db.getSortedSetRange('categories:cid', 0, -1, function (err, cids) {
if (err) {
return next(err);
}
- async.eachSeries(cids, function(cid, next) {
- privilegesAPI.categories.list(cid, function(err, data) {
+ async.eachSeries(cids, function (cid, next) {
+ privilegesAPI.categories.list(cid, function (err, data) {
if (err) {
return next(err);
}
- async.eachSeries(data.groups, function(group, next) {
+ async.eachSeries(data.groups, function (group, next) {
if (group.name === 'guests' && parseInt(meta.config.allowGuestUploads, 10) !== 1) {
return next();
}
@@ -660,7 +660,7 @@ Upgrade.upgrade = function(callback) {
}
}, next);
});
- }, function(err) {
+ }, function (err) {
if (err) {
return next(err);
}
@@ -674,19 +674,19 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2016, 7, 5);
if (schemaDate < thisSchemaDate) {
updatesMade = true;
winston.info('[2016/08/05] Removing best posts with negative scores');
var batch = require('./batch');
- batch.processSortedSet('users:joindate', function(ids, next) {
- async.each(ids, function(id, next) {
+ batch.processSortedSet('users:joindate', function (ids, next) {
+ async.each(ids, function (id, next) {
console.log('processing uid ' + id);
db.sortedSetsRemoveRangeByScore(['uid:' + id + ':posts:votes'], '-inf', 0, next);
}, next);
- }, {}, function(err) {
+ }, {}, function (err) {
if (err) {
return next(err);
}
@@ -699,7 +699,7 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2016, 8, 7);
if (schemaDate < thisSchemaDate) {
@@ -709,13 +709,13 @@ Upgrade.upgrade = function(callback) {
var groupsAPI = require('./groups');
var privilegesAPI = require('./privileges');
- db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
+ db.getSortedSetRange('categories:cid', 0, -1, function (err, cids) {
if (err) {
return next(err);
}
- async.eachSeries(cids, function(cid, next) {
- privilegesAPI.categories.list(cid, function(err, data) {
+ async.eachSeries(cids, function (cid, next) {
+ privilegesAPI.categories.list(cid, function (err, data) {
if (err) {
return next(err);
}
@@ -724,13 +724,13 @@ Upgrade.upgrade = function(callback) {
var users = data.users;
async.waterfall([
- function(next) {
- async.eachSeries(groups, function(group, next) {
+ function (next) {
+ async.eachSeries(groups, function (group, next) {
if (group.privileges['groups:topics:reply']) {
return async.parallel([
async.apply(groupsAPI.join, 'cid:' + cid + ':privileges:groups:posts:edit', group.name),
async.apply(groupsAPI.join, 'cid:' + cid + ':privileges:groups:posts:delete', group.name)
- ], function(err) {
+ ], function (err) {
if (!err) {
winston.info('cid:' + cid + ':privileges:groups:posts:edit, cid:' + cid + ':privileges:groups:posts:delete granted to gid: ' + group.name);
}
@@ -742,10 +742,10 @@ Upgrade.upgrade = function(callback) {
next(null);
}, next);
},
- function(next) {
- async.eachSeries(groups, function(group, next) {
+ function (next) {
+ async.eachSeries(groups, function (group, next) {
if (group.privileges['groups:topics:create']) {
- return groupsAPI.join('cid:' + cid + ':privileges:groups:topics:delete', group.name, function(err) {
+ return groupsAPI.join('cid:' + cid + ':privileges:groups:topics:delete', group.name, function (err) {
if (!err) {
winston.info('cid:' + cid + ':privileges:groups:topics:delete granted to gid: ' + group.name);
}
@@ -757,13 +757,13 @@ Upgrade.upgrade = function(callback) {
next(null);
}, next);
},
- function(next) {
- async.eachSeries(users, function(user, next) {
+ function (next) {
+ async.eachSeries(users, function (user, next) {
if (user.privileges['topics:reply']) {
return async.parallel([
async.apply(groupsAPI.join, 'cid:' + cid + ':privileges:posts:edit', user.uid),
async.apply(groupsAPI.join, 'cid:' + cid + ':privileges:posts:delete', user.uid)
- ], function(err) {
+ ], function (err) {
if (!err) {
winston.info('cid:' + cid + ':privileges:posts:edit, cid:' + cid + ':privileges:posts:delete granted to uid: ' + user.uid);
}
@@ -775,10 +775,10 @@ Upgrade.upgrade = function(callback) {
next(null);
}, next);
},
- function(next) {
- async.eachSeries(users, function(user, next) {
+ function (next) {
+ async.eachSeries(users, function (user, next) {
if (user.privileges['topics:create']) {
- return groupsAPI.join('cid:' + cid + ':privileges:topics:delete', user.uid, function(err) {
+ return groupsAPI.join('cid:' + cid + ':privileges:topics:delete', user.uid, function (err) {
if (!err) {
winston.info('cid:' + cid + ':privileges:topics:delete granted to uid: ' + user.uid);
}
@@ -790,7 +790,7 @@ Upgrade.upgrade = function(callback) {
next(null);
}, next);
}
- ], function(err) {
+ ], function (err) {
if (!err) {
winston.info('-- cid ' + cid + ' upgraded');
}
@@ -798,7 +798,7 @@ Upgrade.upgrade = function(callback) {
next(err);
});
});
- }, function(err) {
+ }, function (err) {
if (err) {
return next(err);
}
@@ -812,7 +812,7 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
thisSchemaDate = Date.UTC(2016, 8, 22);
if (schemaDate < thisSchemaDate) {
@@ -820,24 +820,24 @@ Upgrade.upgrade = function(callback) {
winston.info('[2016/09/22] Setting category recent tids');
- db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
+ db.getSortedSetRange('categories:cid', 0, -1, function (err, cids) {
if (err) {
return next(err);
}
- async.eachSeries(cids, function(cid, next) {
- db.getSortedSetRevRange('cid:' + cid + ':pids', 0, 0, function(err, pid) {
+ async.eachSeries(cids, function (cid, next) {
+ db.getSortedSetRevRange('cid:' + cid + ':pids', 0, 0, function (err, pid) {
if (err || !pid) {
return next(err);
}
- db.getObjectFields('post:' + pid, ['tid', 'timestamp'], function(err, postData) {
+ db.getObjectFields('post:' + pid, ['tid', 'timestamp'], function (err, postData) {
if (err || !postData || !postData.tid) {
return next(err);
}
db.sortedSetAdd('cid:' + cid + ':recent_tids', postData.timestamp, postData.tid, next);
});
});
- }, function(err) {
+ }, function (err) {
if (err) {
return next(err);
}
@@ -851,28 +851,28 @@ Upgrade.upgrade = function(callback) {
next();
}
},
- function(next) {
+ function (next) {
function upgradePosts(next) {
var batch = require('./batch');
- batch.processSortedSet('posts:pid', function(ids, next) {
- async.each(ids, function(id, next) {
+ batch.processSortedSet('posts:pid', function (ids, next) {
+ async.each(ids, function (id, next) {
console.log('processing pid ' + id);
async.waterfall([
- function(next) {
+ function (next) {
db.rename('pid:' + id + ':users_favourited', 'pid:' + id + ':users_bookmarked', next);
},
- function(next) {
+ function (next) {
db.getObjectField('post:' + id, 'reputation', next);
},
- function(reputation, next) {
+ function (reputation, next) {
if (parseInt(reputation, 10)) {
db.setObjectField('post:' + id, 'bookmarks', reputation, next);
} else {
next();
}
},
- function(next) {
+ function (next) {
db.deleteObjectField('post:' + id, 'reputation', next);
}
], next);
@@ -883,8 +883,8 @@ Upgrade.upgrade = function(callback) {
function upgradeUsers(next) {
var batch = require('./batch');
- batch.processSortedSet('users:joindate', function(ids, next) {
- async.each(ids, function(id, next) {
+ batch.processSortedSet('users:joindate', function (ids, next) {
+ async.each(ids, function (id, next) {
console.log('processing uid ' + id);
db.rename('uid:' + id + ':favourites', 'uid:' + id + ':bookmarks', next);
}, next);
@@ -896,7 +896,7 @@ Upgrade.upgrade = function(callback) {
if (schemaDate < thisSchemaDate) {
updatesMade = true;
winston.info('[2016/10/8] favourite -> bookmark refactor');
- async.series([upgradePosts, upgradeUsers], function(err) {
+ async.series([upgradePosts, upgradeUsers], function (err) {
if (err) {
return next(err);
}
@@ -910,7 +910,7 @@ Upgrade.upgrade = function(callback) {
}
// Add new schema updates here
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
- ], function(err) {
+ ], function (err) {
if (!err) {
if(updatesMade) {
winston.info('[upgrade] Schema update complete!');
diff --git a/src/user.js b/src/user.js
index 40aefeaaf2..95e422d7a3 100644
--- a/src/user.js
+++ b/src/user.js
@@ -9,7 +9,7 @@ var topics = require('./topics');
var privileges = require('./privileges');
var meta = require('./meta');
-(function(User) {
+(function (User) {
User.email = require('./user/email');
User.notifications = require('./user/notifications');
@@ -35,9 +35,9 @@ var meta = require('./meta');
require('./user/password')(User);
require('./user/info')(User);
- User.updateLastOnlineTime = function(uid, callback) {
- callback = callback || function() {};
- db.getObjectFields('user:' + uid, ['status', 'lastonline'], function(err, userData) {
+ User.updateLastOnlineTime = function (uid, callback) {
+ callback = callback || function () {};
+ db.getObjectFields('user:' + uid, ['status', 'lastonline'], function (err, userData) {
var now = Date.now();
if (err || userData.status === 'offline' || now - parseInt(userData.lastonline, 10) < 300000) {
return callback(err);
@@ -46,21 +46,21 @@ var meta = require('./meta');
});
};
- User.updateOnlineUsers = function(uid, callback) {
- callback = callback || function() {};
+ User.updateOnlineUsers = function (uid, callback) {
+ callback = callback || function () {};
var now = Date.now();
async.waterfall([
- function(next) {
+ function (next) {
db.sortedSetScore('users:online', uid, next);
},
- function(userOnlineTime, next) {
+ function (userOnlineTime, next) {
if (now - parseInt(userOnlineTime, 10) < 300000) {
return callback();
}
db.sortedSetAdd('users:online', now, uid, next);
},
- function(next) {
+ function (next) {
topics.pushUnreadCount(uid);
plugins.fireHook('action:user.online', {uid: uid, timestamp: now});
next();
@@ -68,7 +68,7 @@ var meta = require('./meta');
], callback);
};
- User.getUidsFromSet = function(set, start, stop, callback) {
+ User.getUidsFromSet = function (set, start, stop, callback) {
if (set === 'users:online') {
var count = parseInt(stop, 10) === -1 ? stop : stop - start + 1;
var now = Date.now();
@@ -78,38 +78,38 @@ var meta = require('./meta');
}
};
- User.getUsersFromSet = function(set, uid, start, stop, callback) {
+ User.getUsersFromSet = function (set, uid, start, stop, callback) {
async.waterfall([
- function(next) {
+ function (next) {
User.getUidsFromSet(set, start, stop, next);
},
- function(uids, next) {
+ function (uids, next) {
User.getUsers(uids, uid, next);
}
], callback);
};
- User.getUsersWithFields = function(uids, fields, uid, callback) {
+ User.getUsersWithFields = function (uids, fields, uid, callback) {
async.waterfall([
function (next) {
plugins.fireHook('filter:users.addFields', {fields: fields}, next);
},
function (data, next) {
- data.fields = data.fields.filter(function(field, index, array) {
+ data.fields = data.fields.filter(function (field, index, array) {
return array.indexOf(field) === index;
});
async.parallel({
- userData: function(next) {
+ userData: function (next) {
User.getUsersFields(uids, data.fields, next);
},
- isAdmin: function(next) {
+ isAdmin: function (next) {
User.isAdministrator(uids, next);
}
}, next);
},
function (results, next) {
- results.userData.forEach(function(user, index) {
+ results.userData.forEach(function (user, index) {
if (user) {
user.status = User.getStatus(user);
user.administrator = results.isAdmin[index];
@@ -127,32 +127,32 @@ var meta = require('./meta');
], callback);
};
- User.getUsers = function(uids, uid, callback) {
+ User.getUsers = function (uids, uid, callback) {
var fields = ['uid', 'username', 'userslug', 'picture', 'status', 'flags',
'banned', 'banned:expire', 'joindate', 'postcount', 'reputation', 'email:confirmed', 'lastonline'];
User.getUsersWithFields(uids, fields, uid, callback);
};
- User.getStatus = function(userData) {
+ User.getStatus = function (userData) {
var isOnline = (Date.now() - parseInt(userData.lastonline, 10)) < 300000;
return isOnline ? (userData.status || 'online') : 'offline';
};
- User.isOnline = function(uid, callback) {
+ User.isOnline = function (uid, callback) {
if (Array.isArray(uid)) {
- db.sortedSetScores('users:online', uid, function(err, lastonline) {
+ db.sortedSetScores('users:online', uid, function (err, lastonline) {
if (err) {
return callback(err);
}
var now = Date.now();
- var isOnline = uid.map(function(uid, index) {
+ var isOnline = uid.map(function (uid, index) {
return now - lastonline[index] < 300000;
});
callback(null, isOnline);
});
} else {
- db.sortedSetScore('users:online', uid, function(err, lastonline) {
+ db.sortedSetScore('users:online', uid, function (err, lastonline) {
if (err) {
return callback(err);
}
@@ -163,41 +163,41 @@ var meta = require('./meta');
};
- User.exists = function(uid, callback) {
+ User.exists = function (uid, callback) {
db.isSortedSetMember('users:joindate', uid, callback);
};
- User.existsBySlug = function(userslug, callback) {
- User.getUidByUserslug(userslug, function(err, exists) {
+ User.existsBySlug = function (userslug, callback) {
+ User.getUidByUserslug(userslug, function (err, exists) {
callback(err, !! exists);
});
};
- User.getUidByUsername = function(username, callback) {
+ User.getUidByUsername = function (username, callback) {
if (!username) {
return callback(null, 0);
}
db.sortedSetScore('username:uid', username, callback);
};
- User.getUidsByUsernames = function(usernames, callback) {
+ User.getUidsByUsernames = function (usernames, callback) {
db.sortedSetScores('username:uid', usernames, callback);
};
- User.getUidByUserslug = function(userslug, callback) {
+ User.getUidByUserslug = function (userslug, callback) {
if (!userslug) {
return callback(null, 0);
}
db.sortedSetScore('userslug:uid', userslug, callback);
};
- User.getUsernamesByUids = function(uids, callback) {
- User.getUsersFields(uids, ['username'], function(err, users) {
+ User.getUsernamesByUids = function (uids, callback) {
+ User.getUsersFields(uids, ['username'], function (err, users) {
if (err) {
return callback(err);
}
- users = users.map(function(user) {
+ users = users.map(function (user) {
return user.username;
});
@@ -205,23 +205,23 @@ var meta = require('./meta');
});
};
- User.getUsernameByUserslug = function(slug, callback) {
+ User.getUsernameByUserslug = function (slug, callback) {
async.waterfall([
- function(next) {
+ function (next) {
User.getUidByUserslug(slug, next);
},
- function(uid, next) {
+ function (uid, next) {
User.getUserField(uid, 'username', next);
}
], callback);
};
- User.getUidByEmail = function(email, callback) {
+ User.getUidByEmail = function (email, callback) {
db.sortedSetScore('email:uid', email.toLowerCase(), callback);
};
- User.getUsernameByEmail = function(email, callback) {
- db.sortedSetScore('email:uid', email.toLowerCase(), function(err, uid) {
+ User.getUsernameByEmail = function (email, callback) {
+ db.sortedSetScore('email:uid', email.toLowerCase(), function (err, uid) {
if (err) {
return callback(err);
}
@@ -229,32 +229,32 @@ var meta = require('./meta');
});
};
- User.isModerator = function(uid, cid, callback) {
+ User.isModerator = function (uid, cid, callback) {
privileges.users.isModerator(uid, cid, callback);
};
- User.isAdministrator = function(uid, callback) {
+ User.isAdministrator = function (uid, callback) {
privileges.users.isAdministrator(uid, callback);
};
- User.isGlobalModerator = function(uid, callback) {
+ User.isGlobalModerator = function (uid, callback) {
privileges.users.isGlobalModerator(uid, callback);
};
- User.isAdminOrGlobalMod = function(uid, callback) {
+ User.isAdminOrGlobalMod = function (uid, callback) {
async.parallel({
isAdmin: async.apply(User.isAdministrator, uid),
isGlobalMod: async.apply(User.isGlobalModerator, uid)
- }, function(err, results) {
+ }, function (err, results) {
callback(err, results ? (results.isAdmin || results.isGlobalMod) : false);
});
};
- User.isAdminOrSelf = function(callerUid, uid, callback) {
+ User.isAdminOrSelf = function (callerUid, uid, callback) {
if (parseInt(callerUid, 10) === parseInt(uid, 10)) {
return callback();
}
- User.isAdministrator(callerUid, function(err, isAdmin) {
+ User.isAdministrator(callerUid, function (err, isAdmin) {
if (err || !isAdmin) {
return callback(err || new Error('[[error:no-privileges]]'));
}
@@ -262,32 +262,32 @@ var meta = require('./meta');
});
};
- User.getAdminsandGlobalMods = function(callback) {
+ User.getAdminsandGlobalMods = function (callback) {
async.parallel({
admins: async.apply(groups.getMembers, 'administrators', 0, -1),
mods: async.apply(groups.getMembers, 'Global Moderators', 0, -1)
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
- var uids = results.admins.concat(results.mods).filter(function(uid, index, array) {
+ var uids = results.admins.concat(results.mods).filter(function (uid, index, array) {
return uid && array.indexOf(uid) === index;
});
User.getUsersData(uids, callback);
});
};
- User.addInterstitials = function(callback) {
+ User.addInterstitials = function (callback) {
plugins.registerHook('core', {
hook: 'filter:register.interstitial',
- method: function(data, callback) {
+ method: function (data, callback) {
if (meta.config.termsOfUse && !data.userData.acceptTos) {
data.interstitials.push({
template: 'partials/acceptTos',
data: {
termsOfUse: meta.config.termsOfUse
},
- callback: function(userData, formData, next) {
+ callback: function (userData, formData, next) {
if (formData['agree-terms'] === 'on') {
userData.acceptTos = true;
}
diff --git a/src/user/admin.js b/src/user/admin.js
index 2509028b55..6a1eb5f458 100644
--- a/src/user/admin.js
+++ b/src/user/admin.js
@@ -7,9 +7,9 @@ var posts = require('../posts');
var plugins = require('../plugins');
var winston = require('winston');
-module.exports = function(User) {
+module.exports = function (User) {
- User.logIP = function(uid, ip) {
+ User.logIP = function (uid, ip) {
var now = Date.now();
db.sortedSetAdd('uid:' + uid + ':ip', now, ip || 'Unknown');
if (ip) {
@@ -17,8 +17,8 @@ module.exports = function(User) {
}
};
- User.getIPs = function(uid, stop, callback) {
- db.getSortedSetRevRange('uid:' + uid + ':ip', 0, stop, function(err, ips) {
+ User.getIPs = function (uid, stop, callback) {
+ db.getSortedSetRevRange('uid:' + uid + ':ip', 0, stop, function (err, ips) {
if (err) {
return callback(err);
}
@@ -27,7 +27,7 @@ module.exports = function(User) {
});
};
- User.getUsersCSV = function(callback) {
+ User.getUsersCSV = function (callback) {
winston.info('[user/getUsersCSV] Compiling User CSV data');
var csvContent = '';
@@ -36,13 +36,13 @@ module.exports = function(User) {
db.getSortedSetRangeWithScores('username:uid', 0, -1, next);
},
function (users, next) {
- var uids = users.map(function(user) {
+ var uids = users.map(function (user) {
return user.score;
});
User.getUsersFields(uids, ['uid', 'email', 'username'], next);
},
function (usersData, next) {
- usersData.forEach(function(user) {
+ usersData.forEach(function (user) {
if (user) {
csvContent += user.email + ',' + user.username + ',' + user.uid + '\n';
}
@@ -53,7 +53,7 @@ module.exports = function(User) {
], callback);
};
- User.ban = function(uid, until, reason, callback) {
+ User.ban = function (uid, until, reason, callback) {
// "until" (optional) is unix timestamp in milliseconds
// "reason" (optional) is a string
if (!callback && typeof until === 'function') {
@@ -102,7 +102,7 @@ module.exports = function(User) {
});
};
- User.unban = function(uid, callback) {
+ User.unban = function (uid, callback) {
async.waterfall([
function (next) {
User.setUserFields(uid, {banned: 0, 'banned:expire': 0}, next);
@@ -117,10 +117,10 @@ module.exports = function(User) {
], callback);
};
- User.isBanned = function(uid, callback) {
+ User.isBanned = function (uid, callback) {
async.waterfall([
async.apply(User.getUserFields, uid, ['banned', 'banned:expire']),
- function(userData, next) {
+ function (userData, next) {
var banned = parseInt(userData.banned, 10) === 1;
if (!banned) {
return next(null, banned);
@@ -136,19 +136,19 @@ module.exports = function(User) {
async.apply(db.sortedSetRemove.bind(db), 'users:banned:expire', uid),
async.apply(db.sortedSetRemove.bind(db), 'users:banned', uid),
async.apply(User.setUserFields, uid, {banned:0, 'banned:expire': 0})
- ], function(err) {
+ ], function (err) {
next(err, false);
});
}
], callback);
};
- User.resetFlags = function(uids, callback) {
+ User.resetFlags = function (uids, callback) {
if (!Array.isArray(uids) || !uids.length) {
return callback();
}
- async.eachSeries(uids, function(uid, next) {
+ async.eachSeries(uids, function (uid, next) {
posts.dismissUserFlags(uid, next);
}, callback);
};
diff --git a/src/user/approval.js b/src/user/approval.js
index 25dcf3479a..ac54bcfc67 100644
--- a/src/user/approval.js
+++ b/src/user/approval.js
@@ -13,18 +13,18 @@ var translator = require('../../public/src/modules/translator');
var utils = require('../../public/src/utils');
var plugins = require('../plugins');
-module.exports = function(User) {
+module.exports = function (User) {
- User.addToApprovalQueue = function(userData, callback) {
+ User.addToApprovalQueue = function (userData, callback) {
userData.userslug = utils.slugify(userData.username);
async.waterfall([
- function(next) {
+ function (next) {
User.isDataValid(userData, next);
},
- function(next) {
+ function (next) {
User.hashPassword(userData.password, next);
},
- function(hashedPassword, next) {
+ function (hashedPassword, next) {
var data = {
username: userData.username,
email: userData.email,
@@ -33,13 +33,13 @@ module.exports = function(User) {
};
plugins.fireHook('filter:user.addToApprovalQueue', {data: data, userData: userData}, next);
},
- function(results, next) {
+ function (results, next) {
db.setObject('registration:queue:name:' + userData.username, results.data, next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('registration:queue', Date.now(), userData.username, next);
},
- function(next) {
+ function (next) {
sendNotificationToAdmins(userData.username, next);
}
], callback);
@@ -51,7 +51,7 @@ module.exports = function(User) {
nid: 'new_register:' + username,
path: '/admin/manage/registration',
mergeId: 'new_register'
- }, function(err, notification) {
+ }, function (err, notification) {
if (err || !notification) {
return callback(err);
}
@@ -60,27 +60,27 @@ module.exports = function(User) {
});
}
- User.acceptRegistration = function(username, callback) {
+ User.acceptRegistration = function (username, callback) {
var uid;
var userData;
async.waterfall([
- function(next) {
+ function (next) {
db.getObject('registration:queue:name:' + username, next);
},
- function(_userData, next) {
+ function (_userData, next) {
if (!_userData) {
return callback(new Error('[[error:invalid-data]]'));
}
userData = _userData;
User.create(userData, next);
},
- function(_uid, next) {
+ function (_uid, next) {
uid = _uid;
User.setUserField(uid, 'password', userData.hashedPassword, next);
},
- function(next) {
+ function (next) {
var title = meta.config.title || meta.config.browserTitle || 'NodeBB';
- translator.translate('[[email:welcome-to, ' + title + ']]', meta.config.defaultLang, function(subject) {
+ translator.translate('[[email:welcome-to, ' + title + ']]', meta.config.defaultLang, function (subject) {
var data = {
site_title: title,
username: username,
@@ -92,10 +92,10 @@ module.exports = function(User) {
emailer.send('registration_accepted', uid, data, next);
});
},
- function(next) {
+ function (next) {
removeFromQueue(username, next);
},
- function(next) {
+ function (next) {
markNotificationRead(username, next);
}
], callback);
@@ -108,14 +108,14 @@ module.exports = function(User) {
groups.getMembers('administrators', 0, -1, next);
},
function (uids, next) {
- async.each(uids, function(uid, next) {
+ async.each(uids, function (uid, next) {
notifications.markRead(nid, uid, next);
}, next);
}
], callback);
}
- User.rejectRegistration = function(username, callback) {
+ User.rejectRegistration = function (username, callback) {
async.waterfall([
function (next) {
removeFromQueue(username, next);
@@ -130,26 +130,26 @@ module.exports = function(User) {
async.parallel([
async.apply(db.sortedSetRemove, 'registration:queue', username),
async.apply(db.delete, 'registration:queue:name:' + username)
- ], function(err) {
+ ], function (err) {
callback(err);
});
}
- User.getRegistrationQueue = function(start, stop, callback) {
+ User.getRegistrationQueue = function (start, stop, callback) {
var data;
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRevRangeWithScores('registration:queue', start, stop, next);
},
- function(_data, next) {
+ function (_data, next) {
data = _data;
- var keys = data.filter(Boolean).map(function(user) {
+ var keys = data.filter(Boolean).map(function (user) {
return 'registration:queue:name:' + user.value;
});
db.getObjects(keys, next);
},
- function(users, next) {
- users = users.map(function(user, index) {
+ function (users, next) {
+ users = users.map(function (user, index) {
if (!user) {
return null;
}
@@ -160,7 +160,7 @@ module.exports = function(User) {
return user;
}).filter(Boolean);
- async.map(users, function(user, next) {
+ async.map(users, function (user, next) {
if (!user) {
return next(null, user);
}
@@ -169,19 +169,19 @@ module.exports = function(User) {
user.ip = user.ip.replace('::ffff:', '');
async.parallel([
- function(next) {
- User.getUidsFromSet('ip:' + user.ip + ':uid', 0, -1, function(err, uids) {
+ function (next) {
+ User.getUidsFromSet('ip:' + user.ip + ':uid', 0, -1, function (err, uids) {
if (err) {
return next(err);
}
- User.getUsersFields(uids, ['uid', 'username', 'picture'], function(err, ipMatch) {
+ User.getUsersFields(uids, ['uid', 'username', 'picture'], function (err, ipMatch) {
user.ipMatch = ipMatch;
next(err);
});
});
},
- function(next) {
+ function (next) {
request({
method: 'get',
url: 'http://api.stopforumspam.org/api' +
@@ -204,15 +204,15 @@ module.exports = function(User) {
next();
});
}
- ], function(err) {
+ ], function (err) {
next(err, user);
});
}, next);
},
- function(users, next) {
+ function (users, next) {
plugins.fireHook('filter:user.getRegistrationQueue', {users: users}, next);
},
- function(results, next) {
+ function (results, next) {
next(null, results.users);
}
], callback);
diff --git a/src/user/auth.js b/src/user/auth.js
index b8ff96053b..a60f59fea4 100644
--- a/src/user/auth.js
+++ b/src/user/auth.js
@@ -6,11 +6,11 @@ var db = require('../database');
var meta = require('../meta');
var events = require('../events');
-module.exports = function(User) {
+module.exports = function (User) {
User.auth = {};
- User.auth.logAttempt = function(uid, ip, callback) {
- db.exists('lockout:' + uid, function(err, exists) {
+ User.auth.logAttempt = function (uid, ip, callback) {
+ db.exists('lockout:' + uid, function (err, exists) {
if (err) {
return callback(err);
}
@@ -19,14 +19,14 @@ module.exports = function(User) {
return callback(new Error('[[error:account-locked]]'));
}
- db.increment('loginAttempts:' + uid, function(err, attempts) {
+ db.increment('loginAttempts:' + uid, function (err, attempts) {
if (err) {
return callback(err);
}
if ((meta.config.loginAttempts || 5) < attempts) {
// Lock out the account
- db.set('lockout:' + uid, '', function(err) {
+ db.set('lockout:' + uid, '', function (err) {
if (err) {
return callback(err);
}
@@ -49,18 +49,18 @@ module.exports = function(User) {
});
};
- User.auth.clearLoginAttempts = function(uid) {
+ User.auth.clearLoginAttempts = function (uid) {
db.delete('loginAttempts:' + uid);
};
- User.auth.resetLockout = function(uid, callback) {
+ User.auth.resetLockout = function (uid, callback) {
async.parallel([
async.apply(db.delete, 'loginAttempts:' + uid),
async.apply(db.delete, 'lockout:' + uid)
], callback);
};
- User.auth.getSessions = function(uid, curSessionId, callback) {
+ User.auth.getSessions = function (uid, curSessionId, callback) {
var _sids;
// curSessionId is optional
@@ -76,7 +76,7 @@ module.exports = function(User) {
async.map(sids, db.sessionStore.get.bind(db.sessionStore), next);
},
function (sessions, next) {
- sessions.forEach(function(sessionObj, idx) {
+ sessions.forEach(function (sessionObj, idx) {
if (sessionObj && sessionObj.meta) {
sessionObj.meta.current = curSessionId === _sids[idx];
}
@@ -86,7 +86,7 @@ module.exports = function(User) {
var expiredSids = [],
expired;
- sessions = sessions.filter(function(sessionObj, idx) {
+ sessions = sessions.filter(function (sessionObj, idx) {
expired = !sessionObj || !sessionObj.hasOwnProperty('passport') ||
!sessionObj.passport.hasOwnProperty('user') ||
parseInt(sessionObj.passport.user, 10) !== parseInt(uid, 10);
@@ -98,29 +98,29 @@ module.exports = function(User) {
return !expired;
});
- async.each(expiredSids, function(sid, next) {
+ async.each(expiredSids, function (sid, next) {
User.auth.revokeSession(sid, uid, next);
- }, function(err) {
+ }, function (err) {
next(err, sessions);
});
}
], function (err, sessions) {
- callback(err, sessions ? sessions.map(function(sessObj) {
+ callback(err, sessions ? sessions.map(function (sessObj) {
sessObj.meta.datetimeISO = new Date(sessObj.meta.datetime).toISOString();
return sessObj.meta;
}) : undefined);
});
};
- User.auth.addSession = function(uid, sessionId, callback) {
- callback = callback || function() {};
+ User.auth.addSession = function (uid, sessionId, callback) {
+ callback = callback || function () {};
db.sortedSetAdd('uid:' + uid + ':sessions', Date.now(), sessionId, callback);
};
- User.auth.revokeSession = function(sessionId, uid, callback) {
+ User.auth.revokeSession = function (sessionId, uid, callback) {
winston.verbose('[user.auth] Revoking session ' + sessionId + ' for user ' + uid);
- db.sessionStore.get(sessionId, function(err, sessionObj) {
+ db.sessionStore.get(sessionId, function (err, sessionObj) {
if (err) {
return callback(err);
}
@@ -138,11 +138,11 @@ module.exports = function(User) {
});
};
- User.auth.revokeAllSessions = function(uid, callback) {
+ User.auth.revokeAllSessions = function (uid, callback) {
async.waterfall([
async.apply(db.getSortedSetRange, 'uid:' + uid + ':sessions', 0, -1),
function (sids, next) {
- async.each(sids, function(sid, next) {
+ async.each(sids, function (sid, next) {
User.auth.revokeSession(sid, uid, next);
}, next);
}
diff --git a/src/user/categories.js b/src/user/categories.js
index 7a87f5e441..fee8fc8bb0 100644
--- a/src/user/categories.js
+++ b/src/user/categories.js
@@ -5,33 +5,33 @@ var async = require('async');
var db = require('../database');
var categories = require('../categories');
-module.exports = function(User) {
+module.exports = function (User) {
- User.getIgnoredCategories = function(uid, callback) {
+ User.getIgnoredCategories = function (uid, callback) {
db.getSortedSetRange('uid:' + uid + ':ignored:cids', 0, -1, callback);
};
- User.getWatchedCategories = function(uid, callback) {
+ User.getWatchedCategories = function (uid, callback) {
async.parallel({
- ignored: function(next) {
+ ignored: function (next) {
User.getIgnoredCategories(uid, next);
},
- all: function(next) {
+ all: function (next) {
db.getSortedSetRange('categories:cid', 0, -1, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
- var watched = results.all.filter(function(cid) {
+ var watched = results.all.filter(function (cid) {
return cid && results.ignored.indexOf(cid) === -1;
});
callback(null, watched);
});
};
- User.ignoreCategory = function(uid, cid, callback) {
+ User.ignoreCategory = function (uid, cid, callback) {
if (!uid) {
return callback();
}
@@ -52,7 +52,7 @@ module.exports = function(User) {
], callback);
};
- User.watchCategory = function(uid, cid, callback) {
+ User.watchCategory = function (uid, cid, callback) {
if (!uid) {
return callback();
}
diff --git a/src/user/create.js b/src/user/create.js
index 51ad7b03d0..46508d1d0b 100644
--- a/src/user/create.js
+++ b/src/user/create.js
@@ -8,16 +8,16 @@ var plugins = require('../plugins');
var groups = require('../groups');
var meta = require('../meta');
-module.exports = function(User) {
+module.exports = function (User) {
- User.create = function(data, callback) {
+ User.create = function (data, callback) {
data.username = data.username.trim();
data.userslug = utils.slugify(data.username);
if (data.email !== undefined) {
data.email = validator.escape(String(data.email).trim());
}
- User.isDataValid(data, function(err) {
+ User.isDataValid(data, function (err) {
if (err) {
return callback(err);
}
@@ -46,13 +46,13 @@ module.exports = function(User) {
};
async.parallel({
- renamedUsername: function(next) {
+ renamedUsername: function (next) {
renameUsername(userData, next);
},
- userData: function(next) {
+ userData: function (next) {
plugins.fireHook('filter:user.create', {user: userData, data: data}, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -65,44 +65,44 @@ module.exports = function(User) {
}
async.waterfall([
- function(next) {
+ function (next) {
db.incrObjectField('global', 'nextUid', next);
},
- function(uid, next) {
+ function (uid, next) {
userData.uid = uid;
db.setObject('user:' + uid, userData, next);
},
- function(next) {
+ function (next) {
async.parallel([
- function(next) {
+ function (next) {
db.incrObjectField('global', 'userCount', next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('username:uid', userData.uid, userData.username, next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('username:sorted', 0, userData.username.toLowerCase() + ':' + userData.uid, next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('userslug:uid', userData.uid, userData.userslug, next);
},
- function(next) {
+ function (next) {
var sets = ['users:joindate', 'users:online'];
if (parseInt(userData.uid) !== 1) {
sets.push('users:notvalidated');
}
db.sortedSetsAdd(sets, timestamp, userData.uid, next);
},
- function(next) {
+ function (next) {
db.sortedSetsAdd(['users:postcount', 'users:reputation'], 0, userData.uid, next);
},
- function(next) {
+ function (next) {
groups.join('registered-users', userData.uid, next);
},
- function(next) {
+ function (next) {
User.notifications.sendWelcomeNotification(userData.uid, next);
},
- function(next) {
+ function (next) {
if (userData.email) {
async.parallel([
async.apply(db.sortedSetAdd, 'email:uid', userData.uid, userData.email.toLowerCase()),
@@ -116,12 +116,12 @@ module.exports = function(User) {
next();
}
},
- function(next) {
+ function (next) {
if (!data.password) {
return next();
}
- User.hashPassword(data.password, function(err, hash) {
+ User.hashPassword(data.password, function (err, hash) {
if (err) {
return next(err);
}
@@ -132,12 +132,12 @@ module.exports = function(User) {
], next);
});
},
- function(next) {
+ function (next) {
User.updateDigestSetting(userData.uid, meta.config.dailyDigestFreq, next);
}
], next);
},
- function(results, next) {
+ function (results, next) {
if (userNameChanged) {
User.notifications.sendNameChangeNotification(userData.uid, userData.username);
}
@@ -149,28 +149,28 @@ module.exports = function(User) {
});
};
- User.isDataValid = function(userData, callback) {
+ User.isDataValid = function (userData, callback) {
async.parallel({
- emailValid: function(next) {
+ emailValid: function (next) {
if (userData.email) {
next(!utils.isEmailValid(userData.email) ? new Error('[[error:invalid-email]]') : null);
} else {
next();
}
},
- userNameValid: function(next) {
+ userNameValid: function (next) {
next((!utils.isUserNameValid(userData.username) || !userData.userslug) ? new Error('[[error:invalid-username, ' + userData.username + ']]') : null);
},
- passwordValid: function(next) {
+ passwordValid: function (next) {
if (userData.password) {
User.isPasswordValid(userData.password, next);
} else {
next();
}
},
- emailAvailable: function(next) {
+ emailAvailable: function (next) {
if (userData.email) {
- User.email.available(userData.email, function(err, available) {
+ User.email.available(userData.email, function (err, available) {
if (err) {
return next(err);
}
@@ -180,12 +180,12 @@ module.exports = function(User) {
next();
}
}
- }, function(err) {
+ }, function (err) {
callback(err);
});
};
- User.isPasswordValid = function(password, callback) {
+ User.isPasswordValid = function (password, callback) {
if (!password || !utils.isPasswordValid(password)) {
return callback(new Error('[[error:invalid-password]]'));
}
@@ -202,15 +202,15 @@ module.exports = function(User) {
};
function renameUsername(userData, callback) {
- meta.userOrGroupExists(userData.userslug, function(err, exists) {
+ meta.userOrGroupExists(userData.userslug, function (err, exists) {
if (err || !exists) {
return callback(err);
}
var newUsername = '';
- async.forever(function(next) {
+ async.forever(function (next) {
newUsername = userData.username + (Math.floor(Math.random() * 255) + 1);
- User.existsBySlug(newUsername, function(err, exists) {
+ User.existsBySlug(newUsername, function (err, exists) {
if (err) {
return callback(err);
}
@@ -220,7 +220,7 @@ module.exports = function(User) {
next();
}
});
- }, function(username) {
+ }, function (username) {
callback(null, username);
});
});
diff --git a/src/user/data.js b/src/user/data.js
index 19c54895dc..cbaf066ded 100644
--- a/src/user/data.js
+++ b/src/user/data.js
@@ -8,24 +8,24 @@ var db = require('../database');
var plugins = require('../plugins');
var utils = require('../../public/src/utils');
-module.exports = function(User) {
+module.exports = function (User) {
var iconBackgrounds = ['#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3',
'#009688', '#1b5e20', '#33691e', '#827717', '#e65100', '#ff5722', '#795548', '#607d8b'];
- User.getUserField = function(uid, field, callback) {
- User.getUserFields(uid, [field], function(err, user) {
+ User.getUserField = function (uid, field, callback) {
+ User.getUserFields(uid, [field], function (err, user) {
callback(err, user ? user[field] : null);
});
};
- User.getUserFields = function(uid, fields, callback) {
- User.getUsersFields([uid], fields, function(err, users) {
+ User.getUserFields = function (uid, fields, callback) {
+ User.getUsersFields([uid], fields, function (err, users) {
callback(err, users ? users[0] : null);
});
};
- User.getUsersFields = function(uids, fields, callback) {
+ User.getUsersFields = function (uids, fields, callback) {
var fieldsToRemove = [];
function addField(field) {
if (fields.indexOf(field) === -1) {
@@ -38,7 +38,7 @@ module.exports = function(User) {
return callback(null, []);
}
- var keys = uids.map(function(uid) {
+ var keys = uids.map(function (uid) {
return 'user:' + uid;
});
@@ -55,7 +55,7 @@ module.exports = function(User) {
addField('lastonline');
}
- db.getObjectsFields(keys, fields, function(err, users) {
+ db.getObjectsFields(keys, fields, function (err, users) {
if (err) {
return callback(err);
}
@@ -64,27 +64,27 @@ module.exports = function(User) {
});
};
- User.getMultipleUserFields = function(uids, fields, callback) {
+ User.getMultipleUserFields = function (uids, fields, callback) {
winston.warn('[deprecated] User.getMultipleUserFields is deprecated please use User.getUsersFields');
User.getUsersFields(uids, fields, callback);
};
- User.getUserData = function(uid, callback) {
- User.getUsersData([uid], function(err, users) {
+ User.getUserData = function (uid, callback) {
+ User.getUsersData([uid], function (err, users) {
callback(err, users ? users[0] : null);
});
};
- User.getUsersData = function(uids, callback) {
+ User.getUsersData = function (uids, callback) {
if (!Array.isArray(uids) || !uids.length) {
return callback(null, []);
}
- var keys = uids.map(function(uid) {
+ var keys = uids.map(function (uid) {
return 'user:' + uid;
});
- db.getObjects(keys, function(err, users) {
+ db.getObjects(keys, function (err, users) {
if (err) {
return callback(err);
}
@@ -94,7 +94,7 @@ module.exports = function(User) {
};
function modifyUserData(users, fieldsToRemove, callback) {
- users.forEach(function(user) {
+ users.forEach(function (user) {
if (!user) {
return;
}
@@ -133,7 +133,7 @@ module.exports = function(User) {
// User Icons
if (user.hasOwnProperty('picture') && user.username && parseInt(user.uid, 10)) {
user['icon:text'] = (user.username[0] || '').toUpperCase();
- user['icon:bgColor'] = iconBackgrounds[Array.prototype.reduce.call(user.username, function(cur, next) {
+ user['icon:bgColor'] = iconBackgrounds[Array.prototype.reduce.call(user.username, function (cur, next) {
return cur + next.charCodeAt();
}, 0) % iconBackgrounds.length];
}
@@ -150,9 +150,9 @@ module.exports = function(User) {
plugins.fireHook('filter:users.get', users, callback);
}
- User.setUserField = function(uid, field, value, callback) {
- callback = callback || function() {};
- db.setObjectField('user:' + uid, field, value, function(err) {
+ User.setUserField = function (uid, field, value, callback) {
+ callback = callback || function () {};
+ db.setObjectField('user:' + uid, field, value, function (err) {
if (err) {
return callback(err);
}
@@ -161,9 +161,9 @@ module.exports = function(User) {
});
};
- User.setUserFields = function(uid, data, callback) {
- callback = callback || function() {};
- db.setObject('user:' + uid, data, function(err) {
+ User.setUserFields = function (uid, data, callback) {
+ callback = callback || function () {};
+ db.setObject('user:' + uid, data, function (err) {
if (err) {
return callback(err);
}
@@ -176,9 +176,9 @@ module.exports = function(User) {
});
};
- User.incrementUserFieldBy = function(uid, field, value, callback) {
- callback = callback || function() {};
- db.incrObjectFieldBy('user:' + uid, field, value, function(err, value) {
+ User.incrementUserFieldBy = function (uid, field, value, callback) {
+ callback = callback || function () {};
+ db.incrObjectFieldBy('user:' + uid, field, value, function (err, value) {
if (err) {
return callback(err);
}
@@ -188,9 +188,9 @@ module.exports = function(User) {
});
};
- User.decrementUserFieldBy = function(uid, field, value, callback) {
- callback = callback || function() {};
- db.incrObjectFieldBy('user:' + uid, field, -value, function(err, value) {
+ User.decrementUserFieldBy = function (uid, field, value, callback) {
+ callback = callback || function () {};
+ db.incrObjectFieldBy('user:' + uid, field, -value, function (err, value) {
if (err) {
return callback(err);
}
diff --git a/src/user/delete.js b/src/user/delete.js
index 1e88c90a5a..e03333d7c1 100644
--- a/src/user/delete.js
+++ b/src/user/delete.js
@@ -9,42 +9,42 @@ var groups = require('../groups');
var plugins = require('../plugins');
var batch = require('../batch');
-module.exports = function(User) {
+module.exports = function (User) {
- User.delete = function(callerUid, uid, callback) {
+ User.delete = function (callerUid, uid, callback) {
if (!parseInt(uid, 10)) {
return callback(new Error('[[error:invalid-uid]]'));
}
async.waterfall([
- function(next) {
+ function (next) {
deletePosts(callerUid, uid, next);
},
- function(next) {
+ function (next) {
deleteTopics(callerUid, uid, next);
},
- function(next) {
+ function (next) {
User.deleteAccount(uid, next);
}
], callback);
};
function deletePosts(callerUid, uid, callback) {
- batch.processSortedSet('uid:' + uid + ':posts', function(ids, next) {
- async.eachSeries(ids, function(pid, next) {
+ batch.processSortedSet('uid:' + uid + ':posts', function (ids, next) {
+ async.eachSeries(ids, function (pid, next) {
posts.purge(pid, callerUid, next);
}, next);
}, {alwaysStartAt: 0}, callback);
}
function deleteTopics(callerUid, uid, callback) {
- batch.processSortedSet('uid:' + uid + ':topics', function(ids, next) {
- async.eachSeries(ids, function(tid, next) {
+ batch.processSortedSet('uid:' + uid + ':topics', function (ids, next) {
+ async.eachSeries(ids, function (tid, next) {
topics.purge(tid, callerUid, next);
}, next);
}, {alwaysStartAt: 0}, callback);
}
- User.deleteAccount = function(uid, callback) {
+ User.deleteAccount = function (uid, callback) {
var userData;
async.waterfall([
function (next) {
@@ -65,19 +65,19 @@ module.exports = function(User) {
},
function (next) {
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetRemove('username:uid', userData.username, next);
},
- function(next) {
+ function (next) {
db.sortedSetRemove('username:sorted', userData.username.toLowerCase() + ':' + uid, next);
},
- function(next) {
+ function (next) {
db.sortedSetRemove('userslug:uid', userData.userslug, next);
},
- function(next) {
+ function (next) {
db.sortedSetRemove('fullname:uid', userData.fullname, next);
},
- function(next) {
+ function (next) {
if (userData.email) {
async.parallel([
async.apply(db.sortedSetRemove, 'email:uid', userData.email.toLowerCase()),
@@ -87,7 +87,7 @@ module.exports = function(User) {
next();
}
},
- function(next) {
+ function (next) {
db.sortedSetsRemove([
'users:joindate',
'users:postcount',
@@ -100,10 +100,10 @@ module.exports = function(User) {
'digest:month:uids'
], uid, next);
},
- function(next) {
+ function (next) {
db.decrObjectField('global', 'userCount', next);
},
- function(next) {
+ function (next) {
var keys = [
'uid:' + uid + ':notifications:read',
'uid:' + uid + ':notifications:unread',
@@ -120,13 +120,13 @@ module.exports = function(User) {
];
db.deleteAll(keys, next);
},
- function(next) {
+ function (next) {
deleteUserIps(uid, next);
},
- function(next) {
+ function (next) {
deleteUserFromFollowers(uid, next);
},
- function(next) {
+ function (next) {
groups.leaveAllGroups(uid, next);
}
], next);
@@ -146,15 +146,15 @@ module.exports = function(User) {
}, next);
},
function (pids, next) {
- pids = pids.upvotedPids.concat(pids.downvotedPids).filter(function(pid, index, array) {
+ pids = pids.upvotedPids.concat(pids.downvotedPids).filter(function (pid, index, array) {
return pid && array.indexOf(pid) === index;
});
- async.eachSeries(pids, function(pid, next) {
+ async.eachSeries(pids, function (pid, next) {
posts.unvote(pid, uid, next);
}, next);
}
- ], function(err) {
+ ], function (err) {
callback(err);
});
}
@@ -165,10 +165,10 @@ module.exports = function(User) {
db.getSortedSetRange('uid:' + uid + ':chat:rooms', 0, -1, next);
},
function (roomIds, next) {
- var userKeys = roomIds.map(function(roomId) {
+ var userKeys = roomIds.map(function (roomId) {
return 'uid:' + uid + ':chat:room:' + roomId + ':mids';
});
- var roomKeys = roomIds.map(function(roomId) {
+ var roomKeys = roomIds.map(function (roomId) {
return 'chat:room:' + roomId + ':uids';
});
@@ -177,7 +177,7 @@ module.exports = function(User) {
async.apply(db.deleteAll, userKeys)
], next);
}
- ], function(err) {
+ ], function (err) {
callback(err);
});
}
@@ -188,7 +188,7 @@ module.exports = function(User) {
db.getSortedSetRange('uid:' + uid + ':ip', 0, -1, next);
},
function (ips, next) {
- var keys = ips.map(function(ip) {
+ var keys = ips.map(function (ip) {
return 'ip:' + ip + ':uid';
});
db.sortedSetsRemove(keys, uid, next);
@@ -203,10 +203,10 @@ module.exports = function(User) {
async.parallel({
followers: async.apply(db.getSortedSetRange, 'followers:' + uid, 0, -1),
following: async.apply(db.getSortedSetRange, 'following:' + uid, 0, -1)
- }, function(err, results) {
+ }, function (err, results) {
function updateCount(uids, name, fieldName, next) {
- async.each(uids, function(uid, next) {
- db.sortedSetCard(name + uid, function(err, count) {
+ async.each(uids, function (uid, next) {
+ db.sortedSetCard(name + uid, function (err, count) {
if (err) {
return next(err);
}
@@ -220,11 +220,11 @@ module.exports = function(User) {
return callback(err);
}
- var followingSets = results.followers.map(function(uid) {
+ var followingSets = results.followers.map(function (uid) {
return 'following:' + uid;
});
- var followerSets = results.following.map(function(uid) {
+ var followerSets = results.following.map(function (uid) {
return 'followers:' + uid;
});
diff --git a/src/user/digest.js b/src/user/digest.js
index c0ae1753a0..2ea1401c2c 100644
--- a/src/user/digest.js
+++ b/src/user/digest.js
@@ -12,8 +12,8 @@ var plugins = require('../plugins');
var emailer = require('../emailer');
var utils = require('../../public/src/utils');
-(function(Digest) {
- Digest.execute = function(interval) {
+(function (Digest) {
+ Digest.execute = function (interval) {
var digestsDisabled = meta.config.disableEmailSubscriptions !== undefined && parseInt(meta.config.disableEmailSubscriptions, 10) === 1;
if (digestsDisabled) {
return winston.verbose('[user/jobs] Did not send digests (' + interval + ') because subscription system is disabled.');
@@ -27,13 +27,13 @@ var utils = require('../../public/src/utils');
async.parallel({
topics: async.apply(topics.getLatestTopics, 0, 0, 9, interval),
subscribers: async.apply(Digest.getSubscribers, interval)
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return winston.error('[user/jobs] Could not send digests (' + interval + '): ' + err.message);
}
// Fix relative paths in topic data
- data.topics.topics = data.topics.topics.map(function(topicObj) {
+ data.topics.topics = data.topics.topics.map(function (topicObj) {
var user = topicObj.hasOwnProperty('teaser') && topicObj.teaser !== undefined ? topicObj.teaser.user : topicObj.user;
if (user && user.picture && utils.isRelativeUrl(user.picture)) {
user.picture = nconf.get('base_url') + user.picture;
@@ -45,7 +45,7 @@ var utils = require('../../public/src/utils');
data.interval = interval;
if (data.subscribers.length) {
- Digest.send(data, function(err) {
+ Digest.send(data, function (err) {
if (err) {
winston.error('[user/jobs] Could not send digests (' + interval + '): ' + err.message);
} else {
@@ -58,8 +58,8 @@ var utils = require('../../public/src/utils');
});
};
- Digest.getSubscribers = function(interval, callback) {
- db.getSortedSetRange('digest:' + interval + ':uids', 0, -1, function(err, subscribers) {
+ Digest.getSubscribers = function (interval, callback) {
+ db.getSortedSetRange('digest:' + interval + ':uids', 0, -1, function (err, subscribers) {
if (err) {
return callback(err);
}
@@ -67,23 +67,23 @@ var utils = require('../../public/src/utils');
plugins.fireHook('filter:digest.subscribers', {
interval: interval,
subscribers: subscribers
- }, function(err, returnData) {
+ }, function (err, returnData) {
callback(err, returnData.subscribers);
});
});
};
- Digest.send = function(data, callback) {
+ Digest.send = function (data, callback) {
var now = new Date();
- user.getUsersFields(data.subscribers, ['uid', 'username', 'userslug', 'lastonline'], function(err, users) {
+ user.getUsersFields(data.subscribers, ['uid', 'username', 'userslug', 'lastonline'], function (err, users) {
if (err) {
winston.error('[user/jobs] Could not send digests (' + data.interval + '): ' + err.message);
return callback(err);
}
- async.eachLimit(users, 100, function(userObj, next) {
- user.notifications.getDailyUnread(userObj.uid, function(err, notifications) {
+ async.eachLimit(users, 100, function (userObj, next) {
+ user.notifications.getDailyUnread(userObj.uid, function (err, notifications) {
if (err) {
winston.error('[user/jobs] Could not send digests (' + data.interval + '): ' + err.message);
return next(err);
diff --git a/src/user/email.js b/src/user/email.js
index 902d2ead73..5eb93b71e0 100644
--- a/src/user/email.js
+++ b/src/user/email.js
@@ -12,59 +12,59 @@ var db = require('../database');
var meta = require('../meta');
var emailer = require('../emailer');
-(function(UserEmail) {
+(function (UserEmail) {
- UserEmail.exists = function(email, callback) {
- user.getUidByEmail(email.toLowerCase(), function(err, exists) {
+ UserEmail.exists = function (email, callback) {
+ user.getUidByEmail(email.toLowerCase(), function (err, exists) {
callback(err, !!exists);
});
};
- UserEmail.available = function(email, callback) {
- db.isSortedSetMember('email:uid', email.toLowerCase(), function(err, exists) {
+ UserEmail.available = function (email, callback) {
+ db.isSortedSetMember('email:uid', email.toLowerCase(), function (err, exists) {
callback(err, !exists);
});
};
- UserEmail.sendValidationEmail = function(uid, email, callback) {
- callback = callback || function() {};
+ UserEmail.sendValidationEmail = function (uid, email, callback) {
+ callback = callback || function () {};
var confirm_code = utils.generateUUID();
var confirm_link = nconf.get('url') + '/confirm/' + confirm_code;
var emailInterval = meta.config.hasOwnProperty('emailConfirmInterval') ? parseInt(meta.config.emailConfirmInterval, 10) : 10;
async.waterfall([
- function(next) {
+ function (next) {
db.get('uid:' + uid + ':confirm:email:sent', next);
},
- function(sent, next) {
+ function (sent, next) {
if (sent) {
return next(new Error('[[error:confirm-email-already-sent, ' + emailInterval + ']]'));
}
db.set('uid:' + uid + ':confirm:email:sent', 1, next);
},
- function(next) {
+ function (next) {
db.pexpireAt('uid:' + uid + ':confirm:email:sent', Date.now() + (emailInterval * 60 * 1000), next);
},
- function(next) {
+ function (next) {
plugins.fireHook('filter:user.verify.code', confirm_code, next);
},
- function(_confirm_code, next) {
+ function (_confirm_code, next) {
confirm_code = _confirm_code;
db.setObject('confirm:' + confirm_code, {
email: email.toLowerCase(),
uid: uid
}, next);
},
- function(next) {
+ function (next) {
db.expireAt('confirm:' + confirm_code, Math.floor(Date.now() / 1000 + 60 * 60 * 24), next);
},
- function(next) {
+ function (next) {
user.getUserField(uid, 'username', next);
},
- function(username, next) {
+ function (username, next) {
var title = meta.config.title || meta.config.browserTitle || 'NodeBB';
- translator.translate('[[email:welcome-to, ' + title + ']]', meta.config.defaultLang, function(subject) {
+ translator.translate('[[email:welcome-to, ' + title + ']]', meta.config.defaultLang, function (subject) {
var data = {
site_title: title,
username: username,
@@ -87,8 +87,8 @@ var emailer = require('../emailer');
], callback);
};
- UserEmail.confirm = function(code, callback) {
- db.getObject('confirm:' + code, function(err, confirmObj) {
+ UserEmail.confirm = function (code, callback) {
+ db.getObject('confirm:' + code, function (err, confirmObj) {
if (err) {
return callback(new Error('[[error:parse-error]]'));
}
@@ -98,10 +98,10 @@ var emailer = require('../emailer');
async.apply(user.setUserField, confirmObj.uid, 'email:confirmed', 1),
async.apply(db.delete, 'confirm:' + code),
async.apply(db.delete, 'uid:' + confirmObj.uid + ':confirm:email:sent'),
- function(next) {
+ function (next) {
db.sortedSetRemove('users:notvalidated', confirmObj.uid, next);
}
- ], function(err) {
+ ], function (err) {
callback(err ? new Error('[[error:email-confirm-failed]]') : null);
});
} else {
diff --git a/src/user/follow.js b/src/user/follow.js
index 7295f01519..0812c1004d 100644
--- a/src/user/follow.js
+++ b/src/user/follow.js
@@ -5,13 +5,13 @@ var async = require('async'),
plugins = require('../plugins'),
db = require('../database');
-module.exports = function(User) {
+module.exports = function (User) {
- User.follow = function(uid, followuid, callback) {
+ User.follow = function (uid, followuid, callback) {
toggleFollow('follow', uid, followuid, callback);
};
- User.unfollow = function(uid, unfollowuid, callback) {
+ User.unfollow = function (uid, unfollowuid, callback) {
toggleFollow('unfollow', uid, unfollowuid, callback);
};
@@ -61,11 +61,11 @@ module.exports = function(User) {
], callback);
}
- User.getFollowing = function(uid, start, stop, callback) {
+ User.getFollowing = function (uid, start, stop, callback) {
getFollow(uid, 'following', start, stop, callback);
};
- User.getFollowers = function(uid, start, stop, callback) {
+ User.getFollowers = function (uid, start, stop, callback) {
getFollow(uid, 'followers', start, stop, callback);
};
@@ -74,7 +74,7 @@ module.exports = function(User) {
return callback(null, []);
}
- db.getSortedSetRevRange(type + ':' + uid, start, stop, function(err, uids) {
+ db.getSortedSetRevRange(type + ':' + uid, start, stop, function (err, uids) {
if (err) {
return callback(err);
}
@@ -84,7 +84,7 @@ module.exports = function(User) {
uid: uid,
start: start,
stop: stop
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return callback(err);
}
@@ -94,7 +94,7 @@ module.exports = function(User) {
});
}
- User.isFollowing = function(uid, theirid, callback) {
+ User.isFollowing = function (uid, theirid, callback) {
if (!parseInt(uid, 10) || !parseInt(theirid, 10)) {
return callback(null, false);
}
diff --git a/src/user/info.js b/src/user/info.js
index 8f2e4d3a83..43991a800f 100644
--- a/src/user/info.js
+++ b/src/user/info.js
@@ -8,24 +8,24 @@ var db = require('../database');
var posts = require('../posts');
var topics = require('../topics');
-module.exports = function(User) {
- User.getLatestBanInfo = function(uid, callback) {
+module.exports = function (User) {
+ User.getLatestBanInfo = function (uid, callback) {
// Simply retrieves the last record of the user's ban, even if they've been unbanned since then.
var timestamp, expiry, reason;
async.waterfall([
async.apply(db.getSortedSetRevRangeWithScores, 'uid:' + uid + ':bans', 0, 0),
- function(record, next) {
+ function (record, next) {
timestamp = record[0].score;
expiry = record[0].value;
db.getSortedSetRangeByScore('banned:' + uid + ':reasons', 0, -1, timestamp, timestamp, next);
},
- function(_reason, next) {
+ function (_reason, next) {
reason = _reason && _reason.length ? _reason[0] : '';
next();
}
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
@@ -40,19 +40,19 @@ module.exports = function(User) {
})
};
- User.getModerationHistory = function(uid, callback) {
+ User.getModerationHistory = function (uid, callback) {
async.waterfall([
- function(next) {
+ function (next) {
async.parallel({
flags: async.apply(db.getSortedSetRevRangeWithScores, 'uid:' + uid + ':flag:pids', 0, 19),
bans: async.apply(db.getSortedSetRevRangeWithScores, 'uid:' + uid + ':bans', 0, 19),
reasons: async.apply(db.getSortedSetRevRangeWithScores, 'banned:' + uid + ':reasons', 0, 19)
}, next);
},
- function(data, next) {
+ function (data, next) {
getFlagMetadata(data, next);
}
- ], function(err, data) {
+ ], function (err, data) {
if (err) {
return callback(err);
}
@@ -61,12 +61,12 @@ module.exports = function(User) {
});
};
- User.getHistory = function(set, callback) {
- db.getSortedSetRevRangeWithScores(set, 0, -1, function(err, data) {
+ User.getHistory = function (set, callback) {
+ db.getSortedSetRevRangeWithScores(set, 0, -1, function (err, data) {
if (err) {
return callback(err);
}
- callback(null, data.map(function(set) {
+ callback(null, data.map(function (set) {
set.timestamp = set.score;
set.timestampISO = new Date(set.score).toISOString();
set.value = validator.escape(String(set.value.split(':')[0]));
@@ -77,24 +77,24 @@ module.exports = function(User) {
};
function getFlagMetadata(data, callback) {
- var pids = data.flags.map(function(flagObj) {
+ var pids = data.flags.map(function (flagObj) {
return parseInt(flagObj.value, 10);
});
- posts.getPostsFields(pids, ['tid'], function(err, postData) {
+ posts.getPostsFields(pids, ['tid'], function (err, postData) {
if (err) {
return callback(err);
}
- var tids = postData.map(function(post) {
+ var tids = postData.map(function (post) {
return post.tid;
});
- topics.getTopicsFields(tids, ['title'], function(err, topicData) {
+ topics.getTopicsFields(tids, ['title'], function (err, topicData) {
if (err) {
return callback(err);
}
- data.flags = data.flags.map(function(flagObj, idx) {
+ data.flags = data.flags.map(function (flagObj, idx) {
flagObj.pid = flagObj.value;
flagObj.timestamp = flagObj.score;
flagObj.timestampISO = new Date(flagObj.score).toISOString();
@@ -112,12 +112,12 @@ module.exports = function(User) {
}
function formatBanData(data) {
- var reasons = data.reasons.reduce(function(memo, cur) {
+ var reasons = data.reasons.reduce(function (memo, cur) {
memo[cur.score] = cur.value;
return memo;
}, {});
- data.bans = data.bans.map(function(banObj) {
+ data.bans = data.bans.map(function (banObj) {
banObj.until = parseInt(banObj.value, 10);
banObj.untilReadable = new Date(banObj.until).toString();
banObj.timestamp = parseInt(banObj.score, 10);
diff --git a/src/user/invite.js b/src/user/invite.js
index 34521550a5..726a7af144 100644
--- a/src/user/invite.js
+++ b/src/user/invite.js
@@ -11,30 +11,30 @@ var translator = require('../../public/src/modules/translator');
var utils = require('../../public/src/utils');
-module.exports = function(User) {
+module.exports = function (User) {
- User.getInvites = function(uid, callback) {
+ User.getInvites = function (uid, callback) {
db.getSetMembers('invitation:uid:' + uid, callback);
};
- User.getInvitesNumber = function(uid, callback) {
+ User.getInvitesNumber = function (uid, callback) {
db.setCount('invitation:uid:' + uid, callback);
};
- User.getInvitingUsers = function(callback) {
+ User.getInvitingUsers = function (callback) {
db.getSetMembers('invitation:uids', callback);
};
- User.getAllInvites = function(callback) {
+ User.getAllInvites = function (callback) {
var uids;
async.waterfall([
User.getInvitingUsers,
- function(_uids, next) {
+ function (_uids, next) {
uids = _uids;
async.map(uids, User.getInvites, next);
},
- function(invitations, next) {
- invitations = invitations.map(function(invites, index) {
+ function (invitations, next) {
+ invitations = invitations.map(function (invites, index) {
return {
uid: uids[index],
invitations: invites
@@ -45,8 +45,8 @@ module.exports = function(User) {
], callback);
};
- User.sendInvitationEmail = function(uid, email, callback) {
- callback = callback || function() {};
+ User.sendInvitationEmail = function (uid, email, callback) {
+ callback = callback || function () {};
var token = utils.generateUUID();
var registerLink = nconf.get('url') + '/register?token=' + token + '&email=' + encodeURIComponent(email);
@@ -54,39 +54,39 @@ module.exports = function(User) {
var oneDay = 86400000;
async.waterfall([
- function(next) {
+ function (next) {
User.getUidByEmail(email, next);
},
- function(exists, next) {
+ function (exists, next) {
if (exists) {
return next(new Error('[[error:email-taken]]'));
}
next();
},
- function(next) {
+ function (next) {
async.parallel([
- function(next) {
+ function (next) {
db.setAdd('invitation:uid:' + uid, email, next);
},
- function(next) {
+ function (next) {
db.setAdd('invitation:uids', uid, next);
}
- ], function(err) {
+ ], function (err) {
next(err);
});
},
- function(next) {
+ function (next) {
db.set('invitation:email:' + email, token, next);
},
- function(next) {
+ function (next) {
db.pexpireAt('invitation:email:' + email, Date.now() + oneDay, next);
},
- function(next) {
+ function (next) {
User.getUserField(uid, 'username', next);
},
- function(username, next) {
+ function (username, next) {
var title = meta.config.title || meta.config.browserTitle || 'NodeBB';
- translator.translate('[[email:invite, ' + title + ']]', meta.config.defaultLang, function(subject) {
+ translator.translate('[[email:invite, ' + title + ']]', meta.config.defaultLang, function (subject) {
var data = {
site_title: title,
registerLink: registerLink,
@@ -101,16 +101,16 @@ module.exports = function(User) {
], callback);
};
- User.verifyInvitation = function(query, callback) {
+ User.verifyInvitation = function (query, callback) {
if (!query.token || !query.email) {
return callback(new Error('[[error:invalid-data]]'));
}
async.waterfall([
- function(next) {
+ function (next) {
db.get('invitation:email:' + query.email, next);
},
- function(token, next) {
+ function (token, next) {
if (!token || token !== query.token) {
return next(new Error('[[error:invalid-token]]'));
}
@@ -120,8 +120,8 @@ module.exports = function(User) {
], callback);
};
- User.deleteInvitation = function(invitedBy, email, callback) {
- callback = callback || function() {};
+ User.deleteInvitation = function (invitedBy, email, callback) {
+ callback = callback || function () {};
async.waterfall([
function getInvitedByUid(next) {
User.getUidByUsername(invitedBy, next);
@@ -137,15 +137,15 @@ module.exports = function(User) {
function deleteInviteKey(next) {
db.delete('invitation:email:' + email, callback);
}
- ], function(err) {
+ ], function (err) {
next(err)
});
}
], callback);
};
- User.deleteInvitationKey = function(email, callback) {
- callback = callback || function() {};
+ User.deleteInvitationKey = function (email, callback) {
+ callback = callback || function () {};
db.delete('invitation:email:' + email, callback);
};
diff --git a/src/user/jobs.js b/src/user/jobs.js
index 9c9569dc40..956559b470 100644
--- a/src/user/jobs.js
+++ b/src/user/jobs.js
@@ -7,8 +7,8 @@ var meta = require('../meta');
var jobs = {};
-module.exports = function(User) {
- User.startJobs = function(callback) {
+module.exports = function (User) {
+ User.startJobs = function (callback) {
winston.verbose('[user/jobs] (Re-)starting user jobs...');
var terminated = 0;
var started = 0;
@@ -32,21 +32,21 @@ module.exports = function(User) {
}
winston.verbose('[user/jobs] ' + terminated + ' jobs terminated');
- jobs['digest.daily'] = new cronJob('0 0 ' + digestHour + ' * * *', function() {
+ jobs['digest.daily'] = new cronJob('0 0 ' + digestHour + ' * * *', function () {
winston.verbose('[user/jobs] Digest job (daily) started.');
User.digest.execute('day');
}, null, true);
winston.verbose('[user/jobs] Starting job (digest.daily)');
++started;
- jobs['digest.weekly'] = new cronJob('0 0 ' + digestHour + ' * * 0', function() {
+ jobs['digest.weekly'] = new cronJob('0 0 ' + digestHour + ' * * 0', function () {
winston.verbose('[user/jobs] Digest job (weekly) started.');
User.digest.execute('week');
}, null, true);
winston.verbose('[user/jobs] Starting job (digest.weekly)');
++started;
- jobs['digest.monthly'] = new cronJob('0 0 ' + digestHour + ' 1 * *', function() {
+ jobs['digest.monthly'] = new cronJob('0 0 ' + digestHour + ' 1 * *', function () {
winston.verbose('[user/jobs] Digest job (monthly) started.');
User.digest.execute('month');
}, null, true);
diff --git a/src/user/notifications.js b/src/user/notifications.js
index dcc7d3eee3..7182c1a223 100644
--- a/src/user/notifications.js
+++ b/src/user/notifications.js
@@ -10,13 +10,13 @@ var meta = require('../meta');
var notifications = require('../notifications');
var privileges = require('../privileges');
-(function(UserNotifications) {
+(function (UserNotifications) {
- UserNotifications.get = function(uid, callback) {
+ UserNotifications.get = function (uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null , {read: [], unread: []});
}
- getNotifications(uid, 0, 9, function(err, notifications) {
+ getNotifications(uid, 0, 9, function (err, notifications) {
if (err) {
return callback(err);
}
@@ -33,13 +33,13 @@ var privileges = require('../privileges');
});
};
- UserNotifications.getAll = function(uid, start, stop, callback) {
- getNotifications(uid, start, stop, function(err, notifs) {
+ UserNotifications.getAll = function (uid, start, stop, callback) {
+ getNotifications(uid, start, stop, function (err, notifs) {
if (err) {
return callback(err);
}
notifs = notifs.unread.concat(notifs.read);
- notifs = notifs.filter(Boolean).sort(function(a, b) {
+ notifs = notifs.filter(Boolean).sort(function (a, b) {
return b.datetime - a.datetime;
});
@@ -49,10 +49,10 @@ var privileges = require('../privileges');
function getNotifications(uid, start, stop, callback) {
async.parallel({
- unread: function(next) {
+ unread: function (next) {
getNotificationsFromSet('uid:' + uid + ':notifications:unread', false, uid, start, stop, next);
},
- read: function(next) {
+ read: function (next) {
getNotificationsFromSet('uid:' + uid + ':notifications:read', true, uid, start, stop, next);
}
}, callback);
@@ -63,7 +63,7 @@ var privileges = require('../privileges');
async.waterfall([
async.apply(db.getSortedSetRevRange, set, start, stop),
- function(nids, next) {
+ function (nids, next) {
if(!Array.isArray(nids) || !nids.length) {
return callback(null, []);
}
@@ -71,10 +71,10 @@ var privileges = require('../privileges');
setNids = nids;
UserNotifications.getNotifications(nids, uid, next);
},
- function(notifs, next) {
+ function (notifs, next) {
var deletedNids = [];
- notifs.forEach(function(notification, index) {
+ notifs.forEach(function (notification, index) {
if (!notification) {
winston.verbose('[notifications.get] nid ' + setNids[index] + ' not found. Removing.');
deletedNids.push(setNids[index]);
@@ -93,12 +93,12 @@ var privileges = require('../privileges');
], callback);
}
- UserNotifications.getNotifications = function(nids, uid, callback) {
- notifications.getMultiple(nids, function(err, notifications) {
+ UserNotifications.getNotifications = function (nids, uid, callback) {
+ notifications.getMultiple(nids, function (err, notifications) {
if (err) {
return callback(err);
}
- notifications = notifications.filter(function(notification) {
+ notifications = notifications.filter(function (notification) {
return notification && notification.path;
});
callback(null, notifications);
@@ -106,10 +106,10 @@ var privileges = require('../privileges');
};
- UserNotifications.getDailyUnread = function(uid, callback) {
+ UserNotifications.getDailyUnread = function (uid, callback) {
var yesterday = Date.now() - (1000 * 60 * 60 * 24); // Approximate, can be more or less depending on time changes, makes no difference really.
- db.getSortedSetRevRangeByScore('uid:' + uid + ':notifications:unread', 0, 20, '+inf', yesterday, function(err, nids) {
+ db.getSortedSetRevRangeByScore('uid:' + uid + ':notifications:unread', 0, 20, '+inf', yesterday, function (err, nids) {
if (err) {
return callback(err);
}
@@ -122,7 +122,7 @@ var privileges = require('../privileges');
});
};
- UserNotifications.getUnreadCount = function(uid, callback) {
+ UserNotifications.getUnreadCount = function (uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null, 0);
}
@@ -131,20 +131,20 @@ var privileges = require('../privileges');
async.waterfall([
async.apply(db.getSortedSetRevRange, 'uid:' + uid + ':notifications:unread', 0, 99),
async.apply(notifications.filterExists),
- function(nids, next) {
- var keys = nids.map(function(nid) {
+ function (nids, next) {
+ var keys = nids.map(function (nid) {
return 'notifications:' + nid;
});
db.getObjectsFields(keys, ['mergeId'], next);
}
- ], function(err, mergeIds) {
+ ], function (err, mergeIds) {
// A missing (null) mergeId means that notification is counted separately.
- mergeIds = mergeIds.map(function(set) {
+ mergeIds = mergeIds.map(function (set) {
return set.mergeId;
});
- callback(err, mergeIds.reduce(function(count, cur, idx, arr) {
+ callback(err, mergeIds.reduce(function (count, cur, idx, arr) {
if (cur === null || idx === arr.indexOf(cur)) {
++count;
}
@@ -154,8 +154,8 @@ var privileges = require('../privileges');
});
};
- UserNotifications.getUnreadByField = function(uid, field, values, callback) {
- db.getSortedSetRevRange('uid:' + uid + ':notifications:unread', 0, 99, function(err, nids) {
+ UserNotifications.getUnreadByField = function (uid, field, values, callback) {
+ db.getSortedSetRevRange('uid:' + uid + ':notifications:unread', 0, 99, function (err, nids) {
if (err) {
return callback(err);
}
@@ -164,19 +164,19 @@ var privileges = require('../privileges');
return callback(null, []);
}
- var keys = nids.map(function(nid) {
+ var keys = nids.map(function (nid) {
return 'notifications:' + nid;
});
- db.getObjectsFields(keys, ['nid', field], function(err, notifications) {
+ db.getObjectsFields(keys, ['nid', field], function (err, notifications) {
if (err) {
return callback(err);
}
- values = values.map(function() { return values.toString(); });
- nids = notifications.filter(function(notification) {
+ values = values.map(function () { return values.toString(); });
+ nids = notifications.filter(function (notification) {
return notification && notification[field] && values.indexOf(notification[field].toString()) !== -1;
- }).map(function(notification) {
+ }).map(function (notification) {
return notification.nid;
});
@@ -185,21 +185,21 @@ var privileges = require('../privileges');
});
};
- UserNotifications.deleteAll = function(uid, callback) {
+ UserNotifications.deleteAll = function (uid, callback) {
if (!parseInt(uid, 10)) {
return callback();
}
async.parallel([
- function(next) {
+ function (next) {
db.delete('uid:' + uid + ':notifications:unread', next);
},
- function(next) {
+ function (next) {
db.delete('uid:' + uid + ':notifications:read', next);
}
], callback);
};
- UserNotifications.sendTopicNotificationToFollowers = function(uid, topicData, postData) {
+ UserNotifications.sendTopicNotificationToFollowers = function (uid, topicData, postData) {
var followers;
async.waterfall([
function (next) {
@@ -232,7 +232,7 @@ var privileges = require('../privileges');
from: uid
}, next);
}
- ], function(err, notification) {
+ ], function (err, notification) {
if (err) {
return winston.error(err);
}
@@ -243,8 +243,8 @@ var privileges = require('../privileges');
});
};
- UserNotifications.sendWelcomeNotification = function(uid, callback) {
- callback = callback || function() {};
+ UserNotifications.sendWelcomeNotification = function (uid, callback) {
+ callback = callback || function () {};
if (!meta.config.welcomeNotification) {
return callback();
}
@@ -255,7 +255,7 @@ var privileges = require('../privileges');
bodyShort: meta.config.welcomeNotification,
path: path,
nid: 'welcome_' + uid
- }, function(err, notification) {
+ }, function (err, notification) {
if (err || !notification) {
return callback(err);
}
@@ -264,22 +264,22 @@ var privileges = require('../privileges');
});
};
- UserNotifications.sendNameChangeNotification = function(uid, username) {
+ UserNotifications.sendNameChangeNotification = function (uid, username) {
notifications.create({
bodyShort: '[[user:username_taken_workaround, ' + username + ']]',
image: 'brand:logo',
nid: 'username_taken:' + uid,
datetime: Date.now()
- }, function(err, notification) {
+ }, function (err, notification) {
if (!err && notification) {
notifications.push(notification, uid);
}
});
};
- UserNotifications.pushCount = function(uid) {
+ UserNotifications.pushCount = function (uid) {
var websockets = require('./../socket.io');
- UserNotifications.getUnreadCount(uid, function(err, count) {
+ UserNotifications.getUnreadCount(uid, function (err, count) {
if (err) {
return winston.error(err.stack);
}
diff --git a/src/user/password.js b/src/user/password.js
index e60ae9b753..8e9b7780e3 100644
--- a/src/user/password.js
+++ b/src/user/password.js
@@ -6,9 +6,9 @@ var nconf = require('nconf');
var db = require('../database');
var Password = require('../password');
-module.exports = function(User) {
+module.exports = function (User) {
- User.hashPassword = function(password, callback) {
+ User.hashPassword = function (password, callback) {
if (!password) {
return callback(null, password);
}
@@ -16,7 +16,7 @@ module.exports = function(User) {
Password.hash(nconf.get('bcrypt_rounds') || 12, password, callback);
};
- User.isPasswordCorrect = function(uid, password, callback) {
+ User.isPasswordCorrect = function (uid, password, callback) {
password = password || '';
async.waterfall([
function (next) {
@@ -27,7 +27,7 @@ module.exports = function(User) {
return callback(null, true);
}
- User.isPasswordValid(password, function(err) {
+ User.isPasswordValid(password, function (err) {
if (err) {
return next(err);
}
@@ -38,8 +38,8 @@ module.exports = function(User) {
], callback);
};
- User.hasPassword = function(uid, callback) {
- db.getObjectField('user:' + uid, 'password', function(err, hashedPassword) {
+ User.hasPassword = function (uid, callback) {
+ db.getObjectField('user:' + uid, 'password', function (err, hashedPassword) {
callback(err, !!hashedPassword);
});
};
diff --git a/src/user/picture.js b/src/user/picture.js
index fcac5c5c6f..64f9c900c2 100644
--- a/src/user/picture.js
+++ b/src/user/picture.js
@@ -16,7 +16,7 @@ var image = require('../image');
var meta = require('../meta');
var db = require('../database');
-module.exports = function(User) {
+module.exports = function (User) {
User.uploadPicture = function (uid, picture, callback) {
@@ -41,7 +41,7 @@ module.exports = function(User) {
}
async.waterfall([
- function(next) {
+ function (next) {
if (plugins.hasListeners('filter:uploadImage')) {
return plugins.fireHook('filter:uploadImage', {image: picture, uid: updateUid}, next);
}
@@ -49,10 +49,10 @@ module.exports = function(User) {
var filename = updateUid + '-profileimg' + (keepAllVersions ? '-' + Date.now() : '') + (convertToPNG ? '.png' : extension);
async.waterfall([
- function(next) {
+ function (next) {
file.isFileTypeAllowed(picture.path, next);
},
- function(next) {
+ function (next) {
image.resizeImage({
path: picture.path,
extension: extension,
@@ -60,38 +60,38 @@ module.exports = function(User) {
height: imageDimension
}, next);
},
- function(next) {
+ function (next) {
if (!convertToPNG) {
return next();
}
async.series([
async.apply(image.normalise, picture.path, extension),
async.apply(fs.rename, picture.path + '.png', picture.path)
- ], function(err) {
+ ], function (err) {
next(err);
});
},
- function(next) {
+ function (next) {
file.saveFileToLocal(filename, 'profile', picture.path, next);
},
], next);
},
- function(_image, next) {
+ function (_image, next) {
uploadedImage = _image;
User.setUserFields(updateUid, {uploadedpicture: uploadedImage.url, picture: uploadedImage.url}, next);
},
- function(next) {
+ function (next) {
next(null, uploadedImage);
}
], callback);
};
- User.uploadFromUrl = function(uid, url, callback) {
+ User.uploadFromUrl = function (uid, url, callback) {
if (!plugins.hasListeners('filter:uploadImage')) {
return callback(new Error('[[error:no-plugin]]'));
}
- request.head(url, function(err, res) {
+ request.head(url, function (err, res) {
if (err) {
return callback(err);
}
@@ -109,7 +109,7 @@ module.exports = function(User) {
}
var picture = {url: url, name: ''};
- plugins.fireHook('filter:uploadImage', {image: picture, uid: uid}, function(err, image) {
+ plugins.fireHook('filter:uploadImage', {image: picture, uid: uid}, function (err, image) {
if (err) {
return callback(err);
}
@@ -119,11 +119,11 @@ module.exports = function(User) {
});
};
- User.updateCoverPosition = function(uid, position, callback) {
+ User.updateCoverPosition = function (uid, position, callback) {
User.setUserField(uid, 'cover:position', position, callback);
};
- User.updateCoverPicture = function(data, callback) {
+ User.updateCoverPicture = function (data, callback) {
var keepAllVersions = parseInt(meta.config['profile:keepAllUserImages'], 10) === 1;
var url, md5sum;
@@ -136,7 +136,7 @@ module.exports = function(User) {
}
async.waterfall([
- function(next) {
+ function (next) {
var size = data.file ? data.file.size : data.imageData.length;
meta.config.maximumCoverImageSize = meta.config.maximumCoverImageSize || 2048;
if (size > parseInt(meta.config.maximumCoverImageSize, 10) * 1024) {
@@ -161,7 +161,7 @@ module.exports = function(User) {
encoding: 'base64'
}, next);
},
- function(next) {
+ function (next) {
var image = {
name: 'profileCover',
path: data.file.path,
@@ -188,21 +188,21 @@ module.exports = function(User) {
}
], next);
},
- function(uploadData, next) {
+ function (uploadData, next) {
url = uploadData.url;
User.setUserField(data.uid, 'cover:url', uploadData.url, next);
},
- function(next) {
- fs.unlink(data.file.path, function(err) {
+ function (next) {
+ fs.unlink(data.file.path, function (err) {
if (err) {
winston.error(err);
}
next();
});
}
- ], function(err) {
+ ], function (err) {
if (err) {
- return fs.unlink(data.file.path, function(unlinkErr) {
+ return fs.unlink(data.file.path, function (unlinkErr) {
if (unlinkErr) {
winston.error(unlinkErr);
}
@@ -212,7 +212,7 @@ module.exports = function(User) {
}
if (data.position) {
- User.updateCoverPosition(data.uid, data.position, function(err) {
+ User.updateCoverPosition(data.uid, data.position, function (err) {
callback(err, {url: url});
});
} else {
@@ -221,7 +221,7 @@ module.exports = function(User) {
});
};
- User.removeCoverPicture = function(data, callback) {
+ User.removeCoverPicture = function (data, callback) {
db.deleteObjectField('user:' + data.uid, 'cover:url', callback);
};
};
diff --git a/src/user/posts.js b/src/user/posts.js
index c5d8cfba1a..37b5e92b16 100644
--- a/src/user/posts.js
+++ b/src/user/posts.js
@@ -5,24 +5,24 @@ var db = require('../database');
var meta = require('../meta');
var privileges = require('../privileges');
-module.exports = function(User) {
+module.exports = function (User) {
- User.isReadyToPost = function(uid, cid, callback) {
+ User.isReadyToPost = function (uid, cid, callback) {
if (parseInt(uid, 10) === 0) {
return callback();
}
async.parallel({
- userData: function(next) {
+ userData: function (next) {
User.getUserFields(uid, ['banned', 'lastposttime', 'joindate', 'email', 'email:confirmed', 'reputation'], next);
},
- exists: function(next) {
+ exists: function (next) {
db.exists('user:' + uid, next);
},
- isAdminOrMod: function(next) {
+ isAdminOrMod: function (next) {
privileges.categories.isAdminOrMod(cid, uid, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
@@ -62,30 +62,30 @@ module.exports = function(User) {
});
};
- User.onNewPostMade = function(postData, callback) {
+ User.onNewPostMade = function (postData, callback) {
async.series([
- function(next) {
+ function (next) {
User.addPostIdToUser(postData.uid, postData.pid, postData.timestamp, next);
},
- function(next) {
+ function (next) {
User.incrementUserPostCountBy(postData.uid, 1, next);
},
- function(next) {
+ function (next) {
User.setUserField(postData.uid, 'lastposttime', postData.timestamp, next);
},
- function(next) {
+ function (next) {
User.updateLastOnlineTime(postData.uid, next);
}
], callback);
};
- User.addPostIdToUser = function(uid, pid, timestamp, callback) {
+ User.addPostIdToUser = function (uid, pid, timestamp, callback) {
db.sortedSetAdd('uid:' + uid + ':posts', timestamp, pid, callback);
};
- User.incrementUserPostCountBy = function(uid, value, callback) {
- callback = callback || function() {};
- User.incrementUserFieldBy(uid, 'postcount', value, function(err, newpostcount) {
+ User.incrementUserPostCountBy = function (uid, value, callback) {
+ callback = callback || function () {};
+ User.incrementUserFieldBy(uid, 'postcount', value, function (err, newpostcount) {
if (err) {
return callback(err);
}
@@ -96,8 +96,8 @@ module.exports = function(User) {
});
};
- User.getPostIds = function(uid, start, stop, callback) {
- db.getSortedSetRevRange('uid:' + uid + ':posts', start, stop, function(err, pids) {
+ User.getPostIds = function (uid, start, stop, callback) {
+ db.getSortedSetRevRange('uid:' + uid + ':posts', start, stop, function (err, pids) {
callback(err, Array.isArray(pids) ? pids : []);
});
};
diff --git a/src/user/profile.js b/src/user/profile.js
index d3a172ec79..1d693abad3 100644
--- a/src/user/profile.js
+++ b/src/user/profile.js
@@ -10,12 +10,12 @@ var db = require('../database');
var groups = require('../groups');
var plugins = require('../plugins');
-module.exports = function(User) {
+module.exports = function (User) {
- User.updateProfile = function(uid, data, callback) {
+ User.updateProfile = function (uid, data, callback) {
var fields = ['username', 'email', 'fullname', 'website', 'location', 'groupTitle', 'birthday', 'signature', 'aboutme', 'picture', 'uploadedpicture'];
- plugins.fireHook('filter:user.updateProfile', {uid: uid, data: data, fields: fields}, function(err, data) {
+ plugins.fireHook('filter:user.updateProfile', {uid: uid, data: data, fields: fields}, function (err, data) {
if (err) {
return callback(err);
}
@@ -48,7 +48,7 @@ module.exports = function(User) {
return next(new Error('[[error:invalid-email]]'));
}
- User.getUserField(uid, 'email', function(err, email) {
+ User.getUserField(uid, 'email', function (err, email) {
if (err) {
return next(err);
}
@@ -57,7 +57,7 @@ module.exports = function(User) {
return next();
}
- User.email.available(data.email, function(err, available) {
+ User.email.available(data.email, function (err, available) {
if (err) {
return next(err);
}
@@ -72,7 +72,7 @@ module.exports = function(User) {
return next();
}
data.username = data.username.trim();
- User.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
+ User.getUserFields(uid, ['username', 'userslug'], function (err, userData) {
if (err) {
return next(err);
}
@@ -95,7 +95,7 @@ module.exports = function(User) {
return next();
}
- User.existsBySlug(userslug, function(err, exists) {
+ User.existsBySlug(userslug, function (err, exists) {
if (err) {
return next(err);
}
@@ -119,12 +119,12 @@ module.exports = function(User) {
isEmailAvailable,
isUsernameAvailable,
isGroupTitleValid
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
- async.each(fields, updateField, function(err) {
+ async.each(fields, updateField, function (err) {
if (err) {
return callback(err);
}
@@ -156,7 +156,7 @@ module.exports = function(User) {
};
function updateEmail(uid, newEmail, callback) {
- User.getUserFields(uid, ['email', 'picture', 'uploadedpicture'], function(err, userData) {
+ User.getUserFields(uid, ['email', 'picture', 'uploadedpicture'], function (err, userData) {
if (err) {
return callback(err);
}
@@ -169,23 +169,23 @@ module.exports = function(User) {
async.series([
async.apply(db.sortedSetRemove, 'email:uid', userData.email.toLowerCase()),
async.apply(db.sortedSetRemove, 'email:sorted', userData.email.toLowerCase() + ':' + uid)
- ], function(err) {
+ ], function (err) {
if (err) {
return callback(err);
}
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetAdd('email:uid', uid, newEmail.toLowerCase(), next);
},
async.apply(db.sortedSetAdd, 'user:' + uid + ':emails', Date.now(), newEmail + ':' + Date.now()),
- function(next) {
+ function (next) {
db.sortedSetAdd('email:sorted', 0, newEmail.toLowerCase() + ':' + uid, next);
},
- function(next) {
+ function (next) {
User.setUserField(uid, 'email', newEmail, next);
},
- function(next) {
+ function (next) {
if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && newEmail) {
User.email.sendValidationEmail(uid, newEmail);
}
@@ -204,20 +204,20 @@ module.exports = function(User) {
return callback();
}
- User.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
+ User.getUserFields(uid, ['username', 'userslug'], function (err, userData) {
if (err) {
return callback(err);
}
async.parallel([
- function(next) {
+ function (next) {
updateUidMapping('username', uid, newUsername, userData.username, next);
},
- function(next) {
+ function (next) {
var newUserslug = utils.slugify(newUsername);
updateUidMapping('userslug', uid, newUserslug, userData.userslug, next);
},
- function(next) {
+ function (next) {
async.series([
async.apply(db.sortedSetRemove, 'username:sorted', userData.username.toLowerCase() + ':' + uid),
async.apply(db.sortedSetAdd, 'username:sorted', 0, newUsername.toLowerCase() + ':' + uid),
@@ -234,13 +234,13 @@ module.exports = function(User) {
}
async.series([
- function(next) {
+ function (next) {
db.sortedSetRemove(field + ':uid', oldValue, next);
},
- function(next) {
+ function (next) {
User.setUserField(uid, field, value, next);
},
- function(next) {
+ function (next) {
if (value) {
db.sortedSetAdd(field + ':uid', uid, value, next);
} else {
@@ -252,16 +252,16 @@ module.exports = function(User) {
function updateFullname(uid, newFullname, callback) {
async.waterfall([
- function(next) {
+ function (next) {
User.getUserField(uid, 'fullname', next);
},
- function(fullname, next) {
+ function (fullname, next) {
updateUidMapping('fullname', uid, newFullname, fullname, next);
}
], callback);
}
- User.changePassword = function(uid, data, callback) {
+ User.changePassword = function (uid, data, callback) {
if (!uid || !data || !data.uid) {
return callback(new Error('[[error:invalid-uid]]'));
}
@@ -288,7 +288,7 @@ module.exports = function(User) {
async.parallel([
async.apply(User.setUserField, data.uid, 'password', hashedPassword),
async.apply(User.reset.updateExpiry, data.uid)
- ], function(err) {
+ ], function (err) {
next(err);
});
}
diff --git a/src/user/reset.js b/src/user/reset.js
index 222e988de6..39bf1f0e07 100644
--- a/src/user/reset.js
+++ b/src/user/reset.js
@@ -12,32 +12,32 @@ var async = require('async'),
meta = require('../meta'),
emailer = require('../emailer');
-(function(UserReset) {
+(function (UserReset) {
var twoHours = 7200000;
- UserReset.validate = function(code, callback) {
+ UserReset.validate = function (code, callback) {
async.waterfall([
- function(next) {
+ function (next) {
db.getObjectField('reset:uid', code, next);
},
- function(uid, next) {
+ function (uid, next) {
if (!uid) {
return callback(null, false);
}
db.sortedSetScore('reset:issueDate', code, next);
},
- function(issueDate, next) {
+ function (issueDate, next) {
next(null, parseInt(issueDate, 10) > Date.now() - twoHours);
}
], callback);
};
- UserReset.generate = function(uid, callback) {
+ UserReset.generate = function (uid, callback) {
var code = utils.generateUUID();
async.parallel([
async.apply(db.setObjectField, 'reset:uid', code, uid),
async.apply(db.sortedSetAdd, 'reset:issueDate', Date.now(), code)
- ], function(err) {
+ ], function (err) {
callback(err, code);
});
};
@@ -56,13 +56,13 @@ var async = require('async'),
], callback);
}
- UserReset.send = function(email, callback) {
+ UserReset.send = function (email, callback) {
var uid;
async.waterfall([
- function(next) {
+ function (next) {
user.getUidByEmail(email, next);
},
- function(_uid, next) {
+ function (_uid, next) {
if (!_uid) {
return next(new Error('[[error:invalid-email]]'));
}
@@ -70,18 +70,18 @@ var async = require('async'),
uid = _uid;
canGenerate(uid, next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('reset:issueDate:uid', Date.now(), uid, next);
},
- function(next) {
+ function (next) {
UserReset.generate(uid, next);
},
- function(code, next) {
- translator.translate('[[email:password-reset-requested, ' + (meta.config.title || 'NodeBB') + ']]', meta.config.defaultLang, function(subject) {
+ function (code, next) {
+ translator.translate('[[email:password-reset-requested, ' + (meta.config.title || 'NodeBB') + ']]', meta.config.defaultLang, function (subject) {
next(null, subject, code);
});
},
- function(subject, code, next) {
+ function (subject, code, next) {
var reset_link = nconf.get('url') + '/reset/' + code;
emailer.send('reset', uid, {
site_title: (meta.config.title || 'NodeBB'),
@@ -94,22 +94,22 @@ var async = require('async'),
], callback);
};
- UserReset.commit = function(code, password, callback) {
+ UserReset.commit = function (code, password, callback) {
var uid;
async.waterfall([
- function(next) {
+ function (next) {
user.isPasswordValid(password, next);
},
- function(next) {
+ function (next) {
UserReset.validate(code, next);
},
- function(validated, next) {
+ function (validated, next) {
if (!validated) {
return next(new Error('[[error:reset-code-not-valid]]'));
}
db.getObjectField('reset:uid', code, next);
},
- function(_uid, next) {
+ function (_uid, next) {
uid = _uid;
if (!uid) {
return next(new Error('[[error:reset-code-not-valid]]'));
@@ -117,7 +117,7 @@ var async = require('async'),
user.hashPassword(password, next);
},
- function(hash, next) {
+ function (hash, next) {
async.parallel([
async.apply(user.setUserField, uid, 'password', hash),
async.apply(db.deleteObjectField, 'reset:uid', code),
@@ -130,28 +130,28 @@ var async = require('async'),
], callback);
};
- UserReset.updateExpiry = function(uid, callback) {
+ UserReset.updateExpiry = function (uid, callback) {
var oneDay = 1000 * 60 * 60 * 24;
var expireDays = parseInt(meta.config.passwordExpiryDays || 0, 10);
var expiry = Date.now() + (oneDay * expireDays);
- callback = callback || function() {};
+ callback = callback || function () {};
user.setUserField(uid, 'passwordExpiry', expireDays > 0 ? expiry : 0, callback);
};
- UserReset.clean = function(callback) {
+ UserReset.clean = function (callback) {
async.waterfall([
- function(next) {
+ function (next) {
async.parallel({
- tokens: function(next) {
+ tokens: function (next) {
db.getSortedSetRangeByScore('reset:issueDate', 0, -1, '-inf', Date.now() - twoHours, next);
},
- uids: function(next) {
+ uids: function (next) {
db.getSortedSetRangeByScore('reset:issueDate:uid', 0, -1, '-inf', Date.now() - twoHours, next);
}
}, next);
},
- function(results, next) {
+ function (results, next) {
if (!results.tokens.length && !results.uids.length) {
return next();
}
diff --git a/src/user/search.js b/src/user/search.js
index 5186b0d497..65d0e41a6a 100644
--- a/src/user/search.js
+++ b/src/user/search.js
@@ -6,9 +6,9 @@ var meta = require('../meta');
var plugins = require('../plugins');
var db = require('../database');
-module.exports = function(User) {
+module.exports = function (User) {
- User.search = function(data, callback) {
+ User.search = function (data, callback) {
var query = data.query || '';
var searchBy = data.searchBy || 'username';
var page = data.page || 1;
@@ -23,20 +23,20 @@ module.exports = function(User) {
var searchResult = {};
async.waterfall([
- function(next) {
+ function (next) {
if (data.findUids) {
data.findUids(query, searchBy, next);
} else {
findUids(query, searchBy, next);
}
},
- function(uids, next) {
+ function (uids, next) {
filterAndSortUids(uids, data, next);
},
- function(uids, next) {
+ function (uids, next) {
plugins.fireHook('filter:users.search', {uids: uids, uid: uid}, next);
},
- function(data, next) {
+ function (data, next) {
var uids = data.uids;
searchResult.matchCount = uids.length;
@@ -50,7 +50,7 @@ module.exports = function(User) {
User.getUsers(uids, uid, next);
},
- function(userData, next) {
+ function (userData, next) {
searchResult.timing = (process.elapsedTimeSince(startTime) / 1000).toFixed(2);
searchResult.users = userData;
next(null, searchResult);
@@ -69,12 +69,12 @@ module.exports = function(User) {
var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20;
var hardCap = resultsPerPage * 10;
- db.getSortedSetRangeByLex(searchBy + ':sorted', min, max, 0, hardCap, function(err, data) {
+ db.getSortedSetRangeByLex(searchBy + ':sorted', min, max, 0, hardCap, function (err, data) {
if (err) {
return callback(err);
}
- var uids = data.map(function(data) {
+ var uids = data.map(function (data) {
return data.split(':')[1];
});
callback(null, uids);
@@ -95,32 +95,32 @@ module.exports = function(User) {
fields.push('flags');
}
- User.getUsersFields(uids, fields, function(err, userData) {
+ User.getUsersFields(uids, fields, function (err, userData) {
if (err) {
return callback(err);
}
if (data.onlineOnly) {
- userData = userData.filter(function(user) {
+ userData = userData.filter(function (user) {
return user && user.status !== 'offline' && (Date.now() - parseInt(user.lastonline, 10) < 300000);
});
}
if (data.bannedOnly) {
- userData = userData.filter(function(user) {
+ userData = userData.filter(function (user) {
return user && user.banned;
});
}
if (data.flaggedOnly) {
- userData = userData.filter(function(user) {
+ userData = userData.filter(function (user) {
return user && parseInt(user.flags, 10) > 0;
});
}
sortUsers(userData, sortBy);
- uids = userData.map(function(user) {
+ uids = userData.map(function (user) {
return user && user.uid;
});
@@ -130,11 +130,11 @@ module.exports = function(User) {
function sortUsers(userData, sortBy) {
if (sortBy === 'joindate' || sortBy === 'postcount' || sortBy === 'reputation') {
- userData.sort(function(u1, u2) {
+ userData.sort(function (u1, u2) {
return u2[sortBy] - u1[sortBy];
});
} else {
- userData.sort(function(u1, u2) {
+ userData.sort(function (u1, u2) {
if(u1[sortBy] < u2[sortBy]) {
return -1;
} else if(u1[sortBy] > u2[sortBy]) {
@@ -148,13 +148,13 @@ module.exports = function(User) {
function searchByIP(ip, uid, callback) {
var start = process.hrtime();
async.waterfall([
- function(next) {
+ function (next) {
db.getSortedSetRevRange('ip:' + ip + ':uid', 0, -1, next);
},
- function(uids, next) {
+ function (uids, next) {
User.getUsers(uids, uid, next);
},
- function(users, next) {
+ function (users, next) {
var diff = process.hrtime(start);
var timing = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(1);
next(null, {timing: timing, users: users});
diff --git a/src/user/settings.js b/src/user/settings.js
index d677710807..29666cfce5 100644
--- a/src/user/settings.js
+++ b/src/user/settings.js
@@ -6,14 +6,14 @@ var meta = require('../meta');
var db = require('../database');
var plugins = require('../plugins');
-module.exports = function(User) {
+module.exports = function (User) {
- User.getSettings = function(uid, callback) {
+ User.getSettings = function (uid, callback) {
if (!parseInt(uid, 10)) {
return onSettingsLoaded(0, {}, callback);
}
- db.getObject('user:' + uid + ':settings', function(err, settings) {
+ db.getObject('user:' + uid + ':settings', function (err, settings) {
if (err) {
return callback(err);
}
@@ -22,16 +22,16 @@ module.exports = function(User) {
});
};
- User.getMultipleUserSettings = function(uids, callback) {
+ User.getMultipleUserSettings = function (uids, callback) {
if (!Array.isArray(uids) || !uids.length) {
return callback(null, []);
}
- var keys = uids.map(function(uid) {
+ var keys = uids.map(function (uid) {
return 'user:' + uid + ':settings';
});
- db.getObjects(keys, function(err, settings) {
+ db.getObjects(keys, function (err, settings) {
if (err) {
return callback(err);
}
@@ -41,14 +41,14 @@ module.exports = function(User) {
settings[i].uid = uids[i];
}
- async.map(settings, function(setting, next) {
+ async.map(settings, function (setting, next) {
onSettingsLoaded(setting.uid, setting, next);
}, callback);
});
};
function onSettingsLoaded(uid, settings, callback) {
- plugins.fireHook('filter:user.getSettings', {uid: uid, settings: settings}, function(err, data) {
+ plugins.fireHook('filter:user.getSettings', {uid: uid, settings: settings}, function (err, data) {
if (err) {
return callback(err);
}
@@ -91,7 +91,7 @@ module.exports = function(User) {
return defaultValue;
}
- User.saveSettings = function(uid, data, callback) {
+ User.saveSettings = function (uid, data, callback) {
if (!data.postsPerPage || parseInt(data.postsPerPage, 10) <= 1 || parseInt(data.postsPerPage, 10) > meta.config.postsPerPage) {
return callback(new Error('[[error:invalid-pagination-value, 2, ' + meta.config.postsPerPage + ']]'));
}
@@ -132,24 +132,24 @@ module.exports = function(User) {
}
async.waterfall([
- function(next) {
+ function (next) {
db.setObject('user:' + uid + ':settings', settings, next);
},
- function(next) {
+ function (next) {
User.updateDigestSetting(uid, data.dailyDigestFreq, next);
},
- function(next) {
+ function (next) {
User.getSettings(uid, next);
}
], callback);
};
- User.updateDigestSetting = function(uid, dailyDigestFreq, callback) {
+ User.updateDigestSetting = function (uid, dailyDigestFreq, callback) {
async.waterfall([
- function(next) {
+ function (next) {
db.sortedSetsRemove(['digest:day:uids', 'digest:week:uids', 'digest:month:uids'], uid, next);
},
- function(next) {
+ function (next) {
if (['day', 'week', 'month'].indexOf(dailyDigestFreq) !== -1) {
db.sortedSetAdd('digest:' + dailyDigestFreq + ':uids', Date.now(), uid, next);
} else {
@@ -159,7 +159,7 @@ module.exports = function(User) {
], callback);
};
- User.setSetting = function(uid, key, value, callback) {
+ User.setSetting = function (uid, key, value, callback) {
db.setObjectField('user:' + uid + ':settings', key, value, callback);
};
};
diff --git a/src/user/topics.js b/src/user/topics.js
index 2df535a1ce..53dade36e9 100644
--- a/src/user/topics.js
+++ b/src/user/topics.js
@@ -3,13 +3,13 @@
var async = require('async');
var db = require('../database');
-module.exports = function(User) {
+module.exports = function (User) {
- User.getIgnoredTids = function(uid, start, stop, callback) {
+ User.getIgnoredTids = function (uid, start, stop, callback) {
db.getSortedSetRevRange('uid:' + uid + ':ignored_tids', start, stop, callback);
};
- User.addTopicIdToUser = function(uid, tid, timestamp, callback) {
+ User.addTopicIdToUser = function (uid, tid, timestamp, callback) {
async.parallel([
async.apply(db.sortedSetAdd, 'uid:' + uid + ':topics', timestamp, tid),
async.apply(User.incrementUserFieldBy, uid, 'topiccount', 1)
diff --git a/src/webserver.js b/src/webserver.js
index c91a33a31b..3436f575c8 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -42,7 +42,7 @@ if (nconf.get('ssl')) {
module.exports.server = server;
-server.on('error', function(err) {
+server.on('error', function (err) {
winston.error(err);
if (err.code === 'EADDRINUSE') {
winston.error('NodeBB address in use, exiting...');
@@ -53,7 +53,7 @@ server.on('error', function(err) {
});
-module.exports.listen = function() {
+module.exports.listen = function () {
emailer.registerApp(app);
setupExpressApp(app);
@@ -62,13 +62,13 @@ module.exports.listen = function() {
logger.init(app);
- emitter.all(['templates:compiled', 'meta:js.compiled', 'meta:css.compiled'], function() {
+ emitter.all(['templates:compiled', 'meta:js.compiled', 'meta:css.compiled'], function () {
winston.info('NodeBB Ready');
emitter.emit('nodebb:ready');
listen();
});
- initializeNodeBB(function(err) {
+ initializeNodeBB(function (err) {
if (err) {
winston.error(err);
process.exit();
@@ -168,12 +168,12 @@ function initializeNodeBB(callback) {
async.waterfall([
async.apply(meta.themes.setupPaths),
- function(next) {
+ function (next) {
plugins.init(app, middleware, next);
},
async.apply(plugins.fireHook, 'static:assets.prepare', {}),
async.apply(meta.js.bridgeModules, app),
- function(next) {
+ function (next) {
async.series([
async.apply(meta.templates.compile),
async.apply(!skipJS ? meta.js.minify : meta.js.getFromFile, 'nodebb.min.js'),
@@ -184,14 +184,14 @@ function initializeNodeBB(callback) {
async.apply(meta.blacklist.load)
], next);
},
- function(results, next) {
+ function (results, next) {
plugins.fireHook('static:app.preload', {
app: app,
middleware: middleware
}, next);
},
async.apply(plugins.fireHook, 'filter:hotswap.prepare', []),
- function(hotswapIds, next) {
+ function (hotswapIds, next) {
routes(app, middleware, hotswapIds);
next();
}
@@ -232,7 +232,7 @@ function listen() {
var bind_address = ((nconf.get('bind_address') === "0.0.0.0" || !nconf.get('bind_address')) ? '0.0.0.0' : nconf.get('bind_address')) + ':' + port;
var oldUmask;
- args.push(function(err) {
+ args.push(function (err) {
if (err) {
winston.info('[startup] NodeBB was unable to listen on: ' + bind_address);
process.exit();
@@ -247,7 +247,7 @@ function listen() {
// Alter umask if necessary
if (isSocket) {
oldUmask = process.umask('0000');
- module.exports.testSocket(socketPath, function(err) {
+ module.exports.testSocket(socketPath, function (err) {
if (!err) {
server.listen.apply(server, args);
} else {
@@ -261,15 +261,15 @@ function listen() {
}
}
-module.exports.testSocket = function(socketPath, callback) {
+module.exports.testSocket = function (socketPath, callback) {
if (typeof socketPath !== 'string') {
return callback(new Error('invalid socket path : ' + socketPath));
}
var net = require('net');
var file = require('./file');
async.series([
- function(next) {
- file.exists(socketPath, function(exists) {
+ function (next) {
+ file.exists(socketPath, function (exists) {
if (exists) {
next();
} else {
@@ -277,12 +277,12 @@ module.exports.testSocket = function(socketPath, callback) {
}
});
},
- function(next) {
+ function (next) {
var testSocket = new net.Socket();
- testSocket.on('error', function(err) {
+ testSocket.on('error', function (err) {
next(err.code !== 'ECONNREFUSED' ? err : null);
});
- testSocket.connect({ path: socketPath }, function() {
+ testSocket.connect({ path: socketPath }, function () {
// Something's listening here, abort
callback(new Error('port-in-use'));
});
diff --git a/src/widgets/admin.js b/src/widgets/admin.js
index 03f16f3a0a..fc380804c6 100644
--- a/src/widgets/admin.js
+++ b/src/widgets/admin.js
@@ -7,9 +7,9 @@ var plugins = require('../plugins');
var admin = {};
-admin.get = function(callback) {
+admin.get = function (callback) {
async.parallel({
- areas: function(next) {
+ areas: function (next) {
var defaultAreas = [
{ name: 'Global Sidebar', template: 'global', location: 'sidebar' },
{ name: 'Global Header', template: 'global', location: 'header' },
@@ -21,36 +21,36 @@ admin.get = function(callback) {
plugins.fireHook('filter:widgets.getAreas', defaultAreas, next);
},
- widgets: function(next) {
+ widgets: function (next) {
plugins.fireHook('filter:widgets.getWidgets', [], next);
},
- adminTemplate: function(next) {
+ adminTemplate: function (next) {
fs.readFile(path.resolve(__dirname, '../../public/templates/admin/partials/widget-settings.tpl'), 'utf8', next);
}
- }, function(err, widgetData) {
+ }, function (err, widgetData) {
if (err) {
return callback(err);
}
widgetData.areas.push({ name: 'Draft Zone', template: 'global', location: 'drafts' });
- async.each(widgetData.areas, function(area, next) {
- require('./index').getArea(area.template, area.location, function(err, areaData) {
+ async.each(widgetData.areas, function (area, next) {
+ require('./index').getArea(area.template, area.location, function (err, areaData) {
area.data = areaData;
next(err);
});
- }, function(err) {
+ }, function (err) {
if (err) {
return callback(err);
}
- widgetData.widgets.forEach(function(w) {
+ widgetData.widgets.forEach(function (w) {
w.content += widgetData.adminTemplate;
});
var templates = [],
list = {}, index = 0;
- widgetData.areas.forEach(function(area) {
+ widgetData.areas.forEach(function (area) {
if (typeof list[area.template] === 'undefined') {
list[area.template] = index;
templates.push({
diff --git a/src/widgets/index.js b/src/widgets/index.js
index fdac7e19d9..eac58e46e3 100644
--- a/src/widgets/index.js
+++ b/src/widgets/index.js
@@ -10,26 +10,26 @@ var db = require('../database');
var widgets = {};
-widgets.render = function(uid, area, req, res, callback) {
+widgets.render = function (uid, area, req, res, callback) {
if (!area.locations || !area.template) {
return callback(new Error('[[error:invalid-data]]'));
}
- widgets.getAreas(['global', area.template], area.locations, function(err, data) {
+ widgets.getAreas(['global', area.template], area.locations, function (err, data) {
if (err) {
return callback(err);
}
var widgetsByLocation = {};
- async.map(area.locations, function(location, done) {
+ async.map(area.locations, function (location, done) {
widgetsByLocation[location] = data.global[location].concat(data[area.template][location]);
if (!widgetsByLocation[location].length) {
return done(null, {location: location, widgets: []});
}
- async.map(widgetsByLocation[location], function(widget, next) {
+ async.map(widgetsByLocation[location], function (widget, next) {
if (!widget || !widget.data ||
(!!widget.data['hide-registered'] && uid !== 0) ||
(!!widget.data['hide-guests'] && uid === 0) ||
@@ -43,7 +43,7 @@ widgets.render = function(uid, area, req, res, callback) {
data: widget.data,
req: req,
res: res
- }, function(err, html) {
+ }, function (err, html) {
if (err || html === null) {
return next(err);
}
@@ -53,7 +53,7 @@ widgets.render = function(uid, area, req, res, callback) {
}
if (widget.data.container && widget.data.container.match('{body}')) {
- translator.translate(widget.data.title, function(title) {
+ translator.translate(widget.data.title, function (title) {
html = templates.parse(widget.data.container, {
title: title,
body: html
@@ -65,27 +65,27 @@ widgets.render = function(uid, area, req, res, callback) {
next(null, {html: html});
}
});
- }, function(err, result) {
+ }, function (err, result) {
done(err, {location: location, widgets: result.filter(Boolean)});
});
}, callback);
});
};
-widgets.getAreas = function(templates, locations, callback) {
- var keys = templates.map(function(tpl) {
+widgets.getAreas = function (templates, locations, callback) {
+ var keys = templates.map(function (tpl) {
return 'widgets:' + tpl;
});
- db.getObjectsFields(keys, locations, function(err, data) {
+ db.getObjectsFields(keys, locations, function (err, data) {
if (err) {
return callback(err);
}
var returnData = {};
- templates.forEach(function(template, index) {
+ templates.forEach(function (template, index) {
returnData[template] = returnData[template] || {};
- locations.forEach(function(location) {
+ locations.forEach(function (location) {
if (data && data[index] && data[index][location]) {
try {
returnData[template][location] = JSON.parse(data[index][location]);
@@ -103,8 +103,8 @@ widgets.getAreas = function(templates, locations, callback) {
});
};
-widgets.getArea = function(template, location, callback) {
- db.getObjectField('widgets:' + template, location, function(err, result) {
+widgets.getArea = function (template, location, callback) {
+ db.getObjectField('widgets:' + template, location, function (err, result) {
if (err) {
return callback(err);
}
@@ -121,7 +121,7 @@ widgets.getArea = function(template, location, callback) {
});
};
-widgets.setArea = function(area, callback) {
+widgets.setArea = function (area, callback) {
if (!area.location || !area.template) {
return callback(new Error('Missing location and template data'));
}
@@ -129,7 +129,7 @@ widgets.setArea = function(area, callback) {
db.setObjectField('widgets:' + area.template, area.location, JSON.stringify(area.widgets), callback);
};
-widgets.reset = function(callback) {
+widgets.reset = function (callback) {
var defaultAreas = [
{ name: 'Draft Zone', template: 'global', location: 'header' },
{ name: 'Draft Zone', template: 'global', location: 'footer' },
@@ -137,21 +137,21 @@ widgets.reset = function(callback) {
];
async.parallel({
- areas: function(next) {
+ areas: function (next) {
plugins.fireHook('filter:widgets.getAreas', defaultAreas, next);
},
- drafts: function(next) {
+ drafts: function (next) {
widgets.getArea('global', 'drafts', next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return callback(err);
}
var drafts = results.drafts || [];
- async.each(results.areas, function(area, next) {
- widgets.getArea(area.template, area.location, function(err, areaData) {
+ async.each(results.areas, function (area, next) {
+ widgets.getArea(area.template, area.location, function (err, areaData) {
if (err) {
return next(err);
}
@@ -160,7 +160,7 @@ widgets.reset = function(callback) {
area.widgets = [];
widgets.setArea(area, next);
});
- }, function(err) {
+ }, function (err) {
if (err) {
return callback(err);
}
diff --git a/test/categories.js b/test/categories.js
index a083f55308..86c158eb3e 100644
--- a/test/categories.js
+++ b/test/categories.js
@@ -10,12 +10,12 @@ var Categories = require('../src/categories');
var Topics = require('../src/topics');
var User = require('../src/user');
-describe('Categories', function() {
+describe('Categories', function () {
var categoryObj;
var posterUid;
- before(function(done) {
- User.create({username: 'poster'}, function(err, _posterUid) {
+ before(function (done) {
+ User.create({username: 'poster'}, function (err, _posterUid) {
if (err) {
return done(err);
}
@@ -26,8 +26,8 @@ describe('Categories', function() {
});
});
- describe('.create', function() {
- it('should create a new category', function(done) {
+ describe('.create', function () {
+ it('should create a new category', function (done) {
Categories.create({
name: 'Test Category',
@@ -35,7 +35,7 @@ describe('Categories', function() {
icon: 'fa-check',
blockclass: 'category-blue',
order: '5'
- }, function(err, category) {
+ }, function (err, category) {
assert.equal(err, null);
categoryObj = category;
@@ -44,8 +44,8 @@ describe('Categories', function() {
});
});
- describe('.getCategoryById', function() {
- it('should retrieve a newly created category by its ID', function(done) {
+ describe('.getCategoryById', function () {
+ it('should retrieve a newly created category by its ID', function (done) {
Categories.getCategoryById({
cid: categoryObj.cid,
set: 'cid:' + categoryObj.cid + ':tids',
@@ -53,7 +53,7 @@ describe('Categories', function() {
start: 0,
stop: -1,
uid: 0
- }, function(err, categoryData) {
+ }, function (err, categoryData) {
assert.equal(err, null);
assert(categoryData);
@@ -65,8 +65,8 @@ describe('Categories', function() {
});
});
- describe('Categories.getRecentTopicReplies', function() {
- it('should not throw', function(done) {
+ describe('Categories.getRecentTopicReplies', function () {
+ it('should not throw', function (done) {
Categories.getCategoryById({
cid: categoryObj.cid,
set: 'cid:' + categoryObj.cid + ':tids',
@@ -74,9 +74,9 @@ describe('Categories', function() {
start: 0,
stop: -1,
uid: 0
- }, function(err, categoryData) {
+ }, function (err, categoryData) {
assert.ifError(err);
- Categories.getRecentTopicReplies(categoryData, 0, function(err) {
+ Categories.getRecentTopicReplies(categoryData, 0, function (err) {
assert.ifError(err);
done();
});
@@ -84,8 +84,8 @@ describe('Categories', function() {
});
});
- describe('.getCategoryTopics', function() {
- it('should return a list of topics', function(done) {
+ describe('.getCategoryTopics', function () {
+ it('should return a list of topics', function (done) {
Categories.getCategoryTopics({
cid: categoryObj.cid,
set: 'cid:' + categoryObj.cid + ':tids',
@@ -93,11 +93,11 @@ describe('Categories', function() {
start: 0,
stop: 10,
uid: 0
- }, function(err, result) {
+ }, function (err, result) {
assert.equal(err, null);
assert(Array.isArray(result.topics));
- assert(result.topics.every(function(topic) {
+ assert(result.topics.every(function (topic) {
return topic instanceof Object;
}));
@@ -105,7 +105,7 @@ describe('Categories', function() {
});
});
- it('should return a list of topics by a specific user', function(done) {
+ it('should return a list of topics by a specific user', function (done) {
Categories.getCategoryTopics({
cid: categoryObj.cid,
set: 'cid:' + categoryObj.cid + ':uid:' + 1 + ':tids',
@@ -114,10 +114,10 @@ describe('Categories', function() {
stop: 10,
uid: 0,
targetUid: 1
- }, function(err, result) {
+ }, function (err, result) {
assert.equal(err, null);
assert(Array.isArray(result.topics));
- assert(result.topics.every(function(topic) {
+ assert(result.topics.every(function (topic) {
return topic instanceof Object && topic.uid === '1';
}));
@@ -126,18 +126,18 @@ describe('Categories', function() {
});
});
- describe('Categories.moveRecentReplies', function() {
+ describe('Categories.moveRecentReplies', function () {
var moveCid;
var moveTid;
- before(function(done) {
+ before(function (done) {
async.parallel({
- category: function(next) {
+ category: function (next) {
Categories.create({
name: 'Test Category 2',
description: 'Test category created by testing script'
}, next);
},
- topic: function(next) {
+ topic: function (next) {
Topics.post({
uid: posterUid,
cid: categoryObj.cid,
@@ -145,25 +145,25 @@ describe('Categories', function() {
content: 'The content of test topic'
}, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return done(err);
}
moveCid = results.category.cid;
moveTid = results.topic.topicData.tid;
- Topics.reply({uid: posterUid, content: 'test post', tid: moveTid}, function(err) {
+ Topics.reply({uid: posterUid, content: 'test post', tid: moveTid}, function (err) {
done(err);
});
});
});
- it('should move posts from one category to another', function(done) {
- Categories.moveRecentReplies(moveTid, categoryObj.cid, moveCid, function(err) {
+ it('should move posts from one category to another', function (done) {
+ Categories.moveRecentReplies(moveTid, categoryObj.cid, moveCid, function (err) {
assert.ifError(err);
- db.getSortedSetRange('cid:' + categoryObj.cid + ':pids', 0, -1, function(err, pids) {
+ db.getSortedSetRange('cid:' + categoryObj.cid + ':pids', 0, -1, function (err, pids) {
assert.ifError(err);
assert.equal(pids.length, 0);
- db.getSortedSetRange('cid:' + moveCid + ':pids', 0, -1, function(err, pids) {
+ db.getSortedSetRange('cid:' + moveCid + ':pids', 0, -1, function (err, pids) {
assert.ifError(err);
assert.equal(pids.length, 2);
done();
@@ -173,7 +173,7 @@ describe('Categories', function() {
});
});
- after(function(done) {
+ after(function (done) {
db.flushdb(done);
});
});
diff --git a/test/database.js b/test/database.js
index 3f8c119002..2750973a0c 100644
--- a/test/database.js
+++ b/test/database.js
@@ -5,9 +5,9 @@ var assert = require('assert'),
db = require('./mocks/databasemock');
-describe('Test database', function() {
- it('should work', function(){
- assert.doesNotThrow(function(){
+describe('Test database', function () {
+ it('should work', function (){
+ assert.doesNotThrow(function (){
var db = require('./mocks/databasemock');
});
});
diff --git a/test/database/hash.js b/test/database/hash.js
index 8489669e92..b1fd87390d 100644
--- a/test/database/hash.js
+++ b/test/database/hash.js
@@ -5,20 +5,20 @@ var async = require('async'),
assert = require('assert'),
db = require('../mocks/databasemock');
-describe('Hash methods', function() {
+describe('Hash methods', function () {
var testData = {
name: 'baris',
lastname: 'usakli',
age: 99
};
- beforeEach(function(done) {
+ beforeEach(function (done) {
db.setObject('hashTestObject', testData, done);
});
- describe('setObject()', function() {
- it('should create a object', function(done) {
- db.setObject('testObject1', {foo: 'baris', bar: 99}, function(err) {
+ describe('setObject()', function () {
+ it('should create a object', function (done) {
+ db.setObject('testObject1', {foo: 'baris', bar: 99}, function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
@@ -26,17 +26,17 @@ describe('Hash methods', function() {
});
});
- describe('setObjectField()', function() {
- it('should create a new object with field', function(done) {
- db.setObjectField('testObject2', 'name', 'ginger', function(err) {
+ describe('setObjectField()', function () {
+ it('should create a new object with field', function (done) {
+ db.setObjectField('testObject2', 'name', 'ginger', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
});
});
- it('should add a new field to an object', function(done) {
- db.setObjectField('testObject2', 'type', 'cat', function(err) {
+ it('should add a new field to an object', function (done) {
+ db.setObjectField('testObject2', 'type', 'cat', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
@@ -44,9 +44,9 @@ describe('Hash methods', function() {
});
});
- describe('getObject()', function() {
- it('should return falsy if object does not exist', function(done) {
- db.getObject('doesnotexist', function(err, data) {
+ describe('getObject()', function () {
+ it('should return falsy if object does not exist', function (done) {
+ db.getObject('doesnotexist', function (err, data) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(!!data, false);
@@ -54,8 +54,8 @@ describe('Hash methods', function() {
});
});
- it('should retrieve an object', function(done) {
- db.getObject('hashTestObject', function(err, data) {
+ it('should retrieve an object', function (done) {
+ db.getObject('hashTestObject', function (err, data) {
assert.equal(err, null);
assert.equal(data.name, testData.name);
assert.equal(data.age, testData.age);
@@ -65,16 +65,16 @@ describe('Hash methods', function() {
});
});
- describe('getObjects()', function() {
- before(function(done) {
+ describe('getObjects()', function () {
+ before(function (done) {
async.parallel([
async.apply(db.setObject, 'testObject4', {name: 'baris'}),
async.apply(db.setObjectField, 'testObject5', 'name', 'ginger')
], done);
});
- it('should return 3 objects with correct data', function(done) {
- db.getObjects(['testObject4', 'testObject5', 'doesnotexist'], function(err, objects) {
+ it('should return 3 objects with correct data', function (done) {
+ db.getObjects(['testObject4', 'testObject5', 'doesnotexist'], function (err, objects) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(Array.isArray(objects) && objects.length === 3, true);
@@ -86,9 +86,9 @@ describe('Hash methods', function() {
});
});
- describe('getObjectField()', function() {
- it('should return falsy if object does not exist', function(done) {
- db.getObjectField('doesnotexist', 'fieldName', function(err, value) {
+ describe('getObjectField()', function () {
+ it('should return falsy if object does not exist', function (done) {
+ db.getObjectField('doesnotexist', 'fieldName', function (err, value) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(!!value, false);
@@ -96,8 +96,8 @@ describe('Hash methods', function() {
});
});
- it('should return falsy if field does not exist', function(done) {
- db.getObjectField('hashTestObject', 'fieldName', function(err, value) {
+ it('should return falsy if field does not exist', function (done) {
+ db.getObjectField('hashTestObject', 'fieldName', function (err, value) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(!!value, false);
@@ -105,8 +105,8 @@ describe('Hash methods', function() {
});
});
- it('should get an objects field', function(done) {
- db.getObjectField('hashTestObject', 'lastname', function(err, value) {
+ it('should get an objects field', function (done) {
+ db.getObjectField('hashTestObject', 'lastname', function (err, value) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(value, 'usakli');
@@ -115,9 +115,9 @@ describe('Hash methods', function() {
});
});
- describe('getObjectFields()', function() {
- it('should return an object with falsy values', function(done) {
- db.getObjectFields('doesnotexist', ['field1', 'field2'], function(err, object) {
+ describe('getObjectFields()', function () {
+ it('should return an object with falsy values', function (done) {
+ db.getObjectFields('doesnotexist', ['field1', 'field2'], function (err, object) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(typeof object, 'object');
@@ -127,8 +127,8 @@ describe('Hash methods', function() {
});
});
- it('should return an object with correct fields', function(done) {
- db.getObjectFields('hashTestObject', ['lastname', 'age', 'field1'], function(err, object) {
+ it('should return an object with correct fields', function (done) {
+ db.getObjectFields('hashTestObject', ['lastname', 'age', 'field1'], function (err, object) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(typeof object, 'object');
@@ -140,16 +140,16 @@ describe('Hash methods', function() {
});
});
- describe('getObjectsFields()', function() {
- before(function(done) {
+ describe('getObjectsFields()', function () {
+ before(function (done) {
async.parallel([
async.apply(db.setObject, 'testObject8', {name: 'baris', age:99}),
async.apply(db.setObject, 'testObject9', {name: 'ginger', age: 3})
], done);
});
- it('should return an array of objects with correct values', function(done) {
- db.getObjectsFields(['testObject8', 'testObject9', 'doesnotexist'], ['name', 'age'], function(err, objects) {
+ it('should return an array of objects with correct values', function (done) {
+ db.getObjectsFields(['testObject8', 'testObject9', 'doesnotexist'], ['name', 'age'], function (err, objects) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(Array.isArray(objects), true);
@@ -164,9 +164,9 @@ describe('Hash methods', function() {
});
});
- describe('getObjectKeys()', function() {
- it('should return an empty array for a object that does not exist', function(done) {
- db.getObjectKeys('doesnotexist', function(err, keys) {
+ describe('getObjectKeys()', function () {
+ it('should return an empty array for a object that does not exist', function (done) {
+ db.getObjectKeys('doesnotexist', function (err, keys) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(Array.isArray(keys) && keys.length === 0, true);
@@ -174,12 +174,12 @@ describe('Hash methods', function() {
});
});
- it('should return an array of keys for the object\'s fields', function(done) {
- db.getObjectKeys('hashTestObject', function(err, keys) {
+ it('should return an array of keys for the object\'s fields', function (done) {
+ db.getObjectKeys('hashTestObject', function (err, keys) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(Array.isArray(keys) && keys.length === 3, true);
- keys.forEach(function(key) {
+ keys.forEach(function (key) {
assert.notEqual(['name', 'lastname', 'age'].indexOf(key), -1);
});
done();
@@ -187,9 +187,9 @@ describe('Hash methods', function() {
});
});
- describe('getObjectValues()', function() {
- it('should return an empty array for a object that does not exist', function(done) {
- db.getObjectValues('doesnotexist', function(err, values) {
+ describe('getObjectValues()', function () {
+ it('should return an empty array for a object that does not exist', function (done) {
+ db.getObjectValues('doesnotexist', function (err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(Array.isArray(values) && values.length === 0, true);
@@ -197,8 +197,8 @@ describe('Hash methods', function() {
});
});
- it('should return an array of values for the object\'s fields', function(done) {
- db.getObjectValues('hashTestObject', function(err, values) {
+ it('should return an array of values for the object\'s fields', function (done) {
+ db.getObjectValues('hashTestObject', function (err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(Array.isArray(values) && values.length === 3, true);
@@ -208,9 +208,9 @@ describe('Hash methods', function() {
});
});
- describe('isObjectField()', function() {
- it('should return false if object does not exist', function(done) {
- db.isObjectField('doesnotexist', 'field1', function(err, value) {
+ describe('isObjectField()', function () {
+ it('should return false if object does not exist', function (done) {
+ db.isObjectField('doesnotexist', 'field1', function (err, value) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(value, false);
@@ -218,8 +218,8 @@ describe('Hash methods', function() {
});
});
- it('should return false if field does not exist', function(done) {
- db.isObjectField('hashTestObject', 'field1', function(err, value) {
+ it('should return false if field does not exist', function (done) {
+ db.isObjectField('hashTestObject', 'field1', function (err, value) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(value, false);
@@ -227,8 +227,8 @@ describe('Hash methods', function() {
});
});
- it('should return true if field exists', function(done) {
- db.isObjectField('hashTestObject', 'name', function(err, value) {
+ it('should return true if field exists', function (done) {
+ db.isObjectField('hashTestObject', 'name', function (err, value) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(value, true);
@@ -238,9 +238,9 @@ describe('Hash methods', function() {
});
- describe('isObjectFields()', function() {
- it('should return an array of false if object does not exist', function(done) {
- db.isObjectFields('doesnotexist', ['field1', 'field2'], function(err, values) {
+ describe('isObjectFields()', function () {
+ it('should return an array of false if object does not exist', function (done) {
+ db.isObjectFields('doesnotexist', ['field1', 'field2'], function (err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, [false, false]);
@@ -248,8 +248,8 @@ describe('Hash methods', function() {
});
});
- it('should return false if field does not exist', function(done) {
- db.isObjectFields('hashTestObject', ['name', 'age', 'field1'], function(err, values) {
+ it('should return false if field does not exist', function (done) {
+ db.isObjectFields('hashTestObject', ['name', 'age', 'field1'], function (err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, [true, true, false]);
@@ -258,16 +258,16 @@ describe('Hash methods', function() {
});
});
- describe('deleteObjectField()', function() {
- before(function(done) {
+ describe('deleteObjectField()', function () {
+ before(function (done) {
db.setObject('testObject10', {foo: 'bar', delete: 'this', delete1: 'this', delete2: 'this'}, done);
});
- it('should delete an objects field', function(done) {
- db.deleteObjectField('testObject10', 'delete', function(err) {
+ it('should delete an objects field', function (done) {
+ db.deleteObjectField('testObject10', 'delete', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
- db.isObjectField('testObject10', 'delete', function(err, isField) {
+ db.isObjectField('testObject10', 'delete', function (err, isField) {
assert.equal(err, null);
assert.equal(isField, false);
done();
@@ -275,14 +275,14 @@ describe('Hash methods', function() {
});
});
- it('should delete multiple fields of the object', function(done) {
- db.deleteObjectFields('testObject10', ['delete1', 'delete2'], function(err) {
+ it('should delete multiple fields of the object', function (done) {
+ db.deleteObjectFields('testObject10', ['delete1', 'delete2'], function (err) {
assert.ifError(err);
assert.equal(arguments.length, 1);
async.parallel({
delete1: async.apply(db.isObjectField, 'testObject10', 'delete1'),
delete2: async.apply(db.isObjectField, 'testObject10', 'delete2')
- }, function(err, results) {
+ }, function (err, results) {
assert.ifError(err);
assert.equal(results.delete1, false);
assert.equal(results.delete2, false);
@@ -292,13 +292,13 @@ describe('Hash methods', function() {
});
});
- describe('incrObjectField()', function() {
- before(function(done) {
+ describe('incrObjectField()', function () {
+ before(function (done) {
db.setObject('testObject11', {age: 99}, done);
});
- it('should set an objects field to 1 if object does not exist', function(done) {
- db.incrObjectField('testObject12', 'field1', function(err, newValue) {
+ it('should set an objects field to 1 if object does not exist', function (done) {
+ db.incrObjectField('testObject12', 'field1', function (err, newValue) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(newValue, 1);
@@ -306,8 +306,8 @@ describe('Hash methods', function() {
});
});
- it('should increment an object fields by 1 and return it', function(done) {
- db.incrObjectField('testObject11', 'age', function(err, newValue) {
+ it('should increment an object fields by 1 and return it', function (done) {
+ db.incrObjectField('testObject11', 'age', function (err, newValue) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(newValue, 100);
@@ -316,13 +316,13 @@ describe('Hash methods', function() {
});
});
- describe('decrObjectField()', function() {
- before(function(done) {
+ describe('decrObjectField()', function () {
+ before(function (done) {
db.setObject('testObject13', {age: 99}, done);
});
- it('should set an objects field to -1 if object does not exist', function(done) {
- db.decrObjectField('testObject14', 'field1', function(err, newValue) {
+ it('should set an objects field to -1 if object does not exist', function (done) {
+ db.decrObjectField('testObject14', 'field1', function (err, newValue) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(newValue, -1);
@@ -330,8 +330,8 @@ describe('Hash methods', function() {
});
});
- it('should decrement an object fields by 1 and return it', function(done) {
- db.decrObjectField('testObject13', 'age', function(err, newValue) {
+ it('should decrement an object fields by 1 and return it', function (done) {
+ db.decrObjectField('testObject13', 'age', function (err, newValue) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(newValue, 98);
@@ -340,13 +340,13 @@ describe('Hash methods', function() {
});
});
- describe('incrObjectFieldBy()', function() {
- before(function(done) {
+ describe('incrObjectFieldBy()', function () {
+ before(function (done) {
db.setObject('testObject15', {age: 100}, done);
});
- it('should set an objects field to 5 if object does not exist', function(done) {
- db.incrObjectFieldBy('testObject16', 'field1', 5, function(err, newValue) {
+ it('should set an objects field to 5 if object does not exist', function (done) {
+ db.incrObjectFieldBy('testObject16', 'field1', 5, function (err, newValue) {
assert.ifError(err);
assert.equal(arguments.length, 2);
assert.equal(newValue, 5);
@@ -354,8 +354,8 @@ describe('Hash methods', function() {
});
});
- it('should increment an object fields by passed in value and return it', function(done) {
- db.incrObjectFieldBy('testObject15', 'age', 11, function(err, newValue) {
+ it('should increment an object fields by passed in value and return it', function (done) {
+ db.incrObjectFieldBy('testObject15', 'age', 11, function (err, newValue) {
assert.ifError(err);
assert.equal(arguments.length, 2);
assert.equal(newValue, 111);
@@ -363,8 +363,8 @@ describe('Hash methods', function() {
});
});
- it('should increment an object fields by passed in value and return it', function(done) {
- db.incrObjectFieldBy('testObject15', 'age', '11', function(err, newValue) {
+ it('should increment an object fields by passed in value and return it', function (done) {
+ db.incrObjectFieldBy('testObject15', 'age', '11', function (err, newValue) {
assert.ifError(err);
assert.equal(newValue, 122);
done();
@@ -374,7 +374,7 @@ describe('Hash methods', function() {
- after(function(done) {
+ after(function (done) {
db.flushdb(done);
});
});
diff --git a/test/database/keys.js b/test/database/keys.js
index 832c91bcba..0166ced52d 100644
--- a/test/database/keys.js
+++ b/test/database/keys.js
@@ -5,22 +5,22 @@ var async = require('async'),
assert = require('assert'),
db = require('../mocks/databasemock');
-describe('Key methods', function() {
+describe('Key methods', function () {
- beforeEach(function(done) {
+ beforeEach(function (done) {
db.set('testKey', 'testValue', done);
});
- it('should set a key without error', function(done) {
- db.set('testKey', 'testValue', function(err) {
+ it('should set a key without error', function (done) {
+ db.set('testKey', 'testValue', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
});
});
- it('should get a key without error', function(done) {
- db.get('testKey', function(err, value) {
+ it('should get a key without error', function (done) {
+ db.get('testKey', function (err, value) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.strictEqual(value, 'testValue');
@@ -28,8 +28,8 @@ describe('Key methods', function() {
});
});
- it('should return true if key exist', function(done) {
- db.exists('testKey', function(err, exists) {
+ it('should return true if key exist', function (done) {
+ db.exists('testKey', function (err, exists) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.strictEqual(exists, true);
@@ -37,8 +37,8 @@ describe('Key methods', function() {
});
});
- it('should return false if key does not exist', function(done) {
- db.exists('doesnotexist', function(err, exists) {
+ it('should return false if key does not exist', function (done) {
+ db.exists('doesnotexist', function (err, exists) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.strictEqual(exists, false);
@@ -46,12 +46,12 @@ describe('Key methods', function() {
});
});
- it('should delete a key without error', function(done) {
- db.delete('testKey', function(err) {
+ it('should delete a key without error', function (done) {
+ db.delete('testKey', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
- db.get('testKey', function(err, value) {
+ db.get('testKey', function (err, value) {
assert.equal(err, null);
assert.equal(false, !!value);
done();
@@ -59,11 +59,11 @@ describe('Key methods', function() {
});
});
- it('should return false if key was deleted', function(done) {
- db.delete('testKey', function(err) {
+ it('should return false if key was deleted', function (done) {
+ db.delete('testKey', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
- db.exists('testKey', function(err, exists) {
+ db.exists('testKey', function (err, exists) {
assert.equal(err, null);
assert.strictEqual(exists, false);
done();
@@ -71,29 +71,29 @@ describe('Key methods', function() {
});
});
- it('should delete all keys passed in', function(done) {
+ it('should delete all keys passed in', function (done) {
async.parallel([
- function(next) {
+ function (next) {
db.set('key1', 'value1', next);
},
- function(next) {
+ function (next) {
db.set('key2', 'value2', next);
}
- ], function(err) {
+ ], function (err) {
if (err) {
return done(err);
}
- db.deleteAll(['key1', 'key2'], function(err) {
+ db.deleteAll(['key1', 'key2'], function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
async.parallel({
- key1exists: function(next) {
+ key1exists: function (next) {
db.exists('key1', next);
},
- key2exists: function(next) {
+ key2exists: function (next) {
db.exists('key2', next);
}
- }, function(err, results) {
+ }, function (err, results) {
assert.equal(err, null);
assert.equal(results.key1exists, false);
assert.equal(results.key2exists, false);
@@ -103,17 +103,17 @@ describe('Key methods', function() {
});
});
- describe('increment', function() {
- it('should initialize key to 1', function(done) {
- db.increment('keyToIncrement', function(err, value) {
+ describe('increment', function () {
+ it('should initialize key to 1', function (done) {
+ db.increment('keyToIncrement', function (err, value) {
assert.equal(err, null);
assert.strictEqual(parseInt(value, 10), 1);
done();
});
});
- it('should increment key to 2', function(done) {
- db.increment('keyToIncrement', function(err, value) {
+ it('should increment key to 2', function (done) {
+ db.increment('keyToIncrement', function (err, value) {
assert.equal(err, null);
assert.strictEqual(parseInt(value, 10), 2);
done();
@@ -121,17 +121,17 @@ describe('Key methods', function() {
});
});
- describe('rename', function() {
- it('should rename key to new name', function(done) {
- db.set('keyOldName', 'renamedKeyValue', function(err) {
+ describe('rename', function () {
+ it('should rename key to new name', function (done) {
+ db.set('keyOldName', 'renamedKeyValue', function (err) {
if (err) {
return done(err);
}
- db.rename('keyOldName', 'keyNewName', function(err) {
+ db.rename('keyOldName', 'keyNewName', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
- db.get('keyNewName', function(err, value) {
+ db.get('keyNewName', function (err, value) {
assert.equal(err, null);
assert.equal(value, 'renamedKeyValue');
done();
@@ -142,7 +142,7 @@ describe('Key methods', function() {
});
- after(function(done) {
+ after(function (done) {
db.flushdb(done);
});
});
diff --git a/test/database/list.js b/test/database/list.js
index c008a0f784..706fc2ef40 100644
--- a/test/database/list.js
+++ b/test/database/list.js
@@ -5,11 +5,11 @@ var async = require('async'),
assert = require('assert'),
db = require('../mocks/databasemock');
-describe('List methods', function() {
+describe('List methods', function () {
- describe('listAppend()', function() {
- it('should append to a list', function(done) {
- db.listAppend('testList1', 5, function(err) {
+ describe('listAppend()', function () {
+ it('should append to a list', function (done) {
+ db.listAppend('testList1', 5, function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
@@ -17,47 +17,47 @@ describe('List methods', function() {
});
});
- describe('listPrepend()', function() {
- it('should prepend to a list', function(done) {
- db.listPrepend('testList2', 3, function(err) {
+ describe('listPrepend()', function () {
+ it('should prepend to a list', function (done) {
+ db.listPrepend('testList2', 3, function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
});
});
- it('should prepend 2 more elements to a list', function(done) {
+ it('should prepend 2 more elements to a list', function (done) {
async.series([
- function(next) {
+ function (next) {
db.listPrepend('testList2', 2, next);
},
- function(next) {
+ function (next) {
db.listPrepend('testList2', 1, next);
}
- ], function(err) {
+ ], function (err) {
assert.equal(err, null);
done();
});
});
});
- describe('getListRange()', function() {
- before(function(done) {
+ describe('getListRange()', function () {
+ before(function (done) {
async.series([
- function(next) {
+ function (next) {
db.listAppend('testList3', 7, next);
},
- function(next) {
+ function (next) {
db.listPrepend('testList3', 3, next);
},
- function(next) {
+ function (next) {
db.listAppend('testList4', 5, next);
}
], done);
});
- it('should return an empty list', function(done) {
- db.getListRange('doesnotexist', 0, -1, function(err, list) {
+ it('should return an empty list', function (done) {
+ db.getListRange('doesnotexist', 0, -1, function (err, list) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(Array.isArray(list), true);
@@ -66,8 +66,8 @@ describe('List methods', function() {
});
});
- it('should return a list with one element', function(done) {
- db.getListRange('testList4', 0, 0, function(err, list) {
+ it('should return a list with one element', function (done) {
+ db.getListRange('testList4', 0, 0, function (err, list) {
assert.equal(err, null);
assert.equal(Array.isArray(list), true);
assert.equal(list[0], 5);
@@ -75,8 +75,8 @@ describe('List methods', function() {
});
});
- it('should return a list with 2 elements 3, 7', function(done) {
- db.getListRange('testList3', 0, -1, function(err, list) {
+ it('should return a list with 2 elements 3, 7', function (done) {
+ db.getListRange('testList3', 0, -1, function (err, list) {
assert.equal(err, null);
assert.equal(Array.isArray(list), true);
assert.equal(list.length, 2);
@@ -86,20 +86,20 @@ describe('List methods', function() {
});
});
- describe('listRemoveLast()', function() {
- before(function(done) {
+ describe('listRemoveLast()', function () {
+ before(function (done) {
async.series([
- function(next) {
+ function (next) {
db.listAppend('testList4', 12, next);
},
- function(next) {
+ function (next) {
db.listPrepend('testList4', 9, next);
}
], done);
});
- it('should remove the last element of list and return it', function(done) {
- db.listRemoveLast('testList4', function(err, lastElement) {
+ it('should remove the last element of list and return it', function (done) {
+ db.listRemoveLast('testList4', function (err, lastElement) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(lastElement, '12');
@@ -108,8 +108,8 @@ describe('List methods', function() {
});
});
- describe('listRemoveAll()', function() {
- before(function(done) {
+ describe('listRemoveAll()', function () {
+ before(function (done) {
async.series([
async.apply(db.listAppend, 'testList5', 1),
async.apply(db.listAppend, 'testList5', 1),
@@ -119,12 +119,12 @@ describe('List methods', function() {
], done);
});
- it('should remove all the matching elements of list', function(done) {
- db.listRemoveAll('testList5', '1', function(err) {
+ it('should remove all the matching elements of list', function (done) {
+ db.listRemoveAll('testList5', '1', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
- db.getListRange('testList5', 0, -1, function(err, list) {
+ db.getListRange('testList5', 0, -1, function (err, list) {
assert.equal(err, null);
assert.equal(Array.isArray(list), true);
assert.equal(list.length, 2);
@@ -135,20 +135,20 @@ describe('List methods', function() {
});
});
- describe('listTrim()', function() {
- it('should trim list to a certain range', function(done) {
+ describe('listTrim()', function () {
+ it('should trim list to a certain range', function (done) {
var list = ['1', '2', '3', '4', '5'];
- async.eachSeries(list, function(value, next) {
+ async.eachSeries(list, function (value, next) {
db.listAppend('testList6', value, next);
- }, function(err) {
+ }, function (err) {
if (err) {
return done(err);
}
- db.listTrim('testList6', 0, 2, function(err) {
+ db.listTrim('testList6', 0, 2, function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
- db.getListRange('testList6', 0, -1, function(err, list) {
+ db.getListRange('testList6', 0, -1, function (err, list) {
assert.equal(err, null);
assert.equal(list.length, 3);
assert.deepEqual(list, ['1', '2', '3']);
@@ -160,7 +160,7 @@ describe('List methods', function() {
});
- after(function(done) {
+ after(function (done) {
db.flushdb(done);
});
});
diff --git a/test/database/sets.js b/test/database/sets.js
index 2b852a5341..4e899c8265 100644
--- a/test/database/sets.js
+++ b/test/database/sets.js
@@ -5,19 +5,19 @@ var async = require('async'),
assert = require('assert'),
db = require('../mocks/databasemock');
-describe('Set methods', function() {
+describe('Set methods', function () {
- describe('setAdd()', function() {
- it('should add to a set', function(done) {
- db.setAdd('testSet1', 5, function(err) {
+ describe('setAdd()', function () {
+ it('should add to a set', function (done) {
+ db.setAdd('testSet1', 5, function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
});
});
- it('should add an array to a set', function(done) {
- db.setAdd('testSet1', [1, 2, 3, 4], function(err) {
+ it('should add an array to a set', function (done) {
+ db.setAdd('testSet1', [1, 2, 3, 4], function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
@@ -25,13 +25,13 @@ describe('Set methods', function() {
});
});
- describe('getSetMembers()', function() {
- before(function(done) {
+ describe('getSetMembers()', function () {
+ before(function (done) {
db.setAdd('testSet2', [1,2,3,4,5], done);
});
- it('should return an empty set', function(done) {
- db.getSetMembers('doesnotexist', function(err, set) {
+ it('should return an empty set', function (done) {
+ db.getSetMembers('doesnotexist', function (err, set) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(Array.isArray(set), true);
@@ -40,11 +40,11 @@ describe('Set methods', function() {
});
});
- it('should return a set with all elements', function(done) {
- db.getSetMembers('testSet2', function(err, set) {
+ it('should return a set with all elements', function (done) {
+ db.getSetMembers('testSet2', function (err, set) {
assert.equal(err, null);
assert.equal(set.length, 5);
- set.forEach(function(value) {
+ set.forEach(function (value) {
assert.notEqual(['1', '2', '3', '4', '5'].indexOf(value), -1);
});
@@ -53,9 +53,9 @@ describe('Set methods', function() {
});
});
- describe('setsAdd()', function() {
- it('should add to multiple sets', function(done) {
- db.setsAdd(['set1', 'set2'], 'value', function(err) {
+ describe('setsAdd()', function () {
+ it('should add to multiple sets', function (done) {
+ db.setsAdd(['set1', 'set2'], 'value', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
@@ -63,13 +63,13 @@ describe('Set methods', function() {
});
});
- describe('getSetsMembers()', function() {
- before(function(done) {
+ describe('getSetsMembers()', function () {
+ before(function (done) {
db.setsAdd(['set3', 'set4'], 'value', done);
});
- it('should return members of two sets', function(done) {
- db.getSetsMembers(['set3', 'set4'], function(err, sets) {
+ it('should return members of two sets', function (done) {
+ db.getSetsMembers(['set3', 'set4'], function (err, sets) {
assert.equal(err, null);
assert.equal(Array.isArray(sets), true);
assert.equal(arguments.length, 2);
@@ -81,13 +81,13 @@ describe('Set methods', function() {
});
});
- describe('isSetMember()', function() {
- before(function(done) {
+ describe('isSetMember()', function () {
+ before(function (done) {
db.setAdd('testSet3', 5, done);
});
- it('should return false if element is not member of set', function(done) {
- db.isSetMember('testSet3', 10, function(err, isMember) {
+ it('should return false if element is not member of set', function (done) {
+ db.isSetMember('testSet3', 10, function (err, isMember) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(isMember, false);
@@ -95,8 +95,8 @@ describe('Set methods', function() {
});
});
- it('should return true if element is a member of set', function(done) {
- db.isSetMember('testSet3', 5, function(err, isMember) {
+ it('should return true if element is a member of set', function (done) {
+ db.isSetMember('testSet3', 5, function (err, isMember) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(isMember, true);
@@ -105,13 +105,13 @@ describe('Set methods', function() {
});
});
- describe('isSetMembers()', function() {
- before(function(done) {
+ describe('isSetMembers()', function () {
+ before(function (done) {
db.setAdd('testSet4', [1, 2, 3, 4, 5], done);
});
- it('should return an array of booleans', function(done) {
- db.isSetMembers('testSet4', ['1', '2', '10', '3'], function(err, members) {
+ it('should return an array of booleans', function (done) {
+ db.isSetMembers('testSet4', ['1', '2', '10', '3'], function (err, members) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(Array.isArray(members), true);
@@ -121,13 +121,13 @@ describe('Set methods', function() {
});
});
- describe('isMemberOfSets()', function() {
- before(function(done) {
+ describe('isMemberOfSets()', function () {
+ before(function (done) {
db.setsAdd(['set1', 'set2'], 'value', done);
});
- it('should return an array of booleans', function(done) {
- db.isMemberOfSets(['set1', 'testSet1', 'set2', 'doesnotexist'], 'value', function(err, members) {
+ it('should return an array of booleans', function (done) {
+ db.isMemberOfSets(['set1', 'testSet1', 'set2', 'doesnotexist'], 'value', function (err, members) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(Array.isArray(members), true);
@@ -137,13 +137,13 @@ describe('Set methods', function() {
});
});
- describe('setCount()', function() {
- before(function(done) {
+ describe('setCount()', function () {
+ before(function (done) {
db.setAdd('testSet5', [1,2,3,4,5], done);
});
- it('should return the element count of set', function(done) {
- db.setCount('testSet5', function(err, count) {
+ it('should return the element count of set', function (done) {
+ db.setCount('testSet5', function (err, count) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.strictEqual(count, 5);
@@ -152,8 +152,8 @@ describe('Set methods', function() {
});
});
- describe('setsCount()', function() {
- before(function(done) {
+ describe('setsCount()', function () {
+ before(function (done) {
async.parallel([
async.apply(db.setAdd, 'set5', [1,2,3,4,5]),
async.apply(db.setAdd, 'set6', 1),
@@ -161,8 +161,8 @@ describe('Set methods', function() {
], done);
});
- it('should return the element count of sets', function(done) {
- db.setsCount(['set5', 'set6', 'set7', 'doesnotexist'], function(err, counts) {
+ it('should return the element count of sets', function (done) {
+ db.setsCount(['set5', 'set6', 'set7', 'doesnotexist'], function (err, counts) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(Array.isArray(counts), true);
@@ -172,17 +172,17 @@ describe('Set methods', function() {
});
});
- describe('setRemove()', function() {
- before(function(done) {
+ describe('setRemove()', function () {
+ before(function (done) {
db.setAdd('testSet6', [1, 2], done);
});
- it('should remove a element from set', function(done) {
- db.setRemove('testSet6', '2', function(err) {
+ it('should remove a element from set', function (done) {
+ db.setRemove('testSet6', '2', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
- db.isSetMember('testSet6', '2', function(err, isMember) {
+ db.isSetMember('testSet6', '2', function (err, isMember) {
assert.equal(err, null);
assert.equal(isMember, false);
done();
@@ -191,16 +191,16 @@ describe('Set methods', function() {
});
});
- describe('setsRemove()', function() {
- before(function(done) {
+ describe('setsRemove()', function () {
+ before(function (done) {
db.setsAdd(['set1', 'set2'], 'value', done);
});
- it('should remove a element from multiple sets', function(done) {
- db.setsRemove(['set1', 'set2'], 'value', function(err) {
+ it('should remove a element from multiple sets', function (done) {
+ db.setsRemove(['set1', 'set2'], 'value', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
- db.isMemberOfSets(['set1', 'set2'], 'value', function(err, members) {
+ db.isMemberOfSets(['set1', 'set2'], 'value', function (err, members) {
assert.equal(err, null);
assert.deepEqual(members, [false, false]);
done();
@@ -209,17 +209,17 @@ describe('Set methods', function() {
});
});
- describe('setRemoveRandom()', function() {
- before(function(done) {
+ describe('setRemoveRandom()', function () {
+ before(function (done) {
db.setAdd('testSet7', [1,2,3,4,5], done);
});
- it('should remove a random element from set', function(done) {
- db.setRemoveRandom('testSet7', function(err, element) {
+ it('should remove a random element from set', function (done) {
+ db.setRemoveRandom('testSet7', function (err, element) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
- db.isSetMember('testSet', element, function(err, ismember) {
+ db.isSetMember('testSet', element, function (err, ismember) {
assert.equal(err, null);
assert.equal(ismember, false);
done();
@@ -229,7 +229,7 @@ describe('Set methods', function() {
});
- after(function(done) {
+ after(function (done) {
db.flushdb(done);
});
});
diff --git a/test/database/sorted.js b/test/database/sorted.js
index 293eef8e43..29ed4cf95e 100644
--- a/test/database/sorted.js
+++ b/test/database/sorted.js
@@ -5,33 +5,33 @@ var async = require('async'),
assert = require('assert'),
db = require('../mocks/databasemock');
-describe('Sorted Set methods', function() {
+describe('Sorted Set methods', function () {
- before(function(done) {
+ before(function (done) {
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetAdd('sortedSetTest1', [1, 2, 3], ['value1', 'value2', 'value3'], next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('sortedSetTest2', [1, 4], ['value1', 'value4'], next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('sortedSetTest3', [2, 4], ['value2', 'value4'], next);
}
], done);
});
- describe('sortedSetAdd()', function() {
- it('should add an element to a sorted set', function(done) {
- db.sortedSetAdd('sorted1', 1, 'value1', function(err) {
+ describe('sortedSetAdd()', function () {
+ it('should add an element to a sorted set', function (done) {
+ db.sortedSetAdd('sorted1', 1, 'value1', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
});
});
- it('should add two elements to a sorted set', function(done) {
- db.sortedSetAdd('sorted2', [1, 2], ['value1', 'value2'], function(err) {
+ it('should add two elements to a sorted set', function (done) {
+ db.sortedSetAdd('sorted2', [1, 2], ['value1', 'value2'], function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
@@ -39,9 +39,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetsAdd()', function() {
- it('should add an element to two sorted sets', function(done) {
- db.sortedSetsAdd(['sorted1', 'sorted2'], 3, 'value3', function(err) {
+ describe('sortedSetsAdd()', function () {
+ it('should add an element to two sorted sets', function (done) {
+ db.sortedSetsAdd(['sorted1', 'sorted2'], 3, 'value3', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
done();
@@ -49,9 +49,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('getSortedSetRange()', function() {
- it('should return the lowest scored element', function(done) {
- db.getSortedSetRange('sortedSetTest1', 0, 0, function(err, value) {
+ describe('getSortedSetRange()', function () {
+ it('should return the lowest scored element', function (done) {
+ db.getSortedSetRange('sortedSetTest1', 0, 0, function (err, value) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(value, ['value1']);
@@ -59,8 +59,8 @@ describe('Sorted Set methods', function() {
});
});
- it('should return elements sorted by score lowest to highest', function(done) {
- db.getSortedSetRange('sortedSetTest1', 0, -1, function(err, values) {
+ it('should return elements sorted by score lowest to highest', function (done) {
+ db.getSortedSetRange('sortedSetTest1', 0, -1, function (err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, ['value1', 'value2', 'value3']);
@@ -69,9 +69,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('getSortedSetRevRange()', function() {
- it('should return the highest scored element', function(done) {
- db.getSortedSetRevRange('sortedSetTest1', 0, 0, function(err, value) {
+ describe('getSortedSetRevRange()', function () {
+ it('should return the highest scored element', function (done) {
+ db.getSortedSetRevRange('sortedSetTest1', 0, 0, function (err, value) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(value, ['value3']);
@@ -79,8 +79,8 @@ describe('Sorted Set methods', function() {
});
});
- it('should return elements sorted by score highest to lowest', function(done) {
- db.getSortedSetRevRange('sortedSetTest1', 0, -1, function(err, values) {
+ it('should return elements sorted by score highest to lowest', function (done) {
+ db.getSortedSetRevRange('sortedSetTest1', 0, -1, function (err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, ['value3', 'value2', 'value1']);
@@ -89,9 +89,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('getSortedSetRangeWithScores()', function() {
- it('should return array of elements sorted by score lowest to highest with scores', function(done) {
- db.getSortedSetRangeWithScores('sortedSetTest1', 0, -1, function(err, values) {
+ describe('getSortedSetRangeWithScores()', function () {
+ it('should return array of elements sorted by score lowest to highest with scores', function (done) {
+ db.getSortedSetRangeWithScores('sortedSetTest1', 0, -1, function (err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, [{value: 'value1', score: 1}, {value: 'value2', score: 2}, {value: 'value3', score: 3}]);
@@ -100,9 +100,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('getSortedSetRevRangeWithScores()', function() {
- it('should return array of elements sorted by score highest to lowest with scores', function(done) {
- db.getSortedSetRevRangeWithScores('sortedSetTest1', 0, -1, function(err, values) {
+ describe('getSortedSetRevRangeWithScores()', function () {
+ it('should return array of elements sorted by score highest to lowest with scores', function (done) {
+ db.getSortedSetRevRangeWithScores('sortedSetTest1', 0, -1, function (err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, [{value: 'value3', score: 3}, {value: 'value2', score: 2}, {value: 'value1', score: 1}]);
@@ -111,9 +111,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('getSortedSetRangeByScore()', function() {
- it('should get count elements with score between min max sorted by score lowest to highest', function(done) {
- db.getSortedSetRangeByScore('sortedSetTest1', 0, -1, '-inf', 2, function(err, values) {
+ describe('getSortedSetRangeByScore()', function () {
+ it('should get count elements with score between min max sorted by score lowest to highest', function (done) {
+ db.getSortedSetRangeByScore('sortedSetTest1', 0, -1, '-inf', 2, function (err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, ['value1', 'value2']);
@@ -122,9 +122,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('getSortedSetRevRangeByScore()', function() {
- it('should get count elements with score between max min sorted by score highest to lowest', function(done) {
- db.getSortedSetRevRangeByScore('sortedSetTest1', 0, -1, '+inf', 2, function(err, values) {
+ describe('getSortedSetRevRangeByScore()', function () {
+ it('should get count elements with score between max min sorted by score highest to lowest', function (done) {
+ db.getSortedSetRevRangeByScore('sortedSetTest1', 0, -1, '+inf', 2, function (err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, ['value3', 'value2']);
@@ -133,9 +133,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('getSortedSetRangeByScoreWithScores()', function() {
- it('should get count elements with score between min max sorted by score lowest to highest with scores', function(done) {
- db.getSortedSetRangeByScoreWithScores('sortedSetTest1', 0, -1, '-inf', 2, function(err, values) {
+ describe('getSortedSetRangeByScoreWithScores()', function () {
+ it('should get count elements with score between min max sorted by score lowest to highest with scores', function (done) {
+ db.getSortedSetRangeByScoreWithScores('sortedSetTest1', 0, -1, '-inf', 2, function (err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, [{value: 'value1', score: 1}, {value: 'value2', score: 2}]);
@@ -144,9 +144,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('getSortedSetRevRangeByScoreWithScores()', function() {
- it('should get count elements with score between max min sorted by score highest to lowest', function(done) {
- db.getSortedSetRevRangeByScoreWithScores('sortedSetTest1', 0, -1, '+inf', 2, function(err, values) {
+ describe('getSortedSetRevRangeByScoreWithScores()', function () {
+ it('should get count elements with score between max min sorted by score highest to lowest', function (done) {
+ db.getSortedSetRevRangeByScoreWithScores('sortedSetTest1', 0, -1, '+inf', 2, function (err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, [{value: 'value3', score: 3}, {value: 'value2', score: 2}]);
@@ -155,9 +155,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetCount()', function() {
- it('should return 0 for a sorted set that does not exist', function(done) {
- db.sortedSetCount('doesnotexist', 0, 10, function(err, count) {
+ describe('sortedSetCount()', function () {
+ it('should return 0 for a sorted set that does not exist', function (done) {
+ db.sortedSetCount('doesnotexist', 0, 10, function (err, count) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(count, 0);
@@ -165,8 +165,8 @@ describe('Sorted Set methods', function() {
});
});
- it('should return number of elements between scores min max inclusive', function(done) {
- db.sortedSetCount('sortedSetTest1', '-inf', 2, function(err, count) {
+ it('should return number of elements between scores min max inclusive', function (done) {
+ db.sortedSetCount('sortedSetTest1', '-inf', 2, function (err, count) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(count, 2);
@@ -174,8 +174,8 @@ describe('Sorted Set methods', function() {
});
});
- it('should return number of elements between scores -inf +inf inclusive', function(done) {
- db.sortedSetCount('sortedSetTest1', '-inf', '+inf', function(err, count) {
+ it('should return number of elements between scores -inf +inf inclusive', function (done) {
+ db.sortedSetCount('sortedSetTest1', '-inf', '+inf', function (err, count) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(count, 3);
@@ -184,9 +184,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetCard()', function() {
- it('should return 0 for a sorted set that does not exist', function(done) {
- db.sortedSetCard('doesnotexist', function(err, count) {
+ describe('sortedSetCard()', function () {
+ it('should return 0 for a sorted set that does not exist', function (done) {
+ db.sortedSetCard('doesnotexist', function (err, count) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(count, 0);
@@ -194,8 +194,8 @@ describe('Sorted Set methods', function() {
});
});
- it('should return number of elements in a sorted set', function(done) {
- db.sortedSetCard('sortedSetTest1', function(err, count) {
+ it('should return number of elements in a sorted set', function (done) {
+ db.sortedSetCard('sortedSetTest1', function (err, count) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(count, 3);
@@ -204,9 +204,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetsCard()', function() {
- it('should return the number of elements in sorted sets', function(done) {
- db.sortedSetsCard(['sortedSetTest1', 'sortedSetTest2', 'doesnotexist'], function(err, counts) {
+ describe('sortedSetsCard()', function () {
+ it('should return the number of elements in sorted sets', function (done) {
+ db.sortedSetsCard(['sortedSetTest1', 'sortedSetTest2', 'doesnotexist'], function (err, counts) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(counts, [3, 2, 0]);
@@ -215,9 +215,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetRank()', function() {
- it('should return falsy if sorted set does not exist', function(done) {
- db.sortedSetRank('doesnotexist', 'value1', function(err, rank) {
+ describe('sortedSetRank()', function () {
+ it('should return falsy if sorted set does not exist', function (done) {
+ db.sortedSetRank('doesnotexist', 'value1', function (err, rank) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(!!rank, false);
@@ -225,8 +225,8 @@ describe('Sorted Set methods', function() {
});
});
- it('should return falsy if element isnt in sorted set', function(done) {
- db.sortedSetRank('sortedSetTest1', 'value5', function(err, rank) {
+ it('should return falsy if element isnt in sorted set', function (done) {
+ db.sortedSetRank('sortedSetTest1', 'value5', function (err, rank) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(!!rank, false);
@@ -234,8 +234,8 @@ describe('Sorted Set methods', function() {
});
});
- it('should return the rank of the element in the sorted set sorted by lowest to highest score', function(done) {
- db.sortedSetRank('sortedSetTest1', 'value1', function(err, rank) {
+ it('should return the rank of the element in the sorted set sorted by lowest to highest score', function (done) {
+ db.sortedSetRank('sortedSetTest1', 'value1', function (err, rank) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(rank, 0);
@@ -244,9 +244,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetRevRank()', function() {
- it('should return falsy if sorted set doesnot exist', function(done) {
- db.sortedSetRevRank('doesnotexist', 'value1', function(err, rank) {
+ describe('sortedSetRevRank()', function () {
+ it('should return falsy if sorted set doesnot exist', function (done) {
+ db.sortedSetRevRank('doesnotexist', 'value1', function (err, rank) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(!!rank, false);
@@ -254,8 +254,8 @@ describe('Sorted Set methods', function() {
});
});
- it('should return falsy if element isnt in sorted set', function(done) {
- db.sortedSetRevRank('sortedSetTest1', 'value5', function(err, rank) {
+ it('should return falsy if element isnt in sorted set', function (done) {
+ db.sortedSetRevRank('sortedSetTest1', 'value5', function (err, rank) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(!!rank, false);
@@ -263,8 +263,8 @@ describe('Sorted Set methods', function() {
});
});
- it('should return the rank of the element in the sorted set sorted by highest to lowest score', function(done) {
- db.sortedSetRevRank('sortedSetTest1', 'value1', function(err, rank) {
+ it('should return the rank of the element in the sorted set sorted by highest to lowest score', function (done) {
+ db.sortedSetRevRank('sortedSetTest1', 'value1', function (err, rank) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(rank, 2);
@@ -273,9 +273,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetsRanks()', function() {
- it('should return the ranks of values in sorted sets', function(done) {
- db.sortedSetsRanks(['sortedSetTest1', 'sortedSetTest2'], ['value1', 'value4'], function(err, ranks) {
+ describe('sortedSetsRanks()', function () {
+ it('should return the ranks of values in sorted sets', function (done) {
+ db.sortedSetsRanks(['sortedSetTest1', 'sortedSetTest2'], ['value1', 'value4'], function (err, ranks) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(ranks, [0, 1]);
@@ -284,9 +284,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetRanks()', function() {
- it('should return the ranks of values in a sorted set', function(done) {
- db.sortedSetRanks('sortedSetTest1', ['value2', 'value1', 'value3', 'value4'], function(err, ranks) {
+ describe('sortedSetRanks()', function () {
+ it('should return the ranks of values in a sorted set', function (done) {
+ db.sortedSetRanks('sortedSetTest1', ['value2', 'value1', 'value3', 'value4'], function (err, ranks) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(ranks, [1, 0, 2, null]);
@@ -295,9 +295,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetScore()', function() {
- it('should return falsy if sorted set does not exist', function(done) {
- db.sortedSetScore('doesnotexist', 'value1', function(err, score) {
+ describe('sortedSetScore()', function () {
+ it('should return falsy if sorted set does not exist', function (done) {
+ db.sortedSetScore('doesnotexist', 'value1', function (err, score) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(!!score, false);
@@ -305,8 +305,8 @@ describe('Sorted Set methods', function() {
});
});
- it('should return falsy if element is not in sorted set', function(done) {
- db.sortedSetScore('sortedSetTest1', 'value5', function(err, score) {
+ it('should return falsy if element is not in sorted set', function (done) {
+ db.sortedSetScore('sortedSetTest1', 'value5', function (err, score) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(!!score, false);
@@ -314,8 +314,8 @@ describe('Sorted Set methods', function() {
});
});
- it('should return the score of an element', function(done) {
- db.sortedSetScore('sortedSetTest1', 'value2', function(err, score) {
+ it('should return the score of an element', function (done) {
+ db.sortedSetScore('sortedSetTest1', 'value2', function (err, score) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(score, 2);
@@ -324,9 +324,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetsScore()', function() {
- it('should return the scores of value in sorted sets', function(done) {
- db.sortedSetsScore(['sortedSetTest1', 'sortedSetTest2', 'doesnotexist'], 'value1', function(err, scores) {
+ describe('sortedSetsScore()', function () {
+ it('should return the scores of value in sorted sets', function (done) {
+ db.sortedSetsScore(['sortedSetTest1', 'sortedSetTest2', 'doesnotexist'], 'value1', function (err, scores) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(scores, [1, 1, null]);
@@ -335,21 +335,21 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetScores()', function() {
- before(function(done) {
+ describe('sortedSetScores()', function () {
+ before(function (done) {
db.sortedSetAdd('zeroScore', 0, 'value1', done);
});
- it('should return 0 if score is 0', function(done) {
- db.sortedSetScores('zeroScore', ['value1'], function(err, scores) {
+ it('should return 0 if score is 0', function (done) {
+ db.sortedSetScores('zeroScore', ['value1'], function (err, scores) {
assert.ifError(err);
assert.equal(0, scores[0]);
done();
});
});
- it('should return the scores of value in sorted sets', function(done) {
- db.sortedSetScores('sortedSetTest1', ['value2', 'value1', 'doesnotexist'], function(err, scores) {
+ it('should return the scores of value in sorted sets', function (done) {
+ db.sortedSetScores('sortedSetTest1', ['value2', 'value1', 'doesnotexist'], function (err, scores) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(scores, [2, 1, null]);
@@ -358,13 +358,13 @@ describe('Sorted Set methods', function() {
});
});
- describe('isSortedSetMember()', function() {
- before(function(done) {
+ describe('isSortedSetMember()', function () {
+ before(function (done) {
db.sortedSetAdd('zeroscore', 0, 'itemwithzeroscore', done);
});
- it('should return false if sorted set does not exist', function(done) {
- db.isSortedSetMember('doesnotexist', 'value1', function(err, isMember) {
+ it('should return false if sorted set does not exist', function (done) {
+ db.isSortedSetMember('doesnotexist', 'value1', function (err, isMember) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(isMember, false);
@@ -372,8 +372,8 @@ describe('Sorted Set methods', function() {
});
});
- it('should return false if element is not in sorted set', function(done) {
- db.isSortedSetMember('sorted2', 'value5', function(err, isMember) {
+ it('should return false if element is not in sorted set', function (done) {
+ db.isSortedSetMember('sorted2', 'value5', function (err, isMember) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(isMember, false);
@@ -381,8 +381,8 @@ describe('Sorted Set methods', function() {
});
});
- it('should return true if element is in sorted set', function(done) {
- db.isSortedSetMember('sortedSetTest1', 'value2', function(err, isMember) {
+ it('should return true if element is in sorted set', function (done) {
+ db.isSortedSetMember('sortedSetTest1', 'value2', function (err, isMember) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(isMember, true);
@@ -390,8 +390,8 @@ describe('Sorted Set methods', function() {
});
});
- it('should return true if element is in sorted set with score 0', function(done) {
- db.isSortedSetMember('zeroscore', 'itemwithzeroscore', function(err, isMember) {
+ it('should return true if element is in sorted set with score 0', function (done) {
+ db.isSortedSetMember('zeroscore', 'itemwithzeroscore', function (err, isMember) {
assert.ifError(err);
assert.deepEqual(isMember, true);
done();
@@ -399,9 +399,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('isSortedSetMembers()', function() {
- it('should return an array of booleans indicating membership', function(done) {
- db.isSortedSetMembers('sortedSetTest1', ['value1', 'value2', 'value5'], function(err, isMembers) {
+ describe('isSortedSetMembers()', function () {
+ it('should return an array of booleans indicating membership', function (done) {
+ db.isSortedSetMembers('sortedSetTest1', ['value1', 'value2', 'value5'], function (err, isMembers) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(isMembers, [true, true, false]);
@@ -410,9 +410,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('isMemberOfSortedSets', function() {
- it('should return true for members false for non members', function(done) {
- db.isMemberOfSortedSets(['doesnotexist', 'sortedSetTest1', 'sortedSetTest2'], 'value2', function(err, isMembers) {
+ describe('isMemberOfSortedSets', function () {
+ it('should return true for members false for non members', function (done) {
+ db.isMemberOfSortedSets(['doesnotexist', 'sortedSetTest1', 'sortedSetTest2'], 'value2', function (err, isMembers) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(isMembers, [false, true, false]);
@@ -421,13 +421,13 @@ describe('Sorted Set methods', function() {
});
});
- describe('getSortedSetsMembers', function() {
- it('should return members of multiple sorted sets', function(done) {
- db.getSortedSetsMembers(['doesnotexist', 'sortedSetTest1'], function(err, sortedSets) {
+ describe('getSortedSetsMembers', function () {
+ it('should return members of multiple sorted sets', function (done) {
+ db.getSortedSetsMembers(['doesnotexist', 'sortedSetTest1'], function (err, sortedSets) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(sortedSets[0], []);
- sortedSets[0].forEach(function(element) {
+ sortedSets[0].forEach(function (element) {
assert.notEqual(['value1', 'value2', 'value3'].indexOf(element), -1);
});
@@ -436,9 +436,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetUnionCard', function() {
- it('should return the number of elements in the union', function(done) {
- db.sortedSetUnionCard(['sortedSetTest2', 'sortedSetTest3'], function(err, count) {
+ describe('sortedSetUnionCard', function () {
+ it('should return the number of elements in the union', function (done) {
+ db.sortedSetUnionCard(['sortedSetTest2', 'sortedSetTest3'], function (err, count) {
assert.ifError(err);
assert.equal(count, 3);
done();
@@ -446,9 +446,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('getSortedSetUnion()', function() {
- it('should return an array of values from both sorted sets sorted by scores lowest to highest', function(done) {
- db.getSortedSetUnion({sets: ['sortedSetTest2', 'sortedSetTest3'], start: 0, stop: -1}, function(err, values) {
+ describe('getSortedSetUnion()', function () {
+ it('should return an array of values from both sorted sets sorted by scores lowest to highest', function (done) {
+ db.getSortedSetUnion({sets: ['sortedSetTest2', 'sortedSetTest3'], start: 0, stop: -1}, function (err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, ['value1', 'value2', 'value4']);
@@ -457,9 +457,9 @@ describe('Sorted Set methods', function() {
});
});
- describe('getSortedSetRevUnion()', function() {
- it('should return an array of values from both sorted sets sorted by scores highest to lowest', function(done) {
- db.getSortedSetRevUnion({sets: ['sortedSetTest2', 'sortedSetTest3'], start: 0, stop: -1}, function(err, values) {
+ describe('getSortedSetRevUnion()', function () {
+ it('should return an array of values from both sorted sets sorted by scores highest to lowest', function (done) {
+ db.getSortedSetRevUnion({sets: ['sortedSetTest2', 'sortedSetTest3'], start: 0, stop: -1}, function (err, values) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.deepEqual(values, ['value4', 'value2', 'value1']);
@@ -468,13 +468,13 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetIncrBy()', function() {
- it('should create a sorted set with a field set to 1', function(done) {
- db.sortedSetIncrBy('sortedIncr', 1, 'field1', function(err, newValue) {
+ describe('sortedSetIncrBy()', function () {
+ it('should create a sorted set with a field set to 1', function (done) {
+ db.sortedSetIncrBy('sortedIncr', 1, 'field1', function (err, newValue) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(newValue, 1);
- db.sortedSetScore('sortedIncr', 'field1', function(err, score) {
+ db.sortedSetScore('sortedIncr', 'field1', function (err, score) {
assert.equal(err, null);
assert.equal(score, 1);
done();
@@ -482,12 +482,12 @@ describe('Sorted Set methods', function() {
});
});
- it('should increment a field of a sorted set by 5', function(done) {
- db.sortedSetIncrBy('sortedIncr', 5, 'field1', function(err, newValue) {
+ it('should increment a field of a sorted set by 5', function (done) {
+ db.sortedSetIncrBy('sortedIncr', 5, 'field1', function (err, newValue) {
assert.equal(err, null);
assert.equal(arguments.length, 2);
assert.equal(newValue, 6);
- db.sortedSetScore('sortedIncr', 'field1', function(err, score) {
+ db.sortedSetScore('sortedIncr', 'field1', function (err, score) {
assert.equal(err, null);
assert.equal(score, 6);
done();
@@ -497,16 +497,16 @@ describe('Sorted Set methods', function() {
});
- describe('sortedSetRemove()', function() {
- before(function(done) {
+ describe('sortedSetRemove()', function () {
+ before(function (done) {
db.sortedSetAdd('sorted3', [1, 2], ['value1', 'value2'], done);
});
- it('should remove an element from a sorted set', function(done) {
- db.sortedSetRemove('sorted3', 'value2', function(err) {
+ it('should remove an element from a sorted set', function (done) {
+ db.sortedSetRemove('sorted3', 'value2', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
- db.isSortedSetMember('sorted3', 'value2', function(err, isMember) {
+ db.isSortedSetMember('sorted3', 'value2', function (err, isMember) {
assert.equal(err, null);
assert.equal(isMember, false);
done();
@@ -515,19 +515,19 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetsRemove()', function() {
- before(function(done) {
+ describe('sortedSetsRemove()', function () {
+ before(function (done) {
async.parallel([
async.apply(db.sortedSetAdd, 'sorted4', [1,2], ['value1', 'value2']),
async.apply(db.sortedSetAdd, 'sorted5', [1,2], ['value1', 'value3']),
], done);
});
- it('should remove element from multiple sorted sets', function(done) {
- db.sortedSetsRemove(['sorted4', 'sorted5'], 'value1', function(err) {
+ it('should remove element from multiple sorted sets', function (done) {
+ db.sortedSetsRemove(['sorted4', 'sorted5'], 'value1', function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
- db.sortedSetsScore(['sorted4', 'sorted5'], 'value1', function(err, scores) {
+ db.sortedSetsScore(['sorted4', 'sorted5'], 'value1', function (err, scores) {
assert.equal(err, null);
assert.deepEqual(scores, [null, null]);
done();
@@ -536,16 +536,16 @@ describe('Sorted Set methods', function() {
});
});
- describe('sortedSetsRemoveRangeByScore()', function() {
- before(function(done) {
+ describe('sortedSetsRemoveRangeByScore()', function () {
+ before(function (done) {
db.sortedSetAdd('sorted6', [1,2,3,4,5], ['value1','value2','value3','value4','value5'], done);
});
- it('should remove elements with scores between min max inclusive', function(done) {
- db.sortedSetsRemoveRangeByScore(['sorted6'], 4, 5, function(err) {
+ it('should remove elements with scores between min max inclusive', function (done) {
+ db.sortedSetsRemoveRangeByScore(['sorted6'], 4, 5, function (err) {
assert.equal(err, null);
assert.equal(arguments.length, 1);
- db.getSortedSetRange('sorted6', 0, -1, function(err, values) {
+ db.getSortedSetRange('sorted6', 0, -1, function (err, values) {
assert.equal(err, null);
assert.deepEqual(values, ['value1', 'value2', 'value3']);
done();
@@ -554,103 +554,103 @@ describe('Sorted Set methods', function() {
});
});
- describe('getSortedSetIntersect', function() {
- before(function(done) {
+ describe('getSortedSetIntersect', function () {
+ before(function (done) {
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetAdd('interSet1', [1,2,3], ['value1', 'value2', 'value3'], next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('interSet2', [4,5,6], ['value2', 'value3', 'value5'], next);
}
], done);
});
- it('should return the intersection of two sets', function(done) {
+ it('should return the intersection of two sets', function (done) {
db.getSortedSetIntersect({
sets: ['interSet1', 'interSet2'],
start: 0,
stop: -1
- }, function(err, data) {
+ }, function (err, data) {
assert.ifError(err);
assert.deepEqual(['value2', 'value3'], data);
done();
});
});
- it('should return the intersection of two sets with scores', function(done) {
+ it('should return the intersection of two sets with scores', function (done) {
db.getSortedSetIntersect({
sets: ['interSet1', 'interSet2'],
start: 0,
stop: -1,
withScores: true
- }, function(err, data) {
+ }, function (err, data) {
assert.ifError(err);
assert.deepEqual([{value: 'value2', score: 6}, {value: 'value3', score: 8}], data);
done();
});
});
- it('should return the intersection of two sets with scores aggregate MIN', function(done) {
+ it('should return the intersection of two sets with scores aggregate MIN', function (done) {
db.getSortedSetIntersect({
sets: ['interSet1', 'interSet2'],
start: 0,
stop: -1,
withScores: true,
aggregate: 'MIN'
- }, function(err, data) {
+ }, function (err, data) {
assert.ifError(err);
assert.deepEqual([{value: 'value2', score: 2}, {value: 'value3', score: 3}], data);
done();
});
});
- it('should return the intersection of two sets with scores aggregate MAX', function(done) {
+ it('should return the intersection of two sets with scores aggregate MAX', function (done) {
db.getSortedSetIntersect({
sets: ['interSet1', 'interSet2'],
start: 0,
stop: -1,
withScores: true,
aggregate: 'MAX'
- }, function(err, data) {
+ }, function (err, data) {
assert.ifError(err);
assert.deepEqual([{value: 'value2', score: 4}, {value: 'value3', score: 5}], data);
done();
});
});
- it('should return the intersection with scores modified by weights', function(done) {
+ it('should return the intersection with scores modified by weights', function (done) {
db.getSortedSetIntersect({
sets: ['interSet1', 'interSet2'],
start: 0,
stop: -1,
withScores: true,
weights: [1, 0.5]
- }, function(err, data) {
+ }, function (err, data) {
assert.ifError(err);
assert.deepEqual([{value: 'value2', score: 4}, {value: 'value3', score: 5.5}], data);
done();
});
});
- it('should return empty array if sets do not exist', function(done) {
+ it('should return empty array if sets do not exist', function (done) {
db.getSortedSetIntersect({
sets: ['interSet10', 'interSet12'],
start: 0,
stop: -1
- }, function(err, data) {
+ }, function (err, data) {
assert.ifError(err);
assert.equal(data.length, 0);
done();
});
});
- it('should return empty array if one set does not exist', function(done) {
+ it('should return empty array if one set does not exist', function (done) {
db.getSortedSetIntersect({
sets: ['interSet1', 'interSet12'],
start: 0,
stop: -1
- }, function(err, data) {
+ }, function (err, data) {
assert.ifError(err);
assert.equal(data.length, 0);
done();
@@ -659,34 +659,34 @@ describe('Sorted Set methods', function() {
});
- describe('sortedSetIntersectCard', function() {
- before(function(done) {
+ describe('sortedSetIntersectCard', function () {
+ before(function (done) {
async.parallel([
- function(next) {
+ function (next) {
db.sortedSetAdd('interCard1', [0, 0, 0], ['value1', 'value2', 'value3'], next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('interCard2', [0, 0, 0], ['value2', 'value3', 'value4'], next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('interCard3', [0, 0, 0], ['value3', 'value4', 'value5'], next);
},
- function(next) {
+ function (next) {
db.sortedSetAdd('interCard4', [0, 0, 0], ['value4', 'value5', 'value6'], next);
}
], done);
});
- it('should return # of elements in intersection', function(done) {
- db.sortedSetIntersectCard(['interCard1', 'interCard2', 'interCard3'], function(err, count) {
+ it('should return # of elements in intersection', function (done) {
+ db.sortedSetIntersectCard(['interCard1', 'interCard2', 'interCard3'], function (err, count) {
assert.ifError(err);
assert.strictEqual(count, 1);
done();
});
});
- it('should return 0 if intersection is empty', function(done) {
- db.sortedSetIntersectCard(['interCard1', 'interCard4'], function(err, count) {
+ it('should return 0 if intersection is empty', function (done) {
+ db.sortedSetIntersectCard(['interCard1', 'interCard4'], function (err, count) {
assert.ifError(err);
assert.strictEqual(count, 0);
done();
@@ -695,7 +695,7 @@ describe('Sorted Set methods', function() {
});
- after(function(done) {
+ after(function (done) {
db.flushdb(done);
});
});
diff --git a/test/groups.js b/test/groups.js
index 5cfef7a3cc..31195719b6 100644
--- a/test/groups.js
+++ b/test/groups.js
@@ -8,34 +8,34 @@ var db = require('./mocks/databasemock');
var Groups = require('../src/groups');
var User = require('../src/user');
-describe('Groups', function() {
- before(function(done) {
+describe('Groups', function () {
+ before(function (done) {
Groups.resetCache();
async.parallel([
- function(next) {
+ function (next) {
// Create a group to play around with
Groups.create({
name: 'Test',
description: 'Foobar!'
}, next);
},
- function(next) {
+ function (next) {
// Create a new user
User.create({
username: 'testuser',
email: 'b@c.com'
}, next);
},
- function(next) {
+ function (next) {
// Also create a hidden group
Groups.join('Hidden', 'Test', next);
}
], done);
});
- describe('.list()', function() {
- it('should list the groups present', function(done) {
- Groups.getGroupsFromSet('groups:createtime', 0, 0, -1, function(err, groups) {
+ describe('.list()', function () {
+ it('should list the groups present', function (done) {
+ Groups.getGroupsFromSet('groups:createtime', 0, 0, -1, function (err, groups) {
assert.ifError(err);
assert.equal(groups.length, 3);
done();
@@ -43,13 +43,13 @@ describe('Groups', function() {
});
});
- describe('.get()', function() {
- before(function(done) {
+ describe('.get()', function () {
+ before(function (done) {
Groups.join('Test', 1, done);
});
- it('with no options, should show group information', function(done) {
- Groups.get('Test', {}, function(err, groupObj) {
+ it('with no options, should show group information', function (done) {
+ Groups.get('Test', {}, function (err, groupObj) {
if (err) return done(err);
assert.equal(typeof groupObj, 'object');
@@ -64,9 +64,9 @@ describe('Groups', function() {
});
});
- describe('.search()', function() {
- it('should return the "Test" group when searched for', function(done) {
- Groups.search('test', {}, function(err, groups) {
+ describe('.search()', function () {
+ it('should return the "Test" group when searched for', function (done) {
+ Groups.search('test', {}, function (err, groups) {
if (err) return done(err);
assert.equal(1, groups.length);
assert.strictEqual('Test', groups[0].name);
@@ -75,9 +75,9 @@ describe('Groups', function() {
});
});
- describe('.isMember()', function() {
- it('should return boolean true when a user is in a group', function(done) {
- Groups.isMember(1, 'Test', function(err, isMember) {
+ describe('.isMember()', function () {
+ it('should return boolean true when a user is in a group', function (done) {
+ Groups.isMember(1, 'Test', function (err, isMember) {
if (err) return done(err);
assert.strictEqual(isMember, true);
@@ -86,8 +86,8 @@ describe('Groups', function() {
});
});
- it('should return boolean false when a user is not in a group', function(done) {
- Groups.isMember(2, 'Test', function(err, isMember) {
+ it('should return boolean false when a user is not in a group', function (done) {
+ Groups.isMember(2, 'Test', function (err, isMember) {
if (err) return done(err);
assert.strictEqual(isMember, false);
@@ -97,9 +97,9 @@ describe('Groups', function() {
});
});
- describe('.isMemberOfGroupList', function() {
- it('should report that a user is part of a groupList, if they are', function(done) {
- Groups.isMemberOfGroupList(1, 'Hidden', function(err, isMember) {
+ describe('.isMemberOfGroupList', function () {
+ it('should report that a user is part of a groupList, if they are', function (done) {
+ Groups.isMemberOfGroupList(1, 'Hidden', function (err, isMember) {
if (err) return done(err);
assert.strictEqual(isMember, true);
@@ -108,8 +108,8 @@ describe('Groups', function() {
});
});
- it('should report that a user is not part of a groupList, if they are not', function(done) {
- Groups.isMemberOfGroupList(2, 'Hidden', function(err, isMember) {
+ it('should report that a user is not part of a groupList, if they are not', function (done) {
+ Groups.isMemberOfGroupList(2, 'Hidden', function (err, isMember) {
if (err) return done(err);
assert.strictEqual(isMember, false);
@@ -119,9 +119,9 @@ describe('Groups', function() {
});
});
- describe('.exists()', function() {
- it('should verify that the test group exists', function(done) {
- Groups.exists('Test', function(err, exists) {
+ describe('.exists()', function () {
+ it('should verify that the test group exists', function (done) {
+ Groups.exists('Test', function (err, exists) {
if (err) return done(err);
assert.strictEqual(exists, true);
@@ -130,8 +130,8 @@ describe('Groups', function() {
});
});
- it('should verify that a fake group does not exist', function(done) {
- Groups.exists('Derp', function(err, exists) {
+ it('should verify that a fake group does not exist', function (done) {
+ Groups.exists('Derp', function (err, exists) {
if (err) return done(err);
assert.strictEqual(exists, false);
@@ -140,8 +140,8 @@ describe('Groups', function() {
});
});
- it('should check if group exists using an array', function(done) {
- Groups.exists(['Test', 'Derp'], function(err, groupsExists) {
+ it('should check if group exists using an array', function (done) {
+ Groups.exists(['Test', 'Derp'], function (err, groupsExists) {
if (err) return done(err);
assert.strictEqual(groupsExists[0], true);
@@ -151,20 +151,20 @@ describe('Groups', function() {
});
});
- describe('.create()', function() {
- it('should create another group', function(done) {
+ describe('.create()', function () {
+ it('should create another group', function (done) {
Groups.create({
name: 'foo',
description: 'bar'
- }, function(err) {
+ }, function (err) {
if (err) return done(err);
Groups.get('foo', {}, done);
});
});
- it('should fail to create group with duplicate group name', function(done) {
- Groups.create({name: 'foo'}, function(err) {
+ it('should fail to create group with duplicate group name', function (done) {
+ Groups.create({name: 'foo'}, function (err) {
assert(err);
assert.equal(err.message, '[[error:group-already-exists]]');
done();
@@ -172,12 +172,12 @@ describe('Groups', function() {
});
});
- describe('.hide()', function() {
- it('should mark the group as hidden', function(done) {
- Groups.hide('foo', function(err) {
+ describe('.hide()', function () {
+ it('should mark the group as hidden', function (done) {
+ Groups.hide('foo', function (err) {
if (err) return done(err);
- Groups.get('foo', {}, function(err, groupObj) {
+ Groups.get('foo', {}, function (err, groupObj) {
if (err) return done(err);
assert.strictEqual(true, groupObj.hidden);
@@ -188,8 +188,8 @@ describe('Groups', function() {
});
});
- describe('.update()', function() {
- before(function(done) {
+ describe('.update()', function () {
+ before(function (done) {
Groups.create({
name: 'updateTestGroup',
description: 'bar',
@@ -198,13 +198,13 @@ describe('Groups', function() {
}, done);
});
- it('should change an aspect of a group', function(done) {
+ it('should change an aspect of a group', function (done) {
Groups.update('updateTestGroup', {
description: 'baz'
- }, function(err) {
+ }, function (err) {
if (err) return done(err);
- Groups.get('updateTestGroup', {}, function(err, groupObj) {
+ Groups.get('updateTestGroup', {}, function (err, groupObj) {
if (err) return done(err);
assert.strictEqual('baz', groupObj.description);
@@ -214,13 +214,13 @@ describe('Groups', function() {
});
});
- it('should rename a group if the name was updated', function(done) {
+ it('should rename a group if the name was updated', function (done) {
Groups.update('updateTestGroup', {
name: 'updateTestGroup?'
- }, function(err) {
+ }, function (err) {
if (err) return done(err);
- Groups.get('updateTestGroup?', {}, function(err, groupObj) {
+ Groups.get('updateTestGroup?', {}, function (err, groupObj) {
if (err) return done(err);
assert.strictEqual('updateTestGroup?', groupObj.name);
@@ -232,16 +232,16 @@ describe('Groups', function() {
});
});
- describe('.destroy()', function() {
- before(function(done) {
+ describe('.destroy()', function () {
+ before(function (done) {
Groups.join('foobar?', 1, done);
});
- it('should destroy a group', function(done) {
- Groups.destroy('foobar?', function(err) {
+ it('should destroy a group', function (done) {
+ Groups.destroy('foobar?', function (err) {
if (err) return done(err);
- Groups.get('foobar?', {}, function(err) {
+ Groups.get('foobar?', {}, function (err) {
assert(err, 'Group still exists!');
done();
@@ -249,8 +249,8 @@ describe('Groups', function() {
});
});
- it('should also remove the members set', function(done) {
- db.exists('group:foo:members', function(err, exists) {
+ it('should also remove the members set', function (done) {
+ db.exists('group:foo:members', function (err, exists) {
if (err) return done(err);
assert.strictEqual(false, exists);
@@ -260,16 +260,16 @@ describe('Groups', function() {
});
});
- describe('.join()', function() {
- before(function(done) {
+ describe('.join()', function () {
+ before(function (done) {
Groups.leave('Test', 1, done);
});
- it('should add a user to a group', function(done) {
- Groups.join('Test', 1, function(err) {
+ it('should add a user to a group', function (done) {
+ Groups.join('Test', 1, function (err) {
if (err) return done(err);
- Groups.isMember(1, 'Test', function(err, isMember) {
+ Groups.isMember(1, 'Test', function (err, isMember) {
assert.equal(err, null);
assert.strictEqual(true, isMember);
@@ -279,12 +279,12 @@ describe('Groups', function() {
});
});
- describe('.leave()', function() {
- it('should remove a user from a group', function(done) {
- Groups.leave('Test', 1, function(err) {
+ describe('.leave()', function () {
+ it('should remove a user from a group', function (done) {
+ Groups.leave('Test', 1, function (err) {
if (err) return done(err);
- Groups.isMember(1, 'Test', function(err, isMember) {
+ Groups.isMember(1, 'Test', function (err, isMember) {
assert.equal(err, null);
assert.strictEqual(false, isMember);
@@ -294,20 +294,20 @@ describe('Groups', function() {
});
});
- describe('.leaveAllGroups()', function() {
- it('should remove a user from all groups', function(done) {
- Groups.leaveAllGroups(1, function(err) {
+ describe('.leaveAllGroups()', function () {
+ it('should remove a user from all groups', function (done) {
+ Groups.leaveAllGroups(1, function (err) {
if (err) return done(err);
var groups = ['Test', 'Hidden'];
- async.every(groups, function(group, next) {
- Groups.isMember(1, group, function(err, isMember) {
+ async.every(groups, function (group, next) {
+ Groups.isMember(1, group, function (err, isMember) {
if (err) done(err);
else {
next(!isMember);
}
});
- }, function(result) {
+ }, function (result) {
assert(result);
done();
@@ -316,12 +316,12 @@ describe('Groups', function() {
});
});
- describe('.show()', function() {
- it('should make a group visible', function(done) {
- Groups.show('Test', function(err) {
+ describe('.show()', function () {
+ it('should make a group visible', function (done) {
+ Groups.show('Test', function (err) {
assert.ifError(err);
assert.equal(arguments.length, 1);
- db.isSortedSetMember('groups:visible:createtime', 'Test', function(err, isMember) {
+ db.isSortedSetMember('groups:visible:createtime', 'Test', function (err, isMember) {
assert.ifError(err);
assert.strictEqual(isMember, true);
done();
@@ -330,12 +330,12 @@ describe('Groups', function() {
});
});
- describe('.hide()', function() {
- it('should make a group hidden', function(done) {
- Groups.hide('Test', function(err) {
+ describe('.hide()', function () {
+ it('should make a group hidden', function (done) {
+ Groups.hide('Test', function (err) {
assert.ifError(err);
assert.equal(arguments.length, 1);
- db.isSortedSetMember('groups:visible:createtime', 'Test', function(err, isMember) {
+ db.isSortedSetMember('groups:visible:createtime', 'Test', function (err, isMember) {
assert.ifError(err);
assert.strictEqual(isMember, false);
done();
@@ -344,7 +344,7 @@ describe('Groups', function() {
});
});
- after(function(done) {
+ after(function (done) {
db.flushdb(done);
});
});
diff --git a/test/messaging.js b/test/messaging.js
index e7a936bae1..9c85259ede 100644
--- a/test/messaging.js
+++ b/test/messaging.js
@@ -9,14 +9,14 @@ var assert = require('assert'),
Messaging = require('../src/messaging'),
testUids;
-describe('Messaging Library', function() {
- before(function(done) {
+describe('Messaging Library', function () {
+ before(function (done) {
// Create 3 users: 1 admin, 2 regular
async.parallel([
async.apply(User.create, { username: 'foo', password: 'bar' }), // admin
async.apply(User.create, { username: 'baz', password: 'quux' }), // restricted user
async.apply(User.create, { username: 'herp', password: 'derp' }) // regular user
- ], function(err, uids) {
+ ], function (err, uids) {
if (err) {
return done(err);
}
@@ -29,40 +29,40 @@ describe('Messaging Library', function() {
});
});
- describe('.canMessage()', function() {
- it('should not error out', function(done) {
- Messaging.canMessageUser(testUids[1], testUids[2], function(err) {
+ describe('.canMessage()', function () {
+ it('should not error out', function (done) {
+ Messaging.canMessageUser(testUids[1], testUids[2], function (err) {
assert.ifError(err);
done();
});
});
- it('should allow messages to be sent to an unrestricted user', function(done) {
- Messaging.canMessageUser(testUids[1], testUids[2], function(err) {
+ it('should allow messages to be sent to an unrestricted user', function (done) {
+ Messaging.canMessageUser(testUids[1], testUids[2], function (err) {
assert.ifError(err);
done();
});
});
- it('should NOT allow messages to be sent to a restricted user', function(done) {
- User.setSetting(testUids[1], 'restrictChat', '1', function() {
- Messaging.canMessageUser(testUids[2], testUids[1], function(err) {
+ it('should NOT allow messages to be sent to a restricted user', function (done) {
+ User.setSetting(testUids[1], 'restrictChat', '1', function () {
+ Messaging.canMessageUser(testUids[2], testUids[1], function (err) {
assert.strictEqual(err.message, '[[error:chat-restricted]]');
done();
});
});
});
- it('should always allow admins through', function(done) {
- Messaging.canMessageUser(testUids[0], testUids[1], function(err) {
+ it('should always allow admins through', function (done) {
+ Messaging.canMessageUser(testUids[0], testUids[1], function (err) {
assert.ifError(err);
done();
});
});
- it('should allow messages to be sent to a restricted user if restricted user follows sender', function(done) {
- User.follow(testUids[1], testUids[2], function() {
- Messaging.canMessageUser(testUids[2], testUids[1], function(err) {
+ it('should allow messages to be sent to a restricted user if restricted user follows sender', function (done) {
+ User.follow(testUids[1], testUids[2], function () {
+ Messaging.canMessageUser(testUids[2], testUids[1], function (err) {
assert.ifError(err);
done();
});
@@ -70,7 +70,7 @@ describe('Messaging Library', function() {
});
});
- after(function(done) {
+ after(function (done) {
db.flushdb(done);
});
});
diff --git a/test/mocks/databasemock.js b/test/mocks/databasemock.js
index 32c062dd8e..36e696f4d2 100644
--- a/test/mocks/databasemock.js
+++ b/test/mocks/databasemock.js
@@ -3,7 +3,7 @@
* ATTENTION: testing db is flushed before every use!
*/
-(function(module) {
+(function (module) {
'use strict';
/*global require, before*/
@@ -73,14 +73,14 @@
var db = require('../../src/database'),
meta = require('../../src/meta');
- before(function(done) {
- db.init(function(err) {
+ before(function (done) {
+ db.init(function (err) {
if (err) {
return done(err);
}
//Clean up
- db.flushdb(function(err) {
+ db.flushdb(function (err) {
if(err) {
winston.error(err);
throw new Error(err);
diff --git a/test/notifications.js b/test/notifications.js
index 48210b49aa..482af2d9bb 100644
--- a/test/notifications.js
+++ b/test/notifications.js
@@ -8,12 +8,12 @@ var db = require('./mocks/databasemock');
var user = require('../src/user');
var notifications = require('../src/notifications');
-describe('Notifications', function() {
+describe('Notifications', function () {
var uid;
var notification;
- before(function(done) {
- user.create({username: 'poster'}, function(err, _uid) {
+ before(function (done) {
+ user.create({username: 'poster'}, function (err, _uid) {
if (err) {
return done(err);
}
@@ -23,18 +23,18 @@ describe('Notifications', function() {
});
});
- it('should create a notification', function(done) {
+ it('should create a notification', function (done) {
notifications.create({
bodyShort: 'bodyShort',
nid: 'notification_id'
- }, function(err, _notification) {
+ }, function (err, _notification) {
notification = _notification;
assert.ifError(err);
assert(notification);
- db.exists('notifications:' + notification.nid, function(err, exists) {
+ db.exists('notifications:' + notification.nid, function (err, exists) {
assert.ifError(err);
assert(exists);
- db.isSortedSetMember('notifications', notification.nid, function(err, isMember) {
+ db.isSortedSetMember('notifications', notification.nid, function (err, isMember) {
assert.ifError(err);
assert(isMember);
done();
@@ -43,8 +43,8 @@ describe('Notifications', function() {
});
});
- it('should get notifications', function(done) {
- notifications.getMultiple([notification.nid], function(err, notificationsData) {
+ it('should get notifications', function (done) {
+ notifications.getMultiple([notification.nid], function (err, notificationsData) {
assert.ifError(err);
assert(Array.isArray(notificationsData));
assert(notificationsData[0]);
@@ -53,11 +53,11 @@ describe('Notifications', function() {
});
});
- it('should push a notification to uid', function(done) {
- notifications.push(notification, [uid], function(err) {
+ it('should push a notification to uid', function (done) {
+ notifications.push(notification, [uid], function (err) {
assert.ifError(err);
- setTimeout(function() {
- db.isSortedSetMember('uid:' + uid + ':notifications:unread', notification.nid, function(err, isMember) {
+ setTimeout(function () {
+ db.isSortedSetMember('uid:' + uid + ':notifications:unread', notification.nid, function (err, isMember) {
assert.ifError(err);
assert(isMember);
done();
@@ -66,13 +66,13 @@ describe('Notifications', function() {
});
});
- it('should mark a notification read', function(done) {
- notifications.markRead(notification.nid, uid, function(err) {
+ it('should mark a notification read', function (done) {
+ notifications.markRead(notification.nid, uid, function (err) {
assert.ifError(err);
- db.isSortedSetMember('uid:' + uid + ':notifications:unread', notification.nid, function(err, isMember) {
+ db.isSortedSetMember('uid:' + uid + ':notifications:unread', notification.nid, function (err, isMember) {
assert.ifError(err);
assert.equal(isMember, false);
- db.isSortedSetMember('uid:' + uid + ':notifications:read', notification.nid, function(err, isMember) {
+ db.isSortedSetMember('uid:' + uid + ':notifications:read', notification.nid, function (err, isMember) {
assert.ifError(err);
assert.equal(isMember, true);
done();
@@ -81,13 +81,13 @@ describe('Notifications', function() {
});
});
- it('should mark a notification unread', function(done) {
- notifications.markUnread(notification.nid, uid, function(err) {
+ it('should mark a notification unread', function (done) {
+ notifications.markUnread(notification.nid, uid, function (err) {
assert.ifError(err);
- db.isSortedSetMember('uid:' + uid + ':notifications:unread', notification.nid, function(err, isMember) {
+ db.isSortedSetMember('uid:' + uid + ':notifications:unread', notification.nid, function (err, isMember) {
assert.ifError(err);
assert.equal(isMember, true);
- db.isSortedSetMember('uid:' + uid + ':notifications:read', notification.nid, function(err, isMember) {
+ db.isSortedSetMember('uid:' + uid + ':notifications:read', notification.nid, function (err, isMember) {
assert.ifError(err);
assert.equal(isMember, false);
done();
@@ -96,7 +96,7 @@ describe('Notifications', function() {
});
});
- after(function(done) {
+ after(function (done) {
db.flushdb(done);
});
});
diff --git a/test/posts.js b/test/posts.js
index eda66ce409..00c9aa01a3 100644
--- a/test/posts.js
+++ b/test/posts.js
@@ -10,26 +10,26 @@ var posts = require('../src/posts');
var categories = require('../src/categories');
var user = require('../src/user');
-describe('Post\'s', function() {
+describe('Post\'s', function () {
var voterUid;
var voteeUid;
var postData;
- before(function(done) {
+ before(function (done) {
async.parallel({
- voterUid: function(next) {
+ voterUid: function (next) {
user.create({username: 'upvoter'}, next);
},
- voteeUid: function(next) {
+ voteeUid: function (next) {
user.create({username: 'upvotee'}, next);
},
- category: function(next) {
+ category: function (next) {
categories.create({
name: 'Test Category',
description: 'Test category created by testing script'
}, next);
}
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return done(err);
}
@@ -42,7 +42,7 @@ describe('Post\'s', function() {
cid: results.category.cid,
title: 'Test Topic Title',
content: 'The content of test topic'
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return done(err);
}
@@ -52,16 +52,16 @@ describe('Post\'s', function() {
});
});
- describe('voting', function() {
+ describe('voting', function () {
- it('should upvote a post', function(done) {
- posts.upvote(postData.pid, voterUid, function(err, result) {
+ it('should upvote a post', function (done) {
+ posts.upvote(postData.pid, voterUid, function (err, result) {
assert.ifError(err);
assert.equal(result.post.upvotes, 1);
assert.equal(result.post.downvotes, 0);
assert.equal(result.post.votes, 1);
assert.equal(result.user.reputation, 1);
- posts.hasVoted(postData.pid, voterUid, function(err, data) {
+ posts.hasVoted(postData.pid, voterUid, function (err, data) {
assert.ifError(err);
assert.equal(data.upvoted, true);
assert.equal(data.downvoted, false);
@@ -70,14 +70,14 @@ describe('Post\'s', function() {
});
});
- it('should unvote a post', function(done) {
- posts.unvote(postData.pid, voterUid, function(err, result) {
+ it('should unvote a post', function (done) {
+ posts.unvote(postData.pid, voterUid, function (err, result) {
assert.ifError(err);
assert.equal(result.post.upvotes, 0);
assert.equal(result.post.downvotes, 0);
assert.equal(result.post.votes, 0);
assert.equal(result.user.reputation, 0);
- posts.hasVoted(postData.pid, voterUid, function(err, data) {
+ posts.hasVoted(postData.pid, voterUid, function (err, data) {
assert.ifError(err);
assert.equal(data.upvoted, false);
assert.equal(data.downvoted, false);
@@ -86,14 +86,14 @@ describe('Post\'s', function() {
});
});
- it('should downvote a post', function(done) {
- posts.downvote(postData.pid, voterUid, function(err, result) {
+ it('should downvote a post', function (done) {
+ posts.downvote(postData.pid, voterUid, function (err, result) {
assert.ifError(err);
assert.equal(result.post.upvotes, 0);
assert.equal(result.post.downvotes, 1);
assert.equal(result.post.votes, -1);
assert.equal(result.user.reputation, -1);
- posts.hasVoted(postData.pid, voterUid, function(err, data) {
+ posts.hasVoted(postData.pid, voterUid, function (err, data) {
assert.ifError(err);
assert.equal(data.upvoted, false);
assert.equal(data.downvoted, true);
@@ -103,12 +103,12 @@ describe('Post\'s', function() {
});
});
- describe('bookmarking', function() {
- it('should bookmark a post', function(done) {
- posts.bookmark(postData.pid, voterUid, function(err, data) {
+ describe('bookmarking', function () {
+ it('should bookmark a post', function (done) {
+ posts.bookmark(postData.pid, voterUid, function (err, data) {
assert.ifError(err);
assert.equal(data.isBookmarked, true);
- posts.hasBookmarked(postData.pid, voterUid, function(err, hasBookmarked) {
+ posts.hasBookmarked(postData.pid, voterUid, function (err, hasBookmarked) {
assert.ifError(err);
assert.equal(hasBookmarked, true);
done();
@@ -116,11 +116,11 @@ describe('Post\'s', function() {
});
});
- it('should unbookmark a post', function(done) {
- posts.unbookmark(postData.pid, voterUid, function(err, data) {
+ it('should unbookmark a post', function (done) {
+ posts.unbookmark(postData.pid, voterUid, function (err, data) {
assert.ifError(err);
assert.equal(data.isBookmarked, false);
- posts.hasBookmarked([postData.pid], voterUid, function(err, hasBookmarked) {
+ posts.hasBookmarked([postData.pid], voterUid, function (err, hasBookmarked) {
assert.ifError(err);
assert.equal(hasBookmarked[0], false);
done();
@@ -130,7 +130,7 @@ describe('Post\'s', function() {
});
- after(function(done) {
+ after(function (done) {
db.flushdb(done);
});
});
diff --git a/test/topics.js b/test/topics.js
index 575ce6a0b1..d0af967a0f 100644
--- a/test/topics.js
+++ b/test/topics.js
@@ -10,11 +10,11 @@ var User = require('../src/user');
var groups = require('../src/groups');
var async = require('async');
-describe('Topic\'s', function() {
+describe('Topic\'s', function () {
var topic,
categoryObj;
- before(function(done) {
+ before(function (done) {
var userData = {
username: 'John Smith',
password: 'swordfish',
@@ -22,7 +22,7 @@ describe('Topic\'s', function() {
callback: undefined
};
- User.create({username: userData.username, password: userData.password, email: userData.email}, function(err, uid) {
+ User.create({username: userData.username, password: userData.password, email: userData.email}, function (err, uid) {
if (err) {
return done(err);
}
@@ -33,7 +33,7 @@ describe('Topic\'s', function() {
icon: 'fa-check',
blockclass: 'category-blue',
order: '5'
- }, function(err, category) {
+ }, function (err, category) {
if (err) {
return done(err);
}
@@ -53,10 +53,10 @@ describe('Topic\'s', function() {
});
- describe('.post', function() {
+ describe('.post', function () {
- it('should create a new topic with proper parameters', function(done) {
- topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
+ it('should create a new topic with proper parameters', function (done) {
+ topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function (err, result) {
assert.equal(err, null, 'was created with error');
assert.ok(result);
@@ -64,41 +64,41 @@ describe('Topic\'s', function() {
});
});
- it('should fail to create new topic with invalid user id', function(done) {
- topics.post({uid: null, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err) {
+ it('should fail to create new topic with invalid user id', function (done) {
+ topics.post({uid: null, title: topic.title, content: topic.content, cid: topic.categoryId}, function (err) {
assert.equal(err.message, '[[error:no-privileges]]');
done();
});
});
- it('should fail to create new topic with empty title', function(done) {
- topics.post({uid: topic.userId, title: '', content: topic.content, cid: topic.categoryId}, function(err) {
+ it('should fail to create new topic with empty title', function (done) {
+ topics.post({uid: topic.userId, title: '', content: topic.content, cid: topic.categoryId}, function (err) {
assert.ok(err);
done();
});
});
- it('should fail to create new topic with empty content', function(done) {
- topics.post({uid: topic.userId, title: topic.title, content: '', cid: topic.categoryId}, function(err) {
+ it('should fail to create new topic with empty content', function (done) {
+ topics.post({uid: topic.userId, title: topic.title, content: '', cid: topic.categoryId}, function (err) {
assert.ok(err);
done();
});
});
- it('should fail to create new topic with non-existant category id', function(done) {
- topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: 99}, function(err) {
+ it('should fail to create new topic with non-existant category id', function (done) {
+ topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: 99}, function (err) {
assert.equal(err.message, '[[error:no-category]]', 'received no error');
done();
});
});
});
- describe('.reply', function() {
+ describe('.reply', function () {
var newTopic;
var newPost;
- before(function(done) {
- topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
+ before(function (done) {
+ topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function (err, result) {
if (err) {
return done(err);
}
@@ -109,8 +109,8 @@ describe('Topic\'s', function() {
});
});
- it('should create a new reply with proper parameters', function(done) {
- topics.reply({uid: topic.userId, content: 'test post', tid: newTopic.tid}, function(err, result) {
+ it('should create a new reply with proper parameters', function (done) {
+ topics.reply({uid: topic.userId, content: 'test post', tid: newTopic.tid}, function (err, result) {
assert.equal(err, null, 'was created with error');
assert.ok(result);
@@ -118,34 +118,34 @@ describe('Topic\'s', function() {
});
});
- it('should fail to create new reply with invalid user id', function(done) {
- topics.reply({uid: null, content: 'test post', tid: newTopic.tid}, function(err) {
+ it('should fail to create new reply with invalid user id', function (done) {
+ topics.reply({uid: null, content: 'test post', tid: newTopic.tid}, function (err) {
assert.equal(err.message, '[[error:no-privileges]]');
done();
});
});
- it('should fail to create new reply with empty content', function(done) {
- topics.reply({uid: topic.userId, content: '', tid: newTopic.tid}, function(err) {
+ it('should fail to create new reply with empty content', function (done) {
+ topics.reply({uid: topic.userId, content: '', tid: newTopic.tid}, function (err) {
assert.ok(err);
done();
});
});
- it('should fail to create new reply with invalid topic id', function(done) {
- topics.reply({uid: null, content: 'test post', tid: 99}, function(err) {
+ it('should fail to create new reply with invalid topic id', function (done) {
+ topics.reply({uid: null, content: 'test post', tid: 99}, function (err) {
assert.equal(err.message, '[[error:no-topic]]');
done();
});
});
});
- describe('Get methods', function() {
+ describe('Get methods', function () {
var newTopic;
var newPost;
- before(function(done) {
- topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
+ before(function (done) {
+ topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function (err, result) {
if (err) {
return done(err);
}
@@ -156,19 +156,19 @@ describe('Topic\'s', function() {
});
});
- describe('.getTopicData', function() {
- it('should not receive errors', function(done) {
+ describe('.getTopicData', function () {
+ it('should not receive errors', function (done) {
topics.getTopicData(newTopic.tid, done);
});
});
- describe('.getTopicWithPosts', function() {
- it('should get a topic with posts and other data', function(done) {
- topics.getTopicData(newTopic.tid, function(err, topicData) {
+ describe('.getTopicWithPosts', function () {
+ it('should get a topic with posts and other data', function (done) {
+ topics.getTopicData(newTopic.tid, function (err, topicData) {
if (err) {
return done(err);
}
- topics.getTopicWithPosts(topicData, 'tid:' + newTopic.tid + ':posts', topic.userId, 0, -1, false, function(err, data) {
+ topics.getTopicWithPosts(topicData, 'tid:' + newTopic.tid + ':posts', topic.userId, 0, -1, false, function (err, data) {
if (err) {
return done(err);
}
@@ -185,14 +185,14 @@ describe('Topic\'s', function() {
});
});
- describe('Title escaping', function() {
+ describe('Title escaping', function () {
- it('should properly escape topic title', function(done) {
+ it('should properly escape topic title', function (done) {
var title = '" new topic test';
var titleEscaped = validator.escape(title);
- topics.post({uid: topic.userId, title: title, content: topic.content, cid: topic.categoryId}, function(err, result) {
+ topics.post({uid: topic.userId, title: title, content: topic.content, cid: topic.categoryId}, function (err, result) {
assert.ifError(err);
- topics.getTopicData(result.topicData.tid, function(err, topicData) {
+ topics.getTopicData(result.topicData.tid, function (err, topicData) {
assert.ifError(err);
assert.strictEqual(topicData.titleRaw, title);
assert.strictEqual(topicData.title, titleEscaped);
@@ -202,39 +202,39 @@ describe('Topic\'s', function() {
});
});
- describe('.purge/.delete', function() {
+ describe('.purge/.delete', function () {
var newTopic;
var followerUid;
- before(function(done) {
+ before(function (done) {
async.waterfall([
- function(next) {
- topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
+ function (next) {
+ topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function (err, result) {
assert.ifError(err);
newTopic = result.topicData;
next();
});
},
- function(next) {
+ function (next) {
User.create({username: 'topicFollower', password: '123456'}, next);
},
- function(_uid, next) {
+ function (_uid, next) {
followerUid = _uid;
topics.follow(newTopic.tid, _uid, next);
}
], done);
});
- it('should delete the topic', function(done) {
- topics.delete(newTopic.tid, 1, function(err) {
+ it('should delete the topic', function (done) {
+ topics.delete(newTopic.tid, 1, function (err) {
assert.ifError(err);
done();
});
});
- it('should purge the topic', function(done) {
- topics.purge(newTopic.tid, 1, function(err) {
+ it('should purge the topic', function (done) {
+ topics.purge(newTopic.tid, 1, function (err) {
assert.ifError(err);
- db.isSortedSetMember('uid:' + followerUid + ':followed_tids', newTopic.tid, function(err, isMember) {
+ db.isSortedSetMember('uid:' + followerUid + ':followed_tids', newTopic.tid, function (err, isMember) {
assert.ifError(err);
assert.strictEqual(false, isMember);
done();
@@ -243,15 +243,15 @@ describe('Topic\'s', function() {
});
});
- describe('.ignore', function(){
+ describe('.ignore', function (){
var newTid;
var uid;
var newTopic;
- before(function(done){
+ before(function (done){
uid = topic.userId;
async.waterfall([
- function(done){
- topics.post({uid: topic.userId, title: 'Topic to be ignored', content: 'Just ignore me, please!', cid: topic.categoryId}, function(err, result) {
+ function (done){
+ topics.post({uid: topic.userId, title: 'Topic to be ignored', content: 'Just ignore me, please!', cid: topic.categoryId}, function (err, result) {
if (err) {
return done(err);
}
@@ -261,38 +261,38 @@ describe('Topic\'s', function() {
done();
});
},
- function(done){
+ function (done){
topics.markUnread( newTid, uid, done );
}
],done);
});
- it('should not appear in the unread list', function(done){
+ it('should not appear in the unread list', function (done){
async.waterfall([
- function(done){
+ function (done){
topics.ignore( newTid, uid, done );
},
- function(done){
+ function (done){
topics.getUnreadTopics(0, uid, 0, -1, '', done );
},
- function(results, done){
+ function (results, done){
var topics = results.topics;
- var tids = topics.map( function(topic){ return topic.tid; } );
+ var tids = topics.map( function (topic){ return topic.tid; } );
assert.equal(tids.indexOf(newTid), -1, 'The topic appeared in the unread list.');
done();
}
], done);
});
- it('should not appear as unread in the recent list', function(done){
+ it('should not appear as unread in the recent list', function (done){
async.waterfall([
- function(done){
+ function (done){
topics.ignore( newTid, uid, done );
},
- function(done){
+ function (done){
topics.getLatestTopics( uid, 0, -1, 'year', done );
},
- function(results, done){
+ function (results, done){
var topics = results.topics;
var topic;
var i;
@@ -308,40 +308,40 @@ describe('Topic\'s', function() {
], done);
});
- it('should appear as unread again when marked as reading', function(done){
+ it('should appear as unread again when marked as reading', function (done){
async.waterfall([
- function(done){
+ function (done){
topics.ignore( newTid, uid, done );
},
- function(done){
+ function (done){
topics.follow( newTid, uid, done );
},
- function(done){
+ function (done){
topics.getUnreadTopics(0, uid, 0, -1, '', done );
},
- function(results, done){
+ function (results, done){
var topics = results.topics;
- var tids = topics.map( function(topic){ return topic.tid; } );
+ var tids = topics.map( function (topic){ return topic.tid; } );
assert.notEqual(tids.indexOf(newTid), -1, 'The topic did not appear in the unread list.');
done();
}
], done);
});
- it('should appear as unread again when marked as following', function(done){
+ it('should appear as unread again when marked as following', function (done){
async.waterfall([
- function(done){
+ function (done){
topics.ignore( newTid, uid, done );
},
- function(done){
+ function (done){
topics.follow( newTid, uid, done );
},
- function(done){
+ function (done){
topics.getUnreadTopics(0, uid, 0, -1, '', done );
},
- function(results, done){
+ function (results, done){
var topics = results.topics;
- var tids = topics.map( function(topic){ return topic.tid; } );
+ var tids = topics.map( function (topic){ return topic.tid; } );
assert.notEqual(tids.indexOf(newTid), -1, 'The topic did not appear in the unread list.');
done();
}
@@ -351,14 +351,14 @@ describe('Topic\'s', function() {
- describe('.fork', function(){
+ describe('.fork', function (){
var newTopic;
var replies = [];
var topicPids;
var originalBookmark = 5;
function postReply( next ){
topics.reply({uid: topic.userId, content: 'test post ' + replies.length, tid: newTopic.tid},
- function(err, result) {
+ function (err, result) {
assert.equal(err, null, 'was created with error');
assert.ok(result);
replies.push( result );
@@ -367,46 +367,46 @@ describe('Topic\'s', function() {
);
}
- before( function(done) {
+ before( function (done) {
async.waterfall(
[
- function(next){
+ function (next){
groups.join('administrators', topic.userId, next);
},
- function( next ){
- topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
+ function ( next ){
+ topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function (err, result) {
assert.ifError( err );
newTopic = result.topicData;
next();
});
},
- function( next ){ postReply( next );},
- function( next ){ postReply( next );},
- function( next ){ postReply( next );},
- function( next ){ postReply( next );},
- function( next ){ postReply( next );},
- function( next ){ postReply( next );},
- function( next ){ postReply( next );},
- function( next ){ postReply( next );},
- function( next ){ postReply( next );},
- function( next ){ postReply( next );},
- function( next ){ postReply( next );},
- function( next ){ postReply( next );},
- function( next ){
- topicPids = replies.map( function( reply ){ return reply.pid; } );
+ function ( next ){ postReply( next );},
+ function ( next ){ postReply( next );},
+ function ( next ){ postReply( next );},
+ function ( next ){ postReply( next );},
+ function ( next ){ postReply( next );},
+ function ( next ){ postReply( next );},
+ function ( next ){ postReply( next );},
+ function ( next ){ postReply( next );},
+ function ( next ){ postReply( next );},
+ function ( next ){ postReply( next );},
+ function ( next ){ postReply( next );},
+ function ( next ){ postReply( next );},
+ function ( next ){
+ topicPids = replies.map( function ( reply ){ return reply.pid; } );
topics.setUserBookmark( newTopic.tid, topic.userId, originalBookmark, next );
}],
done );
});
- it('should have 12 replies', function(done) {
+ it('should have 12 replies', function (done) {
assert.equal( 12, replies.length );
done();
});
- it('should not update the user\'s bookmark', function(done){
+ it('should not update the user\'s bookmark', function (done){
async.waterfall([
- function(next){
+ function (next){
topics.createTopicFromPosts(
topic.userId,
'Fork test, no bookmark update',
@@ -414,19 +414,19 @@ describe('Topic\'s', function() {
newTopic.tid,
next );
},
- function( forkedTopicData, next){
+ function ( forkedTopicData, next){
topics.getUserBookmark( newTopic.tid, topic.userId, next );
},
- function( bookmark, next ){
+ function ( bookmark, next ){
assert.equal( originalBookmark, bookmark );
next();
}
],done);
});
- it('should update the user\'s bookmark ', function(done){
+ it('should update the user\'s bookmark ', function (done){
async.waterfall([
- function(next){
+ function (next){
topics.createTopicFromPosts(
topic.userId,
'Fork test, no bookmark update',
@@ -434,10 +434,10 @@ describe('Topic\'s', function() {
newTopic.tid,
next );
},
- function( forkedTopicData, next){
+ function ( forkedTopicData, next){
topics.getUserBookmark( newTopic.tid, topic.userId, next );
},
- function( bookmark, next ){
+ function ( bookmark, next ){
assert.equal( originalBookmark - 2, bookmark );
next();
}
@@ -445,7 +445,7 @@ describe('Topic\'s', function() {
});
});
- after(function(done) {
+ after(function (done) {
db.flushdb(done);
});
});
diff --git a/test/translator.js b/test/translator.js
index 4dc4156e27..0e18a5f29b 100644
--- a/test/translator.js
+++ b/test/translator.js
@@ -7,10 +7,10 @@ var Translator = shim.Translator;
require('../src/languages').init(function () {});
-describe('translator shim', function(){
- describe('.translate()', function(){
- it('should translate correctly', function(done) {
- shim.translate('[[global:pagination.out_of, (foobar), [[global:home]]]]', function(translated) {
+describe('translator shim', function (){
+ describe('.translate()', function (){
+ it('should translate correctly', function (done) {
+ shim.translate('[[global:pagination.out_of, (foobar), [[global:home]]]]', function (translated) {
assert.strictEqual(translated, '(foobar) out of Home');
done();
});
@@ -18,138 +18,138 @@ describe('translator shim', function(){
});
});
-describe('new Translator(language)', function(){
- describe('.translate()', function(){
- it('should handle basic translations', function(done) {
+describe('new Translator(language)', function (){
+ describe('.translate()', function (){
+ it('should handle basic translations', function (done) {
var translator = new Translator('en_GB');
- translator.translate('[[global:home]]').then(function(translated) {
+ translator.translate('[[global:home]]').then(function (translated) {
assert.strictEqual(translated, 'Home');
done();
});
});
- it('should handle language keys in regular text', function(done) {
+ it('should handle language keys in regular text', function (done) {
var translator = new Translator('en_GB');
- translator.translate('Let\'s go [[global:home]]').then(function(translated) {
+ translator.translate('Let\'s go [[global:home]]').then(function (translated) {
assert.strictEqual(translated, 'Let\'s go Home');
done();
});
});
- it('should accept a language parameter and adjust accordingly', function(done) {
+ it('should accept a language parameter and adjust accordingly', function (done) {
var translator = new Translator('de');
- translator.translate('[[global:home]]').then(function(translated) {
+ translator.translate('[[global:home]]').then(function (translated) {
assert.strictEqual(translated, 'Übersicht');
done();
});
});
- it('should handle language keys in regular text with another language specified', function(done) {
+ it('should handle language keys in regular text with another language specified', function (done) {
var translator = new Translator('de');
- translator.translate('[[global:home]] test').then(function(translated) {
+ translator.translate('[[global:home]] test').then(function (translated) {
assert.strictEqual(translated, 'Übersicht test');
done();
});
});
- it('should handle language keys with parameters', function(done) {
+ it('should handle language keys with parameters', function (done) {
var translator = new Translator('en_GB');
- translator.translate('[[global:pagination.out_of, 1, 5]]').then(function(translated) {
+ translator.translate('[[global:pagination.out_of, 1, 5]]').then(function (translated) {
assert.strictEqual(translated, '1 out of 5');
done();
});
});
- it('should handle language keys inside language keys', function(done) {
+ it('should handle language keys inside language keys', function (done) {
var translator = new Translator('en_GB');
- translator.translate('[[notifications:outgoing_link_message, [[global:guest]]]]').then(function(translated) {
+ translator.translate('[[notifications:outgoing_link_message, [[global:guest]]]]').then(function (translated) {
assert.strictEqual(translated, 'You are now leaving Guest');
done();
});
});
- it('should handle language keys inside language keys with multiple parameters', function(done) {
+ it('should handle language keys inside language keys with multiple parameters', function (done) {
var translator = new Translator('en_GB');
- translator.translate('[[notifications:user_posted_to, [[global:guest]], My Topic]]').then(function(translated) {
+ translator.translate('[[notifications:user_posted_to, [[global:guest]], My Topic]]').then(function (translated) {
assert.strictEqual(translated, '
Guest has posted a reply to:
My Topic');
done();
});
});
- it('should handle language keys inside language keys with all parameters as language keys', function(done) {
+ it('should handle language keys inside language keys with all parameters as language keys', function (done) {
var translator = new Translator('en_GB');
- translator.translate('[[notifications:user_posted_to, [[global:guest]], [[global:guest]]]]').then(function(translated) {
+ translator.translate('[[notifications:user_posted_to, [[global:guest]], [[global:guest]]]]').then(function (translated) {
assert.strictEqual(translated, '
Guest has posted a reply to:
Guest');
done();
});
});
- it('should properly handle parameters that contain square brackets', function(done) {
+ it('should properly handle parameters that contain square brackets', function (done) {
var translator = new Translator('en_GB');
- translator.translate('[[global:pagination.out_of, [guest], [[global:home]]]]').then(function(translated) {
+ translator.translate('[[global:pagination.out_of, [guest], [[global:home]]]]').then(function (translated) {
assert.strictEqual(translated, '[guest] out of Home');
done();
});
});
- it('should properly handle parameters that contain parentheses', function(done) {
+ it('should properly handle parameters that contain parentheses', function (done) {
var translator = new Translator('en_GB');
- translator.translate('[[global:pagination.out_of, (foobar), [[global:home]]]]').then(function(translated) {
+ translator.translate('[[global:pagination.out_of, (foobar), [[global:home]]]]').then(function (translated) {
assert.strictEqual(translated, '(foobar) out of Home');
done();
});
});
- it('should not translate language key parameters with HTML in them', function(done) {
+ it('should not translate language key parameters with HTML in them', function (done) {
var translator = new Translator('en_GB');
var key = '[[global:403.login,
test]]';
- translator.translate(key).then(function(translated) {
+ translator.translate(key).then(function (translated) {
assert.strictEqual(translated, 'Perhaps you should
try logging in?');
done();
});
});
- it('should properly escape % and ,', function(done) {
+ it('should properly escape % and ,', function (done) {
var translator = new Translator('en_GB');
var title = 'Test 1, 2, 3 % salmon';
title = title.replace(/%/g, '%').replace(/,/g, ',');
var key = "[[topic:composer.replying_to, " + title + "]]";
- translator.translate(key).then(function(translated) {
+ translator.translate(key).then(function (translated) {
assert.strictEqual(translated, 'Replying to Test 1, 2, 3 % salmon');
done();
});
});
- it('should throw if not passed a language', function(done) {
+ it('should throw if not passed a language', function (done) {
assert.throws(function () {
new Translator();
}, /language string/);
done();
});
- it('should not translate [[derp] some text', function(done) {
+ it('should not translate [[derp] some text', function (done) {
var translator = new Translator('en_GB');
- translator.translate('[[derp] some text').then(function(translated) {
+ translator.translate('[[derp] some text').then(function (translated) {
assert.strictEqual('[[derp] some text', translated);
done();
});
});
- it('should not translate [[derp:xyz] some text', function(done) {
+ it('should not translate [[derp:xyz] some text', function (done) {
var translator = new Translator('en_GB');
- translator.translate('[[derp:xyz] some text').then(function(translated) {
+ translator.translate('[[derp:xyz] some text').then(function (translated) {
assert.strictEqual('[[derp:xyz] some text', translated);
done();
});
@@ -157,21 +157,21 @@ describe('new Translator(language)', function(){
});
});
-describe('Translator.create()', function(){
- it('should return an instance of Translator', function(done) {
+describe('Translator.create()', function (){
+ it('should return an instance of Translator', function (done) {
var translator = Translator.create('en_GB');
assert(translator instanceof Translator);
done();
});
- it('should return the same object for the same language', function(done) {
+ it('should return the same object for the same language', function (done) {
var one = Translator.create('de');
var two = Translator.create('de');
assert.strictEqual(one, two);
done();
});
- it('should default to defaultLang', function(done) {
+ it('should default to defaultLang', function (done) {
var translator = Translator.create();
assert.strictEqual(translator.lang, 'en_GB');
diff --git a/test/user.js b/test/user.js
index 1ed5bdaf8c..0403076f3a 100644
--- a/test/user.js
+++ b/test/user.js
@@ -17,12 +17,12 @@ var User = require('../src/user'),
Meta = require('../src/meta'),
Password = require('../src/password');
-describe('User', function() {
+describe('User', function () {
var userData,
testUid,
testCid;
- before(function(done) {
+ before(function (done) {
var groups = require('../src/groups');
groups.resetCache();
@@ -30,7 +30,7 @@ describe('User', function() {
name: 'Test Category',
description: 'A test',
order: 1
- }, function(err, categoryObj) {
+ }, function (err, categoryObj) {
if (err) {
return done(err);
}
@@ -40,7 +40,7 @@ describe('User', function() {
});
});
- beforeEach(function() {
+ beforeEach(function () {
userData = {
username: 'John Smith',
fullname: 'John Smith McNamara',
@@ -51,9 +51,9 @@ describe('User', function() {
});
- describe('.create(), when created', function() {
- it('should be created properly', function(done) {
- User.create({username: userData.username, password: userData.password, email: userData.email}, function(error,userId){
+ describe('.create(), when created', function () {
+ it('should be created properly', function (done) {
+ User.create({username: userData.username, password: userData.password, email: userData.email}, function (error,userId){
assert.equal(error, null, 'was created with error');
assert.ok(userId);
@@ -62,8 +62,8 @@ describe('User', function() {
});
});
- it('should have a valid email, if using an email', function(done) {
- User.create({username: userData.username, password: userData.password, email: 'fakeMail'},function(err) {
+ it('should have a valid email, if using an email', function (done) {
+ User.create({username: userData.username, password: userData.password, email: 'fakeMail'},function (err) {
assert(err);
assert.equal(err.message, '[[error:invalid-email]]');
done();
@@ -71,17 +71,17 @@ describe('User', function() {
});
});
- describe('.isModerator()', function() {
- it('should return false', function(done) {
- User.isModerator(testUid, testCid, function(err, isModerator) {
+ describe('.isModerator()', function () {
+ it('should return false', function (done) {
+ User.isModerator(testUid, testCid, function (err, isModerator) {
assert.equal(err, null);
assert.equal(isModerator, false);
done();
});
});
- it('should return two false results', function(done) {
- User.isModerator([testUid, testUid], testCid, function(err, isModerator) {
+ it('should return two false results', function (done) {
+ User.isModerator([testUid, testUid], testCid, function (err, isModerator) {
assert.equal(err, null);
assert.equal(isModerator[0], false);
assert.equal(isModerator[1], false);
@@ -89,8 +89,8 @@ describe('User', function() {
});
});
- it('should return two false results', function(done) {
- User.isModerator(testUid, [testCid, testCid], function(err, isModerator) {
+ it('should return two false results', function (done) {
+ User.isModerator(testUid, [testCid, testCid], function (err, isModerator) {
assert.equal(err, null);
assert.equal(isModerator[0], false);
assert.equal(isModerator[1], false);
@@ -99,8 +99,8 @@ describe('User', function() {
});
});
- describe('.isReadyToPost()', function() {
- it('should error when a user makes two posts in quick succession', function(done) {
+ describe('.isReadyToPost()', function () {
+ it('should error when a user makes two posts in quick succession', function (done) {
Meta.config = Meta.config || {};
Meta.config.postDelay = '10';
@@ -117,54 +117,54 @@ describe('User', function() {
content: 'lorem ipsum',
cid: testCid
})
- ], function(err) {
+ ], function (err) {
assert(err);
done();
});
});
- it('should allow a post if the last post time is > 10 seconds', function(done) {
- User.setUserField(testUid, 'lastposttime', +new Date() - (11 * 1000), function() {
+ it('should allow a post if the last post time is > 10 seconds', function (done) {
+ User.setUserField(testUid, 'lastposttime', +new Date() - (11 * 1000), function () {
Topics.post({
uid: testUid,
title: 'Topic 3',
content: 'lorem ipsum',
cid: testCid
- }, function(err) {
+ }, function (err) {
assert.ifError(err);
done();
});
});
});
- it('should error when a new user posts if the last post time is 10 < 30 seconds', function(done) {
+ it('should error when a new user posts if the last post time is 10 < 30 seconds', function (done) {
Meta.config.newbiePostDelay = 30;
Meta.config.newbiePostDelayThreshold = 3;
- User.setUserField(testUid, 'lastposttime', +new Date() - (20 * 1000), function() {
+ User.setUserField(testUid, 'lastposttime', +new Date() - (20 * 1000), function () {
Topics.post({
uid: testUid,
title: 'Topic 4',
content: 'lorem ipsum',
cid: testCid
- }, function(err) {
+ }, function (err) {
assert(err);
done();
});
});
});
- it('should not error if a non-newbie user posts if the last post time is 10 < 30 seconds', function(done) {
+ it('should not error if a non-newbie user posts if the last post time is 10 < 30 seconds', function (done) {
User.setUserFields(testUid, {
lastposttime: +new Date() - (20 * 1000),
reputation: 10
- }, function() {
+ }, function () {
Topics.post({
uid: testUid,
title: 'Topic 5',
content: 'lorem ipsum',
cid: testCid
- }, function(err) {
+ }, function (err) {
assert.ifError(err);
done();
});
@@ -172,9 +172,9 @@ describe('User', function() {
});
});
- describe('.search()', function() {
- it('should return an object containing an array of matching users', function(done) {
- User.search({query: 'john'}, function(err, searchData) {
+ describe('.search()', function () {
+ it('should return an object containing an array of matching users', function (done) {
+ User.search({query: 'john'}, function (err, searchData) {
assert.ifError(err);
assert.equal(Array.isArray(searchData.users) && searchData.users.length > 0, true);
assert.equal(searchData.users[0].username, 'John Smith');
@@ -183,20 +183,20 @@ describe('User', function() {
});
});
- describe('.delete()', function() {
+ describe('.delete()', function () {
var uid;
- before(function(done) {
- User.create({username: 'usertodelete', password: '123456', email: 'delete@me.com'}, function(err, newUid) {
+ before(function (done) {
+ User.create({username: 'usertodelete', password: '123456', email: 'delete@me.com'}, function (err, newUid) {
assert.ifError(err);
uid = newUid;
done();
});
});
- it('should delete a user account', function(done) {
- User.delete(1, uid, function(err) {
+ it('should delete a user account', function (done) {
+ User.delete(1, uid, function (err) {
assert.ifError(err);
- User.existsBySlug('usertodelete', function(err, exists) {
+ User.existsBySlug('usertodelete', function (err, exists) {
assert.ifError(err);
assert.equal(exists, false);
done();
@@ -205,19 +205,19 @@ describe('User', function() {
});
});
- describe('passwordReset', function() {
+ describe('passwordReset', function () {
var uid,
code;
- before(function(done) {
- User.create({username: 'resetuser', password: '123456', email: 'reset@me.com'}, function(err, newUid) {
+ before(function (done) {
+ User.create({username: 'resetuser', password: '123456', email: 'reset@me.com'}, function (err, newUid) {
assert.ifError(err);
uid = newUid;
done();
});
});
- it('.generate() should generate a new reset code', function(done) {
- User.reset.generate(uid, function(err, _code) {
+ it('.generate() should generate a new reset code', function (done) {
+ User.reset.generate(uid, function (err, _code) {
assert.ifError(err);
assert(_code);
@@ -226,36 +226,36 @@ describe('User', function() {
});
});
- it('.validate() should ensure that this new code is valid', function(done) {
- User.reset.validate(code, function(err, valid) {
+ it('.validate() should ensure that this new code is valid', function (done) {
+ User.reset.validate(code, function (err, valid) {
assert.ifError(err);
assert.strictEqual(valid, true);
done();
});
});
- it('.validate() should correctly identify an invalid code', function(done) {
- User.reset.validate(code + 'abcdef', function(err, valid) {
+ it('.validate() should correctly identify an invalid code', function (done) {
+ User.reset.validate(code + 'abcdef', function (err, valid) {
assert.ifError(err);
assert.strictEqual(valid, false);
done();
});
});
- it('.send() should create a new reset code and reset password', function(done) {
- User.reset.send('reset@me.com', function(err, code) {
+ it('.send() should create a new reset code and reset password', function (done) {
+ User.reset.send('reset@me.com', function (err, code) {
assert.ifError(err);
done();
});
});
- it('.commit() should update the user\'s password', function(done) {
- User.reset.commit(code, 'newpassword', function(err) {
+ it('.commit() should update the user\'s password', function (done) {
+ User.reset.commit(code, 'newpassword', function (err) {
assert.ifError(err);
- db.getObjectField('user:' + uid, 'password', function(err, newPassword) {
+ db.getObjectField('user:' + uid, 'password', function (err, newPassword) {
assert.ifError(err);
- Password.compare('newpassword', newPassword, function(err, match) {
+ Password.compare('newpassword', newPassword, function (err, match) {
assert.ifError(err);
assert(match);
done();
@@ -265,26 +265,26 @@ describe('User', function() {
});
});
- describe('hash methods', function() {
+ describe('hash methods', function () {
- it('should return uid from email', function(done) {
- User.getUidByEmail('john@example.com', function(err, uid) {
+ it('should return uid from email', function (done) {
+ User.getUidByEmail('john@example.com', function (err, uid) {
assert.ifError(err);
assert.equal(parseInt(uid, 10), parseInt(testUid, 10));
done();
});
});
- it('should return uid from username', function(done) {
- User.getUidByUsername('John Smith', function(err, uid) {
+ it('should return uid from username', function (done) {
+ User.getUidByUsername('John Smith', function (err, uid) {
assert.ifError(err);
assert.equal(parseInt(uid, 10), parseInt(testUid, 10));
done();
});
});
- it('should return uid from userslug', function(done) {
- User.getUidByUserslug('john-smith', function(err, uid) {
+ it('should return uid from userslug', function (done) {
+ User.getUidByUserslug('john-smith', function (err, uid) {
assert.ifError(err);
assert.equal(parseInt(uid, 10), parseInt(testUid, 10));
done();
@@ -292,7 +292,7 @@ describe('User', function() {
});
});
- after(function(done) {
+ after(function (done) {
db.flushdb(done);
});
});
\ No newline at end of file
diff --git a/test/utils.js b/test/utils.js
index befb2f78d2..9907689c11 100644
--- a/test/utils.js
+++ b/test/utils.js
@@ -5,31 +5,31 @@ var assert = require('assert'),
utils = require('./../public/src/utils.js');
-describe('Utility Methods', function(){
- describe('username validation', function(){
- it('accepts latin-1 characters', function(){
+describe('Utility Methods', function (){
+ describe('username validation', function (){
+ it('accepts latin-1 characters', function (){
var username = "John\"'-. Doeäâèéë1234";
assert(utils.isUserNameValid(username), 'invalid username');
});
- it('rejects empty string', function(){
+ it('rejects empty string', function (){
var username = '';
assert.ifError(utils.isUserNameValid(username), 'accepted as valid username');
});
});
- describe('email validation', function(){
- it('accepts sample address', function(){
+ describe('email validation', function (){
+ it('accepts sample address', function (){
var email = 'sample@example.com';
assert(utils.isEmailValid(email), 'invalid email');
});
- it('rejects empty address', function(){
+ it('rejects empty address', function (){
var email = '';
assert.ifError(utils.isEmailValid(email), 'accepted as valid email');
});
});
- describe('UUID generation', function(){
- it('return unique random value every time', function(){
+ describe('UUID generation', function (){
+ it('return unique random value every time', function (){
var uuid1 = utils.generateUUID(),
uuid2 = utils.generateUUID();
assert.notEqual(uuid1, uuid2, 'matches');