diff --git a/.eslintrc.json b/.eslintrc.json
index 996ebe85c2..9e8e4dd35b 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -18,7 +18,6 @@
"eqeqeq": "off",
"camelcase": "off",
"no-negated-condition": "off",
- "wrap-iife": "off",
"one-var-declaration-per-line": "off",
"new-cap": "off",
"no-lonely-if": "off",
@@ -57,7 +56,6 @@
"indent": "off",
"func-names": "off",
"prefer-arrow-callback": "off",
- "space-before-function-paren": "off",
"object-curly-spacing": "off",
"no-var": "off",
"no-shadow": "off",
@@ -77,7 +75,6 @@
"no-multi-spaces": "off",
"quotes": "off",
"keyword-spacing": "off",
- "space-infix-ops": "off",
"no-plusplus": "off",
"no-mixed-operators": "off",
"semi": "off",
diff --git a/Gruntfile.js b/Gruntfile.js
index eb3cdc7417..9f1585f301 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -6,7 +6,7 @@ var fork = require('child_process').fork,
incomplete = [];
-module.exports = function(grunt) {
+module.exports = function (grunt) {
var args = [];
if (!grunt.option('verbose')) {
args.push('--log-level=info');
@@ -34,7 +34,7 @@ module.exports = function(grunt) {
fromFile = ['clientLess', 'acpLess', 'js', 'tpl'];
}
- fromFile = fromFile.filter(function(ext) {
+ fromFile = fromFile.filter(function (ext) {
return incomplete.indexOf(ext) === -1;
});
@@ -44,7 +44,7 @@ module.exports = function(grunt) {
worker.kill();
worker = fork('app.js', updateArgs, { env: env });
- worker.on('message', function() {
+ worker.on('message', function () {
if (incomplete.length) {
incomplete = [];
diff --git a/app.js b/app.js
index c348cbfed5..82ffd2f7b1 100644
--- a/app.js
+++ b/app.js
@@ -36,7 +36,7 @@ global.env = process.env.NODE_ENV || 'production';
winston.remove(winston.transports.Console);
winston.add(winston.transports.Console, {
colorize: true,
- timestamp: function() {
+ timestamp: function () {
var date = new Date();
return date.getDate() + '/' + (date.getMonth() + 1) + ' ' + date.toTimeString().substr(0,5) + ' [' + global.process.pid + ']';
},
@@ -146,7 +146,7 @@ function start() {
process.on('SIGTERM', shutdown);
process.on('SIGINT', shutdown);
process.on('SIGHUP', restart);
- process.on('message', function(message) {
+ process.on('message', function (message) {
if (typeof message !== 'object') {
return;
}
@@ -173,7 +173,7 @@ function start() {
}
});
- process.on('uncaughtException', function(err) {
+ process.on('uncaughtException', function (err) {
winston.error(err.stack);
console.log(err.stack);
@@ -184,10 +184,10 @@ function start() {
async.waterfall([
async.apply(db.init),
async.apply(db.checkCompatibility),
- function(next) {
+ function (next) {
require('./src/meta').configs.init(next);
},
- function(next) {
+ function (next) {
if (nconf.get('dep-check') === undefined || nconf.get('dep-check') !== false) {
require('./src/meta').dependencies.check(next);
} else {
@@ -195,10 +195,10 @@ function start() {
setImmediate(next);
}
},
- function(next) {
+ function (next) {
require('./src/upgrade').check(next);
},
- function(next) {
+ function (next) {
var webserver = require('./src/webserver');
require('./src/socket.io').init(webserver.server);
@@ -209,7 +209,7 @@ function start() {
webserver.listen();
}
- ], function(err) {
+ ], function (err) {
if (err) {
switch(err.message) {
case 'schema-out-of-date':
@@ -251,7 +251,7 @@ function setup() {
install.setup(function (err, data) {
var separator = ' ';
if (process.stdout.columns > 10) {
- for(var x=0,cols=process.stdout.columns-10;x ');
@@ -124,18 +124,18 @@
}
function setupRestartLinks() {
- $('.restart').off('click').on('click', function() {
- bootbox.confirm('Are you sure you wish to restart NodeBB?', function(confirm) {
+ $('.restart').off('click').on('click', function () {
+ bootbox.confirm('Are you sure you wish to restart NodeBB?', function (confirm) {
if (confirm) {
- require(['admin/modules/instance'], function(instance) {
+ require(['admin/modules/instance'], function (instance) {
instance.restart();
});
}
});
});
- $('.reload').off('click').on('click', function() {
- require(['admin/modules/instance'], function(instance) {
+ $('.reload').off('click').on('click', function () {
+ require(['admin/modules/instance'], function (instance) {
instance.reload();
});
});
@@ -144,8 +144,8 @@
function launchSnackbar(params) {
var message = (params.title ? "" + params.title + " " : '') + (params.message ? params.message : '');
- require(['translator'], function(translator) {
- translator.translate(message, function(html) {
+ require(['translator'], function (translator) {
+ translator.translate(message, function (html) {
var bar = $.snackbar({
content: html,
timeout: 3000,
@@ -167,15 +167,15 @@
'tolerance': 70
});
- $('#mobile-menu').on('click', function() {
+ $('#mobile-menu').on('click', function () {
slideout.toggle();
});
- $('#menu a').on('click', function() {
+ $('#menu a').on('click', function () {
slideout.close();
});
- $(window).on('resize', function() {
+ $(window).on('resize', function () {
slideout.close();
});
@@ -190,7 +190,7 @@
slideout.on('open', onOpeningMenu);
slideout.on('translate', onOpeningMenu);
- slideout.on('close', function() {
+ slideout.on('close', function () {
$('#header').css({
'top': '0px',
'position': 'fixed'
diff --git a/public/src/admin/advanced/errors.js b/public/src/admin/advanced/errors.js
index 3977778b5a..29ee7e362c 100644
--- a/public/src/admin/advanced/errors.js
+++ b/public/src/admin/advanced/errors.js
@@ -1,19 +1,19 @@
"use strict";
/*global config, define, app, socket, ajaxify, bootbox, templates, Chart, utils */
-define('admin/advanced/errors', ['Chart'], function(Chart) {
+define('admin/advanced/errors', ['Chart'], function (Chart) {
var Errors = {};
- Errors.init = function() {
+ Errors.init = function () {
Errors.setupCharts();
$('[data-action="clear"]').on('click', Errors.clear404);
};
- Errors.clear404 = function() {
- bootbox.confirm('Are you sure you wish to clear the 404 error logs?', function(ok) {
+ Errors.clear404 = function () {
+ bootbox.confirm('Are you sure you wish to clear the 404 error logs?', function (ok) {
if (ok) {
- socket.emit('admin.errors.clear', {}, function(err) {
+ socket.emit('admin.errors.clear', {}, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -25,7 +25,7 @@ define('admin/advanced/errors', ['Chart'], function(Chart) {
});
};
- Errors.setupCharts = function() {
+ Errors.setupCharts = function () {
var notFoundCanvas = document.getElementById('not-found'),
tooBusyCanvas = document.getElementById('toobusy'),
dailyLabels = utils.getDaysArray();
diff --git a/public/src/admin/advanced/events.js b/public/src/admin/advanced/events.js
index a952666786..b4f18414ea 100644
--- a/public/src/admin/advanced/events.js
+++ b/public/src/admin/advanced/events.js
@@ -3,13 +3,13 @@
/* global define, socket, app */
-define('admin/advanced/events', function() {
+define('admin/advanced/events', function () {
var Events = {};
- Events.init = function() {
+ Events.init = function () {
- $('[data-action="clear"]').on('click', function() {
- socket.emit('admin.deleteAllEvents', function(err) {
+ $('[data-action="clear"]').on('click', function () {
+ socket.emit('admin.deleteAllEvents', function (err) {
if (err) {
return app.alertError(err.message);
}
diff --git a/public/src/admin/advanced/logs.js b/public/src/admin/advanced/logs.js
index 8411effabc..2ea10f1b36 100644
--- a/public/src/admin/advanced/logs.js
+++ b/public/src/admin/advanced/logs.js
@@ -1,22 +1,22 @@
"use strict";
/* global define, socket, app */
-define('admin/advanced/logs', function() {
+define('admin/advanced/logs', function () {
var Logs = {};
- Logs.init = function() {
+ Logs.init = function () {
var logsEl = $('.logs pre');
logsEl.scrollTop(logsEl.prop('scrollHeight'));
// Affix menu
$('.affix').affix();
- $('.logs').find('button[data-action]').on('click', function(event) {
+ $('.logs').find('button[data-action]').on('click', function (event) {
var btnEl = $(this),
action = btnEl.attr('data-action');
switch(action) {
case 'reload':
- socket.emit('admin.logs.get', function(err, logs) {
+ socket.emit('admin.logs.get', function (err, logs) {
if (!err) {
logsEl.text(logs);
logsEl.scrollTop(logsEl.prop('scrollHeight'));
@@ -27,7 +27,7 @@ define('admin/advanced/logs', function() {
break;
case 'clear':
- socket.emit('admin.logs.clear', function(err) {
+ socket.emit('admin.logs.clear', function (err) {
if (!err) {
app.alertSuccess('Logs Cleared!');
btnEl.prev().click();
diff --git a/public/src/admin/appearance/customise.js b/public/src/admin/appearance/customise.js
index e76bb9d3e4..d8ad5e3ecb 100644
--- a/public/src/admin/appearance/customise.js
+++ b/public/src/admin/appearance/customise.js
@@ -1,11 +1,11 @@
"use strict";
/* global ace, define, app, socket */
-define('admin/appearance/customise', ['admin/settings'], function(Settings) {
+define('admin/appearance/customise', ['admin/settings'], function (Settings) {
var Customise = {};
- Customise.init = function() {
- Settings.prepare(function() {
+ Customise.init = function () {
+ Settings.prepare(function () {
$('#customCSS').text($('#customCSS-holder').val());
$('#customHTML').text($('#customHTML-holder').val());
@@ -15,7 +15,7 @@ define('admin/appearance/customise', ['admin/settings'], function(Settings) {
customCSS.setTheme("ace/theme/twilight");
customCSS.getSession().setMode("ace/mode/css");
- customCSS.on('change', function(event) {
+ customCSS.on('change', function (event) {
app.flags = app.flags || {};
app.flags._unsaved = true;
$('#customCSS-holder').val(customCSS.getValue());
@@ -24,7 +24,7 @@ define('admin/appearance/customise', ['admin/settings'], function(Settings) {
customHTML.setTheme("ace/theme/twilight");
customHTML.getSession().setMode("ace/mode/html");
- customHTML.on('change', function(event) {
+ customHTML.on('change', function (event) {
app.flags = app.flags || {};
app.flags._unsaved = true;
$('#customHTML-holder').val(customHTML.getValue());
diff --git a/public/src/admin/appearance/skins.js b/public/src/admin/appearance/skins.js
index 4d0d8ffc04..9dc02a1efc 100644
--- a/public/src/admin/appearance/skins.js
+++ b/public/src/admin/appearance/skins.js
@@ -1,17 +1,17 @@
"use strict";
/* global define, app, socket, templates */
-define('admin/appearance/skins', function() {
+define('admin/appearance/skins', function () {
var Skins = {};
- Skins.init = function() {
+ Skins.init = function () {
// Populate skins from Bootswatch API
$.ajax({
method: 'get',
url: 'https://bootswatch.com/api/3.json'
}).done(Skins.render);
- $('#skins').on('click', function(e){
+ $('#skins').on('click', function (e){
var target = $(e.target);
if (!target.attr('data-action')) {
@@ -31,7 +31,7 @@ define('admin/appearance/skins', function() {
type: themeType,
id: themeId,
src: cssSrc
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -49,11 +49,11 @@ define('admin/appearance/skins', function() {
});
};
- Skins.render = function(bootswatch) {
+ Skins.render = function (bootswatch) {
var themeContainer = $('#bootstrap_themes');
templates.parse('admin/partials/theme_list', {
- themes: bootswatch.themes.map(function(theme) {
+ themes: bootswatch.themes.map(function (theme) {
return {
type: 'bootswatch',
id: theme.name,
@@ -66,13 +66,13 @@ define('admin/appearance/skins', function() {
};
}),
showRevert: true
- }, function(html) {
+ }, function (html) {
themeContainer.html(html);
if (config['theme:src']) {
var skin = config['theme:src']
.match(/latest\/(\S+)\/bootstrap.min.css/)[1]
- .replace(/(^|\s)([a-z])/g , function(m,p1,p2){return p1+p2.toUpperCase();});
+ .replace(/(^|\s)([a-z])/g , function (m,p1,p2){return p1 + p2.toUpperCase();});
highlightSelectedTheme(skin);
}
@@ -82,7 +82,7 @@ define('admin/appearance/skins', function() {
function highlightSelectedTheme(themeId) {
$('[data-theme]')
.removeClass('selected')
- .find('[data-action="use"]').each(function() {
+ .find('[data-action="use"]').each(function () {
if ($(this).parents('[data-theme]').attr('data-theme')) {
$(this)
.html('Select Skin')
diff --git a/public/src/admin/appearance/themes.js b/public/src/admin/appearance/themes.js
index 0d4e403fbd..41adcc1589 100644
--- a/public/src/admin/appearance/themes.js
+++ b/public/src/admin/appearance/themes.js
@@ -1,11 +1,11 @@
"use strict";
/* global define, app, socket, bootbox, templates, config */
-define('admin/appearance/themes', function() {
+define('admin/appearance/themes', function () {
var Themes = {};
- Themes.init = function() {
- $('#installed_themes').on('click', function(e){
+ Themes.init = function () {
+ $('#installed_themes').on('click', function (e){
var target = $(e.target),
action = target.attr('data-action');
@@ -19,7 +19,7 @@ define('admin/appearance/themes', function() {
type: themeType,
id: themeId,
src: cssSrc
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -31,7 +31,7 @@ define('admin/appearance/themes', function() {
title: 'Theme Changed',
message: 'Please restart your NodeBB to fully activate this theme',
timeout: 5000,
- clickfn: function() {
+ clickfn: function () {
socket.emit('admin.restart');
}
});
@@ -39,13 +39,13 @@ define('admin/appearance/themes', function() {
}
});
- $('#revert_theme').on('click', function() {
- bootbox.confirm('Are you sure you wish to restore the default NodeBB theme?', function(confirm) {
+ $('#revert_theme').on('click', function () {
+ bootbox.confirm('Are you sure you wish to restore the default NodeBB theme?', function (confirm) {
if (confirm) {
socket.emit('admin.themes.set', {
type: 'local',
id: 'nodebb-theme-persona'
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -62,7 +62,7 @@ define('admin/appearance/themes', function() {
});
});
- socket.emit('admin.themes.getInstalled', function(err, themes) {
+ socket.emit('admin.themes.getInstalled', function (err, themes) {
if(err) {
return app.alertError(err.message);
}
@@ -75,9 +75,9 @@ define('admin/appearance/themes', function() {
} else {
templates.parse('admin/partials/theme_list', {
themes: themes
- }, function(html) {
- require(['translator'], function(translator) {
- translator.translate(html, function(html) {
+ }, function (html) {
+ require(['translator'], function (translator) {
+ translator.translate(html, function (html) {
instListEl.html(html);
highlightSelectedTheme(config['theme:id']);
});
diff --git a/public/src/admin/extend/plugins.js b/public/src/admin/extend/plugins.js
index 3e12074e3a..bb89256959 100644
--- a/public/src/admin/extend/plugins.js
+++ b/public/src/admin/extend/plugins.js
@@ -1,9 +1,9 @@
"use strict";
/* global define, app, socket, bootbox */
-define('admin/extend/plugins', function() {
+define('admin/extend/plugins', function () {
var Plugins = {};
- Plugins.init = function() {
+ Plugins.init = function () {
var pluginsList = $('.plugins'),
numPlugins = pluginsList[0].querySelectorAll('li').length,
pluginID;
@@ -15,11 +15,11 @@ define('admin/extend/plugins', function() {
$('#plugin-search').val('');
- pluginsList.on('click', 'button[data-action="toggleActive"]', function() {
+ pluginsList.on('click', 'button[data-action="toggleActive"]', function () {
var pluginEl = $(this).parents('li');
pluginID = pluginEl.attr('data-plugin-id');
var btn = $('#' + pluginID + ' [data-action="toggleActive"]');
- socket.emit('admin.plugins.toggleActive', pluginID, function(err, status) {
+ socket.emit('admin.plugins.toggleActive', pluginID, function (err, status) {
if (err) {
return app.alertError(err);
}
@@ -37,8 +37,8 @@ define('admin/extend/plugins', function() {
message: status.active ? 'Please restart your NodeBB to fully activate this plugin' : 'Plugin successfully deactivated',
type: status.active ? 'warning' : 'success',
timeout: 5000,
- clickfn: function() {
- require(['admin/modules/instance'], function(instance) {
+ clickfn: function () {
+ require(['admin/modules/instance'], function (instance) {
instance.restart();
});
}
@@ -46,7 +46,7 @@ define('admin/extend/plugins', function() {
});
});
- pluginsList.on('click', 'button[data-action="toggleInstall"]', function() {
+ pluginsList.on('click', 'button[data-action="toggleInstall"]', function () {
var btn = $(this);
btn.attr('disabled', true);
pluginID = $(this).parents('li').attr('data-plugin-id');
@@ -55,9 +55,9 @@ define('admin/extend/plugins', function() {
return Plugins.toggleInstall(pluginID, $(this).parents('li').attr('data-version'));
}
- Plugins.suggest(pluginID, function(err, payload) {
+ Plugins.suggest(pluginID, function (err, payload) {
if (err) {
- bootbox.confirm('NodeBB could not reach the package manager, proceed with installation of latest version?
Server returned (' + err.status + ') : ' + err.responseText + '
', function(confirm) {
+ bootbox.confirm('NodeBB could not reach the package manager, proceed with installation of latest version?
Server returned (' + err.status + ') : ' + err.responseText + '
', function (confirm) {
if (confirm) {
Plugins.toggleInstall(pluginID, 'latest');
} else {
@@ -67,11 +67,11 @@ define('admin/extend/plugins', function() {
return;
}
- require(['semver'], function(semver) {
+ require(['semver'], function (semver) {
if (payload.version !== 'latest') {
Plugins.toggleInstall(pluginID, payload.version);
} else if (payload.version === 'latest') {
- confirmInstall(pluginID, function(confirm) {
+ confirmInstall(pluginID, function (confirm) {
if (confirm) {
Plugins.toggleInstall(pluginID, 'latest');
} else {
@@ -85,21 +85,21 @@ define('admin/extend/plugins', function() {
});
});
- pluginsList.on('click', 'button[data-action="upgrade"]', function() {
+ pluginsList.on('click', 'button[data-action="upgrade"]', function () {
var btn = $(this);
var parent = btn.parents('li');
pluginID = parent.attr('data-plugin-id');
- Plugins.suggest(pluginID, function(err, payload) {
+ Plugins.suggest(pluginID, function (err, payload) {
if (err) {
return bootbox.alert('NodeBB could not reach the package manager, an upgrade is not suggested at this time.
');
}
- require(['semver'], function(semver) {
+ require(['semver'], function (semver) {
if (payload.version !== 'latest' && semver.gt(payload.version, parent.find('.currentVersion').text())) {
upgrade(pluginID, btn, payload.version);
} else if (payload.version === 'latest') {
- confirmInstall(pluginID, function() {
+ confirmInstall(pluginID, function () {
upgrade(pluginID, btn, payload.version);
});
} else {
@@ -109,22 +109,22 @@ define('admin/extend/plugins', function() {
});
});
- $('#plugin-search').on('input propertychange', function() {
+ $('#plugin-search').on('input propertychange', function () {
var term = $(this).val();
- $('.plugins li').each(function() {
+ $('.plugins li').each(function () {
var pluginId = $(this).attr('data-plugin-id');
$(this).toggleClass('hide', pluginId && pluginId.indexOf(term) === -1);
});
});
- $('#plugin-order').on('click', function() {
+ $('#plugin-order').on('click', function () {
$('#order-active-plugins-modal').modal('show');
- socket.emit('admin.plugins.getActive', function(err, activePlugins) {
+ socket.emit('admin.plugins.getActive', function (err, activePlugins) {
if (err) {
return app.alertError(err);
}
var html = '';
- activePlugins.forEach(function(plugin) {
+ activePlugins.forEach(function (plugin) {
html += '' + plugin + ' ';
});
if (!activePlugins.length) {
@@ -134,14 +134,14 @@ define('admin/extend/plugins', function() {
});
});
- $('#save-plugin-order').on('click', function() {
+ $('#save-plugin-order').on('click', function () {
var plugins = $('#order-active-plugins-modal .plugin-list').children();
var data = [];
- plugins.each(function(index, el) {
+ plugins.each(function (index, el) {
data.push({name: $(el).text(), order: index});
});
- socket.emit('admin.plugins.orderActivePlugins', data, function(err) {
+ socket.emit('admin.plugins.orderActivePlugins', data, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -158,7 +158,7 @@ define('admin/extend/plugins', function() {
'No Compatibility Infomation Found
This plugin did not specify a specific version for installation given your NodeBB version. Full compatibility cannot be guaranteed, and may cause your NodeBB to no longer start properly.
' +
'In the event that NodeBB cannot boot properly:
' +
'$ ./nodebb reset plugin="' + pluginID + '" ' +
- 'Continue installation of latest version of this plugin?
', function(confirm) {
+ 'Continue installation of latest version of this plugin?
', function (confirm) {
callback(confirm);
});
}
@@ -168,7 +168,7 @@ define('admin/extend/plugins', function() {
socket.emit('admin.plugins.upgrade', {
id: pluginID,
version: version
- }, function(err, isActive) {
+ }, function (err, isActive) {
if (err) {
return app.alertError(err.message);
}
@@ -183,8 +183,8 @@ define('admin/extend/plugins', function() {
message: 'Please reload your NodeBB to fully upgrade this plugin',
type: 'warning',
timeout: 5000,
- clickfn: function() {
- require(['admin/modules/instance'], function(instance) {
+ clickfn: function () {
+ require(['admin/modules/instance'], function (instance) {
instance.reload();
});
}
@@ -193,7 +193,7 @@ define('admin/extend/plugins', function() {
});
}
- Plugins.toggleInstall = function(pluginID, version, callback) {
+ Plugins.toggleInstall = function (pluginID, version, callback) {
var btn = $('li[data-plugin-id="' + pluginID + '"] button[data-action="toggleInstall"]');
var activateBtn = btn.siblings('[data-action="toggleActive"]');
btn.find('i').attr('class', 'fa fa-refresh fa-spin');
@@ -201,7 +201,7 @@ define('admin/extend/plugins', function() {
socket.emit('admin.plugins.toggleInstall', {
id: pluginID,
version: version
- }, function(err, pluginData) {
+ }, function (err, pluginData) {
if (err) {
btn.removeAttr('disabled');
return app.alertError(err.message);
@@ -223,7 +223,7 @@ define('admin/extend/plugins', function() {
});
};
- Plugins.suggest = function(pluginId, callback) {
+ Plugins.suggest = function (pluginId, callback) {
var nbbVersion = app.config.version.match(/^\d\.\d\.\d/);
$.ajax((app.config.registry || 'https://packages.nodebb.org') + '/api/v1/suggest', {
type: 'GET',
@@ -232,13 +232,13 @@ define('admin/extend/plugins', function() {
version: nbbVersion[0]
},
dataType: 'json'
- }).done(function(payload) {
+ }).done(function (payload) {
callback(undefined, payload);
}).fail(callback);
};
function populateUpgradeablePlugins() {
- $('#installed ul li').each(function() {
+ $('#installed ul li').each(function () {
if ($(this).children('[data-action="upgrade"]').length) {
$('#upgrade ul').append($(this).clone(true));
}
@@ -246,7 +246,7 @@ define('admin/extend/plugins', function() {
}
function populateActivePlugins() {
- $('#installed ul li').each(function() {
+ $('#installed ul li').each(function () {
if ($(this).hasClass('active')) {
$('#active ul').append($(this).clone(true));
} else {
diff --git a/public/src/admin/extend/rewards.js b/public/src/admin/extend/rewards.js
index 255b53dcbf..939bdbb20d 100644
--- a/public/src/admin/extend/rewards.js
+++ b/public/src/admin/extend/rewards.js
@@ -1,7 +1,7 @@
"use strict";
/* global define, app, ajaxify, socket, templates, bootbox */
-define('admin/extend/rewards', function() {
+define('admin/extend/rewards', function () {
var rewards = {};
@@ -10,25 +10,25 @@ define('admin/extend/rewards', function() {
conditions,
conditionals;
- rewards.init = function() {
+ rewards.init = function () {
available = ajaxify.data.rewards;
active = ajaxify.data.active;
conditions = ajaxify.data.conditions;
conditionals = ajaxify.data.conditionals;
- $('[data-selected]').each(function() {
+ $('[data-selected]').each(function () {
select($(this));
});
$('#active')
- .on('change', '[data-selected]', function() {
+ .on('change', '[data-selected]', function () {
update($(this));
})
- .on('click', '.delete', function() {
+ .on('click', '.delete', function () {
var parent = $(this).parents('[data-id]'),
id = parent.attr('data-id');
- socket.emit('admin.rewards.delete', {id: id}, function(err) {
+ socket.emit('admin.rewards.delete', {id: id}, function (err) {
if (err) {
app.alertError(err.message);
} else {
@@ -39,7 +39,7 @@ define('admin/extend/rewards', function() {
parent.remove();
return false;
})
- .on('click', '.toggle', function() {
+ .on('click', '.toggle', function () {
var btn = $(this),
disabled = btn.hasClass('btn-success'),
id = $(this).parents('[data-id]').attr('data-id');
@@ -93,17 +93,17 @@ define('admin/extend/rewards', function() {
return app.alertError('Illegal reward - no inputs found! ' + el.attr('data-selected'));
}
- inputs.forEach(function(input) {
+ inputs.forEach(function (input) {
html += '' + input.label + ' ';
switch (input.type) {
case 'select':
html += '';
- input.values.forEach(function(value) {
+ input.values.forEach(function (value) {
html += '' + value.name + ' ';
});
break;
case 'text':
- html += ' ';
+ html += ' ';
break;
}
html += ' ';
@@ -113,7 +113,7 @@ define('admin/extend/rewards', function() {
}
function populateInputs() {
- $('[data-rid]').each(function(i) {
+ $('[data-rid]').each(function (i) {
var div = $(this).find('.inputs'),
rewards = active[i].rewards;
@@ -141,7 +141,7 @@ define('admin/extend/rewards', function() {
rewards: available,
};
- templates.parse('admin/extend/rewards', 'active', data, function(li) {
+ templates.parse('admin/extend/rewards', 'active', data, function (li) {
li = $(li);
ul.append(li);
li.find('select').val('');
@@ -151,16 +151,16 @@ define('admin/extend/rewards', function() {
function saveRewards() {
var activeRewards = [];
- $('#active li').each(function() {
+ $('#active li').each(function () {
var data = {rewards: {}},
main = $(this).find('form.main').serializeArray(),
rewards = $(this).find('form.rewards').serializeArray();
- main.forEach(function(obj) {
+ main.forEach(function (obj) {
data[obj.name] = obj.value;
});
- rewards.forEach(function(obj) {
+ rewards.forEach(function (obj) {
data.rewards[obj.name] = obj.value;
});
@@ -170,7 +170,7 @@ define('admin/extend/rewards', function() {
activeRewards.push(data);
});
- socket.emit('admin.rewards.save', activeRewards, function(err) {
+ socket.emit('admin.rewards.save', activeRewards, function (err) {
if (err) {
app.alertError(err.message);
} else {
diff --git a/public/src/admin/extend/widgets.js b/public/src/admin/extend/widgets.js
index 91e05beb04..761a57f423 100644
--- a/public/src/admin/extend/widgets.js
+++ b/public/src/admin/extend/widgets.js
@@ -1,11 +1,11 @@
"use strict";
/* global define, app, socket */
-define('admin/extend/widgets', ['jqueryui'], function(jqueryui) {
+define('admin/extend/widgets', ['jqueryui'], function (jqueryui) {
var Widgets = {};
- Widgets.init = function() {
- $('#widgets .nav-pills a').on('click', function(ev) {
+ Widgets.init = function () {
+ $('#widgets .nav-pills a').on('click', function (ev) {
var $this = $(this);
$('#widgets .nav-pills li').removeClass('active');
$this.parent().addClass('active');
@@ -17,7 +17,7 @@ define('admin/extend/widgets', ['jqueryui'], function(jqueryui) {
return false;
});
- $('#widget-selector').on('change', function() {
+ $('#widget-selector').on('change', function () {
$('.available-widgets [data-widget]').addClass('hide');
$('.available-widgets [data-widget="' + $(this).val() + '"]').removeClass('hide');
});
@@ -31,7 +31,7 @@ define('admin/extend/widgets', ['jqueryui'], function(jqueryui) {
$('[data-location="drafts"]').insertAfter($('[data-location="drafts"]').closest('.tab-content'));
$('#widgets .available-widgets .widget-panel').draggable({
- helper: function(e) {
+ helper: function (e) {
return $(e.target).parents('.widget-panel').clone();
},
distance: 10,
@@ -40,7 +40,7 @@ define('admin/extend/widgets', ['jqueryui'], function(jqueryui) {
$('#widgets .available-containers .containers > [data-container-html]')
.draggable({
- helper: function(e) {
+ helper: function (e) {
var target = $(e.target);
target = target.attr('data-container-html') ? target : target.parents('[data-container-html]');
@@ -48,7 +48,7 @@ define('admin/extend/widgets', ['jqueryui'], function(jqueryui) {
},
distance: 10
})
- .each(function() {
+ .each(function () {
$(this).attr('data-container-html', $(this).attr('data-container-html').replace(/\\\{([\s\S]*?)\\\}/g, '{$1}'));
});
@@ -57,15 +57,15 @@ define('admin/extend/widgets', ['jqueryui'], function(jqueryui) {
appendToggle(ui.item);
},
connectWith: "div"
- }).on('click', '.delete-widget', function() {
+ }).on('click', '.delete-widget', function () {
var panel = $(this).parents('.widget-panel');
- bootbox.confirm('Are you sure you wish to delete this widget?', function(confirm) {
+ bootbox.confirm('Are you sure you wish to delete this widget?', function (confirm) {
if (confirm) {
panel.remove();
}
});
- }).on('mouseup', '> .panel > .panel-heading', function(evt) {
+ }).on('mouseup', '> .panel > .panel-heading', function (evt) {
if ( !( $(this).parent().is('.ui-sortable-helper') || $(evt.target).closest('.delete-widget').length ) ) {
$(this).parent().children('.panel-body').toggleClass('hidden');
}
@@ -76,7 +76,7 @@ define('admin/extend/widgets', ['jqueryui'], function(jqueryui) {
function saveWidgets() {
var total = $('#widgets [data-template][data-location]').length;
- $('#widgets [data-template][data-location]').each(function(i, el) {
+ $('#widgets [data-template][data-location]').each(function (i, el) {
el = $(el);
var template = el.attr('data-template'),
@@ -84,7 +84,7 @@ define('admin/extend/widgets', ['jqueryui'], function(jqueryui) {
area = el.children('.widget-area'),
widgets = [];
- area.find('.widget-panel[data-widget]').each(function() {
+ area.find('.widget-panel[data-widget]').each(function () {
var widgetData = {},
data = $(this).find('form').serializeArray();
@@ -113,7 +113,7 @@ define('admin/extend/widgets', ['jqueryui'], function(jqueryui) {
template: template,
location: location,
widgets: widgets
- }, function(err) {
+ }, function (err) {
total--;
if (err) {
@@ -134,13 +134,13 @@ define('admin/extend/widgets', ['jqueryui'], function(jqueryui) {
});
}
- $('.color-selector').on('click', '.btn', function() {
+ $('.color-selector').on('click', '.btn', function () {
var btn = $(this),
selector = btn.parents('.color-selector'),
container = selector.parents('[data-container-html]'),
classList = [];
- selector.children().each(function() {
+ selector.children().each(function () {
classList.push($(this).attr('data-class'));
});
@@ -159,7 +159,7 @@ define('admin/extend/widgets', ['jqueryui'], function(jqueryui) {
el.addClass('block').css('width', '').css('height', '')
.droppable({
accept: '[data-container-html]',
- drop: function(event, ui) {
+ drop: function (event, ui) {
var el = $(this);
el.find('.panel-body .container-html').val(ui.draggable.attr('data-container-html'));
@@ -180,7 +180,7 @@ define('admin/extend/widgets', ['jqueryui'], function(jqueryui) {
title.text(title.text() + ' - ' + data.title);
}
- widget.find('input, textarea, select').each(function() {
+ widget.find('input, textarea, select').each(function () {
var input = $(this),
value = data[input.attr('name')];
@@ -194,16 +194,16 @@ define('admin/extend/widgets', ['jqueryui'], function(jqueryui) {
return widget;
}
- $.get(RELATIVE_PATH + '/api/admin/extend/widgets', function(data) {
+ $.get(RELATIVE_PATH + '/api/admin/extend/widgets', function (data) {
var areas = data.areas;
- for(var i=0; i'+ data.onlineRegisteredCount +'' +
+ '' + data.onlineRegisteredCount + '
' +
'Users
' +
'' +
'' +
- '
'+ data.onlineGuestCount +'
' +
+ '
' + data.onlineGuestCount + '
' +
'
Guests
' +
'
' +
'' +
- '
'+ (data.onlineRegisteredCount + data.onlineGuestCount) +'
' +
+ '
' + (data.onlineRegisteredCount + data.onlineGuestCount) + '
' +
'
Total
' +
'
' +
'' +
- '
'+ data.socketCount +'
' +
+ '
' + data.socketCount + '
' +
'
Connections
' +
'
';
@@ -150,7 +150,7 @@ define('admin/general/dashboard', ['semver', 'Chart'], function(semver, Chart) {
if (g > 255) g = 255;
else if (g < 0) g = 0;
- return (usePound?"#":"") + (g | (b << 8) | (r << 16)).toString(16);
+ return (usePound ? "#" : "") + (g | (b << 8) | (r << 16)).toString(16);
}
function setupGraphs() {
@@ -272,12 +272,12 @@ define('admin/general/dashboard', ['semver', 'Chart'], function(semver, Chart) {
$(window).on('resize', adjustPieCharts);
adjustPieCharts();
- $('[data-action="updateGraph"]').on('click', function() {
+ $('[data-action="updateGraph"]').on('click', function () {
var until = undefined;
switch($(this).attr('data-until')) {
case 'last-month':
var lastMonth = new Date();
- lastMonth.setDate(lastMonth.getDate()-30);
+ lastMonth.setDate(lastMonth.getDate() - 30);
until = lastMonth.getTime();
}
updateTrafficGraph($(this).attr('data-units'), until);
@@ -285,7 +285,7 @@ define('admin/general/dashboard', ['semver', 'Chart'], function(semver, Chart) {
}
function adjustPieCharts() {
- $('.pie-chart.legend-up').each(function() {
+ $('.pie-chart.legend-up').each(function () {
var $this = $(this);
if ($this.width() < 320) {
@@ -396,7 +396,7 @@ define('admin/general/dashboard', ['semver', 'Chart'], function(semver, Chart) {
}
function setupRealtimeButton() {
- $('#toggle-realtime .fa').on('click', function() {
+ $('#toggle-realtime .fa').on('click', function () {
var $this = $(this);
if ($this.hasClass('fa-toggle-on')) {
$this.removeClass('fa-toggle-on').addClass('fa-toggle-off');
@@ -414,13 +414,13 @@ define('admin/general/dashboard', ['semver', 'Chart'], function(semver, Chart) {
clearInterval(intervals.rooms);
clearInterval(intervals.graphs);
- intervals.rooms = setInterval(function() {
+ intervals.rooms = setInterval(function () {
if (app.isFocused && app.isConnected) {
socket.emit('admin.rooms.getAll', Admin.updateRoomUsage);
}
}, realtime ? DEFAULTS.realtimeInterval : DEFAULTS.roomInterval);
- intervals.graphs = setInterval(function() {
+ intervals.graphs = setInterval(function () {
updateTrafficGraph(currentGraph.units, currentGraph.until);
}, realtime ? DEFAULTS.realtimeInterval : DEFAULTS.graphInterval);
}
diff --git a/public/src/admin/general/homepage.js b/public/src/admin/general/homepage.js
index 96a6aac0eb..f0239e784c 100644
--- a/public/src/admin/general/homepage.js
+++ b/public/src/admin/general/homepage.js
@@ -1,7 +1,7 @@
"use strict";
/*global define*/
-define('admin/general/homepage', ['admin/settings'], function(Settings) {
+define('admin/general/homepage', ['admin/settings'], function (Settings) {
function toggleCustomRoute() {
if ($('[data-field="homePageRoute"]').val()) {
@@ -13,7 +13,7 @@ define('admin/general/homepage', ['admin/settings'], function(Settings) {
var Homepage = {};
- Homepage.init = function() {
+ Homepage.init = function () {
$('[data-field="homePageRoute"]').on('change', toggleCustomRoute);
toggleCustomRoute();
diff --git a/public/src/admin/general/languages.js b/public/src/admin/general/languages.js
index 24d6a418c9..7d597ffc46 100644
--- a/public/src/admin/general/languages.js
+++ b/public/src/admin/general/languages.js
@@ -1,10 +1,10 @@
"use strict";
/*global define*/
-define('admin/general/languages', ['admin/settings'], function(Settings) {
+define('admin/general/languages', ['admin/settings'], function (Settings) {
var Languages = {}
- Languages.init = function() {
+ Languages.init = function () {
Settings.prepare();
};
diff --git a/public/src/admin/general/navigation.js b/public/src/admin/general/navigation.js
index 1837fc590f..35ca62e094 100644
--- a/public/src/admin/general/navigation.js
+++ b/public/src/admin/general/navigation.js
@@ -1,18 +1,18 @@
"use strict";
/* global define, app, ajaxify, socket, templates */
-define('admin/general/navigation', ['translator', 'iconSelect', 'jqueryui'], function(translator, iconSelect, jqueryui) {
+define('admin/general/navigation', ['translator', 'iconSelect', 'jqueryui'], function (translator, iconSelect, jqueryui) {
var navigation = {},
available;
- navigation.init = function() {
+ navigation.init = function () {
available = ajaxify.data.available;
- $('#enabled .unescape').each(function() {
+ $('#enabled .unescape').each(function () {
$(this).val(translator.unescape($(this).val()));
});
- translator.translate(translator.unescape($('#available').html()), function(html) {
+ translator.translate(translator.unescape($('#available').html()), function (html) {
$('#available').html(html)
.find('li .drag-item').draggable({
connectToSortable: '#active-navigation',
@@ -26,9 +26,9 @@ define('admin/general/navigation', ['translator', 'iconSelect', 'jqueryui'], fun
accept: $('#available li .drag-item')
});
- $('#enabled').on('click', '.iconPicker', function() {
+ $('#enabled').on('click', '.iconPicker', function () {
var iconEl = $(this).find('i');
- iconSelect.init(iconEl, function(el) {
+ iconSelect.init(iconEl, function (el) {
var newIconClass = el.attr('value');
var index = iconEl.parents('[data-index]').attr('data-index');
$('#active-navigation [data-index="' + index + '"] i').attr('class', 'fa fa-fw ' + newIconClass);
@@ -68,13 +68,13 @@ define('admin/general/navigation', ['translator', 'iconSelect', 'jqueryui'], fun
data.enabled = false;
data.index = (parseInt($('#enabled').children().last().attr('data-index'), 10) || 0) + 1;
- templates.parse('admin/general/navigation', 'navigation', {navigation: [data]}, function(li) {
+ templates.parse('admin/general/navigation', 'navigation', {navigation: [data]}, function (li) {
li = $(translator.unescape(li));
el.after(li);
el.remove();
});
- templates.parse('admin/general/navigation', 'enabled', {enabled: [data]}, function(li) {
+ templates.parse('admin/general/navigation', 'enabled', {enabled: [data]}, function (li) {
li = $(translator.unescape(li));
$('#enabled').append(li);
componentHandler.upgradeDom()
@@ -85,17 +85,17 @@ define('admin/general/navigation', ['translator', 'iconSelect', 'jqueryui'], fun
var nav = [];
var indices = [];
- $('#active-navigation li').each(function() {
+ $('#active-navigation li').each(function () {
indices.push($(this).attr('data-index'));
});
- indices.forEach(function(index) {
+ indices.forEach(function (index) {
var el = $('#enabled').children('[data-index="' + index + '"]');
var form = el.find('form').serializeArray(),
data = {},
properties = {};
- form.forEach(function(input) {
+ form.forEach(function (input) {
if (input.name.slice(0, 9) === 'property:' && input.value === 'on') {
properties[input.name.slice(9)] = true;
} else {
@@ -114,7 +114,7 @@ define('admin/general/navigation', ['translator', 'iconSelect', 'jqueryui'], fun
nav.push(data);
});
- socket.emit('admin.navigation.save', nav, function(err) {
+ socket.emit('admin.navigation.save', nav, function (err) {
if (err) {
app.alertError(err.message);
} else {
diff --git a/public/src/admin/general/social.js b/public/src/admin/general/social.js
index 6816eb3909..9accf87417 100644
--- a/public/src/admin/general/social.js
+++ b/public/src/admin/general/social.js
@@ -1,19 +1,19 @@
"use strict";
/*global define, socket*/
-define('admin/general/social', [], function() {
+define('admin/general/social', [], function () {
var social = {};
- social.init = function() {
- $('#save').on('click', function() {
+ social.init = function () {
+ $('#save').on('click', function () {
var networks = [];
- $('#postSharingNetworks input[type="checkbox"]').each(function() {
+ $('#postSharingNetworks input[type="checkbox"]').each(function () {
if ($(this).prop('checked')) {
networks.push($(this).attr('id'));
}
});
- socket.emit('admin.social.savePostSharingNetworks', networks, function(err) {
+ socket.emit('admin.social.savePostSharingNetworks', networks, function (err) {
if (err) {
return app.alertError(err);
}
diff --git a/public/src/admin/general/sounds.js b/public/src/admin/general/sounds.js
index 73899144a0..0ea87f0917 100644
--- a/public/src/admin/general/sounds.js
+++ b/public/src/admin/general/sounds.js
@@ -1,12 +1,12 @@
"use strict";
/* global app, define, socket */
-define('admin/general/sounds', ['sounds', 'settings'], function(Sounds, Settings) {
+define('admin/general/sounds', ['sounds', 'settings'], function (Sounds, Settings) {
var SoundsAdmin = {};
- SoundsAdmin.init = function() {
+ SoundsAdmin.init = function () {
// Sounds tab
- $('.sounds').find('button[data-action="play"]').on('click', function(e) {
+ $('.sounds').find('button[data-action="play"]').on('click', function (e) {
e.preventDefault();
var fileName = $(this).parent().parent().find('select').val();
@@ -18,8 +18,8 @@ define('admin/general/sounds', ['sounds', 'settings'], function(Sounds, Settings
// Saving of Form Values
var saveEl = $('#save');
- saveEl.on('click', function() {
- Settings.save('sounds', $('.sounds form'), function() {
+ saveEl.on('click', function () {
+ Settings.save('sounds', $('.sounds form'), function () {
socket.emit('admin.fireEvent', {
name: 'event:sounds.reloadMapping'
});
diff --git a/public/src/admin/manage/categories.js b/public/src/admin/manage/categories.js
index 398d24dd42..4244fa41ab 100644
--- a/public/src/admin/manage/categories.js
+++ b/public/src/admin/manage/categories.js
@@ -1,11 +1,11 @@
"use strict";
/*global define, socket, app, bootbox, templates, ajaxify, Sortable */
-define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-serializeobject.min', 'translator'], function(serialize, translator) {
+define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-serializeobject.min', 'translator'], function (serialize, translator) {
var Categories = {}, newCategoryId = -1, sortables;
- Categories.init = function() {
- socket.emit('admin.categories.getAll', function(error, payload){
+ Categories.init = function () {
+ socket.emit('admin.categories.getAll', function (error, payload){
if(error){
return app.alertError(error.message);
}
@@ -16,13 +16,13 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri
$('button[data-action="create"]').on('click', Categories.throwCreateModal);
// Enable/Disable toggle events
- $('.categories').on('click', 'button[data-action="toggle"]', function() {
+ $('.categories').on('click', 'button[data-action="toggle"]', function () {
var $this = $(this),
cid = $this.attr('data-cid'),
parentEl = $this.parents('li[data-cid="' + cid + '"]'),
disabled = parentEl.hasClass('disabled');
- var children = parentEl.find('li[data-cid]').map(function() {
+ var children = parentEl.find('li[data-cid]').map(function () {
return $(this).attr('data-cid');
}).get();
@@ -31,15 +31,15 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri
});
};
- Categories.throwCreateModal = function() {
- socket.emit('admin.categories.getNames', {}, function(err, categories) {
+ Categories.throwCreateModal = function () {
+ socket.emit('admin.categories.getNames', {}, function (err, categories) {
if (err) {
return app.alertError(err.message);
}
templates.parse('admin/partials/categories/create', {
categories: categories
- }, function(html) {
+ }, function (html) {
function submit() {
var formData = modal.find('form').serializeObject();
formData.description = '';
@@ -67,8 +67,8 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri
});
};
- Categories.create = function(payload) {
- socket.emit('admin.categories.create', payload, function(err, data) {
+ Categories.create = function (payload) {
+ socket.emit('admin.categories.create', payload, function (err, data) {
if (err) {
return app.alertError(err.message);
}
@@ -85,7 +85,7 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri
});
};
- Categories.render = function(categories){
+ Categories.render = function (categories){
var container = $('.categories');
if (!categories || !categories.length) {
@@ -99,16 +99,16 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri
}
};
- Categories.toggle = function(cids, disabled) {
+ Categories.toggle = function (cids, disabled) {
var payload = {};
- cids.forEach(function(cid) {
+ cids.forEach(function (cid) {
payload[cid] = {
disabled: disabled ? 1 : 0
};
});
- socket.emit('admin.categories.update', payload, function(err) {
+ socket.emit('admin.categories.update', payload, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -154,8 +154,8 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri
function renderList(categories, container, parentId){
// Translate category names if needed
var count = 0;
- categories.forEach(function(category, idx, parent) {
- translator.translate(category.name, function(translated) {
+ categories.forEach(function (category, idx, parent) {
+ translator.translate(category.name, function (translated) {
if (category.name !== translated) {
category.name = translated;
}
@@ -175,11 +175,11 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri
templates.parse('admin/partials/categories/category-rows', {
cid: parentId,
categories: categories
- }, function(html) {
+ }, function (html) {
container.append(html);
// Handle and children categories in this level have
- for(var x=0,numCategories=categories.length;xDo you really want to purge this category "' + $('form.category').find('input[data-name="name"]').val() + '"?
Warning! All topics and posts in this category will be purged! 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() + '"?
Warning! All topics and posts in this category will be purged! 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() {
- var payload= {};
+ $('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('Are you sure you wish to grant the moderation privilege to this user group? This group is public, and any users can join at will.', function(confirm) {
+ bootbox.confirm('Are you sure you wish to grant the moderation privilege to this user group? This group is public, and any users can join at will.', function (confirm) {
if (confirm) {
Category.setPrivilege(member, privilege, state, checkboxEl);
} else {
@@ -208,36 +208,36 @@ define('admin/manage/category', [
Category.exposeAssumedPrivileges();
};
- Category.refreshPrivilegeTable = function() {
- socket.emit('admin.categories.getPrivilegeSettings', ajaxify.data.category.cid, function(err, privileges) {
+ Category.refreshPrivilegeTable = function () {
+ socket.emit('admin.categories.getPrivilegeSettings', ajaxify.data.category.cid, function (err, privileges) {
if (err) {
return app.alertError(err.message);
}
templates.parse('admin/partials/categories/privileges', {
privileges: privileges
- }, function(html) {
+ }, function (html) {
$('.privilege-table-container').html(html);
Category.exposeAssumedPrivileges();
});
});
};
- Category.exposeAssumedPrivileges = function() {
+ Category.exposeAssumedPrivileges = function () {
/*
If registered-users has a privilege enabled, then all users and groups of that privilege
should be assumed to have that privilege as well, even if not set in the db, so reflect
this arrangement in the table
*/
var privs = [];
- $('.privilege-table tr[data-group-name="registered-users"] td input[type="checkbox"]').parent().each(function(idx, el) {
+ $('.privilege-table tr[data-group-name="registered-users"] td input[type="checkbox"]').parent().each(function (idx, el) {
if ($(el).find('input').prop('checked')) {
privs.push(el.getAttribute('data-privilege'));
}
});
- for(var x=0,numPrivs=privs.length;x ',
show: true
});
- modal.on('shown.bs.modal', function() {
+ modal.on('shown.bs.modal', function () {
var inputEl = modal.find('input');
- autocomplete.user(inputEl, function(ev, ui) {
+ autocomplete.user(inputEl, function (ev, ui) {
socket.emit('admin.categories.setPrivilege', {
cid: ajaxify.data.category.cid,
privilege: ['find', 'read', 'topics:read'],
set: true,
member: ui.item.user.uid
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -335,23 +335,23 @@ define('admin/manage/category', [
});
};
- Category.addGroupToPrivilegeTable = function() {
+ Category.addGroupToPrivilegeTable = function () {
var modal = bootbox.dialog({
title: 'Find a Group',
message: ' ',
show: true
});
- modal.on('shown.bs.modal', function() {
+ modal.on('shown.bs.modal', function () {
var inputEl = modal.find('input');
- autocomplete.group(inputEl, function(ev, ui) {
+ autocomplete.group(inputEl, function (ev, ui) {
socket.emit('admin.categories.setPrivilege', {
cid: ajaxify.data.category.cid,
privilege: ['groups:find', 'groups:read', 'groups:topics:read'],
set: true,
member: ui.item.group.name
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -363,8 +363,8 @@ define('admin/manage/category', [
});
};
- Category.copyPrivilegesToChildren = function() {
- socket.emit('admin.categories.copyPrivilegesToChildren', ajaxify.data.category.cid, function(err) {
+ Category.copyPrivilegesToChildren = function () {
+ socket.emit('admin.categories.copyPrivilegesToChildren', ajaxify.data.category.cid, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -372,9 +372,9 @@ define('admin/manage/category', [
});
};
- Category.copyPrivilegesFromCategory = function() {
- selectCategoryModal(function(cid) {
- socket.emit('admin.categories.copyPrivilegesFrom', {toCid: ajaxify.data.category.cid, fromCid: cid}, function(err) {
+ Category.copyPrivilegesFromCategory = function () {
+ selectCategoryModal(function (cid) {
+ socket.emit('admin.categories.copyPrivilegesFrom', {toCid: ajaxify.data.category.cid, fromCid: cid}, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -384,14 +384,14 @@ define('admin/manage/category', [
};
function selectCategoryModal(callback) {
- socket.emit('admin.categories.getNames', function(err, categories) {
+ socket.emit('admin.categories.getNames', function (err, categories) {
if (err) {
return app.alertError(err.message);
}
templates.parse('admin/partials/categories/select-category', {
categories: categories
- }, function(html) {
+ }, function (html) {
function submit() {
var formData = modal.find('form').serializeObject();
callback(formData['select-cid']);
diff --git a/public/src/admin/manage/flags.js b/public/src/admin/manage/flags.js
index 30209bca11..fb8b32d602 100644
--- a/public/src/admin/manage/flags.js
+++ b/public/src/admin/manage/flags.js
@@ -5,11 +5,11 @@ define('admin/manage/flags', [
'autocomplete',
'Chart',
'components'
-], function(autocomplete, Chart, components) {
+], function (autocomplete, Chart, components) {
var Flags = {};
- Flags.init = function() {
+ Flags.init = function () {
$('.post-container .content img:not(.not-responsive)').addClass('img-responsive');
autocomplete.user($('#byUsername'));
@@ -30,19 +30,19 @@ define('admin/manage/flags', [
};
function handleDismiss() {
- $('.flags').on('click', '.dismiss', function() {
+ $('.flags').on('click', '.dismiss', function () {
var btn = $(this);
var pid = btn.parents('[data-pid]').attr('data-pid');
- socket.emit('posts.dismissFlag', pid, function(err) {
+ socket.emit('posts.dismissFlag', pid, function (err) {
done(err, btn);
});
});
}
function handleDismissAll() {
- $('#dismissAll').on('click', function() {
- socket.emit('posts.dismissAllFlags', function(err) {
+ $('#dismissAll').on('click', function () {
+ socket.emit('posts.dismissAllFlags', function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -54,15 +54,15 @@ define('admin/manage/flags', [
}
function handleDelete() {
- $('.flags').on('click', '.delete', function() {
+ $('.flags').on('click', '.delete', function () {
var btn = $(this);
- bootbox.confirm('Do you really want to delete this post?', function(confirm) {
+ bootbox.confirm('Do you really want to delete this post?', function (confirm) {
if (!confirm) {
return;
}
var pid = btn.parents('[data-pid]').attr('data-pid');
var tid = btn.parents('[data-pid]').attr('data-tid');
- socket.emit('posts.delete', {pid: pid, tid: tid}, function(err) {
+ socket.emit('posts.delete', {pid: pid, tid: tid}, function (err) {
done(err, btn);
});
});
@@ -73,7 +73,7 @@ define('admin/manage/flags', [
if (err) {
return app.alertError(err.messaage);
}
- btn.parents('[data-pid]').fadeOut(function() {
+ btn.parents('[data-pid]').fadeOut(function () {
$(this).remove();
if (!$('.flags [data-pid]').length) {
$('.post-container').text('No flagged posts!');
@@ -83,7 +83,7 @@ define('admin/manage/flags', [
function handleGraphs() {
var dailyCanvas = document.getElementById('flags:daily');
- var dailyLabels = utils.getDaysArray().map(function(text, idx) {
+ var dailyLabels = utils.getDaysArray().map(function (text, idx) {
return idx % 3 ? '' : text;
});
@@ -133,12 +133,12 @@ define('admin/manage/flags', [
// As the flag details are returned in the API, update the form controls to show the correct data
// Create reference hash for use in this method
- source = source.reduce(function(memo, cur) {
+ source = source.reduce(function (memo, cur) {
memo[cur.pid] = cur.flagData;
return memo;
}, {});
- components.get('posts/flag').each(function(idx, el) {
+ components.get('posts/flag').each(function (idx, el) {
var pid = el.getAttribute('data-pid');
var el = $(el);
@@ -159,7 +159,7 @@ define('admin/manage/flags', [
socket.emit('posts.updateFlag', {
pid: pid,
data: formData
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
} else {
diff --git a/public/src/admin/manage/group.js b/public/src/admin/manage/group.js
index 32ff8aea80..ce41436dac 100644
--- a/public/src/admin/manage/group.js
+++ b/public/src/admin/manage/group.js
@@ -6,10 +6,10 @@ define('admin/manage/group', [
'iconSelect',
'admin/modules/colorpicker',
'translator'
-], function(memberList, iconSelect, colorpicker, translator) {
+], function (memberList, iconSelect, colorpicker, translator) {
var Groups = {};
- Groups.init = function() {
+ Groups.init = function () {
var groupDetailsSearch = $('#group-details-search'),
groupDetailsSearchResults = $('#group-details-search-results'),
groupIcon = $('#group-icon'),
@@ -23,25 +23,25 @@ define('admin/manage/group', [
memberList.init();
- changeGroupUserTitle.keyup(function() {
+ changeGroupUserTitle.keyup(function () {
groupLabelPreview.text(changeGroupUserTitle.val());
});
- changeGroupLabelColor.keyup(function() {
+ changeGroupLabelColor.keyup(function () {
groupLabelPreview.css('background', changeGroupLabelColor.val() || '#000000');
});
- groupDetailsSearch.on('keyup', function() {
+ groupDetailsSearch.on('keyup', function () {
if (searchDelay) {
clearTimeout(searchDelay);
}
- searchDelay = setTimeout(function() {
+ searchDelay = setTimeout(function () {
var searchText = groupDetailsSearch.val(),
foundUser;
- socket.emit('admin.user.search', {query: searchText}, function(err, results) {
+ socket.emit('admin.user.search', {query: searchText}, function (err, results) {
if (!err && results && results.users.length > 0) {
var numResults = results.users.length, x;
if (numResults > 20) {
@@ -75,14 +75,14 @@ define('admin/manage/group', [
}, 200);
});
- groupDetailsSearchResults.on('click', 'li[data-uid]', function() {
+ groupDetailsSearchResults.on('click', 'li[data-uid]', function () {
var userLabel = $(this),
uid = parseInt(userLabel.attr('data-uid'), 10);
socket.emit('admin.groups.join', {
groupName: groupName,
uid: uid
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -96,15 +96,15 @@ define('admin/manage/group', [
"icon:text": userLabel.attr('data-usericon-text')
};
- templates.parse('partials/groups/memberlist', 'members', {group: {isOwner: ajaxify.data.group.isOwner, members: [member]}}, function(html) {
- translator.translate(html, function(html) {
+ templates.parse('partials/groups/memberlist', 'members', {group: {isOwner: ajaxify.data.group.isOwner, members: [member]}}, function (html) {
+ translator.translate(html, function (html) {
$('[component="groups/members"] tbody').prepend(html);
});
});
});
});
- $('[component="groups/members"]').on('click', '[data-action]', function() {
+ $('[component="groups/members"]').on('click', '[data-action]', function () {
var btnEl = $(this),
userRow = btnEl.parents('[data-uid]'),
ownerFlagEl = userRow.find('.member-name i'),
@@ -117,7 +117,7 @@ define('admin/manage/group', [
socket.emit('groups.' + (isOwner ? 'rescind' : 'grant'), {
toUid: uid,
groupName: groupName
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -126,14 +126,14 @@ define('admin/manage/group', [
break;
case 'kick':
- bootbox.confirm('Are you sure you want to remove this user?', function(confirm) {
+ bootbox.confirm('Are you sure you want to remove this user?', function (confirm) {
if (!confirm) {
return;
}
socket.emit('admin.groups.leave', {
uid: uid,
groupName: groupName
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -147,15 +147,15 @@ define('admin/manage/group', [
}
});
- $('#group-icon').on('click', function() {
+ $('#group-icon').on('click', function () {
iconSelect.init(groupIcon);
});
- colorpicker.enable(changeGroupLabelColor, function(hsb, hex) {
+ colorpicker.enable(changeGroupLabelColor, function (hsb, hex) {
groupLabelPreview.css('background-color', '#' + hex);
});
- $('.save').on('click', function() {
+ $('.save').on('click', function () {
socket.emit('admin.groups.update', {
groupName: groupName,
values: {
@@ -169,7 +169,7 @@ define('admin/manage/group', [
hidden: $('#group-hidden').is(':checked'),
disableJoinRequests: $('#group-disableJoinRequests').is(':checked')
}
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
diff --git a/public/src/admin/manage/groups.js b/public/src/admin/manage/groups.js
index 3eee1ca08c..bbb0c08352 100644
--- a/public/src/admin/manage/groups.js
+++ b/public/src/admin/manage/groups.js
@@ -4,12 +4,12 @@
define('admin/manage/groups', [
'translator',
'components'
-], function(translator, components) {
+], function (translator, components) {
var Groups = {};
var intervalId = 0;
- Groups.init = function() {
+ Groups.init = function () {
var createModal = $('#create-modal'),
createGroupName = $('#create-group-name'),
createModalGo = $('#create-modal-go'),
@@ -17,30 +17,30 @@ define('admin/manage/groups', [
handleSearch();
- createModal.on('keypress', function(e) {
+ createModal.on('keypress', function (e) {
if (e.keyCode === 13) {
createModalGo.click();
}
});
- $('#create').on('click', function() {
+ $('#create').on('click', function () {
createModal.modal('show');
- setTimeout(function() {
+ setTimeout(function () {
createGroupName.focus();
}, 250);
});
- createModalGo.on('click', function() {
+ createModalGo.on('click', function () {
var submitObj = {
name: createGroupName.val(),
description: $('#create-group-desc').val()
},
errorText;
- socket.emit('admin.groups.create', submitObj, function(err) {
+ socket.emit('admin.groups.create', submitObj, function (err) {
if (err) {
if (err.hasOwnProperty('message') && utils.hasLanguageKey(err.message)) {
- translator.translate(err.message, config.defaultLang, function(translated) {
+ translator.translate(err.message, config.defaultLang, function (translated) {
createModalError.html(translated).removeClass('hide');
});
} else {
@@ -49,7 +49,7 @@ define('admin/manage/groups', [
} else {
createModalError.addClass('hide');
createGroupName.val('');
- createModal.on('hidden.bs.modal', function() {
+ createModal.on('hidden.bs.modal', function () {
ajaxify.refresh();
});
createModal.modal('hide');
@@ -57,18 +57,18 @@ define('admin/manage/groups', [
});
});
- $('.groups-list').on('click', 'button[data-action]', function() {
+ $('.groups-list').on('click', 'button[data-action]', function () {
var el = $(this),
action = el.attr('data-action'),
groupName = el.parents('tr[data-groupname]').attr('data-groupname');
switch (action) {
case 'delete':
- bootbox.confirm('Are you sure you wish to delete this group?', function(confirm) {
+ bootbox.confirm('Are you sure you wish to delete this group?', function (confirm) {
if (confirm) {
socket.emit('groups.delete', {
groupName: groupName
- }, function(err, data) {
+ }, function (err, data) {
if(err) {
return app.alertError(err.message);
}
@@ -94,14 +94,14 @@ define('admin/manage/groups', [
options: {
sort: 'date'
}
- }, function(err, groups) {
+ }, function (err, groups) {
if (err) {
return app.alertError(err.message);
}
templates.parse('admin/manage/groups', 'groups', {
groups: groups
- }, function(html) {
+ }, function (html) {
groupsEl.find('[data-groupname]').remove();
groupsEl.find('tr').after(html);
});
@@ -110,7 +110,7 @@ define('admin/manage/groups', [
var queryEl = $('#group-search');
- queryEl.on('keyup', function() {
+ queryEl.on('keyup', function () {
if (intervalId) {
clearTimeout(intervalId);
intervalId = 0;
diff --git a/public/src/admin/manage/ip-blacklist.js b/public/src/admin/manage/ip-blacklist.js
index 949d8ac8fd..03f4d8bb5c 100644
--- a/public/src/admin/manage/ip-blacklist.js
+++ b/public/src/admin/manage/ip-blacklist.js
@@ -1,19 +1,19 @@
'use strict';
/* globals $, app, socket, templates, define, bootbox */
-define('admin/manage/ip-blacklist', [], function() {
+define('admin/manage/ip-blacklist', [], function () {
var Blacklist = {};
- Blacklist.init = function() {
+ Blacklist.init = function () {
var blacklist = $('#blacklist-rules');
- blacklist.on('keyup', function() {
+ blacklist.on('keyup', function () {
$('#blacklist-rules-holder').val(blacklist.val());
});
- $('[data-action="apply"]').on('click', function() {
- socket.emit('blacklist.save', blacklist.val(), function(err) {
+ $('[data-action="apply"]').on('click', function () {
+ socket.emit('blacklist.save', blacklist.val(), function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -25,15 +25,15 @@ define('admin/manage/ip-blacklist', [], function() {
});
});
- $('[data-action="test"]').on('click', function() {
+ $('[data-action="test"]').on('click', function () {
socket.emit('blacklist.validate', {
rules: blacklist.val()
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return app.alertError(err.message);
}
- templates.parse('admin/partials/blacklist-validate', data, function(html) {
+ templates.parse('admin/partials/blacklist-validate', data, function (html) {
bootbox.alert(html);
});
});
diff --git a/public/src/admin/manage/registration.js b/public/src/admin/manage/registration.js
index 55578901e8..329a4edb96 100644
--- a/public/src/admin/manage/registration.js
+++ b/public/src/admin/manage/registration.js
@@ -2,18 +2,18 @@
/* global config, socket, define, templates, bootbox, app, ajaxify, */
-define('admin/manage/registration', function() {
+define('admin/manage/registration', function () {
var Registration = {};
- Registration.init = function() {
+ Registration.init = function () {
- $('.users-list').on('click', '[data-action]', function(ev) {
+ $('.users-list').on('click', '[data-action]', function (ev) {
var parent = $(this).parents('[data-username]');
var action = $(this).attr('data-action');
var username = parent.attr('data-username');
var method = action === 'accept' ? 'admin.user.acceptRegistration' : 'admin.user.rejectRegistration';
- socket.emit(method, {username: username}, function(err) {
+ socket.emit(method, {username: username}, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -22,7 +22,7 @@ define('admin/manage/registration', function() {
return false;
});
- $('.invites-list').on('click', '[data-action]', function(ev) {
+ $('.invites-list').on('click', '[data-action]', function (ev) {
var parent = $(this).parents('[data-invitation-mail][data-invited-by]');
var email = parent.attr('data-invitation-mail');
var invitedBy = parent.attr('data-invited-by');
@@ -39,9 +39,9 @@ define('admin/manage/registration', function() {
parent.remove();
};
if (action === 'delete') {
- bootbox.confirm('Are you sure you wish to delete this invitation?', function(confirm) {
+ bootbox.confirm('Are you sure you wish to delete this invitation?', function (confirm) {
if (confirm) {
- socket.emit(method, {email: email, invitedBy: invitedBy}, function(err) {
+ socket.emit(method, {email: email, invitedBy: invitedBy}, function (err) {
if (err) {
return app.alertError(err.message);
}
diff --git a/public/src/admin/manage/tags.js b/public/src/admin/manage/tags.js
index 0c0bc368c3..108fce3797 100644
--- a/public/src/admin/manage/tags.js
+++ b/public/src/admin/manage/tags.js
@@ -5,11 +5,11 @@ define('admin/manage/tags', [
'forum/infinitescroll',
'admin/modules/selectable',
'admin/modules/colorpicker'
-], function(infinitescroll, selectable, colorpicker) {
+], function (infinitescroll, selectable, colorpicker) {
var Tags = {},
timeoutId = 0;
- Tags.init = function() {
+ Tags.init = function () {
selectable.enable('.tag-management', '.tag-row');
handleCreate();
@@ -23,29 +23,29 @@ define('admin/manage/tags', [
var createTagName = $('#create-tag-name');
var createModalGo = $('#create-modal-go');
- createModal.on('keypress', function(e) {
+ createModal.on('keypress', function (e) {
if (e.keyCode === 13) {
createModalGo.click();
}
});
- $('#create').on('click', function() {
+ $('#create').on('click', function () {
createModal.modal('show');
- setTimeout(function() {
+ setTimeout(function () {
createTagName.focus();
}, 250);
});
- createModalGo.on('click', function() {
+ createModalGo.on('click', function () {
socket.emit('admin.tags.create', {
tag: createTagName.val()
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
createTagName.val('');
- createModal.on('hidden.bs.modal', function() {
+ createModal.on('hidden.bs.modal', function () {
ajaxify.refresh();
});
createModal.modal('hide');
@@ -54,19 +54,19 @@ define('admin/manage/tags', [
}
function handleSearch() {
- $('#tag-search').on('input propertychange', function() {
+ $('#tag-search').on('input propertychange', function () {
if (timeoutId) {
clearTimeout(timeoutId);
timeoutId = 0;
}
- timeoutId = setTimeout(function() {
- socket.emit('topics.searchAndLoadTags', {query: $('#tag-search').val()}, function(err, result) {
+ timeoutId = setTimeout(function () {
+ socket.emit('topics.searchAndLoadTags', {query: $('#tag-search').val()}, function (err, result) {
if (err) {
return app.alertError(err.message);
}
- app.parseAndTranslate('admin/manage/tags', 'tags', {tags: result.tags}, function(html) {
+ app.parseAndTranslate('admin/manage/tags', 'tags', {tags: result.tags}, function (html) {
$('.tag-list').html(html);
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
timeoutId = 0;
@@ -79,7 +79,7 @@ define('admin/manage/tags', [
}
function handleModify() {
- $('#modify').on('click', function() {
+ $('#modify').on('click', function () {
var tagsToModify = $('.tag-row.ui-selected');
if (!tagsToModify.length) {
return;
@@ -95,12 +95,12 @@ define('admin/manage/tags', [
success: {
label: "Save",
className: "btn-primary save",
- callback: function() {
+ callback: function () {
var modal = $('.bootbox'),
bgColor = modal.find('[data-name="bgColor"]').val(),
color = modal.find('[data-name="color"]').val();
- tagsToModify.each(function(idx, tag) {
+ tagsToModify.each(function (idx, tag) {
tag = $(tag);
tag.find('[data-name="bgColor"]').val(bgColor);
@@ -119,21 +119,21 @@ define('admin/manage/tags', [
}
function handleDeleteSelected() {
- $('#deleteSelected').on('click', function() {
+ $('#deleteSelected').on('click', function () {
var tagsToDelete = $('.tag-row.ui-selected');
if (!tagsToDelete.length) {
return;
}
- bootbox.confirm('Do you want to delete the selected tags?', function(confirm) {
+ bootbox.confirm('Do you want to delete the selected tags?', function (confirm) {
if (!confirm) {
return;
}
var tags = [];
- tagsToDelete.each(function(index, el) {
+ tagsToDelete.each(function (index, el) {
tags.push($(el).attr('data-tag'));
});
- socket.emit('admin.tags.deleteTags', {tags: tags}, function(err) {
+ socket.emit('admin.tags.deleteTags', {tags: tags}, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -159,7 +159,7 @@ define('admin/manage/tags', [
color : tag.find('[data-name="color"]').val()
};
- socket.emit('admin.tags.update', data, function(err) {
+ socket.emit('admin.tags.update', data, function (err) {
if (err) {
return app.alertError(err.message);
}
diff --git a/public/src/admin/manage/users.js b/public/src/admin/manage/users.js
index db2cd3fef3..b8fb8d5de6 100644
--- a/public/src/admin/manage/users.js
+++ b/public/src/admin/manage/users.js
@@ -2,10 +2,10 @@
/* global config, socket, define, templates, bootbox, app, ajaxify */
-define('admin/manage/users', ['translator'], function(translator) {
+define('admin/manage/users', ['translator'], function (translator) {
var Users = {};
- Users.init = function() {
+ Users.init = function () {
var navPills = $('.nav-pills li');
var pathname = window.location.pathname;
if (!navPills.find('a[href="' + pathname + '"]').length) {
@@ -16,7 +16,7 @@ define('admin/manage/users', ['translator'], function(translator) {
function getSelectedUids() {
var uids = [];
- $('.users-table [component="user/select/single"]').each(function() {
+ $('.users-table [component="user/select/single"]').each(function () {
if ($(this).is(':checked')) {
uids.push($(this).attr('data-uid'));
}
@@ -26,7 +26,7 @@ define('admin/manage/users', ['translator'], function(translator) {
}
function update(className, state) {
- $('.users-table [component="user/select/single"]:checked').parents('.user-row').find(className).each(function() {
+ $('.users-table [component="user/select/single"]:checked').parents('.user-row').find(className).each(function () {
$(this).toggleClass('hidden', !state);
});
}
@@ -41,7 +41,7 @@ define('admin/manage/users', ['translator'], function(translator) {
}
function done(successMessage, className, flag) {
- return function(err) {
+ return function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -53,7 +53,7 @@ define('admin/manage/users', ['translator'], function(translator) {
};
}
- $('[component="user/select/all"]').on('click', function() {
+ $('[component="user/select/all"]').on('click', function () {
if ($(this).is(':checked')) {
$('.users-table [component="user/select/single"]').prop('checked', true);
} else {
@@ -61,28 +61,28 @@ define('admin/manage/users', ['translator'], function(translator) {
}
});
- $('.ban-user').on('click', function() {
+ $('.ban-user').on('click', function () {
var uids = getSelectedUids();
if (!uids.length) {
app.alertError('[[error:no-users-selected]]');
return false; // specifically to keep the menu open
}
- bootbox.confirm('Do you really want to ban ' + (uids.length > 1 ? 'these users' : 'this user') + ' permanently ?', function(confirm) {
+ bootbox.confirm('Do you really want to ban ' + (uids.length > 1 ? 'these users' : 'this user') + ' permanently ?', function (confirm) {
if (confirm) {
socket.emit('user.banUsers', { uids: uids, reason: '' }, done('User(s) banned!', '.ban', true));
}
});
});
- $('.ban-user-temporary').on('click', function() {
+ $('.ban-user-temporary').on('click', function () {
var uids = getSelectedUids();
if (!uids.length) {
app.alertError('[[error:no-users-selected]]');
return false; // specifically to keep the menu open
}
- templates.parse('admin/partials/temporary-ban', {}, function(html) {
+ templates.parse('admin/partials/temporary-ban', {}, function (html) {
bootbox.dialog({
className: 'ban-modal',
title: '[[user:ban_account]]',
@@ -95,12 +95,12 @@ define('admin/manage/users', ['translator'], function(translator) {
},
submit: {
label: 'Ban ' + uids.length + (uids.length > 1 ? ' users' : ' user'),
- callback: function() {
- var formData = $('.ban-modal form').serializeArray().reduce(function(data, cur) {
+ callback: function () {
+ var formData = $('.ban-modal form').serializeArray().reduce(function (data, cur) {
data[cur.name] = cur.value;
return data;
}, {});
- var until = formData.length ? (Date.now() + formData.length * 1000*60*60 * (parseInt(formData.unit, 10) ? 24 : 1)) : 0;
+ var until = formData.length ? (Date.now() + formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1)) : 0;
socket.emit('user.banUsers', { uids: uids, until: until, reason: formData.reason }, done('User(s) banned!', '.ban', true));
}
}
@@ -109,7 +109,7 @@ define('admin/manage/users', ['translator'], function(translator) {
});
});
- $('.unban-user').on('click', function() {
+ $('.unban-user').on('click', function () {
var uids = getSelectedUids();
if (!uids.length) {
app.alertError('[[error:no-users-selected]]');
@@ -119,7 +119,7 @@ define('admin/manage/users', ['translator'], function(translator) {
socket.emit('user.unbanUsers', uids, done('User(s) unbanned!', '.ban', false));
});
- $('.reset-lockout').on('click', function() {
+ $('.reset-lockout').on('click', function () {
var uids = getSelectedUids();
if (!uids.length) {
return;
@@ -128,7 +128,7 @@ define('admin/manage/users', ['translator'], function(translator) {
socket.emit('admin.user.resetLockouts', uids, done('Lockout(s) reset!'));
});
- $('.reset-flags').on('click', function() {
+ $('.reset-flags').on('click', function () {
var uids = getSelectedUids();
if (!uids.length) {
return;
@@ -137,7 +137,7 @@ define('admin/manage/users', ['translator'], function(translator) {
socket.emit('admin.user.resetFlags', uids, done('Flags(s) reset!'));
});
- $('.admin-user').on('click', function() {
+ $('.admin-user').on('click', function () {
var uids = getSelectedUids();
if (!uids.length) {
return;
@@ -150,7 +150,7 @@ define('admin/manage/users', ['translator'], function(translator) {
}
});
- $('.remove-admin-user').on('click', function() {
+ $('.remove-admin-user').on('click', function () {
var uids = getSelectedUids();
if (!uids.length) {
return;
@@ -159,7 +159,7 @@ define('admin/manage/users', ['translator'], function(translator) {
if (uids.indexOf(app.user.uid.toString()) !== -1) {
app.alertError('You can\'t remove yourself as Administrator!');
} else {
- bootbox.confirm('Do you really want to remove admins?', function(confirm) {
+ bootbox.confirm('Do you really want to remove admins?', function (confirm) {
if (confirm) {
socket.emit('admin.user.removeAdmins', uids, done('User(s) are no longer administrators.', '.administrator', false));
}
@@ -167,17 +167,17 @@ define('admin/manage/users', ['translator'], function(translator) {
}
});
- $('.validate-email').on('click', function() {
+ $('.validate-email').on('click', function () {
var uids = getSelectedUids();
if (!uids.length) {
return;
}
- bootbox.confirm('Do you want to validate email(s) of these user(s)?', function(confirm) {
+ bootbox.confirm('Do you want to validate email(s) of these user(s)?', function (confirm) {
if (!confirm) {
return;
}
- socket.emit('admin.user.validateEmail', uids, function(err) {
+ socket.emit('admin.user.validateEmail', uids, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -189,12 +189,12 @@ define('admin/manage/users', ['translator'], function(translator) {
});
});
- $('.send-validation-email').on('click', function() {
+ $('.send-validation-email').on('click', function () {
var uids = getSelectedUids();
if (!uids.length) {
return;
}
- socket.emit('admin.user.sendValidationEmail', uids, function(err) {
+ socket.emit('admin.user.sendValidationEmail', uids, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -202,28 +202,28 @@ define('admin/manage/users', ['translator'], function(translator) {
});
});
- $('.password-reset-email').on('click', function() {
+ $('.password-reset-email').on('click', function () {
var uids = getSelectedUids();
if (!uids.length) {
return;
}
- bootbox.confirm('Do you want to send password reset email(s) to these user(s)?', function(confirm) {
+ bootbox.confirm('Do you want to send password reset email(s) to these user(s)?', function (confirm) {
if (confirm) {
socket.emit('admin.user.sendPasswordResetEmail', uids, done('Emails sent'));
}
});
});
- $('.delete-user').on('click', function() {
+ $('.delete-user').on('click', function () {
var uids = getSelectedUids();
if (!uids.length) {
return;
}
- bootbox.confirm('Warning! Do you really want to delete user(s)? This action is not reversable, only the user account will be deleted, their posts and topics will not be deleled!', function(confirm) {
+ bootbox.confirm('Warning! Do you really want to delete user(s)? This action is not reversable, only the user account will be deleted, their posts and topics will not be deleled!', function (confirm) {
if (confirm) {
- socket.emit('admin.user.deleteUsers', uids, function(err) {
+ socket.emit('admin.user.deleteUsers', uids, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -236,14 +236,14 @@ define('admin/manage/users', ['translator'], function(translator) {
});
});
- $('.delete-user-and-content').on('click', function() {
+ $('.delete-user-and-content').on('click', function () {
var uids = getSelectedUids();
if (!uids.length) {
return;
}
- bootbox.confirm('Warning! Do you really want to delete user(s) and their content? This action is not reversable, all user data and content will be erased!', function(confirm) {
+ bootbox.confirm('Warning! Do you really want to delete user(s) and their content? This action is not reversable, all user data and content will be erased!', function (confirm) {
if (confirm) {
- socket.emit('admin.user.deleteUsersAndContent', uids, function(err) {
+ socket.emit('admin.user.deleteUsersAndContent', uids, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -257,9 +257,9 @@ define('admin/manage/users', ['translator'], function(translator) {
});
function handleUserCreate() {
- $('#createUser').on('click', function() {
- templates.parse('admin/partials/create_user_modal', {}, function(html) {
- translator.translate(html, function(html) {
+ $('#createUser').on('click', function () {
+ templates.parse('admin/partials/create_user_modal', {}, function (html) {
+ translator.translate(html, function (html) {
bootbox.dialog({
message: html,
title: 'Create User',
@@ -272,7 +272,7 @@ define('admin/manage/users', ['translator'], function(translator) {
create: {
label: 'Create',
className: 'btn-primary',
- callback: function() {
+ callback: function () {
createUser.call(this);
return false;
}
@@ -303,13 +303,13 @@ define('admin/manage/users', ['translator'], function(translator) {
password: password
};
- socket.emit('admin.user.createUser', user, function(err) {
+ socket.emit('admin.user.createUser', user, function (err) {
if(err) {
return errorEl.translateHtml('Error ' + err.message + '
').removeClass('hide');
}
modal.modal('hide');
- modal.on('hidden.bs.modal', function() {
+ modal.on('hidden.bs.modal', function () {
ajaxify.refresh();
});
app.alertSuccess('User created!');
@@ -318,7 +318,7 @@ define('admin/manage/users', ['translator'], function(translator) {
var timeoutId = 0;
- $('#search-user-name, #search-user-email, #search-user-ip').on('keyup', function() {
+ $('#search-user-name, #search-user-email, #search-user-ip').on('keyup', function () {
if (timeoutId !== 0) {
clearTimeout(timeoutId);
timeoutId = 0;
@@ -327,15 +327,15 @@ define('admin/manage/users', ['translator'], function(translator) {
var $this = $(this);
var type = $this.attr('data-search-type');
- timeoutId = setTimeout(function() {
+ timeoutId = setTimeout(function () {
$('.fa-spinner').removeClass('hidden');
- socket.emit('admin.user.search', {searchBy: type, query: $this.val()}, function(err, data) {
+ socket.emit('admin.user.search', {searchBy: type, query: $this.val()}, function (err, data) {
if (err) {
return app.alertError(err.message);
}
- templates.parse('admin/manage/users', 'users', data, function(html) {
+ templates.parse('admin/manage/users', 'users', data, function (html) {
html = $(html);
$('.users-table tr').not(':first').remove();
$('.users-table tr').first().after(html);
@@ -367,13 +367,13 @@ define('admin/manage/users', ['translator'], function(translator) {
};
function handleInvite() {
- $('[component="user/invite"]').on('click', function() {
- bootbox.prompt('Email: ', function(email) {
+ $('[component="user/invite"]').on('click', function () {
+ bootbox.prompt('Email: ', function (email) {
if (!email) {
return;
}
- socket.emit('user.invite', email, function(err) {
+ socket.emit('user.invite', email, function (err) {
if (err) {
return app.alertError(err.message);
}
diff --git a/public/src/admin/modules/colorpicker.js b/public/src/admin/modules/colorpicker.js
index 6a0054ae85..47e129249a 100644
--- a/public/src/admin/modules/colorpicker.js
+++ b/public/src/admin/modules/colorpicker.js
@@ -2,22 +2,22 @@
/*globals define*/
-define('admin/modules/colorpicker', function() {
+define('admin/modules/colorpicker', function () {
var colorpicker = {};
- colorpicker.enable = function(inputEl, callback) {
- (inputEl instanceof jQuery ? inputEl : $(inputEl)).each(function() {
+ colorpicker.enable = function (inputEl, callback) {
+ (inputEl instanceof jQuery ? inputEl : $(inputEl)).each(function () {
var $this = $(this);
$this.ColorPicker({
color: $this.val() || '#000',
- onChange: function(hsb, hex) {
+ onChange: function (hsb, hex) {
$this.val('#' + hex);
if (typeof callback === 'function') {
callback(hsb, hex);
}
},
- onShow: function(colpkr) {
+ onShow: function (colpkr) {
$(colpkr).css('z-index', 1051);
}
});
diff --git a/public/src/admin/modules/instance.js b/public/src/admin/modules/instance.js
index edad60b80e..d5c2164155 100644
--- a/public/src/admin/modules/instance.js
+++ b/public/src/admin/modules/instance.js
@@ -2,10 +2,10 @@
/*globals define, app, socket*/
-define('admin/modules/instance', function() {
+define('admin/modules/instance', function () {
var instance = {};
- instance.reload = function(callback) {
+ instance.reload = function (callback) {
app.alert({
alert_id: 'instance_reload',
type: 'info',
@@ -14,7 +14,7 @@ define('admin/modules/instance', function() {
timeout: 5000
});
- socket.emit('admin.reload', function(err) {
+ socket.emit('admin.reload', function (err) {
if (!err) {
app.alert({
alert_id: 'instance_reload',
@@ -38,7 +38,7 @@ define('admin/modules/instance', function() {
});
};
- instance.restart = function(callback) {
+ instance.restart = function (callback) {
app.alert({
alert_id: 'instance_restart',
type: 'info',
@@ -47,7 +47,7 @@ define('admin/modules/instance', function() {
timeout: 5000
});
- $(window).one('action:reconnected', function() {
+ $(window).one('action:reconnected', function () {
app.alert({
alert_id: 'instance_restart',
type: 'success',
diff --git a/public/src/admin/modules/search.js b/public/src/admin/modules/search.js
index ae15ad0064..b639034ebd 100644
--- a/public/src/admin/modules/search.js
+++ b/public/src/admin/modules/search.js
@@ -1,11 +1,11 @@
"use strict";
/*globals define, admin, ajaxify, RELATIVE_PATH*/
-define(function() {
+define(function () {
var search = {},
searchIndex;
- search.init = function() {
+ search.init = function () {
$.getJSON(RELATIVE_PATH + '/templates/indexed.json', function (data) {
searchIndex = data;
for (var file in searchIndex) {
@@ -31,17 +31,17 @@ define(function() {
input = $('#acp-search input'),
firstResult = null;
- input.on('keyup', function() {
+ input.on('keyup', function () {
$('#acp-search .dropdown').addClass('open');
});
- $('#acp-search').parents('form').on('submit', function(ev) {
+ $('#acp-search').parents('form').on('submit', function (ev) {
var input = $(this).find('input'),
href = firstResult ? firstResult : RELATIVE_PATH + '/search/' + input.val();
ajaxify.go(href.replace(/^\//, ''));
- setTimeout(function() {
+ setTimeout(function () {
$('#acp-search .dropdown').removeClass('open');
$(input).blur();
}, 150);
@@ -50,11 +50,11 @@ define(function() {
return false;
});
- $('#main-menu a').each(function(idx, link) {
+ $('#main-menu a').each(function (idx, link) {
routes.push($(link).attr('href'));
});
- input.on('keyup focus', function() {
+ input.on('keyup focus', function () {
var $input = $(this),
value = $input.val().toLowerCase(),
menuItems = $('#acp-search .dropdown-menu').html('');
diff --git a/public/src/admin/modules/selectable.js b/public/src/admin/modules/selectable.js
index 5e4bb5725f..6964f74924 100644
--- a/public/src/admin/modules/selectable.js
+++ b/public/src/admin/modules/selectable.js
@@ -2,10 +2,10 @@
/*globals define*/
-define('admin/modules/selectable', ['jqueryui'], function(jqueryui) {
+define('admin/modules/selectable', ['jqueryui'], function (jqueryui) {
var selectable = {};
- selectable.enable = function(containerEl, targets) {
+ selectable.enable = function (containerEl, targets) {
$(containerEl).selectable({
filter: targets
});
diff --git a/public/src/admin/settings.js b/public/src/admin/settings.js
index d6436ccefc..ce0a17933f 100644
--- a/public/src/admin/settings.js
+++ b/public/src/admin/settings.js
@@ -1,16 +1,16 @@
'use strict';
/*global define, app, socket, ajaxify */
-define('admin/settings', ['uploader'], function(uploader) {
+define('admin/settings', ['uploader'], function (uploader) {
var Settings = {};
- Settings.init = function() {
+ Settings.init = function () {
console.warn('[deprecation] require(\'admin/settings\').init() has been deprecated, please call require(\'admin/settings\').prepare() directly instead.');
Settings.prepare();
};
- Settings.populateTOC = function() {
- $('.settings-header').each(function() {
+ Settings.populateTOC = function () {
+ $('.settings-header').each(function () {
var header = $(this).text(),
anchor = header.toLowerCase().replace(/ /g, '-').trim();
@@ -19,7 +19,7 @@ define('admin/settings', ['uploader'], function(uploader) {
});
};
- Settings.prepare = function(callback) {
+ Settings.prepare = function (callback) {
// Populate the fields on the page from the config
var fields = $('#content [data-field]'),
numFields = fields.length,
@@ -28,7 +28,7 @@ define('admin/settings', ['uploader'], function(uploader) {
x, key, inputType, field;
// Handle unsaved changes
- $(fields).on('change', function() {
+ $(fields).on('change', function () {
app.flags = app.flags || {};
app.flags._unsaved = true;
});
@@ -66,11 +66,11 @@ define('admin/settings', ['uploader'], function(uploader) {
}
}
- revertBtn.off('click').on('click', function() {
+ revertBtn.off('click').on('click', function () {
ajaxify.refresh();
});
- saveBtn.off('click').on('click', function(e) {
+ saveBtn.off('click').on('click', function (e) {
e.preventDefault();
saveFields(fields, function onFieldsSaved(err) {
@@ -100,8 +100,8 @@ define('admin/settings', ['uploader'], function(uploader) {
handleUploads();
- $('#clear-sitemap-cache').off('click').on('click', function() {
- socket.emit('admin.settings.clearSitemapCache', function() {
+ $('#clear-sitemap-cache').off('click').on('click', function () {
+ socket.emit('admin.settings.clearSitemapCache', function () {
app.alertSuccess('Sitemap Cache Cleared!');
});
return false;
@@ -111,15 +111,15 @@ define('admin/settings', ['uploader'], function(uploader) {
callback();
}
- setTimeout(function() {
+ setTimeout(function () {
$(window).trigger('action:admin.settingsLoaded');
}, 0);
};
function handleUploads() {
- $('#content input[data-action="upload"]').each(function() {
+ $('#content input[data-action="upload"]').each(function () {
var uploadBtn = $(this);
- uploadBtn.on('click', function() {
+ uploadBtn.on('click', function () {
uploader.show({
title: uploadBtn.attr('data-title'),
description: uploadBtn.attr('data-description'),
@@ -127,7 +127,7 @@ define('admin/settings', ['uploader'], function(uploader) {
params: {},
showHelp: uploadBtn.attr('data-help') ? uploadBtn.attr('data-help') === 1 : undefined,
accept: uploadBtn.attr('data-accept')
- }, function(image) {
+ }, function (image) {
// need to move these into template, ex data-callback
if (ajaxify.currentPage === 'admin/general/sounds') {
ajaxify.refresh();
@@ -139,14 +139,14 @@ define('admin/settings', ['uploader'], function(uploader) {
});
}
- Settings.remove = function(key) {
+ Settings.remove = function (key) {
socket.emit('admin.config.remove', key);
};
function saveFields(fields, callback) {
var data = {};
- fields.each(function() {
+ fields.each(function () {
var field = $(this);
var key = field.attr('data-field'),
value, inputType;
@@ -173,7 +173,7 @@ define('admin/settings', ['uploader'], function(uploader) {
data[key] = value;
});
- socket.emit('admin.config.setMultiple', data, function(err) {
+ socket.emit('admin.config.setMultiple', data, function (err) {
if (err) {
return callback(err);
}
diff --git a/public/src/admin/settings/email.js b/public/src/admin/settings/email.js
index e404099800..d296c8aa25 100644
--- a/public/src/admin/settings/email.js
+++ b/public/src/admin/settings/email.js
@@ -1,23 +1,23 @@
"use strict";
/* global define, socket, app, ajaxify, ace */
-define('admin/settings/email', ['admin/settings'], function(settings) {
+define('admin/settings/email', ['admin/settings'], function (settings) {
var module = {},
emailEditor;
- module.init = function() {
+ module.init = function () {
configureEmailTester();
configureEmailEditor();
$(window).on('action:admin.settingsLoaded action:admin.settingsSaved', handleDigestHourChange);
- $(window).on('action:admin.settingsSaved', function() {
+ $(window).on('action:admin.settingsSaved', function () {
socket.emit('admin.user.restartJobs');
});
};
function configureEmailTester() {
- $('button[data-action="email.test"]').off('click').on('click', function() {
- socket.emit('admin.email.test', {template: $('#test-email').val()}, function(err) {
+ $('button[data-action="email.test"]').off('click').on('click', function () {
+ socket.emit('admin.email.test', {template: $('#test-email').val()}, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -34,10 +34,10 @@ define('admin/settings/email', ['admin/settings'], function(settings) {
emailEditor.setTheme("ace/theme/twilight");
emailEditor.getSession().setMode("ace/mode/html");
- emailEditor.on('change', function() {
+ emailEditor.on('change', function () {
var emailPath = $('#email-editor-selector').val();
var original;
- ajaxify.data.emails.forEach(function(email) {
+ ajaxify.data.emails.forEach(function (email) {
if (email.path === emailPath) {
original = email.original;
}
@@ -46,8 +46,8 @@ define('admin/settings/email', ['admin/settings'], function(settings) {
$('#email-editor-holder').val(newEmail !== original ? newEmail : '');
});
- $('button[data-action="email.revert"]').off('click').on('click', function() {
- ajaxify.data.emails.forEach(function(email) {
+ $('button[data-action="email.revert"]').off('click').on('click', function () {
+ ajaxify.data.emails.forEach(function (email) {
if (email.path === $('#email-editor-selector').val()) {
emailEditor.getSession().setValue(email.original);
$('#email-editor-holder').val('');
@@ -59,7 +59,7 @@ define('admin/settings/email', ['admin/settings'], function(settings) {
}
function updateEmailEditor() {
- ajaxify.data.emails.forEach(function(email) {
+ ajaxify.data.emails.forEach(function (email) {
if (email.path === $('#email-editor-selector').val()) {
emailEditor.getSession().setValue(email.text);
$('#email-editor-holder')
@@ -78,7 +78,7 @@ define('admin/settings/email', ['admin/settings'], function(settings) {
hour = 0;
}
- socket.emit('meta.getServerTime', {}, function(err, now) {
+ socket.emit('meta.getServerTime', {}, function (err, now) {
if (err) {
return app.alertError(err.message);
}
diff --git a/public/src/admin/settings/general.js b/public/src/admin/settings/general.js
index 0c36db401c..fc0d7d540f 100644
--- a/public/src/admin/settings/general.js
+++ b/public/src/admin/settings/general.js
@@ -1,20 +1,20 @@
"use strict";
/* global define, socket */
-define('admin/settings/general', ['admin/settings'], function(Settings) {
+define('admin/settings/general', ['admin/settings'], function (Settings) {
var Module = {}
- Module.init = function() {
- $('button[data-action="removeLogo"]').on('click', function() {
+ Module.init = function () {
+ $('button[data-action="removeLogo"]').on('click', function () {
$('input[data-field="brand:logo"]').val('');
});
- $('button[data-action="removeFavicon"]').on('click', function() {
+ $('button[data-action="removeFavicon"]').on('click', function () {
$('input[data-field="brand:favicon"]').val('');
});
- $('button[data-action="removeTouchIcon"]').on('click', function() {
+ $('button[data-action="removeTouchIcon"]').on('click', function () {
$('input[data-field="brand:touchIcon"]').val('');
});
- $('button[data-action="removeOgImage"]').on('click', function() {
+ $('button[data-action="removeOgImage"]').on('click', function () {
$('input[data-field="removeOgImage"]').val('');
});
};
diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js
index b4ad44e51b..955acab7bb 100644
--- a/public/src/ajaxify.js
+++ b/public/src/ajaxify.js
@@ -3,7 +3,7 @@
var ajaxify = ajaxify || {};
-$(document).ready(function() {
+$(document).ready(function () {
var location = document.location || window.location;
var rootUrl = location.protocol + '//' + (location.hostname || location.host) + (location.port ? ':' + location.port : '');
var apiXHR = null;
@@ -14,7 +14,7 @@ $(document).ready(function() {
// Dumb hack to fool ajaxify into thinking translator is still a global
// When ajaxify is migrated to a require.js module, then this can be merged into the "define" call
- require(['translator'], function(_translator) {
+ require(['translator'], function (_translator) {
translator = _translator;
});
@@ -27,7 +27,7 @@ $(document).ready(function() {
url: ev.state.returnPath
}, ev.state.returnPath, config.relative_path + '/' + ev.state.returnPath);
} else if (ev.state.url !== undefined) {
- ajaxify.go(ev.state.url, function() {
+ ajaxify.go(ev.state.url, function () {
$(window).trigger('action:popstate', {url: ev.state.url});
}, true);
}
@@ -41,7 +41,7 @@ $(document).ready(function() {
if (ajaxify.reconnectAction) {
$(window).off('action:reconnected', ajaxify.reconnectAction);
}
- ajaxify.reconnectAction = function(e) {
+ ajaxify.reconnectAction = function (e) {
ajaxify.go(url, callback, quiet);
$(window).off(e);
};
@@ -75,7 +75,7 @@ $(document).ready(function() {
previousBodyClass = ajaxify.data.bodyClass;
$('#footer, #content').removeClass('hide').addClass('ajaxifying');
- ajaxify.loadData(url, function(err, data) {
+ ajaxify.loadData(url, function (err, data) {
if (!err || (err && err.data && (parseInt(err.data.status, 10) !== 302 && parseInt(err.data.status, 10) !== 308))) {
ajaxify.updateHistory(url, quiet);
@@ -88,7 +88,7 @@ $(document).ready(function() {
retry = true;
app.template = data.template.name;
- require(['translator'], function(translator) {
+ require(['translator'], function (translator) {
translator.load(config.defaultLang, data.template.name);
renderTemplate(url, data.template.name, data, callback);
});
@@ -97,7 +97,7 @@ $(document).ready(function() {
return true;
};
- ajaxify.handleRedirects = function(url) {
+ ajaxify.handleRedirects = function (url) {
url = ajaxify.removeRelativePath(url.replace(/\/$/, '')).toLowerCase();
var isClientToAdmin = url.startsWith('admin') && window.location.pathname.indexOf(RELATIVE_PATH + '/admin') !== 0;
var isAdminToClient = !url.startsWith('admin') && window.location.pathname.indexOf(RELATIVE_PATH + '/admin') === 0;
@@ -110,7 +110,7 @@ $(document).ready(function() {
};
- ajaxify.start = function(url) {
+ ajaxify.start = function (url) {
url = ajaxify.removeRelativePath(url.replace(/^\/|\/$/g, ''));
var payload = {
@@ -122,7 +122,7 @@ $(document).ready(function() {
return payload.url;
};
- ajaxify.updateHistory = function(url, quiet) {
+ ajaxify.updateHistory = function (url, quiet) {
ajaxify.currentPage = url.split(/[?#]/)[0];
if (window.history && window.history.pushState) {
window.history[!quiet ? 'pushState' : 'replaceState']({
@@ -171,8 +171,8 @@ $(document).ready(function() {
function renderTemplate(url, tpl_url, data, callback) {
$(window).trigger('action:ajaxify.loadingTemplates', {});
- templates.parse(tpl_url, data, function(template) {
- translator.translate(template, function(translatedTemplate) {
+ templates.parse(tpl_url, data, function (template) {
+ translator.translate(template, function (translatedTemplate) {
translatedTemplate = translator.unescape(translatedTemplate);
$('body').removeClass(previousBodyClass).addClass(data.bodyClass);
$('#content').html(translatedTemplate);
@@ -190,7 +190,7 @@ $(document).ready(function() {
});
}
- ajaxify.end = function(url, tpl_url) {
+ ajaxify.end = function (url, tpl_url) {
function done() {
if (--count === 0) {
$(window).trigger('action:ajaxify.end', {url: url, tpl_url: tpl_url, title: ajaxify.data.title});
@@ -207,7 +207,7 @@ $(document).ready(function() {
app.processPage();
};
- ajaxify.parseData = function() {
+ ajaxify.parseData = function () {
var dataEl = $('#ajaxify-data');
if (dataEl.length) {
ajaxify.data = JSON.parse(dataEl.text());
@@ -215,18 +215,18 @@ $(document).ready(function() {
}
};
- ajaxify.removeRelativePath = function(url) {
+ ajaxify.removeRelativePath = function (url) {
if (url.startsWith(RELATIVE_PATH.slice(1))) {
url = url.slice(RELATIVE_PATH.length);
}
return url;
};
- ajaxify.refresh = function(callback) {
+ ajaxify.refresh = function (callback) {
ajaxify.go(ajaxify.currentPage + window.location.search + window.location.hash, callback, true);
};
- ajaxify.loadScript = function(tpl_url, callback) {
+ ajaxify.loadScript = function (tpl_url, callback) {
var location = !app.inAdmin ? 'forum/' : '';
if (tpl_url.startsWith('admin')) {
@@ -239,7 +239,7 @@ $(document).ready(function() {
$(window).trigger('action:script.load', data);
- require(data.scripts, function(script) {
+ require(data.scripts, function (script) {
if (script && script.init) {
script.init();
}
@@ -250,7 +250,7 @@ $(document).ready(function() {
});
};
- ajaxify.loadData = function(url, callback) {
+ ajaxify.loadData = function (url, callback) {
url = ajaxify.removeRelativePath(url);
$(window).trigger('action:ajaxify.loadingData', {url: url});
@@ -258,7 +258,7 @@ $(document).ready(function() {
apiXHR = $.ajax({
url: RELATIVE_PATH + '/api/' + url,
cache: false,
- success: function(data) {
+ success: function (data) {
if (!data) {
return;
}
@@ -270,7 +270,7 @@ $(document).ready(function() {
callback(null, data);
},
- error: function(data, textStatus) {
+ error: function (data, textStatus) {
if (data.status === 0 && textStatus === 'error') {
data.status = 500;
}
@@ -282,17 +282,17 @@ $(document).ready(function() {
});
};
- ajaxify.loadTemplate = function(template, callback) {
+ ajaxify.loadTemplate = function (template, callback) {
if (templates.cache[template]) {
callback(templates.cache[template]);
} else {
$.ajax({
url: RELATIVE_PATH + '/templates/' + template + '.tpl' + (config['cache-buster'] ? '?v=' + config['cache-buster'] : ''),
type: 'GET',
- success: function(data) {
+ success: function (data) {
callback(data.toString());
},
- error: function(error) {
+ error: function (error) {
throw new Error("Unable to load template: " + template + " (" + error.statusText + ")");
}
});
@@ -309,7 +309,7 @@ $(document).ready(function() {
// Enhancing all anchors to ajaxify...
$(document.body).on('click', 'a', function (e) {
var _self = this;
- var process = function() {
+ var process = function () {
if (!e.ctrlKey && !e.shiftKey && !e.metaKey && e.which === 1) {
if (internalLink) {
var pathname = this.href.replace(rootUrl + RELATIVE_PATH + '/', '');
@@ -358,8 +358,8 @@ $(document).ready(function() {
}
if (app.flags && app.flags.hasOwnProperty('_unsaved') && app.flags._unsaved === true) {
- translator.translate('[[global:unsaved-changes]]', function(text) {
- bootbox.confirm(text, function(navigate) {
+ translator.translate('[[global:unsaved-changes]]', function (text) {
+ bootbox.confirm(text, function (navigate) {
if (navigate) {
app.flags._unsaved = false;
process.call(_self);
@@ -382,7 +382,7 @@ $(document).ready(function() {
app.load();
- $('[type="text/tpl"][data-template]').each(function() {
+ $('[type="text/tpl"][data-template]').each(function () {
templates.cache[$(this).attr('data-template')] = $('
').html($(this).html()).text();
$(this).parent().remove();
});
diff --git a/public/src/app.js b/public/src/app.js
index 46f0419709..442e57f373 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -19,7 +19,7 @@ app.cacheBuster = null;
locale: config.userLang
});
- app.load = function() {
+ app.load = function () {
app.loadProgressiveStylesheet();
var url = ajaxify.start(window.location.pathname.slice(1) + window.location.search + window.location.hash);
@@ -33,15 +33,15 @@ app.cacheBuster = null;
app.handleSearch();
}
- $('body').on('click', '#new_topic', function(){
+ $('body').on('click', '#new_topic', function (){
app.newTopic();
});
- require(['components'], function(components) {
+ require(['components'], function (components) {
components.get('user/logout').on('click', app.logout);
});
- Visibility.change(function(event, state){
+ Visibility.change(function (event, state){
if (state === 'visible') {
app.isFocused = true;
app.alternatingTitle('');
@@ -56,7 +56,7 @@ app.cacheBuster = null;
app.showEmailConfirmWarning();
socket.removeAllListeners('event:nodebb.ready');
- socket.on('event:nodebb.ready', function(data) {
+ socket.on('event:nodebb.ready', function (data) {
if (!app.cacheBuster || app.cacheBuster !== data['cache-buster']) {
app.cacheBuster = data['cache-buster'];
@@ -64,7 +64,7 @@ app.cacheBuster = null;
alert_id: 'forum_updated',
title: '[[global:updated.title]]',
message: '[[global:updated.message]]',
- clickfn: function() {
+ clickfn: function () {
window.location.reload();
},
type: 'warning'
@@ -72,7 +72,7 @@ app.cacheBuster = null;
}
});
- require(['taskbar', 'helpers', 'forum/pagination'], function(taskbar, helpers, pagination) {
+ require(['taskbar', 'helpers', 'forum/pagination'], function (taskbar, helpers, pagination) {
taskbar.init();
// templates.js helpers
@@ -84,14 +84,14 @@ app.cacheBuster = null;
});
};
- app.logout = function() {
+ app.logout = function () {
$(window).trigger('action:app.logout');
$.ajax(config.relative_path + '/logout', {
type: 'POST',
headers: {
'x-csrf-token': config.csrf_token
},
- success: function() {
+ success: function () {
var payload = {
next: config.relative_path + '/'
};
@@ -103,13 +103,13 @@ app.cacheBuster = null;
};
app.alert = function (params) {
- require(['alerts'], function(alerts) {
+ require(['alerts'], function (alerts) {
alerts.alert(params);
});
};
- app.removeAlert = function(id) {
- require(['alerts'], function(alerts) {
+ app.removeAlert = function (id) {
+ require(['alerts'], function (alerts) {
alerts.remove(id);
});
};
@@ -136,7 +136,7 @@ app.cacheBuster = null;
});
};
- app.handleInvalidSession = function() {
+ app.handleInvalidSession = function () {
if (app.flags && app.flags._sessionRefresh) {
return;
}
@@ -144,13 +144,13 @@ app.cacheBuster = null;
app.flags = app.flags || {};
app.flags._sessionRefresh = true;
- require(['translator'], function(translator) {
- translator.translate('[[error:invalid-session-text]]', function(translated) {
+ require(['translator'], function (translator) {
+ translator.translate('[[error:invalid-session-text]]', function (translated) {
bootbox.alert({
title: '[[error:invalid-session]]',
message: translated,
closeButton: false,
- callback: function() {
+ callback: function () {
window.location.reload();
}
});
@@ -159,13 +159,13 @@ app.cacheBuster = null;
};
app.enterRoom = function (room, callback) {
- callback = callback || function() {};
+ callback = callback || function () {};
if (socket && app.user.uid && app.currentRoom !== room) {
var previousRoom = app.currentRoom;
app.currentRoom = room;
socket.emit('meta.rooms.enter', {
enter: room
- }, function(err) {
+ }, function (err) {
if (err) {
app.currentRoom = previousRoom;
return app.alertError(err.message);
@@ -176,11 +176,11 @@ app.cacheBuster = null;
}
};
- app.leaveCurrentRoom = function() {
+ app.leaveCurrentRoom = function () {
if (!socket) {
return;
}
- socket.emit('meta.rooms.leaveCurrent', function(err) {
+ socket.emit('meta.rooms.leaveCurrent', function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -196,9 +196,9 @@ app.cacheBuster = null;
}
}
- app.createUserTooltips = function(els, placement) {
+ app.createUserTooltips = function (els, placement) {
els = els || $('body');
- els.find('.avatar,img[title].teaser-pic,img[title].user-img,div.user-icon,span.user-icon').each(function() {
+ els.find('.avatar,img[title].teaser-pic,img[title].user-img,div.user-icon,span.user-icon').each(function () {
if (!utils.isTouchDevice()) {
$(this).tooltip({
placement: placement || $(this).attr('title-placement') || 'top',
@@ -208,7 +208,7 @@ app.cacheBuster = null;
});
};
- app.createStatusTooltips = function() {
+ app.createStatusTooltips = function () {
if (!utils.isTouchDevice()) {
$('body').tooltip({
selector:'.fa-circle.status',
@@ -217,9 +217,9 @@ app.cacheBuster = null;
}
};
- app.replaceSelfLinks = function(selector) {
+ app.replaceSelfLinks = function (selector) {
selector = selector || $('a');
- selector.each(function() {
+ selector.each(function () {
var href = $(this).attr('href');
if (href && app.user.userslug && href.indexOf('user/_self_') !== -1) {
$(this).attr('href', href.replace(/user\/_self_/g, 'user/' + app.user.userslug));
@@ -281,11 +281,11 @@ app.cacheBuster = null;
if (chat.modalExists(roomId)) {
loadAndCenter(chat.getModal(roomId));
} else {
- socket.emit('modules.chats.loadRoom', {roomId: roomId, uid: uid || app.user.uid}, function(err, roomData) {
+ socket.emit('modules.chats.loadRoom', {roomId: roomId, uid: uid || app.user.uid}, function (err, roomData) {
if (err) {
return app.alertError(err.message);
}
- roomData.users = roomData.users.filter(function(user) {
+ roomData.users = roomData.users.filter(function (user) {
return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10);
});
roomData.uid = uid || app.user.uid;
@@ -296,12 +296,12 @@ app.cacheBuster = null;
};
app.newChat = function (touid, callback) {
- callback = callback || function() {};
+ callback = callback || function () {};
if (!app.user.uid) {
return app.alertError('[[error:not-logged-in]]');
}
- socket.emit('modules.chats.newRoom', {touid: touid}, function(err, roomId) {
+ socket.emit('modules.chats.newRoom', {touid: touid}, function (err, roomId) {
if (err) {
return app.alertError(err.message);
}
@@ -332,14 +332,14 @@ app.cacheBuster = null;
titleObj.titles[0] = window.document.title;
}
- require(['translator'], function(translator) {
- translator.translate(title, function(translated) {
+ require(['translator'], function (translator) {
+ translator.translate(title, function (translated) {
titleObj.titles[1] = translated;
if (titleObj.interval) {
clearInterval(titleObj.interval);
}
- titleObj.interval = setInterval(function() {
+ titleObj.interval = setInterval(function () {
var title = titleObj.titles[titleObj.titles.indexOf(window.document.title) ^ 1];
if (title) {
window.document.title = $('
').html(title).text();
@@ -357,23 +357,23 @@ app.cacheBuster = null;
}
};
- app.refreshTitle = function(title) {
+ app.refreshTitle = function (title) {
if (!title) {
return;
}
- require(['translator'], function(translator) {
+ require(['translator'], function (translator) {
title = config.titleLayout.replace(/{/g, '{').replace(/}/g, '}')
- .replace('{pageTitle}', function() { return title; })
- .replace('{browserTitle}', function() { return config.browserTitle; });
+ .replace('{pageTitle}', function () { return title; })
+ .replace('{browserTitle}', function () { return config.browserTitle; });
- translator.translate(title, function(translated) {
+ translator.translate(title, function (translated) {
titleObj.titles[0] = translated;
app.alternatingTitle('');
});
});
};
- app.toggleNavbar = function(state) {
+ app.toggleNavbar = function (state) {
var navbarEl = $('.navbar');
if (navbarEl) {
navbarEl.toggleClass('hidden', !!!state);
@@ -385,7 +385,7 @@ app.cacheBuster = null;
if (env === 'xs' || env === 'sm') {
return;
}
- $('#header-menu li a[title]').each(function() {
+ $('#header-menu li a[title]').each(function () {
if (!utils.isTouchDevice()) {
$(this).tooltip({
placement: 'bottom',
@@ -417,7 +417,7 @@ app.cacheBuster = null;
searchFields = $("#search-fields"),
searchInput = $('#search-fields input');
- $('#search-form .advanced-search-link').on('mousedown', function() {
+ $('#search-form .advanced-search-link').on('mousedown', function () {
ajaxify.go('/search');
});
@@ -429,7 +429,7 @@ app.cacheBuster = null;
searchButton.removeClass('hidden');
}
- searchButton.on('click', function(e) {
+ searchButton.on('click', function (e) {
if (!config.loggedIn && !config.allowGuestSearching) {
app.alert({
message:'[[error:search-requires-login]]',
@@ -446,10 +446,10 @@ app.cacheBuster = null;
$('#search-form').on('submit', function () {
var input = $(this).find('input');
- require(['search'], function(search) {
+ require(['search'], function (search) {
var data = search.getSearchPreferences();
data.term = input.val();
- search.query(data, function() {
+ search.query(data, function () {
input.val('');
});
});
@@ -457,16 +457,16 @@ app.cacheBuster = null;
});
};
- app.prepareSearch = function() {
+ app.prepareSearch = function () {
$("#search-fields").removeClass('hidden');
$("#search-button").addClass('hidden');
$('#search-fields input').focus();
};
function handleStatusChange() {
- $('[component="header/usercontrol"] [data-status]').off('click').on('click', function(e) {
+ $('[component="header/usercontrol"] [data-status]').off('click').on('click', function (e) {
var status = $(this).attr('data-status');
- socket.emit('user.setStatus', status, function(err) {
+ socket.emit('user.setStatus', status, function (err) {
if(err) {
return app.alertError(err.message);
}
@@ -480,13 +480,13 @@ app.cacheBuster = null;
});
}
- app.updateUserStatus = function(el, status) {
+ app.updateUserStatus = function (el, status) {
if (!el.length) {
return;
}
- require(['translator'], function(translator) {
- translator.translate('[[global:' + status + ']]', function(translated) {
+ require(['translator'], function (translator) {
+ translator.translate('[[global:' + status + ']]', function (translated) {
el.removeClass('online offline dnd away')
.addClass(status)
.attr('title', translated)
@@ -502,7 +502,7 @@ app.cacheBuster = null;
});
};
- app.loadJQueryUI = function(callback) {
+ app.loadJQueryUI = function (callback) {
if (typeof $().autocomplete === 'function') {
return callback();
}
@@ -514,7 +514,7 @@ app.cacheBuster = null;
document.head.appendChild(scriptEl);
};
- app.showEmailConfirmWarning = function(err) {
+ app.showEmailConfirmWarning = function (err) {
if (!config.requireEmailConfirmation || !app.user.uid) {
return;
}
@@ -526,16 +526,16 @@ app.cacheBuster = null;
if (!app.user.email) {
msg.message = '[[error:no-email-to-confirm]]';
- msg.clickfn = function() {
+ msg.clickfn = function () {
app.removeAlert('email_confirm');
ajaxify.go('user/' + app.user.userslug + '/edit');
};
app.alert(msg);
} else if (!app.user['email:confirmed'] && !app.user.isEmailConfirmSent) {
msg.message = err ? err.message : '[[error:email-not-confirmed]]';
- msg.clickfn = function() {
+ msg.clickfn = function () {
app.removeAlert('email_confirm');
- socket.emit('user.emailConfirm', {}, function(err) {
+ socket.emit('user.emailConfirm', {}, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -550,30 +550,30 @@ app.cacheBuster = null;
}
};
- app.parseAndTranslate = function(template, blockName, data, callback) {
- require(['translator'], function(translator) {
+ app.parseAndTranslate = function (template, blockName, data, callback) {
+ require(['translator'], function (translator) {
function translate(html, callback) {
- translator.translate(html, function(translatedHTML) {
+ translator.translate(html, function (translatedHTML) {
translatedHTML = translator.unescape(translatedHTML);
callback($(translatedHTML));
});
}
if (typeof blockName === 'string') {
- templates.parse(template, blockName, data, function(html) {
+ templates.parse(template, blockName, data, function (html) {
translate(html, callback);
});
} else {
callback = data;
data = blockName;
- templates.parse(template, data, function(html) {
+ templates.parse(template, data, function (html) {
translate(html, callback);
});
}
});
};
- app.loadProgressiveStylesheet = function() {
+ app.loadProgressiveStylesheet = function () {
var linkEl = document.createElement('link');
linkEl.rel = 'stylesheet';
linkEl.href = config.relative_path + '/js-enabled.css';
diff --git a/public/src/client/account/best.js b/public/src/client/account/best.js
index 27384f9638..abc88620bf 100644
--- a/public/src/client/account/best.js
+++ b/public/src/client/account/best.js
@@ -2,10 +2,10 @@
/* globals define */
-define('forum/account/best', ['forum/account/header', 'forum/account/posts'], function(header, posts) {
+define('forum/account/best', ['forum/account/header', 'forum/account/posts'], function (header, posts) {
var Best = {};
- Best.init = function() {
+ Best.init = function () {
header.init();
$('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
diff --git a/public/src/client/account/bookmarks.js b/public/src/client/account/bookmarks.js
index d1aca2080e..3f9b848b75 100644
--- a/public/src/client/account/bookmarks.js
+++ b/public/src/client/account/bookmarks.js
@@ -2,10 +2,10 @@
/* globals define */
-define('forum/account/bookmarks', ['forum/account/header', 'forum/account/posts'], function(header, posts) {
+define('forum/account/bookmarks', ['forum/account/header', 'forum/account/posts'], function (header, posts) {
var Bookmarks = {};
- Bookmarks.init = function() {
+ Bookmarks.init = function () {
header.init();
$('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
diff --git a/public/src/client/account/downvoted.js b/public/src/client/account/downvoted.js
index 1a3758e215..b84e5da6bf 100644
--- a/public/src/client/account/downvoted.js
+++ b/public/src/client/account/downvoted.js
@@ -2,10 +2,10 @@
/* globals define */
-define('forum/account/downvoted', ['forum/account/header', 'forum/account/posts'], function(header, posts) {
+define('forum/account/downvoted', ['forum/account/header', 'forum/account/posts'], function (header, posts) {
var Downvoted = {};
- Downvoted.init = function() {
+ Downvoted.init = function () {
header.init();
$('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
diff --git a/public/src/client/account/edit.js b/public/src/client/account/edit.js
index 51632481cb..915e2b5079 100644
--- a/public/src/client/account/edit.js
+++ b/public/src/client/account/edit.js
@@ -2,16 +2,16 @@
/* globals define, ajaxify, socket, app, config, templates, bootbox */
-define('forum/account/edit', ['forum/account/header', 'uploader', 'translator', 'components'], function(header, uploader, translator, components) {
+define('forum/account/edit', ['forum/account/header', 'uploader', 'translator', 'components'], function (header, uploader, translator, components) {
var AccountEdit = {};
- AccountEdit.init = function() {
+ AccountEdit.init = function () {
header.init();
$('#submitBtn').on('click', updateProfile);
- app.loadJQueryUI(function() {
+ app.loadJQueryUI(function () {
$('#inputBirthday').datepicker({
changeMonth: true,
changeYear: true,
@@ -39,7 +39,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
aboutme: $('#inputAboutMe').val()
};
- socket.emit('user.updateProfile', userData, function(err, data) {
+ socket.emit('user.updateProfile', userData, function (err, data) {
if (err) {
return app.alertError(err.message);
}
@@ -70,14 +70,14 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
function handleImageChange() {
- $('#changePictureBtn').on('click', function() {
- socket.emit('user.getProfilePictures', {uid: ajaxify.data.uid}, function(err, pictures) {
+ $('#changePictureBtn').on('click', function () {
+ socket.emit('user.getProfilePictures', {uid: ajaxify.data.uid}, function (err, pictures) {
if (err) {
return app.alertError(err.message);
}
// boolean to signify whether an uploaded picture is present in the pictures list
- var uploaded = pictures.reduce(function(memo, cur) {
+ var uploaded = pictures.reduce(function (memo, cur) {
return memo || cur.type === 'uploaded';
}, false);
@@ -85,8 +85,8 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
pictures: pictures,
uploaded: uploaded,
allowProfileImageUploads: ajaxify.data.allowProfileImageUploads
- }, function(html) {
- translator.translate(html, function(html) {
+ }, function (html) {
+ translator.translate(html, function (html) {
var modal = bootbox.dialog({
className: 'picture-switcher',
title: '[[user:change_picture]]',
@@ -124,7 +124,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
if (!ajaxify.data.picture) {
modal.find('.list-group-item .user-icon').parents('.list-group-item').addClass('active');
} else {
- modal.find('.list-group-item img').each(function() {
+ modal.find('.list-group-item img').each(function () {
if (this.getAttribute('src') === ajaxify.data.picture) {
$(this).parents('.list-group-item').addClass('active');
}
@@ -135,7 +135,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
function saveSelection() {
var type = modal.find('.list-group-item.active').attr('data-type');
- changeUserPicture(type, function(err) {
+ changeUserPicture(type, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -157,9 +157,9 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
}
function handleAccountDelete() {
- $('#deleteAccountBtn').on('click', function() {
- translator.translate('[[user:delete_account_confirm]]', function(translated) {
- var modal = bootbox.confirm(translated + '
', function(confirm) {
+ $('#deleteAccountBtn').on('click', function () {
+ translator.translate('[[user:delete_account_confirm]]', function (translated) {
+ var modal = bootbox.confirm(translated + '
', function (confirm) {
if (!confirm) {
return;
}
@@ -168,7 +168,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
app.alertError('[[error:invalid-username]]');
return false;
} else {
- socket.emit('user.deleteAccount', {}, function(err) {
+ socket.emit('user.deleteAccount', {}, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -178,7 +178,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
}
});
- modal.on('shown.bs.modal', function() {
+ modal.on('shown.bs.modal', function () {
modal.find('input').focus();
});
});
@@ -196,7 +196,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
$('#user-current-picture, img.avatar').attr('src', urlOnServer);
ajaxify.data.uploadedpicture = urlOnServer;
} else {
- ajaxify.refresh(function() {
+ ajaxify.refresh(function () {
$('#user-current-picture, img.avatar').attr('src', urlOnServer);
});
}
@@ -209,7 +209,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
}
}
- modal.find('[data-action="upload"]').on('click', function() {
+ modal.find('[data-action="upload"]').on('click', function () {
modal.modal('hide');
uploader.show({
@@ -219,26 +219,26 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
title: '[[user:upload_picture]]',
description: '[[user:upload_a_picture]]',
accept: '.png,.jpg,.bmp'
- }, function(imageUrlOnServer) {
+ }, function (imageUrlOnServer) {
onUploadComplete(imageUrlOnServer);
});
return false;
});
- modal.find('[data-action="upload-url"]').on('click', function() {
+ modal.find('[data-action="upload-url"]').on('click', function () {
modal.modal('hide');
- templates.parse('partials/modals/upload_picture_from_url_modal', {}, function(html) {
- translator.translate(html, function(html) {
+ templates.parse('partials/modals/upload_picture_from_url_modal', {}, function (html) {
+ translator.translate(html, function (html) {
var uploadModal = $(html);
uploadModal.modal('show');
- uploadModal.find('.upload-btn').on('click', function() {
+ uploadModal.find('.upload-btn').on('click', function () {
var url = uploadModal.find('#uploadFromUrl').val();
if (!url) {
return;
}
- socket.emit('user.uploadProfileImageFromUrl', {url: url, uid: ajaxify.data.theirid}, function(err, imageUrlOnServer) {
+ socket.emit('user.uploadProfileImageFromUrl', {url: url, uid: ajaxify.data.theirid}, function (err, imageUrlOnServer) {
if (err) {
return app.alertError(err.message);
}
@@ -255,8 +255,8 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
return false;
});
- modal.find('[data-action="remove-uploaded"]').on('click', function() {
- socket.emit('user.removeUploadedPicture', {uid: ajaxify.data.theirid}, function(err) {
+ modal.find('[data-action="remove-uploaded"]').on('click', function () {
+ socket.emit('user.removeUploadedPicture', {uid: ajaxify.data.theirid}, function (err) {
modal.modal('hide');
if (err) {
return app.alertError(err.message);
@@ -267,9 +267,9 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
}
function handleEmailConfirm() {
- $('#confirm-email').on('click', function() {
+ $('#confirm-email').on('click', function () {
var btn = $(this).attr('disabled', true);
- socket.emit('user.emailConfirm', {}, function(err) {
+ socket.emit('user.emailConfirm', {}, function (err) {
btn.removeAttr('disabled');
if (err) {
return app.alertError(err.message);
@@ -294,7 +294,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
var el = $('#inputSignature');
$('#signatureCharCountLeft').html(getCharsLeft(el, ajaxify.data.maximumSignatureLength));
- el.on('keyup change', function() {
+ el.on('keyup change', function () {
$('#signatureCharCountLeft').html(getCharsLeft(el, ajaxify.data.maximumSignatureLength));
});
}
@@ -303,7 +303,7 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator',
var el = $('#inputAboutMe');
$('#aboutMeCharCountLeft').html(getCharsLeft(el, ajaxify.data.maximumAboutMeLength));
- el.on('keyup change', function() {
+ el.on('keyup change', function () {
$('#aboutMeCharCountLeft').html(getCharsLeft(el, ajaxify.data.maximumAboutMeLength));
});
}
diff --git a/public/src/client/account/edit/email.js b/public/src/client/account/edit/email.js
index 1772f76c49..df998bead0 100644
--- a/public/src/client/account/edit/email.js
+++ b/public/src/client/account/edit/email.js
@@ -2,10 +2,10 @@
/* globals define, ajaxify, socket, app */
-define('forum/account/edit/email', ['forum/account/header'], function(header) {
+define('forum/account/edit/email', ['forum/account/header'], function (header) {
var AccountEditEmail = {};
- AccountEditEmail.init = function() {
+ AccountEditEmail.init = function () {
header.init();
$('#submitBtn').on('click', function () {
@@ -26,7 +26,7 @@ define('forum/account/edit/email', ['forum/account/header'], function(header) {
var btn = $(this);
btn.addClass('disabled').find('i').removeClass('hide');
- socket.emit('user.changeUsernameEmail', userData, function(err) {
+ socket.emit('user.changeUsernameEmail', userData, function (err) {
btn.removeClass('disabled').find('i').addClass('hide');
if (err) {
return app.alertError(err.message);
diff --git a/public/src/client/account/edit/password.js b/public/src/client/account/edit/password.js
index cadf12c146..a123959804 100644
--- a/public/src/client/account/edit/password.js
+++ b/public/src/client/account/edit/password.js
@@ -2,10 +2,10 @@
/* globals define, ajaxify, socket, app, utils */
-define('forum/account/edit/password', ['forum/account/header', 'translator'], function(header, translator) {
+define('forum/account/edit/password', ['forum/account/header', 'translator'], function (header, translator) {
var AccountEditPassword = {};
- AccountEditPassword.init = function() {
+ AccountEditPassword.init = function () {
header.init();
handlePasswordChange();
@@ -56,7 +56,7 @@ define('forum/account/edit/password', ['forum/account/header', 'translator'], fu
password.on('blur', onPasswordChanged);
password_confirm.on('blur', onPasswordConfirmChanged);
- $('#changePasswordBtn').on('click', function() {
+ $('#changePasswordBtn').on('click', function () {
onPasswordChanged();
onPasswordConfirmChanged();
@@ -67,7 +67,7 @@ define('forum/account/edit/password', ['forum/account/header', 'translator'], fu
'currentPassword': currentPassword.val(),
'newPassword': password.val(),
'uid': ajaxify.data.theirid
- }, function(err) {
+ }, function (err) {
btn.removeClass('disabled').find('i').addClass('hide');
currentPassword.val('');
password.val('');
@@ -97,7 +97,7 @@ define('forum/account/edit/password', ['forum/account/header', 'translator'], fu
}
function showError(element, msg) {
- translator.translate(msg, function(msg) {
+ translator.translate(msg, function (msg) {
element.html(msg);
element.parent()
diff --git a/public/src/client/account/edit/username.js b/public/src/client/account/edit/username.js
index 64f9baa0bc..cb924a3f53 100644
--- a/public/src/client/account/edit/username.js
+++ b/public/src/client/account/edit/username.js
@@ -2,10 +2,10 @@
/* globals define, ajaxify, socket, app, utils, config */
-define('forum/account/edit/username', ['forum/account/header'], function(header) {
+define('forum/account/edit/username', ['forum/account/header'], function (header) {
var AccountEditUsername = {};
- AccountEditUsername.init = function() {
+ AccountEditUsername.init = function () {
header.init();
$('#submitBtn').on('click', function updateUsername() {
@@ -25,7 +25,7 @@ define('forum/account/edit/username', ['forum/account/header'], function(header)
var btn = $(this);
btn.addClass('disabled').find('i').removeClass('hide');
- socket.emit('user.changeUsernameEmail', userData, function(err, data) {
+ socket.emit('user.changeUsernameEmail', userData, function (err, data) {
btn.removeClass('disabled').find('i').addClass('hide');
if (err) {
return app.alertError(err.message);
diff --git a/public/src/client/account/followers.js b/public/src/client/account/followers.js
index 8a2d15f0b0..22970327fb 100644
--- a/public/src/client/account/followers.js
+++ b/public/src/client/account/followers.js
@@ -2,10 +2,10 @@
/* globals define */
-define('forum/account/followers', ['forum/account/header'], function(header) {
+define('forum/account/followers', ['forum/account/header'], function (header) {
var Followers = {};
- Followers.init = function() {
+ Followers.init = function () {
header.init();
};
diff --git a/public/src/client/account/following.js b/public/src/client/account/following.js
index 04230fb979..dff2f92709 100644
--- a/public/src/client/account/following.js
+++ b/public/src/client/account/following.js
@@ -2,10 +2,10 @@
/* globals define */
-define('forum/account/following', ['forum/account/header'], function(header) {
+define('forum/account/following', ['forum/account/header'], function (header) {
var Following = {};
- Following.init = function() {
+ Following.init = function () {
header.init();
};
diff --git a/public/src/client/account/groups.js b/public/src/client/account/groups.js
index e4c932161d..f8fe55fdd9 100644
--- a/public/src/client/account/groups.js
+++ b/public/src/client/account/groups.js
@@ -2,15 +2,15 @@
/* globals ajaxify, define, app, socket, utils */
-define('forum/account/groups', ['forum/account/header'], function(header) {
+define('forum/account/groups', ['forum/account/header'], function (header) {
var AccountTopics = {};
- AccountTopics.init = function() {
+ AccountTopics.init = function () {
header.init();
var groupsEl = $('#groups-list');
- groupsEl.on('click', '.list-cover', function() {
+ groupsEl.on('click', '.list-cover', function () {
var groupSlug = $(this).parents('[data-slug]').attr('data-slug');
ajaxify.go('groups/' + groupSlug);
diff --git a/public/src/client/account/header.js b/public/src/client/account/header.js
index 0c65653e0f..d29b58c05b 100644
--- a/public/src/client/account/header.js
+++ b/public/src/client/account/header.js
@@ -6,11 +6,11 @@ define('forum/account/header', [
'uploader',
'components',
'translator'
-], function(coverPhoto, uploader, components, translator) {
+], function (coverPhoto, uploader, components, translator) {
var AccountHeader = {};
var isAdminOrSelfOrGlobalMod;
- AccountHeader.init = function() {
+ AccountHeader.init = function () {
isAdminOrSelfOrGlobalMod = ajaxify.data.isAdmin || ajaxify.data.isSelf || ajaxify.data.isGlobalModerator;
hidePrivateLinks();
@@ -20,16 +20,16 @@ define('forum/account/header', [
setupCoverPhoto();
}
- components.get('account/follow').on('click', function() {
+ components.get('account/follow').on('click', function () {
toggleFollow('follow');
});
- components.get('account/unfollow').on('click', function() {
+ components.get('account/unfollow').on('click', function () {
toggleFollow('unfollow');
});
- components.get('account/chat').on('click', function() {
- socket.emit('modules.chats.hasPrivateChat', ajaxify.data.uid, function(err, roomId) {
+ components.get('account/chat').on('click', function () {
+ socket.emit('modules.chats.hasPrivateChat', ajaxify.data.uid, function (err, roomId) {
if (err) {
return app.alertError(err.message);
}
@@ -53,7 +53,7 @@ define('forum/account/header', [
}
function selectActivePill() {
- $('.account-sub-links li').removeClass('active').each(function() {
+ $('.account-sub-links li').removeClass('active').each(function () {
var href = $(this).find('a').attr('href');
if (decodeURIComponent(href) === decodeURIComponent(window.location.pathname)) {
@@ -65,20 +65,20 @@ define('forum/account/header', [
function setupCoverPhoto() {
coverPhoto.init(components.get('account/cover'),
- function(imageData, position, callback) {
+ function (imageData, position, callback) {
socket.emit('user.updateCover', {
uid: ajaxify.data.uid,
imageData: imageData,
position: position
}, callback);
},
- function() {
+ function () {
uploader.show({
title: '[[user:upload_cover_picture]]',
route: config.relative_path + '/api/user/' + ajaxify.data.userslug + '/uploadcover',
params: {uid: ajaxify.data.uid },
accept: '.png,.jpg,.bmp'
- }, function(imageUrlOnServer) {
+ }, function (imageUrlOnServer) {
components.get('account/cover').css('background-image', 'url(' + imageUrlOnServer + '?v=' + Date.now() + ')');
});
},
@@ -89,7 +89,7 @@ define('forum/account/header', [
function toggleFollow(type) {
socket.emit('user.' + type, {
uid: ajaxify.data.uid
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -102,7 +102,7 @@ define('forum/account/header', [
}
function banAccount() {
- templates.parse('admin/partials/temporary-ban', {}, function(html) {
+ templates.parse('admin/partials/temporary-ban', {}, function (html) {
bootbox.dialog({
className: 'ban-modal',
title: '[[user:ban_account]]',
@@ -115,14 +115,14 @@ define('forum/account/header', [
},
submit: {
label: '[[user:ban_account]]',
- callback: function() {
- var formData = $('.ban-modal form').serializeArray().reduce(function(data, cur) {
+ callback: function () {
+ var formData = $('.ban-modal form').serializeArray().reduce(function (data, cur) {
data[cur.name] = cur.value;
return data;
}, {});
- var until = formData.length ? (Date.now() + formData.length * 1000*60*60 * (parseInt(formData.unit, 10) ? 24 : 1)) : 0;
+ var until = formData.length ? (Date.now() + formData.length * 1000 * 60 * 60 * (parseInt(formData.unit, 10) ? 24 : 1)) : 0;
- socket.emit('user.banUsers', { uids: [ajaxify.data.theirid], until: until, reason: formData.reason || '' }, function(err) {
+ socket.emit('user.banUsers', { uids: [ajaxify.data.theirid], until: until, reason: formData.reason || '' }, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -136,7 +136,7 @@ define('forum/account/header', [
}
function unbanAccount() {
- socket.emit('user.unbanUsers', [ajaxify.data.theirid], function(err) {
+ socket.emit('user.unbanUsers', [ajaxify.data.theirid], function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -145,13 +145,13 @@ define('forum/account/header', [
}
function deleteAccount() {
- translator.translate('[[user:delete_this_account_confirm]]', function(translated) {
- bootbox.confirm(translated, function(confirm) {
+ translator.translate('[[user:delete_this_account_confirm]]', function (translated) {
+ bootbox.confirm(translated, function (confirm) {
if (!confirm) {
return;
}
- socket.emit('admin.user.deleteUsersAndContent', [ajaxify.data.theirid], function(err) {
+ socket.emit('admin.user.deleteUsersAndContent', [ajaxify.data.theirid], function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -165,7 +165,7 @@ define('forum/account/header', [
function removeCover() {
socket.emit('user.removeCover', {
uid: ajaxify.data.uid
- }, function(err) {
+ }, function (err) {
if (!err) {
ajaxify.refresh();
} else {
diff --git a/public/src/client/account/info.js b/public/src/client/account/info.js
index 3e1a218827..4ee76b21a3 100644
--- a/public/src/client/account/info.js
+++ b/public/src/client/account/info.js
@@ -2,18 +2,18 @@
/* globals define, socket, ajaxify, app */
-define('forum/account/info', ['forum/account/header'], function(header) {
+define('forum/account/info', ['forum/account/header'], function (header) {
var Info = {};
- Info.init = function() {
+ Info.init = function () {
header.init();
handleModerationNote();
};
function handleModerationNote() {
- $('[component="account/save-moderation-note"]').on('click', function() {
+ $('[component="account/save-moderation-note"]').on('click', function () {
var note = $('[component="account/moderation-note"]').val();
- socket.emit('user.setModerationNote', {uid: ajaxify.data.uid, note: note}, function(err) {
+ socket.emit('user.setModerationNote', {uid: ajaxify.data.uid, note: note}, function (err) {
if (err) {
return app.alertError(err.message);
}
diff --git a/public/src/client/account/posts.js b/public/src/client/account/posts.js
index 35e60e890b..9e2082e211 100644
--- a/public/src/client/account/posts.js
+++ b/public/src/client/account/posts.js
@@ -2,11 +2,11 @@
/* globals define, app, socket, utils, config, ajaxify */
-define('forum/account/posts', ['forum/account/header', 'forum/infinitescroll'], function(header, infinitescroll) {
+define('forum/account/posts', ['forum/account/header', 'forum/infinitescroll'], function (header, infinitescroll) {
var AccountPosts = {};
var method, template;
- AccountPosts.init = function() {
+ AccountPosts.init = function () {
header.init();
$('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
@@ -14,7 +14,7 @@ define('forum/account/posts', ['forum/account/header', 'forum/infinitescroll'],
AccountPosts.handleInfiniteScroll('posts.loadMoreUserPosts', 'account/posts');
};
- AccountPosts.handleInfiniteScroll = function(_method, _template) {
+ AccountPosts.handleInfiniteScroll = function (_method, _template) {
method = _method;
template = _template;
if (!config.usePagination) {
@@ -30,7 +30,7 @@ define('forum/account/posts', ['forum/account/header', 'forum/infinitescroll'],
infinitescroll.loadMore(method, {
uid: ajaxify.data.theirid,
after: $('[component="posts"]').attr('data-nextstart')
- }, function(data, done) {
+ }, function (data, done) {
if (data.posts && data.posts.length) {
onPostsLoaded(data.posts, done);
} else {
@@ -41,7 +41,7 @@ define('forum/account/posts', ['forum/account/header', 'forum/infinitescroll'],
}
function onPostsLoaded(posts, callback) {
- app.parseAndTranslate(template, 'posts', {posts: posts}, function(html) {
+ app.parseAndTranslate(template, 'posts', {posts: posts}, function (html) {
$('[component="posts"]').append(html);
html.find('img:not(.not-responsive)').addClass('img-responsive');
html.find('.timeago').timeago();
diff --git a/public/src/client/account/profile.js b/public/src/client/account/profile.js
index 0d59a96df1..f1d41db46f 100644
--- a/public/src/client/account/profile.js
+++ b/public/src/client/account/profile.js
@@ -7,11 +7,11 @@ define('forum/account/profile', [
'forum/infinitescroll',
'translator',
'components'
-], function(header, infinitescroll, translator) {
+], function (header, infinitescroll, translator) {
var Account = {},
theirid;
- Account.init = function() {
+ Account.init = function () {
header.init();
theirid = ajaxify.data.theirid;
@@ -48,7 +48,7 @@ define('forum/account/profile', [
infinitescroll.loadMore('posts.loadMoreUserPosts', {
after: $('[component="posts"]').attr('data-nextstart'),
uid: theirid
- }, function(data, done) {
+ }, function (data, done) {
if (data.posts && data.posts.length) {
onPostsLoaded(data.posts, done);
} else {
@@ -60,7 +60,7 @@ define('forum/account/profile', [
}
function onPostsLoaded(posts, callback) {
- posts = posts.filter(function(post) {
+ posts = posts.filter(function (post) {
return !$('[component="posts"] [data-pid=' + post.pid + ']').length;
});
@@ -68,7 +68,7 @@ define('forum/account/profile', [
return callback();
}
- app.parseAndTranslate('account/profile', 'posts', {posts: posts}, function(html) {
+ app.parseAndTranslate('account/profile', 'posts', {posts: posts}, function (html) {
$('[component="posts"]').append(html);
html.find('.timeago').timeago();
diff --git a/public/src/client/account/settings.js b/public/src/client/account/settings.js
index cc9aaf0439..6410267795 100644
--- a/public/src/client/account/settings.js
+++ b/public/src/client/account/settings.js
@@ -2,19 +2,19 @@
/*global define, socket, app, ajaxify, config*/
-define('forum/account/settings', ['forum/account/header', 'components', 'sounds'], function(header, components, sounds) {
+define('forum/account/settings', ['forum/account/header', 'components', 'sounds'], function (header, components, sounds) {
var AccountSettings = {};
- AccountSettings.init = function() {
+ AccountSettings.init = function () {
header.init();
- $('#submitBtn').on('click', function() {
+ $('#submitBtn').on('click', function () {
var settings = loadSettings();
if (settings.homePageRoute === 'custom' && settings.homePageCustom) {
- $.get(config.relative_path + '/' + settings.homePageCustom, function() {
+ $.get(config.relative_path + '/' + settings.homePageCustom, function () {
saveSettings(settings);
- }).fail(function() {
+ }).fail(function () {
app.alertError('[[error:invalid-home-page-route]]');
});
} else {
@@ -24,7 +24,7 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds'
return false;
});
- $('#bootswatchSkin').on('change', function() {
+ $('#bootswatchSkin').on('change', function () {
var css = $('#bootswatchCSS');
var val = $(this).val() === 'default' ? config['theme:src'] : '//maxcdn.bootstrapcdn.com/bootswatch/latest/' + $(this).val() + '/bootstrap.min.css';
@@ -33,7 +33,7 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds'
$('[data-property="homePageRoute"]').on('change', toggleCustomRoute);
- $('.account').find('button[data-action="play"]').on('click', function(e) {
+ $('.account').find('button[data-action="play"]').on('click', function (e) {
e.preventDefault();
var fileName = $(this).parent().parent().find('select').val();
@@ -49,7 +49,7 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds'
function loadSettings() {
var settings = {};
- $('.account').find('input, textarea, select').each(function(id, input) {
+ $('.account').find('input, textarea, select').each(function (id, input) {
input = $(input);
var setting = input.attr('data-property');
if (input.is('select')) {
@@ -72,7 +72,7 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds'
}
function saveSettings(settings) {
- socket.emit('user.saveSettings', {uid: ajaxify.data.theirid, settings: settings}, function(err, newSettings) {
+ socket.emit('user.saveSettings', {uid: ajaxify.data.theirid, settings: settings}, function (err, newSettings) {
if (err) {
return app.alertError(err.message);
}
@@ -98,7 +98,7 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds'
message: '[[user:settings-require-reload]]',
type: 'warning',
timeout: 5000,
- clickfn: function() {
+ clickfn: function () {
ajaxify.refresh();
}
});
@@ -116,7 +116,7 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds'
}
function prepareSessionRevoking() {
- components.get('user/sessions').on('click', '[data-action]', function() {
+ components.get('user/sessions').on('click', '[data-action]', function () {
var parentEl = $(this).parents('[data-uuid]');
var uuid = parentEl.attr('data-uuid');
@@ -129,9 +129,9 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds'
headers: {
'x-csrf-token': config.csrf_token
}
- }).done(function() {
+ }).done(function () {
parentEl.remove();
- }).fail(function(err) {
+ }).fail(function (err) {
try {
var errorObj = JSON.parse(err.responseText);
if (errorObj.loggedIn === false) {
diff --git a/public/src/client/account/topics.js b/public/src/client/account/topics.js
index 1fefc727d1..63658f0cbf 100644
--- a/public/src/client/account/topics.js
+++ b/public/src/client/account/topics.js
@@ -2,17 +2,17 @@
/* globals define, app, socket, utils, config, ajaxify */
-define('forum/account/topics', ['forum/account/header', 'forum/infinitescroll'], function(header, infinitescroll) {
+define('forum/account/topics', ['forum/account/header', 'forum/infinitescroll'], function (header, infinitescroll) {
var AccountTopics = {};
var template, set;
- AccountTopics.init = function() {
+ AccountTopics.init = function () {
header.init();
AccountTopics.handleInfiniteScroll('account/topics', 'uid:' + ajaxify.data.theirid + ':topics');
};
- AccountTopics.handleInfiniteScroll = function(_template, _set) {
+ AccountTopics.handleInfiniteScroll = function (_template, _set) {
template = _template;
set = _set;
@@ -29,7 +29,7 @@ define('forum/account/topics', ['forum/account/header', 'forum/infinitescroll'],
infinitescroll.loadMore('topics.loadMoreFromSet', {
set: set,
after: $('[component="category"]').attr('data-nextstart')
- }, function(data, done) {
+ }, function (data, done) {
if (data.topics && data.topics.length) {
onTopicsLoaded(data.topics, done);
} else {
@@ -41,7 +41,7 @@ define('forum/account/topics', ['forum/account/header', 'forum/infinitescroll'],
}
function onTopicsLoaded(topics, callback) {
- app.parseAndTranslate('account/topics', 'topics', {topics: topics}, function(html) {
+ app.parseAndTranslate('account/topics', 'topics', {topics: topics}, function (html) {
$('[component="category"]').append(html);
html.find('.timeago').timeago();
app.createUserTooltips();
diff --git a/public/src/client/account/upvoted.js b/public/src/client/account/upvoted.js
index 1d0ef86294..76bf001b77 100644
--- a/public/src/client/account/upvoted.js
+++ b/public/src/client/account/upvoted.js
@@ -2,10 +2,10 @@
/* globals define */
-define('forum/account/upvoted', ['forum/account/header', 'forum/account/posts'], function(header, posts) {
+define('forum/account/upvoted', ['forum/account/header', 'forum/account/posts'], function (header, posts) {
var Upvoted = {};
- Upvoted.init = function() {
+ Upvoted.init = function () {
header.init();
$('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
diff --git a/public/src/client/account/watched.js b/public/src/client/account/watched.js
index dae195df2d..4e1ca01cfe 100644
--- a/public/src/client/account/watched.js
+++ b/public/src/client/account/watched.js
@@ -1,10 +1,10 @@
'use strict';
/* globals define, app, socket, utils */
-define('forum/account/watched', ['forum/account/header', 'forum/account/topics'], function(header, topics) {
+define('forum/account/watched', ['forum/account/header', 'forum/account/topics'], function (header, topics) {
var AccountWatched = {};
- AccountWatched.init = function() {
+ AccountWatched.init = function () {
header.init();
topics.handleInfiniteScroll('account/watched', 'uid:' + ajaxify.data.theirid + ':followed_tids');
diff --git a/public/src/client/categories.js b/public/src/client/categories.js
index a73ed617bb..672fa38cf9 100644
--- a/public/src/client/categories.js
+++ b/public/src/client/categories.js
@@ -2,16 +2,16 @@
/* globals define, socket, app, templates, ajaxify*/
-define('forum/categories', ['components', 'translator'], function(components, translator) {
+define('forum/categories', ['components', 'translator'], function (components, translator) {
var categories = {};
- $(window).on('action:ajaxify.start', function(ev, data) {
+ $(window).on('action:ajaxify.start', function (ev, data) {
if (ajaxify.currentPage !== data.url) {
socket.removeListener('event:new_post', categories.onNewPost);
}
});
- categories.init = function() {
+ categories.init = function () {
app.enterRoom('categories');
socket.removeListener('event:new_post', categories.onNewPost);
@@ -22,7 +22,7 @@ define('forum/categories', ['components', 'translator'], function(components, tr
});
};
- categories.onNewPost = function(data) {
+ categories.onNewPost = function (data) {
if (data && data.posts && data.posts.length && data.posts[0].topic) {
renderNewPost(data.posts[0].topic.cid, data.posts[0]);
}
@@ -38,7 +38,7 @@ define('forum/categories', ['components', 'translator'], function(components, tr
var recentPosts = category.find('[component="category/posts"]');
var insertBefore = recentPosts.first();
- parseAndTranslate([post], function(html) {
+ parseAndTranslate([post], function (html) {
html.hide();
if(recentPosts.length === 0) {
html.appendTo(category);
@@ -60,8 +60,8 @@ define('forum/categories', ['components', 'translator'], function(components, tr
}
function parseAndTranslate(posts, callback) {
- templates.parse('categories', '(categories.)?posts', {categories: {posts: posts}}, function(html) {
- translator.translate(html, function(translatedHTML) {
+ templates.parse('categories', '(categories.)?posts', {categories: {posts: posts}}, function (html) {
+ translator.translate(html, function (translatedHTML) {
translatedHTML = $(translatedHTML);
translatedHTML.find('img:not(.not-responsive)').addClass('img-responsive');
diff --git a/public/src/client/category.js b/public/src/client/category.js
index d0a6d37f2a..7f64fd4f7f 100644
--- a/public/src/client/category.js
+++ b/public/src/client/category.js
@@ -11,10 +11,10 @@ define('forum/category', [
'translator',
'topicSelect',
'forum/pagination'
-], function(infinitescroll, share, navigator, categoryTools, sort, components, translator, topicSelect, pagination) {
+], function (infinitescroll, share, navigator, categoryTools, sort, components, translator, topicSelect, pagination) {
var Category = {};
- $(window).on('action:ajaxify.start', function(ev, data) {
+ $(window).on('action:ajaxify.start', function (ev, data) {
if (ajaxify.currentPage !== data.url) {
navigator.disable();
@@ -27,7 +27,7 @@ define('forum/category', [
categoryTools.removeListeners();
}
- Category.init = function() {
+ Category.init = function () {
var cid = ajaxify.data.cid;
app.enterRoom('category_' + cid);
@@ -47,9 +47,9 @@ define('forum/category', [
enableInfiniteLoadingOrPagination();
- $('[component="category"]').on('click', '[component="topic/header"]', function() {
+ $('[component="category"]').on('click', '[component="topic/header"]', function () {
var clickedIndex = $(this).parents('[data-index]').attr('data-index');
- $('[component="category/topic"]').each(function(index, el) {
+ $('[component="category/topic"]').each(function (index, el) {
if ($(el).offset().top - $(window).scrollTop() > 0) {
localStorage.setItem('category:' + cid + ':bookmark', $(el).attr('data-index'));
localStorage.setItem('category:' + cid + ':bookmark:clicked', clickedIndex);
@@ -65,11 +65,11 @@ define('forum/category', [
};
function handleIgnoreWatch(cid) {
- $('[component="category/watching"], [component="category/ignoring"]').on('click', function() {
+ $('[component="category/watching"], [component="category/ignoring"]').on('click', function () {
var $this = $(this);
var command = $this.attr('component') === 'category/watching' ? 'watch' : 'ignore';
- socket.emit('categories.' + command, cid, function(err) {
+ socket.emit('categories.' + command, cid, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -85,12 +85,12 @@ define('forum/category', [
});
}
- Category.toTop = function() {
+ Category.toTop = function () {
navigator.scrollTop(0);
};
- Category.toBottom = function() {
- socket.emit('categories.getTopicCount', ajaxify.data.cid, function(err, count) {
+ Category.toBottom = function () {
+ socket.emit('categories.getTopicCount', ajaxify.data.cid, function (err, count) {
if (err) {
return app.alertError(err.message);
}
@@ -99,11 +99,11 @@ define('forum/category', [
});
};
- Category.navigatorCallback = function(topIndex, bottomIndex, elementCount) {
+ Category.navigatorCallback = function (topIndex, bottomIndex, elementCount) {
return bottomIndex;
};
- $(window).on('action:popstate', function(ev, data) {
+ $(window).on('action:popstate', function (ev, data) {
if (data.url.startsWith('category/')) {
var cid = data.url.match(/^category\/(\d+)/);
if (cid && cid[1]) {
@@ -125,7 +125,7 @@ define('forum/category', [
if (config.usePagination) {
var page = Math.ceil((parseInt(bookmarkIndex, 10) + 1) / config.topicsPerPage);
if (parseInt(page, 10) !== ajaxify.data.pagination.currentPage) {
- pagination.loadPage(page, function() {
+ pagination.loadPage(page, function () {
Category.scrollToTopic(bookmarkIndex, clickedIndex, 400);
});
} else {
@@ -139,25 +139,25 @@ define('forum/category', [
$('[component="category"]').empty();
- loadTopicsAfter(Math.max(0, bookmarkIndex - 1), 1, function() {
+ loadTopicsAfter(Math.max(0, bookmarkIndex - 1), 1, function () {
Category.scrollToTopic(bookmarkIndex, clickedIndex, 0);
});
}
}
});
- Category.highlightTopic = function(topicIndex) {
+ Category.highlightTopic = function (topicIndex) {
var highlight = components.get('category/topic', 'index', topicIndex);
if (highlight.length && !highlight.hasClass('highlight')) {
highlight.addClass('highlight');
- setTimeout(function() {
+ setTimeout(function () {
highlight.removeClass('highlight');
}, 5000);
}
};
- Category.scrollToTopic = function(bookmarkIndex, clickedIndex, duration, offset) {
+ Category.scrollToTopic = function (bookmarkIndex, clickedIndex, duration, offset) {
if (!bookmarkIndex) {
return;
}
@@ -172,7 +172,7 @@ define('forum/category', [
if (scrollTo.length && cid) {
$('html, body').animate({
scrollTop: (scrollTo.offset().top - offset) + 'px'
- }, duration !== undefined ? duration : 400, function() {
+ }, duration !== undefined ? duration : 400, function () {
Category.highlightTopic(clickedIndex);
navigator.update();
});
@@ -187,7 +187,7 @@ define('forum/category', [
}
}
- Category.onNewTopic = function(topic) {
+ Category.onNewTopic = function (topic) {
var cid = ajaxify.data.cid;
if (!topic || parseInt(topic.cid, 10) !== parseInt(cid, 10)) {
return;
@@ -202,8 +202,8 @@ define('forum/category', [
showSelect: editable,
topics: [topic],
template: {category: true}
- }, function(html) {
- translator.translate(html, function(translatedHTML) {
+ }, function (html) {
+ translator.translate(html, function (translatedHTML) {
var topic = $(translatedHTML),
container = $('[component="category"]'),
topics = $('[component="category/topic"]'),
@@ -246,7 +246,7 @@ define('forum/category', [
};
function updateTopicCount() {
- socket.emit('categories.getTopicCount', ajaxify.data.cid, function(err, topicCount) {
+ socket.emit('categories.getTopicCount', ajaxify.data.cid, function (err, topicCount) {
if(err) {
return app.alertError(err.message);
}
@@ -254,7 +254,7 @@ define('forum/category', [
});
}
- Category.loadMoreTopics = function(direction) {
+ Category.loadMoreTopics = function (direction) {
if (!$('[component="category"]').length || !$('[component="category"]').children().length) {
return;
}
@@ -267,7 +267,7 @@ define('forum/category', [
};
function loadTopicsAfter(after, direction, callback) {
- callback = callback || function() {};
+ callback = callback || function () {};
if (!utils.isNumber(after) || (after === 0 && components.get('category/topic', 'index', 0).length)) {
return callback();
}
@@ -294,13 +294,13 @@ define('forum/category', [
}
- Category.onTopicsLoaded = function(data, direction, callback) {
+ Category.onTopicsLoaded = function (data, direction, callback) {
if (!data || !data.topics.length) {
return callback();
}
function removeAlreadyAddedTopics(topics) {
- return topics.filter(function(topic) {
+ return topics.filter(function (topic) {
return components.get('category/topic', 'tid', topic.tid).length === 0;
});
}
@@ -321,7 +321,7 @@ define('forum/category', [
before = topics.first();
}
- app.parseAndTranslate('category', 'topics', data, function(html) {
+ app.parseAndTranslate('category', 'topics', data, function (html) {
$('[component="category"]').removeClass('hidden');
$('.category-sidebar').removeClass('hidden');
diff --git a/public/src/client/categoryTools.js b/public/src/client/categoryTools.js
index 8344ddf355..548386ffc6 100644
--- a/public/src/client/categoryTools.js
+++ b/public/src/client/categoryTools.js
@@ -4,31 +4,31 @@
/* globals define, app, socket, bootbox, ajaxify */
-define('forum/categoryTools', ['forum/topic/move', 'topicSelect', 'components', 'translator'], function(move, topicSelect, components, translator) {
+define('forum/categoryTools', ['forum/topic/move', 'topicSelect', 'components', 'translator'], function (move, topicSelect, components, translator) {
var CategoryTools = {};
- CategoryTools.init = function(cid) {
+ CategoryTools.init = function (cid) {
CategoryTools.cid = cid;
topicSelect.init(updateDropdownOptions);
- components.get('topic/delete').on('click', function() {
+ components.get('topic/delete').on('click', function () {
categoryCommand('delete', topicSelect.getSelectedTids());
return false;
});
- components.get('topic/restore').on('click', function() {
+ components.get('topic/restore').on('click', function () {
categoryCommand('restore', topicSelect.getSelectedTids());
return false;
});
- components.get('topic/purge').on('click', function() {
+ components.get('topic/purge').on('click', function () {
categoryCommand('purge', topicSelect.getSelectedTids());
return false;
});
- components.get('topic/lock').on('click', function() {
+ components.get('topic/lock').on('click', function () {
var tids = topicSelect.getSelectedTids();
if (tids.length) {
socket.emit('topics.lock', {tids: tids, cid: CategoryTools.cid}, onCommandComplete);
@@ -36,7 +36,7 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect', 'components',
return false;
});
- components.get('topic/unlock').on('click', function() {
+ components.get('topic/unlock').on('click', function () {
var tids = topicSelect.getSelectedTids();
if (tids.length) {
socket.emit('topics.unlock', {tids: tids, cid: CategoryTools.cid}, onCommandComplete);
@@ -44,7 +44,7 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect', 'components',
return false;
});
- components.get('topic/pin').on('click', function() {
+ components.get('topic/pin').on('click', function () {
var tids = topicSelect.getSelectedTids();
if (tids.length) {
socket.emit('topics.pin', {tids: tids, cid: CategoryTools.cid}, onCommandComplete);
@@ -52,7 +52,7 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect', 'components',
return false;
});
- components.get('topic/unpin').on('click', function() {
+ components.get('topic/unpin').on('click', function () {
var tids = topicSelect.getSelectedTids();
if (tids.length) {
socket.emit('topics.unpin', {tids: tids, cid: CategoryTools.cid}, onCommandComplete);
@@ -60,15 +60,15 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect', 'components',
return false;
});
- components.get('topic/mark-unread-for-all').on('click', function() {
+ components.get('topic/mark-unread-for-all').on('click', function () {
var tids = topicSelect.getSelectedTids();
if (tids.length) {
- socket.emit('topics.markAsUnreadForAll', tids, function(err) {
+ socket.emit('topics.markAsUnreadForAll', tids, function (err) {
if (err) {
return app.alertError(err.message);
}
app.alertSuccess('[[topic:markAsUnreadForAll.success]]');
- tids.forEach(function(tid) {
+ tids.forEach(function (tid) {
$('[component="category/topic"][data-tid="' + tid + '"]').addClass('unread');
});
onCommandComplete();
@@ -78,7 +78,7 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect', 'components',
return false;
});
- components.get('topic/move').on('click', function() {
+ components.get('topic/move').on('click', function () {
var tids = topicSelect.getSelectedTids();
if (tids.length) {
@@ -87,8 +87,8 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect', 'components',
return false;
});
- components.get('topic/move-all').on('click', function() {
- move.init(null, cid, function(err) {
+ components.get('topic/move-all').on('click', function () {
+ move.init(null, cid, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -113,8 +113,8 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect', 'components',
return;
}
- translator.translate('[[topic:thread_tools.' + command + '_confirm]]', function(msg) {
- bootbox.confirm(msg, function(confirm) {
+ translator.translate('[[topic:thread_tools.' + command + '_confirm]]', function (msg) {
+ bootbox.confirm(msg, function (confirm) {
if (!confirm) {
return;
}
@@ -124,7 +124,7 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect', 'components',
});
}
- CategoryTools.removeListeners = function() {
+ CategoryTools.removeListeners = function () {
socket.removeListener('event:topic_deleted', setDeleteState);
socket.removeListener('event:topic_restored', setDeleteState);
socket.removeListener('event:topic_purged', onTopicPurged);
@@ -175,7 +175,7 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect', 'components',
}
function isAny(method, tids) {
- for(var i=0; i ').html(user.username).text());
});
}
- tagEl.on('beforeItemAdd', function(event) {
+ tagEl.on('beforeItemAdd', function (event) {
event.cancel = event.item === app.user.username;
});
- tagEl.on('itemAdded', function(event) {
+ tagEl.on('itemAdded', function (event) {
if (event.item === app.user.username) {
return;
}
- socket.emit('modules.chats.addUserToRoom', {roomId: data.roomId, username: event.item}, function(err) {
+ socket.emit('modules.chats.addUserToRoom', {roomId: data.roomId, username: event.item}, function (err) {
if (err) {
app.alertError(err.message);
tagEl.tagsinput('remove', event.item, {nouser: true});
@@ -241,7 +241,7 @@ define('forum/chats', [
});
});
- tagEl.on('beforeItemRemove', function(event) {
+ tagEl.on('beforeItemRemove', function (event) {
if (event.options && event.options.nouser) {
return;
}
@@ -256,11 +256,11 @@ define('forum/chats', [
}
});
- tagEl.on('itemRemoved', function(event) {
+ tagEl.on('itemRemoved', function (event) {
if (event.options && event.options.nouser) {
return;
}
- socket.emit('modules.chats.removeUserFromRoom', {roomId: data.roomId, username: event.item}, function(err) {
+ socket.emit('modules.chats.removeUserFromRoom', {roomId: data.roomId, username: event.item}, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -269,14 +269,14 @@ define('forum/chats', [
var input = $('.users-tag-container').find('.bootstrap-tagsinput input');
- require(['autocomplete'], function(autocomplete) {
+ require(['autocomplete'], function (autocomplete) {
autocomplete.user(input);
});
};
- Chats.leave = function(el) {
+ Chats.leave = function (el) {
var roomId = el.attr('data-roomid');
- socket.emit('modules.chats.leave', roomId, function(err) {
+ socket.emit('modules.chats.leave', roomId, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -288,13 +288,13 @@ define('forum/chats', [
});
};
- Chats.switchChat = function(roomid) {
+ Chats.switchChat = function (roomid) {
ajaxify.go('user/' + ajaxify.data.userslug + '/chats/' + roomid);
};
- Chats.addGlobalEventListeners = function() {
+ Chats.addGlobalEventListeners = function () {
$(window).on('resize', Chats.resizeMainWindow);
- $(window).on('mousemove keypress click', function() {
+ $(window).on('mousemove keypress click', function () {
if (newMessage && ajaxify.data.roomId) {
socket.emit('modules.chats.markRead', ajaxify.data.roomId);
newMessage = false;
@@ -302,8 +302,8 @@ define('forum/chats', [
});
};
- Chats.addSocketListeners = function() {
- socket.on('event:chats.receive', function(data) {
+ Chats.addSocketListeners = function () {
+ socket.on('event:chats.receive', function (data) {
if (parseInt(data.roomId, 10) === parseInt(ajaxify.data.roomId, 10)) {
newMessage = data.self === 0;
data.message.self = data.self;
@@ -319,8 +319,8 @@ define('forum/chats', [
var recentEl = components.get('chat/recent');
templates.parse('partials/chat_recent_room', {
rooms: { "roomId": data.roomId, "lastUser": data.message.fromUser, "usernames": data.message.fromUser.username, "unread": true }
- }, function(html) {
- translator.translate(html, function(translated) {
+ }, function (html) {
+ translator.translate(html, function (translated) {
recentEl.prepend(translated);
});
});
@@ -329,18 +329,18 @@ define('forum/chats', [
}
});
- socket.on('event:user_status_change', function(data) {
+ socket.on('event:user_status_change', function (data) {
app.updateUserStatus($('.chats-list [data-uid="' + data.uid + '"] [component="user/status"]'), data.status);
});
messages.onChatMessageEdit();
- socket.on('event:chats.roomRename', function(data) {
+ socket.on('event:chats.roomRename', function (data) {
$('[component="chat/room/name"]').val($('
').html(data.newName).text());
});
};
- Chats.resizeMainWindow = function() {
+ Chats.resizeMainWindow = function () {
var messagesList = $('.expanded-chat .chat-content');
if (messagesList.length) {
@@ -352,13 +352,13 @@ define('forum/chats', [
messagesList.height($(window).height() - (fromTop + inputHeight + (margin * 4)));
components.get('chat/recent').height($('.expanded-chat').height() - (searchHeight + searchListHeight));
- $('[component="chat/search/list"]').css('max-height', components.get('chat/recent').height()/2 + 'px');
+ $('[component="chat/search/list"]').css('max-height', components.get('chat/recent').height() / 2 + 'px');
}
Chats.setActive();
};
- Chats.setActive = function() {
+ Chats.setActive = function () {
if (ajaxify.data.roomId) {
socket.emit('modules.chats.markRead', ajaxify.data.roomId);
$('.expanded-chat input').focus();
diff --git a/public/src/client/chats/messages.js b/public/src/client/chats/messages.js
index ab444e36a4..9d91910493 100644
--- a/public/src/client/chats/messages.js
+++ b/public/src/client/chats/messages.js
@@ -2,11 +2,11 @@
/* globals define, socket, app, ajaxify, templates, bootbox */
-define('forum/chats/messages', ['components', 'sounds', 'translator'], function(components, sounds, translator) {
+define('forum/chats/messages', ['components', 'sounds', 'translator'], function (components, sounds, translator) {
var messages = {};
- messages.sendMessage = function(roomId, inputEl) {
+ messages.sendMessage = function (roomId, inputEl) {
var msg = inputEl.val();
var mid = inputEl.attr('data-mid');
@@ -25,7 +25,7 @@ define('forum/chats/messages', ['components', 'sounds', 'translator'], function(
socket.emit('modules.chats.send', {
roomId: roomId,
message: msg
- }, function(err) {
+ }, function (err) {
if (err) {
if (err.message === '[[error:email-not-confirmed-chat]]') {
return app.showEmailConfirmWarning(err);
@@ -40,7 +40,7 @@ define('forum/chats/messages', ['components', 'sounds', 'translator'], function(
roomId: roomId,
mid: mid,
message: msg
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -48,14 +48,14 @@ define('forum/chats/messages', ['components', 'sounds', 'translator'], function(
}
};
- messages.appendChatMessage = function(chatContentEl, data) {
+ messages.appendChatMessage = function (chatContentEl, data) {
var lastSpeaker = parseInt(chatContentEl.find('.chat-message').last().attr('data-uid'), 10);
if (!Array.isArray(data)) {
data.newSet = lastSpeaker !== data.fromuid;
}
- messages.parseMessage(data, function(html) {
+ messages.parseMessage(data, function (html) {
onMessagesParsed(chatContentEl, html);
});
};
@@ -70,16 +70,16 @@ define('forum/chats/messages', ['components', 'sounds', 'translator'], function(
}
- messages.parseMessage = function(data, callback) {
+ messages.parseMessage = function (data, callback) {
templates.parse('partials/chat_message' + (Array.isArray(data) ? 's' : ''), {
messages: data
- }, function(html) {
+ }, function (html) {
translator.translate(html, callback);
});
};
- messages.scrollToBottom = function(containerEl) {
+ messages.scrollToBottom = function (containerEl) {
if (containerEl.length) {
containerEl.scrollTop(
containerEl[0].scrollHeight - containerEl.height()
@@ -87,8 +87,8 @@ define('forum/chats/messages', ['components', 'sounds', 'translator'], function(
}
};
- messages.prepEdit = function(inputEl, messageId, roomId) {
- socket.emit('modules.chats.getRaw', { mid: messageId, roomId: roomId }, function(err, raw) {
+ messages.prepEdit = function (inputEl, messageId, roomId) {
+ socket.emit('modules.chats.getRaw', { mid: messageId, roomId: roomId }, function (err, raw) {
if (err) {
return app.alertError(err.message);
}
@@ -102,12 +102,12 @@ define('forum/chats/messages', ['components', 'sounds', 'translator'], function(
});
};
- messages.onChatMessageEdit = function() {
- socket.on('event:chats.edit', function(data) {
- data.messages.forEach(function(message) {
+ messages.onChatMessageEdit = function () {
+ socket.on('event:chats.edit', function (data) {
+ data.messages.forEach(function (message) {
var self = parseInt(message.fromuid, 10) === parseInt(app.user.uid);
message.self = self ? 1 : 0;
- messages.parseMessage(message, function(html) {
+ messages.parseMessage(message, function (html) {
var body = components.get('chat/message', message.messageId);
if (body.length) {
body.replaceWith(html);
@@ -118,9 +118,9 @@ define('forum/chats/messages', ['components', 'sounds', 'translator'], function(
});
};
- messages.delete = function(messageId, roomId) {
- translator.translate('[[modules:chat.delete_message_confirm]]', function(translated) {
- bootbox.confirm(translated, function(ok) {
+ messages.delete = function (messageId, roomId) {
+ translator.translate('[[modules:chat.delete_message_confirm]]', function (translated) {
+ bootbox.confirm(translated, function (ok) {
if (!ok) {
return;
}
@@ -128,12 +128,12 @@ define('forum/chats/messages', ['components', 'sounds', 'translator'], function(
socket.emit('modules.chats.delete', {
messageId: messageId,
roomId: roomId
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
- components.get('chat/message', messageId).slideUp('slow', function() {
+ components.get('chat/message', messageId).slideUp('slow', function () {
$(this).remove();
});
});
diff --git a/public/src/client/chats/recent.js b/public/src/client/chats/recent.js
index 9afc7ab76a..b4b9ba115b 100644
--- a/public/src/client/chats/recent.js
+++ b/public/src/client/chats/recent.js
@@ -2,12 +2,12 @@
/* globals define, socket, app */
-define('forum/chats/recent', function() {
+define('forum/chats/recent', function () {
var recent = {};
- recent.init = function() {
- $('[component="chat/recent"]').on('scroll', function() {
+ recent.init = function () {
+ $('[component="chat/recent"]').on('scroll', function () {
var $this = $(this);
var bottom = ($this[0].scrollHeight - $this.height()) * 0.9;
if ($this.scrollTop() > bottom) {
@@ -25,13 +25,13 @@ define('forum/chats/recent', function() {
socket.emit('modules.chats.getRecentChats', {
uid: ajaxify.data.uid,
after: recentChats.attr('data-nextstart')
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return app.alertError(err.message);
}
if (data && data.rooms.length) {
- onRecentChatsLoaded(data, function() {
+ onRecentChatsLoaded(data, function () {
recentChats.removeAttr('loading');
recentChats.attr('data-nextstart', data.nextStart);
});
@@ -46,7 +46,7 @@ define('forum/chats/recent', function() {
return callback();
}
- app.parseAndTranslate('chats', 'rooms', data, function(html) {
+ app.parseAndTranslate('chats', 'rooms', data, function (html) {
$('[component="chat/recent"]').append(html);
html.find('.timeago').timeago();
callback();
diff --git a/public/src/client/chats/search.js b/public/src/client/chats/search.js
index 6701563639..82b3923d2d 100644
--- a/public/src/client/chats/search.js
+++ b/public/src/client/chats/search.js
@@ -2,14 +2,14 @@
/* globals define, socket, app */
-define('forum/chats/search', ['components'], function(components) {
+define('forum/chats/search', ['components'], function (components) {
var search = {};
- search.init = function() {
+ search.init = function () {
var timeoutId = 0;
- components.get('chat/search').on('keyup', function() {
+ components.get('chat/search').on('keyup', function () {
if (timeoutId) {
clearTimeout(timeoutId);
timeoutId = 0;
@@ -30,7 +30,7 @@ define('forum/chats/search', ['components'], function(components) {
socket.emit('user.search', {
query: username,
searchBy: 'username'
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return app.alertError(err.message);
}
@@ -46,7 +46,7 @@ define('forum/chats/search', ['components'], function(components) {
return chatsListEl.translateHtml('[[users:no-users-found]]
');
}
- data.users.forEach(function(userObj) {
+ data.users.forEach(function (userObj) {
var chatEl = displayUser(chatsListEl, userObj);
onUserClick(chatEl, userObj);
});
@@ -55,7 +55,7 @@ define('forum/chats/search', ['components'], function(components) {
function displayUser(chatsListEl, userObj) {
function createUserImage() {
return (userObj.picture ?
- ' ' :
+ ' ' :
'' + userObj['icon:text'] + '
') +
' ' + userObj.username;
}
@@ -69,13 +69,13 @@ define('forum/chats/search', ['components'], function(components) {
}
function onUserClick(chatEl, userObj) {
- chatEl.on('click', function() {
- socket.emit('modules.chats.hasPrivateChat', userObj.uid, function(err, roomId) {
+ chatEl.on('click', function () {
+ socket.emit('modules.chats.hasPrivateChat', userObj.uid, function (err, roomId) {
if (err) {
return app.alertError(err.message);
}
if (roomId) {
- require(['forum/chats'], function(chats) {
+ require(['forum/chats'], function (chats) {
chats.switchChat(roomId);
});
} else {
diff --git a/public/src/client/compose.js b/public/src/client/compose.js
index c50ffe9945..4b2bb87b4e 100644
--- a/public/src/client/compose.js
+++ b/public/src/client/compose.js
@@ -2,10 +2,10 @@
/* globals define */
-define('forum/compose', [], function() {
+define('forum/compose', [], function () {
var Compose = {};
- Compose.init = function() {
+ Compose.init = function () {
var container = $('.composer');
if (container.length) {
diff --git a/public/src/client/footer.js b/public/src/client/footer.js
index 30da71aa12..d10f47e317 100644
--- a/public/src/client/footer.js
+++ b/public/src/client/footer.js
@@ -1,7 +1,7 @@
"use strict";
/*globals define, app, socket*/
-define('forum/footer', ['notifications', 'chat', 'components', 'translator'], function(Notifications, Chat, components, translator) {
+define('forum/footer', ['notifications', 'chat', 'components', 'translator'], function (Notifications, Chat, components, translator) {
Notifications.prepareDOM();
Chat.prepareDOM();
@@ -49,7 +49,7 @@ define('forum/footer', ['notifications', 'chat', 'components', 'translator'], fu
$('[data-tid="' + tid + '"]').addClass('unread');
}
- $(window).on('action:ajaxify.end', function(ev, data) {
+ $(window).on('action:ajaxify.end', function (ev, data) {
if (data.url) {
var tid = data.url.match(/^topic\/(\d+)/);
@@ -63,7 +63,7 @@ define('forum/footer', ['notifications', 'chat', 'components', 'translator'], fu
}
if (app.user.uid) {
- socket.emit('user.getUnreadCounts', function(err, data) {
+ socket.emit('user.getUnreadCounts', function (err, data) {
if (err) {
return app.alert(err.message);
}
diff --git a/public/src/client/groups/details.js b/public/src/client/groups/details.js
index d2f1cfbd8d..e8c449f5f6 100644
--- a/public/src/client/groups/details.js
+++ b/public/src/client/groups/details.js
@@ -8,12 +8,12 @@ define('forum/groups/details', [
'coverPhoto',
'uploader',
'vendor/colorpicker/colorpicker'
-], function(memberList, iconSelect, components, coverPhoto, uploader) {
+], function (memberList, iconSelect, components, coverPhoto, uploader) {
var Details = {};
var groupName;
- Details.init = function() {
+ Details.init = function () {
var detailsPage = components.get('groups/container');
groupName = ajaxify.data.group.name;
@@ -22,19 +22,19 @@ define('forum/groups/details', [
Details.prepareSettings();
coverPhoto.init(components.get('groups/cover'),
- function(imageData, position, callback) {
+ function (imageData, position, callback) {
socket.emit('groups.cover.update', {
groupName: groupName,
imageData: imageData,
position: position
}, callback);
},
- function() {
+ function () {
uploader.show({
title: '[[groups:upload-group-cover]]',
route: config.relative_path + '/api/groups/uploadpicture',
params: {groupName: groupName}
- }, function(imageUrlOnServer) {
+ }, function (imageUrlOnServer) {
components.get('groups/cover').css('background-image', 'url(' + imageUrlOnServer + ')');
});
},
@@ -48,7 +48,7 @@ define('forum/groups/details', [
components.get('groups/activity').find('.content img:not(.not-responsive)').addClass('img-responsive');
- detailsPage.on('click', '[data-action]', function() {
+ detailsPage.on('click', '[data-action]', function () {
var btnEl = $(this),
userRow = btnEl.parents('[data-uid]'),
ownerFlagEl = userRow.find('.member-name > i'),
@@ -61,7 +61,7 @@ define('forum/groups/details', [
socket.emit('groups.' + (isOwner ? 'rescind' : 'grant'), {
toUid: uid,
groupName: groupName
- }, function(err) {
+ }, function (err) {
if (!err) {
ownerFlagEl.toggleClass('invisible');
} else {
@@ -74,7 +74,7 @@ define('forum/groups/details', [
socket.emit('groups.kick', {
uid: uid,
groupName: groupName
- }, function(err) {
+ }, function (err) {
if (!err) {
userRow.slideUp().remove();
} else {
@@ -104,7 +104,7 @@ define('forum/groups/details', [
socket.emit('groups.' + action, {
toUid: uid,
groupName: groupName
- }, function(err) {
+ }, function (err) {
if (!err) {
ajaxify.refresh();
} else {
@@ -116,7 +116,7 @@ define('forum/groups/details', [
});
};
- Details.prepareSettings = function() {
+ Details.prepareSettings = function () {
var settingsFormEl = components.get('groups/settings'),
colorBtn = settingsFormEl.find('[data-action="color-select"]'),
colorValueEl = settingsFormEl.find('[name="labelColor"]'),
@@ -130,31 +130,31 @@ define('forum/groups/details', [
// Add color picker to settings form
colorBtn.ColorPicker({
color: colorValueEl.val() || '#000',
- onChange: function(hsb, hex) {
+ onChange: function (hsb, hex) {
colorValueEl.val('#' + hex);
previewEl.css('background-color', '#' + hex);
},
- onShow: function(colpkr) {
+ onShow: function (colpkr) {
$(colpkr).css('z-index', 1051);
}
});
// Add icon selection interface
- iconBtn.on('click', function() {
- iconSelect.init(previewIcon, function() {
+ iconBtn.on('click', function () {
+ iconSelect.init(previewIcon, function () {
iconValueEl.val(previewIcon.val());
});
});
// If the user title changes, update that too
- userTitleEl.on('keyup', function() {
+ userTitleEl.on('keyup', function () {
var icon = previewIcon.detach();
previewEl.text(' ' + (this.value || settingsFormEl.find('#name').val()));
previewEl.prepend(icon);
});
// Disable user title customisation options if the the user title itself is disabled
- userTitleEnabledEl.on('change', function() {
+ userTitleEnabledEl.on('change', function () {
var customOpts = components.get('groups/userTitleOption');
if (this.checked) {
@@ -167,16 +167,16 @@ define('forum/groups/details', [
});
};
- Details.update = function() {
+ Details.update = function () {
var settingsFormEl = components.get('groups/settings'),
checkboxes = settingsFormEl.find('input[type="checkbox"][name]');
if (settingsFormEl.length) {
- require(['vendor/jquery/serializeObject/jquery.ba-serializeobject.min'], function() {
+ require(['vendor/jquery/serializeObject/jquery.ba-serializeobject.min'], function () {
var settings = settingsFormEl.serializeObject();
// Fix checkbox values
- checkboxes.each(function(idx, inputEl) {
+ checkboxes.each(function (idx, inputEl) {
inputEl = $(inputEl);
if (inputEl.length) {
settings[inputEl.attr('name')] = inputEl.prop('checked');
@@ -186,7 +186,7 @@ define('forum/groups/details', [
socket.emit('groups.update', {
groupName: groupName,
values: settings
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -205,14 +205,14 @@ define('forum/groups/details', [
}
};
- Details.deleteGroup = function() {
- bootbox.confirm('Are you sure you want to delete the group: ' + utils.escapeHTML(groupName), function(confirm) {
+ Details.deleteGroup = function () {
+ bootbox.confirm('Are you sure you want to delete the group: ' + utils.escapeHTML(groupName), function (confirm) {
if (confirm) {
- bootbox.prompt('Please enter the name of this group in order to delete it:', function(response) {
+ bootbox.prompt('Please enter the name of this group in order to delete it:', function (response) {
if (response === groupName) {
socket.emit('groups.delete', {
groupName: groupName
- }, function(err) {
+ }, function (err) {
if (!err) {
app.alertSuccess('[[groups:event.deleted, ' + utils.escapeHTML(groupName) + ']]');
ajaxify.go('groups');
@@ -232,12 +232,12 @@ define('forum/groups/details', [
}
var searchInput = $('[component="groups/members/invite"]');
- require(['autocomplete'], function(autocomplete) {
- autocomplete.user(searchInput, function(event, selected) {
+ require(['autocomplete'], function (autocomplete) {
+ autocomplete.user(searchInput, function (event, selected) {
socket.emit('groups.issueInvite', {
toUid: selected.item.user.uid,
groupName: ajaxify.data.group.name
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -246,7 +246,7 @@ define('forum/groups/details', [
});
});
- $('[component="groups/members/bulk-invite-button"]').on('click', function() {
+ $('[component="groups/members/bulk-invite-button"]').on('click', function () {
var usernames = $('[component="groups/members/bulk-invite"]').val();
if (!usernames) {
return false;
@@ -254,7 +254,7 @@ define('forum/groups/details', [
socket.emit('groups.issueMassInvite', {
usernames: usernames,
groupName: ajaxify.data.group.name
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -267,7 +267,7 @@ define('forum/groups/details', [
function removeCover() {
socket.emit('groups.cover.remove', {
groupName: ajaxify.data.group.name
- }, function(err) {
+ }, function (err) {
if (!err) {
ajaxify.refresh();
} else {
diff --git a/public/src/client/groups/list.js b/public/src/client/groups/list.js
index 606a460dff..55ac232eb1 100644
--- a/public/src/client/groups/list.js
+++ b/public/src/client/groups/list.js
@@ -1,21 +1,21 @@
"use strict";
/* globals app, define, ajaxify, socket, bootbox, utils, templates */
-define('forum/groups/list', ['forum/infinitescroll'], function(infinitescroll) {
+define('forum/groups/list', ['forum/infinitescroll'], function (infinitescroll) {
var Groups = {};
- Groups.init = function() {
+ Groups.init = function () {
var groupsEl = $('#groups-list');
infinitescroll.init(Groups.loadMoreGroups);
// Group creation
- $('button[data-action="new"]').on('click', function() {
- bootbox.prompt('[[groups:new-group.group_name]]', function(name) {
+ $('button[data-action="new"]').on('click', function () {
+ bootbox.prompt('[[groups:new-group.group_name]]', function (name) {
if (name && name.length) {
socket.emit('groups.create', {
name: name
- }, function(err) {
+ }, function (err) {
if (!err) {
ajaxify.go('groups/' + utils.slugify(name));
} else {
@@ -31,12 +31,12 @@ define('forum/groups/list', ['forum/infinitescroll'], function(infinitescroll) {
// Group searching
$('#search-text').on('keyup', Groups.search);
$('#search-button').on('click', Groups.search);
- $('#search-sort').on('change', function() {
+ $('#search-sort').on('change', function () {
ajaxify.go('groups?sort=' + $('#search-sort').val());
});
};
- Groups.loadMoreGroups = function(direction) {
+ Groups.loadMoreGroups = function (direction) {
if (direction < 0) {
return;
}
@@ -44,11 +44,11 @@ define('forum/groups/list', ['forum/infinitescroll'], function(infinitescroll) {
infinitescroll.loadMore('groups.loadMore', {
sort: $('#search-sort').val(),
after: $('[component="groups/container"]').attr('data-nextstart')
- }, function(data, done) {
+ }, function (data, done) {
if (data && data.groups.length) {
templates.parse('partials/groups/list', {
groups: data.groups
- }, function(html) {
+ }, function (html) {
$('#groups-list').append(html);
done();
});
@@ -62,7 +62,7 @@ define('forum/groups/list', ['forum/infinitescroll'], function(infinitescroll) {
});
}
- Groups.search = function() {
+ Groups.search = function () {
var groupsEl = $('#groups-list'),
queryEl = $('#search-text'),
sortEl = $('#search-sort');
@@ -73,16 +73,16 @@ define('forum/groups/list', ['forum/infinitescroll'], function(infinitescroll) {
sort: sortEl.val(),
filterHidden: true
}
- }, function(err, groups) {
+ }, function (err, groups) {
if (err) {
return app.alertError(err.message);
}
- groups = groups.filter(function(group) {
+ groups = groups.filter(function (group) {
return group.name !== 'registered-users' && group.name !== 'guests';
});
templates.parse('partials/groups/list', {
groups: groups
- }, function(html) {
+ }, function (html) {
groupsEl.empty().append(html);
});
});
diff --git a/public/src/client/groups/memberlist.js b/public/src/client/groups/memberlist.js
index 7fc3bb6781..e7e6d8b1f1 100644
--- a/public/src/client/groups/memberlist.js
+++ b/public/src/client/groups/memberlist.js
@@ -1,13 +1,13 @@
"use strict";
/* globals define, socket, ajaxify, app */
-define('forum/groups/memberlist', ['components', 'forum/infinitescroll'], function(components, infinitescroll) {
+define('forum/groups/memberlist', ['components', 'forum/infinitescroll'], function (components, infinitescroll) {
var MemberList = {};
var searchInterval;
var groupName;
- MemberList.init = function() {
+ MemberList.init = function () {
groupName = ajaxify.data.group.name;
handleMemberSearch();
@@ -15,19 +15,19 @@ define('forum/groups/memberlist', ['components', 'forum/infinitescroll'], functi
};
function handleMemberSearch() {
- $('[component="groups/members/search"]').on('keyup', function() {
+ $('[component="groups/members/search"]').on('keyup', function () {
var query = $(this).val();
if (searchInterval) {
clearInterval(searchInterval);
searchInterval = 0;
}
- searchInterval = setTimeout(function() {
- socket.emit('groups.searchMembers', {groupName: groupName, query: query}, function(err, results) {
+ searchInterval = setTimeout(function () {
+ socket.emit('groups.searchMembers', {groupName: groupName, query: query}, function (err, results) {
if (err) {
return app.alertError(err.message);
}
- parseAndTranslate(results.users, function(html) {
+ parseAndTranslate(results.users, function (html) {
$('[component="groups/members"] tbody').html(html);
$('[component="groups/members"]').attr('data-nextstart', 20);
});
@@ -37,7 +37,7 @@ define('forum/groups/memberlist', ['components', 'forum/infinitescroll'], functi
}
function handleMemberInfiniteScroll() {
- $('[component="groups/members"] tbody').on('scroll', function() {
+ $('[component="groups/members"] tbody').on('scroll', function () {
var $this = $(this);
var bottom = ($this[0].scrollHeight - $this.innerHeight()) * 0.9;
@@ -57,13 +57,13 @@ define('forum/groups/memberlist', ['components', 'forum/infinitescroll'], functi
socket.emit('groups.loadMoreMembers', {
groupName: groupName,
after: members.attr('data-nextstart')
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return app.alertError(err.message);
}
if (data && data.users.length) {
- onMembersLoaded(data.users, function() {
+ onMembersLoaded(data.users, function () {
members.removeAttr('loading');
members.attr('data-nextstart', data.nextStart);
});
@@ -74,11 +74,11 @@ define('forum/groups/memberlist', ['components', 'forum/infinitescroll'], functi
}
function onMembersLoaded(users, callback) {
- users = users.filter(function(user) {
+ users = users.filter(function (user) {
return !$('[component="groups/members"] [data-uid="' + user.uid + '"]').length;
});
- parseAndTranslate(users, function(html) {
+ parseAndTranslate(users, function (html) {
$('[component="groups/members"] tbody').append(html);
callback();
});
diff --git a/public/src/client/infinitescroll.js b/public/src/client/infinitescroll.js
index aa559c623e..6ae9b5cbbc 100644
--- a/public/src/client/infinitescroll.js
+++ b/public/src/client/infinitescroll.js
@@ -2,7 +2,7 @@
/* globals define, socket, app */
-define('forum/infinitescroll', function() {
+define('forum/infinitescroll', function () {
var scroll = {};
var callback;
@@ -10,7 +10,7 @@ define('forum/infinitescroll', function() {
var loadingMore = false;
var container;
- scroll.init = function(el, cb) {
+ scroll.init = function (el, cb) {
if (typeof el === 'function') {
callback = el;
container = $('body');
@@ -47,7 +47,7 @@ define('forum/infinitescroll', function() {
previousScrollTop = currentScrollTop;
}
- scroll.loadMore = function(method, data, callback) {
+ scroll.loadMore = function (method, data, callback) {
if (loadingMore) {
return;
}
@@ -56,18 +56,18 @@ define('forum/infinitescroll', function() {
var hookData = {method: method, data: data};
$(window).trigger('action:infinitescroll.loadmore', hookData);
- socket.emit(hookData.method, hookData.data, function(err, data) {
+ socket.emit(hookData.method, hookData.data, function (err, data) {
if (err) {
loadingMore = false;
return app.alertError(err.message);
}
- callback(data, function() {
+ callback(data, function () {
loadingMore = false;
});
});
};
- scroll.removeExtra = function(els, direction, count) {
+ scroll.removeExtra = function (els, direction, count) {
if (els.length <= count) {
return;
}
diff --git a/public/src/client/login.js b/public/src/client/login.js
index c86e743be2..254c90d583 100644
--- a/public/src/client/login.js
+++ b/public/src/client/login.js
@@ -1,15 +1,15 @@
"use strict";
/* global define, app, config, RELATIVE_PATH */
-define('forum/login', ['translator'], function(translator) {
+define('forum/login', ['translator'], function (translator) {
var Login = {};
- Login.init = function() {
+ Login.init = function () {
var errorEl = $('#login-error-notify'),
submitEl = $('#login'),
formEl = $('#login-form');
- submitEl.on('click', function(e) {
+ submitEl.on('click', function (e) {
e.preventDefault();
if (!$('#username').val() || !$('#password').val()) {
@@ -27,10 +27,10 @@ define('forum/login', ['translator'], function(translator) {
headers: {
'x-csrf-token': config.csrf_token
},
- success: function(data, status) {
+ success: function (data, status) {
window.location.href = data + '?loggedin';
},
- error: function(data, status) {
+ error: function (data, status) {
if (data.status === 403 && data.responseText === 'Forbidden') {
window.location.href = config.relative_path + '/login?error=csrf-invalid';
} else {
@@ -48,7 +48,7 @@ define('forum/login', ['translator'], function(translator) {
}
});
- $('#login-error-notify button').on('click', function(e) {
+ $('#login-error-notify button').on('click', function (e) {
e.preventDefault();
errorEl.hide();
return false;
diff --git a/public/src/client/notifications.js b/public/src/client/notifications.js
index 6d353ddc21..baeaa262cd 100644
--- a/public/src/client/notifications.js
+++ b/public/src/client/notifications.js
@@ -2,14 +2,14 @@
/* globals define, socket, app */
-define('forum/notifications', ['components', 'notifications', 'forum/infinitescroll'], function(components, notifs, infinitescroll) {
+define('forum/notifications', ['components', 'notifications', 'forum/infinitescroll'], function (components, notifs, infinitescroll) {
var Notifications = {};
- Notifications.init = function() {
+ Notifications.init = function () {
var listEl = $('.notifications-list');
- listEl.on('click', '[component="notifications/item/link"]', function() {
+ listEl.on('click', '[component="notifications/item/link"]', function () {
var nid = $(this).parents('[data-nid]').attr('data-nid');
- socket.emit('notifications.markRead', nid, function(err) {
+ socket.emit('notifications.markRead', nid, function (err) {
if (err) {
return app.alertError(err);
}
@@ -18,8 +18,8 @@ define('forum/notifications', ['components', 'notifications', 'forum/infinitescr
$('.timeago').timeago();
- components.get('notifications/mark_all').on('click', function() {
- socket.emit('notifications.markAllRead', function(err) {
+ components.get('notifications/mark_all').on('click', function () {
+ socket.emit('notifications.markAllRead', function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -39,7 +39,7 @@ define('forum/notifications', ['components', 'notifications', 'forum/infinitescr
var notifList = $('.notifications-list');
infinitescroll.loadMore('notifications.loadMore', {
after: notifList.attr('data-nextstart')
- }, function(data, done) {
+ }, function (data, done) {
if (!data) {
return done();
}
@@ -47,7 +47,7 @@ define('forum/notifications', ['components', 'notifications', 'forum/infinitescr
if (!data.notifications || !data.notifications.length) {
return done();
}
- app.parseAndTranslate('notifications', 'notifications', {notifications: data.notifications}, function(html) {
+ app.parseAndTranslate('notifications', 'notifications', {notifications: data.notifications}, function (html) {
notifList.append(html);
html.find('.timeago').timeago();
done();
diff --git a/public/src/client/pagination.js b/public/src/client/pagination.js
index 3bac155dc5..6cbd7102f0 100644
--- a/public/src/client/pagination.js
+++ b/public/src/client/pagination.js
@@ -1,20 +1,20 @@
'use strict';
/*global define, utils, ajaxify, bootbox*/
-define('forum/pagination', function() {
+define('forum/pagination', function () {
var pagination = {};
- pagination.init = function() {
- $('body').on('click', '[component="pagination/select-page"]', function() {
- bootbox.prompt('[[global:enter_page_number]]', function(pageNum) {
+ pagination.init = function () {
+ $('body').on('click', '[component="pagination/select-page"]', function () {
+ bootbox.prompt('[[global:enter_page_number]]', function (pageNum) {
pagination.loadPage(pageNum);
});
return false;
});
};
- pagination.loadPage = function(page, callback) {
- callback = callback || function() {};
+ pagination.loadPage = function (page, callback) {
+ callback = callback || function () {};
page = parseInt(page, 10);
if (!utils.isNumber(page) || page < 1 || page > ajaxify.data.pagination.pageCount) {
return;
diff --git a/public/src/client/popular.js b/public/src/client/popular.js
index f7f0cd568e..00fb6937e2 100644
--- a/public/src/client/popular.js
+++ b/public/src/client/popular.js
@@ -2,10 +2,10 @@
/* globals define, app, socket*/
-define('forum/popular', ['components'], function(components) {
+define('forum/popular', ['components'], function (components) {
var Popular = {};
- Popular.init = function() {
+ Popular.init = function () {
app.enterRoom('popular_topics');
components.get('popular/tab')
diff --git a/public/src/client/recent.js b/public/src/client/recent.js
index 973819d44d..15b37eaf19 100644
--- a/public/src/client/recent.js
+++ b/public/src/client/recent.js
@@ -2,24 +2,24 @@
/* globals define, app, socket, utils, ajaxify, config */
-define('forum/recent', ['forum/infinitescroll', 'components'], function(infinitescroll, components) {
+define('forum/recent', ['forum/infinitescroll', 'components'], function (infinitescroll, components) {
var Recent = {};
var newTopicCount = 0;
var newPostCount = 0;
- $(window).on('action:ajaxify.start', function(ev, data) {
+ $(window).on('action:ajaxify.start', function (ev, data) {
if (ajaxify.currentPage !== data.url) {
Recent.removeListeners();
}
});
- Recent.init = function() {
+ Recent.init = function () {
app.enterRoom('recent_topics');
Recent.watchForNewPosts();
- $('#new-topics-alert').on('click', function() {
+ $('#new-topics-alert').on('click', function () {
$(this).addClass('hide');
});
@@ -74,7 +74,7 @@ define('forum/recent', ['forum/infinitescroll', 'components'], function(infinite
}
if (ajaxify.data.selectedFilter && ajaxify.data.selectedFilter.url === 'unread/watched') {
- socket.emit('topics.isFollowed', post.tid, function(err, isFollowed) {
+ socket.emit('topics.isFollowed', post.tid, function (err, isFollowed) {
if (err) {
app.alertError(err.message);
}
@@ -88,12 +88,12 @@ define('forum/recent', ['forum/infinitescroll', 'components'], function(infinite
showAlert();
}
- Recent.removeListeners = function() {
+ Recent.removeListeners = function () {
socket.removeListener('event:new_topic', onNewTopic);
socket.removeListener('event:new_post', onNewPost);
};
- Recent.updateAlertText = function() {
+ Recent.updateAlertText = function () {
var text = '';
if (newTopicCount === 0) {
@@ -108,7 +108,7 @@ define('forum/recent', ['forum/infinitescroll', 'components'], function(infinite
} else if (newPostCount === 1) {
text = '[[recent:there-is-a-new-topic-and-a-new-post]]';
} else if (newPostCount > 1) {
- text = '[[recent:there-is-a-new-topic-and-new-posts, ' + newPostCount +']]';
+ text = '[[recent:there-is-a-new-topic-and-new-posts, ' + newPostCount + ']]';
}
} else if (newTopicCount > 1) {
if (newPostCount === 0) {
@@ -116,7 +116,7 @@ define('forum/recent', ['forum/infinitescroll', 'components'], function(infinite
} else if (newPostCount === 1) {
text = '[[recent:there-are-new-topics-and-a-new-post, ' + newTopicCount + ']]';
} else if (newPostCount > 1) {
- text = '[[recent:there-are-new-topics-and-new-posts, ' + newTopicCount + ', ' + newPostCount +']]';
+ text = '[[recent:there-are-new-topics-and-new-posts, ' + newTopicCount + ', ' + newPostCount + ']]';
}
}
@@ -126,7 +126,7 @@ define('forum/recent', ['forum/infinitescroll', 'components'], function(infinite
$('#category-no-topics').addClass('hide');
};
- Recent.loadMoreTopics = function(direction) {
+ Recent.loadMoreTopics = function (direction) {
if(direction < 0 || !$('[component="category"]').length) {
return;
}
@@ -134,7 +134,7 @@ define('forum/recent', ['forum/infinitescroll', 'components'], function(infinite
infinitescroll.loadMore('topics.loadMoreFromSet', {
after: $('[component="category"]').attr('data-nextstart'),
set: $('[component="category"]').attr('data-set') ? $('[component="category"]').attr('data-set') : 'topics:recent'
- }, function(data, done) {
+ }, function (data, done) {
if (data.topics && data.topics.length) {
Recent.onTopicsLoaded('recent', data.topics, false, done);
} else {
@@ -144,9 +144,9 @@ define('forum/recent', ['forum/infinitescroll', 'components'], function(infinite
});
};
- Recent.onTopicsLoaded = function(templateName, topics, showSelect, callback) {
+ Recent.onTopicsLoaded = function (templateName, topics, showSelect, callback) {
- topics = topics.filter(function(topic) {
+ topics = topics.filter(function (topic) {
return !components.get('category/topic', 'tid', topic.tid).length;
});
@@ -154,7 +154,7 @@ define('forum/recent', ['forum/infinitescroll', 'components'], function(infinite
return callback();
}
- app.parseAndTranslate(templateName, 'topics', {topics: topics, showSelect: showSelect}, function(html) {
+ app.parseAndTranslate(templateName, 'topics', {topics: topics, showSelect: showSelect}, function (html) {
$('#category-no-topics').remove();
$('[component="category"]').append(html);
diff --git a/public/src/client/register.js b/public/src/client/register.js
index 4b5d5a02d6..01dfa4dfc1 100644
--- a/public/src/client/register.js
+++ b/public/src/client/register.js
@@ -3,12 +3,12 @@
/* globals define, app, utils, socket, config, ajaxify, bootbox */
-define('forum/register', ['translator'], function(translator) {
+define('forum/register', ['translator'], function (translator) {
var Register = {},
validationError = false,
successIcon = '';
- Register.init = function() {
+ Register.init = function () {
var email = $('#email'),
username = $('#username'),
password = $('#password'),
@@ -19,7 +19,7 @@ define('forum/register', ['translator'], function(translator) {
$('#referrer').val(app.previousUrl);
- email.on('blur', function() {
+ email.on('blur', function () {
if (email.val().length) {
validateEmail(email.val());
}
@@ -32,23 +32,23 @@ define('forum/register', ['translator'], function(translator) {
}
// Update the "others can mention you via" text
- username.on('keyup', function() {
+ username.on('keyup', function () {
$('#yourUsername').text(this.value.length > 0 ? utils.slugify(this.value) : 'username');
});
- username.on('blur', function() {
+ username.on('blur', function () {
if (username.val().length) {
validateUsername(username.val());
}
});
- password.on('blur', function() {
+ password.on('blur', function () {
if (password.val().length) {
validatePassword(password.val(), password_confirm.val());
}
});
- password_confirm.on('blur', function() {
+ password_confirm.on('blur', function () {
if (password_confirm.val().length) {
validatePasswordConfirm(password.val(), password_confirm.val());
}
@@ -59,17 +59,17 @@ define('forum/register', ['translator'], function(translator) {
validatePassword(password.val(), password_confirm.val());
validatePasswordConfirm(password.val(), password_confirm.val());
- validateEmail(email.val(), function() {
+ validateEmail(email.val(), function () {
validateUsername(username.val(), callback);
});
}
- register.on('click', function(e) {
+ register.on('click', function (e) {
var registerBtn = $(this);
var errorEl = $('#register-error-notify');
errorEl.addClass('hidden');
e.preventDefault();
- validateForm(function() {
+ validateForm(function () {
if (validationError) {
return;
}
@@ -80,7 +80,7 @@ define('forum/register', ['translator'], function(translator) {
headers: {
'x-csrf-token': config.csrf_token
},
- success: function(data) {
+ success: function (data) {
registerBtn.removeClass('disabled');
if (!data) {
return;
@@ -88,16 +88,16 @@ define('forum/register', ['translator'], function(translator) {
if (data.referrer) {
window.location.href = data.referrer;
} else if (data.message) {
- require(['translator'], function(translator) {
- translator.translate(data.message, function(msg) {
+ require(['translator'], function (translator) {
+ translator.translate(data.message, function (msg) {
bootbox.alert(msg);
ajaxify.go('/');
});
});
}
},
- error: function(data) {
- translator.translate(data.responseText, config.defaultLang, function(translated) {
+ error: function (data) {
+ translator.translate(data.responseText, config.defaultLang, function (translated) {
if (data.status === 403 && data.responseText === 'Forbidden') {
window.location.href = config.relative_path + '/register?error=csrf-invalid';
} else {
@@ -113,7 +113,7 @@ define('forum/register', ['translator'], function(translator) {
};
function validateEmail(email, callback) {
- callback = callback || function() {};
+ callback = callback || function () {};
var email_notify = $('#email-notify');
if (!utils.isEmailValid(email)) {
@@ -123,7 +123,7 @@ define('forum/register', ['translator'], function(translator) {
socket.emit('user.emailExists', {
email: email
- }, function(err, exists) {
+ }, function (err, exists) {
if (err) {
app.alertError(err.message);
return callback();
@@ -140,7 +140,7 @@ define('forum/register', ['translator'], function(translator) {
}
function validateUsername(username, callback) {
- callback = callback || function() {};
+ callback = callback || function () {};
var username_notify = $('#username-notify');
@@ -153,7 +153,7 @@ define('forum/register', ['translator'], function(translator) {
} else {
socket.emit('user.exists', {
username: username
- }, function(err, exists) {
+ }, function (err, exists) {
if (err) {
return app.alertError(err.message);
}
@@ -208,7 +208,7 @@ define('forum/register', ['translator'], function(translator) {
}
function showError(element, msg) {
- translator.translate(msg, function(msg) {
+ translator.translate(msg, function (msg) {
element.html(msg);
element.parent()
.removeClass('register-success')
@@ -219,7 +219,7 @@ define('forum/register', ['translator'], function(translator) {
}
function showSuccess(element, msg) {
- translator.translate(msg, function(msg) {
+ translator.translate(msg, function (msg) {
element.html(msg);
element.parent()
.removeClass('register-danger')
diff --git a/public/src/client/reset.js b/public/src/client/reset.js
index ef6856555a..3e0220957b 100644
--- a/public/src/client/reset.js
+++ b/public/src/client/reset.js
@@ -1,17 +1,17 @@
"use strict";
/*globals define, app, socket*/
-define('forum/reset', function() {
+define('forum/reset', function () {
var ResetPassword = {};
- ResetPassword.init = function() {
+ ResetPassword.init = function () {
var inputEl = $('#email'),
errorEl = $('#error'),
successEl = $('#success');
- $('#reset').on('click', function() {
+ $('#reset').on('click', function () {
if (inputEl.val() && inputEl.val().indexOf('@') !== -1) {
- socket.emit('user.reset.send', inputEl.val(), function(err) {
+ socket.emit('user.reset.send', inputEl.val(), function (err) {
if(err) {
return app.alertError(err.message);
}
diff --git a/public/src/client/reset_code.js b/public/src/client/reset_code.js
index 2efd14b1a6..044602144c 100644
--- a/public/src/client/reset_code.js
+++ b/public/src/client/reset_code.js
@@ -1,17 +1,17 @@
"use strict";
/*globals define, app, ajaxify, socket, config*/
-define('forum/reset_code', function() {
+define('forum/reset_code', function () {
var ResetCode = {};
- ResetCode.init = function() {
+ ResetCode.init = function () {
var reset_code = ajaxify.data.code;
var resetEl = $('#reset');
var password = $('#password');
var repeat = $('#repeat');
- resetEl.on('click', function() {
+ resetEl.on('click', function () {
if (password.val().length < ajaxify.data.minimumPasswordLength) {
app.alertError('[[reset_password:password_too_short]]');
} else if (password.val() !== repeat.val()) {
@@ -21,7 +21,7 @@ define('forum/reset_code', function() {
socket.emit('user.reset.commit', {
code: reset_code,
password: password.val()
- }, function(err) {
+ }, function (err) {
if (err) {
ajaxify.refresh();
return app.alertError(err.message);
diff --git a/public/src/client/search.js b/public/src/client/search.js
index 91839ff880..20c85c13c2 100644
--- a/public/src/client/search.js
+++ b/public/src/client/search.js
@@ -2,10 +2,10 @@
/* globals app, define, utils*/
-define('forum/search', ['search', 'autocomplete'], function(searchModule, autocomplete) {
+define('forum/search', ['search', 'autocomplete'], function (searchModule, autocomplete) {
var Search = {};
- Search.init = function() {
+ Search.init = function () {
var searchQuery = $('#results').attr('data-search-query');
$('#search-input').val(searchQuery);
@@ -14,15 +14,15 @@ define('forum/search', ['search', 'autocomplete'], function(searchModule, autoco
fillOutForm();
- searchIn.on('change', function() {
+ searchIn.on('change', function () {
updateFormItemVisiblity(searchIn.val());
});
highlightMatches(searchQuery);
- $('#advanced-search').off('submit').on('submit', function(e) {
+ $('#advanced-search').off('submit').on('submit', function (e) {
e.preventDefault();
- searchModule.query(getSearchData(), function() {
+ searchModule.query(getSearchData(), function () {
$('#search-input').val('');
});
return false;
@@ -120,10 +120,10 @@ define('forum/search', ['search', 'autocomplete'], function(searchModule, autoco
var regexStr = searchQuery.replace(/^"/, '').replace(/"$/, '').trim().split(' ').join('|');
var regex = new RegExp('(' + regexStr + ')', 'gi');
- $('.search-result-text p, .search-result-text h4').each(function() {
+ $('.search-result-text p, .search-result-text h4').each(function () {
var result = $(this), nested = [];
- result.find('*').each(function() {
+ result.find('*').each(function () {
$(this).after('');
nested.push($('
').append($(this)));
});
@@ -139,13 +139,13 @@ define('forum/search', ['search', 'autocomplete'], function(searchModule, autoco
}
function handleSavePreferences() {
- $('#save-preferences').on('click', function() {
+ $('#save-preferences').on('click', function () {
localStorage.setItem('search-preferences', JSON.stringify(getSearchData()));
app.alertSuccess('[[search:search-preferences-saved]]');
return false;
});
- $('#clear-preferences').on('click', function() {
+ $('#clear-preferences').on('click', function () {
localStorage.removeItem('search-preferences');
var query = $('#search-input').val();
$('#advanced-search')[0].reset();
diff --git a/public/src/client/tag.js b/public/src/client/tag.js
index b475c7406b..e48252ec76 100644
--- a/public/src/client/tag.js
+++ b/public/src/client/tag.js
@@ -2,17 +2,17 @@
/* globals define, app, ajaxify, socket */
-define('forum/tag', ['forum/recent', 'forum/infinitescroll'], function(recent, infinitescroll) {
+define('forum/tag', ['forum/recent', 'forum/infinitescroll'], function (recent, infinitescroll) {
var Tag = {};
- Tag.init = function() {
+ Tag.init = function () {
app.enterRoom('tags');
if ($('body').height() <= $(window).height() && $('[component="category"]').children().length >= 20) {
$('#load-more-btn').show();
}
- $('#load-more-btn').on('click', function() {
+ $('#load-more-btn').on('click', function () {
loadMoreTopics();
});
@@ -28,7 +28,7 @@ define('forum/tag', ['forum/recent', 'forum/infinitescroll'], function(recent, i
infinitescroll.loadMore('topics.loadMoreFromSet', {
set: 'tag:' + ajaxify.data.tag + ':topics',
after: $('[component="category"]').attr('data-nextstart')
- }, function(data, done) {
+ }, function (data, done) {
if (data.topics && data.topics.length) {
recent.onTopicsLoaded('tag', data.topics, false, done);
} else {
diff --git a/public/src/client/tags.js b/public/src/client/tags.js
index 5ea916257e..4fbae1ecf5 100644
--- a/public/src/client/tags.js
+++ b/public/src/client/tags.js
@@ -2,14 +2,14 @@
/* globals define, app, utils, socket */
-define('forum/tags', ['forum/infinitescroll'], function(infinitescroll) {
+define('forum/tags', ['forum/infinitescroll'], function (infinitescroll) {
var Tags = {};
var timeoutId = 0;
- Tags.init = function() {
+ Tags.init = function () {
app.enterRoom('tags');
- $('#tag-search').on('input propertychange', function() {
+ $('#tag-search').on('input propertychange', function () {
if (timeoutId) {
clearTimeout(timeoutId);
timeoutId = 0;
@@ -19,12 +19,12 @@ define('forum/tags', ['forum/infinitescroll'], function(infinitescroll) {
return resetSearch();
}
- timeoutId = setTimeout(function() {
- socket.emit('topics.searchAndLoadTags', {query: $('#tag-search').val()}, function(err, results) {
+ timeoutId = setTimeout(function () {
+ socket.emit('topics.searchAndLoadTags', {query: $('#tag-search').val()}, function (err, results) {
if (err) {
return app.alertError(err.message);
}
- onTagsLoaded(results.tags, true, function() {
+ onTagsLoaded(results.tags, true, function () {
timeoutId = 0;
});
});
@@ -34,14 +34,14 @@ define('forum/tags', ['forum/infinitescroll'], function(infinitescroll) {
infinitescroll.init(Tags.loadMoreTags);
};
- Tags.loadMoreTags = function(direction) {
+ Tags.loadMoreTags = function (direction) {
if(direction < 0 || !$('.tag-list').length) {
return;
}
infinitescroll.loadMore('topics.loadMoreTags', {
after: $('.tag-list').attr('data-nextstart')
- }, function(data, done) {
+ }, function (data, done) {
if (data && data.tags && data.tags.length) {
onTagsLoaded(data.tags, false, done);
$('.tag-list').attr('data-nextstart', data.nextStart);
@@ -54,7 +54,7 @@ define('forum/tags', ['forum/infinitescroll'], function(infinitescroll) {
function resetSearch() {
socket.emit('topics.loadMoreTags', {
after: 0
- }, function(err, data) {
+ }, function (err, data) {
if (err) {
return app.alertError(err.message);
}
@@ -63,8 +63,8 @@ define('forum/tags', ['forum/infinitescroll'], function(infinitescroll) {
}
function onTagsLoaded(tags, replace, callback) {
- callback = callback || function() {};
- app.parseAndTranslate('tags', 'tags', {tags: tags}, function(html) {
+ callback = callback || function () {};
+ app.parseAndTranslate('tags', 'tags', {tags: tags}, function (html) {
$('.tag-list')[replace ? 'html' : 'append'](html);
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
callback();
diff --git a/public/src/client/topic.js b/public/src/client/topic.js
index 6f81233ee4..3408f18560 100644
--- a/public/src/client/topic.js
+++ b/public/src/client/topic.js
@@ -12,11 +12,11 @@ define('forum/topic', [
'navigator',
'sort',
'components'
-], function(infinitescroll, threadTools, postTools, events, posts, navigator, sort, components) {
+], function (infinitescroll, threadTools, postTools, events, posts, navigator, sort, components) {
var Topic = {},
currentUrl = '';
- $(window).on('action:ajaxify.start', function(ev, data) {
+ $(window).on('action:ajaxify.start', function (ev, data) {
if (Topic.replaceURLTimeout) {
clearTimeout(Topic.replaceURLTimeout);
Topic.replaceURLTimeout = 0;
@@ -32,7 +32,7 @@ define('forum/topic', [
}
if (data.url && !data.url.startsWith('topic/')) {
- require(['search'], function(search) {
+ require(['search'], function (search) {
if (search.topicDOM.active) {
search.topicDOM.end();
}
@@ -40,7 +40,7 @@ define('forum/topic', [
}
});
- Topic.init = function() {
+ Topic.init = function () {
var tid = ajaxify.data.tid;
$(window).trigger('action:topic.loading');
@@ -98,16 +98,16 @@ define('forum/topic', [
}
function handleTopicSearch() {
- require(['search', 'mousetrap'], function(search, mousetrap) {
+ require(['search', 'mousetrap'], function (search, mousetrap) {
$('.topic-search')
- .on('click', '.prev', function() {
+ .on('click', '.prev', function () {
search.topicDOM.prev();
})
- .on('click', '.next', function() {
+ .on('click', '.next', function () {
search.topicDOM.next();
});
- mousetrap.bind('ctrl+f', function(e) {
+ mousetrap.bind('ctrl+f', function (e) {
if (config.topicSearchEnabled) {
// If in topic, open search window and populate, otherwise regular behaviour
var match = ajaxify.currentPage.match(/^topic\/([\d]+)/),
@@ -123,12 +123,12 @@ define('forum/topic', [
});
}
- Topic.toTop = function() {
+ Topic.toTop = function () {
navigator.scrollTop(0);
};
- Topic.toBottom = function() {
- socket.emit('topics.postcount', ajaxify.data.tid, function(err, postCount) {
+ Topic.toBottom = function () {
+ socket.emit('topics.postcount', ajaxify.data.tid, function (err, postCount) {
if (err) {
return app.alertError(err.message);
}
@@ -155,14 +155,14 @@ define('forum/topic', [
message: '[[topic:bookmark_instructions]]',
timeout: 0,
type: 'info',
- clickfn : function() {
+ clickfn : function () {
navigator.scrollToPost(parseInt(bookmark - 1, 10), true);
},
- closefn : function() {
+ closefn : function () {
localStorage.removeItem('topic:' + tid + ':bookmark');
}
});
- setTimeout(function() {
+ setTimeout(function () {
app.removeAlert('bookmark');
}, 10000);
} else {
@@ -187,7 +187,7 @@ define('forum/topic', [
}
function addBlockQuoteHandler() {
- components.get('topic').on('click', 'blockquote .toggle', function() {
+ components.get('topic').on('click', 'blockquote .toggle', function () {
var blockQuote = $(this).parent('blockquote');
var toggle = $(this);
blockQuote.toggleClass('uncollapsed');
@@ -197,7 +197,7 @@ define('forum/topic', [
}
function addParentHandler() {
- components.get('topic').on('click', '[component="post/parent"]', function(e) {
+ components.get('topic').on('click', '[component="post/parent"]', function (e) {
var toPid = $(this).attr('data-topid');
var toPost = $('[component="post"][data-pid="' + toPid + '"]');
@@ -221,14 +221,14 @@ define('forum/topic', [
}
}
- Topic.calculateIndex = function(index, elementCount) {
+ Topic.calculateIndex = function (index, elementCount) {
if (index !== 1 && config.topicPostSort !== 'oldest_to_newest') {
return elementCount - index + 2;
}
return index;
};
- Topic.navigatorCallback = function(index, elementCount, threshold) {
+ Topic.navigatorCallback = function (index, elementCount, threshold) {
var path = ajaxify.removeRelativePath(window.location.pathname.slice(1));
if (!path.startsWith('topic')) {
return;
@@ -248,7 +248,7 @@ define('forum/topic', [
clearTimeout(Topic.replaceURLTimeout);
}
- Topic.replaceURLTimeout = setTimeout(function() {
+ Topic.replaceURLTimeout = setTimeout(function () {
if (index >= elementCount && app.user.uid) {
socket.emit('topics.markAsRead', [ajaxify.data.tid]);
@@ -281,7 +281,7 @@ define('forum/topic', [
socket.emit('topics.bookmark', {
'tid': ajaxify.data.tid,
'index': index
- }, function(err) {
+ }, function (err) {
if (err) {
return app.alertError(err.message);
}
diff --git a/public/src/client/topic/delete-posts.js b/public/src/client/topic/delete-posts.js
index 8c114679c4..ec7a0ca1d5 100644
--- a/public/src/client/topic/delete-posts.js
+++ b/public/src/client/topic/delete-posts.js
@@ -2,14 +2,14 @@
/* globals define, app, ajaxify, socket */
-define('forum/topic/delete-posts', ['components', 'postSelect'], function(components, postSelect) {
+define('forum/topic/delete-posts', ['components', 'postSelect'], function (components, postSelect) {
var DeletePosts = {};
var modal;
var deleteBtn;
var purgeBtn;
- DeletePosts.init = function() {
+ DeletePosts.init = function () {
$('.topic').on('click', '[component="topic/delete/posts"]', onDeletePostsClicked);
$(window).on('action:ajaxify.start', onAjaxifyStart);
};
@@ -20,7 +20,7 @@ define('forum/topic/delete-posts', ['components', 'postSelect'], function(compon
}
function onDeletePostsClicked() {
- app.parseAndTranslate('partials/delete_posts_modal', {}, function(html) {
+ app.parseAndTranslate('partials/delete_posts_modal', {}, function (html) {
modal = html;
$('body').append(modal);
@@ -30,16 +30,16 @@ define('forum/topic/delete-posts', ['components', 'postSelect'], function(compon
modal.find('.close,#delete_posts_cancel').on('click', closeModal);
- postSelect.init(function() {
+ postSelect.init(function () {
checkButtonEnable();
showPostsSelected();
});
showPostsSelected();
- deleteBtn.on('click', function() {
+ deleteBtn.on('click', function () {
deletePosts(deleteBtn, 'posts.deletePosts');
});
- purgeBtn.on('click', function() {
+ purgeBtn.on('click', function () {
deletePosts(purgeBtn, 'posts.purgePosts');
});
});
@@ -50,7 +50,7 @@ define('forum/topic/delete-posts', ['components', 'postSelect'], function(compon
socket.emit(command, {
tid: ajaxify.data.tid,
pids: postSelect.pids
- }, function(err) {
+ }, function (err) {
btn.removeAttr('disabled');
if (err) {
return app.alertError(err.message);
@@ -79,7 +79,7 @@ define('forum/topic/delete-posts', ['components', 'postSelect'], function(compon
}
function closeModal() {
- postSelect.pids.forEach(function(pid) {
+ postSelect.pids.forEach(function (pid) {
components.get('post', 'pid', pid).toggleClass('bg-success', false);
});
diff --git a/public/src/client/topic/events.js b/public/src/client/topic/events.js
index bba3cb0dcb..f6a6aecc6d 100644
--- a/public/src/client/topic/events.js
+++ b/public/src/client/topic/events.js
@@ -9,7 +9,7 @@ define('forum/topic/events', [
'forum/topic/posts',
'components',
'translator'
-], function(postTools, threadTools, posts, components, translator) {
+], function (postTools, threadTools, posts, components, translator) {
var Events = {};
@@ -47,7 +47,7 @@ define('forum/topic/events', [
'event:new_post': posts.onNewPost
};
- Events.init = function() {
+ Events.init = function () {
Events.removeListeners();
for(var eventName in events) {
if (events.hasOwnProperty(eventName)) {
@@ -56,7 +56,7 @@ define('forum/topic/events', [
}
};
- Events.removeListeners = function() {
+ Events.removeListeners = function () {
for(var eventName in events) {
if (events.hasOwnProperty(eventName)) {
socket.removeListener(eventName, events[eventName]);
@@ -107,18 +107,18 @@ define('forum/topic/events', [
var newUrl = 'topic/' + data.topic.slug + (window.location.search ? window.location.search : '');
history.replaceState({url: newUrl}, null, window.location.protocol + '//' + window.location.host + config.relative_path + '/' + newUrl);
- topicTitle.fadeOut(250, function() {
+ topicTitle.fadeOut(250, function () {
topicTitle.html(data.topic.title).fadeIn(250);
});
- breadCrumb.fadeOut(250, function() {
+ breadCrumb.fadeOut(250, function () {
breadCrumb.html(data.topic.title).fadeIn(250);
});
- navbarTitle.fadeOut(250, function() {
+ navbarTitle.fadeOut(250, function () {
navbarTitle.html(data.topic.title).fadeIn(250);
});
}
- editedPostEl.fadeOut(250, function() {
+ editedPostEl.fadeOut(250, function () {
editedPostEl.html(translator.unescape(data.post.content));
editedPostEl.find('img:not(.not-responsive)').addClass('img-responsive');
app.replaceSelfLinks(editedPostEl.find('a'));
@@ -132,8 +132,8 @@ define('forum/topic/events', [
editedISO: utils.toISOString(data.post.edited)
};
- templates.parse('partials/topic/post-editor', editData, function(html) {
- translator.translate(html, function(translated) {
+ templates.parse('partials/topic/post-editor', editData, function (html) {
+ translator.translate(html, function (translated) {
html = $(translated);
editorEl.replaceWith(html);
html.find('.timeago').timeago();
@@ -143,10 +143,10 @@ define('forum/topic/events', [
});
if (data.topic.tags && tagsUpdated(data.topic.tags)) {
- templates.parse('partials/post_bar', 'tags', {tags: data.topic.tags}, function(html) {
+ templates.parse('partials/post_bar', 'tags', {tags: data.topic.tags}, function (html) {
var tags = $('.tags');
- tags.fadeOut(250, function() {
+ tags.fadeOut(250, function () {
tags.html(html).fadeIn(250);
});
});
@@ -158,7 +158,7 @@ define('forum/topic/events', [
return true;
}
- for (var i=0; i ');
var indent = ' ';
- category.children.forEach(function(childCategory) {
+ category.children.forEach(function (childCategory) {
if (!childCategory.link) {
buildRecursive(parentEl, childCategory, indent + level);
}
@@ -110,7 +110,7 @@ define('forum/topic/move', function() {
tids: Move.tids,
cid: selectedEl.attr('data-cid'),
currentCid: Move.currentCid
- }, function(err) {
+ }, function (err) {
modal.modal('hide');
if (err) {
diff --git a/public/src/client/topic/postTools.js b/public/src/client/topic/postTools.js
index b5095384da..d09325ebfd 100644
--- a/public/src/client/topic/postTools.js
+++ b/public/src/client/topic/postTools.js
@@ -2,13 +2,13 @@
/* globals define, app, ajaxify, bootbox, socket, templates, utils, config */
-define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator'], function(share, navigator, components, translator) {
+define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator'], function (share, navigator, components, translator) {
var PostTools = {};
var staleReplyAnyway = false;
- PostTools.init = function(tid) {
+ PostTools.init = function (tid) {
staleReplyAnyway = false;
renderMenu();
@@ -23,7 +23,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
};
function renderMenu() {
- $('[component="topic"]').on('show.bs.dropdown', '.moderator-tools', function() {
+ $('[component="topic"]').on('show.bs.dropdown', '.moderator-tools', function () {
var $this = $(this);
var dropdownMenu = $this.find('.dropdown-menu');
if (dropdownMenu.html()) {
@@ -33,14 +33,14 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
var pid = postEl.attr('data-pid');
var index = parseInt(postEl.attr('data-index'), 10);
- socket.emit('posts.loadPostTools', {pid: pid, cid: ajaxify.data.cid}, function(err, data) {
+ socket.emit('posts.loadPostTools', {pid: pid, cid: ajaxify.data.cid}, function (err, data) {
if (err) {
return app.alertError(err.message);
}
data.posts.display_move_tools = data.posts.display_move_tools && index !== 0;
- templates.parse('partials/topic/post-menu-list', data, function(html) {
- translator.translate(html, function(html) {
+ templates.parse('partials/topic/post-menu-list', data, function (html) {
+ translator.translate(html, function (html) {
dropdownMenu.html(html);
$(window).trigger('action:post.tools.load');
});
@@ -49,7 +49,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
});
}
- PostTools.toggle = function(pid, isDeleted) {
+ PostTools.toggle = function (pid, isDeleted) {
var postEl = components.get('post', 'pid', pid);
postEl.find('[component="post/quote"], [component="post/bookmark"], [component="post/reply"], [component="post/flag"], [component="user/chat"]')
@@ -62,7 +62,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
postEl.find('[component="post/tools"] .dropdown-menu').html('');
};
- PostTools.updatePostCount = function(postCount) {
+ PostTools.updatePostCount = function (postCount) {
var postCountEl = components.get('topic/post-count');
postCountEl.html(postCount).attr('title', postCount);
utils.makeNumbersHumanReadable(postCountEl);
@@ -71,9 +71,9 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
function addVoteHandler() {
components.get('topic').on('mouseenter', '[data-pid] [component="post/vote-count"]', loadDataAndCreateTooltip);
- components.get('topic').on('mouseout', '[data-pid] [component="post/vote-count"]', function() {
+ components.get('topic').on('mouseout', '[data-pid] [component="post/vote-count"]', function () {
var el = $(this).parent();
- el.on('shown.bs.tooltip', function() {
+ el.on('shown.bs.tooltip', function () {
$('.tooltip').tooltip('destroy');
el.off('shown.bs.tooltip');
});
@@ -92,7 +92,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
$('.tooltip').tooltip('destroy');
$this.off('mouseenter', loadDataAndCreateTooltip);
- socket.emit('posts.getUpvoters', [pid], function(err, data) {
+ socket.emit('posts.getUpvoters', [pid], function (err, data) {
if (err) {
return app.alertError(err.message);
}
@@ -115,7 +115,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
}
if (usernames.length + data.otherCount > 6) {
usernames = usernames.join(', ').replace(/,/g, '|');
- translator.translate('[[topic:users_and_others, ' + usernames + ', ' + data.otherCount + ']]', function(translated) {
+ translator.translate('[[topic:users_and_others, ' + usernames + ', ' + data.otherCount + ']]', function (translated) {
translated = translated.replace(/\|/g, ',');
doCreateTooltip(translated);
});
@@ -128,20 +128,20 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
function addPostHandlers(tid) {
var postContainer = components.get('topic');
- postContainer.on('click', '[component="post/quote"]', function() {
+ postContainer.on('click', '[component="post/quote"]', function () {
onQuoteClicked($(this), tid);
});
- postContainer.on('click', '[component="post/reply"]', function() {
+ postContainer.on('click', '[component="post/reply"]', function () {
onReplyClicked($(this), tid);
});
- $('.topic').on('click', '[component="topic/reply"]', function() {
+ $('.topic').on('click', '[component="topic/reply"]', function () {
onReplyClicked($(this), tid);
});
- $('.topic').on('click', '[component="topic/reply-as-topic"]', function() {
- translator.translate('[[topic:link_back, ' + ajaxify.data.titleRaw + ', ' + config.relative_path + '/topic/' + ajaxify.data.slug + ']]', function(body) {
+ $('.topic').on('click', '[component="topic/reply-as-topic"]', function () {
+ translator.translate('[[topic:link_back, ' + ajaxify.data.titleRaw + ', ' + config.relative_path + '/topic/' + ajaxify.data.slug + ']]', function (body) {
$(window).trigger('action:composer.topic.new', {
cid: ajaxify.data.cid,
body: body
@@ -149,30 +149,30 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
});
});
- postContainer.on('click', '[component="post/bookmark"]', function() {
+ postContainer.on('click', '[component="post/bookmark"]', function () {
bookmarkPost($(this), getData($(this), 'data-pid'));
});
- postContainer.on('click', '[component="post/upvote"]', function() {
+ postContainer.on('click', '[component="post/upvote"]', function () {
return toggleVote($(this), '.upvoted', 'posts.upvote');
});
- postContainer.on('click', '[component="post/downvote"]', function() {
+ postContainer.on('click', '[component="post/downvote"]', function () {
return toggleVote($(this), '.downvoted', 'posts.downvote');
});
- postContainer.on('click', '[component="post/vote-count"]', function() {
+ postContainer.on('click', '[component="post/vote-count"]', function () {
showVotes(getData($(this), 'data-pid'));
});
- postContainer.on('click', '[component="post/flag"]', function() {
+ postContainer.on('click', '[component="post/flag"]', function () {
var pid = getData($(this), 'data-pid');
- require(['forum/topic/flag'], function(flag) {
+ require(['forum/topic/flag'], function (flag) {
flag.showFlagModal(pid);
});
});
- postContainer.on('click', '[component="post/edit"]', function() {
+ postContainer.on('click', '[component="post/edit"]', function () {
var btn = $(this);
var timestamp = parseInt(getData(btn, 'data-timestamp'), 10);
@@ -185,7 +185,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
}
});
- postContainer.on('click', '[component="post/delete"]', function() {
+ postContainer.on('click', '[component="post/delete"]', function () {
var btn = $(this);
var timestamp = parseInt(getData(btn, 'data-timestamp'), 10);
var postDeleteDuration = parseInt(ajaxify.data.postDeleteDuration, 10);
@@ -226,19 +226,19 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
return true;
}
- postContainer.on('click', '[component="post/restore"]', function() {
+ postContainer.on('click', '[component="post/restore"]', function () {
togglePostDelete($(this), tid);
});
- postContainer.on('click', '[component="post/purge"]', function() {
+ postContainer.on('click', '[component="post/purge"]', function () {
purgePost($(this), tid);
});
- postContainer.on('click', '[component="post/move"]', function() {
+ postContainer.on('click', '[component="post/move"]', function () {
openMovePostModal($(this));
});
- postContainer.on('click', '[component="post/chat"]', function() {
+ postContainer.on('click', '[component="post/chat"]', function () {
openChat($(this));
});
}
@@ -246,7 +246,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
function onReplyClicked(button, tid) {
var selectedText = getSelectedText(button);
- showStaleWarning(function() {
+ showStaleWarning(function () {
var username = getUserName(button);
if (getData(button, 'data-uid') === '0' || !getData(button, 'data-userslug')) {
username = '';
@@ -278,7 +278,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
function onQuoteClicked(button, tid) {
var selectedText = getSelectedText(button);
- showStaleWarning(function() {
+ showStaleWarning(function () {
function quote(text) {
$(window).trigger('action:composer.addQuote', {
@@ -298,7 +298,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
if (selectedText) {
return quote(selectedText);
}
- socket.emit('posts.getRawPost', pid, function(err, post) {
+ socket.emit('posts.getRawPost', pid, function (err, post) {
if (err) {
return app.alertError(err.message);
}
@@ -336,7 +336,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
socket.emit(method, {
pid: pid,
room_id: app.currentRoom
- }, function(err) {
+ }, function (err) {
if (err) {
app.alertError(err.message);
}
@@ -352,7 +352,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
socket.emit(currentState ? 'posts.unvote' : method , {
pid: post.attr('data-pid'),
room_id: app.currentRoom
- }, function(err) {
+ }, function (err) {
if (err) {
if (err.message === 'self-vote') {
showVotes(post.attr('data-pid'));
@@ -366,7 +366,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
}
function showVotes(pid) {
- socket.emit('posts.getVoters', {pid: pid, cid: ajaxify.data.cid}, function(err, data) {
+ socket.emit('posts.getVoters', {pid: pid, cid: ajaxify.data.cid}, function (err, data) {
if (err) {
if (err.message === '[[error:no-privileges]]') {
return;
@@ -376,8 +376,8 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
return app.alertError(err.message);
}
- templates.parse('partials/modals/votes_modal', data, function(html) {
- translator.translate(html, function(translated) {
+ templates.parse('partials/modals/votes_modal', data, function (html) {
+ translator.translate(html, function (translated) {
var dialog = bootbox.dialog({
title: 'Voters',
message: translated,
@@ -385,7 +385,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
show: true
});
- dialog.on('click', function() {
+ dialog.on('click', function () {
dialog.modal('hide');
});
@@ -429,8 +429,8 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
}
function postAction(action, pid, tid) {
- translator.translate('[[topic:post_' + action + '_confirm]]', function(msg) {
- bootbox.confirm(msg, function(confirm) {
+ translator.translate('[[topic:post_' + action + '_confirm]]', function (msg) {
+ bootbox.confirm(msg, function (confirm) {
if (!confirm) {
return;
}
@@ -438,7 +438,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
socket.emit('posts.' + action, {
pid: pid,
tid: tid
- }, function(err) {
+ }, function (err) {
if (err) {
app.alertError(err.message);
}
@@ -448,28 +448,28 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
}
function openMovePostModal(button) {
- parseMoveModal(function(html) {
+ parseMoveModal(function (html) {
var moveModal = $(html);
var moveBtn = moveModal.find('#move_post_commit'),
topicId = moveModal.find('#topicId');
- moveModal.on('hidden.bs.modal', function() {
+ moveModal.on('hidden.bs.modal', function () {
moveModal.remove();
});
showMoveModal(moveModal);
- moveModal.find('.close, #move_post_cancel').on('click', function() {
+ moveModal.find('.close, #move_post_cancel').on('click', function () {
moveModal.addClass('hide');
});
- topicId.on('keyup change', function() {
+ topicId.on('keyup change', function () {
moveBtn.attr('disabled', !topicId.val());
});
- moveBtn.on('click', function() {
- movePost(button.parents('[data-pid]'), getData(button, 'data-pid'), topicId.val(), function() {
+ moveBtn.on('click', function () {
+ movePost(button.parents('[data-pid]'), getData(button, 'data-pid'), topicId.val(), function () {
moveModal.modal('hide');
topicId.val('');
});
@@ -479,7 +479,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
}
function parseMoveModal(callback) {
- templates.parse('partials/move_post_modal', {}, function(html) {
+ templates.parse('partials/move_post_modal', {}, function (html) {
translator.translate(html, callback);
});
}
@@ -493,13 +493,13 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
}
function movePost(post, pid, tid, callback) {
- socket.emit('posts.movePost', {pid: pid, tid: tid}, function(err) {
+ socket.emit('posts.movePost', {pid: pid, tid: tid}, function (err) {
if (err) {
app.alertError(err.message);
return callback();
}
- post.fadeOut(500, function() {
+ post.fadeOut(500, function () {
post.remove();
});
@@ -521,7 +521,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
return callback();
}
- translator.translate('[[topic:stale.warning]]', function(translated) {
+ translator.translate('[[topic:stale.warning]]', function (translated) {
var warning = bootbox.dialog({
title: '[[topic:stale.title]]',
message: translated,
@@ -529,7 +529,7 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
reply: {
label: '[[topic:stale.reply_anyway]]',
className: 'btn-link',
- callback: function() {
+ callback: function () {
staleReplyAnyway = true;
callback();
}
@@ -537,8 +537,8 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
create: {
label: '[[topic:stale.create]]',
className: 'btn-primary',
- callback: function() {
- translator.translate('[[topic:link_back, ' + ajaxify.data.title + ', ' + config.relative_path + '/topic/' + ajaxify.data.slug + ']]', function(body) {
+ callback: function () {
+ translator.translate('[[topic:link_back, ' + ajaxify.data.title + ', ' + config.relative_path + '/topic/' + ajaxify.data.slug + ']]', function (body) {
$(window).trigger('action:composer.topic.new', {
cid: ajaxify.data.cid,
body: body
diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.js
index 1c0d03eeb0..bc2d297112 100644
--- a/public/src/client/topic/posts.js
+++ b/public/src/client/topic/posts.js
@@ -8,13 +8,13 @@ define('forum/topic/posts', [
'forum/topic/postTools',
'navigator',
'components'
-], function(pagination, infinitescroll, postTools, navigator, components) {
+], function (pagination, infinitescroll, postTools, navigator, components) {
var Posts = {
_imageLoaderTimeout: undefined
};
- Posts.onNewPost = function(data) {
+ Posts.onNewPost = function (data) {
if (!data || !data.posts || !data.posts.length) {
return;
}
@@ -25,7 +25,7 @@ define('forum/topic/posts', [
data.loggedIn = app.user.uid ? true : false;
data.privileges = ajaxify.data.privileges;
- data.posts.forEach(function(post) {
+ data.posts.forEach(function (post) {
post.selfPost = !!app.user.uid && parseInt(post.uid, 10) === parseInt(app.user.uid, 10);
post.display_edit_tools = (ajaxify.data.privileges['posts:edit'] && post.selfPost) || ajaxify.data.privileges.isAdminOrMod;
post.display_delete_tools = (ajaxify.data.privileges['posts:delete'] && post.selfPost) || ajaxify.data.privileges.isAdminOrMod;
@@ -47,7 +47,7 @@ define('forum/topic/posts', [
};
function updatePostCounts(posts) {
- for (var i=0; i 1) {
- data.posts.forEach(function(post) {
+ data.posts.forEach(function (post) {
var p = components.get('post', 'pid', post.pid);
if (p.hasClass('new')) {
p.remove();
@@ -145,7 +145,7 @@ define('forum/topic/posts', [
});
}
- data.posts = data.posts.filter(function(post) {
+ data.posts = data.posts.filter(function (post) {
return $('[component="post"][data-pid="' + post.pid + '"]').length === 0;
});
}
@@ -168,9 +168,9 @@ define('forum/topic/posts', [
$(window).trigger('action:posts.loading', {posts: data.posts, after: after, before: before});
- app.parseAndTranslate('topic', 'posts', data, function(html) {
+ app.parseAndTranslate('topic', 'posts', data, function (html) {
- html = html.filter(function() {
+ html = html.filter(function () {
var pid = $(this).attr('data-pid');
return pid && $('[component="post"][data-pid="' + pid + '"]').length === 0;
});
@@ -200,12 +200,12 @@ define('forum/topic/posts', [
});
}
- Posts.loadMorePosts = function(direction) {
+ Posts.loadMorePosts = function (direction) {
if (!components.get('topic').length || navigator.scrollActive || Posts._infiniteScrollTimeout) {
return;
}
- Posts._infiniteScrollTimeout = setTimeout(function() {
+ Posts._infiniteScrollTimeout = setTimeout(function () {
delete Posts._infiniteScrollTimeout;
}, 1000);
var replies = components.get('post').not('[data-index=0]').not('.new');
@@ -239,7 +239,7 @@ define('forum/topic/posts', [
});
};
- Posts.processPage = function(posts) {
+ Posts.processPage = function (posts) {
Posts.unloadImages(posts);
Posts.showBottomPostBar();
posts.find('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
@@ -253,11 +253,11 @@ define('forum/topic/posts', [
hidePostToolsForDeletedPosts(posts);
};
- Posts.unloadImages = function(posts) {
+ Posts.unloadImages = function (posts) {
var images = posts.find('[component="post/content"] img:not(.not-responsive)');
if (config.delayImageLoading) {
- images.each(function() {
+ images.each(function () {
$(this).attr('data-src', $(this).attr('src'));
}).attr('data-state', 'unloaded').attr('src', 'about:blank');
} else {
@@ -266,12 +266,12 @@ define('forum/topic/posts', [
}
};
- Posts.loadImages = function(threshold) {
+ Posts.loadImages = function (threshold) {
if (Posts._imageLoaderTimeout) {
clearTimeout(Posts._imageLoaderTimeout);
}
- Posts._imageLoaderTimeout = setTimeout(function() {
+ Posts._imageLoaderTimeout = setTimeout(function () {
/*
If threshold is defined, images loaded above this threshold will modify
the user's scroll position so they are not scrolled away from content
@@ -282,16 +282,16 @@ define('forum/topic/posts', [
*/
var images = components.get('post/content').find('img[data-state="unloaded"]'),
- visible = images.filter(function() {
+ visible = images.filter(function () {
return utils.isElementInViewport(this);
}),
- posts = $.unique(visible.map(function() {
+ posts = $.unique(visible.map(function () {
return $(this).parents('[component="post"]').get(0);
})),
scrollTop = $(window).scrollTop(),
adjusting = false,
adjustQueue = [],
- adjustPosition = function() {
+ adjustPosition = function () {
adjusting = true;
oldHeight = document.body.clientHeight;
@@ -318,10 +318,10 @@ define('forum/topic/posts', [
// For each image, reset the source and adjust scrollTop when loaded
visible.attr('data-state', 'loading');
- visible.each(function(index, image) {
+ visible.each(function (index, image) {
image = $(image);
- image.on('load', function() {
+ image.on('load', function () {
if (!adjusting) {
adjustPosition.call(this);
} else {
@@ -335,8 +335,8 @@ define('forum/topic/posts', [
}, 250);
};
- Posts.wrapImagesInLinks = function(posts) {
- posts.find('[component="post/content"] img:not(.emoji)').each(function() {
+ Posts.wrapImagesInLinks = function (posts) {
+ posts.find('[component="post/content"] img:not(.emoji)').each(function () {
var $this = $(this),
src = $this.attr('src'),
suffixRegex = /-resized(\.[\w]+)?$/;
@@ -355,7 +355,7 @@ define('forum/topic/posts', [
});
};
- Posts.showBottomPostBar = function() {
+ Posts.showBottomPostBar = function () {
var mainPost = components.get('post', 'index', 0);
var placeHolder = $('.post-bar-placeholder');
var posts = $('[component="post"]');
@@ -368,7 +368,7 @@ define('forum/topic/posts', [
};
function hidePostToolsForDeletedPosts(posts) {
- posts.each(function() {
+ posts.each(function () {
if ($(this).hasClass('deleted')) {
postTools.toggle($(this).attr('data-pid'), true);
}
@@ -376,7 +376,7 @@ define('forum/topic/posts', [
}
function addBlockquoteEllipses(blockquotes) {
- blockquotes.each(function() {
+ blockquotes.each(function () {
var $this = $(this);
if ($this.find(':hidden:not(br)').length && !$this.find('.toggle').length) {
$this.append(' ');
diff --git a/public/src/client/topic/threadTools.js b/public/src/client/topic/threadTools.js
index a18c069cd5..7eef6306a3 100644
--- a/public/src/client/topic/threadTools.js
+++ b/public/src/client/topic/threadTools.js
@@ -8,53 +8,53 @@ define('forum/topic/threadTools', [
'forum/topic/delete-posts',
'components',
'translator'
-], function(fork, move, deletePosts, components, translator) {
+], function (fork, move, deletePosts, components, translator) {
var ThreadTools = {};
- ThreadTools.init = function(tid) {
+ ThreadTools.init = function (tid) {
renderMenu();
var topicContainer = $('.topic');
- topicContainer.on('click', '[component="topic/delete"]', function() {
+ topicContainer.on('click', '[component="topic/delete"]', function () {
topicCommand('delete', tid);
return false;
});
- topicContainer.on('click', '[component="topic/restore"]', function() {
+ topicContainer.on('click', '[component="topic/restore"]', function () {
topicCommand('restore', tid);
return false;
});
- topicContainer.on('click', '[component="topic/purge"]', function() {
+ topicContainer.on('click', '[component="topic/purge"]', function () {
topicCommand('purge', tid);
return false;
});
- topicContainer.on('click', '[component="topic/lock"]', function() {
+ topicContainer.on('click', '[component="topic/lock"]', function () {
socket.emit('topics.lock', {tids: [tid], cid: ajaxify.data.cid});
return false;
});
- topicContainer.on('click', '[component="topic/unlock"]', function() {
+ topicContainer.on('click', '[component="topic/unlock"]', function () {
socket.emit('topics.unlock', {tids: [tid], cid: ajaxify.data.cid});
return false;
});
- topicContainer.on('click', '[component="topic/pin"]', function() {
+ topicContainer.on('click', '[component="topic/pin"]', function () {
socket.emit('topics.pin', {tids: [tid], cid: ajaxify.data.cid});
return false;
});
- topicContainer.on('click', '[component="topic/unpin"]', function() {
+ topicContainer.on('click', '[component="topic/unpin"]', function () {
socket.emit('topics.unpin', {tids: [tid], cid: ajaxify.data.cid});
return false;
});
- topicContainer.on('click', '[component="topic/mark-unread"]', function() {
- socket.emit('topics.markUnread', tid, function(err) {
+ topicContainer.on('click', '[component="topic/mark-unread"]', function () {
+ socket.emit('topics.markUnread', tid, function (err) {
if (err) {
return app.alertError(err);
}
@@ -63,9 +63,9 @@ define('forum/topic/threadTools', [
return false;
});
- topicContainer.on('click', '[component="topic/mark-unread-for-all"]', function() {
+ topicContainer.on('click', '[component="topic/mark-unread-for-all"]', function () {
var btn = $(this);
- socket.emit('topics.markAsUnreadForAll', [tid], function(err) {
+ socket.emit('topics.markAsUnreadForAll', [tid], function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -75,7 +75,7 @@ define('forum/topic/threadTools', [
return false;
});
- topicContainer.on('click', '[component="topic/move"]', function() {
+ topicContainer.on('click', '[component="topic/move"]', function () {
move.init([tid], ajaxify.data.cid);
return false;
});
@@ -83,18 +83,18 @@ define('forum/topic/threadTools', [
deletePosts.init();
fork.init();
- $('.topic').on('click', '[component="topic/following"]', function() {
+ $('.topic').on('click', '[component="topic/following"]', function () {
changeWatching('follow');
});
- $('.topic').on('click', '[component="topic/not-following"]', function() {
+ $('.topic').on('click', '[component="topic/not-following"]', function () {
changeWatching('unfollow');
});
- $('.topic').on('click', '[component="topic/ignoring"]', function() {
+ $('.topic').on('click', '[component="topic/ignoring"]', function () {
changeWatching('ignore');
});
function changeWatching(type) {
- socket.emit('topics.changeWatching', {tid: tid, type: type}, function(err) {
+ socket.emit('topics.changeWatching', {tid: tid, type: type}, function (err) {
if (err) {
return app.alert({
type: 'danger',
@@ -136,13 +136,13 @@ define('forum/topic/threadTools', [
return;
}
- socket.emit('topics.loadTopicTools', {tid: ajaxify.data.tid, cid: ajaxify.data.cid}, function(err, data) {
+ socket.emit('topics.loadTopicTools', {tid: ajaxify.data.tid, cid: ajaxify.data.cid}, function (err, data) {
if (err) {
return app.alertError(err);
}
- templates.parse('partials/topic/topic-menu-list', data, function(html) {
- translator.translate(html, function(html) {
+ templates.parse('partials/topic/topic-menu-list', data, function (html) {
+ translator.translate(html, function (html) {
dropdownMenu.html(html);
$(window).trigger('action:topic.tools.load');
});
@@ -152,13 +152,13 @@ define('forum/topic/threadTools', [
}
function topicCommand(command, tid) {
- translator.translate('[[topic:thread_tools.' + command + '_confirm]]', function(msg) {
- bootbox.confirm(msg, function(confirm) {
+ translator.translate('[[topic:thread_tools.' + command + '_confirm]]', function (msg) {
+ bootbox.confirm(msg, function (confirm) {
if (!confirm) {
return;
}
- socket.emit('topics.' + command, {tids: [tid], cid: ajaxify.data.cid}, function(err) {
+ socket.emit('topics.' + command, {tids: [tid], cid: ajaxify.data.cid}, function (err) {
if (err) {
app.alertError(err.message);
}
@@ -167,7 +167,7 @@ define('forum/topic/threadTools', [
});
}
- ThreadTools.setLockedState = function(data) {
+ ThreadTools.setLockedState = function (data) {
var threadEl = components.get('topic');
if (parseInt(data.tid, 10) !== parseInt(threadEl.attr('data-tid'), 10)) {
return;
@@ -186,14 +186,14 @@ define('forum/topic/threadTools', [
threadEl.find('[component="post"]:not(.deleted) [component="post/reply"], [component="post"]:not(.deleted) [component="post/quote"]').toggleClass('hidden', hideReply);
threadEl.find('[component="post/edit"], [component="post/delete"]').toggleClass('hidden', isLocked);
- threadEl.find('[component="post"][data-uid="'+app.user.uid+'"].deleted [component="post/tools"]').toggleClass('hidden', isLocked);
+ threadEl.find('[component="post"][data-uid="' + app.user.uid + '"].deleted [component="post/tools"]').toggleClass('hidden', isLocked);
$('[component="post/header"] i.fa-lock').toggleClass('hidden', !data.isLocked);
$('[component="post/tools"] .dropdown-menu').html('');
ajaxify.data.locked = data.isLocked;
};
- ThreadTools.setDeleteState = function(data) {
+ ThreadTools.setDeleteState = function (data) {
var threadEl = components.get('topic');
if (parseInt(data.tid, 10) !== parseInt(threadEl.attr('data-tid'), 10)) {
return;
@@ -215,7 +215,7 @@ define('forum/topic/threadTools', [
};
- ThreadTools.setPinnedState = function(data) {
+ ThreadTools.setPinnedState = function (data) {
var threadEl = components.get('topic');
if (parseInt(data.tid, 10) !== parseInt(threadEl.attr('data-tid'), 10)) {
return;
diff --git a/public/src/client/unread.js b/public/src/client/unread.js
index 4984d398b0..e185788981 100644
--- a/public/src/client/unread.js
+++ b/public/src/client/unread.js
@@ -2,19 +2,19 @@
/* globals define, app, socket */
-define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll', 'components'], function(recent, topicSelect, infinitescroll, components) {
+define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll', 'components'], function (recent, topicSelect, infinitescroll, components) {
var Unread = {};
- $(window).on('action:ajaxify.start', function(ev, data) {
+ $(window).on('action:ajaxify.start', function (ev, data) {
if (ajaxify.currentPage !== data.url) {
recent.removeListeners();
}
});
- Unread.init = function() {
+ Unread.init = function () {
app.enterRoom('unread_topics');
- $('#new-topics-alert').on('click', function() {
+ $('#new-topics-alert').on('click', function () {
$(this).addClass('hide');
});
@@ -22,12 +22,12 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll', '
$(window).trigger('action:topics.loaded', {topics: ajaxify.data.topics});
- $('#markSelectedRead').on('click', function() {
+ $('#markSelectedRead').on('click', function () {
var tids = topicSelect.getSelectedTids();
if(!tids.length) {
return;
}
- socket.emit('topics.markAsRead', tids, function(err) {
+ socket.emit('topics.markAsRead', tids, function (err) {
if(err) {
return app.alertError(err.message);
}
@@ -36,8 +36,8 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll', '
});
});
- $('#markAllRead').on('click', function() {
- socket.emit('topics.markAllRead', function(err) {
+ $('#markAllRead').on('click', function () {
+ socket.emit('topics.markAllRead', function (err) {
if(err) {
return app.alertError(err.message);
}
@@ -51,10 +51,10 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll', '
});
});
- $('.markread').on('click', '.category', function() {
+ $('.markread').on('click', '.category', function () {
function getCategoryTids(cid) {
var tids = [];
- components.get('category/topic', 'cid', cid).each(function() {
+ components.get('category/topic', 'cid', cid).each(function () {
tids.push($(this).attr('data-tid'));
});
return tids;
@@ -62,7 +62,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll', '
var cid = $(this).attr('data-cid');
var tids = getCategoryTids(cid);
- socket.emit('topics.markCategoryTopicsRead', cid, function(err) {
+ socket.emit('topics.markCategoryTopicsRead', cid, function (err) {
if(err) {
return app.alertError(err.message);
}
@@ -77,7 +77,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll', '
$('#load-more-btn').show();
}
- $('#load-more-btn').on('click', function() {
+ $('#load-more-btn').on('click', function () {
loadMoreTopics();
});
@@ -95,7 +95,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll', '
after: $('[component="category"]').attr('data-nextstart'),
cid: cid,
filter: ajaxify.data.selectedFilter.filter
- }, function(data, done) {
+ }, function (data, done) {
if (data.topics && data.topics.length) {
recent.onTopicsLoaded('unread', data.topics, true, done);
$('[component="category"]').attr('data-nextstart', data.nextStart);
@@ -119,7 +119,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll', '
}
function removeTids(tids) {
- for(var i=0; i').html(user.username).text()
return user && {
label: username,
@@ -42,21 +42,21 @@ define('autocomplete', function() {
});
};
- module.group = function(input, onselect) {
- app.loadJQueryUI(function() {
+ module.group = function (input, onselect) {
+ app.loadJQueryUI(function () {
input.autocomplete({
delay: 200,
select: onselect,
- source: function(request, response) {
+ source: function (request, response) {
socket.emit('groups.search', {
query: request.term
- }, function(err, results) {
+ }, function (err, results) {
if (err) {
return app.alertError(err.message);
}
if (results && results.length) {
- var names = results.map(function(group) {
+ var names = results.map(function (group) {
return group && {
label: group.name,
value: group.name,
diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js
index a856f3d88c..af7ef0fff3 100644
--- a/public/src/modules/chat.js
+++ b/public/src/modules/chat.js
@@ -9,16 +9,16 @@ define('chat', [
'forum/chats',
'forum/chats/messages',
'translator'
-], function(components, taskbar, S, sounds, Chats, ChatsMessages, translator) {
+], function (components, taskbar, S, sounds, Chats, ChatsMessages, translator) {
var module = {};
var newMessage = false;
- module.prepareDOM = function() {
+ module.prepareDOM = function () {
var chatsToggleEl = components.get('chat/dropdown');
var chatsListEl = components.get('chat/list');
- chatsToggleEl.on('click', function() {
+ chatsToggleEl.on('click', function () {
if (chatsToggleEl.parent().hasClass('open')) {
return;
}
@@ -26,7 +26,7 @@ define('chat', [
module.loadChatsDropdown(chatsListEl);
});
- chatsListEl.on('click', '[data-roomid]', function(ev) {
+ chatsListEl.on('click', '[data-roomid]', function (ev) {
if ($(ev.target).parents('.user-link').length) {
return;
}
@@ -38,15 +38,15 @@ define('chat', [
}
});
- $('[component="chats/mark-all-read"]').on('click', function() {
- socket.emit('modules.chats.markAllRead', function(err) {
+ $('[component="chats/mark-all-read"]').on('click', function () {
+ socket.emit('modules.chats.markAllRead', function (err) {
if (err) {
return app.alertError(err);
}
});
});
- socket.on('event:chats.receive', function(data) {
+ socket.on('event:chats.receive', function (data) {
var username = data.message.fromUser.username;
var isSelf = data.self === 1;
data.message.self = data.self;
@@ -75,16 +75,16 @@ define('chat', [
});
}
} else {
- socket.emit('modules.chats.loadRoom', {roomId: data.roomId}, function(err, roomData) {
+ socket.emit('modules.chats.loadRoom', {roomId: data.roomId}, function (err, roomData) {
if (err) {
return app.alertError(err.message);
}
- roomData.users = roomData.users.filter(function(user) {
+ roomData.users = roomData.users.filter(function (user) {
return user && parseInt(user.uid, 10) !== parseInt(app.user.uid, 10);
});
roomData.silent = true;
roomData.uid = app.user.uid;
- module.createModal(roomData, function(modal) {
+ module.createModal(roomData, function (modal) {
module.toggleNew(modal.attr('UUID'), !isSelf, true);
if (!isSelf) {
app.alternatingTitle('[[modules:chat.user_has_messaged_you, ' + username + ']]');
@@ -95,32 +95,32 @@ define('chat', [
}
});
- socket.on('event:user_status_change', function(data) {
+ socket.on('event:user_status_change', function (data) {
var modal = module.getModal(data.uid);
app.updateUserStatus(modal.find('[component="user/status"]'), data.status);
});
- socket.on('event:chats.roomRename', function(data) {
+ socket.on('event:chats.roomRename', function (data) {
module.getModal(data.roomId).find('[component="chat/room/name"]').val($('
').html(data.newName).text());
});
ChatsMessages.onChatMessageEdit();
};
- module.loadChatsDropdown = function(chatsListEl) {
- socket.emit('modules.chats.getRecentChats', {uid: app.user.uid, after: 0}, function(err, data) {
+ module.loadChatsDropdown = function (chatsListEl) {
+ socket.emit('modules.chats.getRecentChats', {uid: app.user.uid, after: 0}, function (err, data) {
if (err) {
return app.alertError(err.message);
}
- var rooms = data.rooms.filter(function(room) {
+ var rooms = data.rooms.filter(function (room) {
return room.teaser;
});
templates.parse('partials/chat_dropdown', {
rooms: rooms
- }, function(html) {
- translator.translate(html, function(translated) {
+ }, function (html) {
+ translator.translate(html, function (translated) {
chatsListEl.empty().html(translated);
app.createUserTooltips(chatsListEl, 'right');
});
@@ -128,7 +128,7 @@ define('chat', [
});
};
- module.bringModalToTop = function(chatModal) {
+ module.bringModalToTop = function (chatModal) {
var topZ = 0;
taskbar.updateActive(chatModal.attr('UUID'));
@@ -136,7 +136,7 @@ define('chat', [
if ($('.chat-modal').length === 1) {
return;
}
- $('.chat-modal').each(function() {
+ $('.chat-modal').each(function () {
var thisZ = parseInt($(this).css('zIndex'), 10);
if (thisZ > topZ) {
topZ = thisZ;
@@ -146,16 +146,16 @@ define('chat', [
chatModal.css('zIndex', topZ + 1);
};
- module.getModal = function(roomId) {
+ module.getModal = function (roomId) {
return $('#chat-modal-' + roomId);
};
- module.modalExists = function(roomId) {
+ module.modalExists = function (roomId) {
return $('#chat-modal-' + roomId).length !== 0;
};
- module.createModal = function(data, callback) {
- app.parseAndTranslate('chat', data, function(chatModal) {
+ module.createModal = function (data, callback) {
+ app.parseAndTranslate('chat', data, function (chatModal) {
var uuid = utils.generateUUID();
var dragged = false;
@@ -170,14 +170,14 @@ define('chat', [
chatModal.find('.timeago').timeago();
module.center(chatModal);
- app.loadJQueryUI(function() {
+ app.loadJQueryUI(function () {
chatModal.find('.modal-content').resizable({
handles: 'n, e, s, w, se',
minHeight: 250,
minWidth: 400
});
- chatModal.find('.modal-content').on('resize', function(event, ui) {
+ chatModal.find('.modal-content').on('resize', function (event, ui) {
if (ui.originalSize.height === ui.size.height) {
return;
}
@@ -186,10 +186,10 @@ define('chat', [
});
chatModal.draggable({
- start:function() {
+ start:function () {
module.bringModalToTop(chatModal);
},
- stop:function() {
+ stop:function () {
chatModal.find('#chat-message-input').focus();
},
distance: 10,
@@ -197,13 +197,13 @@ define('chat', [
});
});
- chatModal.find('#chat-close-btn').on('click', function() {
+ chatModal.find('#chat-close-btn').on('click', function () {
module.close(chatModal);
});
function gotoChats() {
var text = components.get('chat/input').val();
- $(window).one('action:ajaxify.end', function() {
+ $(window).one('action:ajaxify.end', function () {
components.get('chat/input').val(text);
});
@@ -214,7 +214,7 @@ define('chat', [
chatModal.find('.modal-header').on('dblclick', gotoChats);
chatModal.find('button[data-action="maximize"]').on('click', gotoChats);
- chatModal.on('click', function() {
+ chatModal.on('click', function () {
module.bringModalToTop(chatModal);
if (dragged) {
@@ -222,13 +222,13 @@ define('chat', [
}
});
- chatModal.on('mousemove', function(e) {
+ chatModal.on('mousemove', function (e) {
if (e.which === 1) {
dragged = true;
}
});
- chatModal.on('mousemove keypress click', function() {
+ chatModal.on('mousemove keypress click', function () {
if (newMessage) {
socket.emit('modules.chats.markRead', data.roomId);
newMessage = false;
@@ -237,7 +237,7 @@ define('chat', [
Chats.addEditDeleteHandler(chatModal.find('[component="chat/messages"]'), data.roomId);
- chatModal.find('[component="chat/controlsToggle"]').on('click', function() {
+ chatModal.find('[component="chat/controlsToggle"]').on('click', function () {
var messagesEl = chatModal.find('[component="chat/messages"]');
chatModal.find('[component="chat/controls"]').toggle();
@@ -268,11 +268,11 @@ define('chat', [
});
};
- module.focusInput = function(chatModal) {
+ module.focusInput = function (chatModal) {
chatModal.find('#chat-message-input').focus();
};
- module.close = function(chatModal) {
+ module.close = function (chatModal) {
clearInterval(chatModal.attr('intervalId'));
chatModal.attr('intervalId', 0);
chatModal.remove();
@@ -284,7 +284,7 @@ define('chat', [
}
};
- module.center = function(chatModal) {
+ module.center = function (chatModal) {
var hideAfter = false;
if (chatModal.hasClass('hide')) {
chatModal.removeClass('hide');
@@ -299,7 +299,7 @@ define('chat', [
return chatModal;
};
- module.load = function(uuid) {
+ module.load = function (uuid) {
var chatModal = $('div[UUID="' + uuid + '"]');
chatModal.removeClass('hide');
taskbar.updateActive(uuid);
@@ -314,22 +314,22 @@ define('chat', [
}
};
- module.enableMobileBehaviour = function(modalEl) {
+ module.enableMobileBehaviour = function (modalEl) {
app.toggleNavbar(false);
modalEl.attr('data-mobile', '1');
var messagesEl = modalEl.find('.chat-content');
messagesEl.css('height', module.calculateChatListHeight(modalEl));
- $(window).on('resize', function() {
+ $(window).on('resize', function () {
messagesEl.css('height', module.calculateChatListHeight(modalEl));
});
};
- module.disableMobileBehaviour = function() {
+ module.disableMobileBehaviour = function () {
app.toggleNavbar(true);
};
- module.calculateChatListHeight = function(modalEl) {
+ module.calculateChatListHeight = function (modalEl) {
var totalHeight = modalEl.find('.modal-content').outerHeight() - modalEl.find('.modal-header').outerHeight();
var padding = parseInt(modalEl.find('.modal-body').css('padding-top'), 10) + parseInt(modalEl.find('.modal-body').css('padding-bottom'), 10);
var contentMargin = parseInt(modalEl.find('.chat-content').css('margin-top'), 10) + parseInt(modalEl.find('.chat-content').css('margin-bottom'), 10);
@@ -338,7 +338,7 @@ define('chat', [
return totalHeight - padding - contentMargin - inputGroupHeight;
};
- module.minimize = function(uuid) {
+ module.minimize = function (uuid) {
var chatModal = $('div[UUID="' + uuid + '"]');
chatModal.addClass('hide');
taskbar.minimize('chat', uuid);
diff --git a/public/src/modules/components.js b/public/src/modules/components.js
index 4a08e4073c..ef936d0f75 100644
--- a/public/src/modules/components.js
+++ b/public/src/modules/components.js
@@ -1,61 +1,61 @@
"use strict";
-define('components', function() {
+define('components', function () {
var components = {};
components.core = {
- 'topic/teaser': function(tid) {
+ 'topic/teaser': function (tid) {
if (tid) {
return $('[component="category/topic"][data-tid="' + tid + '"] [component="topic/teaser"]');
} else {
return $('[component="topic/teaser"]');
}
},
- 'topic': function(name, value) {
+ 'topic': function (name, value) {
return $('[component="topic"][data-' + name + '="' + value + '"]');
},
- 'post': function(name, value) {
+ 'post': function (name, value) {
return $('[component="post"][data-' + name + '="' + value + '"]');
},
- 'post/content': function(pid) {
+ 'post/content': function (pid) {
return components.core.post('pid', pid).find('[component="post/content"]');
},
- 'post/header': function(pid) {
+ 'post/header': function (pid) {
return components.core.post('pid', pid).find('[component="post/header"]');
},
- 'post/anchor': function(index) {
+ 'post/anchor': function (index) {
return components.core.post('index', index).find('[component="post/anchor"]');
},
- 'post/vote-count': function(pid) {
+ 'post/vote-count': function (pid) {
return components.core.post('pid', pid).find('[component="post/vote-count"]');
},
- 'post/bookmark-count': function(pid) {
+ 'post/bookmark-count': function (pid) {
return components.core.post('pid', pid).find('[component="post/bookmark-count"]');
},
- 'user/postcount': function(uid) {
+ 'user/postcount': function (uid) {
return $('[component="user/postcount"][data-uid="' + uid + '"]');
},
- 'user/reputation': function(uid) {
+ 'user/reputation': function (uid) {
return $('[component="user/reputation"][data-uid="' + uid + '"]');
},
- 'category/topic': function(name, value) {
+ 'category/topic': function (name, value) {
return $('[component="category/topic"][data-' + name + '="' + value + '"]');
},
- 'categories/category': function(name, value) {
+ 'categories/category': function (name, value) {
return $('[component="categories/category"][data-' + name + '="' + value + '"]');
},
- 'chat/message': function(messageId) {
+ 'chat/message': function (messageId) {
return $('[component="chat/message"][data-mid="' + messageId + '"]');
},
- 'chat/message/body': function(messageId) {
+ 'chat/message/body': function (messageId) {
return $('[component="chat/message"][data-mid="' + messageId + '"] [component="chat/message/body"]');
}
};
- components.get = function() {
+ components.get = function () {
var args = Array.prototype.slice.call(arguments, 1);
if (components.core[arguments[0]] && args.length) {
diff --git a/public/src/modules/coverPhoto.js b/public/src/modules/coverPhoto.js
index 6a45732c9b..fa6bdc4d7d 100644
--- a/public/src/modules/coverPhoto.js
+++ b/public/src/modules/coverPhoto.js
@@ -3,19 +3,19 @@
define('coverPhoto', [
'vendor/jquery/draggable-background/backgroundDraggable'
-], function() {
+], function () {
var coverPhoto = {
coverEl: null,
saveFn: null
};
- coverPhoto.init = function(coverEl, saveFn, uploadFn, removeFn) {
+ coverPhoto.init = function (coverEl, saveFn, uploadFn, removeFn) {
coverPhoto.coverEl = coverEl;
coverPhoto.saveFn = saveFn;
coverEl.find('.upload').on('click', uploadFn);
- coverEl.find('.resize').on('click', function() {
+ coverEl.find('.resize').on('click', function () {
enableDragging(coverEl);
});
coverEl.find('.remove').on('click', removeFn);
@@ -28,13 +28,13 @@ define('coverPhoto', [
coverEl.addClass('initialised');
};
- coverPhoto.onDragOver = function(e) {
+ coverPhoto.onDragOver = function (e) {
e.stopPropagation();
e.preventDefault();
e.originalEvent.dataTransfer.dropEffect = 'copy';
};
- coverPhoto.onDrop = function(e) {
+ coverPhoto.onDrop = function (e) {
e.stopPropagation();
e.preventDefault();
@@ -42,7 +42,7 @@ define('coverPhoto', [
reader = new FileReader();
if (files.length && files[0].type.match('image.*')) {
- reader.onload = function(e) {
+ reader.onload = function (e) {
coverPhoto.coverEl.css('background-image', 'url(' + e.target.result + ')');
coverPhoto.newCover = e.target.result;
};
@@ -67,10 +67,10 @@ define('coverPhoto', [
});
}
- coverPhoto.save = function() {
+ coverPhoto.save = function () {
coverPhoto.coverEl.addClass('saving');
- coverPhoto.saveFn(coverPhoto.newCover || undefined, coverPhoto.coverEl.css('background-position'), function(err) {
+ coverPhoto.saveFn(coverPhoto.newCover || undefined, coverPhoto.coverEl.css('background-position'), function (err) {
if (!err) {
coverPhoto.coverEl.toggleClass('active', 0);
coverPhoto.coverEl.backgroundDraggable('disable');
diff --git a/public/src/modules/helpers.js b/public/src/modules/helpers.js
index 7250fab3b6..5de0cdbb3b 100644
--- a/public/src/modules/helpers.js
+++ b/public/src/modules/helpers.js
@@ -1,4 +1,4 @@
-;(function(exports) {
+;(function (exports) {
"use strict";
/* globals define, utils, config */
@@ -9,7 +9,7 @@
var helpers = {};
- helpers.displayMenuItem = function(data, index) {
+ helpers.displayMenuItem = function (data, index) {
var item = data.navigation[index];
if (!item) {
return false;
@@ -36,7 +36,7 @@
return true;
};
- helpers.buildMetaTag = function(tag) {
+ helpers.buildMetaTag = function (tag) {
var name = tag.name ? 'name="' + tag.name + '" ' : '',
property = tag.property ? 'property="' + tag.property + '" ' : '',
content = tag.content ? 'content="' + tag.content.replace(/\n/g, ' ') + '" ' : '';
@@ -44,7 +44,7 @@
return ' \n\t';
};
- helpers.buildLinkTag = function(tag) {
+ helpers.buildLinkTag = function (tag) {
var link = tag.link ? 'link="' + tag.link + '" ' : '',
rel = tag.rel ? 'rel="' + tag.rel + '" ' : '',
type = tag.type ? 'type="' + tag.type + '" ' : '',
@@ -54,12 +54,12 @@
return ' \n\t';
};
- helpers.stringify = function(obj) {
+ helpers.stringify = function (obj) {
// Turns the incoming object into a JSON string
return JSON.stringify(obj).replace(/&/gm,"&").replace(//gm,">").replace(/"/g, '"');
};
- helpers.escape = function(str) {
+ helpers.escape = function (str) {
if (typeof utils !== 'undefined') {
return utils.escapeHTML(str);
} else {
@@ -67,7 +67,7 @@
}
};
- helpers.stripTags = function(str) {
+ helpers.stripTags = function (str) {
if (typeof S !== 'undefined') {
return S(str).stripTags().s;
} else {
@@ -76,7 +76,7 @@
}
};
- helpers.generateCategoryBackground = function(category) {
+ helpers.generateCategoryBackground = function (category) {
if (!category) {
return '';
}
@@ -100,13 +100,13 @@
return style.join('; ') + ';';
};
- helpers.generateChildrenCategories = function(category) {
+ helpers.generateChildrenCategories = function (category) {
var html = '';
var relative_path = (typeof config !== 'undefined' ? config.relative_path : require('nconf').get('relative_path'));
if (!category || !category.children) {
return html;
}
- category.children.forEach(function(child) {
+ category.children.forEach(function (child) {
if (!child) {
return;
}
@@ -121,7 +121,7 @@
return html;
};
- helpers.generateTopicClass = function(topic) {
+ helpers.generateTopicClass = function (topic) {
var style = [];
if (topic.locked) {
@@ -143,16 +143,16 @@
return style.join(' ');
};
- helpers.getBookmarkFromIndex = function(topic) {
+ helpers.getBookmarkFromIndex = function (topic) {
return (topic.index || 0) + 1;
};
- helpers.displayUserSearch = function(data, allowGuestUserSearching) {
+ helpers.displayUserSearch = function (data, allowGuestUserSearching) {
return data.loggedIn || allowGuestUserSearching === 'true';
};
// Groups helpers
- helpers.membershipBtn = function(groupObj) {
+ helpers.membershipBtn = function (groupObj) {
if (groupObj.name === 'administrators') {
return '';
}
@@ -172,7 +172,7 @@
}
};
- helpers.spawnPrivilegeStates = function(member, privileges) {
+ helpers.spawnPrivilegeStates = function (member, privileges) {
var states = [];
for(var priv in privileges) {
if (privileges.hasOwnProperty(priv)) {
@@ -182,16 +182,16 @@
});
}
}
- return states.map(function(priv) {
+ return states.map(function (priv) {
return ' ';
}).join('');
};
- helpers.localeToHTML = function(locale) {
+ helpers.localeToHTML = function (locale) {
return locale.replace('_', '-');
};
- helpers.renderTopicImage = function(topicObj) {
+ helpers.renderTopicImage = function (topicObj) {
if (topicObj.thumb) {
return ' ';
} else {
@@ -199,7 +199,7 @@
}
};
- helpers.renderDigestAvatar = function(block) {
+ helpers.renderDigestAvatar = function (block) {
if (block.teaser) {
if (block.teaser.user.picture) {
return ' ';
@@ -215,7 +215,7 @@
}
};
- helpers.userAgentIcons = function(data) {
+ helpers.userAgentIcons = function (data) {
var icons = '';
switch(data.platform) {
@@ -267,7 +267,7 @@
return icons;
};
- exports.register = function() {
+ exports.register = function () {
var templates;
if (typeof module === 'object') {
@@ -276,7 +276,7 @@
templates = window.templates;
}
- Object.keys(helpers).forEach(function(helperName) {
+ Object.keys(helpers).forEach(function (helperName) {
templates.registerHelper(helperName, helpers[helperName]);
});
};
@@ -286,8 +286,8 @@
define('helpers', exports);
}
-})(
+}(
typeof exports === 'object' ? exports :
typeof define === 'function' && define.amd ? {} :
helpers = {}
-);
+));
diff --git a/public/src/modules/iconSelect.js b/public/src/modules/iconSelect.js
index 00804d1616..34a7d595ce 100644
--- a/public/src/modules/iconSelect.js
+++ b/public/src/modules/iconSelect.js
@@ -2,11 +2,11 @@
/* globals define, bootbox, templates */
-define('iconSelect', function() {
+define('iconSelect', function () {
var iconSelect = {};
- iconSelect.init = function(el, onModified) {
- onModified = onModified || function() {};
+ iconSelect.init = function (el, onModified) {
+ onModified = onModified || function () {};
var doubleSize = el.hasClass('fa-2x'),
selected = el.attr('class').replace('fa-2x', '').replace('fa', '').replace(/\s+/g, '');
@@ -16,7 +16,7 @@ define('iconSelect', function() {
$('#icons .fa-icons .fa.' + selected).addClass('selected');
}
- templates.parse('partials/fontawesome', {}, function(html) {
+ templates.parse('partials/fontawesome', {}, function (html) {
html = $(html);
html.find('.fa-icons').prepend($(' '));
@@ -30,7 +30,7 @@ define('iconSelect', function() {
noIcon: {
label: 'No Icon',
className: 'btn-default',
- callback: function() {
+ callback: function () {
el.attr('class', 'fa ' + (doubleSize ? 'fa-2x ' : ''));
el.val('');
el.attr('value', '');
@@ -41,7 +41,7 @@ define('iconSelect', function() {
success: {
label: 'Select',
className: 'btn-primary',
- callback: function(confirm) {
+ callback: function (confirm) {
var iconClass = $('.bootbox .selected').attr('class');
var categoryIconClass = $('
').addClass(iconClass).removeClass('fa').removeClass('selected').attr('class');
@@ -57,7 +57,7 @@ define('iconSelect', function() {
}
});
- picker.on('show.bs.modal', function() {
+ picker.on('show.bs.modal', function () {
var modalEl = $(this),
searchEl = modalEl.find('input');
@@ -67,7 +67,7 @@ define('iconSelect', function() {
}
}).modal('show');
- picker.on('shown.bs.modal', function() {
+ picker.on('shown.bs.modal', function () {
var modalEl = $(this),
searchEl = modalEl.find('input'),
icons = modalEl.find('.fa-icons i'),
@@ -89,16 +89,16 @@ define('iconSelect', function() {
// Focus on the input box
searchEl.selectRange(0, searchEl.val().length);
- modalEl.find('.icon-container').on('click', 'i', function() {
+ modalEl.find('.icon-container').on('click', 'i', function () {
searchEl.val($(this).attr('class').replace('fa fa-', '').replace('selected', ''));
changeSelection($(this));
});
- searchEl.on('keyup', function(e) {
+ searchEl.on('keyup', function (e) {
if (e.keyCode !== 13) {
// Filter
icons.show();
- icons.each(function(idx, el) {
+ icons.each(function (idx, el) {
if (!el.className.match(new RegExp('^fa fa-.*' + searchEl.val() + '.*$'))) {
$(el).hide();
}
diff --git a/public/src/modules/navigator.js b/public/src/modules/navigator.js
index 965b3ba28e..9700db947c 100644
--- a/public/src/modules/navigator.js
+++ b/public/src/modules/navigator.js
@@ -4,7 +4,7 @@
/* globals define, ajaxify, utils, config */
-define('navigator', ['forum/pagination', 'components'], function(pagination, components) {
+define('navigator', ['forum/pagination', 'components'], function (pagination, components) {
var navigator = {};
var index = 1;
@@ -13,21 +13,21 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
navigator.scrollActive = false;
- navigator.init = function(selector, count, toTop, toBottom, callback, calculateIndex) {
+ navigator.init = function (selector, count, toTop, toBottom, callback, calculateIndex) {
index = 1;
navigator.selector = selector;
navigator.callback = callback;
- toTop = toTop || function() {};
- toBottom = toBottom || function() {};
+ toTop = toTop || function () {};
+ toBottom = toBottom || function () {};
$(window).off('scroll', navigator.delayedUpdate).on('scroll', navigator.delayedUpdate);
- $('.pagination-block .dropdown-menu').off('click').on('click', function(e) {
+ $('.pagination-block .dropdown-menu').off('click').on('click', function (e) {
e.stopPropagation();
});
- $('.pagination-block').off('shown.bs.dropdown', '.dropdown').on('shown.bs.dropdown', '.dropdown', function() {
- setTimeout(function() {
+ $('.pagination-block').off('shown.bs.dropdown', '.dropdown').on('shown.bs.dropdown', '.dropdown', function () {
+ setTimeout(function () {
$('.pagination-block input').focus();
}, 100);
});
@@ -37,7 +37,7 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
$('.pagination-block .pagetop').off('click').on('click', toTop);
$('.pagination-block .pagebottom').off('click').on('click', toBottom);
- $('.pagination-block input').on('keydown', function(e) {
+ $('.pagination-block input').on('keydown', function (e) {
if (e.which === 13) {
var input = $(this);
if (!utils.isNumber(input.val())) {
@@ -66,16 +66,16 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
return parts[1] + '/' + parts[2] + '/' + parts[3] + (index ? '/' + index : '');
}
- navigator.setCount = function(value) {
+ navigator.setCount = function (value) {
count = parseInt(value, 10);
navigator.updateTextAndProgressBar();
};
- navigator.show = function() {
+ navigator.show = function () {
toggle(true);
};
- navigator.disable = function() {
+ navigator.disable = function () {
count = 0;
index = 1;
navigator.selector = navigator.callback = null;
@@ -93,7 +93,7 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
$('.pagination-block').toggleClass('ready', flag);
}
- navigator.delayedUpdate = function() {
+ navigator.delayedUpdate = function () {
if (navigatorUpdateTimeoutId) {
clearTimeout(navigatorUpdateTimeoutId);
navigatorUpdateTimeoutId = 0;
@@ -101,7 +101,7 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
navigatorUpdateTimeoutId = setTimeout(navigator.update, 100);
};
- navigator.update = function(threshold) {
+ navigator.update = function (threshold) {
/*
The "threshold" is defined as the distance from the top of the page to
a spot where a user is expecting to begin reading.
@@ -118,7 +118,7 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
var documentHeight = $(document).height();
var middleOfViewport = scrollTop + windowHeight / 2;
var previousDistance = Number.MAX_VALUE;
- els.each(function() {
+ els.each(function () {
var distanceToMiddle = Math.abs(middleOfViewport - $(this).offset().top);
if (distanceToMiddle > previousDistance) {
@@ -161,7 +161,7 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
toggle(!!count);
};
- navigator.updateTextAndProgressBar = function() {
+ navigator.updateTextAndProgressBar = function () {
index = index > count ? count : index;
$('.pagination-block .pagination-text').translateHtml('[[global:pagination.out_of, ' + index + ', ' + count + ']]');
@@ -180,7 +180,7 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
});
};
- navigator.scrollTop = function(index) {
+ navigator.scrollTop = function (index) {
if ($(navigator.selector + '[data-index="' + index + '"]').length) {
navigator.scrollToPost(index, true);
} else {
@@ -188,7 +188,7 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
}
};
- navigator.scrollBottom = function(index) {
+ navigator.scrollBottom = function (index) {
if (parseInt(index, 10) < 0) {
return;
}
@@ -200,7 +200,7 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
}
};
- navigator.scrollToPost = function(postIndex, highlight, duration) {
+ navigator.scrollToPost = function (postIndex, highlight, duration) {
if (!utils.isNumber(postIndex) || !components.get('topic').length) {
return;
}
@@ -220,7 +220,7 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
var page = Math.max(1, Math.ceil(index / config.postsPerPage));
if (parseInt(page, 10) !== ajaxify.data.pagination.currentPage) {
- pagination.loadPage(page, function() {
+ pagination.loadPage(page, function () {
navigator.scrollToPostIndex(postIndex, highlight, duration);
});
} else {
@@ -233,7 +233,7 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
}
};
- navigator.scrollToPostIndex = function(postIndex, highlight, duration) {
+ navigator.scrollToPostIndex = function (postIndex, highlight, duration) {
var scrollTo = components.get('post', 'index', postIndex);
var postHeight = scrollTo.height();
var viewportHeight = $(window).height();
@@ -261,7 +261,7 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
$('html, body').animate({
scrollTop: scrollTop + 'px'
- }, duration, function() {
+ }, duration, function () {
if (done) {
// Re-enable onScroll behaviour
$(window).on('scroll', navigator.update);
@@ -281,7 +281,7 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
function highlightPost() {
if (highlight) {
scrollTo.addClass('highlight');
- setTimeout(function() {
+ setTimeout(function () {
scrollTo.removeClass('highlight');
}, 10000);
}
diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js
index dcabe7d0a1..a5b32c1037 100644
--- a/public/src/modules/notifications.js
+++ b/public/src/modules/notifications.js
@@ -2,19 +2,19 @@
/* globals define, socket, app, ajaxify, templates, Tinycon*/
-define('notifications', ['sounds', 'translator', 'components'], function(sound, translator, components) {
+define('notifications', ['sounds', 'translator', 'components'], function (sound, translator, components) {
var Notifications = {};
var unreadNotifs = {};
- Notifications.prepareDOM = function() {
+ Notifications.prepareDOM = function () {
var notifContainer = components.get('notifications'),
notifTrigger = notifContainer.children('a'),
notifList = components.get('notifications/list'),
notifIcon = components.get('notifications/icon');
notifTrigger
- .on('click', function(e) {
+ .on('click', function (e) {
e.preventDefault();
if (notifContainer.hasClass('open')) {
return;
@@ -22,20 +22,20 @@ define('notifications', ['sounds', 'translator', 'components'], function(sound,
Notifications.loadNotifications(notifList);
})
- .on('dblclick', function(e) {
+ .on('dblclick', function (e) {
e.preventDefault();
if (parseInt(notifIcon.attr('data-content'), 10) > 0) {
Notifications.markAllRead();
}
});
- notifList.on('click', '[data-nid]', function() {
+ notifList.on('click', '[data-nid]', function () {
var unread = $(this).hasClass('unread');
var nid = $(this).attr('data-nid');
if (!unread) {
return;
}
- socket.emit('notifications.markRead', nid, function(err) {
+ socket.emit('notifications.markRead', nid, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -48,12 +48,12 @@ define('notifications', ['sounds', 'translator', 'components'], function(sound,
notifContainer.on('click', '.mark-all-read', Notifications.markAllRead);
- notifList.on('click', '.mark-read', function() {
+ notifList.on('click', '.mark-read', function () {
var liEl = $(this).parent();
var unread = liEl.hasClass('unread');
var nid = liEl.attr('data-nid');
- socket.emit('notifications.mark' + (unread ? 'Read' : 'Unread'), nid, function(err) {
+ socket.emit('notifications.mark' + (unread ? 'Read' : 'Unread'), nid, function (err) {
if (err) {
return app.alertError(err.message);
}
@@ -72,7 +72,7 @@ define('notifications', ['sounds', 'translator', 'components'], function(sound,
Notifications.updateNotifCount(count);
}
- socket.on('event:new_notification', function(notifData) {
+ socket.on('event:new_notification', function (notifData) {
// If a path is defined, show notif data, otherwise show generic data
var payload = {
alert_id: 'new_notif',
@@ -83,7 +83,7 @@ define('notifications', ['sounds', 'translator', 'components'], function(sound,
if (notifData.path) {
payload.message = notifData.bodyShort;
payload.type = 'info';
- payload.clickfn = function() {
+ payload.clickfn = function () {
if (notifData.path.startsWith('http') && notifData.path.startsWith('https')) {
window.location.href = notifData.path;
} else {
@@ -102,7 +102,7 @@ define('notifications', ['sounds', 'translator', 'components'], function(sound,
ajaxify.refresh();
}
- socket.emit('notifications.getCount', function(err, count) {
+ socket.emit('notifications.getCount', function (err, count) {
if (err) {
return app.alertError(err.message);
}
@@ -116,34 +116,34 @@ define('notifications', ['sounds', 'translator', 'components'], function(sound,
}
});
- socket.on('event:notifications.updateCount', function(count) {
+ socket.on('event:notifications.updateCount', function (count) {
Notifications.updateNotifCount(count);
});
};
- Notifications.loadNotifications = function(notifList) {
- socket.emit('notifications.get', null, function(err, data) {
+ Notifications.loadNotifications = function (notifList) {
+ socket.emit('notifications.get', null, function (err, data) {
if (err) {
return app.alertError(err.message);
}
- var notifs = data.unread.concat(data.read).sort(function(a, b) {
+ var notifs = data.unread.concat(data.read).sort(function (a, b) {
return parseInt(a.datetime, 10) > parseInt(b.datetime, 10) ? -1 : 1;
});
translator.toggleTimeagoShorthand();
- for(var i=0; i 0) {
@@ -166,8 +166,8 @@ define('notifications', ['sounds', 'translator', 'components'], function(sound,
}
};
- Notifications.markAllRead = function() {
- socket.emit('notifications.markAllRead', function(err) {
+ Notifications.markAllRead = function () {
+ socket.emit('notifications.markAllRead', function (err) {
if (err) {
app.alertError(err.message);
}
diff --git a/public/src/modules/postSelect.js b/public/src/modules/postSelect.js
index 4f7439aff0..6001488708 100644
--- a/public/src/modules/postSelect.js
+++ b/public/src/modules/postSelect.js
@@ -2,14 +2,14 @@
/* globals define*/
-define('postSelect', ['components'], function(components) {
+define('postSelect', ['components'], function (components) {
var PostSelect = {};
PostSelect.pids = [];
- PostSelect.init = function(onSelect) {
+ PostSelect.init = function (onSelect) {
PostSelect.pids.length = 0;
- components.get('topic').on('click', '[data-pid]', function() {
+ components.get('topic').on('click', '[data-pid]', function () {
togglePostSelection($(this), onSelect);
});
disableClicksOnPosts();
@@ -34,7 +34,7 @@ define('postSelect', ['components'], function(components) {
}
if (PostSelect.pids.length) {
- PostSelect.pids.sort(function(a,b) { return a - b; });
+ PostSelect.pids.sort(function (a,b) { return a - b; });
}
callback();
}
@@ -49,7 +49,7 @@ define('postSelect', ['components'], function(components) {
components.get('post').on('click', 'button,a', disableClicks);
}
- PostSelect.enableClicksOnPosts = function() {
+ PostSelect.enableClicksOnPosts = function () {
components.get('post').off('click', 'button,a', disableClicks);
};
diff --git a/public/src/modules/search.js b/public/src/modules/search.js
index 304235c7fa..4319de5617 100644
--- a/public/src/modules/search.js
+++ b/public/src/modules/search.js
@@ -1,13 +1,13 @@
"use strict";
/* globals socket, ajaxify, app, define, config */
-define('search', ['navigator', 'translator'], function(nav, translator) {
+define('search', ['navigator', 'translator'], function (nav, translator) {
var Search = {
current: {}
};
- Search.query = function(data, callback) {
+ Search.query = function (data, callback) {
var term = data.term;
// Detect if a tid was specified
@@ -74,7 +74,7 @@ define('search', ['navigator', 'translator'], function(nav, translator) {
return decodeURIComponent($.param(query));
}
- Search.getSearchPreferences = function() {
+ Search.getSearchPreferences = function () {
try {
return JSON.parse(localStorage.getItem('search-preferences') || '{}');
} catch(e) {
@@ -82,11 +82,11 @@ define('search', ['navigator', 'translator'], function(nav, translator) {
}
};
- Search.queryTopic = function(tid, term, callback) {
+ Search.queryTopic = function (tid, term, callback) {
socket.emit('topics.search', {
tid: tid,
term: term
- }, function(err, pids) {
+ }, function (err, pids) {
if (err) {
return app.alertError(err.message);
}
@@ -94,21 +94,21 @@ define('search', ['navigator', 'translator'], function(nav, translator) {
if (Array.isArray(pids)) {
// Sort pids numerically & store
Search.current = {
- results: pids.sort(function(a, b) {
- return a-b;
+ results: pids.sort(function (a, b) {
+ return a - b;
}),
tid: tid,
term: term
};
- Search.checkPagePresence(tid, function() {
+ Search.checkPagePresence(tid, function () {
Search.topicDOM.update(0);
});
}
});
};
- Search.checkPagePresence = function(tid, callback) {
+ Search.checkPagePresence = function (tid, callback) {
if (parseInt(ajaxify.data.tid, 10) !== parseInt(tid, 10)) {
ajaxify.go('topic/' + tid, callback);
} else {
@@ -120,29 +120,29 @@ define('search', ['navigator', 'translator'], function(nav, translator) {
active: false
};
- Search.topicDOM.prev = function() {
- Search.topicDOM.update((Search.current.index === 0) ? Search.current.results.length-1 : Search.current.index-1);
+ Search.topicDOM.prev = function () {
+ Search.topicDOM.update((Search.current.index === 0) ? Search.current.results.length - 1 : Search.current.index - 1);
};
- Search.topicDOM.next = function() {
- Search.topicDOM.update((Search.current.index === Search.current.results.length-1) ? 0 : Search.current.index+1);
+ Search.topicDOM.next = function () {
+ Search.topicDOM.update((Search.current.index === Search.current.results.length - 1) ? 0 : Search.current.index + 1);
};
- Search.topicDOM.update = function(index) {
+ Search.topicDOM.update = function (index) {
var topicSearchEl = $('.topic-search');
Search.current.index = index;
Search.topicDOM.start();
if (Search.current.results.length > 0) {
- topicSearchEl.find('.count').html((index+1) + ' / ' + Search.current.results.length);
+ topicSearchEl.find('.count').html((index + 1) + ' / ' + Search.current.results.length);
topicSearchEl.find('.prev, .next').removeAttr('disabled');
var data = {
pid: Search.current.results[index],
tid: Search.current.tid,
topicPostSort: config.topicPostSort
};
- socket.emit('posts.getPidIndex', data, function(err, postIndex) {
+ socket.emit('posts.getPidIndex', data, function (err, postIndex) {
if (err) {
return app.alertError(err.message);
}
@@ -150,31 +150,31 @@ define('search', ['navigator', 'translator'], function(nav, translator) {
nav.scrollToPost(postIndex, true);
});
} else {
- translator.translate('[[search:no-matches]]', function(text) {
+ translator.translate('[[search:no-matches]]', function (text) {
topicSearchEl.find('.count').html(text);
});
topicSearchEl.removeClass('hidden').find('.prev, .next').attr('disabled', 'disabled');
}
};
- Search.topicDOM.start = function() {
+ Search.topicDOM.start = function () {
$('.topic-search').removeClass('hidden');
if (!Search.topicDOM.active) {
Search.topicDOM.active = true;
// Bind to esc
- require(['mousetrap'], function(mousetrap) {
+ require(['mousetrap'], function (mousetrap) {
mousetrap.bind('esc', Search.topicDOM.end);
});
}
};
- Search.topicDOM.end = function() {
+ Search.topicDOM.end = function () {
$('.topic-search').addClass('hidden').find('.prev, .next').attr('disabled', 'disabled');
Search.topicDOM.active = false;
// Unbind esc
- require(['mousetrap'], function(mousetrap) {
+ require(['mousetrap'], function (mousetrap) {
mousetrap.unbind('esc', Search.topicDOM.end);
});
};
diff --git a/public/src/modules/settings.js b/public/src/modules/settings.js
index 692e0ec7b4..090c83e2d0 100644
--- a/public/src/modules/settings.js
+++ b/public/src/modules/settings.js
@@ -448,7 +448,7 @@ define('settings', function () {
helper.persistSettings(hash, Settings.cfg, notify, callback);
},
load: function (hash, formEl, callback) {
- callback = callback || function() {};
+ callback = callback || function () {};
socket.emit('admin.settings.get', {
hash: hash
}, function (err, values) {
@@ -468,13 +468,13 @@ define('settings', function () {
}
$(formEl).deserialize(values);
- $(formEl).find('input[type="checkbox"]').each(function() {
+ $(formEl).find('input[type="checkbox"]').each(function () {
$(this).parents('.mdl-switch').toggleClass('is-checked', $(this).is(':checked'));
});
$(window).trigger('action:admin.settingsLoaded');
// Handle unsaved changes
- $(formEl).on('change', 'input, select, textarea', function() {
+ $(formEl).on('change', 'input, select, textarea', function () {
app.flags = app.flags || {};
app.flags._unsaved = true;
});
@@ -495,7 +495,7 @@ define('settings', function () {
});
// Normalizing value of multiple selects
- formEl.find('select[multiple]').each(function(idx, selectEl) {
+ formEl.find('select[multiple]').each(function (idx, selectEl) {
selectEl = $(selectEl);
values[selectEl.attr('name')] = JSON.stringify(selectEl.val());
});
diff --git a/public/src/modules/settings/array.js b/public/src/modules/settings/array.js
index 81071a65fa..fd94ed8226 100644
--- a/public/src/modules/settings/array.js
+++ b/public/src/modules/settings/array.js
@@ -107,7 +107,7 @@ define('settings/array', function () {
} catch (_error) {
return $(document.createTextNode(separator));
}
- })();
+ }());
if (typeof attributes !== 'object') {
attributes = {};
}
diff --git a/public/src/modules/settings/object.js b/public/src/modules/settings/object.js
index 8c7a53f99a..05971d6d73 100644
--- a/public/src/modules/settings/object.js
+++ b/public/src/modules/settings/object.js
@@ -69,7 +69,7 @@ define('settings/object', function () {
} catch (_error) {
return $(document.createTextNode(separator));
}
- })();
+ }());
element.empty();
if (typeof value !== 'object') {
value = {};
diff --git a/public/src/modules/share.js b/public/src/modules/share.js
index 6fe2f5f8bf..9229ca549e 100644
--- a/public/src/modules/share.js
+++ b/public/src/modules/share.js
@@ -2,11 +2,11 @@
/* globals define */
-define('share', function() {
+define('share', function () {
var module = {};
- module.addShareHandlers = function(name) {
+ module.addShareHandlers = function (name) {
var baseUrl = window.location.protocol + '//' + window.location.host;
@@ -15,18 +15,18 @@ define('share', function() {
return false;
}
- $('#content').off('shown.bs.dropdown', '.share-dropdown').on('shown.bs.dropdown', '.share-dropdown', function() {
+ $('#content').off('shown.bs.dropdown', '.share-dropdown').on('shown.bs.dropdown', '.share-dropdown', function () {
var postLink = $(this).find('.post-link');
postLink.val(baseUrl + getPostUrl($(this)));
// without the setTimeout can't select the text in the input
- setTimeout(function() {
+ setTimeout(function () {
postLink.putCursorAtEnd().select();
}, 50);
});
- addHandler('.post-link', function(e) {
+ addHandler('.post-link', function (e) {
e.preventDefault();
return false;
});
diff --git a/public/src/modules/sort.js b/public/src/modules/sort.js
index 960e21facb..c9e80020af 100644
--- a/public/src/modules/sort.js
+++ b/public/src/modules/sort.js
@@ -1,7 +1,7 @@
'use strict';
/* globals define, config, socket, app, ajaxify, templates */
-define('sort', ['components'], function(components) {
+define('sort', ['components'], function (components) {
var module = {};
module.handleSort = function (field, method, gotoOnSave) {
@@ -10,9 +10,9 @@ define('sort', ['components'], function(components) {
var currentSetting = threadSort.find('a[data-sort="' + config[field] + '"]');
currentSetting.find('i').addClass('fa-check');
- $('.category, .topic').on('click', '[component="thread/sort"] a', function() {
+ $('.category, .topic').on('click', '[component="thread/sort"] a', function () {
var newSetting = $(this).attr('data-sort');
- socket.emit(method, newSetting, function(err) {
+ socket.emit(method, newSetting, function (err) {
if (err) {
return app.alertError(err.message);
}
diff --git a/public/src/modules/sounds.js b/public/src/modules/sounds.js
index a9a1840fd4..c82391159e 100644
--- a/public/src/modules/sounds.js
+++ b/public/src/modules/sounds.js
@@ -1,19 +1,19 @@
"use strict";
/* global app, define, socket, config */
-define('sounds', ['buzz'], function(buzz) {
+define('sounds', ['buzz'], function (buzz) {
var Sounds = {};
var loadedSounds = {};
var eventSoundMapping;
var files;
- socket.on('event:sounds.reloadMapping', function() {
+ socket.on('event:sounds.reloadMapping', function () {
Sounds.reloadMapping();
});
- Sounds.reloadMapping = function() {
- socket.emit('modules.sounds.getMapping', function(err, mapping) {
+ Sounds.reloadMapping = function () {
+ socket.emit('modules.sounds.getMapping', function (err, mapping) {
if (err) {
return app.alertError(err.message);
}
@@ -22,7 +22,7 @@ define('sounds', ['buzz'], function(buzz) {
}
function loadData(callback) {
- socket.emit('modules.sounds.getData', function(err, data) {
+ socket.emit('modules.sounds.getData', function (err, data) {
if (err) {
return app.alertError('[sounds] Could not load sound mapping!');
}
@@ -54,7 +54,7 @@ define('sounds', ['buzz'], function(buzz) {
createSound();
}
- Sounds.play = function(name) {
+ Sounds.play = function (name) {
function play() {
Sounds.playFile(eventSoundMapping[name]);
}
@@ -66,7 +66,7 @@ define('sounds', ['buzz'], function(buzz) {
play();
};
- Sounds.playFile = function(fileName) {
+ Sounds.playFile = function (fileName) {
if (!fileName) {
return;
}
diff --git a/public/src/modules/taskbar.js b/public/src/modules/taskbar.js
index 7f5978250b..9e51e34d72 100644
--- a/public/src/modules/taskbar.js
+++ b/public/src/modules/taskbar.js
@@ -1,23 +1,23 @@
"use strict";
/*global define, app, templates*/
-define('taskbar', function() {
+define('taskbar', function () {
var taskbar = {};
- taskbar.init = function() {
+ taskbar.init = function () {
var self = this;
- templates.parse('modules/taskbar', {}, function(html) {
+ templates.parse('modules/taskbar', {}, function (html) {
self.taskbar = $(html);
self.tasklist = self.taskbar.find('ul');
$(document.body).append(self.taskbar);
- self.taskbar.on('click', 'li', function() {
+ self.taskbar.on('click', 'li', function () {
var $btn = $(this),
module = $btn.attr('data-module'),
uuid = $btn.attr('data-uuid');
- require([module], function(module) {
+ require([module], function (module) {
if (!$btn.hasClass('active')) {
minimizeAll();
module.load(uuid);
@@ -36,14 +36,14 @@ define('taskbar', function() {
});
};
- taskbar.discard = function(module, uuid) {
+ taskbar.discard = function (module, uuid) {
var btnEl = taskbar.tasklist.find('[data-module="' + module + '"][data-uuid="' + uuid + '"]');
btnEl.remove();
update();
};
- taskbar.push = function(module, uuid, options) {
+ taskbar.push = function (module, uuid, options) {
var element = taskbar.tasklist.find('li[data-uuid="' + uuid + '"]');
var data = {
@@ -60,20 +60,20 @@ define('taskbar', function() {
}
};
- taskbar.get = function(module) {
- var items = $('[data-module="' + module + '"]').map(function(idx, el) {
+ taskbar.get = function (module) {
+ var items = $('[data-module="' + module + '"]').map(function (idx, el) {
return $(el).data();
});
return items;
};
- taskbar.minimize = function(module, uuid) {
+ taskbar.minimize = function (module, uuid) {
var btnEl = taskbar.tasklist.find('[data-module="' + module + '"][data-uuid="' + uuid + '"]');
btnEl.removeClass('active');
};
- taskbar.toggleNew = function(uuid, state, silent) {
+ taskbar.toggleNew = function (uuid, state, silent) {
var btnEl = taskbar.tasklist.find('[data-uuid="' + uuid + '"]');
btnEl.toggleClass('new', state);
@@ -82,13 +82,13 @@ define('taskbar', function() {
}
};
- taskbar.updateActive = function(uuid) {
+ taskbar.updateActive = function (uuid) {
var tasks = taskbar.tasklist.find('li');
tasks.removeClass('active');
tasks.filter('[data-uuid="' + uuid + '"]').addClass('active');
};
- taskbar.isActive = function(uuid) {
+ taskbar.isActive = function (uuid) {
var taskBtn = taskbar.tasklist.find('li[data-uuid="' + uuid + '"]');
return taskBtn.hasClass('active');
};
@@ -114,7 +114,7 @@ define('taskbar', function() {
.addClass(data.options.className)
.html('' +
(data.options.icon ? ' ' : '') +
- (data.options.image ? ' ': '') +
+ (data.options.image ? ' ' : '') +
'' + title + ' ' +
' ')
.attr({
diff --git a/public/src/modules/topicSelect.js b/public/src/modules/topicSelect.js
index d0dd85b601..6169b1f891 100644
--- a/public/src/modules/topicSelect.js
+++ b/public/src/modules/topicSelect.js
@@ -2,19 +2,19 @@
/* globals define*/
-define('topicSelect', ['components'], function(components) {
+define('topicSelect', ['components'], function (components) {
var TopicSelect = {};
var lastSelected;
var topicsContainer;
- TopicSelect.init = function(onSelect) {
+ TopicSelect.init = function (onSelect) {
topicsContainer = $('[component="category"]');
- topicsContainer.on('selectstart', function() {
+ topicsContainer.on('selectstart', function () {
return false;
});
- topicsContainer.on('click', '[component="topic/select"]', function(ev) {
+ topicsContainer.on('click', '[component="topic/select"]', function (ev) {
var select = $(this);
if (ev.shiftKey) {
@@ -38,15 +38,15 @@ define('topicSelect', ['components'], function(components) {
select.parents('[component="category/topic"]').toggleClass('selected', isSelected);
}
- TopicSelect.getSelectedTids = function() {
+ TopicSelect.getSelectedTids = function () {
var tids = [];
- topicsContainer.find('[component="category/topic"].selected').each(function() {
+ topicsContainer.find('[component="category/topic"].selected').each(function () {
tids.push($(this).attr('data-tid'));
});
return tids;
};
- TopicSelect.unselectAll = function() {
+ TopicSelect.unselectAll = function () {
topicsContainer.find('[component="category/topic"].selected').removeClass('selected');
topicsContainer.find('[component="topic/select"]').toggleClass('fa-check-square-o', false).toggleClass('fa-square-o', true);
};
@@ -71,7 +71,7 @@ define('topicSelect', ['components'], function(components) {
end = tmp;
}
- for(var i=start; i<=end; ++i) {
+ for(var i = start; i <= end; ++i) {
var topic = $('[component="category/topic"]').eq(i);
toggleSelect(topic.find('[component="topic/select"]'), isSelected);
}
diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js
index 08525702d5..65a92772e5 100644
--- a/public/src/modules/translator.js
+++ b/public/src/modules/translator.js
@@ -29,16 +29,16 @@
}
module.exports = factory(require('string'), loadServer);
- })();
+ }());
} else {
window.translator = factory(window.string, loadClient);
}
-})(function (string, load) {
+}(function (string, load) {
'use strict';
var assign = Object.assign || jQuery.extend;
function classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- var Translator = function () {
+ var Translator = (function () {
/**
* Construct a new Translator object
* @param {string} language - Language code for this translator instance
@@ -305,7 +305,7 @@
Translator.cache = {};
return Translator;
- }();
+ }());
var adaptor = {
/**
@@ -453,4 +453,4 @@
};
return adaptor;
-});
+}));
diff --git a/public/src/modules/uploader.js b/public/src/modules/uploader.js
index 5d257e4cfb..106b82d67d 100644
--- a/public/src/modules/uploader.js
+++ b/public/src/modules/uploader.js
@@ -2,11 +2,11 @@
/* globals define, templates */
-define('uploader', ['translator'], function(translator) {
+define('uploader', ['translator'], function (translator) {
var module = {};
- module.open = function(route, params, fileSize, callback) {
+ module.open = function (route, params, fileSize, callback) {
console.warn('[uploader] uploader.open() is deprecated, please use uploader.show() instead, and pass parameters as a singe option with callback, e.g. uploader.show({}, callback);');
module.show({
route: route,
@@ -15,7 +15,7 @@ define('uploader', ['translator'], function(translator) {
}, callback);
};
- module.show = function(data, callback) {
+ module.show = function (data, callback) {
var fileSize = data.hasOwnProperty('fileSize') && data.fileSize !== undefined ? parseInt(data.fileSize, 10) : false;
parseModal({
showHelp: data.hasOwnProperty('showHelp') && data.showHelp !== undefined ? data.showHelp : true,
@@ -24,11 +24,11 @@ define('uploader', ['translator'], function(translator) {
description: data.description || '',
button: data.button || '[[global:upload]]',
accept: data.accept ? data.accept.replace(/,/g, ', ') : ''
- }, function(uploadModal) {
+ }, function (uploadModal) {
uploadModal = $(uploadModal);
uploadModal.modal('show');
- uploadModal.on('hidden.bs.modal', function() {
+ uploadModal.on('hidden.bs.modal', function () {
uploadModal.remove();
});
@@ -36,19 +36,19 @@ define('uploader', ['translator'], function(translator) {
uploadForm.attr('action', data.route);
uploadForm.find('#params').val(JSON.stringify(data.params));
- uploadModal.find('#fileUploadSubmitBtn').on('click', function() {
+ uploadModal.find('#fileUploadSubmitBtn').on('click', function () {
$(this).addClass('disabled');
uploadForm.submit();
});
- uploadForm.submit(function() {
+ uploadForm.submit(function () {
onSubmit(uploadModal, fileSize, callback);
return false;
});
});
};
- module.hideAlerts = function(modal) {
+ module.hideAlerts = function (modal) {
$(modal).find('#alert-status, #alert-success, #alert-error, #upload-progress-box').addClass('hide');
};
@@ -78,14 +78,14 @@ define('uploader', ['translator'], function(translator) {
headers: {
'x-csrf-token': config.csrf_token
},
- error: function(xhr) {
+ error: function (xhr) {
xhr = maybeParse(xhr);
showAlert('error', xhr.responseJSON ? (xhr.responseJSON.error || xhr.statusText) : 'error uploading, code : ' + xhr.status);
},
- uploadProgress: function(event, position, total, percent) {
+ uploadProgress: function (event, position, total, percent) {
uploadModal.find('#upload-progress-bar').css('width', percent + '%');
},
- success: function(response) {
+ success: function (response) {
response = maybeParse(response);
if (response.error) {
@@ -95,7 +95,7 @@ define('uploader', ['translator'], function(translator) {
callback(response[0].url);
showAlert('success', '[[uploads:upload-success]]');
- setTimeout(function() {
+ setTimeout(function () {
module.hideAlerts(uploadModal);
uploadModal.modal('hide');
}, 750);
@@ -104,7 +104,7 @@ define('uploader', ['translator'], function(translator) {
}
function parseModal(tplVals, callback) {
- templates.parse('partials/modals/upload_file_modal', tplVals, function(html) {
+ templates.parse('partials/modals/upload_file_modal', tplVals, function (html) {
translator.translate(html, callback);
});
}
diff --git a/public/src/overrides.js b/public/src/overrides.js
index 49dce7e754..c644bb6281 100644
--- a/public/src/overrides.js
+++ b/public/src/overrides.js
@@ -7,8 +7,8 @@ var overrides = overrides || {};
if ('undefined' !== typeof window) {
(function ($, undefined) {
- require(['translator'], function(translator) {
- $.fn.getCursorPosition = function() {
+ require(['translator'], function (translator) {
+ $.fn.getCursorPosition = function () {
var el = $(this).get(0);
var pos = 0;
if('selectionStart' in el) {
@@ -23,11 +23,11 @@ if ('undefined' !== typeof window) {
return pos;
};
- $.fn.selectRange = function(start, end) {
+ $.fn.selectRange = function (start, end) {
if(!end) {
end = start;
}
- return this.each(function() {
+ return this.each(function () {
if (this.setSelectionRange) {
this.focus();
this.setSelectionRange(start, end);
@@ -42,8 +42,8 @@ if ('undefined' !== typeof window) {
};
//http://stackoverflow.com/questions/511088/use-javascript-to-place-cursor-at-end-of-text-in-text-input-element
- $.fn.putCursorAtEnd = function() {
- return this.each(function() {
+ $.fn.putCursorAtEnd = function () {
+ return this.each(function () {
$(this).focus();
if (this.setSelectionRange) {
@@ -56,39 +56,39 @@ if ('undefined' !== typeof window) {
});
};
- $.fn.translateHtml = function(str) {
+ $.fn.translateHtml = function (str) {
return translate(this, 'html', str);
};
- $.fn.translateText = function(str) {
+ $.fn.translateText = function (str) {
return translate(this, 'text', str);
};
- $.fn.translateVal = function(str) {
+ $.fn.translateVal = function (str) {
return translate(this, 'val', str);
};
- $.fn.translateAttr = function(attr, str) {
- return this.each(function() {
+ $.fn.translateAttr = function (attr, str) {
+ return this.each(function () {
var el = $(this);
- translator.translate(str, function(translated) {
+ translator.translate(str, function (translated) {
el.attr(attr, translated);
});
});
};
function translate(elements, type, str) {
- return elements.each(function() {
+ return elements.each(function () {
var el = $(this);
- translator.translate(str, function(translated) {
+ translator.translate(str, function (translated) {
el[type](translated);
});
});
}
});
- })(jQuery || {fn:{}});
+ }(jQuery || {fn:{}}));
- (function(){
+ (function (){
// FIX FOR #1245 - https://github.com/NodeBB/NodeBB/issues/1245
// from http://stackoverflow.com/questions/15931962/bootstrap-dropdown-disappear-with-right-click-on-firefox
// obtain a reference to the original handler
@@ -109,10 +109,10 @@ if ('undefined' !== typeof window) {
_clearMenus();
}
});
- })();
+ }());
overrides.overrideBootbox = function () {
- require(['translator'], function(translator) {
+ require(['translator'], function (translator) {
var dialog = bootbox.dialog,
prompt = bootbox.prompt,
confirm = bootbox.confirm;
@@ -120,27 +120,27 @@ if ('undefined' !== typeof window) {
function translate(modal) {
var header = modal.find('.modal-header'),
footer = modal.find('.modal-footer');
- translator.translate(header.html(), function(html) {
+ translator.translate(header.html(), function (html) {
header.html(html);
});
- translator.translate(footer.html(), function(html) {
+ translator.translate(footer.html(), function (html) {
footer.html(html);
});
}
- bootbox.dialog = function() {
+ bootbox.dialog = function () {
var modal = $(dialog.apply(this, arguments)[0]);
translate(modal);
return modal;
};
- bootbox.prompt = function() {
+ bootbox.prompt = function () {
var modal = $(prompt.apply(this, arguments)[0]);
translate(modal);
return modal;
};
- bootbox.confirm = function() {
+ bootbox.confirm = function () {
var modal = $(confirm.apply(this, arguments)[0]);
translate(modal);
return modal;
@@ -148,13 +148,13 @@ if ('undefined' !== typeof window) {
});
};
- overrides.overrideTimeago = function() {
+ overrides.overrideTimeago = function () {
var timeagoFn = $.fn.timeago;
- $.fn.timeago = function() {
+ $.fn.timeago = function () {
var els = timeagoFn.apply(this, arguments);
if (els) {
- els.each(function() {
+ els.each(function () {
$(this).attr('title', (new Date($(this).attr('title'))).toString());
});
}
diff --git a/public/src/sockets.js b/public/src/sockets.js
index 15eee26b5e..a8c33be1e8 100644
--- a/public/src/sockets.js
+++ b/public/src/sockets.js
@@ -23,12 +23,12 @@ app.isConnected = false;
socket.on('disconnect', onDisconnect);
- socket.on('reconnect_failed', function() {
+ socket.on('reconnect_failed', function () {
// Wait ten times the reconnection delay and then start over
setTimeout(socket.connect.bind(socket), parseInt(config.reconnectionDelay, 10) * 10);
});
- socket.on('checkSession', function(uid) {
+ socket.on('checkSession', function (uid) {
if (parseInt(uid, 10) !== parseInt(app.user.uid, 10)) {
app.handleInvalidSession();
}
@@ -61,7 +61,7 @@ app.isConnected = false;
$(window).trigger('action:reconnected');
- setTimeout(function() {
+ setTimeout(function () {
reconnectEl.removeClass('active').addClass('hide');
}, 3000);
}
@@ -129,7 +129,7 @@ app.isConnected = false;
timeout: 1000
});
- setTimeout(function() {
+ setTimeout(function () {
window.location.href = config.relative_path + '/';
}, 1000);
}
diff --git a/public/src/utils.js b/public/src/utils.js
index 190d0ab3c6..b2d86fedb1 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -1,4 +1,4 @@
-(function(module) {
+(function (module) {
'use strict';
var utils, fs, XRegExp;
@@ -7,11 +7,11 @@
fs = require('fs');
XRegExp = require('xregexp');
- process.profile = function(operation, start) {
+ process.profile = function (operation, start) {
console.log('%s took %d milliseconds', operation, process.elapsedTimeSince(start));
};
- process.elapsedTimeSince = function(start) {
+ process.elapsedTimeSince = function (start) {
var diff = process.hrtime(start);
return diff[0] * 1e3 + diff[1] / 1e6;
};
@@ -22,8 +22,8 @@
module.exports = utils = {
- generateUUID: function() {
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
+ generateUUID: function () {
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0,
v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
@@ -31,10 +31,10 @@
},
//Adapted from http://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search
- walk: function(dir, done) {
+ walk: function (dir, done) {
var results = [];
- fs.readdir(dir, function(err, list) {
+ fs.readdir(dir, function (err, list) {
if (err) {
return done(err);
}
@@ -42,15 +42,15 @@
if (!pending) {
return done(null, results);
}
- list.forEach(function(file) {
+ list.forEach(function (file) {
file = dir + '/' + file;
- fs.stat(file, function(err, stat) {
+ fs.stat(file, function (err, stat) {
if (err) {
return done(err);
}
if (stat && stat.isDirectory()) {
- utils.walk(file, function(err, res) {
+ utils.walk(file, function (err, res) {
if (err) {
return done(err);
}
@@ -82,7 +82,7 @@
languageKeyRegex: /\[\[[\w]+:.+\]\]/,
//http://dense13.com/blog/2009/05/03/converting-string-to-slug-javascript/
- slugify: function(str, preserveCase) {
+ slugify: function (str, preserveCase) {
if (!str) {
return '';
}
@@ -100,7 +100,7 @@
return str;
},
- cleanUpTag: function(tag, maxLength) {
+ cleanUpTag: function (tag, maxLength) {
if (typeof tag !== 'string' || !tag.length ) {
return '';
}
@@ -117,32 +117,32 @@
return tag;
},
- removePunctuation: function(str) {
+ removePunctuation: function (str) {
return str.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`<>'"~()?]/g, '');
},
- isEmailValid: function(email) {
+ isEmailValid: function (email) {
return typeof email === 'string' && email.length && email.indexOf('@') !== -1;
},
- isUserNameValid: function(name) {
+ isUserNameValid: function (name) {
return (name && name !== '' && (/^['"\s\-.*0-9\u00BF-\u1FFF\u2C00-\uD7FF\w]+$/.test(name)));
},
- isPasswordValid: function(password) {
+ isPasswordValid: function (password) {
return typeof password === 'string' && password.length;
},
- isNumber: function(n) {
+ isNumber: function (n) {
return !isNaN(parseFloat(n)) && isFinite(n);
},
- hasLanguageKey: function(input) {
+ hasLanguageKey: function (input) {
return utils.languageKeyRegex.test(input);
},
// shallow objects merge
- merge: function() {
+ merge: function () {
var result = {}, obj, keys;
for (var i = 0; i < arguments.length; i++) {
obj = arguments[i] || {};
@@ -188,22 +188,22 @@
return utils.extensionToMimeType(utils.fileExtension(path));
},
- extensionToMimeType: function(extension) {
+ extensionToMimeType: function (extension) {
return utils.extensionMimeTypeMap[extension] || '*';
},
- isRelativeUrl: function(url) {
+ isRelativeUrl: function (url) {
var firstChar = url.slice(0, 1);
return (firstChar === '.' || firstChar === '/');
},
- makeNumbersHumanReadable: function(elements) {
- elements.each(function() {
+ makeNumbersHumanReadable: function (elements) {
+ elements.each(function () {
$(this).html(utils.makeNumberHumanReadable($(this).attr('title')));
});
},
- makeNumberHumanReadable: function(num) {
+ makeNumberHumanReadable: function (num) {
var n = parseInt(num, 10);
if(!n) {
return num;
@@ -228,7 +228,7 @@
return text.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
},
- toISOString: function(timestamp) {
+ toISOString: function (timestamp) {
if (!timestamp || !Date.prototype.toISOString) {
return '';
}
@@ -248,25 +248,25 @@
'source', 'span', 'strike', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot',
'th', 'thead', 'time', 'title', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr'],
- escapeRegexChars: function(text) {
+ escapeRegexChars: function (text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
},
- escapeHTML: function(raw) {
+ escapeHTML: function (raw) {
return raw.replace(/&/gm,"&").replace(//gm,">");
},
- isAndroidBrowser: function() {
+ isAndroidBrowser: function () {
// http://stackoverflow.com/questions/9286355/how-to-detect-only-the-native-android-browser
var nua = navigator.userAgent;
return ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1));
},
- isTouchDevice: function() {
+ isTouchDevice: function () {
return 'ontouchstart' in document.documentElement;
},
- findBootstrapEnvironment: function() {
+ findBootstrapEnvironment: function () {
//http://stackoverflow.com/questions/14441456/how-to-detect-which-device-view-youre-on-using-twitter-bootstrap-api
var envs = ['xs', 'sm', 'md', 'lg'],
$el = $('');
@@ -276,7 +276,7 @@
for (var i = envs.length - 1; i >= 0; i--) {
var env = envs[i];
- $el.addClass('hidden-'+env);
+ $el.addClass('hidden-' + env);
if ($el.is(':hidden')) {
$el.remove();
return env;
@@ -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,14 +303,14 @@
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 = [],
tmpDate;
- for(var x=29;x>=0;x--) {
- tmpDate = new Date(currentDay - (1000*60*60*24*x));
+ for(var x = 29;x >= 0;x--) {
+ tmpDate = new Date(currentDay - (1000 * 60 * 60 * 24 * x));
labels.push(months[tmpDate.getMonth()] + ' ' + tmpDate.getDate());
}
@@ -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,13 +455,13 @@
}
if (typeof String.prototype.endsWith != 'function') {
- String.prototype.endsWith = function(suffix) {
+ String.prototype.endsWith = function (suffix) {
if (this.length < suffix.length) {
return false;
}
var len = this.length;
var suffixLen = suffix.length;
- for (var i=1; (i <= suffixLen && this[len - i] === suffix[suffixLen - i]); ++i) {
+ for (var i = 1; (i <= suffixLen && this[len - i] === suffix[suffixLen - i]); ++i) {
continue;
}
return i > suffixLen;
@@ -469,7 +469,7 @@
}
if (typeof String.prototype.rtrim != 'function') {
- String.prototype.rtrim = function() {
+ String.prototype.rtrim = function () {
return this.replace(/\s+$/g, '');
};
}
@@ -478,8 +478,8 @@
window.utils = module.exports;
}
-})('undefined' === typeof module ? {
+}('undefined' === typeof module ? {
module: {
exports: {}
}
-} : module);
+} : module));
diff --git a/public/src/widgets.js b/public/src/widgets.js
index 8bae7cc465..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,13 +41,13 @@
template: template + '.tpl',
url: url,
isMobile: utils.isMobile()
- }, function(renderedAreas) {
- for (var x=0; x
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 a5628f5a4d..7e4fd1ffec 100644
--- a/src/controllers/globalmods.js
+++ b/src/controllers/globalmods.js
@@ -5,8 +5,8 @@ var adminBlacklistController = require('./admin/blacklist');
var globalModsController = {};
-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 6e18283d5e..6f73886986 100644
--- a/src/controllers/index.js
+++ b/src/controllers/index.js
@@ -32,10 +32,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);
}
@@ -72,9 +72,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);
}
@@ -99,7 +99,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';
@@ -132,7 +132,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);
}
@@ -146,7 +146,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') {
@@ -159,17 +159,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);
}
@@ -194,7 +194,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');
}
@@ -202,7 +202,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);
}
@@ -211,12 +211,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);
}
@@ -230,13 +230,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);
}
@@ -252,7 +252,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 : '',
@@ -273,7 +273,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') + '/',
@@ -319,7 +319,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)),
@@ -334,18 +334,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');
@@ -379,7 +379,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 {
@@ -387,7 +387,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+)\//);
@@ -405,7 +405,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)) });
});
}
@@ -417,7 +417,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);
@@ -439,7 +439,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 2200929ab6..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);
@@ -56,7 +56,7 @@ topicsController.get = function(req, res, callback) {
if (!res.locals.isAPI && (!req.params.slug || results.topic.slug !== tid + '/' + req.params.slug) && (results.topic.slug && results.topic.slug !== tid + '/')) {
var url = '/topic/' + results.topic.slug;
if (req.params.post_index){
- url += '/'+req.params.post_index;
+ url += '/' + req.params.post_index;
}
if (currentPage > 1) {
url += '?page=' + currentPage;
@@ -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);
}
@@ -149,7 +149,7 @@ topicsController.get = function(req, res, callback) {
},
function (topicData, next) {
function findPost(index) {
- for(var i=0; i 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,15 +73,15 @@ 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 origRatio) {
- desiredRatio = 1/desiredRatio;
+ desiredRatio = 1 / desiredRatio;
}
if (origRatio >= 1) {
y = 0; // height is the smaller dimension here
- x = Math.floor((w/2) - (h * desiredRatio / 2));
+ x = Math.floor((w / 2) - (h * desiredRatio / 2));
crop = async.apply(image.crop.bind(image), x, y, h * desiredRatio, h);
} else {
x = 0; // width is the smaller dimension here
- y = Math.floor(h/2 - (w * desiredRatio / 2));
+ y = Math.floor(h / 2 - (w * desiredRatio / 2));
crop = async.apply(image.crop.bind(image), x, y, w, w * desiredRatio);
}
} else {
@@ -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 e646046bd9..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,21 +141,21 @@ 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
*
* The format is: io:
*/
try {
- return 'io: '+_uid+' '+_type+' '+util.inspect(Array.prototype.slice.call(_args))+'\n';
+ return 'io: ' + _uid + ' ' + _type + ' ' + util.inspect(Array.prototype.slice.call(_args)) + '\n';
} catch(err) {
winston.info("Logger.prepare_io_string: Failed", err);
return "error";
}
};
- 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 ae554f7359..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,15 +151,15 @@ 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 (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
message.newSet = true;
- } else if (index > 0 && message.fromuid !== messages[index-1].fromuid) {
+ } else if (index > 0 && message.fromuid !== messages[index - 1].fromuid) {
// If the previous message was from the other person, this is also a new set
message.newSet = true;
}
@@ -173,25 +173,25 @@ 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);
+ db.getSortedSetRange(key, index - 1, index - 1, next);
} else {
messages[0].newSet = true;
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);
}
if (
- (parseInt(messages[0].timestamp, 10) > parseInt(fields.timestamp, 10) + (1000*60*5)) ||
+ (parseInt(messages[0].timestamp, 10) > parseInt(fields.timestamp, 10) + (1000 * 60 * 5)) ||
(parseInt(messages[0].fromuid, 10) !== parseInt(fields.fromuid, 10))
) {
// If it's been 5 minutes, this is a new set of messages
@@ -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 e1997ddab9..2741a599f8 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'],
@@ -50,7 +50,7 @@ module.exports = function(middleware) {
'brand:logo': meta.config['brand:logo'] || '',
'brand:logo:url': meta.config['brand:logo:url'] || '',
'brand:logo:alt': meta.config['brand:logo:alt'] || '',
- 'brand:logo:display': meta.config['brand:logo']?'':'hide',
+ 'brand:logo:display': meta.config['brand:logo'] ? '' : 'hide',
allowRegistration: registrationType === 'normal' || registrationType === 'admin-approval' || registrationType === 'admin-approval-ip',
searchEnabled: plugins.hasListeners('filter:search.query'),
config: res.locals.config,
@@ -61,19 +61,19 @@ 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);
},
- isModerator: function(next) {
+ isModerator: function (next) {
user.isModeratorOfAnyCategory(req.uid, next);
},
- user: function(next) {
+ user: function (next) {
var userData = {
uid: 0,
username: '[[global:guest]]',
@@ -91,7 +91,7 @@ module.exports = function(middleware) {
next(null, userData);
}
},
- isEmailConfirmSent: function(next) {
+ isEmailConfirmSent: function (next) {
if (!meta.config.requireEmailConfirmation || !req.uid) {
return next(null, false);
}
@@ -99,7 +99,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);
}
@@ -142,7 +142,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};
});
@@ -150,7 +150,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);
}
@@ -160,8 +160,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);
}
@@ -174,7 +174,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 33079b88ef..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,8 +42,8 @@ module.exports = function(middleware) {
}
};
- var isAllowed = function(url) {
- for(var x=0,numAllowed=allowedRoutes.length,route;x' + ajaxifyData + '');
}
], 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 7c0056a533..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;
@@ -464,7 +464,7 @@ var utils = require('../public/src/utils');
notifications[modifyIndex].bodyShort = '[[' + mergeId + '_multiple, ' + usernames[0] + ', ' + (numUsers - 1) + titleEscaped + ']]';
}
- notifications[modifyIndex].path = set[set.length-1].path;
+ notifications[modifyIndex].path = set[set.length - 1].path;
break;
case 'new_register':
@@ -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 69896ccd3f..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},
@@ -23,13 +23,13 @@ pagination.create = function(currentPage, pageCount, queryObj) {
var next = Math.min(pageCount, currentPage + 1);
var startPage = currentPage - 2;
- for(var i=0; i<5; ++i) {
+ for(var i = 0; i < 5; ++i) {
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,12 +37,12 @@ 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)};
});
- for (i=pages.length - 1; i>0; --i) {
+ for (i = pages.length - 1; i > 0; --i) {
if (pages[i - 1].page !== pages[i].page - 1) {
pages.splice(i, 0, {separator: true});
}
diff --git a/src/password.js b/src/password.js
index 20f4c79a95..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));
}
@@ -30,4 +30,4 @@
}
return module;
-})(exports);
\ No newline at end of file
+}(exports));
\ No newline at end of file
diff --git a/src/plugins.js b/src/plugins.js
index af3bc887c9..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,52 +89,52 @@ 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');
winston.warn('[plugins/load] The following plugins may not be compatible with your version of NodeBB. This may cause unintended behaviour or crashing. In the event of an unresponsive NodeBB caused by this plugin, run `./nodebb reset -p PLUGINNAME` to disable it.');
- for(var x=0,numPlugins=Plugins.versionWarning.length;x 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 04c0c84bba..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);
}
@@ -318,7 +318,7 @@ module.exports = function(Plugins) {
callback(null, pluginData);
} catch(err) {
var pluginDir = pluginPath.split(path.sep);
- pluginDir = pluginDir[pluginDir.length -1];
+ pluginDir = pluginDir[pluginDir.length - 1];
winston.error('[plugins/' + pluginDir + '] Error in plugin.json or package.json! ' + err.message);
diff --git a/src/posts.js b/src/posts.js
index 3a08272f70..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,34 +26,34 @@ 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, []);
}
var keys = [];
- for (var x=0, numPids=pids.length; x 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 31a82b340f..270d9d480b 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,20 +45,20 @@ 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);
}
}, 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) {
+ posts.forEach(function (post) {
// If the post author isn't represented in the retrieved users' data, then it means they were deleted, assume guest.
if (!results.users.hasOwnProperty(post.uid)) {
post.uid = 0;
@@ -74,23 +74,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);
@@ -99,7 +99,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);
}
@@ -113,22 +113,22 @@ module.exports = function(Posts) {
}
function getTopicAndCategories(topicKeys, callback) {
- db.getObjectsFields(topicKeys, ['uid', 'tid', 'title', 'cid', 'slug', 'deleted', 'postcount', 'mainPid'], function(err, topics) {
+ db.getObjectsFields(topicKeys, ['uid', 'tid', 'title', 'cid', 'slug', 'deleted', 'postcount', 'mainPid'], 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});
});
});
@@ -136,7 +136,7 @@ module.exports = function(Posts) {
function toObject(key, data) {
var obj = {};
- for(var i=0; i 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 921acc2481..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);
}
@@ -207,7 +207,7 @@ module.exports = function(privileges) {
var preventTopicDeleteAfterReplies = parseInt(meta.config.preventTopicDeleteAfterReplies, 10) || 0;
if (preventTopicDeleteAfterReplies && (topicData.postcount - 1) >= preventTopicDeleteAfterReplies) {
var langKey = preventTopicDeleteAfterReplies > 1 ?
- '[[error:cant-delete-topic-has-replies, ' + meta.config.preventTopicDeleteAfterReplies + ']]':
+ '[[error:cant-delete-topic-has-replies, ' + meta.config.preventTopicDeleteAfterReplies + ']]' :
'[[error:cant-delete-topic-has-reply]]';
return callback(new Error(langKey));
}
@@ -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 9775f9c99f..7a178ab9f0 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 6325ec322c..e1e5c79d80 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -84,7 +84,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
@@ -97,13 +97,13 @@ module.exports = function(app, middleware, hotswapIds) {
var ensureLoggedIn = require('connect-ensure-login');
if (Array.isArray(hotswapIds) && hotswapIds.length) {
- for(var idx,x=0;x= 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 acda852ae9..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,17 +27,17 @@ 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 {
numPages = Math.ceil(tids.length / numTopics);
}
- for(var x=1;x<=numPages;x++) {
+ for(var x = 1;x <= numPages;x++) {
returnData.topics.push(x);
}
@@ -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();
}
@@ -124,30 +124,30 @@ sitemap.getTopicPage = function(page, callback) {
var max = min + numTopics;
if (
- sitemap.maps.topics[page-1] &&
- Date.now() < parseInt(sitemap.maps.topics[page-1].cacheSetTimestamp, 10) + parseInt(sitemap.maps.topics[page-1].cacheResetPeriod, 10)
+ sitemap.maps.topics[page - 1] &&
+ Date.now() < parseInt(sitemap.maps.topics[page - 1].cacheSetTimestamp, 10) + parseInt(sitemap.maps.topics[page - 1].cacheResetPeriod, 10)
) {
- return sitemap.maps.topics[page-1].toXML(callback);
+ return sitemap.maps.topics[page - 1].toXML(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,
@@ -158,17 +158,17 @@ sitemap.getTopicPage = function(page, callback) {
}
});
- sitemap.maps.topics[page-1] = sm.createSitemap({
+ sitemap.maps.topics[page - 1] = sm.createSitemap({
hostname: nconf.get('url'),
cacheTime: 1000 * 60 * 60, // Cached for 1 hour
urls: topicUrls
});
- sitemap.maps.topics[page-1].toXML(callback);
+ sitemap.maps.topics[page - 1].toXML(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 fcb52debe1..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) {
@@ -144,7 +144,7 @@ SocketRooms.getLocalStats = function(callback) {
users: {
categories: roomClients.categories ? roomClients.categories.length : 0,
recent: roomClients.recent_topics ? roomClients.recent_topics.length : 0,
- unread: roomClients.unread_topics ? roomClients.unread_topics.length: 0,
+ unread: roomClients.unread_topics ? roomClients.unread_topics.length : 0,
topics: 0,
category: 0
},
@@ -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 d8cbb74e34..3d0a114695 100644
--- a/src/socket.io/admin/user.js
+++ b/src/socket.io/admin/user.js
@@ -11,35 +11,35 @@ 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);
}
- for(var i=0; i 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 453ffed7d2..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,16 +112,16 @@ 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);
}
var uid = results.uid;
var now = new Date();
- var parsedDate = now.getFullYear() + '/' + (now.getMonth()+1) + '/' + now.getDate();
+ 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 9fb8f827a8..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,34 +122,34 @@ 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);
- for (var i=0; i parseInt(max, 10)) {
- return callback(new Error('[[error:'+ maxError + ', ' + max + ']]'));
+ return callback(new Error('[[error:' + maxError + ', ' + max + ']]'));
}
callback();
}
@@ -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 6e7172bb5f..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= (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);
}
@@ -317,7 +317,7 @@ module.exports = function(Topics) {
query = query.toLowerCase();
var matches = [];
- for(var i=0; i 19) {
@@ -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 1c7b2f772a..077b67ad22 100644
--- a/src/user.js
+++ b/src/user.js
@@ -10,7 +10,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');
@@ -36,9 +36,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);
@@ -47,21 +47,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();
@@ -69,7 +69,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();
@@ -79,38 +79,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];
@@ -128,32 +128,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);
}
@@ -164,41 +164,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;
});
@@ -206,23 +206,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);
}
@@ -230,7 +230,7 @@ var meta = require('./meta');
});
};
- User.isModerator = function(uid, cid, callback) {
+ User.isModerator = function (uid, cid, callback) {
privileges.users.isModerator(uid, cid, callback);
};
@@ -247,28 +247,28 @@ var meta = require('./meta');
});
};
- 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]]'));
}
@@ -276,15 +276,15 @@ 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);
@@ -324,17 +324,17 @@ var meta = require('./meta');
], 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 c8af4698a9..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;
}
@@ -126,14 +126,14 @@ module.exports = function(User) {
user.status = User.getStatus(user);
}
- for(var i=0; i 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 984bee50f2..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,33 +22,33 @@ 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);
}
- for (var i=0; i 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 b18d19e338..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*/
@@ -29,22 +29,22 @@
if(!testDbConfig){
errorText = 'test_database is not defined';
winston.info(
- '\n===========================================================\n'+
- 'Please, add parameters for test database in config.json\n'+
- 'For example (redis):\n'+
+ '\n===========================================================\n' +
+ 'Please, add parameters for test database in config.json\n' +
+ 'For example (redis):\n' +
'"test_database": {' + '\n' +
' "host": "127.0.0.1",' + '\n' +
' "port": "6379",' + '\n' +
' "password": "",' + '\n' +
' "database": "1"' + '\n' +
- '}\n'+
+ '}\n' +
' or (mongo):\n' +
'"test_database": {' + '\n' +
' "host": "127.0.0.1",' + '\n' +
' "port": "27017",' + '\n' +
' "password": "",' + '\n' +
' "database": "1"' + '\n' +
- '}\n'+
+ '}\n' +
' or (mongo) in a replicaset' + '\n' +
'"test_database": {' + '\n' +
' "host": "127.0.0.1,127.0.0.1,127.0.0.1",' + '\n' +
@@ -52,7 +52,7 @@
' "username": "",' + '\n' +
' "password": "",' + '\n' +
' "database": "nodebb_test"' + '\n' +
- '}\n'+
+ '}\n' +
'==========================================================='
);
winston.error(errorText);
@@ -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 9ec4e49094..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),
+ 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');