From a71a8a7efc074be7d0ab86a240d95afefb38df53 Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Fri, 29 Jun 2012 11:26:12 -0700 Subject: [PATCH] Add in padUsersCount method and API call The PadMessageHandler objects now have a new API call associated with them. I'm sure that's a funny place to put it, but the pad2sessions object in that file seems to be the only place user counts are stored! Anyway, I hope this is helpful. I know it would be for me :) --- src/node/db/API.js | 1 + src/node/handler/APIHandler.js | 3 ++- src/node/handler/PadMessageHandler.js | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/node/db/API.js b/src/node/db/API.js index e2b6f6f8b..661b78595 100644 --- a/src/node/db/API.js +++ b/src/node/db/API.js @@ -48,6 +48,7 @@ exports.createGroupPad = groupManager.createGroupPad; exports.createAuthor = authorManager.createAuthor; exports.createAuthorIfNotExistsFor = authorManager.createAuthorIfNotExistsFor; exports.listPadsOfAuthor = authorManager.listPadsOfAuthor; +exports.padUsersCount = padMessageHandler.padUsersCount; /**********************/ /**SESSION FUNCTIONS***/ diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js index 567a90d28..40c08441a 100644 --- a/src/node/handler/APIHandler.js +++ b/src/node/handler/APIHandler.js @@ -65,7 +65,8 @@ var functions = { "getPublicStatus" : ["padID"], "setPassword" : ["padID", "password"], "isPasswordProtected" : ["padID"], - "listAuthorsOfPad" : ["padID"] + "listAuthorsOfPad" : ["padID"], + "padUsersCount" : ["padID"] }; /** diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index b356230c7..9cf396691 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -1348,3 +1348,14 @@ function composePadChangesets(padId, startNum, endNum, callback) callback(null, changeset); }); } + +/** + * Get the number of users in a pad + */ +exports.padUsersCount = function (padID, callback) { + if (!pad2sessions[padID] || typeof pad2sessions[padID] != typeof []) { + callback(null, {padUsersCount: 0}); + } else { + callback(null, {padUsersCount: pad2sessions[padID].length}); + } +}