diff --git a/www/code/inner.js b/www/code/inner.js index 05356a972..5a4748f9b 100644 --- a/www/code/inner.js +++ b/www/code/inner.js @@ -128,7 +128,6 @@ define([ }; var mkHelpMenu = function (framework) { var $codeMirrorContainer = $('#cp-app-code-container'); - $codeMirrorContainer.prepend(framework._.sfCommon.getBurnAfterReadingWarning()); var helpMenu = framework._.sfCommon.createHelpMenu(['text', 'code']); $codeMirrorContainer.prepend(helpMenu.menu); diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index c3f429f01..36e88f067 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -1464,28 +1464,41 @@ define([ }; var getVersionHash = function (clientId, data) { + var validateKey; var fakeNetflux = Hash.createChannelId(); - Store.getHistoryRange(clientId, { - cpCount: 1, - channel: data.channel, - lastKnownHash: data.versionHash - }, function (obj) { - if (obj && obj.error) { - postMessage(clientId, "PAD_ERROR", obj.error); - return; - } - postMessage(clientId, "PAD_CONNECT", { - myID: fakeNetflux, - id: data.channel, - members: [fakeNetflux] - }); - (obj.messages || []).forEach(function (data) { - postMessage(clientId, "PAD_MESSAGE", { - msg: data.msg, - user: fakeNetflux.slice(0,16), // fake history keeper to avoid validate + nThen(function (waitFor) { + Store.getPadMetadata(null, { + channel: data.channel + }, waitFor(function (md) { + validateKey = md.validateKey; + })); + }).nThen(function () { + Store.getHistoryRange(clientId, { + cpCount: 1, + channel: data.channel, + lastKnownHash: data.versionHash + }, function (obj) { + if (obj && obj.error) { + postMessage(clientId, "PAD_ERROR", obj.error); + return; + } + postMessage(clientId, "PAD_CONNECT", { + myID: fakeNetflux, + id: data.channel, + members: [fakeNetflux] }); + (obj.messages || []).forEach(function (data) { + postMessage(clientId, "PAD_MESSAGE", { + msg: data.msg, + time: data.time, + user: fakeNetflux.slice(0,16), // fake history keeper to avoid validate + }); + }); + if (validateKey && store.messenger) { + store.messenger.storeValidateKey(data.channel, validateKey); + } + postMessage(clientId, "PAD_READY"); }); - postMessage(clientId, "PAD_READY"); }); }; diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index 2df62c73a..8e78e312f 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -438,6 +438,36 @@ define([ window.dispatchEvent(evt); }; + var versionHashEl; + var onInit = function () { + UI.updateLoadingProgress({ + state: 2, + progress: 0.1 + }, false); + stateChange(STATE.INITIALIZING); + if ($('.cp-help-container').length) { + var privateDat = cpNfInner.metadataMgr.getPrivateData(); + // Burn after reading warning + $('.cp-help-container').before(common.getBurnAfterReadingWarning()); + // Versioned link warning + if (privateDat.isHistoryVersion) { + versionHashEl = h('div.alert.alert-warning.cp-burn-after-reading'); + $('.cp-help-container').before(versionHashEl); + } + } + + common.getSframeChannel().on('EV_VERSION_TIME', function (time) { + if (!versionHashEl) { return; } + Messages.infobar_versionHash = "You're currently viewing an old version of this document ({0})."; // XXX + var vTime = time; + var vTimeStr = vTime ? new Date(vTime).toLocaleString() + : 'v' + privateDat.isHistoryVersion; + var vTxt = Messages._getKey('infobar_versionHash',  [vTimeStr]); + versionHashEl.innerText = vTxt; + versionHashEl = undefined; + }); + }; + var onReady = function () { var newContentStr = cpNfInner.chainpad.getUserDoc(); if (state === STATE.DELETED) { return; } @@ -455,6 +485,7 @@ define([ var privateDat = cpNfInner.metadataMgr.getPrivateData(); var type = privateDat.app; + // contentUpdate may be async so we need an nthen here nThen(function (waitFor) { if (!newPad) { @@ -706,13 +737,7 @@ define([ }, onRemote: onRemote, onLocal: onLocal, - onInit: function () { - UI.updateLoadingProgress({ - state: 2, - progress: 0.1 - }, false); - stateChange(STATE.INITIALIZING); - }, + onInit: onInit, onReady: function () { evStart.reg(onReady); }, onConnectionChange: onConnectionChange, onError: onError, diff --git a/www/common/sframe-chainpad-netflux-outer.js b/www/common/sframe-chainpad-netflux-outer.js index e1ade0f88..72cfdef9a 100644 --- a/www/common/sframe-chainpad-netflux-outer.js +++ b/www/common/sframe-chainpad-netflux-outer.js @@ -31,12 +31,16 @@ define([], function () { var versionHash = conf.versionHash; var validateKey = metadata.validateKey; var onConnect = conf.onConnect || function () { }; + var lastTime; // Time of last patch (if versioned link); conf = undefined; if (versionHash) { readOnly = true; } padRpc.onReadyEvent.reg(function () { sframeChan.event('EV_RT_READY', null); + if (lastTime && versionHash) { + sframeChan.event('EV_VERSION_TIME', lastTime); + } }); // shim between chainpad and netflux @@ -86,6 +90,7 @@ define([], function () { } var message = msgIn(msgObj.user, msgObj.msg); if (!message) { return; } + lastTime = msgObj.time; verbose(message); diff --git a/www/common/toolbar.js b/www/common/toolbar.js index 1b3dcc17c..cf319f124 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -1350,11 +1350,13 @@ MessengerUI, Messages) { } }; + Messages.snaphot_title = "Snapshot"; //XXX + toolbar.setSnapshot = function (bool) { toolbar.history = bool; toolbar.title.toggleClass('cp-toolbar-unsync', bool); if (bool && toolbar.spinner) { - toolbar.spinner.text("SNAPSHOT"); // XXX + toolbar.spinner.text(Messages.snaphot_title); } else { kickSpinner(toolbar, config); } @@ -1363,7 +1365,7 @@ MessengerUI, Messages) { toolbar.history = bool; toolbar.title.toggleClass('cp-toolbar-unsync', bool); if (bool && toolbar.spinner) { - toolbar.spinner.text("HISTORY"); // XXX + toolbar.spinner.text(Messages.historyText); } else { kickSpinner(toolbar, config); } diff --git a/www/kanban/inner.js b/www/kanban/inner.js index 7a1450d8b..61a7ad23d 100644 --- a/www/kanban/inner.js +++ b/www/kanban/inner.js @@ -1013,7 +1013,6 @@ define([ var mkHelpMenu = function (framework) { var $toolbarContainer = $('#cp-app-kanban-container'); - $toolbarContainer.prepend(framework._.sfCommon.getBurnAfterReadingWarning()); var helpMenu = framework._.sfCommon.createHelpMenu(['kanban']); $toolbarContainer.prepend(helpMenu.menu); diff --git a/www/pad/inner.js b/www/pad/inner.js index fb4523fb0..9b840602d 100644 --- a/www/pad/inner.js +++ b/www/pad/inner.js @@ -206,7 +206,6 @@ define([ var mkHelpMenu = function(framework) { var $toolbarContainer = $('.cke_toolbox_main'); - $toolbarContainer.before(framework._.sfCommon.getBurnAfterReadingWarning()); var helpMenu = framework._.sfCommon.createHelpMenu(['text', 'pad']); $toolbarContainer.before(helpMenu.menu); diff --git a/www/slide/inner.js b/www/slide/inner.js index 4b7691ced..3af7185c5 100644 --- a/www/slide/inner.js +++ b/www/slide/inner.js @@ -428,7 +428,6 @@ define([ var mkHelpMenu = function (framework) { var $codeMirrorContainer = $('#cp-app-slide-editor-container'); - $codeMirrorContainer.prepend(framework._.sfCommon.getBurnAfterReadingWarning()); var helpMenu = framework._.sfCommon.createHelpMenu(['text', 'slide']); $codeMirrorContainer.prepend(helpMenu.menu); diff --git a/www/whiteboard/inner.js b/www/whiteboard/inner.js index bfcb55424..44efd1421 100644 --- a/www/whiteboard/inner.js +++ b/www/whiteboard/inner.js @@ -250,7 +250,6 @@ define([ var mkHelpMenu = function (framework) { var $appContainer = $('#cp-app-whiteboard-container'); - $appContainer.prepend(framework._.sfCommon.getBurnAfterReadingWarning()); var helpMenu = framework._.sfCommon.createHelpMenu(['whiteboard']); $appContainer.prepend(helpMenu.menu); framework._.toolbar.$drawer.append(helpMenu.button);