From c805d55b858c6fb315b565cd3156f937b66dd1d2 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 17 Mar 2017 13:16:16 -0400 Subject: [PATCH] creating notification for flag assignment --- public/language/en-GB/notifications.json | 1 + src/flags.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) 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": "%1 and %2 others started following you.", "new_register": "%1 sent a registration request.", "new_register_multiple": "There are %1 registration requests awaiting review.", + "flag_assigned_to_you": "Flag %1 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; } }