From 15feaafd68310d7cc303c76010303bfc333a05be Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 26 Aug 2013 15:20:06 -0400 Subject: [PATCH] attempting fix for #179, @barisusakli can you pull and test if this is still present? --- public/src/forum/footer.js | 80 +++++++++++++++++++------------------- src/websockets.js | 4 +- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js index 75ef3d499a..439bbdca50 100644 --- a/public/src/forum/footer.js +++ b/public/src/forum/footer.js @@ -6,7 +6,7 @@ user_label = document.getElementById('user_label'), active_record = document.getElementById('active_record'), right_menu = document.getElementById('right-menu'); - + socket.emit('user.count', {}); socket.on('user.count', function(data) { num_users.innerHTML = "We currently have " + data.count + " registered users."; @@ -28,22 +28,22 @@ socket.emit('api:user.active.get'); socket.on('api:user.active.get', function(data) { - + var plural_users = parseInt(data.users) !== 1, plural_anon = parseInt(data.anon) !== 1; active_users.innerHTML = 'There ' + (plural_users ? 'are' : 'is') + ' ' + data.users + ' user' + (plural_users ? 's' : '') + ' and ' + data.anon + ' guest' + (plural_anon ? 's' : '') + ' online'; }); - + socket.emit('api:user.active.get_record'); socket.on('api:user.active.get_record', function(data) { active_record.innerHTML = "most users ever online was " + data.record + " on " + (new Date(parseInt(data.timestamp,10))).toUTCString() + ""; }); socket.emit('api:updateHeader', { fields: ['username', 'picture', 'userslug'] }); - + socket.on('api:updateHeader', function(data) { - + var rightMenu = $('#right-menu'), isLoggedIn = data.uid > 0; @@ -96,10 +96,39 @@ notifTrigger.addEventListener('click', function(e) { e.preventDefault(); if (notifContainer.className.indexOf('open') === -1) { - socket.emit('api:notifications.get'); - socket.emit('api:notifications.mark_all_read', null, function() { - notifIcon.className = 'icon-circle-blank'; - utils.refreshTitle(); + socket.emit('api:notifications.get', null, function(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) { + for(x=0;x' + utils.relativeTime(data.unread[x].datetime, true) + '' + data.unread[x].text + ''; + notifFrag.appendChild(notifEl.cloneNode(true)); + } + for(x=0;x' + utils.relativeTime(data.read[x].datetime, true) + '' + data.read[x].text + ''; + notifFrag.appendChild(notifEl.cloneNode(true)); + } + } else { + notifEl.innerHTML = 'You have no notifications'; + notifFrag.appendChild(notifEl); + } + notifList.appendChild(notifFrag); + + if (data.unread.length > 0) notifIcon.className = 'icon-circle active'; + else notifIcon.className = 'icon-circle-blank'; + + socket.emit('api:notifications.mark_all_read', null, function() { + notifIcon.className = 'icon-circle-blank'; + utils.refreshTitle(); + }); }); } }); @@ -115,35 +144,6 @@ if (nid > 0) socket.emit('api:notifications.mark_read', nid); } }); - socket.on('api:notifications.get', function(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) { - for(x=0;x' + utils.relativeTime(data.unread[x].datetime, true) + '' + data.unread[x].text + ''; - notifFrag.appendChild(notifEl.cloneNode(true)); - } - for(x=0;x' + utils.relativeTime(data.read[x].datetime, true) + '' + data.read[x].text + ''; - notifFrag.appendChild(notifEl.cloneNode(true)); - } - } else { - notifEl.innerHTML = 'You have no notifications'; - notifFrag.appendChild(notifEl); - } - notifList.appendChild(notifFrag); - - if (data.unread.length > 0) notifIcon.className = 'icon-circle active'; - else notifIcon.className = 'icon-circle-blank'; - }); socket.on('event:new_notification', function() { document.querySelector('.notifications a i').className = 'icon-circle active'; app.alert({ @@ -160,12 +160,12 @@ var username = data.username; var fromuid = data.fromuid; var message = data.message; - + require(['chat'], function(chat) { var chatModal = chat.createModalIfDoesntExist(username, fromuid); chatModal.show(); chat.bringModalToTop(chatModal); - + chat.appendChatMessage(chatModal, message); }); }); diff --git a/src/websockets.js b/src/websockets.js index 72940c11eb..c2604eff14 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -484,9 +484,9 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), postTools.restore(uid, data.pid); }); - socket.on('api:notifications.get', function(data) { + socket.on('api:notifications.get', function(data, callback) { user.notifications.get(uid, function(notifs) { - socket.emit('api:notifications.get', notifs); + callback(notifs); }); });