generate paths on retrieval instead of notification creation
also fix follow notification path
v1.18.x
barisusakli 10 years ago
parent 82543bdeee
commit 756d03fa62

@ -320,33 +320,34 @@ var db = require('./database'),
};
function sendNotifications(fromuid, touid, messageObj, callback) {
if (!websockets.isUserOnline(touid)) {
notifications.create({
bodyShort: '[[notifications:new_message_from, ' + messageObj.fromUser.username + ']]',
bodyLong: messageObj.content,
path: nconf.get('relative_path') + '/chats/' + utils.slugify(messageObj.fromUser.username),
nid: 'chat_' + fromuid + '_' + touid,
from: fromuid
}, function(err, notification) {
if (!err && notification) {
notifications.push(notification, [touid], callback);
}
});
user.getSettings(messageObj.toUser.uid, function(err, settings) {
if (settings.sendChatNotifications && !parseInt(meta.config.disableEmailSubscriptions, 10)) {
emailer.send('notif_chat', touid, {
subject: '[[email:notif.chat.subject, ' + messageObj.fromUser.username + ']]',
username: messageObj.toUser.username,
summary: '[[notifications:new_message_from, ' + messageObj.fromUser.username + ']]',
message: messageObj,
site_title: meta.config.title || 'NodeBB',
url: nconf.get('url'),
fromUserslug: utils.slugify(messageObj.fromUser.username)
});
}
});
if (websockets.isUserOnline(touid)) {
return callback();
}
notifications.create({
bodyShort: '[[notifications:new_message_from, ' + messageObj.fromUser.username + ']]',
bodyLong: messageObj.content,
nid: 'chat_' + fromuid + '_' + touid,
from: fromuid
}, function(err, notification) {
if (!err && notification) {
notifications.push(notification, [touid], callback);
}
});
user.getSettings(messageObj.toUser.uid, function(err, settings) {
if (settings.sendChatNotifications && !parseInt(meta.config.disableEmailSubscriptions, 10)) {
emailer.send('notif_chat', touid, {
subject: '[[email:notif.chat.subject, ' + messageObj.fromUser.username + ']]',
username: messageObj.toUser.username,
summary: '[[notifications:new_message_from, ' + messageObj.fromUser.username + ']]',
message: messageObj,
site_title: meta.config.title || 'NodeBB',
url: nconf.get('url'),
fromUserslug: utils.slugify(messageObj.fromUser.username)
});
}
});
}
}(exports));

@ -55,11 +55,12 @@ var async = require('async'),
}
if (notification.from && !notification.image) {
User.getUserField(notification.from, 'picture', function(err, picture) {
User.getUserFields(notification.from, ['username', 'userslug', 'picture'], function(err, userData) {
if (err) {
return next(err);
}
notification.image = picture;
notification.image = userData.picture;
notification.user = userData;
next(null, notification);
});
return;

@ -294,7 +294,6 @@ SocketUser.follow = function(socket, data, callback) {
notifications.create({
bodyShort: '[[notifications:user_started_following_you, ' + userData.username + ']]',
path: nconf.get('relative_path') + '/user/' + userData.userslug,
nid: 'follow:' + data.uid + ':uid:' + socket.uid,
from: socket.uid
}, function(err, notification) {

@ -124,6 +124,13 @@ var async = require('async'),
}
notification.path = pidToPaths[notification.pid] || notification.path || '';
if (notification.nid.startsWith('chat')) {
notification.path = nconf.get('relative_path') + '/chats/' + notification.user.userslug;
} else if (notification.nid.startsWith('follow')) {
notification.path = nconf.get('relative_path') + '/user/' + notification.user.userslug;
}
notification.datetimeISO = utils.toISOString(notification.datetime);
return notification;
});

Loading…
Cancel
Save