Skip to content

Node.js based forum software built for the modern web

first pass #1720, updating existing calls to notifications.create, backwards compatibility in case plugins create notifications too.

Julian Lamd257632878d7
diff --git a/src/notifications.js b/src/notifications.js
index 3912d2cd22..8942690cec 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -85,18 +85,32 @@ var async = require('async'),
// Add default values to data Object if not already set
var defaults = {
- text: '',
+ body: {
+ short: '',
+ long: ''
+ },
path: '',
importance: 5,
datetime: Date.now(),
uniqueId: utils.generateUUID()
};
+
for(var v in defaults) {
if (defaults.hasOwnProperty(v) && !data[v]) {
data[v] = defaults[v];
}
}
+ // Backwards compatibility for old notification syntax
+ // Remove this block for NodeBB v0.6.0
+ if (data.hasOwnProperty('text') && !data.hasOwnProperty('body')) {
+ data.body = {
+ short: data.text,
+ long: ''
+ };
+ delete data.text;
+ }
+
db.incrObjectField('global', 'nextNid', function(err, nid) {
data.nid = nid;
db.setAdd('notifications', nid);
diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js
index 95083f85bf..3aac1aafdf 100644
--- a/src/socket.io/modules.js
+++ b/src/socket.io/modules.js
@@ -186,7 +186,7 @@ SocketModules.chats.send = function(socket, data, callback) {
return callback(err);
}
- sendChatNotification(socket.uid, touid, message.fromUser.username);
+ sendChatNotification(socket.uid, touid, message.fromUser.username, message);
server.getUserSockets(touid).forEach(function(s) {
s.emit('event:chats.receive', {
@@ -204,11 +204,14 @@ SocketModules.chats.send = function(socket, data, callback) {
});
};
-function sendChatNotification(fromuid, touid, username) {
+function sendChatNotification(fromuid, touid, username, message) {
if (!module.parent.exports.isUserOnline(touid)) {
var notifText = '[[notifications:new_message_from, ' + username + ']]';
notifications.create({
- text: notifText,
+ body: {
+ short: notifText,
+ long: 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 5ec2a6737f..df2285cc77 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -103,8 +103,8 @@ function sendNotificationToPostOwner(data, uid, notification) {
username: function(next) {
user.getUserField(uid, 'username', next);
},
- slug: function(next) {
- topics.getTopicField(postData.tid, 'slug', next);
+ topicData: function(next) {
+ topics.getTopicFields(postData.tid, ['slug', 'content'], next);
},
index: function(next) {
posts.getPidIndex(data.pid, next);
@@ -115,8 +115,11 @@ function sendNotificationToPostOwner(data, uid, notification) {
}
notifications.create({
- text: '[[' + notification + ', ' + results.username + ']]',
- path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.index,
+ body: {
+ short: '[[' + notification + ', ' + results.username + ']]',
+ long: results.topicData.content
+ },
+ path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.index,
uniqueId: 'post:' + data.pid,
from: uid
}, function(nid) {
@@ -290,7 +293,7 @@ SocketPosts.flag = function(socket, pid, callback) {
},
function(username, next) {
message = '[[notifications:user_flagged_post, ' + username + ']]';
- posts.getPostFields(pid, ['tid', 'uid'], next);
+ posts.getPostFields(pid, ['tid', 'uid', 'content'], next);
},
function(postData, next) {
post = postData;
@@ -306,7 +309,10 @@ SocketPosts.flag = function(socket, pid, callback) {
},
function(adminGroup, next) {
notifications.create({
- text: message,
+ body: {
+ short: message,
+ long: post.content
+ },
path: path,
uniqueId: 'post_flag:' + pid,
from: socket.uid
diff --git a/src/topics/follow.js b/src/topics/follow.js
index 731963c623..c881febe52 100644
--- a/src/topics/follow.js
+++ b/src/topics/follow.js
@@ -24,22 +24,20 @@ module.exports = function(Topics) {
async.parallel({
nid: function(next) {
async.parallel({
- topicData: function(next) {
- Topics.getTopicFields(tid, ['title', 'slug'], next);
- },
- username: function(next) {
- user.getUserField(exceptUid, 'username', next);
- },
- postIndex: function(next) {
- posts.getPidIndex(pid, next);
- }
+ topicData: async.apply(Topics.getTopicFields, tid, ['title', 'slug']),
+ username: async.apply(user.getUserField, exceptUid, 'username'),
+ postIndex: async.apply(posts.getPidIndex, pid),
+ postContent: async.apply(posts.getPostField, pid, 'content')
}, function(err, results) {
if (err) {
return next(err);
}
notifications.create({
- text: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]',
+ body: {
+ short: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]',
+ long: 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 a7900c7484..37fb7c2f66 100644
--- a/src/user/create.js
+++ b/src/user/create.js
@@ -163,7 +163,10 @@ module.exports = function(User) {
if (userNameChanged) {
notifications.create({
- text: '[[user:username_taken_workaround, ' + userData.username + ']]',
+ body: {
+ short: '[[user:username_taken_workaround, ' + userData.username + ']]',
+ long: ''
+ },
image: 'brand:logo',
datetime: Date.now()
}, function(nid) {
diff --git a/src/user/notifications.js b/src/user/notifications.js
index 2a6830c55a..a3d42080cb 100644
--- a/src/user/notifications.js
+++ b/src/user/notifications.js
@@ -153,22 +153,20 @@ var async = require('async'),
}
async.parallel({
- username: function(next) {
- user.getUserField(uid, 'username', next);
- },
- slug: function(next) {
- topics.getTopicField(tid, 'slug', next);
- },
- postIndex: function(next) {
- posts.getPidIndex(pid, next);
- }
+ username: async.apply(user.getUserField, uid, 'username'),
+ slug: async.apply(topics.getTopicField, tid, 'slug'),
+ postIndex: async.apply(posts.getPidIndex, pid),
+ postContent: async.apply(posts.getPostField, pid, 'content')
}, function(err, results) {
if (err) {
return;
}
notifications.create({
- text: '[[notifications:user_made_post, ' + results.username + ']]',
+ body: {
+ short: '[[notifications:user_made_post, ' + results.username + ']]',
+ long: results.postContent
+ },
path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.postIndex,
uniqueId: 'topic:' + tid,
from: uid