Node.js based forum software built for the modern web
potential fix for duplicate chat results, started recent replies block
psychobunny55cb790d3c89
diff --git a/public/templates/category.tpl b/public/templates/category.tplindex 40ee2654a9..464aa5d4e4 100644--- a/public/templates/category.tpl+++ b/public/templates/category.tpl@@ -126,5 +126,13 @@// jQuery('<div></div>').appendTo("#topics-container").hide().append(html).fadeIn('slow');// set_up_posts(uniqueid);});++++ //socket.emit('api:topics.getRecentReplies', tid);+ socket.on('api:topics.getRecentReplies', function(replies) {+ console.log(replies);+ });+})();</script>\ No newline at end of filediff --git a/public/templates/topic.tpl b/public/templates/topic.tplindex c2611a59ee..5d9b8f17c5 100644--- a/public/templates/topic.tpl+++ b/public/templates/topic.tpl@@ -398,7 +398,7 @@'event:topic_deleted', 'event:topic_restored', 'event:topic:locked','event:topic_unlocked', 'event:topic_pinned', 'event:topic_unpinned','event:topic_moved', 'event:post_edited', 'event:post_deleted', 'event:post_restored',- 'api:posts.favourite'+ 'api:posts.favourite', 'chatMessage']);diff --git a/src/posts.js b/src/posts.jsindex 59bf61a568..e8de7135de 100644--- a/src/posts.js+++ b/src/posts.js@@ -140,6 +140,8 @@ marked.setOptions({RDB.del('cid:' + cid + ':read_by_uid');});+ RDB.zadd('topics:recent_posts:tid:' + tid, (new Date()).getTime(), pid);+// Re-add the poster, so he/she does not get an "unread" flag on this topictopics.markAsRead(tid, uid);// this will duplicate once we enter the thread, which is where we should be goingdiff --git a/src/topics.js b/src/topics.jsindex 43dc651053..422b1e7a49 100644--- a/src/topics.js+++ b/src/topics.js@@ -274,6 +274,12 @@ marked.setOptions({});}+ Topics.getRecentReplies = function(tid, callback) {+ RDB.zrange('topics:recent_posts:tid:' + tid, 0, -1, 'WITHSCORES', function(err, replies) {+ callback(replies);+ });+ }+Topics.post = function(socket, uid, title, content, category_id) {if (!category_id) throw new Error('Attempted to post without a category_id');diff --git a/src/websockets.js b/src/websockets.jsindex 5db88cb5e8..0a3c15d826 100644--- a/src/websockets.js+++ b/src/websockets.js@@ -263,6 +263,13 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),notifications.mark_read(nid, uid);});+ socket.on('api:topics.getRecentReplies', function(tid) {+ console.log('test');+ topics.getRecentReplies(tid, function(replies) {+ socket.emit('api:topics.getRecentReplies', replies);+ });+ });+socket.on('sendChatMessage', function(data) {var touid = data.touid;