diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 8fc43b15..77d7dc6c 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -330,7 +330,7 @@ function handleSaveRevisionMessage(client, message){ * @param msg {Object} the message we're sending * @param sessionID {string} the socketIO session to which we're sending this message */ -exports.handleCustomObjectMessage = thenify(function(msg, sessionID, cb) { +exports.handleCustomObjectMessage = async function(msg, sessionID) { if (msg.data.type === "CUSTOM") { if (sessionID){ // a sessionID is targeted: directly to this sessionID @@ -340,9 +340,7 @@ exports.handleCustomObjectMessage = thenify(function(msg, sessionID, cb) { socketio.sockets.in(msg.data.payload.padId).json.send(msg); } } - cb(null, {}); -}); - +} /** * Handles a custom message (sent via HTTP API request) @@ -809,7 +807,7 @@ function handleUserChanges(data, cb) }); } -exports.updatePadClients = function(pad, callback) +exports.updatePadClients = thenify(function(pad, callback) { // skip this if no-one is on this pad var roomClients = _getRoomClients(pad.id); @@ -886,7 +884,7 @@ exports.updatePadClients = function(pad, callback) callback ); },callback); -} +}); /** * Copied from the Etherpad Source Code. Don't know what this method does excatly... @@ -1503,7 +1501,7 @@ function handleChangesetRequest(client, message) * Tries to rebuild the getChangestInfo function of the original Etherpad * https://github.com/ether/pad/blob/master/etherpad/src/etherpad/control/pad/pad_changeset_control.js#L144 */ -function getChangesetInfo(padId, startNum, endNum, granularity, callback) +let getChangesetInfo = thenify(function getChangesetInfo(padId, startNum, endNum, granularity, callback) { var forwardsChangesets = []; var backwardsChangesets = []; @@ -1643,13 +1641,13 @@ function getChangesetInfo(padId, startNum, endNum, granularity, callback) start: startNum, granularity: granularity }); }); -} +}); /** * Tries to rebuild the getPadLines function of the original Etherpad * https://github.com/ether/pad/blob/master/etherpad/src/etherpad/control/pad/pad_changeset_control.js#L263 */ -function getPadLines(padId, revNum, callback) +let getPadLines = thenify(function getPadLines(padId, revNum, callback) { var atext; var result = {}; @@ -1693,13 +1691,13 @@ function getPadLines(padId, revNum, callback) callback(null, result); }); -} +}); /** * Tries to rebuild the composePadChangeset function of the original Etherpad * https://github.com/ether/pad/blob/master/etherpad/src/etherpad/control/pad/pad_changeset_control.js#L241 */ -function composePadChangesets(padId, startNum, endNum, callback) +let composePadChangesets = thenify(function(padId, startNum, endNum, callback) { var pad; var changesets = {}; @@ -1772,7 +1770,7 @@ function composePadChangesets(padId, startNum, endNum, callback) callback(null, changeset); }); -} +}); function _getRoomClients(padID) { var roomClients = []; @@ -1790,39 +1788,32 @@ function _getRoomClients(padID) { /** * Get the number of users in a pad */ -exports.padUsersCount = thenify(function(padID, callback) { - callback(null, { +exports.padUsersCount = function(padID) { + return { padUsersCount: _getRoomClients(padID).length - }); -}); + } +} /** * Get the list of users in a pad */ -exports.padUsers = thenify(function(padID, callback) { - var result = []; +exports.padUsers = async function(padID) { - var roomClients = _getRoomClients(padID); + let padUsers = []; + let roomClients = _getRoomClients(padID); - async.forEach(roomClients, function(roomClient, callback) { - var s = sessioninfos[roomClient.id]; + for (let i = 0, n = roomClients.length; i < n; ++i) { + let roomClient = roomClients[i]; + + let s = sessioninfos[roomClient.id]; if (s) { - authorManager.getAuthor(s.author, function(err, author) { - if (ERR(err, callback)) return; - - author.id = s.author; - result.push(author); - callback(); - }); - } else { - callback(); + let author = await authorManager.getAuthor(s.author); + author.id = s.author; + padUsers.push(author); } - }, - function(err) { - if (ERR(err, callback)) return; + } - callback(null, {padUsers: result}); - }); -}); + return { padUsers }; +} exports.sessioninfos = sessioninfos;