Merge pull request #2859 from thelounge/xpaw/openChannel

Fix timing issue crashing on undefined when setting openChannel
This commit is contained in:
Jérémie Astori 2018-10-21 14:14:15 -04:00 committed by GitHub
commit 18f96934f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View file

@ -404,9 +404,14 @@ Client.prototype.more = function(data) {
};
Client.prototype.open = function(socketId, target) {
// Due to how socket.io works internally, normal events may arrive later than
// the disconnect event, and because we can't control this timing precisely,
// process this event normally even if there is no attached client anymore.
const attachedClient = this.attachedClients[socketId] || {};
// Opening a window like settings
if (target === null) {
this.attachedClients[socketId].openChannel = -1;
attachedClient.openChannel = -1;
return;
}
@ -420,7 +425,7 @@ Client.prototype.open = function(socketId, target) {
target.chan.unread = 0;
target.chan.highlight = 0;
this.attachedClients[socketId].openChannel = target.chan.id;
attachedClient.openChannel = target.chan.id;
this.lastActiveChannel = target.chan.id;
this.emit("open", target.chan.id);

View file

@ -295,7 +295,7 @@ function initializeClient(socket, client, token, lastMessage) {
}
socket.on("disconnect", function() {
client.clientDetach(socket.id);
process.nextTick(() => client.clientDetach(socket.id));
});
socket.on("input", (data) => {