From c320051a1ec04e4f65579017f5a1b94d031b4b4d Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 12 Mar 2014 01:40:31 -0400 Subject: [PATCH 1/2] chat jshint --- public/src/modules/chat.js | 63 +++++++++++++++++++++----------------- public/src/templates.js | 2 +- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js index 5818c36b03..476718aa9a 100644 --- a/public/src/modules/chat.js +++ b/public/src/modules/chat.js @@ -1,3 +1,7 @@ + +'use strict'; +/* globals app, config, define, socket, translator, templates, utils */ + define(['taskbar', 'string', 'sound'], function(taskbar, S, sound) { var module = {}; @@ -5,42 +9,45 @@ define(['taskbar', 'string', 'sound'], function(taskbar, S, sound) { module.prepareDOM = function() { // Chats Dropdown var chatsToggleEl = $('#chat_dropdown'), - chatsListEl = $('#chat-list'), - chatDropdownEl = chatsToggleEl.parent(); + chatsListEl = $('#chat-list'); chatsToggleEl.on('click', function() { - if (chatDropdownEl.hasClass('open')) { + if (chatsToggleEl.parent().hasClass('open')) { return; } socket.emit('modules.chats.list', function(err, chats) { - var numChats = chats.length, - chatEl, x, userObj; + if (err) { + return app.alertError(err.message); + } + + var userObj; + chatsListEl.empty(); - if (!err && numChats > 0) { - - for(x = 0;x < numChats; x++) { - userObj = chats[x]; - chatEl = $('
  • ') - .attr('data-uid', userObj.uid) - .html('' + userObj.username + ''); - - chatsListEl.append(chatEl); - } - } else { + + if (!chats.length) { translator.get('modules:chat.no_active', function(str) { - chatEl = $('
  • ') + $('
  • ') .addClass('no_active') - .html('' + str + ''); - chatsListEl.append(chatEl); + .html('' + str + '') + .appendTo(chatsListEl); }); + return; + } + + for(var x = 0; x') + .attr('data-uid', userObj.uid) + .html('' + userObj.username + '') + .appendTo(chatsListEl); } }); }); @@ -72,7 +79,7 @@ define(['taskbar', 'string', 'sound'], function(taskbar, S, sound) { sound.play('chat-incoming'); }); - } + }; module.bringModalToTop = function(chatModal) { var topZ = 0; @@ -114,7 +121,7 @@ define(['taskbar', 'string', 'sound'], function(taskbar, S, sound) { module.createModal = function(username, touid, callback) { templates.preload_template('chat', function() { - translator.translate(templates['chat'].parse({}), function (chatTpl) { + translator.translate(templates.chat.parse({}), function (chatTpl) { var chatModal = $(chatTpl), uuid = utils.generateUUID(); diff --git a/public/src/templates.js b/public/src/templates.js index 2e31e6a4ab..0ee0c13339 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -174,7 +174,7 @@ value = $(element).val(); break; } - + templates.set($(element).attr('template-variable'), value); }); }; From 6eff7d4c51a1cfbd165566cd3c78b28b00afe1bd Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 12 Mar 2014 02:04:31 -0400 Subject: [PATCH 2/2] mongo cleanup --- src/database/mongo.js | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index 8c2d527309..f73557a8a7 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -257,11 +257,7 @@ var data = {}; field = fieldToString(field); data[field] = value; - db.collection('objects').update({_key:key}, {$set:data}, {upsert:true, w: 1}, function(err, result) { - if(typeof callback === 'function') { - callback(err, result); - } - }); + module.setObject(key, data, callback); }; module.getObject = function(key, callback) { @@ -480,7 +476,7 @@ } values = values.map(function(value) { - return items.members.indexOf(value) !== -1 + return items.members.indexOf(value) !== -1; }); callback(null, values); @@ -676,36 +672,24 @@ }; module.sortedSetRank = function(key, value, callback) { - value = toString(value); - module.getSortedSetRange(key, 0, -1, function(err, result) { - if(err) { - return callback(err); - } - var rank = result.indexOf(value); - if(rank === -1) { - return callback(null, null); - } - - callback(null, rank); - }); + getSortedSetRank(module.getSortedSetRange, key, value, callback); }; module.sortedSetRevRank = function(key, value, callback) { + getSortedSetRank(module.getSortedSetRevRange, key, value, callback); + }; + + function getSortedSetRank(method, key, value, callback) { value = toString(value); - module.getSortedSetRevRange(key, 0, -1, function(err, result) { + method(key, 0, -1, function(err, result) { if(err) { return callback(err); } var rank = result.indexOf(value); - - if(rank === -1) { - return callback(null, null); - } - - callback(null, rank); + callback(null, rank !== -1 ? rank : null); }); - }; + } module.sortedSetScore = function(key, value, callback) { value = toString(value);