Fix style and race condition for history mode
This commit is contained in:
parent
456370b1aa
commit
a810d7bd85
@ -1,7 +1,7 @@
|
|||||||
@import (once) "./colortheme.less";
|
@import (once) "./colortheme.less";
|
||||||
|
|
||||||
.history_main () {
|
.history_main () {
|
||||||
body .cp-toolbar-history {
|
.cp-toolbar-history {
|
||||||
display: none;
|
display: none;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
* {
|
* {
|
||||||
|
|||||||
@ -21,6 +21,15 @@ define([
|
|||||||
var createRealtime = function () {
|
var createRealtime = function () {
|
||||||
return ChainPad.create({
|
return ChainPad.create({
|
||||||
userName: 'history',
|
userName: 'history',
|
||||||
|
validateContent: function (content) {
|
||||||
|
try {
|
||||||
|
JSON.parse(content);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Failed to parse, rejecting patch');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
initialState: '',
|
initialState: '',
|
||||||
transformFunction: JsonOT.validate,
|
transformFunction: JsonOT.validate,
|
||||||
logLevel: 0,
|
logLevel: 0,
|
||||||
@ -69,9 +78,9 @@ define([
|
|||||||
config.onLocal();
|
config.onLocal();
|
||||||
config.onRemote();
|
config.onRemote();
|
||||||
};
|
};
|
||||||
var onReady = function () {
|
|
||||||
config.setHistory(true);
|
config.setHistory(true);
|
||||||
};
|
var onReady = function () { };
|
||||||
|
|
||||||
var Messages = common.Messages;
|
var Messages = common.Messages;
|
||||||
var Cryptpad = common.getCryptpadCommon();
|
var Cryptpad = common.getCryptpadCommon();
|
||||||
|
|||||||
@ -244,23 +244,22 @@ define([
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
var msgs = [];
|
||||||
var onMsg = function (msg) {
|
var onMsg = function (msg) {
|
||||||
var parsed = parse(msg);
|
var parsed = parse(msg);
|
||||||
if (parsed[0] === 'FULL_HISTORY_END') {
|
if (parsed[0] === 'FULL_HISTORY_END') {
|
||||||
console.log('END');
|
cb(msgs);
|
||||||
cb();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (parsed[0] !== 'FULL_HISTORY') { return; }
|
if (parsed[0] !== 'FULL_HISTORY') { return; }
|
||||||
if (parsed[1] && parsed[1].validateKey) { // First message
|
if (parsed[1] && parsed[1].validateKey) { // First message
|
||||||
secret.keys.validateKey = parsed[1].validateKey;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
msg = parsed[1][4];
|
msg = parsed[1][4];
|
||||||
if (msg) {
|
if (msg) {
|
||||||
msg = msg.replace(/^cp\|/, '');
|
msg = msg.replace(/^cp\|/, '');
|
||||||
var decryptedMsg = crypto.decrypt(msg, secret.keys.validateKey);
|
var decryptedMsg = crypto.decrypt(msg, secret.keys.validateKey);
|
||||||
sframeChan.event('EV_RT_HIST_MESSAGE', decryptedMsg);
|
msgs.push(decryptedMsg)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
network.on('message', onMsg);
|
network.on('message', onMsg);
|
||||||
|
|||||||
@ -171,10 +171,14 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
funcs.getFullHistory = function (realtime, cb) {
|
funcs.getFullHistory = function (realtime, cb) {
|
||||||
ctx.sframeChan.on('EV_RT_HIST_MESSAGE', function (content) {
|
ctx.sframeChan.query('Q_GET_FULL_HISTORY', null, function (err, messages) {
|
||||||
realtime.message(content);
|
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) {
|
funcs.getPadAttribute = function (key, cb) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user