diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 4ebfb4aae7..6caea47b10 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -618,7 +618,6 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { ]); socket.on('get_users_in_room', function(data) { - if(data && data.room.indexOf('topic') !== -1) { var activeEl = $('li.post-bar[data-index="0"] .thread_active_users'); @@ -696,6 +695,17 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { title: title }); } + + // Get users who are currently replying to the topic entered + socket.emit('modules.composer.getUsersByTid', templates.get('topic_id'), function(err, uids) { + var activeUsersEl = $('.thread_active_users'), + x; + if (uids && uids.length) { + for(var x=0;x [[topic:thread_tools.' + (locked ? 'un': '') + 'lock]]', function(translated) { @@ -943,7 +953,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { } thread_state.locked = locked ? '1' : '0'; - } + }; function set_delete_state(deleted) { var threadEl = $('#post-container'); @@ -960,7 +970,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { } else { $('#thread-deleted').remove(); } - } + }; function set_pinned_state(pinned, alert) { translator.translate(' [[topic:thread_tools.' + (pinned ? 'unpin' : 'pin') + ']]', function(translated) { @@ -977,7 +987,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { } thread_state.pinned = pinned ? '1' : '0'; }); - } + }; function toggle_post_delete_state(pid) { var postEl = $('#post-container li[data-pid="' + pid + '"]'); @@ -989,7 +999,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { updatePostCount(); } - } + }; function toggle_post_tools(pid, isDeleted) { var postEl = $('#post-container li[data-pid="' + pid + '"]'); @@ -999,7 +1009,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { translator.translate(isDeleted ? ' [[topic:restore]]' : ' [[topic:delete]]', function(translated) { postEl.find('.delete').find('span').html(translated); }); - } + }; $(window).on('scroll', updateHeader); $(window).trigger('action:topic.loaded'); diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js index 8566e65786..d931185135 100644 --- a/src/socket.io/modules.js +++ b/src/socket.io/modules.js @@ -12,6 +12,7 @@ var posts = require('../posts'), async = require('async'), S = require('string'), winston = require('winston'), + _ = require('underscore'), server = require('./'), SocketModules = {}; @@ -22,6 +23,27 @@ SocketModules.composer = { replyHash: {} }; +var stopTracking = function(replyObj) { + if (isLast(replyObj.uid, replyObj.tid)) { + server.in('topic_' + replyObj.tid).emit('event:topic.replyStop', replyObj.uid); + } + + clearInterval(replyObj.timer); + delete SocketModules.composer.replyHash[replyObj.uuid]; + }, + isLast = function(uid, tid) { + return _.filter(SocketModules.composer.replyHash, function(replyObj, uuid) { + if ( + parseInt(replyObj.tid, 10) === parseInt(tid, 10) && + parseInt(replyObj.uid, 10) === parseInt(uid, 10) + ) { + return true; + } else { + return false; + } + }).length === 1; + }; + SocketModules.composer.push = function(socket, pid, callback) { if (socket.uid || parseInt(meta.config.allowGuestPosting, 10)) { if (parseInt(pid, 10) > 0) { @@ -90,8 +112,7 @@ SocketModules.composer.register = function(socket, data) { data.lastPing = Date.now(); socket.emit('event:composer.ping', data.uuid); } else { - server.in('topic_' + data.tid).emit('event:topic.replyStop', data.uid); - delete SocketModules.composer.replyHash[data.uuid]; + stopTracking(data); } }, 1000*5); // Every 5 seconds... @@ -101,9 +122,7 @@ SocketModules.composer.register = function(socket, data) { SocketModules.composer.unregister = function(socket, uuid) { var replyObj = SocketModules.composer.replyHash[uuid]; if (uuid && replyObj) { - server.in('topic_' + replyObj.tid).emit('event:topic.replyStop', replyObj.uid); - clearInterval(replyObj.timer); - delete SocketModules.composer.replyHash[replyObj.uuid]; + stopTracking(replyObj); } }; @@ -114,6 +133,20 @@ SocketModules.composer.pingActive = function(socket, uuid) { } }; +SocketModules.composer.getUsersByTid = function(socket, tid, callback) { + // Return uids with active composers + console.log(tid); + callback(null, _.filter(SocketModules.composer.replyHash, function(replyObj, uuid) { + if (parseInt(replyObj.tid, 10) === parseInt(tid, 10)) { + return true; + } else { + return false; + } + }).map(function(replyObj) { + return replyObj.uid + })); +} + /* Chat */ SocketModules.chats = {};