From fc39a67e10eb17ffcf22ea79e0876333c957a0ce Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 7 Jan 2018 15:04:37 +0200 Subject: [PATCH] Only emit "more" history to the client that requested it --- src/client.js | 6 +++--- src/server.js | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/client.js b/src/client.js index fe602bce..eda7f194 100644 --- a/src/client.js +++ b/src/client.js @@ -396,7 +396,7 @@ Client.prototype.more = function(data) { const target = client.find(data.target); if (!target) { - return; + return null; } const chan = target.chan; @@ -415,10 +415,10 @@ Client.prototype.more = function(data) { messages = chan.messages.slice(Math.max(0, index - 100), index); } - client.emit("more", { + return { chan: chan.id, messages: messages, - }); + }; }; Client.prototype.open = function(socketId, target) { diff --git a/src/server.js b/src/server.js index beed5d34..6ec523ff 100644 --- a/src/server.js +++ b/src/server.js @@ -258,7 +258,11 @@ function initializeClient(socket, client, token, lastMessage) { socket.on( "more", function(data) { - client.more(data); + const history = client.more(data); + + if (history !== null) { + socket.emit("more", history); + } } );