From f47d93af8a766dda239716aed77a1db3d3288b88 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 11 Feb 2022 21:02:34 +0100 Subject: [PATCH] Don't fetch backlog before read receipt --- components/app.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/app.js b/components/app.js index 15efbe1..548c90c 100644 --- a/components/app.js +++ b/components/app.js @@ -879,11 +879,19 @@ export default class App extends Component { switch (msg.command) { case irc.RPL_WELCOME: let lastReceipt = getLatestReceipt(this.bufferStore, client.params, ReceiptType.DELIVERED); - if (lastReceipt && lastReceipt.time && client.caps.enabled.has("draft/chathistory") && (!client.caps.enabled.has("soju.im/bouncer-networks") || client.params.bouncerNetwork)) { + if (lastReceipt && client.caps.enabled.has("draft/chathistory") && (!client.caps.enabled.has("soju.im/bouncer-networks") || client.params.bouncerNetwork)) { let now = irc.formatDate(new Date()); client.fetchHistoryTargets(now, lastReceipt.time).then((targets) => { targets.forEach((target) => { + // 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 (readReceipt && readReceipt.time > from.time) { + from = readReceipt; + } + let to = { time: msg.tags.time || now }; this.fetchBacklog(client, target.name, from, to); });