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) {
async.waterfall([
async.apply(inviteOrRequestMembership, groupName, uid, 'request'),
function(next) {
user.getUserField(uid, 'username', function(err, username) {
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)
});
});
function (next) {
user.getUserField(uid, 'username', next);
},
async.apply(notifications.create),
function(notification, next) {
Groups.getOwners(groupName, function(err, ownerUids) {
next(null, notification, ownerUids);
});
function (username, next) {
async.parallel({
notification: function(next) {
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);
};
@ -123,10 +127,13 @@ module.exports = function(Groups) {
nid: 'group:' + groupName + ':uid:' + uid + ':invite',
path: '/groups/' + utils.slugify(groupName)
}),
function(notification, next) {
next(null, notification, [uid]);
},
async.apply(notifications.push)
function (notification, next) {
if (!notification) {
return next();
}
notifications.push(notification, [uid]);
}
], callback);
};

@ -90,7 +90,7 @@ var async = require('async'),
if (oldNotification) {
if (parseInt(oldNotification.pid, 10) === parseInt(data.pid, 10) && parseInt(oldNotification.importance, 10) > parseInt(data.importance, 10)) {
return callback();
return callback(null, null);
}
}
@ -367,7 +367,7 @@ var async = require('async'),
return cur;
}, []);
differentiators.forEach(function(differentiator) {
set = isolated.filter(function(notifObj) {
return notifObj.mergeId === (mergeId + '|' + differentiator);

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

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

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

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

Loading…
Cancel
Save