fix(style): switch..case

v1.18.x
Julian Lam 5 years ago
parent d7ab0894d4
commit 922d49be0b

@ -15,25 +15,25 @@ define('admin/advanced/logs', function () {
var action = btnEl.attr('data-action'); var action = btnEl.attr('data-action');
switch (action) { switch (action) {
case 'reload': case 'reload':
socket.emit('admin.logs.get', function (err, logs) { socket.emit('admin.logs.get', function (err, logs) {
if (!err) { if (!err) {
logsEl.text(logs); logsEl.text(logs);
logsEl.scrollTop(logsEl.prop('scrollHeight')); logsEl.scrollTop(logsEl.prop('scrollHeight'));
} else { } else {
app.alertError(err.message); app.alertError(err.message);
} }
}); });
break; break;
case 'clear': case 'clear':
socket.emit('admin.logs.clear', function (err) { socket.emit('admin.logs.clear', function (err) {
if (!err) { if (!err) {
app.alertSuccess('[[admin/advanced/logs:clear-success]]'); app.alertSuccess('[[admin/advanced/logs:clear-success]]');
btnEl.prev().click(); btnEl.prev().click();
} }
}); });
break; break;
} }
}); });
}; };

@ -56,18 +56,18 @@ define('admin/extend/rewards', ['translator', 'benchpress'], function (translato
function select(el) { function select(el) {
el.val(el.attr('data-selected')); el.val(el.attr('data-selected'));
switch (el.attr('name')) { switch (el.attr('name')) {
case 'rid': case 'rid':
selectReward(el); selectReward(el);
break; break;
} }
} }
function update(el) { function update(el) {
el.attr('data-selected', el.val()); el.attr('data-selected', el.val());
switch (el.attr('name')) { switch (el.attr('name')) {
case 'rid': case 'rid':
selectReward(el); selectReward(el);
break; break;
} }
} }
@ -94,15 +94,15 @@ define('admin/extend/rewards', ['translator', 'benchpress'], function (translato
inputs.forEach(function (input) { inputs.forEach(function (input) {
html += '<label for="' + input.name + '">' + input.label + '<br />'; html += '<label for="' + input.name + '">' + input.label + '<br />';
switch (input.type) { switch (input.type) {
case 'select': case 'select':
html += '<select name="' + input.name + '">'; html += '<select name="' + input.name + '">';
input.values.forEach(function (value) { input.values.forEach(function (value) {
html += '<option value="' + value.value + '">' + value.name + '</option>'; html += '<option value="' + value.value + '">' + value.name + '</option>';
}); });
break; break;
case 'text': case 'text':
html += '<input type="text" name="' + input.name + '" />'; html += '<input type="text" name="' + input.name + '" />';
break; break;
} }
html += '</label><br />'; html += '</label><br />';
}); });

@ -45,36 +45,36 @@ define('admin/manage/group', [
var action = btnEl.attr('data-action'); var action = btnEl.attr('data-action');
switch (action) { switch (action) {
case 'toggleOwnership': case 'toggleOwnership':
socket.emit('groups.' + (isOwner ? 'rescind' : 'grant'), { socket.emit('groups.' + (isOwner ? 'rescind' : 'grant'), {
toUid: uid, toUid: uid,
groupName: groupName,
}, function (err) {
if (err) {
return app.alertError(err.message);
}
ownerFlagEl.toggleClass('invisible');
});
break;
case 'kick':
bootbox.confirm('[[admin/manage/groups:edit.confirm-remove-user]]', function (confirm) {
if (!confirm) {
return;
}
socket.emit('admin.groups.leave', {
uid: uid,
groupName: groupName, groupName: groupName,
}, function (err) { }, function (err) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} }
userRow.slideUp().remove(); ownerFlagEl.toggleClass('invisible');
}); });
}); break;
break;
default: case 'kick':
break; bootbox.confirm('[[admin/manage/groups:edit.confirm-remove-user]]', function (confirm) {
if (!confirm) {
return;
}
socket.emit('admin.groups.leave', {
uid: uid,
groupName: groupName,
}, function (err) {
if (err) {
return app.alertError(err.message);
}
userRow.slideUp().remove();
});
});
break;
default:
break;
} }
}); });

@ -58,21 +58,21 @@ define('admin/manage/groups', ['translator', 'benchpress'], function (translator
var groupName = el.parents('tr[data-groupname]').attr('data-groupname'); var groupName = el.parents('tr[data-groupname]').attr('data-groupname');
switch (action) { switch (action) {
case 'delete': case 'delete':
bootbox.confirm('[[admin/manage/groups:alerts.confirm-delete]]', function (confirm) { bootbox.confirm('[[admin/manage/groups:alerts.confirm-delete]]', function (confirm) {
if (confirm) { if (confirm) {
socket.emit('groups.delete', { socket.emit('groups.delete', {
groupName: groupName, groupName: groupName,
}, function (err) { }, function (err) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} }
ajaxify.refresh(); ajaxify.refresh();
}); });
} }
}); });
break; break;
} }
}); });
}; };

@ -156,17 +156,17 @@ define('admin/settings', ['uploader'], function (uploader) {
if (field.is('input')) { if (field.is('input')) {
inputType = field.attr('type'); inputType = field.attr('type');
switch (inputType) { switch (inputType) {
case 'text': case 'text':
case 'password': case 'password':
case 'hidden': case 'hidden':
case 'textarea': case 'textarea':
case 'number': case 'number':
value = field.val(); value = field.val();
break; break;
case 'checkbox': case 'checkbox':
value = field.prop('checked') ? '1' : '0'; value = field.prop('checked') ? '1' : '0';
break; break;
} }
} else if (field.is('textarea') || field.is('select')) { } else if (field.is('textarea') || field.is('select')) {
value = field.val(); value = field.val();

@ -275,25 +275,25 @@ app.cacheBuster = null;
function showAlert(type, message) { function showAlert(type, message) {
switch (messages[type].format) { switch (messages[type].format) {
case 'alert': case 'alert':
app.alert({ app.alert({
type: 'success', type: 'success',
title: messages[type].title, title: messages[type].title,
message: messages[type].message, message: messages[type].message,
timeout: 5000, timeout: 5000,
}); });
break; break;
case 'modal': case 'modal':
require(['translator'], function (translator) { require(['translator'], function (translator) {
translator.translate(message || messages[type].message, function (translated) { translator.translate(message || messages[type].message, function (translated) {
bootbox.alert({ bootbox.alert({
title: messages[type].title, title: messages[type].title,
message: translated, message: translated,
});
}); });
}); });
}); break;
break;
} }
} }

@ -61,13 +61,13 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds'
} }
switch (input.attr('type')) { switch (input.attr('type')) {
case 'text': case 'text':
case 'textarea': case 'textarea':
settings[setting] = input.val(); settings[setting] = input.val();
break; break;
case 'checkbox': case 'checkbox':
settings[setting] = input.is(':checked') ? 1 : 0; settings[setting] = input.is(':checked') ? 1 : 0;
break; break;
} }
}); });

@ -157,18 +157,18 @@ define('forum/chats', [
var action = this.getAttribute('data-action'); var action = this.getAttribute('data-action');
switch (action) { switch (action) {
case 'edit': case 'edit':
var inputEl = $('[data-roomid="' + roomId + '"] [component="chat/input"]'); var inputEl = $('[data-roomid="' + roomId + '"] [component="chat/input"]');
messages.prepEdit(inputEl, messageId, roomId); messages.prepEdit(inputEl, messageId, roomId);
break; break;
case 'delete': case 'delete':
messages.delete(messageId, roomId); messages.delete(messageId, roomId);
break; break;
case 'restore': case 'restore':
messages.restore(messageId, roomId); messages.restore(messageId, roomId);
break; break;
} }
}); });
}; };

@ -13,44 +13,44 @@ define('forum/flags/detail', ['forum/flags/list', 'components', 'translator', 'b
var uid = $(this).parents('[data-uid]').attr('data-uid'); var uid = $(this).parents('[data-uid]').attr('data-uid');
switch (action) { switch (action) {
case 'update': case 'update':
socket.emit('flags.update', { socket.emit('flags.update', {
flagId: ajaxify.data.flagId, flagId: ajaxify.data.flagId,
data: $('#attributes').serializeArray(), data: $('#attributes').serializeArray(),
}, function (err, history) { }, function (err, history) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} }
app.alertSuccess('[[flags:updated]]'); app.alertSuccess('[[flags:updated]]');
Detail.reloadHistory(history); Detail.reloadHistory(history);
}); });
break; break;
case 'appendNote': case 'appendNote':
socket.emit('flags.appendNote', { socket.emit('flags.appendNote', {
flagId: ajaxify.data.flagId, flagId: ajaxify.data.flagId,
note: document.getElementById('note').value, note: document.getElementById('note').value,
}, function (err, payload) { }, function (err, payload) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} }
app.alertSuccess('[[flags:note-added]]'); app.alertSuccess('[[flags:note-added]]');
Detail.reloadNotes(payload.notes); Detail.reloadNotes(payload.notes);
Detail.reloadHistory(payload.history); Detail.reloadHistory(payload.history);
}); });
break; break;
case 'chat': case 'chat':
app.newChat(uid); app.newChat(uid);
break; break;
case 'ban': case 'ban':
AccountHeader.banAccount(uid, ajaxify.refresh); AccountHeader.banAccount(uid, ajaxify.refresh);
break; break;
case 'delete': case 'delete':
AccountHeader.deleteAccount(uid, ajaxify.refresh); AccountHeader.deleteAccount(uid, ajaxify.refresh);
break; break;
} }
}); });

@ -63,69 +63,69 @@ define('forum/groups/details', [
var action = btnEl.attr('data-action'); var action = btnEl.attr('data-action');
switch (action) { switch (action) {
case 'toggleOwnership': case 'toggleOwnership':
socket.emit('groups.' + (isOwner ? 'rescind' : 'grant'), { socket.emit('groups.' + (isOwner ? 'rescind' : 'grant'), {
toUid: uid, toUid: uid,
groupName: groupName, groupName: groupName,
}, function (err) { }, function (err) {
if (!err) { if (!err) {
ownerFlagEl.toggleClass('invisible'); ownerFlagEl.toggleClass('invisible');
} else { } else {
app.alertError(err.message); app.alertError(err.message);
}
});
break;
case 'kick':
translator.translate('[[groups:details.kick_confirm]]', function (translated) {
bootbox.confirm(translated, function (confirm) {
if (!confirm) {
return;
} }
});
break;
socket.emit('groups.kick', { case 'kick':
uid: uid, translator.translate('[[groups:details.kick_confirm]]', function (translated) {
groupName: groupName, bootbox.confirm(translated, function (confirm) {
}, function (err) { if (!confirm) {
if (!err) { return;
userRow.slideUp().remove();
} else {
app.alertError(err.message);
} }
socket.emit('groups.kick', {
uid: uid,
groupName: groupName,
}, function (err) {
if (!err) {
userRow.slideUp().remove();
} else {
app.alertError(err.message);
}
});
}); });
}); });
}); break;
break;
case 'update':
case 'update': Details.update();
Details.update(); break;
break;
case 'delete':
case 'delete': Details.deleteGroup();
Details.deleteGroup(); break;
break;
case 'join': // intentional fall-throughs!
case 'join': // intentional fall-throughs! case 'leave':
case 'leave': case 'accept':
case 'accept': case 'reject':
case 'reject': case 'issueInvite':
case 'issueInvite': case 'rescindInvite':
case 'rescindInvite': case 'acceptInvite':
case 'acceptInvite': case 'rejectInvite':
case 'rejectInvite': case 'acceptAll':
case 'acceptAll': case 'rejectAll':
case 'rejectAll': socket.emit('groups.' + action, {
socket.emit('groups.' + action, { toUid: uid,
toUid: uid, groupName: groupName,
groupName: groupName, }, function (err) {
}, function (err) { if (!err) {
if (!err) { ajaxify.refresh();
ajaxify.refresh(); } else {
} else { app.alertError(err.message);
app.alertError(err.message); }
} });
}); break;
break;
} }
}); });
}; };

@ -107,16 +107,16 @@ $('document').ready(function () {
} }
switch (type) { switch (type) {
case 'admin:username': case 'admin:username':
return validateUsername(field); return validateUsername(field);
case 'admin:password': case 'admin:password':
return validatePassword(field); return validatePassword(field);
case 'admin:passwordConfirm': case 'admin:passwordConfirm':
return validateConfirmPassword(field); return validateConfirmPassword(field);
case 'admin:email': case 'admin:email':
return validateEmail(field); return validateEmail(field);
case 'database': case 'database':
return switchDatabase(field); return switchDatabase(field);
} }
} }

@ -225,49 +225,49 @@
var icons = ''; var icons = '';
switch (data.platform) { switch (data.platform) {
case 'Linux': case 'Linux':
icons += '<i class="fa fa-fw fa-linux"></i>'; icons += '<i class="fa fa-fw fa-linux"></i>';
break; break;
case 'Microsoft Windows': case 'Microsoft Windows':
icons += '<i class="fa fa-fw fa-windows"></i>'; icons += '<i class="fa fa-fw fa-windows"></i>';
break; break;
case 'Apple Mac': case 'Apple Mac':
icons += '<i class="fa fa-fw fa-apple"></i>'; icons += '<i class="fa fa-fw fa-apple"></i>';
break; break;
case 'Android': case 'Android':
icons += '<i class="fa fa-fw fa-android"></i>'; icons += '<i class="fa fa-fw fa-android"></i>';
break; break;
case 'iPad': case 'iPad':
icons += '<i class="fa fa-fw fa-tablet"></i>'; icons += '<i class="fa fa-fw fa-tablet"></i>';
break; break;
case 'iPod': // intentional fall-through case 'iPod': // intentional fall-through
case 'iPhone': case 'iPhone':
icons += '<i class="fa fa-fw fa-mobile"></i>'; icons += '<i class="fa fa-fw fa-mobile"></i>';
break; break;
default: default:
icons += '<i class="fa fa-fw fa-question-circle"></i>'; icons += '<i class="fa fa-fw fa-question-circle"></i>';
break; break;
} }
switch (data.browser) { switch (data.browser) {
case 'Chrome': case 'Chrome':
icons += '<i class="fa fa-fw fa-chrome"></i>'; icons += '<i class="fa fa-fw fa-chrome"></i>';
break; break;
case 'Firefox': case 'Firefox':
icons += '<i class="fa fa-fw fa-firefox"></i>'; icons += '<i class="fa fa-fw fa-firefox"></i>';
break; break;
case 'Safari': case 'Safari':
icons += '<i class="fa fa-fw fa-safari"></i>'; icons += '<i class="fa fa-fw fa-safari"></i>';
break; break;
case 'IE': case 'IE':
icons += '<i class="fa fa-fw fa-internet-explorer"></i>'; icons += '<i class="fa fa-fw fa-internet-explorer"></i>';
break; break;
case 'Edge': case 'Edge':
icons += '<i class="fa fa-fw fa-edge"></i>'; icons += '<i class="fa fa-fw fa-edge"></i>';
break; break;
default: default:
icons += '<i class="fa fa-fw fa-question-circle"></i>'; icons += '<i class="fa fa-fw fa-question-circle"></i>';
break; break;
} }
return icons; return icons;

@ -141,28 +141,28 @@ define('settings/key', function () {
for (var i = 0; i < parts.length; i += 1) { for (var i = 0; i < parts.length; i += 1) {
var part = parts[i]; var part = parts[i];
switch (part) { switch (part) {
case 'C': case 'C':
case 'Ctrl': case 'Ctrl':
key.c = true; key.c = true;
break; break;
case 'A': case 'A':
case 'Alt': case 'Alt':
key.a = true; key.a = true;
break; break;
case 'S': case 'S':
case 'Shift': case 'Shift':
key.s = true; key.s = true;
break; break;
case 'M': case 'M':
case 'Meta': case 'Meta':
key.m = true; key.m = true;
break; break;
default: default:
var num = /\d+/.exec(part); var num = /\d+/.exec(part);
if (num != null) { if (num != null) {
key.code = num[0]; key.code = num[0];
} }
key.char = convertKeyCodeToChar(key.code); key.char = convertKeyCodeToChar(key.code);
} }
} }
return key; return key;

@ -183,18 +183,18 @@ define('taskbar', ['benchpress', 'translator'], function (Benchpress, translator
var processUpdate = function (element, key, value) { var processUpdate = function (element, key, value) {
switch (key) { switch (key) {
case 'title': case 'title':
element.find('[component="taskbar/title"]').text(value); element.find('[component="taskbar/title"]').text(value);
break; break;
case 'icon': case 'icon':
element.find('i').attr('class', 'fa fa-' + value); element.find('i').attr('class', 'fa fa-' + value);
break; break;
case 'image': case 'image':
element.find('a').css('background-image', 'url("' + value + '")'); element.find('a').css('background-image', 'url("' + value + '")');
break; break;
case 'background-color': case 'background-color':
element.find('a').css('background-color', value); element.find('a').css('background-color', value);
break; break;
} }
}; };

@ -109,30 +109,30 @@ app.isConnected = false;
var room; var room;
switch (url_parts[0]) { switch (url_parts[0]) {
case 'user': case 'user':
room = 'user/' + (ajaxify.data ? ajaxify.data.theirid : 0); room = 'user/' + (ajaxify.data ? ajaxify.data.theirid : 0);
break; break;
case 'topic': case 'topic':
room = 'topic_' + url_parts[1]; room = 'topic_' + url_parts[1];
break; break;
case 'category': case 'category':
room = 'category_' + url_parts[1]; room = 'category_' + url_parts[1];
break; break;
case 'recent': case 'recent':
room = 'recent_topics'; room = 'recent_topics';
break; break;
case 'unread': case 'unread':
room = 'unread_topics'; room = 'unread_topics';
break; break;
case 'popular': case 'popular':
room = 'popular_topics'; room = 'popular_topics';
break; break;
case 'admin': case 'admin':
room = 'admin'; room = 'admin';
break; break;
case 'categories': case 'categories':
room = 'categories'; room = 'categories';
break; break;
} }
app.currentRoom = ''; app.currentRoom = '';
app.enterRoom(room); app.enterRoom(room);

@ -175,15 +175,15 @@ function info() {
var config = require('../../config.json'); var config = require('../../config.json');
switch (config.database) { switch (config.database) {
case 'redis': case 'redis':
console.log(' version: ' + info.redis_version); console.log(' version: ' + info.redis_version);
console.log(' disk sync: ' + info.rdb_last_bgsave_status); console.log(' disk sync: ' + info.rdb_last_bgsave_status);
break; break;
case 'mongo': case 'mongo':
console.log(' version: ' + info.version); console.log(' version: ' + info.version);
console.log(' engine: ' + info.storageEngine); console.log(' engine: ' + info.storageEngine);
break; break;
} }
next(); next();

@ -43,17 +43,17 @@ function installAll() {
const packageManager = require('nconf').get('package_manager'); const packageManager = require('nconf').get('package_manager');
if (supportedPackageManagerList.indexOf(packageManager) >= 0) { if (supportedPackageManagerList.indexOf(packageManager) >= 0) {
switch (packageManager) { switch (packageManager) {
case 'yarn': case 'yarn':
command = 'yarn'; command = 'yarn';
break; break;
case 'pnpm': case 'pnpm':
command = 'pnpm install'; command = 'pnpm install';
break; break;
case 'cnpm': case 'cnpm':
command = 'cnpm install'; command = 'cnpm install';
break; break;
default: default:
break; break;
} }
} }
} catch (e) { } catch (e) {

@ -151,25 +151,25 @@ userController.exportUploads = function (req, res, next) {
archive.on('warning', function (err) { archive.on('warning', function (err) {
switch (err.code) { switch (err.code) {
case 'ENOENT': case 'ENOENT':
winston.warn('[user/export/uploads] File not found: ' + trimPath(err.path)); winston.warn('[user/export/uploads] File not found: ' + trimPath(err.path));
break; break;
default: default:
winston.warn('[user/export/uploads] Unexpected warning: ' + err.message); winston.warn('[user/export/uploads] Unexpected warning: ' + err.message);
break; break;
} }
}); });
archive.on('error', function (err) { archive.on('error', function (err) {
switch (err.code) { switch (err.code) {
case 'EACCES': case 'EACCES':
winston.error('[user/export/uploads] File inaccessible: ' + trimPath(err.path)); winston.error('[user/export/uploads] File inaccessible: ' + trimPath(err.path));
break; break;
default: default:
winston.error('[user/export/uploads] Unable to construct archive: ' + err.message); winston.error('[user/export/uploads] Unable to construct archive: ' + err.message);
break; break;
} }
res.sendStatus(500); res.sendStatus(500);

@ -63,9 +63,9 @@ Flags.init = async function () {
perPage: function () { /* noop */ }, perPage: function () { /* noop */ },
quick: function (sets, orSets, key, uid) { quick: function (sets, orSets, key, uid) {
switch (key) { switch (key) {
case 'mine': case 'mine':
sets.push('flags:byAssignee:' + uid); sets.push('flags:byAssignee:' + uid);
break; break;
} }
}, },
}, },

@ -31,18 +31,18 @@ module.exports = function (Groups) {
Groups.sort = function (strategy, groups) { Groups.sort = function (strategy, groups) {
switch (strategy) { switch (strategy) {
case 'count': case 'count':
groups.sort((a, b) => a.slug > b.slug) groups.sort((a, b) => a.slug > b.slug)
.sort((a, b) => b.memberCount - a.memberCount); .sort((a, b) => b.memberCount - a.memberCount);
break; break;
case 'date': case 'date':
groups.sort((a, b) => b.createtime - a.createtime); groups.sort((a, b) => b.createtime - a.createtime);
break; break;
case 'alpha': // intentional fall-through case 'alpha': // intentional fall-through
default: default:
groups.sort((a, b) => (a.slug > b.slug ? 1 : -1)); groups.sort((a, b) => (a.slug > b.slug ? 1 : -1));
} }
return groups; return groups;

@ -87,44 +87,44 @@ async function getThemes(themePath) {
Themes.set = async (data) => { Themes.set = async (data) => {
switch (data.type) { switch (data.type) {
case 'local': { case 'local': {
const current = await Meta.configs.get('theme:id'); const current = await Meta.configs.get('theme:id');
if (current !== data.id) { if (current !== data.id) {
let config = await fsReadfile(path.join(nconf.get('themes_path'), data.id, 'theme.json'), 'utf8'); let config = await fsReadfile(path.join(nconf.get('themes_path'), data.id, 'theme.json'), 'utf8');
config = JSON.parse(config); config = JSON.parse(config);
await db.sortedSetRemove('plugins:active', current); await db.sortedSetRemove('plugins:active', current);
const numPlugins = await db.sortedSetCard('plugins:active'); const numPlugins = await db.sortedSetCard('plugins:active');
await db.sortedSetAdd('plugins:active', numPlugins, data.id); await db.sortedSetAdd('plugins:active', numPlugins, data.id);
// Re-set the themes path (for when NodeBB is reloaded) // Re-set the themes path (for when NodeBB is reloaded)
Themes.setPath(config); Themes.setPath(config);
await Meta.configs.setMultiple({
'theme:type': data.type,
'theme:id': data.id,
'theme:staticDir': config.staticDir ? config.staticDir : '',
'theme:templates': config.templates ? config.templates : '',
'theme:src': '',
bootswatchSkin: '',
});
await events.log({
type: 'theme-set',
uid: parseInt(data.uid, 10) || 0,
ip: data.ip || '127.0.0.1',
text: data.id,
});
Meta.reloadRequired = true;
}
break;
}
case 'bootswatch':
await Meta.configs.setMultiple({ await Meta.configs.setMultiple({
'theme:type': data.type, 'theme:src': data.src,
'theme:id': data.id, bootswatchSkin: data.id.toLowerCase(),
'theme:staticDir': config.staticDir ? config.staticDir : '',
'theme:templates': config.templates ? config.templates : '',
'theme:src': '',
bootswatchSkin: '',
});
await events.log({
type: 'theme-set',
uid: parseInt(data.uid, 10) || 0,
ip: data.ip || '127.0.0.1',
text: data.id,
}); });
break;
Meta.reloadRequired = true;
}
break;
}
case 'bootswatch':
await Meta.configs.setMultiple({
'theme:src': data.src,
bootswatchSkin: data.id.toLowerCase(),
});
break;
} }
}; };

@ -373,30 +373,30 @@ Notifications.merge = async function (notifications) {
} }
switch (mergeId) { switch (mergeId) {
case 'notifications:upvoted_your_post_in': case 'notifications:upvoted_your_post_in':
case 'notifications:user_started_following_you': case 'notifications:user_started_following_you':
case 'notifications:user_posted_to': case 'notifications:user_posted_to':
case 'notifications:user_flagged_post_in': case 'notifications:user_flagged_post_in':
case 'notifications:user_flagged_user': case 'notifications:user_flagged_user':
var usernames = _.uniq(set.map(notifObj => notifObj && notifObj.user && notifObj.user.username)); var usernames = _.uniq(set.map(notifObj => notifObj && notifObj.user && notifObj.user.username));
var numUsers = usernames.length; var numUsers = usernames.length;
var title = utils.decodeHTMLEntities(notifications[modifyIndex].topicTitle || ''); var title = utils.decodeHTMLEntities(notifications[modifyIndex].topicTitle || '');
var titleEscaped = title.replace(/%/g, '&#37;').replace(/,/g, '&#44;'); var titleEscaped = title.replace(/%/g, '&#37;').replace(/,/g, '&#44;');
titleEscaped = titleEscaped ? (', ' + titleEscaped) : ''; titleEscaped = titleEscaped ? (', ' + titleEscaped) : '';
if (numUsers === 2) { if (numUsers === 2) {
notifications[modifyIndex].bodyShort = '[[' + mergeId + '_dual, ' + usernames.join(', ') + titleEscaped + ']]'; notifications[modifyIndex].bodyShort = '[[' + mergeId + '_dual, ' + usernames.join(', ') + titleEscaped + ']]';
} else if (numUsers > 2) { } else if (numUsers > 2) {
notifications[modifyIndex].bodyShort = '[[' + mergeId + '_multiple, ' + usernames[0] + ', ' + (numUsers - 1) + titleEscaped + ']]'; 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; break;
case 'new_register': case 'new_register':
notifications[modifyIndex].bodyShort = '[[notifications:' + mergeId + '_multiple, ' + set.length + ']]'; notifications[modifyIndex].bodyShort = '[[notifications:' + mergeId + '_multiple, ' + set.length + ']]';
break; break;
} }
// Filter out duplicates // Filter out duplicates

@ -90,20 +90,20 @@ module.exports = function (Plugins) {
// clear old data before build // clear old data before build
fields.forEach((field) => { fields.forEach((field) => {
switch (field) { switch (field) {
case 'clientScripts': case 'clientScripts':
case 'acpScripts': case 'acpScripts':
case 'cssFiles': case 'cssFiles':
case 'lessFiles': case 'lessFiles':
case 'acpLessFiles': case 'acpLessFiles':
Plugins[field].length = 0; Plugins[field].length = 0;
break; break;
case 'soundpack': case 'soundpack':
Plugins.soundpacks.length = 0; Plugins.soundpacks.length = 0;
break; break;
case 'languageData': case 'languageData':
Plugins.languageData.languages = []; Plugins.languageData.languages = [];
Plugins.languageData.namespaces = []; Plugins.languageData.namespaces = [];
break; break;
// do nothing for modules and staticDirs // do nothing for modules and staticDirs
} }
}); });

@ -15,55 +15,55 @@ Email.test = function (socket, data, callback) {
}; };
switch (data.template) { switch (data.template) {
case 'digest': case 'digest':
userDigest.execute({ userDigest.execute({
interval: 'alltime', interval: 'alltime',
subscribers: [socket.uid], subscribers: [socket.uid],
}, callback); }, callback);
break; break;
case 'banned': case 'banned':
Object.assign(payload, { Object.assign(payload, {
username: 'test-user', username: 'test-user',
until: utils.toISOString(Date.now()), until: utils.toISOString(Date.now()),
reason: 'Test Reason', reason: 'Test Reason',
}); });
emailer.send(data.template, socket.uid, payload, callback); emailer.send(data.template, socket.uid, payload, callback);
break; break;
case 'welcome': case 'welcome':
userEmail.sendValidationEmail(socket.uid, { userEmail.sendValidationEmail(socket.uid, {
force: 1, force: 1,
}, callback); }, callback);
break; break;
case 'notification': case 'notification':
async.waterfall([ async.waterfall([
function (next) { function (next) {
notifications.create({ notifications.create({
type: 'test', type: 'test',
bodyShort: '[[email:notif.test.short]]', bodyShort: '[[email:notif.test.short]]',
bodyLong: '[[email:notif.test.long]]', bodyLong: '[[email:notif.test.long]]',
nid: 'uid:' + socket.uid + ':test', nid: 'uid:' + socket.uid + ':test',
path: '/', path: '/',
from: socket.uid, from: socket.uid,
}, next); }, next);
}, },
function (notifObj, next) { function (notifObj, next) {
emailer.send('notification', socket.uid, { emailer.send('notification', socket.uid, {
path: notifObj.path, path: notifObj.path,
subject: utils.stripHTMLTags(notifObj.subject || '[[notifications:new_notification]]'), subject: utils.stripHTMLTags(notifObj.subject || '[[notifications:new_notification]]'),
intro: utils.stripHTMLTags(notifObj.bodyShort), intro: utils.stripHTMLTags(notifObj.bodyShort),
body: notifObj.bodyLong || '', body: notifObj.bodyLong || '',
notification: notifObj, notification: notifObj,
showUnsubscribe: true, showUnsubscribe: true,
}, next); }, next);
}, },
], callback); ], callback);
break; break;
default: default:
emailer.send(data.template, socket.uid, payload, callback); emailer.send(data.template, socket.uid, payload, callback);
break; break;
} }
}; };

@ -50,17 +50,17 @@ start.start = async function () {
} }
} catch (err) { } catch (err) {
switch (err.message) { switch (err.message) {
case 'dependencies-out-of-date': case 'dependencies-out-of-date':
winston.error('One or more of NodeBB\'s dependent packages are out-of-date. Please run the following command to update them:'); winston.error('One or more of NodeBB\'s dependent packages are out-of-date. Please run the following command to update them:');
winston.error(' ./nodebb upgrade'); winston.error(' ./nodebb upgrade');
break; break;
case 'dependencies-missing': case 'dependencies-missing':
winston.error('One or more of NodeBB\'s dependent packages are missing. Please run the following command to update them:'); winston.error('One or more of NodeBB\'s dependent packages are missing. Please run the following command to update them:');
winston.error(' ./nodebb upgrade'); winston.error(' ./nodebb upgrade');
break; break;
default: default:
winston.error(err.stack); winston.error(err.stack);
break; break;
} }
// Either way, bad stuff happened. Abort start. // Either way, bad stuff happened. Abort start.

Loading…
Cancel
Save