From 8d837d22ea1341d046314bce172bb758c2703fea Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 21 Aug 2017 17:40:21 +0200 Subject: [PATCH] Add history to pad2 --- www/common/common-history.js | 8 ++++---- www/common/sframe-common.js | 28 ++++++++++++++++++++++++---- www/common/sframe-protocol.js | 14 ++++++++++---- www/pad2/main.js | 11 +++++++++++ www/pad2/outer.js | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 12 deletions(-) diff --git a/www/common/common-history.js b/www/common/common-history.js index e29e95753..6dea29ab7 100644 --- a/www/common/common-history.js +++ b/www/common/common-history.js @@ -38,13 +38,13 @@ define([ var parsed = config.href ? common.parsePadUrl(config.href) : {}; var secret = common.getSecrets(parsed.type, parsed.hash); - History.readOnly = 1; + History.readOnly = 0; if (!secret.keys) { secret.keys = secret.key; - History.readOnly = 2; + History.readOnly = 0; } else if (!secret.keys.validateKey) { - History.readOnly = 0; + History.readOnly = 1; } var crypto = Crypto.createEncryptor(secret.keys); @@ -203,7 +203,7 @@ define([ 'class':'revertHistory buttonSuccess', title: Messages.history_restoreTitle }).text(Messages.history_restore).appendTo($nav); - if (!History.readOnly) { $rev.hide(); } + if (History.readOnly) { $rev.hide(); } onUpdate = function () { $cur.attr('max', states.length); diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index a2677a4b7..6cedc7235 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -5,15 +5,18 @@ define([ '/common/sframe-channel.js', '/common/sframe-common-title.js', '/common/sframe-common-interface.js', + '/common/sframe-common-history.js', '/common/metadata-manager.js', '/common/cryptpad-common.js' -], function (nThen, Messages, CpNfInner, SFrameChannel, Title, UI, MetadataMgr, Cryptpad) { +], function (nThen, Messages, CpNfInner, SFrameChannel, Title, UI, History, MetadataMgr, Cryptpad) { // Chainpad Netflux Inner var funcs = {}; var ctx = {}; + funcs.Messages = Messages; + funcs.startRealtime = function (options) { if (ctx.cpNfInner) { return ctx.cpNfInner; } options.sframeChan = ctx.sframeChan; @@ -23,6 +26,13 @@ define([ return ctx.cpNfInner; }; + funcs.getMetadataMgr = function () { + return ctx.metadataMgr; + }; + funcs.getCryptpadCommon = function () { + return Cryptpad; + }; + var isLoggedIn = funcs.isLoggedIn = function () { if (!ctx.cpNfInner) { throw new Error("cpNfInner is not ready!"); } return ctx.cpNfInner.metadataMgr.getPrivateData().accountName; @@ -38,6 +48,9 @@ define([ funcs.createUserAdminMenu = UI.createUserAdminMenu; funcs.displayAvatar = UI.displayAvatar; + // History + funcs.getHistory = function (config) { return History.create(funcs, config); }; + // Title module funcs.createTitle = Title.create; @@ -79,6 +92,13 @@ define([ }); }; + funcs.getFullHistory = function (realtime, cb) { + ctx.sframeChan.on('EV_RT_HIST_MESSAGE', function (content) { + realtime.message(content); + }); + ctx.sframeChan.query('Q_GET_FULL_HISTORY', null, cb); + }; + // TODO funcs.feedback = function () {}; @@ -199,10 +219,10 @@ define([ } break; case 'history': - if (!AppConfig.enableHistory) { + /*if (!AppConfig.enableHistory) { button = $(''); break; - } + }*/ button = $('