mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 18:16:17 +01:00
closes #2291
This commit is contained in:
@@ -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.notifyTyping = function(socket, data) {
|
||||
server.in('topic_' + data.tid).emit('event:topic.notifyTyping', 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.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 */
|
||||
|
||||
Reference in New Issue
Block a user