Skip to content

Node.js based forum software built for the modern web

creating notification for flag assignment

Julian Lamc805d55b858c
diff --git a/public/language/en-GB/notifications.json b/public/language/en-GB/notifications.json
index e04482c633..8c7ed9d07a 100644
--- a/public/language/en-GB/notifications.json
+++ b/public/language/en-GB/notifications.json
@@ -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.",
diff --git a/src/flags.js b/src/flags.js
index 185ef6f6ad..af63365a2a 100644
--- a/src/flags.js
+++ b/src/flags.js
@@ -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;
}
}