From c215e61541dc589b6dd3875dd558ddf6f4038ad9 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 16 Jan 2014 15:13:22 -0500 Subject: [PATCH 1/2] fixed up admin.js --- public/src/forum/admin/categories.js | 7 ++++- src/socket.io/admin.js | 38 ++++++++++++++-------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/public/src/forum/admin/categories.js b/public/src/forum/admin/categories.js index 0cff58bef2..8f2a18c69b 100644 --- a/public/src/forum/admin/categories.js +++ b/public/src/forum/admin/categories.js @@ -303,7 +303,12 @@ define(['uploader'], function(uploader) { gid = btnEl.parents('tr[data-gid]').attr('data-gid'), privilege = this.getAttribute('data-gpriv'); e.preventDefault(); - socket.emit('admin.categories.setGroupPrivilege', cid, gid, privilege, !btnEl.hasClass('active'), function(err) { + socket.emit('admin.categories.setGroupPrivilege', { + cid: cid, + gid: gid, + privilege: privilege, + set: !btnEl.hasClass('active') + }, function(err) { if (!err) { btnEl.toggleClass('active'); } diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index bcc647b1c2..555c9308d3 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -150,7 +150,7 @@ SocketAdmin.categories.setPrivilege = function(socket, data, callback) { } }; -SocketAdmin.categories.getPrivilegeSettings = function(cid, callback) { +SocketAdmin.categories.getPrivilegeSettings = function(socket, cid, callback) { async.parallel({ "+r": function(next) { groups.getByGroupName('cid:' + cid + ':privileges:+r', { expand: true }, function(err, groupObj) { @@ -182,15 +182,15 @@ SocketAdmin.categories.getPrivilegeSettings = function(cid, callback) { }); }; -SocketAdmin.categories.setGroupPrivilege = function(cid, gid, privilege, set, callback) { - if (set) { - groups.joinByGroupName('cid:' + cid + ':privileges:' + privilege, gid, callback); +SocketAdmin.categories.setGroupPrivilege = function(socket, data, callback) { + if (data.set) { + groups.joinByGroupName('cid:' + data.cid + ':privileges:' + data.privilege, data.gid, callback); } else { - groups.leaveByGroupName('cid:' + cid + ':privileges:' + privilege, gid, callback); + groups.leaveByGroupName('cid:' + data.cid + ':privileges:' + data.privilege, data.gid, callback); } }; -SocketAdmin.categories.groupsList = function(cid, callback) { +SocketAdmin.categories.groupsList = function(socket, cid, callback) { groups.list({expand:false}, function(err, data){ async.map(data, function(groupObj, next) { CategoryTools.groupPrivileges(cid, groupObj.gid, function(err, privileges) { @@ -213,7 +213,7 @@ SocketAdmin.categories.groupsList = function(cid, callback) { SocketAdmin.themes = {}; SocketAdmin.plugins = {}; -SocketAdmin.themes.getInstalled = function(callback) { +SocketAdmin.themes.getInstalled = function(socket, data, callback) { meta.themes.get(function(err, themeArr) { callback(themeArr); }); @@ -221,9 +221,9 @@ SocketAdmin.themes.getInstalled = function(callback) { SocketAdmin.themes.set = meta.themes.set; -SocketAdmin.plugins.toggle = function(plugin_id, sessionData) { +SocketAdmin.plugins.toggle = function(socket, plugin_id) { plugins.toggleActive(plugin_id, function(status) { - sessionData.socket.emit('api:admin.plugins.toggle', status); + socket.emit('api:admin.plugins.toggle', status); }); }; @@ -231,7 +231,7 @@ SocketAdmin.plugins.toggle = function(plugin_id, sessionData) { SocketAdmin.config = {}; -SocketAdmin.config.get = function(callback, sessionData) { +SocketAdmin.config.get = function(socket, data, callback) { meta.configs.list(function(err, config) { if (!err) { callback(config); @@ -239,7 +239,7 @@ SocketAdmin.config.get = function(callback, sessionData) { }); }; -SocketAdmin.config.set = function(data, callback, sessionData) { +SocketAdmin.config.set = function(socket, data, callback) { meta.configs.set(data.key, data.value, function(err) { if (!err) { callback({ @@ -252,11 +252,11 @@ SocketAdmin.config.set = function(data, callback, sessionData) { }); } - logger.monitorConfig({io: sessionData.server}, data); + logger.monitorConfig({io: socket.server}, data); }); }; -SocketAdmin.config.remove = function(key) { +SocketAdmin.config.remove = function(socket, key) { meta.configs.remove(key); }; @@ -264,19 +264,19 @@ SocketAdmin.config.remove = function(key) { SocketAdmin.groups = {}; -SocketAdmin.groups.create = function(data, callback) { +SocketAdmin.groups.create = function(socket, data, callback) { groups.create(data.name, data.description, function(err, groupObj) { callback(err ? err.message : null, groupObj || undefined); }); }; -SocketAdmin.groups.delete = function(gid, callback) { +SocketAdmin.groups.delete = function(socket, gid, callback) { groups.destroy(gid, function(err) { callback(err ? err.message : null, err ? null : 'OK'); }); }; -SocketAdmin.groups.get = function(gid, callback) { +SocketAdmin.groups.get = function(socket, gid, callback) { groups.get(gid, { expand: true }, function(err, groupObj) { @@ -284,15 +284,15 @@ SocketAdmin.groups.get = function(gid, callback) { }); }; -SocketAdmin.groups.join = function(data, callback) { +SocketAdmin.groups.join = function(socket, data, callback) { groups.join(data.gid, data.uid, callback); }; -SocketAdmin.groups.leave = function(data, callback) { +SocketAdmin.groups.leave = function(socket, data, callback) { groups.leave(data.gid, data.uid, callback); }; -SocketAdmin.groups.update = function(data, callback) { +SocketAdmin.groups.update = function(socket, data, callback) { groups.update(data.gid, data.values, function(err) { callback(err ? err.message : null); }); From 69a9570186db99edec8a56fd18194827cebd0204 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 16 Jan 2014 15:16:12 -0500 Subject: [PATCH 2/2] migrated catefories.js to new socketAL format --- src/socket.io/categories.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/socket.io/categories.js b/src/socket.io/categories.js index e00e61c1e5..b670f1ff8d 100644 --- a/src/socket.io/categories.js +++ b/src/socket.io/categories.js @@ -2,13 +2,13 @@ var categories = require('../categories'), SocketCategories = {}; -SocketCategories.getRecentReplies = function(tid, callback, sessionData) { - categories.getRecentReplies(tid, sessionData.uid, 4, function(err, replies) { +SocketCategories.getRecentReplies = function(socket, tid, callback) { + categories.getRecentReplies(tid, socket.uid, 4, function(err, replies) { callback(replies); }); }; -SocketCategories.get = function(callback) { +SocketCategories.get = function(socket, data, callback) { categories.getAllCategories(0, function(err, categories) { if(callback) { callback(categories); @@ -16,11 +16,11 @@ SocketCategories.get = function(callback) { }); }; -SocketCategories.loadMore = function(data, callback, sessionData) { +SocketCategories.loadMore = function(socket, data, callback) { var start = data.after, end = start + 9; - categories.getCategoryTopics(data.cid, start, end, sessionData.uid, function(topics) { + categories.getCategoryTopics(data.cid, start, end, socket.uid, function(topics) { callback({ topics: topics });