proper tracking of users' reply status when others enter the room

v1.18.x
Julian Lam 11 years ago
parent a9b78d2600
commit 2b178ff76d

@ -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<uids.length;x++) {
activeUsersEl.find('[data-uid="' + uids[x] + '"]').addClass('replying');
}
}
});
}
app.populateOnlineUsers();
@ -896,7 +906,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
votes.html(currentVotes).attr('data-votes', currentVotes);
reputationElements.html(reputation).attr('data-reputation', reputation);
}
};
function adjust_favourites(value, pid, uid) {
var favourites = $('li[data-pid="' + pid + '"] .favouriteCount'),
@ -905,7 +915,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
currentFavourites += value;
favourites.html(currentFavourites).attr('data-favourites', currentFavourites);
}
};
function set_follow_state(state, alert) {
@ -920,7 +930,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
type: 'success'
});
}
}
};
function set_locked_state(locked, alert) {
translator.translate('<i class="fa fa-fw fa-' + (locked ? 'un': '') + 'lock"></i> [[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('<i class="fa fa-fw fa-thumb-tack"></i> [[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');

@ -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 = {};

Loading…
Cancel
Save