diff --git a/public/src/forum/recent.js b/public/src/forum/recent.js new file mode 100644 index 0000000000..9cc0c31208 --- /dev/null +++ b/public/src/forum/recent.js @@ -0,0 +1,50 @@ +(function() { + app.enter_room('recent_posts'); + + ajaxify.register_events([ + 'event:new_topic', + 'event:new_post' + ]); + + var newTopicCount = 0, newPostCount = 0; + + $('#new-topics-alert').on('click', function() { + $(this).hide(); + }); + + socket.on('event:new_topic', function(data) { + + ++newTopicCount; + updateAlertText(); + + }); + + function updateAlertText() { + var text = ''; + + if(newTopicCount > 1) + text = 'There are ' + newTopicCount + ' new topics'; + else if(newTopicCount === 1) + text = 'There is 1 new topic'; + else + text = 'There are no new topics'; + + if(newPostCount > 1) + text += ' and ' + newPostCount + ' new posts.'; + else if(newPostCount === 1) + text += ' and 1 new post.'; + else + text += ' and no new posts.'; + + text += ' Click here to reload.'; + + $('#new-topics-alert').html(text).fadeIn('slow'); + } + + socket.on('event:new_post', function(data) { + ++newPostCount; + updateAlertText(); + + }); + +})(); \ No newline at end of file diff --git a/public/templates/config.json b/public/templates/config.json index 9f998567ca..f84272d554 100644 --- a/public/templates/config.json +++ b/public/templates/config.json @@ -25,7 +25,7 @@ "users[^]*followers": "followers", "users/[^]*": "account", - "recent": "category", + "recent": "recent", "popular": "category", "active": "category" }, diff --git a/public/templates/recent.tpl b/public/templates/recent.tpl new file mode 100644 index 0000000000..6cb0beb1ec --- /dev/null +++ b/public/templates/recent.tpl @@ -0,0 +1,52 @@ +
+ +
+ + +
+ There are no topics in this category.
+ Why don't you try posting one? +
+ + +
+
+ + +
+
+ +
+
+ + \ No newline at end of file diff --git a/src/posts.js b/src/posts.js index 21851b965a..0136c729fc 100644 --- a/src/posts.js +++ b/src/posts.js @@ -207,8 +207,7 @@ marked.setOptions({ user.getUserFields(uid, ['username','reputation','picture','signature'], function(data) { var timestamp = Date.now(); - - io.sockets.in('topic_' + tid).emit('event:new_post', { + var socketData = { 'posts' : [ { 'pid' : pid, @@ -226,7 +225,11 @@ marked.setOptions({ 'editor': '', } ] - }); + }; + + io.sockets.in('topic_' + tid).emit('event:new_post', socketData); + io.sockets.in('recent_posts').emit('event:new_post', socketData); + }); } else { socket.emit('event:alert', { diff --git a/src/topics.js b/src/topics.js index 5c87fa95d4..341d9d2c02 100644 --- a/src/topics.js +++ b/src/topics.js @@ -366,6 +366,7 @@ marked.setOptions({ // Notify any users looking at the category that a new topic has arrived Topics.get_topic(tid, uid, function(topicData) { io.sockets.in('category_' + category_id).emit('event:new_topic', topicData); + io.sockets.in('recent_posts').emit('event:new_topic', topicData); }); } });