From 1182237f3d9caf25a864689e6ddb9ffba4ce97c7 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 17 Sep 2015 20:55:18 -0400 Subject: [PATCH] isInvited --- src/socket.io/groups.js | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/socket.io/groups.js b/src/socket.io/groups.js index 89eb0abd8b..30417c5e27 100644 --- a/src/socket.io/groups.js +++ b/src/socket.io/groups.js @@ -61,6 +61,17 @@ function isOwner(next) { }; } +function isInvited(next) { + return function (socket, data, callback) { + groups.isInvited(socket.uid, data.groupName, function(err, invited) { + if (err || !invited) { + return callback(err || new Error('[[error:not-invited]]')); + } + next(socket, data, callback); + }); + }; +} + SocketGroups.grant = isOwner(function(socket, data, callback) { groups.ownership.grant(data.toUid, data.groupName, callback); }); @@ -106,25 +117,13 @@ SocketGroups.rescindInvite = isOwner(function(socket, data, callback) { groups.rejectMembership(data.groupName, data.toUid, callback); }); -SocketGroups.acceptInvite = function(socket, data, callback) { - groups.isInvited(socket.uid, data.groupName, function(err, invited) { - if (err || !invited) { - return callback(err || new Error('[[error:no-privileges]]')); - } - - groups.acceptMembership(data.groupName, socket.uid, callback); - }); -}; - -SocketGroups.rejectInvite = function(socket, data, callback) { - groups.isInvited(socket.uid, data.groupName, function(err, invited) { - if (err || !invited) { - return callback(err || new Error('[[error:no-privileges]]')); - } +SocketGroups.acceptInvite = isInvited(function(socket, data, callback) { + groups.acceptMembership(data.groupName, socket.uid, callback); +}); - groups.rejectMembership(data.groupName, socket.uid, callback); - }); -}; +SocketGroups.rejectInvite = isInvited(function(socket, data, callback) { + groups.rejectMembership(data.groupName, socket.uid, callback); +}); SocketGroups.update = isOwner(function(socket, data, callback) { groups.update(data.groupName, data.values, callback);