notifications.create can return null

v1.18.x
barisusakli 9 years ago
parent 19c7411c38
commit add4e6ee5b

@ -74,26 +74,30 @@ module.exports = function(Groups) {
Groups.requestMembership = function(groupName, uid, callback) { Groups.requestMembership = function(groupName, uid, callback) {
async.waterfall([ async.waterfall([
async.apply(inviteOrRequestMembership, groupName, uid, 'request'), async.apply(inviteOrRequestMembership, groupName, uid, 'request'),
function(next) { function (next) {
user.getUserField(uid, 'username', function(err, username) { user.getUserField(uid, 'username', next);
if (err) {
return next(err);
}
next(null, {
bodyShort: '[[groups:request.notification_title, ' + username + ']]',
bodyLong: '[[groups:request.notification_text, ' + username + ', ' + groupName + ']]',
nid: 'group:' + groupName + ':uid:' + uid + ':request',
path: '/groups/' + utils.slugify(groupName)
});
});
}, },
async.apply(notifications.create), function (username, next) {
function(notification, next) { async.parallel({
Groups.getOwners(groupName, function(err, ownerUids) { notification: function(next) {
next(null, notification, ownerUids); notifications.create({
}); bodyShort: '[[groups:request.notification_title, ' + username + ']]',
bodyLong: '[[groups:request.notification_text, ' + username + ', ' + groupName + ']]',
nid: 'group:' + groupName + ':uid:' + uid + ':request',
path: '/groups/' + utils.slugify(groupName)
}, next);
},
owners: function(next) {
Groups.getOwners(groupName, next);
}
}, next);
}, },
async.apply(notifications.push) function (results, next) {
if (!results.notification || !results.owners.length) {
return next();
}
notifications.push(results.notification, results.owners, next);
}
], callback); ], callback);
}; };
@ -123,10 +127,13 @@ module.exports = function(Groups) {
nid: 'group:' + groupName + ':uid:' + uid + ':invite', nid: 'group:' + groupName + ':uid:' + uid + ':invite',
path: '/groups/' + utils.slugify(groupName) path: '/groups/' + utils.slugify(groupName)
}), }),
function(notification, next) { function (notification, next) {
next(null, notification, [uid]); if (!notification) {
}, return next();
async.apply(notifications.push) }
notifications.push(notification, [uid]);
}
], callback); ], callback);
}; };

@ -90,7 +90,7 @@ var async = require('async'),
if (oldNotification) { if (oldNotification) {
if (parseInt(oldNotification.pid, 10) === parseInt(data.pid, 10) && parseInt(oldNotification.importance, 10) > parseInt(data.importance, 10)) { if (parseInt(oldNotification.pid, 10) === parseInt(data.pid, 10) && parseInt(oldNotification.importance, 10) > parseInt(data.importance, 10)) {
return callback(); return callback(null, null);
} }
} }

@ -137,13 +137,13 @@ SocketUser.follow = function(socket, data, callback) {
} }
var userData; var userData;
async.waterfall([ async.waterfall([
function(next) { function (next) {
toggleFollow('follow', socket.uid, data.uid, next); toggleFollow('follow', socket.uid, data.uid, next);
}, },
function(next) { function (next) {
user.getUserFields(socket.uid, ['username', 'userslug'], next); user.getUserFields(socket.uid, ['username', 'userslug'], next);
}, },
function(_userData, next) { function (_userData, next) {
userData = _userData; userData = _userData;
notifications.create({ notifications.create({
bodyShort: '[[notifications:user_started_following_you, ' + userData.username + ']]', bodyShort: '[[notifications:user_started_following_you, ' + userData.username + ']]',
@ -153,7 +153,10 @@ SocketUser.follow = function(socket, data, callback) {
mergeId: 'notifications:user_started_following_you' mergeId: 'notifications:user_started_following_you'
}, next); }, next);
}, },
function(notification, next) { function (notification, next) {
if (!notification) {
return next();
}
notification.user = userData; notification.user = userData;
notifications.push(notification, [data.uid], next); notifications.push(notification, [data.uid], next);
} }

@ -139,18 +139,12 @@ module.exports = function(Topics) {
from: exceptUid, from: exceptUid,
mergeId: 'notifications:user_posted_to|' + postData.topic.tid, mergeId: 'notifications:user_posted_to|' + postData.topic.tid,
topicTitle: title topicTitle: title
}, function(err, notification) { }, next);
if (err) {
return next(err);
}
if (notification) {
notifications.push(notification, followers);
}
next();
});
}, },
function (next) { function (notification, next) {
if (notification) {
notifications.push(notification, followers);
}
if (parseInt(meta.config.disableEmailSubscriptions, 10) === 1) { if (parseInt(meta.config.disableEmailSubscriptions, 10) === 1) {
return next(); return next();

@ -50,14 +50,11 @@ module.exports = function(User) {
nid: 'new_register:' + username, nid: 'new_register:' + username,
path: '/admin/manage/registration' path: '/admin/manage/registration'
}, function(err, notification) { }, function(err, notification) {
if (err) { if (err || !notification) {
return callback(err); return callback(err);
} }
if (notification) {
notifications.pushGroup(notification, 'administrators', callback); notifications.pushGroup(notification, 'administrators', callback);
} else {
callback();
}
}); });
} }

@ -295,14 +295,11 @@ var async = require('async'),
path: path, path: path,
nid: 'welcome_' + uid nid: 'welcome_' + uid
}, function(err, notification) { }, function(err, notification) {
if (err) { if (err || !notification) {
return callback(err); return callback(err);
} }
if (notification) {
notifications.push(notification, [uid], callback); notifications.push(notification, [uid], callback);
} else {
callback();
}
}); });
}; };

Loading…
Cancel
Save