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) {
|
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);
|
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(null, {
|
}, next);
|
||||||
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 (results, next) {
|
||||||
function(notification, next) {
|
if (!results.notification || !results.owners.length) {
|
||||||
Groups.getOwners(groupName, function(err, ownerUids) {
|
return next();
|
||||||
next(null, notification, ownerUids);
|
}
|
||||||
});
|
notifications.push(results.notification, results.owners, next);
|
||||||
},
|
}
|
||||||
async.apply(notifications.push)
|
|
||||||
], 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,7 +367,7 @@ var async = require('async'),
|
|||||||
|
|
||||||
return cur;
|
return cur;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
differentiators.forEach(function(differentiator) {
|
differentiators.forEach(function(differentiator) {
|
||||||
set = isolated.filter(function(notifObj) {
|
set = isolated.filter(function(notifObj) {
|
||||||
return notifObj.mergeId === (mergeId + '|' + differentiator);
|
return notifObj.mergeId === (mergeId + '|' + differentiator);
|
||||||
|
|||||||
@@ -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();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user