join, leave, accept, reject: handlers + UI, #2588

v1.18.x
Julian Lam 10 years ago
parent b0182f702f
commit 96c37c25b0

@ -1,15 +1,15 @@
"use strict"; "use strict";
/* globals socket, ajaxify */ /* globals define, socket, ajaxify, app */
define('forum/groups/details', function() { define('forum/groups/details', function() {
var Details = {}; var Details = {};
Details.init = function() { Details.init = function() {
var memberList = $('.groups .members'); var detailsPage = $('.groups');
$('.latest-posts .content img').addClass('img-responsive'); $('.latest-posts .content img').addClass('img-responsive');
memberList.on('click', '[data-action]', function() { detailsPage.on('click', '[data-action]', function() {
var btnEl = $(this), var btnEl = $(this),
userRow = btnEl.parents('tr'), userRow = btnEl.parents('tr'),
ownerFlagEl = userRow.find('.member-name i'), ownerFlagEl = userRow.find('.member-name i'),
@ -25,6 +25,24 @@ define('forum/groups/details', function() {
}, function(err) { }, function(err) {
if (!err) { if (!err) {
ownerFlagEl.toggleClass('invisible'); ownerFlagEl.toggleClass('invisible');
} else {
app.alertError(err);
}
});
break;
case 'join': // intentional fall-throughs!
case 'leave':
case 'accept':
case 'reject':
socket.emit('groups.' + action, {
toUid: uid,
groupName: ajaxify.variables.get('group_name')
}, function(err) {
if (!err) {
ajaxify.refresh();
} else {
app.alertError(err);
} }
}); });
break; break;

@ -558,12 +558,17 @@ var async = require('async'),
}); });
}; };
Groups.approveMembership = function(groupName, uid, callback) { Groups.acceptMembership = function(groupName, uid, callback) {
// Note: For simplicity, this method intentially doesn't check the caller uid for ownership! // Note: For simplicity, this method intentially doesn't check the caller uid for ownership!
db.setRemove('group:' + groupName + ':pending', uid, callback); db.setRemove('group:' + groupName + ':pending', uid, callback);
Groups.join.apply(Groups, arguments); Groups.join.apply(Groups, arguments);
}; };
Groups.rejectMembership = function(groupName, uid, callback) {
// Note: For simplicity, this method intentially doesn't check the caller uid for ownership!
db.setRemove('group:' + groupName + ':pending', uid, callback);
};
Groups.leave = function(groupName, uid, callback) { Groups.leave = function(groupName, uid, callback) {
callback = callback || function() {}; callback = callback || function() {};

@ -59,4 +59,32 @@ SocketGroups.rescind = function(socket, data, callback) {
}); });
}; };
SocketGroups.accept = function(socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {
if (!isOwner) {
return callback(new Error('[[error:no-privileges]]'));
}
groups.acceptMembership(data.groupName, data.toUid, callback);
});
};
SocketGroups.reject = function(socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {
if (!isOwner) {
return callback(new Error('[[error:no-privileges]]'));
}
groups.rejectMembership(data.groupName, data.toUid, callback);
});
};
module.exports = SocketGroups; module.exports = SocketGroups;

Loading…
Cancel
Save