Display a warning bar when viewing a versioned link

pull/1/head
yflory 4 years ago
parent 65af20d7cc
commit 784306f947

@ -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);

@ -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");
});
};

@ -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,

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

Loading…
Cancel
Save