mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
notifications.create can return null
This commit is contained in:
@@ -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, {
|
||||
function (next) {
|
||||
user.getUserField(uid, 'username', next);
|
||||
},
|
||||
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);
|
||||
},
|
||||
async.apply(notifications.create),
|
||||
function(notification, next) {
|
||||
Groups.getOwners(groupName, function(err, ownerUids) {
|
||||
next(null, notification, ownerUids);
|
||||
});
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}, next);
|
||||
},
|
||||
function (notification, next) {
|
||||
if (notification) {
|
||||
notifications.push(notification, followers);
|
||||
}
|
||||
next();
|
||||
});
|
||||
},
|
||||
function (next) {
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user