diff --git a/src/notifications.js b/src/notifications.js index c70c0cbb0a..ed2e98b7da 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -236,6 +236,19 @@ var utils = require('../public/src/utils'); }); }; + Notifications.pushGroups = function (notification, groupNames, callback) { + callback = callback || function () {}; + groups.getMembersOfGroups(groupNames, function (err, groupMembers) { + if (err) { + return callback(err); + } + + var members = _.unique(_.flatten(groupMembers)); + + Notifications.push(notification, members, callback); + }); + }; + Notifications.rescind = function (nid, callback) { callback = callback || function () {}; diff --git a/test/notifications.js b/test/notifications.js index 3eebe656bb..4a4f6c320d 100644 --- a/test/notifications.js +++ b/test/notifications.js @@ -67,6 +67,32 @@ describe('Notifications', function () { }); }); + it('should push a notification to a group', function (done) { + notifications.pushGroup(notification, 'registered-users', function (err) { + assert.ifError(err); + setTimeout(function () { + db.isSortedSetMember('uid:' + uid + ':notifications:unread', notification.nid, function (err, isMember) { + assert.ifError(err); + assert(isMember); + done(); + }); + }, 2000); + }); + }); + + it('should push a notification to groups', function (done) { + notifications.pushGroup(notification, ['registered-users', 'administrators'], function (err) { + assert.ifError(err); + setTimeout(function () { + db.isSortedSetMember('uid:' + uid + ':notifications:unread', notification.nid, function (err, isMember) { + assert.ifError(err); + assert(isMember); + done(); + }); + }, 2000); + }); + }); + it('should mark a notification read', function (done) { notifications.markRead(notification.nid, uid, function (err) { assert.ifError(err);