diff --git a/public/language/en_GB/groups.json b/public/language/en_GB/groups.json
index 958efd13e0..d800d74b1c 100644
--- a/public/language/en_GB/groups.json
+++ b/public/language/en_GB/groups.json
@@ -14,6 +14,10 @@
"invited.none": "There are no invited members at this time",
"invited.uninvite": "Rescind Invitation",
"invited.search": "Search for a user to invite to this group",
+ "invited.notification_title": "You have been invited to join %1",
+
+ "request.notification_title": "Group Membership Request from %1",
+ "request.notification_text": "%1 has requested to become a member of %2",
"cover-instructions": "Drag and Drop a photo, drag to position, and hit Save",
"cover-change": "Change",
diff --git a/src/groups.js b/src/groups.js
index 13bae53e5f..24ee5a9fd8 100644
--- a/src/groups.js
+++ b/src/groups.js
@@ -197,6 +197,10 @@ var async = require('async'),
});
};
+ Groups.getOwners = function(groupName, callback) {
+ db.getSetMembers('group:' + groupName + ':owners', callback);
+ };
+
Groups.getOwnersAndMembers = function(groupName, uid, start, stop, callback) {
async.parallel({
owners: function (next) {
diff --git a/src/groups/membership.js b/src/groups/membership.js
index 51ee633787..c8cf9a9871 100644
--- a/src/groups/membership.js
+++ b/src/groups/membership.js
@@ -5,7 +5,9 @@ var async = require('async'),
_ = require('underscore'),
user = require('../user'),
+ utils = require('../../public/src/utils'),
plugins = require('../plugins'),
+ notifications = require('../notifications'),
db = require('./../database');
module.exports = function(Groups) {
@@ -66,7 +68,29 @@ module.exports = function(Groups) {
};
Groups.requestMembership = function(groupName, uid, callback) {
- inviteOrRequestMembership(groupName, uid, 'request', callback);
+ async.waterfall([
+ async.apply(inviteOrRequestMembership, groupName, uid, 'request'),
+ function(next) {
+ user.getUserField(uid, 'username', function(err, username) {
+ if (err) {
+ return next(err);
+ }
+ next(null, {
+ 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(notification, next) {
+ Groups.getOwners(groupName, function(err, ownerUids) {
+ next(null, notification, ownerUids);
+ });
+ },
+ async.apply(notifications.push)
+ ], callback);
};
Groups.acceptMembership = function(groupName, uid, callback) {
@@ -87,7 +111,19 @@ module.exports = function(Groups) {
};
Groups.invite = function(groupName, uid, callback) {
- inviteOrRequestMembership(groupName, uid, 'invite', callback);
+ async.waterfall([
+ async.apply(inviteOrRequestMembership, groupName, uid, 'invite'),
+ async.apply(notifications.create, {
+ bodyShort: '[[groups:invited.notification_title, ' + groupName + ']]',
+ bodyLong: '',
+ nid: 'group:' + groupName + ':uid:' + uid + ':invite',
+ path: '/groups/' + utils.slugify(groupName)
+ }),
+ function(notification, next) {
+ next(null, notification, [uid]);
+ },
+ async.apply(notifications.push)
+ ], callback);
};
function inviteOrRequestMembership(groupName, uid, type, callback) {