Fix style and race condition for history mode

This commit is contained in:
yflory
2017-09-21 18:00:11 +02:00
parent 95302366d1
commit dfdeb7b113
4 changed files with 23 additions and 11 deletions

View File

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