From 962c05c06621c9963e353d3fdfcc82e9ee23530b Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sun, 13 Feb 2022 15:20:21 +0100 Subject: [PATCH] Prevent hole in history when reconnecting --- components/app.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/components/app.js b/components/app.js index d26ba94..8883485 100644 --- a/components/app.js +++ b/components/app.js @@ -870,15 +870,24 @@ export default class App extends Component { let now = irc.formatDate(new Date()); client.fetchHistoryTargets(now, lastReceipt.time).then((targets) => { targets.forEach((target) => { + let from = lastReceipt; + // Maybe we've just received a READ update from the // server, avoid over-fetching history - let from = lastReceipt; let stored = this.bufferStore.get({ name: target.name, server: client.params }); let readReceipt = getReceipt(stored, ReceiptType.READ); if (isReceiptBefore(from, readReceipt)) { from = readReceipt; } + // If we already have messages stored for the target, + // fetch all messages we've missed + let buf = State.getBuffer(this.state, { server: serverID, name: target.name }); + if (buf && buf.messages.length > 0) { + let lastMsg = buf.messages[buf.messages.length - 1]; + from = receiptFromMessage(lastMsg); + } + let to = { time: msg.tags.time || now }; this.fetchBacklog(client, target.name, from, to); });