diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js index 8553f55280..bf257c2e20 100644 --- a/public/src/modules/notifications.js +++ b/public/src/modules/notifications.js @@ -25,7 +25,7 @@ define('notifications', ['sounds'], function(sound) { image = ''; } - return '
  • ' + image + '' + utils.relativeTime(notification.datetime, true) + '' + notification.text + '
  • '; + return '
  • ' + image + '' + utils.relativeTime(notification.datetime, true) + '' + notification.bodyShort + '
  • '; } var x, html = ''; diff --git a/src/notifications.js b/src/notifications.js index 8942690cec..6fec98e3da 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -32,10 +32,18 @@ var async = require('async'), if (exists) { db.sortedSetRank('uid:' + uid + ':notifications:read', nid, function(err, rank) { - - db.getObjectFields('notifications:' + nid, ['nid', 'from', 'text', 'image', 'importance', 'score', 'path', 'datetime', 'uniqueId'], function(err, notification) { + db.getObject('notifications:' + nid, function(err, notification) { notification.read = rank !== null ? true:false; - notification.text = validator.escape(notification.text); + + // Backwards compatibility for old notification schema + if (notification.hasOwnProperty('text')) { + notification.bodyShort = notification.text; + notification.bodyLong = ''; + notification.text = validator.escape(notification.text); + } + + notification.bodyShort = validator.escape(notification.bodyShort); + notification.bodyLong = validator.escape(notification.bodyLong); if (notification.from && !notification.image) { User.getUserField(notification.from, 'picture', function(err, picture) { @@ -85,10 +93,8 @@ var async = require('async'), // Add default values to data Object if not already set var defaults = { - body: { - short: '', - long: '' - }, + bodyShort: '', + bodyLong: '', path: '', importance: 5, datetime: Date.now(), @@ -101,13 +107,11 @@ var async = require('async'), } } - // Backwards compatibility for old notification syntax + // Backwards compatibility for old notification schema // Remove this block for NodeBB v0.6.0 - if (data.hasOwnProperty('text') && !data.hasOwnProperty('body')) { - data.body = { - short: data.text, - long: '' - }; + if (data.hasOwnProperty('text')) { + data.bodyShort = data.text; + data.bodyLong = ''; delete data.text; } @@ -117,6 +121,8 @@ var async = require('async'), db.setObject('notifications:' + nid, data, function(err, status) { if (!err) { callback(nid); + } else { + winston.error('[notifications.create] ' + err.message); } }); }); diff --git a/src/routes/debug.js b/src/routes/debug.js index 1484f1483e..ccaa4209a6 100644 --- a/src/routes/debug.js +++ b/src/routes/debug.js @@ -54,10 +54,7 @@ module.exports = function(app, middleware, controllers) { }); app.get('/test', function(req, res) { - var a = require('../groups'); - a.getLatestMemberPosts('mcg', 5, function() { - res.json(arguments); - }); + res.redirect('404'); }); }); }; diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js index 3aac1aafdf..d2877a3d43 100644 --- a/src/socket.io/modules.js +++ b/src/socket.io/modules.js @@ -208,10 +208,8 @@ function sendChatNotification(fromuid, touid, username, message) { if (!module.parent.exports.isUserOnline(touid)) { var notifText = '[[notifications:new_message_from, ' + username + ']]'; notifications.create({ - body: { - short: notifText, - long: message - }, + bodyShort: notifText, + bodyLong: message, path: 'javascript:app.openChat('' + username + '', ' + fromuid + ');', uniqueId: 'notification_' + fromuid + '_' + touid, from: fromuid diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index df2285cc77..7c68e8429c 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -115,10 +115,8 @@ function sendNotificationToPostOwner(data, uid, notification) { } notifications.create({ - body: { - short: '[[' + notification + ', ' + results.username + ']]', - long: results.topicData.content - }, + bodyShort: '[[' + notification + ', ' + results.username + ']]', + bodyLong: results.topicData.content, path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.index, uniqueId: 'post:' + data.pid, from: uid @@ -309,10 +307,8 @@ SocketPosts.flag = function(socket, pid, callback) { }, function(adminGroup, next) { notifications.create({ - body: { - short: message, - long: post.content - }, + bodyShort: message, + bodyLong: post.content, path: path, uniqueId: 'post_flag:' + pid, from: socket.uid diff --git a/src/topics/follow.js b/src/topics/follow.js index c881febe52..ac08f3fd59 100644 --- a/src/topics/follow.js +++ b/src/topics/follow.js @@ -34,10 +34,8 @@ module.exports = function(Topics) { } notifications.create({ - body: { - short: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]', - long: results.postContent - }, + bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]', + bodyLong: results.postContent, path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.postIndex, uniqueId: 'topic:' + tid, from: exceptUid diff --git a/src/user/create.js b/src/user/create.js index 37fb7c2f66..48e47ee8ce 100644 --- a/src/user/create.js +++ b/src/user/create.js @@ -163,10 +163,8 @@ module.exports = function(User) { if (userNameChanged) { notifications.create({ - body: { - short: '[[user:username_taken_workaround, ' + userData.username + ']]', - long: '' - }, + bodyShort: '[[user:username_taken_workaround, ' + userData.username + ']]', + bodyLong: '', image: 'brand:logo', datetime: Date.now() }, function(nid) { diff --git a/src/user/notifications.js b/src/user/notifications.js index a3d42080cb..935ec26cd4 100644 --- a/src/user/notifications.js +++ b/src/user/notifications.js @@ -163,10 +163,8 @@ var async = require('async'), } notifications.create({ - body: { - short: '[[notifications:user_made_post, ' + results.username + ']]', - long: results.postContent - }, + bodyShort: '[[notifications:user_made_post, ' + results.username + ']]', + bodyLong: results.postContent, path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.postIndex, uniqueId: 'topic:' + tid, from: uid