creating notification for flag assignment

v1.18.x
Julian Lam 8 years ago
parent 7f8f197e60
commit c805d55b85

@ -44,6 +44,7 @@
"user_started_following_you_multiple": "<strong>%1</strong> and %2 others started following you.",
"new_register": "<strong>%1</strong> sent a registration request.",
"new_register_multiple": "There are <strong>%1</strong> registration requests awaiting review.",
"flag_assigned_to_you": "<strong>Flag %1</strong> has been assigned to you",
"email-confirmed": "Email Confirmed",
"email-confirmed-message": "Thank you for validating your email. Your account is now fully activated.",

@ -439,6 +439,27 @@ Flags.update = function (flagId, uid, changeset, callback) {
var fields = ['state', 'assignee'];
var tasks = [];
var now = changeset.datetime || Date.now();
var notifyAssignee = function (assigneeId, next) {
if (assigneeId === '') {
// Do nothing
return next();
}
// Notify assignee of this update
notifications.create({
type: 'my-flags',
bodyShort: '[[notifications:flag_assigned_to_you, ' + flagId + ']]',
bodyLong: '',
path: '/flags/' + flagId,
nid: 'flags:assign:' + flagId + ':uid:' + assigneeId,
from: uid,
}, function (err, notification) {
if (err) {
return next(err);
}
notifications.push(notification, [assigneeId], next);
});
};
async.waterfall([
async.apply(db.getObjectFields.bind(db), 'flag:' + flagId, fields),
@ -457,6 +478,7 @@ Flags.update = function (flagId, uid, changeset, callback) {
case 'assignee':
tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byAssignee:' + changeset[prop], now, flagId));
tasks.push(async.apply(notifyAssignee, changeset[prop]));
break;
}
}

Loading…
Cancel
Save