Fix style and race condition for history mode
parent
95302366d1
commit
dfdeb7b113
|
@ -1,7 +1,7 @@
|
|||
@import (once) "./colortheme.less";
|
||||
|
||||
.history_main () {
|
||||
body .cp-toolbar-history {
|
||||
.cp-toolbar-history {
|
||||
display: none;
|
||||
text-align: center;
|
||||
* {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -228,23 +228,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);
|
||||
|
|
|
@ -164,10 +164,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) {
|
||||
|
|
Loading…
Reference in New Issue