From 6377e0de66877783c13fde3867284b7d083ea3c7 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sat, 23 Dec 2017 11:36:52 +0200 Subject: [PATCH] Fix #1883: message gaps when reconnecting --- src/models/chan.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/models/chan.js b/src/models/chan.js index dbcdcd98..f52364f4 100644 --- a/src/models/chan.js +++ b/src/models/chan.js @@ -151,16 +151,18 @@ Chan.prototype.getFilteredClone = function(lastActiveChannel, lastMessage) { // Do not send users, client requests updated user list whenever needed newChannel[prop] = []; } else if (prop === "messages") { - // If channel is active, send up to 100 last messages, for all others send just 1 - // Client will automatically load more messages whenever needed based on last seen messages - const messagesToSend = lastActiveChannel === true || this.id === lastActiveChannel ? -100 : -1; - // If client is reconnecting, only send new messages that client has not seen yet if (lastMessage > -1) { + // When reconnecting, always send up to 100 messages to prevent message gaps on the client + // See https://github.com/thelounge/lounge/issues/1883 newChannel[prop] = this[prop] .filter((m) => m.id > lastMessage) - .slice(messagesToSend); + .slice(-100); } else { + // If channel is active, send up to 100 last messages, for all others send just 1 + // Client will automatically load more messages whenever needed based on last seen messages + const messagesToSend = lastActiveChannel === true || this.id === lastActiveChannel ? -100 : -1; + newChannel[prop] = this[prop].slice(messagesToSend); } } else {