Merge pull request #1884 from thelounge/xpaw/fix-1883

Fix #1883: message gaps when reconnecting
This commit is contained in:
Jérémie Astori 2017-12-23 13:10:17 -05:00 committed by GitHub
commit 0cbe0cb24e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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 {