From 65cab7fbad3facf2af5aac6d7f73babc8aa67828 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Mon, 8 Sep 2025 17:03:48 +0200 Subject: [PATCH] WIP --- www/common/onlyoffice/history.js | 32 ++++++++++------------- www/common/onlyoffice/inner.js | 44 ++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 72b077f54..b7a0bb522 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -19,7 +19,6 @@ define([ var $toolbar = config.$toolbar; var sframeChan = common.getSframeChannel(); History.readOnly = common.getMetadataMgr().getPrivateData().readOnly || !common.isLoggedIn(); - console.log("HOR", common.getMetadataMgr().getPrivateData().readOnly, !common.isLoggedIn()) if (!config.onlyoffice || !config.setHistory || !config.onCheckpoint || !config.onPatch || !config.makeSnapshot) { throw new Error("Missing config element"); } @@ -31,6 +30,7 @@ define([ var loading = false; var update = function () {}; var currentTime; + var newlyLoaded = true; // Get an array of the checkpoint IDs sorted their patch index var hashes = config.onlyoffice.hashes; @@ -167,8 +167,8 @@ define([ }); var onClose = function () { config.setHistory(false); }; - var onRevert = function () { - config.onRevert(); + var onRevert = function (msgs) { + config.onRevert(msgs); }; config.setHistory(true); @@ -194,6 +194,7 @@ define([ $fastNext.show(); $hist.find('.cp-toolbar-history-next, .cp-toolbar-history-previous') .prop('disabled', ''); + if (cpIndex >= cps && msgIndex === 0) { $fastPrev.prop('disabled', 'disabled'); } @@ -202,24 +203,19 @@ define([ } var id = getId(); var msgs = (ooMessages[id] || []).length; - console.log("next mgsi", msgIndex, msgs) - - if (msgIndex >= (msgs-1)) { - console.log("next disabled") + var v = getVersion() + if (msgIndex >= (msgs-1) || v === '1.0') { $next.prop('disabled', 'disabled'); } }; var next = function () { - var id = getId(); + var id = -1 if (!ooMessages[id]) { loading = false; return; } var msgs = ooMessages[id]; var cp = ooCheckpoints[id]; msgIndex++; - // var patch = msgs[msgIndex]; - // if (!patch) { loading = false; return; } - // config.onPatchBack(patch); var queue = msgs.slice(0, msgIndex); config.onPatchBack(cp, queue); showVersion(); @@ -232,14 +228,13 @@ define([ var prev = function () { var id = getId(); - var msgs = ooMessages[id]; - console.log("msgs", id, msgIndex, ooMessages, msgs) + var msgs = ooMessages[-1]; var cp = ooCheckpoints[id]; - console.log("cp", cp, ooCheckpoints) - console.log("msgs", id, msgIndex, ooMessages, msgs) - var queue = msgs.slice(0, msgIndex); - config.onPatchBack(cp, queue); + config.onPatchBack(cp, queue, newlyLoaded); + newlyLoaded = false + showVersion(); + msgIndex--; @@ -439,7 +434,8 @@ define([ if (!yes) { return; } closeUI(); History.loading = false; - onRevert(); + console.log("messages2", ooMessages[-1]) + onRevert(ooMessages[-1]); UI.log(Messages.history_restoreDone); }); }); diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 7ea023242..ca6ebf85c 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -587,7 +587,8 @@ define([ startOO(blob, type, true); }; - var saveToServer = function (blob, title) { + var saveToServer = function (blob, title, msgs) { + APP.msgs = msgs if (APP.cantCheckpoint) { return; } // TOO_LARGE var text = !blob && getContent(); if (!text && !blob) { @@ -614,7 +615,7 @@ define([ isLockedModal.modal = UI.openCustomModal(isLockedModal.content); } ooChannel.ready = false; - ooChannel.queue = []; + // ooChannel.queue = []; data.callback = function () { if (APP.template) { APP.template = false; } resetData(blob, file); @@ -625,7 +626,7 @@ define([ var noLogin = false; - var makeCheckpoint = function (force) { + var makeCheckpoint = function (force, msgs) { if (APP.cantCheckpoint) { return; } // TOO_LARGE var locked = content.saveLock; @@ -661,7 +662,7 @@ define([ content.saveLock = myOOId; APP.onLocal(); APP.realtime.onSettle(function () { - saveToServer(); + saveToServer(null, null, msgs); }); } }; @@ -1093,19 +1094,35 @@ define([ const getInitialChanges = function() { const changes = []; + if (APP.msgs) { + msgsFormatted = [] + APP.msgs.forEach(function(msg) { + var parsedMsg = JSON.parse(msg.msg); + var formattedMsg = { + msg: parsedMsg, + hash: msg.serverHash, + author: msg.author, + time: msg.time + }; + + msgsFormatted.push(formattedMsg) + + }) + ooChannel.queue = msgsFormatted + } if (content.version > 2) { ooChannel.queue.forEach(function (data) { Array.prototype.push.apply(changes, data.msg.changes); }); ooChannel.ready = true; - console.log("oochannelq", ooChannel.queue) ooChannel.cpIndex += ooChannel.queue.length; var last = ooChannel.queue.pop(); if (last) { ooChannel.lastHash = last.hash; } } - console.log("changes", changes) - return changes; + APP.msgs = false + return changes + }; const onAuth = function () { @@ -3148,12 +3165,12 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null if (!privateData.ooVersionHash) { (function () { /* add a history button */ - var commit = function () { + var commit = function (msgs) { // Wait for the checkpoint to be uploaded before leaving history mode // (race condition). We use "stopHistory" to remove the history // flag only when the checkpoint is ready. APP.stopHistory = true; - makeCheckpoint(true); + makeCheckpoint(true, msgs); }; var onPatch = function (patch) { // Patch on the current cp @@ -3163,7 +3180,11 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null // We want to load a checkpoint: loadCp(cp); }; - var onPatchBack = function (cp, msgs) { + var onPatchBack = function (cp, msgs, newlyLoaded) { + var originalHistory + if (newlyLoaded) { + originalHistory = ooChannel.queue + } // We want to load a checkpoint: msgsFormatted = [] msgs.forEach(function(msg) { @@ -3181,9 +3202,6 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null }) ooChannel.queue = msgsFormatted; - console.log("q1", ooChannel.queue) - console.log("q2", msgs) - // console.log("q2", queue) loadCp(cp, true); }; var setHistoryMode = function (bool) {