From 111776d8781465579404a8e016549c880e1bf6e2 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 16 Jan 2014 20:29:11 -0500 Subject: [PATCH] notifications socket callbacks --- public/src/modules/notifications.js | 4 ++-- src/socket.io/notifications.js | 10 ++++------ src/user.js | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js index c5e172f165..8994ba008a 100644 --- a/public/src/modules/notifications.js +++ b/public/src/modules/notifications.js @@ -11,14 +11,14 @@ define(function() { notifTrigger.addEventListener('click', function(e) { e.preventDefault(); if (notifContainer.className.indexOf('open') === -1) { - socket.emit('notifications.get', null, function(data) { + socket.emit('notifications.get', null, function(err, data) { var notifFrag = document.createDocumentFragment(), notifEl = document.createElement('li'), numRead = data.read.length, numUnread = data.unread.length, x; notifList.innerHTML = ''; - if ((data.read.length + data.unread.length) > 0) { + if (!err && (data.read.length + data.unread.length) > 0) { for (x = 0; x < numUnread; x++) { notifEl.setAttribute('data-nid', data.unread[x].nid); notifEl.className = 'unread'; diff --git a/src/socket.io/notifications.js b/src/socket.io/notifications.js index 3c4d7c352a..3c41f33d5d 100644 --- a/src/socket.io/notifications.js +++ b/src/socket.io/notifications.js @@ -1,17 +1,15 @@ +"use strict"; + var user = require('../user'), SocketNotifs = {}; SocketNotifs.get = function(socket, data, callback) { - user.notifications.get(socket.uid, function(notifs) { - callback(notifs); - }); + user.notifications.get(socket.uid, callback); }; SocketNotifs.getCount = function(socket, data, callback) { - user.notifications.getUnreadCount(socket.uid, function(err, count) { - callback(err ? err.message : null, count); - }); + user.notifications.getUnreadCount(socket.uid, callback); }; module.exports = SocketNotifs; \ No newline at end of file diff --git a/src/user.js b/src/user.js index b17e612ba9..09155e17f7 100644 --- a/src/user.js +++ b/src/user.js @@ -1016,7 +1016,7 @@ var bcrypt = require('bcrypt'), notifications.read.length = maxNotifs - notifications.unread.length; } - callback(notifications); + callback(err, notifications); }); }, getAll: function(uid, limit, before, callback) {