Skip to content

Node.js based forum software built for the modern web

showing who is replying in the active users block

Julian Lamb3d7ae1c861a
diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js
index 9a86aaec32..4ebfb4aae7 100644
--- a/public/src/forum/topic.js
+++ b/public/src/forum/topic.js
@@ -613,7 +613,8 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
'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',
- 'posts.favourite', 'user.isOnline', 'posts.upvote', 'posts.downvote'
+ 'posts.favourite', 'user.isOnline', 'posts.upvote', 'posts.downvote',
+ 'event:topic.replyStart', 'event:topic.replyStop'
]);
socket.on('get_users_in_room', function(data) {
@@ -876,6 +877,14 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
}
});
+ socket.on('event:topic.replyStart', function(uid) {
+ $('.thread_active_users [data-uid="' + uid + '"]').addClass('replying');
+ });
+
+ socket.on('event:topic.replyStop', function(uid) {
+ $('.thread_active_users [data-uid="' + uid + '"]').removeClass('replying');
+ });
+
function adjust_rep(value, pid, uid) {
var votes = $('li[data-pid="' + pid + '"] .votes'),
reputationElements = $('.reputation[data-uid="' + uid + '"]'),
diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js
index 55a0b1450b..0c4f3193ad 100644
--- a/public/src/modules/composer.js
+++ b/public/src/modules/composer.js
@@ -4,6 +4,15 @@ define(['taskbar'], function(taskbar) {
posts: {}
};
+ function initialise() {
+ socket.on('event:composer.ping', function(post_uuid) {
+ if (composer.active !== post_uuid) {
+ socket.emit('modules.composer.pingInactive', post_uuid);
+ }
+ });
+ };
+ initialise();
+
function maybeParse(response) {
if (typeof response == 'string') {
try {
@@ -380,6 +389,16 @@ define(['taskbar'], function(taskbar) {
} else {
composer.createNewComposer(post_uuid);
}
+
+ var tid = templates.get('topic_id');
+ if (tid) {
+ // Replying to a topic
+ socket.emit('modules.composer.register', {
+ uuid: post_uuid,
+ tid: templates.get('topic_id'),
+ uid: app.uid
+ });
+ }
};
composer.createNewComposer = function(post_uuid) {
diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js
index a9d9d659be..817cca5096 100644
--- a/src/socket.io/modules.js
+++ b/src/socket.io/modules.js
@@ -18,7 +18,9 @@ var posts = require('../posts'),
/* Posts Composer */
-SocketModules.composer = {};
+SocketModules.composer = {
+ replyHash: {}
+};
SocketModules.composer.push = function(socket, pid, callback) {
if (socket.uid || parseInt(meta.config.allowGuestPosting, 10)) {
@@ -74,6 +76,27 @@ SocketModules.composer.renderHelp = function(socket, data, callback) {
plugins.fireHook('filter:composer.help', '', callback);
};
+SocketModules.composer.register = function(socket, data) {
+ server.in('topic_' + data.tid).emit('event:topic.replyStart', data.uid);
+
+ data.socket = socket;
+ data.timer = setInterval(function() {
+ // Ping the socket to see if the composer is still active
+ socket.emit('event:composer.ping', data.uuid);
+ }, 1000*10); // Every 10 seconds...
+
+ SocketModules.composer.replyHash[data.uuid] = data;
+};
+
+SocketModules.composer.pingInactive = function(socket, uuid) {
+ var data = SocketModules.composer.replyHash[uuid];
+ if (SocketModules.composer.replyHash[uuid]) {
+ server.in('topic_' + data.tid).emit('event:topic.replyStop', data.uid);
+ clearInterval(data.timer);
+ delete SocketModules.composer.replyHash[uuid];
+ }
+};
+
/* Chat */
SocketModules.chats = {};