mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 18:16:17 +01:00
proper tracking of users' reply status when others enter the room
This commit is contained in:
@@ -618,7 +618,6 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
socket.on('get_users_in_room', function(data) {
|
socket.on('get_users_in_room', function(data) {
|
||||||
|
|
||||||
if(data && data.room.indexOf('topic') !== -1) {
|
if(data && data.room.indexOf('topic') !== -1) {
|
||||||
var activeEl = $('li.post-bar[data-index="0"] .thread_active_users');
|
var activeEl = $('li.post-bar[data-index="0"] .thread_active_users');
|
||||||
|
|
||||||
@@ -696,6 +695,17 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
title: title
|
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();
|
app.populateOnlineUsers();
|
||||||
@@ -896,7 +906,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
|
|
||||||
votes.html(currentVotes).attr('data-votes', currentVotes);
|
votes.html(currentVotes).attr('data-votes', currentVotes);
|
||||||
reputationElements.html(reputation).attr('data-reputation', reputation);
|
reputationElements.html(reputation).attr('data-reputation', reputation);
|
||||||
}
|
};
|
||||||
|
|
||||||
function adjust_favourites(value, pid, uid) {
|
function adjust_favourites(value, pid, uid) {
|
||||||
var favourites = $('li[data-pid="' + pid + '"] .favouriteCount'),
|
var favourites = $('li[data-pid="' + pid + '"] .favouriteCount'),
|
||||||
@@ -905,7 +915,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
currentFavourites += value;
|
currentFavourites += value;
|
||||||
|
|
||||||
favourites.html(currentFavourites).attr('data-favourites', currentFavourites);
|
favourites.html(currentFavourites).attr('data-favourites', currentFavourites);
|
||||||
}
|
};
|
||||||
|
|
||||||
function set_follow_state(state, alert) {
|
function set_follow_state(state, alert) {
|
||||||
|
|
||||||
@@ -920,7 +930,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
type: 'success'
|
type: 'success'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function set_locked_state(locked, alert) {
|
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) {
|
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';
|
thread_state.locked = locked ? '1' : '0';
|
||||||
}
|
};
|
||||||
|
|
||||||
function set_delete_state(deleted) {
|
function set_delete_state(deleted) {
|
||||||
var threadEl = $('#post-container');
|
var threadEl = $('#post-container');
|
||||||
@@ -960,7 +970,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
} else {
|
} else {
|
||||||
$('#thread-deleted').remove();
|
$('#thread-deleted').remove();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function set_pinned_state(pinned, alert) {
|
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) {
|
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';
|
thread_state.pinned = pinned ? '1' : '0';
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
function toggle_post_delete_state(pid) {
|
function toggle_post_delete_state(pid) {
|
||||||
var postEl = $('#post-container li[data-pid="' + pid + '"]');
|
var postEl = $('#post-container li[data-pid="' + pid + '"]');
|
||||||
@@ -989,7 +999,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
|
|
||||||
updatePostCount();
|
updatePostCount();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function toggle_post_tools(pid, isDeleted) {
|
function toggle_post_tools(pid, isDeleted) {
|
||||||
var postEl = $('#post-container li[data-pid="' + pid + '"]');
|
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) {
|
translator.translate(isDeleted ? ' [[topic:restore]]' : ' [[topic:delete]]', function(translated) {
|
||||||
postEl.find('.delete').find('span').html(translated);
|
postEl.find('.delete').find('span').html(translated);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
$(window).on('scroll', updateHeader);
|
$(window).on('scroll', updateHeader);
|
||||||
$(window).trigger('action:topic.loaded');
|
$(window).trigger('action:topic.loaded');
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ var posts = require('../posts'),
|
|||||||
async = require('async'),
|
async = require('async'),
|
||||||
S = require('string'),
|
S = require('string'),
|
||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
|
_ = require('underscore'),
|
||||||
server = require('./'),
|
server = require('./'),
|
||||||
|
|
||||||
SocketModules = {};
|
SocketModules = {};
|
||||||
@@ -22,6 +23,27 @@ SocketModules.composer = {
|
|||||||
replyHash: {}
|
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) {
|
SocketModules.composer.push = function(socket, pid, callback) {
|
||||||
if (socket.uid || parseInt(meta.config.allowGuestPosting, 10)) {
|
if (socket.uid || parseInt(meta.config.allowGuestPosting, 10)) {
|
||||||
if (parseInt(pid, 10) > 0) {
|
if (parseInt(pid, 10) > 0) {
|
||||||
@@ -90,8 +112,7 @@ SocketModules.composer.register = function(socket, data) {
|
|||||||
data.lastPing = Date.now();
|
data.lastPing = Date.now();
|
||||||
socket.emit('event:composer.ping', data.uuid);
|
socket.emit('event:composer.ping', data.uuid);
|
||||||
} else {
|
} else {
|
||||||
server.in('topic_' + data.tid).emit('event:topic.replyStop', data.uid);
|
stopTracking(data);
|
||||||
delete SocketModules.composer.replyHash[data.uuid];
|
|
||||||
}
|
}
|
||||||
}, 1000*5); // Every 5 seconds...
|
}, 1000*5); // Every 5 seconds...
|
||||||
|
|
||||||
@@ -101,9 +122,7 @@ SocketModules.composer.register = function(socket, data) {
|
|||||||
SocketModules.composer.unregister = function(socket, uuid) {
|
SocketModules.composer.unregister = function(socket, uuid) {
|
||||||
var replyObj = SocketModules.composer.replyHash[uuid];
|
var replyObj = SocketModules.composer.replyHash[uuid];
|
||||||
if (uuid && replyObj) {
|
if (uuid && replyObj) {
|
||||||
server.in('topic_' + replyObj.tid).emit('event:topic.replyStop', replyObj.uid);
|
stopTracking(replyObj);
|
||||||
clearInterval(replyObj.timer);
|
|
||||||
delete SocketModules.composer.replyHash[replyObj.uuid];
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -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 */
|
/* Chat */
|
||||||
|
|
||||||
SocketModules.chats = {};
|
SocketModules.chats = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user