From e405dcff7e48c75706cd4d54a0585bc86b1792f2 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 8 Dec 2020 16:46:39 +0100 Subject: [PATCH] Don't show saved in OO until the ACK is received --- www/common/onlyoffice/inner.js | 14 +++++++++++++- www/common/toolbar.js | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index b4bdeef92..c7f5ce9c2 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -99,6 +99,9 @@ define([ var sessionId = Hash.createChannelId(); var cpNfInner; + var evOnPatch = Util.mkEvent(); + var evOnSync = Util.mkEvent(); + // This structure is used for caching media data and blob urls for each media cryptpad url var mediasData = {}; @@ -261,13 +264,17 @@ define([ }); }, sendMsg: function (msg, cp, cb) { + evOnPatch.fire(); rtChannel.sendCmd({ cmd: 'SEND_MESSAGE', data: { msg: msg, isCp: cp } - }, cb); + }, function (err, h) { + if (!err) { evOnSync.fire(); } + cb(err, h); + }); }, }; @@ -1221,6 +1228,7 @@ define([ } }, "onDocumentReady": function () { + evOnSync.fire(); var onMigrateRdy = Util.mkEvent(); onMigrateRdy.reg(function () { var div = h('div.cp-oo-x2tXls', [ @@ -1963,6 +1971,10 @@ define([ metadataMgr: metadataMgr, readOnly: readOnly, realtime: info.realtime, + spinner: { + onPatch: evOnPatch, + onSync: evOnSync + }, sfCommon: common, $container: $bar, $contentContainer: $('#cp-app-oo-container') diff --git a/www/common/toolbar.js b/www/common/toolbar.js index e2c5af1dd..7794f3fde 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -879,6 +879,14 @@ MessengerUI, Messages) { $spin.text(Messages.saved); }, /*local ? 0 :*/ SPINNER_DISAPPEAR_TIME); }; + if (config.spinner) { + var h = function () { + onSynced(); + try { config.spinner.onSync.unreg(h); } catch (e) { console.error(e); } + }; + config.spinner.onSync.reg(h); + return; + } config.sfCommon.whenRealtimeSyncs(onSynced); }; var ks = function (toolbar, config, local) { @@ -891,6 +899,15 @@ MessengerUI, Messages) { var $spin = $('', {'class': SPINNER_CLS}).appendTo(toolbar.title); $spin.text(Messages.synchronizing); + if (config.spinner) { + config.spinner.onPatch.reg(ks(toolbar, config)); + typing = 0; + setTimeout(function () { + kickSpinner(toolbar, config); + }); + return $spin; + } + if (config.realtime) { config.realtime.onPatch(ks(toolbar, config)); config.realtime.onMessage(ks(toolbar, config, true));