Only emit "more" history to the client that requested it

This commit is contained in:
Pavel Djundik 2018-01-07 15:04:37 +02:00
parent 011b086760
commit fc39a67e10
2 changed files with 8 additions and 4 deletions

View File

@ -396,7 +396,7 @@ Client.prototype.more = function(data) {
const target = client.find(data.target); const target = client.find(data.target);
if (!target) { if (!target) {
return; return null;
} }
const chan = target.chan; const chan = target.chan;
@ -415,10 +415,10 @@ Client.prototype.more = function(data) {
messages = chan.messages.slice(Math.max(0, index - 100), index); messages = chan.messages.slice(Math.max(0, index - 100), index);
} }
client.emit("more", { return {
chan: chan.id, chan: chan.id,
messages: messages, messages: messages,
}); };
}; };
Client.prototype.open = function(socketId, target) { Client.prototype.open = function(socketId, target) {

View File

@ -258,7 +258,11 @@ function initializeClient(socket, client, token, lastMessage) {
socket.on( socket.on(
"more", "more",
function(data) { function(data) {
client.more(data); const history = client.more(data);
if (history !== null) {
socket.emit("more", history);
}
} }
); );