From cf4ba9d1d34711c1901ca5f63421c91205ce7d77 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 18 Sep 2013 10:44:54 -0400 Subject: [PATCH] format/jshint favourites.js --- .jsbeautifyrc | 2 +- src/favourites.js | 32 +++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.jsbeautifyrc b/.jsbeautifyrc index 5102dfec5f..d76e93f2d5 100644 --- a/.jsbeautifyrc +++ b/.jsbeautifyrc @@ -2,7 +2,7 @@ "indent_size": 4, "indent_char": " ", "indent_level": 0, - "indent_with_tabs": false, + "indent_with_tabs": true, "preserve_newlines": true, "max_preserve_newlines": 10, "jslint_happy": true, diff --git a/src/favourites.js b/src/favourites.js index f8f88ecbee..1691e20f13 100644 --- a/src/favourites.js +++ b/src/favourites.js @@ -2,9 +2,10 @@ var RDB = require('./redis.js'), posts = require('./posts.js'), user = require('./user.js'); -(function(Favourites) { +(function (Favourites) { + "use strict"; - Favourites.favourite = function(pid, room_id, uid, socket) { + Favourites.favourite = function (pid, room_id, uid, socket) { if (uid === 0) { socket.emit('event:alert', { alert_id: 'post_favourite', @@ -16,9 +17,9 @@ var RDB = require('./redis.js'), return; } - posts.getPostFields(pid, ['uid', 'timestamp'], function(postData) { + posts.getPostFields(pid, ['uid', 'timestamp'], function (postData) { - Favourites.hasFavourited(pid, uid, function(hasFavourited) { + Favourites.hasFavourited(pid, uid, function (hasFavourited) { if (hasFavourited === 0) { RDB.sadd('pid:' + pid + ':users_favourited', uid); RDB.zadd('uid:' + uid + ':favourites', postData.timestamp, pid); @@ -26,7 +27,7 @@ var RDB = require('./redis.js'), RDB.hincrby('post:' + pid, 'reputation', 1); if (uid !== postData.uid) { - user.incrementUserFieldBy(postData.uid, 'reputation', 1, function(err, newreputation) { + user.incrementUserFieldBy(postData.uid, 'reputation', 1, function (err, newreputation) { RDB.zadd('users:reputation', newreputation, postData.uid); }); } @@ -47,7 +48,7 @@ var RDB = require('./redis.js'), }); }; - Favourites.unfavourite = function(pid, room_id, uid, socket) { + Favourites.unfavourite = function (pid, room_id, uid, socket) { if (uid === 0) { socket.emit('event:alert', { alert_id: 'post_favourite', @@ -59,8 +60,8 @@ var RDB = require('./redis.js'), return; } - posts.getPostField(pid, 'uid', function(uid_of_poster) { - Favourites.hasFavourited(pid, uid, function(hasFavourited) { + posts.getPostField(pid, 'uid', function (uid_of_poster) { + Favourites.hasFavourited(pid, uid, function (hasFavourited) { if (hasFavourited === 1) { RDB.srem('pid:' + pid + ':users_favourited', uid); RDB.zrem('uid:' + uid + ':favourites', pid); @@ -68,7 +69,7 @@ var RDB = require('./redis.js'), RDB.hincrby('post:' + pid, 'reputation', -1); if (uid !== uid_of_poster) { - user.incrementUserFieldBy(uid_of_poster, 'reputation', -1, function(err, newreputation) { + user.incrementUserFieldBy(uid_of_poster, 'reputation', -1, function (err, newreputation) { RDB.zadd('users:reputation', newreputation, uid_of_poster); }); } @@ -89,26 +90,27 @@ var RDB = require('./redis.js'), }); }; - Favourites.hasFavourited = function(pid, uid, callback) { - RDB.sismember('pid:' + pid + ':users_favourited', uid, function(err, hasFavourited) { + Favourites.hasFavourited = function (pid, uid, callback) { + RDB.sismember('pid:' + pid + ':users_favourited', uid, function (err, hasFavourited) { RDB.handle(err); callback(hasFavourited); }); }; - Favourites.getFavouritesByPostIDs = function(pids, uid, callback) { + Favourites.getFavouritesByPostIDs = function (pids, uid, callback) { var loaded = 0; var data = {}; for (var i = 0, ii = pids.length; i < ii; i++) { - (function(post_id) { - Favourites.hasFavourited(post_id, uid, function(hasFavourited) { + (function (post_id) { + Favourites.hasFavourited(post_id, uid, function (hasFavourited) { data[post_id] = hasFavourited; loaded++; - if (loaded === pids.length) + if (loaded === pids.length) { callback(data); + } }); }(pids[i])); }