Merge pull request #3460 from thelounge/xpaw/history-reconnect
Fix history not loading in certain cases after reconnect
This commit is contained in:
commit
00e59000fd
@ -228,6 +228,10 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
onShowMoreClick() {
|
onShowMoreClick() {
|
||||||
|
if (!this.$root.isConnected) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let lastMessage = this.channel.messages[0];
|
let lastMessage = this.channel.messages[0];
|
||||||
lastMessage = lastMessage ? lastMessage.id : -1;
|
lastMessage = lastMessage ? lastMessage.id : -1;
|
||||||
|
|
||||||
|
@ -178,6 +178,15 @@ function mergeChannelData(oldChannels, newChannels) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Server sends total count of messages in memory, we compare it to amount of messages
|
||||||
|
// on the client, and decide whether theres more messages to load from server
|
||||||
|
if (key === "totalMessages") {
|
||||||
|
currentChannel.moreHistoryAvailable =
|
||||||
|
channel.totalMessages > currentChannel.messages.length;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Reconnection only sends new messages, so merge it on the client
|
// Reconnection only sends new messages, so merge it on the client
|
||||||
// Only concat if server sent us less than 100 messages so we don't introduce gaps
|
// Only concat if server sent us less than 100 messages so we don't introduce gaps
|
||||||
if (key === "messages" && currentChannel.messages && channel.messages.length < 100) {
|
if (key === "messages" && currentChannel.messages && channel.messages.length < 100) {
|
||||||
|
@ -10,7 +10,8 @@ socket.on("more", function(data) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.channel.moreHistoryAvailable = data.moreHistoryAvailable;
|
channel.channel.moreHistoryAvailable =
|
||||||
|
data.totalMessages > channel.channel.messages.length + data.messages.length;
|
||||||
channel.channel.messages.unshift(...data.messages);
|
channel.channel.messages.unshift(...data.messages);
|
||||||
|
|
||||||
vueApp.$nextTick(() => {
|
vueApp.$nextTick(() => {
|
||||||
|
@ -78,6 +78,9 @@ function initChannel(channel) {
|
|||||||
channel.scrolledToBottom = true;
|
channel.scrolledToBottom = true;
|
||||||
channel.editTopic = false;
|
channel.editTopic = false;
|
||||||
|
|
||||||
|
channel.moreHistoryAvailable = channel.totalMessages > channel.messages.length;
|
||||||
|
delete channel.totalMessages;
|
||||||
|
|
||||||
if (channel.type === "channel") {
|
if (channel.type === "channel") {
|
||||||
channel.usersOutdated = true;
|
channel.usersOutdated = true;
|
||||||
}
|
}
|
||||||
|
@ -448,7 +448,7 @@ Client.prototype.more = function(data) {
|
|||||||
return {
|
return {
|
||||||
chan: chan.id,
|
chan: chan.id,
|
||||||
messages: messages,
|
messages: messages,
|
||||||
moreHistoryAvailable: index > 100,
|
totalMessages: chan.messages.length,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -177,7 +177,6 @@ Chan.prototype.getFilteredClone = function(lastActiveChannel, lastMessage) {
|
|||||||
// When reconnecting, always send up to 100 messages to prevent message gaps on the client
|
// When reconnecting, always send up to 100 messages to prevent message gaps on the client
|
||||||
// See https://github.com/thelounge/thelounge/issues/1883
|
// See https://github.com/thelounge/thelounge/issues/1883
|
||||||
newChannel[prop] = this[prop].filter((m) => m.id > lastMessage).slice(-100);
|
newChannel[prop] = this[prop].filter((m) => m.id > lastMessage).slice(-100);
|
||||||
newChannel.moreHistoryAvailable = this[prop].length > 100;
|
|
||||||
} else {
|
} else {
|
||||||
// If channel is active, send up to 100 last messages, for all others send just 1
|
// 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
|
// Client will automatically load more messages whenever needed based on last seen messages
|
||||||
@ -185,8 +184,9 @@ Chan.prototype.getFilteredClone = function(lastActiveChannel, lastMessage) {
|
|||||||
lastActiveChannel === true || this.id === lastActiveChannel ? 100 : 1;
|
lastActiveChannel === true || this.id === lastActiveChannel ? 100 : 1;
|
||||||
|
|
||||||
newChannel[prop] = this[prop].slice(-messagesToSend);
|
newChannel[prop] = this[prop].slice(-messagesToSend);
|
||||||
newChannel.moreHistoryAvailable = this[prop].length > messagesToSend;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newChannel.totalMessages = this[prop].length;
|
||||||
} else {
|
} else {
|
||||||
newChannel[prop] = this[prop];
|
newChannel[prop] = this[prop];
|
||||||
}
|
}
|
||||||
@ -261,7 +261,7 @@ Chan.prototype.loadMessages = function(client, network) {
|
|||||||
client.emit("more", {
|
client.emit("more", {
|
||||||
chan: this.id,
|
chan: this.id,
|
||||||
messages: messages.slice(-100),
|
messages: messages.slice(-100),
|
||||||
moreHistoryAvailable: messages.length > 100,
|
totalMessages: messages.length,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (network.irc.network.cap.isEnabled("znc.in/playback")) {
|
if (network.irc.network.cap.isEnabled("znc.in/playback")) {
|
||||||
|
@ -213,7 +213,7 @@ describe("Chan", function() {
|
|||||||
"id",
|
"id",
|
||||||
"key",
|
"key",
|
||||||
"messages",
|
"messages",
|
||||||
"moreHistoryAvailable",
|
"totalMessages",
|
||||||
"name",
|
"name",
|
||||||
"state",
|
"state",
|
||||||
"topic",
|
"topic",
|
||||||
|
Loading…
Reference in New Issue
Block a user