Fix #1883: message gaps when reconnecting

This commit is contained in:
Pavel Djundik 2017-12-23 11:36:52 +02:00
parent 5490235f4d
commit 6377e0de66

View File

@ -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 {