From 0d543794bb89088f3c7bdc903111bab54ccabc00 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 1 Oct 2020 10:55:20 +0200 Subject: [PATCH 1/2] Display an error message when a snapshot has been deleted --- www/common/inner/snapshots.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/www/common/inner/snapshots.js b/www/common/inner/snapshots.js index dbbf41bf5..4810d0e85 100644 --- a/www/common/inner/snapshots.js +++ b/www/common/inner/snapshots.js @@ -46,6 +46,13 @@ define([ sframeChan.query("Q_GET_SNAPSHOT", {hash: config.hash}, function (err, obj) { if (err || (obj && obj.error)) { return void console.error(err || obj.error); } if (!Array.isArray(obj)) { return void console.error("invalid type"); } + if (!obj.length) { return void console.error("Empty channel"); } + var checkLast = obj[obj.length - 1].serverHash === config.hash; + if (!checkLast) { + $snap.find('.cp-toolbar-snapshots-close').click(); + return void UI.alert(Messages.snapshots_notFound); + } + var messages = obj; var chainpad = createChainPad(); messages.forEach(function (m) { @@ -57,6 +64,7 @@ define([ }); }; +Messages.snapshots_notFound = "This snapshot no longer exists. It has been deleted with the history of the pad."; Messages.snapshots_restore = "Restore"; // XXX Messages.snapshots_close = "Close"; Messages.snapshots_cantRestore = "Can't restore now. Disconnected..."; From 65af20d7cc62e3d54ae7857b2b9b711fd5de0b98 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 1 Oct 2020 11:16:08 +0200 Subject: [PATCH 2/2] Fix history 'loadMore' with trimmed history --- www/common/sframe-common-history.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/www/common/sframe-common-history.js b/www/common/sframe-common-history.js index 1ccec88be..506abeffb 100644 --- a/www/common/sframe-common-history.js +++ b/www/common/sframe-common-history.js @@ -214,6 +214,16 @@ define([ var messages = (data.messages || []).map(function (obj) { return obj; }); + + // We're supposed to receive 2 checkpoints. If the result is only ONE message + // and this message is a checkpoint, it means it's the last message of the history + // (and this is a trimmed history) + if (messages.length === 1) { + var parsed = JSON.parse(messages[0].msg); + if (parsed[0] === 4) { + isComplete = true; + } + } if (config.debug) { console.log(data.messages); } Array.prototype.unshift.apply(allMessages, messages); // Destructive concat fillChainPad(realtime, allMessages);