v1.18.x
barisusakli 10 years ago
parent ca9cc6b32f
commit 4c90c9a759

@ -16,7 +16,6 @@ define('forum/topic/browsing', function() {
}
updateUserCount(data.total);
getReplyingUsers();
}
};
@ -93,17 +92,6 @@ define('forum/topic/browsing', function() {
}
}
function getReplyingUsers() {
var activeEl = $('.thread_active_users');
socket.emit('modules.composer.getUsersByTid', ajaxify.variables.get('topic_id'), function(err, uids) {
if (uids && uids.length) {
for(var x=0;x<uids.length;x++) {
activeEl.find('[data-uid="' + uids[x] + '"]').addClass('replying');
}
}
});
}
function updateUserCount(count) {
count = parseInt(count, 10);
if (!count || count < 0) {

@ -40,7 +40,8 @@ define('forum/topic/events', ['forum/topic/browsing', 'forum/topic/postTools', '
'posts.downvote': togglePostVote,
'posts.unvote': togglePostVote,
'event:topic.toggleReply': toggleReply,
'event:topic.notifyTyping': onNotifyTyping,
'event:topic.stopNotifyTyping': onStopNotifyTyping
};
Events.init = function() {
@ -168,8 +169,23 @@ define('forum/topic/events', ['forum/topic/browsing', 'forum/topic/postTools', '
post.find('.downvote').toggleClass('btn-primary downvoted', data.downvote);
}
function toggleReply(data) {
$('.thread_active_users [data-uid="' + data.uid + '"]').toggleClass('replying', data.isReplying);
function onNotifyTyping(data) {
var userEl = $('.thread_active_users [data-uid="' + data.uid + '"]');
userEl.addClass('replying');
var timeoutId = userEl.attr('timeoutId');
if (timeoutId) {
clearTimeout(timeoutId);
timeoutId = 0;
}
timeoutId = setTimeout(function() {
userEl.removeClass('replying');
}, 7000);
userEl.attr('timeoutId', timeoutId);
}
function onStopNotifyTyping(data) {
$('.thread_active_users [data-uid="' + data.uid + '"]').removeClass('replying');
}
return Events;

@ -21,12 +21,6 @@ define('composer', dependencies, function(taskbar, controls, uploads, formatting
bsEnvironment: undefined
};
socket.on('event:composer.ping', function(post_uuid) {
if (composer.active === post_uuid) {
socket.emit('modules.composer.pingActive', post_uuid);
}
});
$(window).off('resize', onWindowResize).on('resize', onWindowResize);
function onWindowResize() {
@ -182,15 +176,36 @@ define('composer', dependencies, function(taskbar, controls, uploads, formatting
createNewComposer(post_uuid);
}
var postData = composer.posts[post_uuid];
if (postData.tid) {
socket.emit('modules.composer.register', {
uuid: post_uuid,
startNotifyTyping(composer.posts[post_uuid]);
};
function startNotifyTyping(postData) {
function emit() {
socket.emit('modules.composer.notifyTyping', {
tid: postData.tid,
uid: app.uid
});
}
};
stopNotifyInterval(postData);
emit();
postData.notifyTypingIntervalId = setInterval(emit, 5000);
}
function stopNotifyTyping(postData) {
socket.emit('modules.composer.stopNotifyTyping', {
tid: postData.tid,
uid: app.uid
});
}
function stopNotifyInterval(postData) {
if (postData.notifyTypingIntervalId) {
clearInterval(postData.notifyTypingIntervalId);
postData.notifyTypingIntervalId = 0;
}
}
function createNewComposer(post_uuid) {
var allowTopicsThumbnail = config.allowTopicsThumbnail && composer.posts[post_uuid].isMain && (config.hasImageUploadPlugin || config.allowFileUploads);
@ -456,6 +471,9 @@ define('composer', dependencies, function(taskbar, controls, uploads, formatting
if (composer.posts[post_uuid]) {
$('#cmp-uuid-' + post_uuid).remove();
drafts.removeDraft(composer.posts[post_uuid].save_id);
stopNotifyInterval(composer.posts[post_uuid]);
stopNotifyTyping(composer.posts[post_uuid]);
delete composer.posts[post_uuid];
composer.active = undefined;
taskbar.discard('composer', post_uuid);
@ -463,7 +481,6 @@ define('composer', dependencies, function(taskbar, controls, uploads, formatting
$('.action-bar button').removeAttr('disabled');
app.toggleNavbar(true);
socket.emit('modules.composer.unregister', post_uuid);
}
}
@ -473,7 +490,8 @@ define('composer', dependencies, function(taskbar, controls, uploads, formatting
composer.active = undefined;
taskbar.minimize('composer', post_uuid);
socket.emit('modules.composer.unregister', post_uuid);
stopNotifyInterval(composer.posts[post_uuid]);
stopNotifyTyping(composer.posts[post_uuid]);
};
return composer;

@ -18,9 +18,7 @@ var posts = require('../posts'),
nconf = require('nconf'),
SocketModules = {
composer: {
replyHash: {}
},
composer: {},
chats: {},
notifications: {},
sounds: {},
@ -29,27 +27,6 @@ var posts = require('../posts'),
/* Posts Composer */
var stopTracking = function(replyObj) {
if (isLast(replyObj.uid, replyObj.tid)) {
server.in('topic_' + replyObj.tid).emit('event:topic.toggleReply', {uid: replyObj.uid, isReplying: false});
}
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) {
posts.getPostFields(pid, ['content', 'tid'], function(err, postData) {
if(err || (!postData && !postData.content)) {
@ -115,48 +92,12 @@ SocketModules.composer.renderHelp = function(socket, data, callback) {
});
};
SocketModules.composer.register = function(socket, data) {
var now = Date.now();
server.in('topic_' + data.tid).emit('event:topic.toggleReply', {uid: data.uid, isReplying: true});
data.socket = socket;
data.lastPing = now;
data.lastAnswer = now;
data.timer = setInterval(function() {
if (data.lastPing === data.lastAnswer) {
// Ping the socket to see if the composer is still active
data.lastPing = Date.now();
socket.emit('event:composer.ping', data.uuid);
} else {
stopTracking(data);
}
}, 1000*5); // Every 5 seconds...
SocketModules.composer.replyHash[data.uuid] = data;
};
SocketModules.composer.unregister = function(socket, uuid) {
var replyObj = SocketModules.composer.replyHash[uuid];
if (uuid && replyObj) {
stopTracking(replyObj);
}
};
SocketModules.composer.pingActive = function(socket, uuid) {
var data = SocketModules.composer.replyHash[uuid];
if (data) {
data.lastAnswer = data.lastPing;
}
SocketModules.composer.notifyTyping = function(socket, data) {
server.in('topic_' + data.tid).emit('event:topic.notifyTyping', data);
};
SocketModules.composer.getUsersByTid = function(socket, tid, callback) {
// Return uids with active composers
callback(null, _.filter(SocketModules.composer.replyHash, function(replyObj, uuid) {
return parseInt(replyObj.tid, 10) === parseInt(tid, 10);
}).map(function(replyObj) {
return replyObj.uid;
}));
SocketModules.composer.stopNotifyTyping = function(socket, data) {
server.in('topic_' + data.tid).emit('event:topic.stopNotifyTyping', data);
};
/* Chat */

Loading…
Cancel
Save