From 32257c9b2f35334837404dd69d575e2d08fb634c Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 16 Sep 2014 11:06:10 -0400 Subject: [PATCH] updateUnreadCount --- public/src/forum/footer.js | 16 ++++++++++++++++ src/socket.io/posts.js | 3 +-- src/socket.io/topics.js | 5 ++--- src/topics/unread.js | 36 ++++++++---------------------------- src/user.js | 4 ++-- 5 files changed, 29 insertions(+), 35 deletions(-) diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js index e7e8209a1b..c983e0a834 100644 --- a/public/src/forum/footer.js +++ b/public/src/forum/footer.js @@ -24,6 +24,22 @@ define('forum/footer', ['notifications', 'chat'], function(Notifications, Chat) .attr('data-content', count > 20 ? '20+' : count); } + function onNewPost(data) { + if (data && data.posts && data.posts.length) { + var post = data.posts[0]; + if (parseInt(post.uid, 10) !== parseInt(app.uid, 10)) { + increaseUnreadCount(); + } + } + } + + function increaseUnreadCount() { + var count = parseInt($('#unread-count').attr('data-content'), 10) + 1; + updateUnreadTopicCount(null, count); + } + + + socket.on('event:new_post', onNewPost); socket.on('event:unread.updateCount', updateUnreadTopicCount); socket.emit('user.getUnreadCount', updateUnreadTopicCount); diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index 582e3fa7c9..e7d5e330d3 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -51,14 +51,13 @@ SocketPosts.reply = function(socket, data, callback) { return; } for(var i=0; i