feat: send notification to group owners when someone leaves

v1.18.x
Barış Soner Uşaklı 5 years ago
parent 2150701f32
commit ed1223645e

@ -60,6 +60,7 @@
"membership.invitation-pending": "Invitation Pending", "membership.invitation-pending": "Invitation Pending",
"membership.join-group": "Join Group", "membership.join-group": "Join Group",
"membership.leave-group": "Leave Group", "membership.leave-group": "Leave Group",
"membership.leave.notification_title": "<strong>%1</strong> has left group <strong>%2</strong>",
"membership.reject": "Reject", "membership.reject": "Reject",
"new-group.group_name": "Group Name:", "new-group.group_name": "Group Name:",

@ -45,9 +45,7 @@ module.exports = function (Groups) {
groupNames = [groupNames]; groupNames = [groupNames];
} }
const sets = []; const sets = [];
groupNames.forEach(function (groupName) { groupNames.forEach(groupName => sets.push('group:' + groupName + ':pending', 'group:' + groupName + ':invited'));
sets.push('group:' + groupName + ':pending', 'group:' + groupName + ':invited');
});
await db.setsRemove(sets, uid); await db.setsRemove(sets, uid);
}; };

@ -1,11 +1,13 @@
'use strict'; 'use strict';
const validator = require('validator');
const groups = require('../groups'); const groups = require('../groups');
const meta = require('../meta'); const meta = require('../meta');
const user = require('../user'); const user = require('../user');
const utils = require('../utils'); const utils = require('../utils');
const events = require('../events'); const events = require('../events');
const privileges = require('../privileges'); const privileges = require('../privileges');
const notifications = require('../notifications');
const SocketGroups = module.exports; const SocketGroups = module.exports;
@ -74,6 +76,16 @@ SocketGroups.leave = async (socket, data) => {
} }
await groups.leave(data.groupName, socket.uid); await groups.leave(data.groupName, socket.uid);
const username = await user.getUserField(socket.uid, 'username');
const notification = await notifications.create({
type: 'group-leave',
bodyShort: '[[groups:membership.leave.notification_title, ' + username + ', ' + data.groupName + ']]',
nid: 'group:' + validator.escape(data.groupName) + ':uid:' + socket.uid + ':group-leave',
path: '/groups/' + utils.slugify(data.groupName),
});
const uids = await groups.getOwners(data.groupName);
await notifications.push(notification, uids);
logGroupEvent(socket, 'group-leave', { logGroupEvent(socket, 'group-leave', {
groupName: data.groupName, groupName: data.groupName,
}); });

Loading…
Cancel
Save