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

v1.18.x
Julian Lam 11 years ago
parent 454c05c391
commit d257632878

@ -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);

@ -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

@ -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

@ -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

@ -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) {

@ -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

Loading…
Cancel
Save