From 5ffeb3319b26baa0c539281634cbd0d18f6edfbf Mon Sep 17 00:00:00 2001 From: psychobunny Date: Tue, 15 Apr 2014 02:33:31 -0400 Subject: [PATCH] socket.io admin/groups --- src/socket.io/admin.js | 54 +---------------------------------- src/socket.io/admin/groups.js | 54 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 53 deletions(-) create mode 100644 src/socket.io/admin/groups.js diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index 70dfcffdb4..8b9adfb871 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -18,11 +18,11 @@ var groups = require('../groups'), SocketAdmin = { user: require('admin/user'), categories: require('admin/categories'), + groups: require('admin/groups'), themes: {}, plugins: {}, widgets: {}, config: {}, - groups: {}, settings: {} }; @@ -67,7 +67,6 @@ SocketAdmin.fireEvent = function(socket, data, callback) { index.server.sockets.emit(data.name, data.payload || {}); }; - SocketAdmin.themes.getInstalled = function(socket, data, callback) { meta.themes.get(callback); }; @@ -100,7 +99,6 @@ SocketAdmin.widgets.set = function(socket, data, callback) { widgets.setArea(data, callback); }; -/* Configs */ SocketAdmin.config.get = function(socket, data, callback) { meta.configs.list(callback); }; @@ -130,56 +128,6 @@ SocketAdmin.config.remove = function(socket, key) { meta.configs.remove(key); }; -/* Groups */ -SocketAdmin.groups.create = function(socket, data, callback) { - if(!data) { - return callback(new Error('[[error:invalid-data]]')); - } - - groups.create(data.name, data.description, function(err, groupObj) { - callback(err, groupObj || undefined); - }); -}; - -SocketAdmin.groups.delete = function(socket, groupName, callback) { - groups.destroy(groupName, callback); -}; - -SocketAdmin.groups.get = function(socket, groupName, callback) { - groups.get(groupName, { - expand: true - }, function(err, groupObj) { - callback(err, groupObj || undefined); - }); -}; - -SocketAdmin.groups.join = function(socket, data, callback) { - if(!data) { - return callback(new Error('[[error:invalid-data]]')); - } - - groups.join(data.groupName, data.uid, callback); -}; - -SocketAdmin.groups.leave = function(socket, data, callback) { - if(!data) { - return callback(new Error('[[error:invalid-data]]')); - } - - groups.leave(data.groupName, data.uid, callback); -}; - -SocketAdmin.groups.update = function(socket, data, callback) { - if(!data) { - return callback(new Error('[[error:invalid-data]]')); - } - - groups.update(data.groupName, data.values, function(err) { - callback(err ? err.message : null); - }); -}; - -/* Settings */ SocketAdmin.settings.get = function(socket, data, callback) { meta.settings.get(data.hash, callback); }; diff --git a/src/socket.io/admin/groups.js b/src/socket.io/admin/groups.js new file mode 100644 index 0000000000..c6254a2631 --- /dev/null +++ b/src/socket.io/admin/groups.js @@ -0,0 +1,54 @@ +"use strict"; + +var groups = require('../../groups'), + Groups = {}; + +Groups.create = function(socket, data, callback) { + if(!data) { + return callback(new Error('[[error:invalid-data]]')); + } + + groups.create(data.name, data.description, function(err, groupObj) { + callback(err, groupObj || undefined); + }); +}; + +Groups.delete = function(socket, groupName, callback) { + groups.destroy(groupName, callback); +}; + +Groups.get = function(socket, groupName, callback) { + groups.get(groupName, { + expand: true + }, function(err, groupObj) { + callback(err, groupObj || undefined); + }); +}; + +Groups.join = function(socket, data, callback) { + if(!data) { + return callback(new Error('[[error:invalid-data]]')); + } + + groups.join(data.groupName, data.uid, callback); +}; + +Groups.leave = function(socket, data, callback) { + if(!data) { + return callback(new Error('[[error:invalid-data]]')); + } + + groups.leave(data.groupName, data.uid, callback); +}; + +Groups.update = function(socket, data, callback) { + if(!data) { + return callback(new Error('[[error:invalid-data]]')); + } + + groups.update(data.groupName, data.values, function(err) { + callback(err ? err.message : null); + }); +}; + +module.exports = Groups; \ No newline at end of file