mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 12:31:33 +01:00
Close #3578
This commit introduces notification creation if a user requests membership to a group (in which case notifications are sent to all group owners), and user invites to a group (in which case a notification is sent to the invitee).
This commit is contained in:
@@ -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 <strong>%1</strong>",
|
||||
|
||||
"request.notification_title": "Group Membership Request from <strong>%1</strong>",
|
||||
"request.notification_text": "<strong>%1</strong> has requested to become a member of <strong>%2</strong>",
|
||||
|
||||
"cover-instructions": "Drag and Drop a photo, drag to position, and hit <strong>Save</strong>",
|
||||
"cover-change": "Change",
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user