diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index fa80c68cc..fd34ee1c2 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -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(); diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index ed17c1a39..43d4203f0 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -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); }); }; diff --git a/www/common/outer/onlyoffice.js b/www/common/outer/onlyoffice.js index 83e1df64a..773774c5a 100644 --- a/www/common/outer/onlyoffice.js +++ b/www/common/outer/onlyoffice.js @@ -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) {