diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index c567fe070..8b2d8328b 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -52,7 +52,6 @@ define([ $: $ }; - var CHECKPOINT_INTERVAL = 50; var DISPLAY_RESTORE_BUTTON = false; var NEW_VERSION = 2; @@ -91,6 +90,7 @@ define([ var myUniqueOOId; var myOOId; var sessionId = Hash.createChannelId(); + var cpNfInner; // This structure is used for caching media data and blob urls for each media cryptpad url var mediasData = {}; @@ -589,15 +589,21 @@ define([ oldLocks = JSON.parse(JSON.stringify(content.locks)); // Remove old locks deleteOfflineLocks(); + // Prepare callback + if (cpNfInner) { + var onPatchSent = function () { + cpNfInner.offPatchSent(onPatchSent); + // Answer to our onlyoffice + send({ + type: "getLock", + locks: getLock() + }); + }; + cpNfInner.onPatchSent(onPatchSent); + } // Commit APP.onLocal(); - APP.realtime.onSettle(function () { - // Answer to our onlyoffice - send({ - type: "getLock", - locks: getLock() - }); - }); + APP.realtime.sync(); }; var parseChanges = function (changes) { @@ -1335,7 +1341,6 @@ define([ var initializing = true; var $bar = $('#cp-toolbar'); - var cpNfInner; config = { patchTransformer: ChainPad.SmartJSONTransformer, diff --git a/www/common/sframe-chainpad-netflux-inner.js b/www/common/sframe-chainpad-netflux-inner.js index baa4802d7..65feb67da 100644 --- a/www/common/sframe-chainpad-netflux-inner.js +++ b/www/common/sframe-chainpad-netflux-inner.js @@ -48,6 +48,8 @@ define([ var updateLoadingProgress = config.updateLoadingProgress; config = undefined; + var evPatchSent = Util.mkEvent(); + var chainpad = ChainPad.create({ userName: userName, initialState: initialState, @@ -57,7 +59,10 @@ define([ logLevel: logLevel }); chainpad.onMessage(function(message, cb) { - sframeChan.query('Q_RT_MESSAGE', message, cb); + sframeChan.query('Q_RT_MESSAGE', message, function (err) { + if (!err) { evPatchSent.fire(); } + cb(err); + }); }); chainpad.onPatch(function () { onRemote({ realtime: chainpad }); @@ -149,6 +154,8 @@ define([ metadataMgr: metadataMgr, whenRealtimeSyncs: whenRealtimeSyncs, onInfiniteSpinner: evInfiniteSpinner.reg, + onPatchSent: evPatchSent.reg, + offPatchSent: evPatchSent.unreg, chainpad: chainpad, }); };