From 59387540c757658fa6509a4767a8bd683897a92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 20 May 2017 20:26:54 -0400 Subject: [PATCH] style --- src/messaging/rooms.js | 48 ++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/messaging/rooms.js b/src/messaging/rooms.js index ead62fee4d..0d7e1d2b1f 100644 --- a/src/messaging/rooms.js +++ b/src/messaging/rooms.js @@ -9,26 +9,33 @@ var plugins = require('../plugins'); module.exports = function (Messaging) { Messaging.getRoomData = function (roomId, callback) { - db.getObject('chat:room:' + roomId, function (err, data) { - if (err || !data) { - return callback(err || new Error('[[error:no-chat-room]]')); - } - modifyRoomData([data]); - callback(null, data); - }); + async.waterfall([ + function (next) { + db.getObject('chat:room:' + roomId, next); + }, + function (data, next) { + if (!data) { + return callback(new Error('[[error:no-chat-room]]')); + } + modifyRoomData([data]); + next(null, data); + }, + ], callback); }; Messaging.getRoomsData = function (roomIds, callback) { var keys = roomIds.map(function (roomId) { return 'chat:room:' + roomId; }); - db.getObjects(keys, function (err, roomData) { - if (err) { - return callback(err); + async.waterfall([ + function (next) { + db.getObjects(keys, next); + }, + function (roomData, next) { + modifyRoomData(roomData); + next(null, roomData); } - modifyRoomData(roomData); - callback(null, roomData); - }); + ], callback); }; function modifyRoomData(rooms) { @@ -96,13 +103,14 @@ module.exports = function (Messaging) { }; Messaging.isRoomOwner = function (uid, roomId, callback) { - db.getObjectField('chat:room:' + roomId, 'owner', function (err, owner) { - if (err) { - return callback(err); - } - - callback(null, parseInt(uid, 10) === parseInt(owner, 10)); - }); + async.waterfall([ + function (next) { + db.getObjectField('chat:room:' + roomId, 'owner', next); + }, + function (owner, next) { + next(null, parseInt(uid, 10) === parseInt(owner, 10)); + }, + ], callback); }; Messaging.addUsersToRoom = function (uid, uids, roomId, callback) {