diff --git a/doc/api/http_api.md b/doc/api/http_api.md index d51f42c4..335efb3c 100644 --- a/doc/api/http_api.md +++ b/doc/api/http_api.md @@ -206,6 +206,10 @@ Group pads are normal pads, but with the name schema GROUPID$PADNAME. A security * **padUsersCount(padID)** returns the number of user that are currently editing this pad

*Example returns:* * `{code: 0, message:"ok", data: {padUsersCount: 5}}` +* **padUsers(padID)** returns the list of users that are currently editing this pad

*Example returns:* + * `{code: 0, message:"ok", data: {padUsers: [{colorId:"#c1a9d9","name":"username1","timestamp":1345228793126},{"colorId":"#d9a9cd","name":"Hmmm","timestamp":1345228796042}]}}` + * `{code: 0, message:"ok", data: {padUsers: []}}` + * **deletePad(padID)** deletes a pad

*Example returns:* * `{code: 0, message:"ok", data: null}` * `{code: 1, message:"padID does not exist", data: null}` diff --git a/src/node/db/API.js b/src/node/db/API.js index 64ddef68..f0f1ebd4 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.padUsers = padMessageHandler.padUsers; exports.padUsersCount = padMessageHandler.padUsersCount; /**********************/ diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js index 4e16d56e..4d3b38dd 100644 --- a/src/node/handler/APIHandler.js +++ b/src/node/handler/APIHandler.js @@ -67,6 +67,7 @@ var functions = { "isPasswordProtected" : ["padID"], "listAuthorsOfPad" : ["padID"], "padUsersCount" : ["padID"], + "padUsers" : ["padID"], "sendClientsMessage" : ["padID", "msg"] }; diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 6a2dcaf2..913433b0 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -1410,3 +1410,26 @@ exports.padUsersCount = function (padID, callback) { callback(null, {padUsersCount: pad2sessions[padID].length}); } } + +/** + * Get the list of users in a pad + */ +exports.padUsers = function (padID, callback) { + if (!pad2sessions[padID] || typeof pad2sessions[padID] != typeof []) { + callback(null, {padUsers: []}); + } else { + var authors = []; + for ( var ix in sessioninfos ) { + if ( sessioninfos[ix].padId !== padID ) { + continue; + } + var aid = sessioninfos[ix].author; + authorManager.getAuthor( aid, function ( err, author ) { + authors.push( author ); + if ( authors.length === pad2sessions[padID].length ) { + callback(null, {padUsers: authors}); + } + } ); + } + } +}