Skip to content

Node.js based forum software built for the modern web

Merge branch 'master' into develop

Julian Lam72e77772dbca
diff --cc package.json
index ebbfc51212,94c021490d..a733cdebb2
--- a/package.json
+++ b/package.json
@@@ -53,11 -53,11 +53,11 @@@
"mousetrap": "^1.5.3",
"nconf": "~0.8.2",
"nodebb-plugin-composer-default": "4.4.1",
- "nodebb-plugin-dbsearch": "1.0.5",
+ "nodebb-plugin-dbsearch": "2.0.2",
"nodebb-plugin-emoji-extended": "1.1.1",
"nodebb-plugin-emoji-one": "1.1.5",
- "nodebb-plugin-markdown": "7.1.0",
+ "nodebb-plugin-markdown": "7.1.1",
- "nodebb-plugin-mentions": "1.1.3",
+ "nodebb-plugin-mentions": "2.0.1",
"nodebb-plugin-soundpack-default": "1.0.0",
"nodebb-plugin-spam-be-gone": "0.4.10",
"nodebb-rewards-essentials": "0.0.9",
diff --cc public/src/admin/general/dashboard.js
index 5a582abbda,363311c9f9..696ad80fae
--- a/public/src/admin/general/dashboard.js
+++ b/public/src/admin/general/dashboard.js
@@@ -289,19 -294,14 +292,19 @@@ define('admin/general/dashboard', ['sem
$('[data-action="updateGraph"]').on('click', function () {
var until;
- switch($(this).attr('data-until')) {
- case 'last-month':
- var lastMonth = new Date();
- lastMonth.setDate(lastMonth.getDate() - 30);
- until = lastMonth.getTime();
+ switch ($(this).attr('data-until')) {
+ case 'last-month':
+ var lastMonth = new Date();
+ lastMonth.setDate(lastMonth.getDate() - 30);
+ until = lastMonth.getTime();
}
updateTrafficGraph($(this).attr('data-units'), until);
+ $('[data-action="updateGraph"]').removeClass('active');
+ $(this).addClass('active');
});
+
+ socket.emit('admin.rooms.getAll', Admin.updateRoomUsage);
+ initiateDashboard();
});
}
diff --cc public/src/client/topic/replies.js
index d025091d1e,56b5981843..bdb2cc1519
--- a/public/src/client/topic/replies.js
+++ b/public/src/client/topic/replies.js
@@@ -18,12 -16,12 +16,12 @@@ define('forum/topic/replies', ['navigat
});
}
- function onRepliesClicked(button, tid) {
+ function onRepliesClicked(button) {
var post = button.closest('[data-pid]');
var pid = post.data('pid');
- var open = button.children('[component="post/replies/open"]');
- var loading = button.children('[component="post/replies/loading"]');
- var close = button.children('[component="post/replies/close"]');
+ var open = button.find('[component="post/replies/open"]');
+ var loading = button.find('[component="post/replies/loading"]');
+ var close = button.find('[component="post/replies/close"]');
if (open.is(':not(.hidden)') && loading.is('.hidden')) {
open.addClass('hidden');
diff --cc public/src/modules/chat.js
index 68eecec1db,2a226a28a7..1d4150b179
--- a/public/src/modules/chat.js
+++ b/public/src/modules/chat.js
@@@ -70,9 -69,9 +69,9 @@@ define('chat',
sounds.play('chat-incoming', 'chat.incoming:' + data.message.mid);
taskbar.push('chat', modal.attr('UUID'), {
- title: username,
+ title: data.roomName || username,
touid: data.message.fromUser.uid,
- roomId: data.roomId
+ roomId: data.roomId,
});
}
} else {
diff --cc public/src/modules/flags.js
index cc9fd5103a,1d1c68a8c3..f95953c65e
--- a/public/src/modules/flags.js
+++ b/public/src/modules/flags.js
@@@ -1,14 -1,17 +1,13 @@@
'use strict';
- /* globals define, app, socket, templates */
-define('forum/topic/flag', [], function () {
+define('flags', [], function () {
- var Flag = {},
- flagModal,
- flagCommit;
+ var Flag = {};
+ var flagModal;
+ var flagCommit;
- Flag.showFlagModal = function (pid, username, userslug) {
- parseModal({
- pid: pid,
- username: username,
- userslug: userslug,
- }, function (html) {
+ Flag.showFlagModal = function (data) {
+ parseModal(data, function (html) {
flagModal = $(html);
flagModal.on('hidden.bs.modal', function () {
@@@ -39,11 -42,11 +38,11 @@@
});
}
- function flagPost(pid, reason) {
- if (!pid || !reason) {
+ function createFlag(type, id, reason) {
+ if (!type || !id || !reason) {
return;
}
- socket.emit('flags.create', {type: type, id: id, reason: reason}, function (err) {
- socket.emit('posts.flag', { pid: pid, reason: reason }, function (err) {
++ socket.emit('flags.create', { type: type, id: id, reason: reason }, function (err) {
if (err) {
return app.alertError(err.message);
}
diff --cc src/analytics.js
index c6cfbeba7e,6a733b1a5f..8e9871580b
--- a/src/analytics.js
+++ b/src/analytics.js
@@@ -25,12 -25,8 +25,12 @@@ Analytics.increment = function (keys, c
keys.forEach(function (key) {
counters[key] = counters[key] || 0;
- ++counters[key];
+ counters[key] += 1;
});
+
+ if (typeof callback === 'function') {
+ callback();
+ }
};
Analytics.pageView = function (payload) {
diff --cc src/categories/create.js
index ba12fc31b0,7be163bd5b..140b23dc9d
--- a/src/categories/create.js
+++ b/src/categories/create.js
@@@ -73,9 -72,9 +72,9 @@@ module.exports = function (Categories)
next(null, category);
},
function (category, next) {
- plugins.fireHook('action:category.create', category);
+ plugins.fireHook('action:category.create', {category: category});
next(null, category);
- }
+ },
], callback);
};
diff --cc src/categories/delete.js
index cb0d30a09d,4aad25846f..b9ddeca6a4
--- a/src/categories/delete.js
+++ b/src/categories/delete.js
@@@ -31,9 -30,9 +30,9 @@@ module.exports = function (Categories)
purgeCategory(cid, next);
},
function (next) {
- plugins.fireHook('action:category.delete', cid);
+ plugins.fireHook('action:category.delete', {cid: cid, uid: uid});
next();
- }
+ },
], callback);
};
diff --cc src/controllers/admin/themes.js
index 97e7a58d6e,598cd7cf94..94fdf43746
--- a/src/controllers/admin/themes.js
+++ b/src/controllers/admin/themes.js
@@@ -7,13 -7,13 +7,13 @@@ var themesController = {}
themesController.get = function (req, res, next) {
var themeDir = path.join(__dirname, '../../../node_modules/' + req.params.theme);
- file.exists(themeDir, function (exists) {
- if (!exists) {
- return next();
+ file.exists(themeDir, function (err, exists) {
+ if (err || !exists) {
+ return next(err);
}
- var themeConfig = require(path.join(themeDir, 'theme.json')),
- screenshotPath = path.join(themeDir, themeConfig.screenshot);
+ var themeConfig = require(path.join(themeDir, 'theme.json'));
+ var screenshotPath = path.join(themeDir, themeConfig.screenshot);
if (themeConfig.screenshot && file.existsSync(screenshotPath)) {
res.sendFile(screenshotPath);
} else {
diff --cc src/controllers/mods.js
index 8056b8c5b5,6a1835f980..a34ebacb8b
--- a/src/controllers/mods.js
+++ b/src/controllers/mods.js
@@@ -3,23 -3,17 +3,23 @@@
var async = require('async');
var user = require('../user');
-var adminFlagsController = require('./admin/flags');
+var categories = require('../categories');
+var flags = require('../flags');
+var analytics = require('../analytics');
-var modsController = {};
+var modsController = {
+ flags: {}
+};
-modsController.flagged = function (req, res, next) {
+modsController.flags.list = function (req, res, next) {
async.parallel({
isAdminOrGlobalMod: async.apply(user.isAdminOrGlobalMod, req.uid),
- moderatedCids: async.apply(user.getModeratedCids, req.uid)
+ moderatedCids: async.apply(user.getModeratedCids, req.uid),
}, function (err, results) {
- if (err || !(results.isAdminOrGlobalMod || !!results.moderatedCids.length)) {
+ if (err) {
return next(err);
+ } else if (!(results.isAdminOrGlobalMod || !!results.moderatedCids.length)) {
+ return next(new Error('[[error:no-privileges]]'));
}
if (!results.isAdminOrGlobalMod && results.moderatedCids.length) {
diff --cc src/controllers/search.js
index db3adf0682,29a883489f..be98589c54
--- a/src/controllers/search.js
+++ b/src/controllers/search.js
@@@ -65,9 -65,8 +65,9 @@@ searchController.search = function (req
searchData.showAsPosts = !req.query.showAs || req.query.showAs === 'posts';
searchData.showAsTopics = req.query.showAs === 'topics';
searchData.title = '[[global:header.search]]';
- searchData.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:search]]'}]);
+ searchData.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[global:search]]' }]);
searchData.expandSearch = !req.query.term;
+ searchData.searchDefaultSortBy = meta.config.searchDefaultSortBy || '';
res.render('search', searchData);
});
diff --cc src/controllers/unread.js
index 8be52f955c,c5d0d4d950..5e00cf5c96
--- a/src/controllers/unread.js
+++ b/src/controllers/unread.js
@@@ -40,16 -40,8 +40,16 @@@ unreadController.get = function (req, r
settings = results.settings;
var start = Math.max(0, (page - 1) * settings.topicsPerPage);
var stop = start + settings.topicsPerPage - 1;
- topics.getUnreadTopics(cid, req.uid, start, stop, filter, next);
+ var cutoff = req.session.unreadCutoff ? req.session.unreadCutoff : topics.unreadCutoff();
+ topics.getUnreadTopics({
+ cid: cid,
+ uid: req.uid,
+ start: start,
+ stop: stop,
+ filter: filter,
- cutoff: cutoff
++ cutoff: cutoff,
+ }, next);
- }
+ },
], function (err, data) {
if (err) {
return next(err);
diff --cc src/groups/create.js
index e4533e1ab0,4b680b8992..c7d57b1ebb
--- a/src/groups/create.js
+++ b/src/groups/create.js
@@@ -70,11 -69,10 +69,10 @@@ module.exports = function (Groups)
async.series(tasks, next);
},
function (results, next) {
- plugins.fireHook('action:group.create', groupData);
+ plugins.fireHook('action:group.create', {group: groupData});
next(null, groupData);
- }
+ },
], callback);
-
};
function isSystemGroup(data) {
diff --cc src/meta/dependencies.js
index fdfa755198,939f14b674..034061f636
--- a/src/meta/dependencies.js
+++ b/src/meta/dependencies.js
@@@ -19,25 -19,22 +19,25 @@@ module.exports = function (Meta)
winston.verbose('Checking dependencies for outdated modules');
- async.every(modules, function (module, next) {
+ async.each(modules, function (module, next) {
fs.readFile(path.join(__dirname, '../../node_modules/', module, 'package.json'), {
- encoding: 'utf-8'
+ encoding: 'utf-8',
}, 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.');
- return next(true);
+ if (err) {
+ // If a bundled plugin/theme is not present, skip the dep check (#3384)
+ if (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.');
+ return next();
+ }
+ return next(err);
}
try {
pkgData = JSON.parse(pkgData);
- } catch(e) {
+ } catch (e) {
process.stdout.write('[' + 'missing'.red + '] ' + module.bold + ' is a required dependency but could not be found\n');
depsMissing = true;
- return next(true);
+ return next();
}
var ok = !semver.validRange(pkg.dependencies[module]) || semver.satisfies(pkgData.version, pkg.dependencies[module]);
@@@ -47,14 -44,10 +47,14 @@@
} else {
process.stdout.write('[' + 'outdated'.yellow + '] ' + module.bold + ' installed v' + pkgData.version + ', package.json requires ' + pkg.dependencies[module] + '\n');
depsOutdated = true;
- next(true);
+ next();
}
});
- }, function () {
+ }, function (err) {
+ if (err) {
+ return callback(err);
+ }
-
++
if (depsMissing) {
callback(new Error('dependencies-missing'));
} else if (depsOutdated) {
diff --cc src/meta/js.js
index 9af088c2cd,679236d9c8..b82aa34d25
--- a/src/meta/js.js
+++ b/src/meta/js.js
@@@ -79,7 -79,6 +78,7 @@@ module.exports = function (Meta)
'public/src/modules/helpers.js',
'public/src/modules/sounds.js',
'public/src/modules/string.js',
- 'public/src/modules/flags.js'
++ 'public/src/modules/flags.js',
],
// modules listed below are built (/src/modules) so they can be defined anonymously
diff --cc src/notifications.js
index 0fb1e1ace3,31960dc2f1..752915d636
--- a/src/notifications.js
+++ b/src/notifications.js
@@@ -411,14 -407,17 +407,18 @@@ var utils = require('../public/src/util
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',
- 'notifications:user_started_following_you',
- 'notifications:user_posted_to',
- 'notifications:user_flagged_post_in',
- 'notifications:user_flagged_user',
- 'new_register'
- ],
- isolated, differentiators, differentiator, modifyIndex, set;
+ 'notifications:upvoted_your_post_in',
+ 'notifications:user_started_following_you',
+ 'notifications:user_posted_to',
+ 'notifications:user_flagged_post_in',
++ 'notifications:user_flagged_user',
+ 'new_register',
+ ];
+ var isolated;
+ var differentiators;
+ var differentiator;
+ var modifyIndex;
+ var set;
notifications = mergeIds.reduce(function (notifications, mergeId) {
isolated = notifications.filter(function (notifObj) {
@@@ -457,36 -456,35 +457,36 @@@
return notifications;
}
- switch(mergeId) {
- // intentional fall-through
- case 'notifications:upvoted_your_post_in':
- case 'notifications:user_started_following_you':
- case 'notifications:user_posted_to':
- case 'notifications:user_flagged_post_in':
- case 'notifications:user_flagged_user':
- var usernames = set.map(function (notifObj) {
- return notifObj && notifObj.user && notifObj.user.username;
- }).filter(function (username, idx, array) {
- return array.indexOf(username) === idx;
- });
- var numUsers = usernames.length;
-
- var title = S(notifications[modifyIndex].topicTitle || '').decodeHTMLEntities().s;
- var titleEscaped = title.replace(/%/g, '%').replace(/,/g, ',');
- titleEscaped = titleEscaped ? (', ' + titleEscaped) : '';
-
- if (numUsers === 2) {
- notifications[modifyIndex].bodyShort = '[[' + mergeId + '_dual, ' + usernames.join(', ') + titleEscaped + ']]';
- } else if (numUsers > 2) {
- notifications[modifyIndex].bodyShort = '[[' + mergeId + '_multiple, ' + usernames[0] + ', ' + (numUsers - 1) + titleEscaped + ']]';
- }
+ switch (mergeId) {
- // intentional fall-through
++ // intentional fall-through
+ case 'notifications:upvoted_your_post_in':
+ case 'notifications:user_started_following_you':
+ case 'notifications:user_posted_to':
+ case 'notifications:user_flagged_post_in':
++ case 'notifications:user_flagged_user':
+ var usernames = set.map(function (notifObj) {
+ return notifObj && notifObj.user && notifObj.user.username;
+ }).filter(function (username, idx, array) {
+ return array.indexOf(username) === idx;
+ });
+ var numUsers = usernames.length;
- notifications[modifyIndex].path = set[set.length - 1].path;
- break;
+ var title = S(notifications[modifyIndex].topicTitle || '').decodeHTMLEntities().s;
+ var titleEscaped = title.replace(/%/g, '%').replace(/,/g, ',');
+ titleEscaped = titleEscaped ? (', ' + titleEscaped) : '';
- case 'new_register':
- notifications[modifyIndex].bodyShort = '[[notifications:' + mergeId + '_multiple, ' + set.length + ']]';
- break;
+ if (numUsers === 2) {
+ notifications[modifyIndex].bodyShort = '[[' + mergeId + '_dual, ' + usernames.join(', ') + titleEscaped + ']]';
+ } else if (numUsers > 2) {
+ notifications[modifyIndex].bodyShort = '[[' + mergeId + '_multiple, ' + usernames[0] + ', ' + (numUsers - 1) + titleEscaped + ']]';
+ }
+
+ notifications[modifyIndex].path = set[set.length - 1].path;
+ break;
+
+ case 'new_register':
+ notifications[modifyIndex].bodyShort = '[[notifications:' + mergeId + '_multiple, ' + set.length + ']]';
+ break;
}
// Filter out duplicates
diff --cc src/plugins/hooks.js
index a6a014e776,208eaae1b8..f8f5f6bc44
--- a/src/plugins/hooks.js
+++ b/src/plugins/hooks.js
@@@ -8,9 -8,6 +8,9 @@@ module.exports = function (Plugins)
'filter:user.custom_fields': null, // remove in v1.1.0
'filter:post.save': 'filter:post.create',
'filter:user.profileLinks': 'filter:user.profileMenu',
+ 'action:post.flag': 'action:flag.create',
+ 'action:plugin.activate': null,
- 'action:plugin.install': null
++ 'action:plugin.install': null,
};
/*
`data` is an object consisting of (* is required):
diff --cc src/plugins/install.js
index bc93a2eb6c,1e0fe0838c..beb38bf3d9
--- a/src/plugins/install.js
+++ b/src/plugins/install.js
@@@ -50,12 -49,9 +49,12 @@@ module.exports = function (Plugins)
},
function (next) {
meta.reloadRequired = true;
- Plugins.fireHook(isActive ? 'action:plugin.deactivate' : 'action:plugin.activate', id);
- next();
+ if (isActive) {
- Plugins.fireHook('action:plugin.deactivate', {id: id});
++ Plugins.fireHook('action:plugin.deactivate', { id: id });
+ }
+
+ setImmediate(next);
- }
+ },
], function (err) {
if (err) {
winston.warn('[plugins] Could not toggle active state on plugin \'' + id + '\'');
@@@ -96,12 -94,9 +95,12 @@@
Plugins.get(id, next);
},
function (pluginData, next) {
- Plugins.fireHook('action:plugin.' + type, id);
- next(null, pluginData);
+ if (installed) {
- Plugins.fireHook('action:plugin.uninstall', {id: id, version: version});
++ Plugins.fireHook('action:plugin.uninstall', { id: id, version: version });
+ }
+
+ setImmediate(next, null, pluginData);
- }
+ },
], callback);
}
diff --cc src/posts.js
index b8eb93fa1a,c7e7ec3e0a..10f65a5e29
--- a/src/posts.js
+++ b/src/posts.js
@@@ -153,10 -153,10 +152,10 @@@ var plugins = require('./plugins')
return callback(err);
}
var data = {
- pid: pid
+ pid: pid,
};
data[field] = value;
- plugins.fireHook('action:post.setFields', data);
+ plugins.fireHook('action:post.setFields', {data: data});
callback();
});
};
diff --cc src/posts/create.js
index 6cb925dc4c,e8e24a5585..7ea3ef0dbb
--- a/src/posts/create.js
+++ b/src/posts/create.js
@@@ -108,9 -106,9 +106,9 @@@ module.exports = function (Posts)
},
function (postData, next) {
postData.isMain = isMain;
- plugins.fireHook('action:post.save', _.clone(postData));
+ plugins.fireHook('action:post.save', {post: _.clone(postData)});
next(null, postData);
- }
+ },
], callback);
};
};
diff --cc src/posts/delete.js
index d54846c2fd,63f511481b..af281be698
--- a/src/posts/delete.js
+++ b/src/posts/delete.js
@@@ -8,10 -8,8 +8,9 @@@ var topics = require('../topics')
var user = require('../user');
var notifications = require('../notifications');
var plugins = require('../plugins');
+var flags = require('../flags');
module.exports = function (Posts) {
-
Posts.delete = function (pid, uid, callback) {
var postData;
async.waterfall([
@@@ -43,9 -40,9 +42,9 @@@
], next);
},
function (results, next) {
- plugins.fireHook('action:post.delete', {post: _.clone(postData), uid: uid});
- plugins.fireHook('action:post.delete', pid);
++ plugins.fireHook('action:post.delete', { post: _.clone(postData), uid: uid });
next(null, postData);
- }
+ },
], callback);
};
@@@ -80,9 -77,9 +79,9 @@@
], next);
},
function (results, next) {
- plugins.fireHook('action:post.restore', {post: _.clone(postData), uid: uid});
- plugins.fireHook('action:post.restore', _.clone(postData));
++ plugins.fireHook('action:post.restore', { post: _.clone(postData), uid: uid });
next(null, postData);
- }
+ },
], callback);
};
@@@ -145,18 -142,18 +144,18 @@@
},
function (next) {
db.sortedSetsRemove(['posts:pid', 'posts:flagged'], pid, next);
- }
+ },
- function (next) {
- Posts.dismissFlag(pid, next);
- },
], function (err) {
- if (err) {
- return next(err);
- }
- plugins.fireHook('action:post.purge', pid);
- db.delete('post:' + pid, next);
+ next(err);
});
},
+ function (next) {
+ Posts.getPostData(pid, next);
+ },
+ function (postData, next) {
- plugins.fireHook('action:post.purge', {post: postData, uid: uid});
++ plugins.fireHook('action:post.purge', { post: postData, uid: uid });
+ db.delete('post:' + pid, next);
- }
++ },
], callback);
};
diff --cc src/routes/helpers.js
index 0d27f5a3a7,8452b7f6d9..0aae67cbec
--- a/src/routes/helpers.js
+++ b/src/routes/helpers.js
@@@ -9,10 -9,4 +9,9 @@@ helpers.setupPageRoute = function (rout
router.get('/api' + name, middlewares, controller);
};
+helpers.setupAdminPageRoute = function (router, name, middleware, middlewares, controller) {
+ router.get(name, middleware.admin.buildHeader, middlewares, controller);
+ router.get('/api' + name, middlewares, controller);
+};
+
-
- module.exports = helpers;
+ module.exports = helpers;
diff --cc src/socket.io/admin.js
index 807abe25ef,0e7c277dfd..44a44f28e7
--- a/src/socket.io/admin.js
+++ b/src/socket.io/admin.js
@@@ -166,15 -166,14 +166,15 @@@ SocketAdmin.config.setMultiple = functi
if (data.hasOwnProperty(field)) {
setting = {
key: field,
- value: data[field]
+ value: data[field],
};
-
- logger.monitorConfig({io: index.server}, setting);
+ plugins.fireHook('action:config.set', setting);
+ logger.monitorConfig({ io: index.server }, setting);
}
}
- plugins.fireHook('action:config.set', {settings: data});
++ plugins.fireHook('action:config.set', { settings: data });
setImmediate(next);
- }
+ },
], callback);
};
diff --cc src/socket.io/index.js
index 0097a25950,253f5628e1..a52841e57c
--- a/src/socket.io/index.js
+++ b/src/socket.io/index.js
@@@ -152,7 -151,7 +151,7 @@@ function onMessage(socket, payload)
function requireModules() {
var modules = ['admin', 'categories', 'groups', 'meta', 'modules',
- 'notifications', 'plugins', 'posts', 'topics', 'user', 'blacklist', 'flags'
- 'notifications', 'plugins', 'posts', 'topics', 'user', 'blacklist',
++ 'notifications', 'plugins', 'posts', 'topics', 'user', 'blacklist', 'flags',
];
modules.forEach(function (module) {
diff --cc src/socket.io/user/picture.js
index 32be0869f8,109b2635e1..3723699461
--- a/src/socket.io/user/picture.js
+++ b/src/socket.io/user/picture.js
@@@ -97,12 -96,9 +96,12 @@@ module.exports = function (SocketUser)
user.setUserFields(data.uid, {
uploadedpicture: '',
- picture: userData.uploadedpicture === userData.picture ? '' : userData.picture // if current picture is uploaded picture, reset to user icon
+ picture: userData.uploadedpicture === userData.picture ? '' : userData.picture, // if current picture is uploaded picture, reset to user icon
}, next);
},
+ function (next) {
- plugins.fireHook('action:user.removeUploadedPicture', {callerUid: socket.uid, uid: data.uid}, next);
- }
++ plugins.fireHook('action:user.removeUploadedPicture', { callerUid: socket.uid, uid: data.uid }, next);
++ },
], callback);
};
diff --cc src/topics/create.js
index 2026f006da,815d703d01..5cee9e3d7c
--- a/src/topics/create.js
+++ b/src/topics/create.js
@@@ -83,9 -81,9 +82,9 @@@ module.exports = function (Topics)
], next);
},
function (results, next) {
- plugins.fireHook('action:topic.save', topicData);
+ plugins.fireHook('action:topic.save', {topic: _.clone(topicData)});
next(null, topicData.tid);
- }
+ },
], callback);
};
@@@ -270,10 -268,10 +269,10 @@@
Topics.notifyFollowers(postData, uid);
analytics.increment(['posts', 'posts:byCid:' + cid]);
- plugins.fireHook('action:topic.reply', postData);
+ plugins.fireHook('action:topic.reply', {post: _.clone(postData)});
next(null, postData);
- }
+ },
], callback);
};
diff --cc src/topics/delete.js
index d7148f55c3,7fdd0bc1a7..ec9d7f3a42
--- a/src/topics/delete.js
+++ b/src/topics/delete.js
@@@ -136,19 -136,16 +136,19 @@@ module.exports = function (Topics)
},
function (next) {
reduceCounters(tid, next);
- }
+ },
- ], next);
+ ], function (err) {
+ next(err);
+ });
},
- ], function (err) {
- if (err) {
- return callback(err);
- }
- plugins.fireHook('action:topic.purge', tid);
- db.delete('topic:' + tid, callback);
- });
+ function (next) {
+ Topics.getTopicData(tid, next);
+ },
+ function (topicData, next) {
- plugins.fireHook('action:topic.purge', {topic: topicData, uid: uid});
++ plugins.fireHook('action:topic.purge', { topic: topicData, uid: uid });
+ db.delete('topic:' + tid, next);
- }
++ },
+ ], callback);
};
function deleteFromFollowersIgnorers(tid, callback) {
diff --cc src/topics/fork.js
index 403331f902,396ae3d63b..5edd9f55f4
--- a/src/topics/fork.js
+++ b/src/topics/fork.js
@@@ -9,8 -9,8 +9,7 @@@ var privileges = require('../privileges
var plugins = require('../plugins');
var meta = require('../meta');
-
module.exports = function (Topics) {
-
Topics.createTopicFromPosts = function (uid, title, pids, fromTid, callback) {
if (title) {
title = title.trim();
@@@ -51,16 -51,13 +50,14 @@@
if (!results.isAdminOrMod) {
return next(new Error('[[error:no-privileges]]'));
}
- Topics.create({uid: results.postData.uid, title: title, cid: cid}, next);
+ Topics.create({ uid: results.postData.uid, title: title, cid: cid }, next);
},
- function (_tid, next) {
- Topics.updateTopicBookmarks(fromTid, pids, function (err) {
- next(err, _tid);
- });
+ function (results, next) {
+ Topics.updateTopicBookmarks(fromTid, pids, function () { next(null, results); });
},
function (_tid, next) {
- function move(pid, next) {
+ tid = _tid;
+ async.eachSeries(pids, function (pid, next) {
privileges.posts.canEdit(pid, uid, function (err, canEdit) {
if (err || !canEdit.flag) {
return next(err || new Error(canEdit.message));
@@@ -74,9 -73,8 +71,9 @@@
Topics.updateTimestamp(tid, Date.now(), next);
},
function (next) {
- plugins.fireHook('action:topic.fork', {tid: tid, fromTid: fromTid, uid: uid});
++ plugins.fireHook('action:topic.fork', { tid: tid, fromTid: fromTid, uid: uid });
Topics.getTopicData(tid, next);
- }
+ },
], callback);
};
diff --cc src/topics/tools.js
index 295e2a028b,f83a5f91f0..d44f259ba7
--- a/src/topics/tools.js
+++ b/src/topics/tools.js
@@@ -56,9 -55,9 +55,9 @@@ module.exports = function (Topics)
topicData.deleted = isDelete ? 1 : 0;
if (isDelete) {
- plugins.fireHook('action:topic.delete', {topic: topicData, uid: uid});
- plugins.fireHook('action:topic.delete', topicData);
++ plugins.fireHook('action:topic.delete', { topic: topicData, uid: uid });
} else {
- plugins.fireHook('action:topic.restore', {topic: topicData, uid: uid});
- plugins.fireHook('action:topic.restore', topicData);
++ plugins.fireHook('action:topic.restore', { topic: topicData, uid: uid });
}
var data = {
@@@ -135,12 -134,17 +134,12 @@@
Topics.setTopicField(tid, 'locked', lock ? 1 : 0, next);
},
function (next) {
- var data = {
- tid: tid,
- isLocked: lock,
- uid: uid,
- cid: cid,
- };
+ topicData.isLocked = lock;
- plugins.fireHook('action:topic.lock', {topic: _.clone(topicData), uid: uid});
- plugins.fireHook('action:topic.lock', data);
++ plugins.fireHook('action:topic.lock', { topic: _.clone(topicData), uid: uid });
- next(null, data);
+ next(null, topicData);
- }
+ },
], callback);
}
@@@ -193,13 -197,17 +192,12 @@@
], next);
},
function (results, next) {
-
- var data = {
- tid: tid,
- isPinned: pin,
- uid: uid,
- cid: topicData.cid,
- };
+ topicData.isPinned = pin;
- plugins.fireHook('action:topic.pin', {topic: _.clone(topicData), uid: uid});
- plugins.fireHook('action:topic.pin', data);
++ plugins.fireHook('action:topic.pin', { topic: _.clone(topicData), uid: uid });
- next(null, data);
+ next(null, topicData);
- }
+ },
], callback);
}
diff --cc src/topics/unread.js
index a754fa0f99,cc3101ee05..3e8fb55da9
--- a/src/topics/unread.js
+++ b/src/topics/unread.js
@@@ -18,17 -17,17 +17,17 @@@ module.exports = function (Topics)
callback = filter;
filter = '';
}
- Topics.getUnreadTids({cid: 0, uid: uid, filter: filter}, function (err, tids) {
- Topics.getUnreadTids(0, uid, filter, function (err, tids) {
++ Topics.getUnreadTids({ cid: 0, uid: uid, filter: filter }, function (err, tids) {
callback(err, Array.isArray(tids) ? tids.length : 0);
});
};
- Topics.getUnreadTopics = function (cid, uid, start, stop, filter, callback) {
+ Topics.getUnreadTopics = function (params, callback) {
var unreadTopics = {
showSelect: true,
- nextStart : 0,
- topics: []
+ nextStart: 0,
+ topics: [],
};
async.waterfall([
@@@ -56,18 -55,19 +55,19 @@@
}
unreadTopics.topics = topicData;
- unreadTopics.nextStart = stop + 1;
+ unreadTopics.nextStart = params.stop + 1;
next(null, unreadTopics);
- }
+ },
], callback);
};
Topics.unreadCutoff = function () {
- return Date.now() - (parseInt(meta.config.unreadCutoff, 10) || 2) * 86400000;
+ var cutoff = parseInt(meta.config.unreadCutoff, 10) || 2;
+ return Date.now() - (cutoff * 86400000);
};
- Topics.getUnreadTids = function (cid, uid, filter, callback) {
- uid = parseInt(uid, 10);
+ Topics.getUnreadTids = function (params, callback) {
+ var uid = parseInt(params.uid, 10);
if (uid === 0) {
return callback(null, []);
}
@@@ -118,11 -120,11 +118,11 @@@
if (results.ignoredTids.indexOf(recentTopic.value.toString()) !== -1) {
return false;
}
- switch (filter) {
+ switch (params.filter) {
- case 'new':
- return !userRead[recentTopic.value];
- default:
- return !userRead[recentTopic.value] || recentTopic.score > userRead[recentTopic.value];
+ case 'new':
+ return !userRead[recentTopic.value];
+ default:
+ return !userRead[recentTopic.value] || recentTopic.score > userRead[recentTopic.value];
}
}).map(function (topic) {
return topic.value;
@@@ -137,11 -139,10 +137,10 @@@
}
},
function (tids, next) {
-
tids = tids.slice(0, 200);
- filterTopics(uid, tids, cid, ignoredCids, filter, next);
+ filterTopics(uid, tids, params.cid, ignoredCids, params.filter, next);
- }
+ },
], callback);
};
diff --cc src/user/admin.js
index 4f7ecf66fb,7ef6c0dda7..cf3a2004db
--- a/src/user/admin.js
+++ b/src/user/admin.js
@@@ -6,10 -6,8 +6,9 @@@ var db = require('../database')
var posts = require('../posts');
var plugins = require('../plugins');
var winston = require('winston');
+var flags = require('../flags');
module.exports = function (User) {
-
User.logIP = function (uid, ip) {
var now = Date.now();
db.sortedSetAdd('uid:' + uid + ':ip', now, ip || 'Unknown');
@@@ -53,7 -51,17 +52,7 @@@
});
next(null, csvContent);
- }
+ },
], callback);
};
-
- User.resetFlags = function (uids, callback) {
- if (!Array.isArray(uids) || !uids.length) {
- return callback();
- }
-
- async.eachSeries(uids, function (uid, next) {
- posts.dismissUserFlags(uid, next);
- }, callback);
- };
};
diff --cc src/user/create.js
index c6cd92460a,2620cb67d3..40ba2d5540
--- a/src/user/create.js
+++ b/src/user/create.js
@@@ -141,9 -140,9 +140,9 @@@ module.exports = function (User)
if (userNameChanged) {
User.notifications.sendNameChangeNotification(userData.uid, userData.username);
}
- plugins.fireHook('action:user.create', userData);
+ plugins.fireHook('action:user.create', {user: userData});
next(null, userData.uid);
- }
+ },
], callback);
});
});
diff --cc src/user/profile.js
index c25dd3bf83,b0d40cf02d..84c142f35b
--- a/src/user/profile.js
+++ b/src/user/profile.js
@@@ -16,12 -15,9 +15,12 @@@ module.exports = function (User)
var fields = ['username', 'email', 'fullname', 'website', 'location',
'groupTitle', 'birthday', 'signature', 'aboutme'];
+ var updateUid = data.uid;
+ var oldData;
+
async.waterfall([
function (next) {
- plugins.fireHook('filter:user.updateProfile', {uid: uid, data: data, fields: fields}, next);
+ plugins.fireHook('filter:user.updateProfile', { uid: uid, data: data, fields: fields }, next);
},
function (data, next) {
fields = data.fields;
@@@ -30,9 -26,9 +29,9 @@@
async.series([
async.apply(isAboutMeValid, data),
async.apply(isSignatureValid, data),
- async.apply(isEmailAvailable, data, uid),
- async.apply(isUsernameAvailable, data, uid),
+ async.apply(isEmailAvailable, data, updateUid),
+ async.apply(isUsernameAvailable, data, updateUid),
- async.apply(isGroupTitleValid, data)
+ async.apply(isGroupTitleValid, data),
], function (err) {
next(err);
});
@@@ -63,9 -55,9 +62,9 @@@
}, next);
},
function (next) {
- plugins.fireHook('action:user.updateProfile', {uid: uid, data: data, fields: fields, oldData: oldData});
- plugins.fireHook('action:user.updateProfile', { data: data, uid: uid });
- User.getUserFields(uid, ['email', 'username', 'userslug', 'picture', 'icon:text', 'icon:bgColor'], next);
++ plugins.fireHook('action:user.updateProfile', { uid: uid, data: data, fields: fields, oldData: oldData });
+ User.getUserFields(updateUid, ['email', 'username', 'userslug', 'picture', 'icon:text', 'icon:bgColor'], next);
- }
+ },
], callback);
};
diff --cc test/topics.js
index 42701a6d93,2573225511..3c6e7efe71
--- a/test/topics.js
+++ b/test/topics.js
@@@ -486,10 -499,10 +499,10 @@@ describe('Topic\'s', function ()
it('should not appear in the unread list', function (done) {
async.waterfall([
function (done) {
- topics.ignore( newTid, uid, done );
+ topics.ignore(newTid, uid, done);
},
function (done) {
- topics.getUnreadTopics({cid: 0, uid: uid, start: 0, stop: -1, filter: ''}, done );
- topics.getUnreadTopics(0, uid, 0, -1, '', done);
++ topics.getUnreadTopics({ cid: 0, uid: uid, start: 0, stop: -1, filter: '' }, done);
},
function (results, done) {
var topics = results.topics;
@@@ -527,13 -540,13 +540,13 @@@
it('should appear as unread again when marked as reading', function (done) {
async.waterfall([
function (done) {
- topics.ignore( newTid, uid, done );
+ topics.ignore(newTid, uid, done);
},
function (done) {
- topics.follow( newTid, uid, done );
+ topics.follow(newTid, uid, done);
},
function (done) {
- topics.getUnreadTopics({cid: 0, uid: uid, start: 0, stop: -1, filter: ''}, done );
- topics.getUnreadTopics(0, uid, 0, -1, '', done);
++ topics.getUnreadTopics({ cid: 0, uid: uid, start: 0, stop: -1, filter: '' }, done);
},
function (results, done) {
var topics = results.topics;
@@@ -547,13 -560,13 +560,13 @@@
it('should appear as unread again when marked as following', function (done) {
async.waterfall([
function (done) {
- topics.ignore( newTid, uid, done );
+ topics.ignore(newTid, uid, done);
},
function (done) {
- topics.follow( newTid, uid, done );
+ topics.follow(newTid, uid, done);
},
function (done) {
- topics.getUnreadTopics({cid: 0, uid: uid, start: 0, stop: -1, filter: ''}, done );
- topics.getUnreadTopics(0, uid, 0, -1, '', done);
++ topics.getUnreadTopics({ cid: 0, uid: uid, start: 0, stop: -1, filter: '' }, done);
},
function (results, done) {
var topics = results.topics;
diff --cc test/translator.js
index 17affe1700,196d5ce56f..6411d01992
--- a/test/translator.js
+++ b/test/translator.js
@@@ -119,20 -118,10 +119,20 @@@ describe('new Translator(language)', fu
it('should properly escape and ignore % and \\, in arguments', function () {
var translator = Translator.create('en-GB');
- var title = 'Test 1\\, 2\\, 3 % salmon';
+ var title = 'Test 1\\, 2\\, 3 %2 salmon';
- var key = "[[topic:composer.replying_to, " + title + "]]";
+ var key = '[[topic:composer.replying_to, ' + title + ']]';
return translator.translate(key).then(function (translated) {
- assert.strictEqual(translated, 'Replying to Test 1, 2, 3 % salmon');
+ assert.strictEqual(translated, 'Replying to Test 1, 2, 3 %2 salmon');
+ });
+ });
+
+ it('should not escape regular %', function () {
+ var translator = Translator.create('en-GB');
+
+ var title = '3 % salmon';
- var key = "[[topic:composer.replying_to, " + title + "]]";
++ var key = '[[topic:composer.replying_to, ' + title + ']]';
+ return translator.translate(key).then(function (translated) {
+ assert.strictEqual(translated, 'Replying to 3 % salmon');
});
});