Merge pull request #957 from MarkTraceur/hook/http/padUsers

Add in padUsers HTTP API call
pull/984/head
John McLear 2012-08-22 13:13:27 -07:00
commit 7f9edd1df1
4 changed files with 29 additions and 0 deletions

View File

@ -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 <br><br>*Example returns:* * **padUsersCount(padID)** returns the number of user that are currently editing this pad <br><br>*Example returns:*
* `{code: 0, message:"ok", data: {padUsersCount: 5}}` * `{code: 0, message:"ok", data: {padUsersCount: 5}}`
* **padUsers(padID)** returns the list of users that are currently editing this pad <br><br>*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 <br><br>*Example returns:* * **deletePad(padID)** deletes a pad <br><br>*Example returns:*
* `{code: 0, message:"ok", data: null}` * `{code: 0, message:"ok", data: null}`
* `{code: 1, message:"padID does not exist", data: null}` * `{code: 1, message:"padID does not exist", data: null}`

View File

@ -48,6 +48,7 @@ exports.createGroupPad = groupManager.createGroupPad;
exports.createAuthor = authorManager.createAuthor; exports.createAuthor = authorManager.createAuthor;
exports.createAuthorIfNotExistsFor = authorManager.createAuthorIfNotExistsFor; exports.createAuthorIfNotExistsFor = authorManager.createAuthorIfNotExistsFor;
exports.listPadsOfAuthor = authorManager.listPadsOfAuthor; exports.listPadsOfAuthor = authorManager.listPadsOfAuthor;
exports.padUsers = padMessageHandler.padUsers;
exports.padUsersCount = padMessageHandler.padUsersCount; exports.padUsersCount = padMessageHandler.padUsersCount;
/**********************/ /**********************/

View File

@ -67,6 +67,7 @@ var functions = {
"isPasswordProtected" : ["padID"], "isPasswordProtected" : ["padID"],
"listAuthorsOfPad" : ["padID"], "listAuthorsOfPad" : ["padID"],
"padUsersCount" : ["padID"], "padUsersCount" : ["padID"],
"padUsers" : ["padID"],
"sendClientsMessage" : ["padID", "msg"] "sendClientsMessage" : ["padID", "msg"]
}; };

View File

@ -1410,3 +1410,26 @@ exports.padUsersCount = function (padID, callback) {
callback(null, {padUsersCount: pad2sessions[padID].length}); 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});
}
} );
}
}
}