diff --git a/customize.dist/src/less2/include/toolbar-history.less b/customize.dist/src/less2/include/toolbar-history.less index 1a099bb76..0388f6401 100644 --- a/customize.dist/src/less2/include/toolbar-history.less +++ b/customize.dist/src/less2/include/toolbar-history.less @@ -1,7 +1,7 @@ @import (once) "./colortheme.less"; .history_main () { - body .cp-toolbar-history { + .cp-toolbar-history { display: none; text-align: center; * { diff --git a/www/common/sframe-common-history.js b/www/common/sframe-common-history.js index 3b95674bc..9167afc5f 100644 --- a/www/common/sframe-common-history.js +++ b/www/common/sframe-common-history.js @@ -21,6 +21,15 @@ define([ var createRealtime = function () { return ChainPad.create({ userName: 'history', + validateContent: function (content) { + try { + JSON.parse(content); + return true; + } catch (e) { + console.log('Failed to parse, rejecting patch'); + return false; + } + }, initialState: '', transformFunction: JsonOT.validate, logLevel: 0, @@ -69,9 +78,9 @@ define([ config.onLocal(); config.onRemote(); }; - var onReady = function () { - config.setHistory(true); - }; + + config.setHistory(true); + var onReady = function () { }; var Messages = common.Messages; var Cryptpad = common.getCryptpadCommon(); diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index e1528de41..5aed37271 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -244,23 +244,22 @@ define([ return null; } }; + var msgs = []; var onMsg = function (msg) { var parsed = parse(msg); if (parsed[0] === 'FULL_HISTORY_END') { - console.log('END'); - cb(); + cb(msgs); return; } if (parsed[0] !== 'FULL_HISTORY') { return; } if (parsed[1] && parsed[1].validateKey) { // First message - secret.keys.validateKey = parsed[1].validateKey; return; } msg = parsed[1][4]; if (msg) { msg = msg.replace(/^cp\|/, ''); var decryptedMsg = crypto.decrypt(msg, secret.keys.validateKey); - sframeChan.event('EV_RT_HIST_MESSAGE', decryptedMsg); + msgs.push(decryptedMsg) } }; network.on('message', onMsg); diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index eaad84c47..b658bf959 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -171,10 +171,14 @@ 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, function (err, messages) { + if (err) { return void console.error(err); } + if (!Array.isArray(messages)) { return; } + messages.forEach(function (m) { + realtime.message(m); + }); + cb(); }); - ctx.sframeChan.query('Q_GET_FULL_HISTORY', null, cb); }; funcs.getPadAttribute = function (key, cb) {