mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	join, leave, accept, reject: handlers + UI, #2588
This commit is contained in:
		| @@ -1,15 +1,15 @@ | ||||
| "use strict"; | ||||
| /* globals socket, ajaxify */ | ||||
| /* globals define, socket, ajaxify, app */ | ||||
|  | ||||
| define('forum/groups/details', function() { | ||||
| 	var Details = {}; | ||||
|  | ||||
| 	Details.init = function() { | ||||
| 		var memberList = $('.groups .members'); | ||||
| 		var detailsPage = $('.groups'); | ||||
|  | ||||
| 		$('.latest-posts .content img').addClass('img-responsive'); | ||||
|  | ||||
| 		memberList.on('click', '[data-action]', function() { | ||||
| 		detailsPage.on('click', '[data-action]', function() { | ||||
| 			var btnEl = $(this), | ||||
| 				userRow = btnEl.parents('tr'), | ||||
| 				ownerFlagEl = userRow.find('.member-name i'), | ||||
| @@ -25,6 +25,24 @@ define('forum/groups/details', function() { | ||||
| 					}, function(err) { | ||||
| 						if (!err) { | ||||
| 							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; | ||||
|   | ||||
| @@ -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! | ||||
| 		db.setRemove('group:' + groupName + ':pending', uid, callback); | ||||
| 		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) { | ||||
| 		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; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user