From 36942125e629ae633e3e268a1cf708910e88a702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 25 Mar 2015 15:51:11 -0400 Subject: [PATCH] closes #2894 also mark user online if they post a reply --- public/src/client/topic/posts.js | 31 ++++++++++++++++++++++++++++--- src/socket.io/posts.js | 2 ++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.js index c2ea3940ff..85dfbbb6bb 100644 --- a/public/src/client/topic/posts.js +++ b/public/src/client/topic/posts.js @@ -56,9 +56,34 @@ define('forum/topic/posts', [ } function removeAlreadyAddedPosts() { - data.posts = data.posts.filter(function(post) { - return components.get('post', 'pid', post.pid).length === 0; - }); + var newPosts = components.get('topic').find('[data-index][data-index!="0"].new'); + + if (newPosts.length === data.posts.length) { + var allSamePids = true; + newPosts.each(function(index, el) { + if (parseInt($(el).attr('data-pid'), 10) !== parseInt(data.posts[index].pid, 10)) { + allSamePids = false; + } + }); + + if (allSamePids) { + newPosts.each(function() { + $(this).removeClass('new'); + }); + data.posts.length = 0; + return; + } + } + + if (data.posts.length > 1) { + data.posts.forEach(function(post) { + components.get('post', 'pid', post.pid).remove(); + }); + } else { + data.posts = data.posts.filter(function(post) { + return components.get('post', 'pid', post.pid).length === 0; + }); + } } var after = null, diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index 94f6be7a37..2fdf4425b5 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -49,6 +49,8 @@ SocketPosts.reply = function(socket, data, callback) { socket.emit('event:new_post', result); + user.updateOnlineUsers(socket.uid); + SocketPosts.notifyOnlineUsers(socket.uid, result); if (data.lock) {