Prevent hole in history when reconnecting

This commit is contained in:
Simon Ser 2022-02-13 15:20:21 +01:00
parent f2c9fd1d7f
commit 962c05c066

View file

@ -870,15 +870,24 @@ export default class App extends Component {
let now = irc.formatDate(new Date()); let now = irc.formatDate(new Date());
client.fetchHistoryTargets(now, lastReceipt.time).then((targets) => { client.fetchHistoryTargets(now, lastReceipt.time).then((targets) => {
targets.forEach((target) => { targets.forEach((target) => {
let from = lastReceipt;
// Maybe we've just received a READ update from the // Maybe we've just received a READ update from the
// server, avoid over-fetching history // server, avoid over-fetching history
let from = lastReceipt;
let stored = this.bufferStore.get({ name: target.name, server: client.params }); let stored = this.bufferStore.get({ name: target.name, server: client.params });
let readReceipt = getReceipt(stored, ReceiptType.READ); let readReceipt = getReceipt(stored, ReceiptType.READ);
if (isReceiptBefore(from, readReceipt)) { if (isReceiptBefore(from, readReceipt)) {
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 }; let to = { time: msg.tags.time || now };
this.fetchBacklog(client, target.name, from, to); this.fetchBacklog(client, target.name, from, to);
}); });