mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
first pass #1720, updating existing calls to notifications.create, backwards compatibility in case plugins create notifications too.
This commit is contained in:
@@ -85,18 +85,32 @@ var async = require('async'),
|
|||||||
|
|
||||||
// Add default values to data Object if not already set
|
// Add default values to data Object if not already set
|
||||||
var defaults = {
|
var defaults = {
|
||||||
text: '',
|
body: {
|
||||||
|
short: '',
|
||||||
|
long: ''
|
||||||
|
},
|
||||||
path: '',
|
path: '',
|
||||||
importance: 5,
|
importance: 5,
|
||||||
datetime: Date.now(),
|
datetime: Date.now(),
|
||||||
uniqueId: utils.generateUUID()
|
uniqueId: utils.generateUUID()
|
||||||
};
|
};
|
||||||
|
|
||||||
for(var v in defaults) {
|
for(var v in defaults) {
|
||||||
if (defaults.hasOwnProperty(v) && !data[v]) {
|
if (defaults.hasOwnProperty(v) && !data[v]) {
|
||||||
data[v] = defaults[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) {
|
db.incrObjectField('global', 'nextNid', function(err, nid) {
|
||||||
data.nid = nid;
|
data.nid = nid;
|
||||||
db.setAdd('notifications', nid);
|
db.setAdd('notifications', nid);
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ SocketModules.chats.send = function(socket, data, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendChatNotification(socket.uid, touid, message.fromUser.username);
|
sendChatNotification(socket.uid, touid, message.fromUser.username, message);
|
||||||
|
|
||||||
server.getUserSockets(touid).forEach(function(s) {
|
server.getUserSockets(touid).forEach(function(s) {
|
||||||
s.emit('event:chats.receive', {
|
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)) {
|
if (!module.parent.exports.isUserOnline(touid)) {
|
||||||
var notifText = '[[notifications:new_message_from, ' + username + ']]';
|
var notifText = '[[notifications:new_message_from, ' + username + ']]';
|
||||||
notifications.create({
|
notifications.create({
|
||||||
text: notifText,
|
body: {
|
||||||
|
short: notifText,
|
||||||
|
long: message
|
||||||
|
},
|
||||||
path: 'javascript:app.openChat('' + username + '', ' + fromuid + ');',
|
path: 'javascript:app.openChat('' + username + '', ' + fromuid + ');',
|
||||||
uniqueId: 'notification_' + fromuid + '_' + touid,
|
uniqueId: 'notification_' + fromuid + '_' + touid,
|
||||||
from: fromuid
|
from: fromuid
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ function sendNotificationToPostOwner(data, uid, notification) {
|
|||||||
username: function(next) {
|
username: function(next) {
|
||||||
user.getUserField(uid, 'username', next);
|
user.getUserField(uid, 'username', next);
|
||||||
},
|
},
|
||||||
slug: function(next) {
|
topicData: function(next) {
|
||||||
topics.getTopicField(postData.tid, 'slug', next);
|
topics.getTopicFields(postData.tid, ['slug', 'content'], next);
|
||||||
},
|
},
|
||||||
index: function(next) {
|
index: function(next) {
|
||||||
posts.getPidIndex(data.pid, next);
|
posts.getPidIndex(data.pid, next);
|
||||||
@@ -115,8 +115,11 @@ function sendNotificationToPostOwner(data, uid, notification) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
notifications.create({
|
notifications.create({
|
||||||
text: '[[' + notification + ', ' + results.username + ']]',
|
body: {
|
||||||
path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.index,
|
short: '[[' + notification + ', ' + results.username + ']]',
|
||||||
|
long: results.topicData.content
|
||||||
|
},
|
||||||
|
path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.index,
|
||||||
uniqueId: 'post:' + data.pid,
|
uniqueId: 'post:' + data.pid,
|
||||||
from: uid
|
from: uid
|
||||||
}, function(nid) {
|
}, function(nid) {
|
||||||
@@ -290,7 +293,7 @@ SocketPosts.flag = function(socket, pid, callback) {
|
|||||||
},
|
},
|
||||||
function(username, next) {
|
function(username, next) {
|
||||||
message = '[[notifications:user_flagged_post, ' + username + ']]';
|
message = '[[notifications:user_flagged_post, ' + username + ']]';
|
||||||
posts.getPostFields(pid, ['tid', 'uid'], next);
|
posts.getPostFields(pid, ['tid', 'uid', 'content'], next);
|
||||||
},
|
},
|
||||||
function(postData, next) {
|
function(postData, next) {
|
||||||
post = postData;
|
post = postData;
|
||||||
@@ -306,7 +309,10 @@ SocketPosts.flag = function(socket, pid, callback) {
|
|||||||
},
|
},
|
||||||
function(adminGroup, next) {
|
function(adminGroup, next) {
|
||||||
notifications.create({
|
notifications.create({
|
||||||
text: message,
|
body: {
|
||||||
|
short: message,
|
||||||
|
long: post.content
|
||||||
|
},
|
||||||
path: path,
|
path: path,
|
||||||
uniqueId: 'post_flag:' + pid,
|
uniqueId: 'post_flag:' + pid,
|
||||||
from: socket.uid
|
from: socket.uid
|
||||||
|
|||||||
@@ -24,22 +24,20 @@ module.exports = function(Topics) {
|
|||||||
async.parallel({
|
async.parallel({
|
||||||
nid: function(next) {
|
nid: function(next) {
|
||||||
async.parallel({
|
async.parallel({
|
||||||
topicData: function(next) {
|
topicData: async.apply(Topics.getTopicFields, tid, ['title', 'slug']),
|
||||||
Topics.getTopicFields(tid, ['title', 'slug'], next);
|
username: async.apply(user.getUserField, exceptUid, 'username'),
|
||||||
},
|
postIndex: async.apply(posts.getPidIndex, pid),
|
||||||
username: function(next) {
|
postContent: async.apply(posts.getPostField, pid, 'content')
|
||||||
user.getUserField(exceptUid, 'username', next);
|
|
||||||
},
|
|
||||||
postIndex: function(next) {
|
|
||||||
posts.getPidIndex(pid, next);
|
|
||||||
}
|
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifications.create({
|
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,
|
path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.postIndex,
|
||||||
uniqueId: 'topic:' + tid,
|
uniqueId: 'topic:' + tid,
|
||||||
from: exceptUid
|
from: exceptUid
|
||||||
|
|||||||
@@ -163,7 +163,10 @@ module.exports = function(User) {
|
|||||||
|
|
||||||
if (userNameChanged) {
|
if (userNameChanged) {
|
||||||
notifications.create({
|
notifications.create({
|
||||||
text: '[[user:username_taken_workaround, ' + userData.username + ']]',
|
body: {
|
||||||
|
short: '[[user:username_taken_workaround, ' + userData.username + ']]',
|
||||||
|
long: ''
|
||||||
|
},
|
||||||
image: 'brand:logo',
|
image: 'brand:logo',
|
||||||
datetime: Date.now()
|
datetime: Date.now()
|
||||||
}, function(nid) {
|
}, function(nid) {
|
||||||
|
|||||||
@@ -153,22 +153,20 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
username: function(next) {
|
username: async.apply(user.getUserField, uid, 'username'),
|
||||||
user.getUserField(uid, 'username', next);
|
slug: async.apply(topics.getTopicField, tid, 'slug'),
|
||||||
},
|
postIndex: async.apply(posts.getPidIndex, pid),
|
||||||
slug: function(next) {
|
postContent: async.apply(posts.getPostField, pid, 'content')
|
||||||
topics.getTopicField(tid, 'slug', next);
|
|
||||||
},
|
|
||||||
postIndex: function(next) {
|
|
||||||
posts.getPidIndex(pid, next);
|
|
||||||
}
|
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
notifications.create({
|
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,
|
path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.postIndex,
|
||||||
uniqueId: 'topic:' + tid,
|
uniqueId: 'topic:' + tid,
|
||||||
from: uid
|
from: uid
|
||||||
|
|||||||
Reference in New Issue
Block a user