No page reload when the cache is corrupted onReady

pull/1/head
yflory 4 years ago
parent 517492f7d3
commit 5946b10d0b

@ -440,9 +440,11 @@ const getHistoryOffset = (Env, channelName, lastKnownHash, _cb) => {
// If our lastKnownHash is older than the 2nd to last checkpoint,
// only send the last 2 checkpoints and ignore "lkh"
if (lkh && index.cpIndex.length >= 2 && lkh < index.cpIndex[0].offset) {
// XXX XXX this is probably wrong! ChainPad may not accept checkpoints that are not connected to root
// XXX We probably need to send an EUNKNOWN here so that the client can recreate a new chainpad
/*if (lkh && index.cpIndex.length >= 2 && lkh < index.cpIndex[0].offset) {
return void cb(null, index.cpIndex[0].offset);
}
}*/
// Otherwise use our lastKnownHash
cb(null, lkh);

@ -55,7 +55,9 @@ define([
S.clearChannel = function (id, _cb) {
cb = Util.once(Util.mkAsync(_cb || function () {}));
cache.removeItem(id, cb);
cache.removeItem(id, function () {
cb();
});
};
S.clear = function () {

@ -467,9 +467,14 @@ define([
});
};
var onCorruptedCache = function (cb) {
var sframeChan = common.getSframeChannel();
sframeChan.event("Q_CORRUPTED_CACHE", cb);
var noCache = false; // Prevent reload loops
var onCorruptedCache = function () {
if (noCache) {
// XXX translation key
return UI.errorLoadingScreen("Reload loop: empty chainpad for a non-empty channel");
}
noCache = true;
sframeChan.event("Q_CORRUPTED_CACHE");
};
var onCacheReady = function () {
stateChange(STATE.DISCONNECTED);
@ -547,17 +552,17 @@ define([
Feedback.send("NON_EMPTY_NEWDOC");
// The cache may be wrong, empty it and reload after.
waitFor.abort();
UI.errorLoadingScreen("MAYBE CORRUPTED CACHE... RELOADING"); // XXX
onCorruptedCache(function () {
setTimeout(function () { common.gotoURL(); }, 1000);
});
onCorruptedCache();
return;
}
console.log('updating title');
title.updateTitle(title.defaultTitle);
evOnDefaultContentNeeded.fire();
}
}).nThen(function () {
// We have a valid chainpad, reenable cache fix in case with reconnect with
// a corrupted cache
noCache = false;
stateChange(STATE.READY);
firstConnection = false;

@ -1637,8 +1637,7 @@ define([
});
};
sframeChan.on('Q_CORRUPTED_CACHE', function (data, cb) {
Utils.Cache.clearChannel(secret.channel, cb);
sframeChan.on('EV_CORRUPTED_CACHE', function () {
Cryptpad.onCorruptedCache(secret.channel);
});

Loading…
Cancel
Save