Fix race conditon when leaving history mode in OO
parent
d3cbefb5c6
commit
c6f87e6ccd
|
@ -116,7 +116,11 @@ define([
|
|||
if (err) { return void console.error(err); }
|
||||
if (!Array.isArray(data.messages)) { return void console.error('Not an array!'); }
|
||||
|
||||
var messages = (data.messages || []).slice(1);
|
||||
// The first "cp" in history is the empty doc. It doesn't include the first patch
|
||||
// of the history
|
||||
var initialCp = cpIndex === sortedCp.length;
|
||||
|
||||
var messages = (data.messages || []).slice(initialCp ? 0 : 1);
|
||||
|
||||
if (config.debug) { console.log(data.messages); }
|
||||
fillOO(id, messages);
|
||||
|
@ -148,9 +152,7 @@ define([
|
|||
};
|
||||
|
||||
update = function () {
|
||||
console.log($fastPrev, $next, $fastNext);
|
||||
var cps = sortedCp.length;
|
||||
console.log(cpIndex, msgIndex, cps);
|
||||
$fastPrev.show();
|
||||
$next.show();
|
||||
$fastNext.show();
|
||||
|
|
|
@ -252,7 +252,9 @@ define([
|
|||
rtChannel.sendCmd({
|
||||
cmd: 'GET_HISTORY',
|
||||
data: {}
|
||||
}, cb);
|
||||
}, function () {
|
||||
APP.onHistorySynced = cb;
|
||||
});
|
||||
},
|
||||
sendMsg: function (msg, cp, cb) {
|
||||
rtChannel.sendCmd({
|
||||
|
@ -718,6 +720,12 @@ define([
|
|||
ooChannel.queue.push(obj.data);
|
||||
}
|
||||
break;
|
||||
case 'HISTORY_SYNCED':
|
||||
if (typeof(APP.onHistorySynced) !== "function") { return; }
|
||||
APP.onHistorySynced();
|
||||
delete APP.onHistorySynced;
|
||||
break;
|
||||
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -1832,15 +1840,15 @@ define([
|
|||
APP.stopHistory = true;
|
||||
makeCheckpoint(true);
|
||||
};
|
||||
var loadCp = function (cp) {
|
||||
var loadCp = function (cp, keepQueue) {
|
||||
loadLastDocument(cp, function () {
|
||||
var file = getFileType();
|
||||
var type = common.getMetadataMgr().getPrivateData().ooType;
|
||||
var blob = loadInitDocument(type, true);
|
||||
ooChannel.queue = [];
|
||||
if (!keepQueue) { ooChannel.queue = []; }
|
||||
resetData(blob, file);
|
||||
}, function (blob, file) {
|
||||
ooChannel.queue = [];
|
||||
if (!keepQueue) { ooChannel.queue = []; }
|
||||
resetData(blob, file);
|
||||
});
|
||||
};
|
||||
|
@ -1862,9 +1870,10 @@ define([
|
|||
APP.history = false;
|
||||
ooChannel.queue = [];
|
||||
ooChannel.ready = false;
|
||||
// Fill the queue and then load the last CP
|
||||
rtChannel.getHistory(function () {
|
||||
var lastCp = getLastCp();
|
||||
loadCp(lastCp);
|
||||
loadCp(lastCp, true);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -7,13 +7,14 @@ define([
|
|||
if (!c) { return void cb({error: 'ENOENT'}); }
|
||||
var chan = ctx.channels[c.channel];
|
||||
if (!chan) { return void cb({error: 'ENOCHAN'}); }
|
||||
cb();
|
||||
chan.history.forEach(function (msg) {
|
||||
ctx.emit('MESSAGE', {
|
||||
msg: msg,
|
||||
validateKey: chan.validateKey
|
||||
}, [client]);
|
||||
});
|
||||
cb();
|
||||
ctx.emit('HISTORY_SYNCED', {}, [client]);
|
||||
};
|
||||
|
||||
var openChannel = function (ctx, obj, client, cb) {
|
||||
|
|
Loading…
Reference in New Issue