From ac8473d8e937b37bfd7175ffbb9de965c4e66b43 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 1 Sep 2025 15:42:49 +0200 Subject: [PATCH 01/51] pewpewpew --- www/common/onlyoffice/history.js | 16 ++++++++++++++++ www/common/onlyoffice/inner.js | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 7cce229af..a0c9c9038 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -25,6 +25,7 @@ define([ var cpIndex = -1; var msgIndex = -1; var ooMessages = {}; + var ooCheckpoints = {}; var loading = false; var update = function () {}; var currentTime; @@ -93,6 +94,8 @@ define([ } var nextId = sortedCp[sortedCp.length - cpIndex]; + ooCheckpoints[id] = cp; + // Get the history between "toHash" and "fromHash". This function is using // "getOlderHistory", that's why we start from the more recent hash // and we go back in time to an older hash @@ -189,6 +192,19 @@ define([ }, 200); }; + var back = function () { + // Load checkpoint data if needed + + + var id = getId(); + var msgs = ooMessages[id]; + var cp = ooCheckpoints[id]; + msgIndex--; + var queue = msgs.slice(0, msgIndex); + config.onPatchBack(cp, msgs); + + }; + // Create the history toolbar var display = function () { diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index d91394fc4..b22a02eb3 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -3137,6 +3137,11 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null // We want to load a checkpoint: loadCp(cp); }; + var onPatchBack = function (cp, queue) { + // We want to load a checkpoint: + ooChannel.queue = queue; + loadCp(cp, true); + }; var setHistoryMode = function (bool) { if (bool) { APP.history = true; From b7014ee605ce5e6027e8f403e1b014ba40edd402 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 5 Sep 2025 17:56:56 +0200 Subject: [PATCH 02/51] add UI --- www/common/onlyoffice/history.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index a0c9c9038..bce52d991 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -150,7 +150,7 @@ define([ UI.spinner($hist).get().show(); - var $fastPrev, $fastNext, $next; + var $fastPrev, $fastNext, $next, $prev; var getId = function () { var cps = sortedCp.length; @@ -161,6 +161,7 @@ define([ var cps = sortedCp.length; $fastPrev.show(); $next.show(); + $prev.show(); $fastNext.show(); $hist.find('.cp-toolbar-history-next, .cp-toolbar-history-previous') .prop('disabled', ''); @@ -192,12 +193,13 @@ define([ }, 200); }; - var back = function () { + var prev = function () { // Load checkpoint data if needed var id = getId(); var msgs = ooMessages[id]; + console.log("msgs", id, ooMessages, msgs) var cp = ooCheckpoints[id]; msgIndex--; var queue = msgs.slice(0, msgIndex); @@ -219,10 +221,15 @@ define([ var _next = h('button.cp-toolbar-history-next', { title: Messages.history_next }, [ h('i.fa.fa-step-forward') ]); + var _prev = h('button.cp-toolbar-history-next', { title: Messages.history_next }, [ + h('i.fa.fa-step-forward') + ]); $fastPrev = $(fastPrev); + $prev = $(_prev); $fastNext = $(fastNext).prop('disabled', 'disabled'); $next = $(_next).prop('disabled', 'disabled'); + var pos = h('span.cp-history-timeline-pos.fa.fa-caret-down'); var time = h('div.cp-history-timeline-time'); var version = h('div.cp-history-timeline-version'); @@ -236,6 +243,7 @@ define([ h('div.cp-history-timeline-actions', [ h('span.cp-history-timeline-prev', [ fastPrev, + _prev ]), time, version, @@ -300,6 +308,12 @@ define([ next(); update(); }); + $prev.click(function () { + if (loading) { return; } + loading = true; + prev(); + update(); + }); // Go to previous checkpoint $fastNext.click(function () { if (loading) { return; } From c9949fae53349896fb0a949247a339785e57a5f3 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 5 Sep 2025 19:03:40 +0200 Subject: [PATCH 03/51] go back incrementally --- www/common/onlyoffice/history.js | 84 +++++++++++++++++++++----------- www/common/onlyoffice/inner.js | 25 +++++++++- 2 files changed, 79 insertions(+), 30 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index bce52d991..e5322baf9 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -80,6 +80,38 @@ define([ else { $time.text(''); } }; + function getMessages(fromHash, toHash, cpIndex, sortedCp, cp, id, config, fillOO, $share, callback) { + sframeChan.query('Q_GET_HISTORY_RANGE', { + channel: config.onlyoffice.channel, + lastKnownHash: fromHash, + toHash: toHash, + }, function (err, data) { + if (err) { + console.error(err); + callback(err); + return; + } + + if (!Array.isArray(data.messages)) { + return; + } + + let initialCp = cpIndex === sortedCp.length || cp ? !cp?.hash : undefined; + + const messages = (data.messages || []).slice(initialCp ? 0 : 1); + + if (config.debug) { + console.log(data.messages); + } + + fillOO(id, messages); + loading = false; + // $share.show(); + + callback(null, messages); + }); + } + // We want to load a checkpoint (or initial state) var loadMoreOOHistory = function () { if (!Array.isArray(sortedCp)) { return void console.error("Wrong type"); } @@ -103,7 +135,7 @@ define([ // We need to get all the patches between the current cp hash and the next cp hash // Current cp or initial hash (invalid hash ==> initial hash) - var toHash = cp.hash || 'NONE'; + var toHash = cp?.hash || 'NONE'; // Next cp or last hash var fromHash = nextId ? hashes[nextId].hash : config.onlyoffice.lastHash; @@ -116,28 +148,22 @@ define([ return void config.onCheckpoint(cp); } - sframeChan.query('Q_GET_HISTORY_RANGE', { - channel: config.onlyoffice.channel, - lastKnownHash: fromHash, - toHash: toHash, - }, function (err, data) { - if (err) { return void console.error(err); } - if (!Array.isArray(data.messages)) { return void console.error('Not an array!'); } - - // The first "cp" in history is the empty doc. It doesn't include the first patch - // of the history - var initialCp = cpIndex === sortedCp.length || !cp.hash; - - var messages = (data.messages || []).slice(initialCp ? 0 : 1); - - if (config.debug) { console.log(data.messages); } - fillOO(id, messages); - loading = false; - config.onCheckpoint(cp); - $share.show(); + getMessages(fromHash, toHash, cpIndex, sortedCp, cp, id, config, fillOO, $share, function (err, messages) { + if (err) { + return; + } }); + + }; + getMessages(config.onlyoffice.lastHash, 'NONE', cpIndex, sortedCp, undefined, -1, config, fillOO, $share, function (err, messages) { + if (err) { + console.error(err); + return; + } + }); + var onClose = function () { config.setHistory(false); }; var onRevert = function () { config.onRevert(); @@ -185,7 +211,7 @@ define([ msgIndex++; var patch = msgs[msgIndex]; if (!patch) { loading = false; return; } - config.onPatch(patch); + config.onPatchBack(patch); showVersion(); setTimeout(function () { $('iframe').blur(); @@ -194,16 +220,17 @@ define([ }; var prev = function () { - // Load checkpoint data if needed - var id = getId(); var msgs = ooMessages[id]; - console.log("msgs", id, ooMessages, msgs) + console.log("msgs", id, msgIndex, ooMessages, msgs) var cp = ooCheckpoints[id]; - msgIndex--; + console.log("msgs", id, msgIndex, ooMessages, msgs) + var queue = msgs.slice(0, msgIndex); - config.onPatchBack(cp, msgs); + config.onPatchBack(cp, queue); + msgIndex--; + }; @@ -303,14 +330,15 @@ define([ // Push one patch $next.click(function () { - if (loading) { return; } + // if (loading) { return; } loading = true; next(); update(); }); $prev.click(function () { - if (loading) { return; } + // if (loading) { return; } loading = true; + // loadMoreOOHistory(); prev(); update(); }); diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index b22a02eb3..1d0291d6c 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -1078,11 +1078,13 @@ define([ 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; }; @@ -3137,9 +3139,27 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null // We want to load a checkpoint: loadCp(cp); }; - var onPatchBack = function (cp, queue) { + var onPatchBack = function (cp, msgs) { // We want to load a checkpoint: - ooChannel.queue = queue; + msgsFormatted = [] + msgs.forEach(function(msg) { + var parsedMsg = JSON.parse(msg.msg); + + // Create the new format2 object structure + var formattedMsg = { + msg: parsedMsg, + hash: msg.serverHash, // Map serverHash to hash + author: msg.author, + time: msg.time + }; + + msgsFormatted.push(formattedMsg) + + }) + ooChannel.queue = msgsFormatted; + console.log("q1", ooChannel.queue) + console.log("q2", msgs) + // console.log("q2", queue) loadCp(cp, true); }; var setHistoryMode = function (bool) { @@ -3208,6 +3228,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null Feedback.send('OO_HISTORY'); var histConfig = { onPatch: onPatch, + onPatchBack: onPatchBack, onCheckpoint: onCheckpoint, onRevert: commit, setHistory: setHistoryMode, From 3ee1eb5f64adad9b5682c81f6cfbcb91981a10cb Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 5 Sep 2025 19:07:54 +0200 Subject: [PATCH 04/51] can go back and forth incrementally --- www/common/onlyoffice/history.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index e5322baf9..38ee0d0c7 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -208,10 +208,14 @@ define([ var id = getId(); 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 patch = msgs[msgIndex]; + // if (!patch) { loading = false; return; } + // config.onPatchBack(patch); + var queue = msgs.slice(0, msgIndex); + config.onPatchBack(cp, queue); showVersion(); setTimeout(function () { $('iframe').blur(); @@ -225,6 +229,7 @@ define([ var msgs = ooMessages[id]; console.log("msgs", id, msgIndex, ooMessages, msgs) var cp = ooCheckpoints[id]; + console.log("cp", cp, ooCheckpoints) console.log("msgs", id, msgIndex, ooMessages, msgs) var queue = msgs.slice(0, msgIndex); From 1f95975052f969130c5c37f8be285a650fb3b881 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Mon, 8 Sep 2025 11:05:18 +0200 Subject: [PATCH 05/51] wip --- www/common/onlyoffice/history.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 38ee0d0c7..c01207cf7 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -17,7 +17,7 @@ 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"); } @@ -199,7 +199,10 @@ define([ } var id = getId(); var msgs = (ooMessages[id] || []).length; + console.log("next mgsi", msgIndex, msgs) + if (msgIndex >= (msgs-1)) { + console.log("next disabled") $next.prop('disabled', 'disabled'); } }; @@ -253,8 +256,8 @@ define([ var _next = h('button.cp-toolbar-history-next', { title: Messages.history_next }, [ h('i.fa.fa-step-forward') ]); - var _prev = h('button.cp-toolbar-history-next', { title: Messages.history_next }, [ - h('i.fa.fa-step-forward') + var _prev = h('button.cp-toolbar-history-previous', { title: Messages.history_next }, [ + h('i.fa.fa-step-backward') ]); $fastPrev = $(fastPrev); $prev = $(_prev); From 2499d021556c6ca3c1c549f1ffadf3b705ef2ea2 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Mon, 8 Sep 2025 17:03:48 +0200 Subject: [PATCH 06/51] 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 c01207cf7..a357b0163 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -17,7 +17,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"); } @@ -29,6 +28,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; @@ -165,8 +165,8 @@ define([ }); var onClose = function () { config.setHistory(false); }; - var onRevert = function () { - config.onRevert(); + var onRevert = function (msgs) { + config.onRevert(msgs); }; config.setHistory(true); @@ -191,6 +191,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'); } @@ -199,24 +200,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(); @@ -229,14 +225,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--; @@ -436,7 +431,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 1d0291d6c..8f985f2dc 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -568,7 +568,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) { @@ -595,7 +596,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); @@ -606,7 +607,7 @@ define([ var noLogin = false; - var makeCheckpoint = function (force) { + var makeCheckpoint = function (force, msgs) { if (APP.cantCheckpoint) { return; } // TOO_LARGE var locked = content.saveLock; @@ -642,7 +643,7 @@ define([ content.saveLock = myOOId; APP.onLocal(); APP.realtime.onSettle(function () { - saveToServer(); + saveToServer(null, null, msgs); }); } }; @@ -1073,19 +1074,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 () { @@ -3124,12 +3141,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 @@ -3139,7 +3156,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) { @@ -3157,9 +3178,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) { From 1b112a6bc4efc2f00ca608f0766fc0c0b590b9ae Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Tue, 9 Sep 2025 15:25:00 +0200 Subject: [PATCH 07/51] wip --- www/common/onlyoffice/history.js | 28 ++++++++++++++-------------- www/common/onlyoffice/inner.js | 21 +-------------------- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index a357b0163..a4caf5400 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -41,8 +41,10 @@ define([ var fillOO = function (id, messages) { if (!id) { return; } - if (ooMessages[id]) { return; } + // if (ooMessages[id]) { return; } + ooMessages[id] = messages; + update(); }; @@ -103,7 +105,7 @@ define([ if (config.debug) { console.log(data.messages); } - + id = getId() fillOO(id, messages); loading = false; // $share.show(); @@ -114,6 +116,7 @@ define([ // We want to load a checkpoint (or initial state) var loadMoreOOHistory = function () { + if (!Array.isArray(sortedCp)) { return void console.error("Wrong type"); } var cp = {}; @@ -139,7 +142,7 @@ define([ // Next cp or last hash var fromHash = nextId ? hashes[nextId].hash : config.onlyoffice.lastHash; - msgIndex = -1; + // msgIndex = -1; showVersion(); if (ooMessages[id]) { @@ -165,8 +168,8 @@ define([ }); var onClose = function () { config.setHistory(false); }; - var onRevert = function (msgs) { - config.onRevert(msgs); + var onRevert = function () { + config.onRevert(); }; config.setHistory(true); @@ -180,7 +183,7 @@ define([ var getId = function () { var cps = sortedCp.length; - return sortedCp[cps - cpIndex -1] || -1; + return sortedCp[cps-1] || -1; }; update = function () { @@ -201,13 +204,13 @@ define([ var id = getId(); var msgs = (ooMessages[id] || []).length; var v = getVersion() - if (msgIndex >= (msgs-1) || v === '1.0') { + if (msgIndex >= (msgs-1)) { $next.prop('disabled', 'disabled'); } }; var next = function () { - var id = -1 + var id = getId() if (!ooMessages[id]) { loading = false; return; } var msgs = ooMessages[id]; var cp = ooCheckpoints[id]; @@ -225,16 +228,14 @@ define([ var prev = function () { var id = getId(); - var msgs = ooMessages[-1]; + var msgs = ooMessages[id]; var cp = ooCheckpoints[id]; var queue = msgs.slice(0, msgIndex); config.onPatchBack(cp, queue, newlyLoaded); newlyLoaded = false showVersion(); - msgIndex--; - }; @@ -341,7 +342,7 @@ define([ $prev.click(function () { // if (loading) { return; } loading = true; - // loadMoreOOHistory(); + loadMoreOOHistory(); prev(); update(); }); @@ -431,8 +432,7 @@ define([ if (!yes) { return; } closeUI(); History.loading = false; - console.log("messages2", ooMessages[-1]) - onRevert(ooMessages[-1]); + onRevert(); UI.log(Messages.history_restoreDone); }); }); diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 8f985f2dc..c7688469f 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -569,7 +569,6 @@ define([ }; var saveToServer = function (blob, title, msgs) { - APP.msgs = msgs if (APP.cantCheckpoint) { return; } // TOO_LARGE var text = !blob && getContent(); if (!text && !blob) { @@ -1074,22 +1073,7 @@ 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); @@ -1100,7 +1084,6 @@ define([ var last = ooChannel.queue.pop(); if (last) { ooChannel.lastHash = last.hash; } } - APP.msgs = false return changes }; @@ -3161,15 +3144,13 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null if (newlyLoaded) { originalHistory = ooChannel.queue } - // We want to load a checkpoint: msgsFormatted = [] msgs.forEach(function(msg) { var parsedMsg = JSON.parse(msg.msg); - // Create the new format2 object structure var formattedMsg = { msg: parsedMsg, - hash: msg.serverHash, // Map serverHash to hash + hash: msg.serverHash, author: msg.author, time: msg.time }; From 19ecb64b048135942aafbba6620aec0022afc07b Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Tue, 9 Sep 2025 16:27:40 +0200 Subject: [PATCH 08/51] WIP --- www/common/onlyoffice/history.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index a4caf5400..545a230b5 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -210,23 +210,24 @@ define([ }; var next = function () { + var id = getId() if (!ooMessages[id]) { loading = false; return; } var msgs = ooMessages[id]; - var cp = ooCheckpoints[id]; - msgIndex++; - var queue = msgs.slice(0, msgIndex); - config.onPatchBack(cp, queue); + if (msgIndex < 0) { + var patch = msgs[msgs.length + msgIndex]; + } + config.onPatch(patch) showVersion(); setTimeout(function () { $('iframe').blur(); loading = false; }, 200); + }; var prev = function () { - var id = getId(); var msgs = ooMessages[id]; var cp = ooCheckpoints[id]; From d1dd0112f8bd8adb31117dd52e36aeb148a69b42 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Wed, 10 Sep 2025 18:38:59 +0200 Subject: [PATCH 09/51] checkpoints added --- www/common/onlyoffice/history.js | 81 +++++++++++++++++++++----------- www/common/onlyoffice/inner.js | 22 ++++++--- 2 files changed, 70 insertions(+), 33 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 545a230b5..3137c39e1 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -23,12 +23,13 @@ define([ var cpIndex = -1; var msgIndex = -1; + + var ooMessages = {}; var ooCheckpoints = {}; 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; @@ -36,14 +37,26 @@ define([ return hashes[a].index - hashes[b].index; }); + var getId = function () { + var cps = sortedCp.length; + return sortedCp[cps-1] || -1; + }; + + var id = getId(); + var endWithCp = sortedCp.length && config.onlyoffice.lastHash === hashes[sortedCp[sortedCp.length - 1]].hash; - var fillOO = function (id, messages) { + var fillOO = function (id, messages, ooCheckpoints) { if (!id) { return; } - // if (ooMessages[id]) { return; } - - ooMessages[id] = messages; + var checkpoints = [] + Object.keys(ooCheckpoints).forEach(function(key) { + checkpoints.push(ooCheckpoints[key].index) + }) + checkpoints.forEach((current, index) => { + var preceding = index > 0 ? checkpoints[index - 1] : 1; + ooMessages[index+1] = messages.slice(preceding-1, current-1) + }); update(); }; @@ -82,7 +95,7 @@ define([ else { $time.text(''); } }; - function getMessages(fromHash, toHash, cpIndex, sortedCp, cp, id, config, fillOO, $share, callback) { + function getMessages(fromHash, toHash, cpIndex, sortedCp, cp, id, config, fillOO, $share, ooCheckpoints, callback) { sframeChan.query('Q_GET_HISTORY_RANGE', { channel: config.onlyoffice.channel, lastKnownHash: fromHash, @@ -106,7 +119,7 @@ define([ console.log(data.messages); } id = getId() - fillOO(id, messages); + fillOO(id, messages, ooCheckpoints); loading = false; // $share.show(); @@ -115,7 +128,8 @@ define([ } // We want to load a checkpoint (or initial state) - var loadMoreOOHistory = function () { + var loadMoreOOHistory = function (cb) { + console.log("oomessages!", ooMessages) if (!Array.isArray(sortedCp)) { return void console.error("Wrong type"); } @@ -143,6 +157,7 @@ define([ var fromHash = nextId ? hashes[nextId].hash : config.onlyoffice.lastHash; // msgIndex = -1; + cb() showVersion(); if (ooMessages[id]) { @@ -150,17 +165,19 @@ define([ loading = false; return void config.onCheckpoint(cp); } + // getMessages(fromHash, toHash, cpIndex, sortedCp, cp, id, config, fillOO, $share, function (err, messages) { + // if (err) { + // return; + // } + // }); - getMessages(fromHash, toHash, cpIndex, sortedCp, cp, id, config, fillOO, $share, function (err, messages) { - if (err) { - return; - } - }); + }; + console.log("oom cp", ooCheckpoints, hashes) - getMessages(config.onlyoffice.lastHash, 'NONE', cpIndex, sortedCp, undefined, -1, config, fillOO, $share, function (err, messages) { + getMessages(config.onlyoffice.lastHash, 'NONE', cpIndex, sortedCp, undefined, -1, config, fillOO, $share, hashes, function (err, messages) { if (err) { console.error(err); return; @@ -181,10 +198,6 @@ define([ var $fastPrev, $fastNext, $next, $prev; - var getId = function () { - var cps = sortedCp.length; - return sortedCp[cps-1] || -1; - }; update = function () { var cps = sortedCp.length; @@ -227,15 +240,29 @@ define([ }; + var msgs var prev = function () { - var id = getId(); - var msgs = ooMessages[id]; - var cp = ooCheckpoints[id]; - var queue = msgs.slice(0, msgIndex); - config.onPatchBack(cp, queue, newlyLoaded); - newlyLoaded = false - showVersion(); - msgIndex--; + loadMoreOOHistory(function() { + console.log("ooms!", msgs?.length, msgIndex) + + if (Math.abs(msgIndex) > msgs?.length) { + id-- + msgIndex = ooMessages[id].length + } + + msgs = ooMessages[id]; + cp = hashes[id-1] ? hashes[id-1] : {} + console.log("ooms!2", id, hashes, cp) + + var queue = msgs.slice(0, msgIndex); + // console.log("ooms!", ooMessages, id, cp, ooCheckpoints, hashes, msgs, msgIndex, queue) + + config.onPatchBack(cp, queue); + showVersion(); + msgIndex--; + + }); + }; @@ -343,7 +370,7 @@ define([ $prev.click(function () { // if (loading) { return; } loading = true; - loadMoreOOHistory(); + // loadMoreOOHistory(); prev(); update(); }); diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index c7688469f..81b607ebd 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -1073,6 +1073,7 @@ define([ const getInitialChanges = function() { const changes = []; + console.log("oom2", ooChannel.queue) if (content.version > 2) { ooChannel.queue.forEach(function (data) { @@ -1084,6 +1085,7 @@ define([ var last = ooChannel.queue.pop(); if (last) { ooChannel.lastHash = last.hash; } } + console.log("oom2", changes) return changes }; @@ -2145,6 +2147,7 @@ define([ const createOOConfig = function(blob, file, lock, fromContent, lang, force) { const url = URL.createObjectURL(blob); + console.log("beep blob", blob, url) let username = Util.find(privateData, ['integrationConfig', 'user', 'name']) || metadataMgr.getUserData().name || Messages.anonymous; @@ -2911,12 +2914,15 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null try { const {blob, fileType} = await loadLastDocument(cp); if (!keepQueue) { ooChannel.queue = []; } + console.log("beep1", ooChannel.queue, cp, blob) resetData(blob, fileType); } catch (e) { var file = getFileType(); var type = common.getMetadataMgr().getPrivateData().ooType; var blob = loadInitDocument(type, true); if (!keepQueue) { ooChannel.queue = []; } + console.log("beep2", ooChannel.queue, blob) + resetData(blob, file); } }; @@ -2968,6 +2974,8 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null }); ooChannel.historyLastHash = ooChannel.lastHash; ooChannel.currentIndex = ooChannel.cpIndex; + console.log("beep - 3") + loadCp(lastCp, true); }); }; @@ -3137,13 +3145,9 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null }; var onCheckpoint = function (cp) { // We want to load a checkpoint: - loadCp(cp); + loadCp(cp, true); }; - var onPatchBack = function (cp, msgs, newlyLoaded) { - var originalHistory - if (newlyLoaded) { - originalHistory = ooChannel.queue - } + var onPatchBack = function (cp, msgs) { msgsFormatted = [] msgs.forEach(function(msg) { var parsedMsg = JSON.parse(msg.msg); @@ -3159,7 +3163,11 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null }) ooChannel.queue = msgsFormatted; + console.log("oom", msgsFormatted, ooChannel.queue) + setTimeout(() => { loadCp(cp, true); + }, 100); + }; var setHistoryMode = function (bool) { if (bool) { @@ -3174,6 +3182,8 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null // Fill the queue and then load the last CP rtChannel.getHistory(function () { var lastCp = getLastCp(); + console.log("beep - 2") + loadCp(lastCp, true); }); }; From 7cb1e8d64d5045dc2745b7b528da179c2f3bcd7c Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Thu, 11 Sep 2025 15:42:35 +0200 Subject: [PATCH 10/51] forward and backward checkpoints --- www/common/onlyoffice/history.js | 41 ++++++++++++++++---------------- www/common/onlyoffice/inner.js | 11 --------- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 3137c39e1..c2795f3b4 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -129,8 +129,6 @@ define([ // We want to load a checkpoint (or initial state) var loadMoreOOHistory = function (cb) { - console.log("oomessages!", ooMessages) - if (!Array.isArray(sortedCp)) { return void console.error("Wrong type"); } var cp = {}; @@ -175,7 +173,6 @@ define([ }; - console.log("oom cp", ooCheckpoints, hashes) getMessages(config.onlyoffice.lastHash, 'NONE', cpIndex, sortedCp, undefined, -1, config, fillOO, $share, hashes, function (err, messages) { if (err) { @@ -215,22 +212,31 @@ define([ $fastNext.prop('disabled', 'disabled'); } var id = getId(); - var msgs = (ooMessages[id] || []).length; - var v = getVersion() - if (msgIndex >= (msgs-1)) { + if (msgIndex === -1 && cps === id) { $next.prop('disabled', 'disabled'); } }; + var next = function () { - - var id = getId() if (!ooMessages[id]) { loading = false; return; } var msgs = ooMessages[id]; + msgIndex++; - if (msgIndex < 0) { + if (msgIndex < msgs.length && Math.sign(msgIndex) === -1) { var patch = msgs[msgs.length + msgIndex]; - } + } else if (msgIndex < msgs.length && Math.sign(msgIndex) === 1) { + var patch = msgs[msgIndex]; + } else if (msgIndex === msgs.length) { + id++; + var msgs = ooMessages[id]; + msgIndex = 0; + var patch = msgs[msgIndex]; + cp = hashes[id-1]; + config.onPatchBack(cp, [patch]); + return; + } + config.onPatch(patch) showVersion(); setTimeout(function () { @@ -240,23 +246,16 @@ define([ }; - var msgs + var msgs; var prev = function () { loadMoreOOHistory(function() { - console.log("ooms!", msgs?.length, msgIndex) - if (Math.abs(msgIndex) > msgs?.length) { - id-- - msgIndex = ooMessages[id].length + id--; + msgIndex = ooMessages[id].length; } - msgs = ooMessages[id]; - cp = hashes[id-1] ? hashes[id-1] : {} - console.log("ooms!2", id, hashes, cp) - + cp = hashes[id-1] ? hashes[id-1] : {}; var queue = msgs.slice(0, msgIndex); - // console.log("ooms!", ooMessages, id, cp, ooCheckpoints, hashes, msgs, msgIndex, queue) - config.onPatchBack(cp, queue); showVersion(); msgIndex--; diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 81b607ebd..4c97ce71f 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -1073,7 +1073,6 @@ define([ const getInitialChanges = function() { const changes = []; - console.log("oom2", ooChannel.queue) if (content.version > 2) { ooChannel.queue.forEach(function (data) { @@ -1085,7 +1084,6 @@ define([ var last = ooChannel.queue.pop(); if (last) { ooChannel.lastHash = last.hash; } } - console.log("oom2", changes) return changes }; @@ -2147,7 +2145,6 @@ define([ const createOOConfig = function(blob, file, lock, fromContent, lang, force) { const url = URL.createObjectURL(blob); - console.log("beep blob", blob, url) let username = Util.find(privateData, ['integrationConfig', 'user', 'name']) || metadataMgr.getUserData().name || Messages.anonymous; @@ -2914,15 +2911,12 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null try { const {blob, fileType} = await loadLastDocument(cp); if (!keepQueue) { ooChannel.queue = []; } - console.log("beep1", ooChannel.queue, cp, blob) resetData(blob, fileType); } catch (e) { var file = getFileType(); var type = common.getMetadataMgr().getPrivateData().ooType; var blob = loadInitDocument(type, true); if (!keepQueue) { ooChannel.queue = []; } - console.log("beep2", ooChannel.queue, blob) - resetData(blob, file); } }; @@ -2974,8 +2968,6 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null }); ooChannel.historyLastHash = ooChannel.lastHash; ooChannel.currentIndex = ooChannel.cpIndex; - console.log("beep - 3") - loadCp(lastCp, true); }); }; @@ -3163,7 +3155,6 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null }) ooChannel.queue = msgsFormatted; - console.log("oom", msgsFormatted, ooChannel.queue) setTimeout(() => { loadCp(cp, true); }, 100); @@ -3182,8 +3173,6 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null // Fill the queue and then load the last CP rtChannel.getHistory(function () { var lastCp = getLastCp(); - console.log("beep - 2") - loadCp(lastCp, true); }); }; From e9b76a67983cf6bb9768b2447ba7657f96bf8081 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Thu, 11 Sep 2025 17:50:07 +0200 Subject: [PATCH 11/51] fastprev --- www/common/onlyoffice/history.js | 78 ++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index c2795f3b4..ce98800c8 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -71,8 +71,13 @@ define([ var Messages = common.Messages; var getVersion = function () { - var major = sortedCp.length - cpIndex; - return major + '.' + (msgIndex+1); + if (Object.keys(ooMessages).length) { + var major = sortedCp.length - cpIndex; + console.log("version", major, sortedCp.length, cpIndex, msgIndex, ooMessages, id ) + // console.log("version2", ooMessages ) + return major-1 + '.' + (ooMessages[id]?.length-Math.abs(msgIndex+1)); + } + }; var showVersion = function (initial) { var v = getVersion(); @@ -134,14 +139,14 @@ define([ var cp = {}; // Get the checkpoint ID - var id = -1; - if (cpIndex < sortedCp.length) { - id = sortedCp[sortedCp.length - 1 - cpIndex]; - cp = hashes[id]; - } - var nextId = sortedCp[sortedCp.length - cpIndex]; + // var id = -1; + // if (cpIndex < sortedCp.length) { + // id = sortedCp[sortedCp.length - 1 - cpIndex]; + // cp = hashes[id]; + // } + // var nextId = sortedCp[sortedCp.length - cpIndex]; - ooCheckpoints[id] = cp; + // ooCheckpoints[id] = cp; // Get the history between "toHash" and "fromHash". This function is using // "getOlderHistory", that's why we start from the more recent hash @@ -150,26 +155,22 @@ define([ // We need to get all the patches between the current cp hash and the next cp hash // Current cp or initial hash (invalid hash ==> initial hash) - var toHash = cp?.hash || 'NONE'; - // Next cp or last hash - var fromHash = nextId ? hashes[nextId].hash : config.onlyoffice.lastHash; + // var toHash = cp?.hash || 'NONE'; + // // Next cp or last hash + // var fromHash = nextId ? hashes[nextId].hash : config.onlyoffice.lastHash; - // msgIndex = -1; - cb() + console.log("hashes,", cb) + if (cb) { + cb() + } + showVersion(); - if (ooMessages[id]) { + if (ooMessages[id] || id === 0) { // Cp already loaded: reload OO loading = false; return void config.onCheckpoint(cp); } - // getMessages(fromHash, toHash, cpIndex, sortedCp, cp, id, config, fillOO, $share, function (err, messages) { - // if (err) { - // return; - // } - // }); - - }; @@ -210,22 +211,31 @@ define([ } if (cpIndex === 0) { $fastNext.prop('disabled', 'disabled'); - } - var id = getId(); + } if (msgIndex === -1 && cps === id) { $next.prop('disabled', 'disabled'); } + if (id === 0 && msgIndex === 0) { + $prev.prop('disabled', 'disabled'); + } }; var next = function () { - if (!ooMessages[id]) { loading = false; return; } - var msgs = ooMessages[id]; + if (!ooMessages[id] && (id !== 0 && id !== 0)) { loading = false; return; } + console.log("next", hashes, cpIndex, id, ooMessages, msgIndex) + + if (id === 0 && msgIndex === 0) { + id++ + msgIndex = -1 + } + var msgs = ooMessages[id]; msgIndex++; + if (msgIndex < msgs.length && Math.sign(msgIndex) === -1) { var patch = msgs[msgs.length + msgIndex]; - } else if (msgIndex < msgs.length && Math.sign(msgIndex) === 1) { + } else if (msgIndex < msgs.length && (Math.sign(msgIndex) === 1 || msgIndex === 0)) { var patch = msgs[msgIndex]; } else if (msgIndex === msgs.length) { id++; @@ -279,7 +289,7 @@ define([ var _next = h('button.cp-toolbar-history-next', { title: Messages.history_next }, [ h('i.fa.fa-step-forward') ]); - var _prev = h('button.cp-toolbar-history-previous', { title: Messages.history_next }, [ + var _prev = h('button.cp-toolbar-history-previous', { title: Messages.history_prev }, [ h('i.fa.fa-step-backward') ]); $fastPrev = $(fastPrev); @@ -369,7 +379,6 @@ define([ $prev.click(function () { // if (loading) { return; } loading = true; - // loadMoreOOHistory(); prev(); update(); }); @@ -385,11 +394,14 @@ define([ $fastPrev.click(function () { if (loading) { return; } loading = true; - if (msgIndex === -1) { - cpIndex++; - } + id = 0 + msgIndex = 0 + console.log("prev0", id, msgIndex) loadMoreOOHistory(); - update(); + setTimeout(function () { + update(); + }, 100); + }); onKeyDown = function (e) { var p = function () { e.preventDefault(); }; From a38ac1e19a39b73921a9008f54989eb8fcf7bec4 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 12 Sep 2025 12:59:30 +0200 Subject: [PATCH 12/51] WIP --- www/common/onlyoffice/history.js | 22 +++++++++++++++++++--- www/common/onlyoffice/inner.js | 13 +++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index ce98800c8..2f6e7dfac 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -27,6 +27,7 @@ define([ var ooMessages = {}; var ooCheckpoints = {}; + var currentMessages = {} var loading = false; var update = function () {}; var currentTime; @@ -57,6 +58,13 @@ define([ var preceding = index > 0 ? checkpoints[index - 1] : 1; ooMessages[index+1] = messages.slice(preceding-1, current-1) }); + var cpMessages = Object.values(ooMessages).flat().length; + var messageDiff = messages.length - cpMessages + if (messageDiff !== 0) { + currentMessages = messages.slice(-messageDiff) + + } + console.log("next fill", messageDiff, cpMessages, currentMessages, ooMessages, messages, hashes) update(); }; @@ -263,10 +271,18 @@ define([ id--; msgIndex = ooMessages[id].length; } + console.log("prev", ooMessages, hashes, id, Object.keys(hashes).length > id, hashes[Object.keys(hashes).length].length === 0, hashes[Object.keys(hashes).length], Math.abs(msgIndex) === -1, msgIndex) msgs = ooMessages[id]; - cp = hashes[id-1] ? hashes[id-1] : {}; - var queue = msgs.slice(0, msgIndex); - config.onPatchBack(cp, queue); + if (Object.keys(hashes).length > id && ooMessages[Object.keys(hashes).length].length === 0 && Math.sign(msgIndex) === -1) { + console.log("kurwa", currentMessages, msgIndex) + cp = hashes[id+1] + config.onPatchBack(cp, currentMessages.slice(0, msgIndex)) + } else { + cp = hashes[id-1] ? hashes[id-1] : {}; + var queue = msgs.slice(0, msgIndex); + config.onPatchBack(cp, queue); + } + showVersion(); msgIndex--; diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 4c97ce71f..1a83b2a0b 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -587,7 +587,7 @@ define([ blob.name = title || (metadataMgr.getMetadataLazy().title || file.doc) + '.' + file.type; var data = { hash: (APP.history || APP.template) ? ooChannel.historyLastHash : ooChannel.lastHash, - index: (APP.history || APP.template) ? ooChannel.currentIndex : ooChannel.cpIndex + index: ooChannel.cpIndex }; fixSheets(); @@ -1440,7 +1440,7 @@ define([ return; } - debug(obj, 'toOOClient'); + // debug(obj, 'toOOClient'); APP.docEditor.sendMessageToOO(obj); if (obj && obj.type === "saveChanges") { evIntegrationSave.fire(); @@ -1448,7 +1448,7 @@ define([ }; const fromOOHandler = function (obj) { - debug(obj, 'fromOOClient'); + // debug(obj, 'fromOOClient'); switch (obj.type) { case "auth": // Handled by onlyoffice-editor now @@ -3140,7 +3140,8 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null loadCp(cp, true); }; var onPatchBack = function (cp, msgs) { - msgsFormatted = [] + if (msgs) { + msgsFormatted = [] msgs.forEach(function(msg) { var parsedMsg = JSON.parse(msg.msg); @@ -3158,6 +3159,10 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null setTimeout(() => { loadCp(cp, true); }, 100); + } else { + loadCp(cp) + } + }; var setHistoryMode = function (bool) { From 7f25d91839343ec1044ef8ed92e01ccf7605620b Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 12 Sep 2025 23:08:56 +0200 Subject: [PATCH 13/51] wip --- www/common/onlyoffice/history.js | 82 +++++++++++++++++++------------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 2f6e7dfac..6408aa27b 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -230,30 +230,39 @@ define([ var next = function () { - if (!ooMessages[id] && (id !== 0 && id !== 0)) { loading = false; return; } - console.log("next", hashes, cpIndex, id, ooMessages, msgIndex) - - if (id === 0 && msgIndex === 0) { - id++ - msgIndex = -1 - } - var msgs = ooMessages[id]; - msgIndex++; - - if (msgIndex < msgs.length && Math.sign(msgIndex) === -1) { - var patch = msgs[msgs.length + msgIndex]; - } else if (msgIndex < msgs.length && (Math.sign(msgIndex) === 1 || msgIndex === 0)) { - var patch = msgs[msgIndex]; - } else if (msgIndex === msgs.length) { - id++; + //hashes + if (Object.keys(hashes).length) { + if (!ooMessages[id] && (id !== 0 && id !== 0)) { loading = false; return; } + // console.log("next", hashes, cpIndex, id, ooMessages, msgIndex) + console.log("next", currentMessages, msgIndex) + + if (id === 0 && msgIndex === 0) { + id++ + msgIndex = -1 + } var msgs = ooMessages[id]; - msgIndex = 0; - var patch = msgs[msgIndex]; - cp = hashes[id-1]; - config.onPatchBack(cp, [patch]); - return; - } + msgIndex++; + + if (msgIndex < msgs.length && Math.sign(msgIndex) === -1) { + var patch = msgs[msgs.length + msgIndex]; + } else if (msgIndex < msgs.length && (Math.sign(msgIndex) === 1 || msgIndex === 0)) { + var patch = msgs[msgIndex]; + } else if (msgIndex === msgs.length) { + id++; + var msgs = ooMessages[id]; + msgIndex = 0; + var patch = msgs[msgIndex]; + cp = hashes[id-1]; + config.onPatchBack(cp, [patch]); + return; + } + } else { + msgIndex++ + var patch = currentMessages[currentMessages.length + msgIndex] + + } + config.onPatch(patch) showVersion(); @@ -271,17 +280,26 @@ define([ id--; msgIndex = ooMessages[id].length; } - console.log("prev", ooMessages, hashes, id, Object.keys(hashes).length > id, hashes[Object.keys(hashes).length].length === 0, hashes[Object.keys(hashes).length], Math.abs(msgIndex) === -1, msgIndex) + // console.log("prev", ooMessages, hashes, id, Object.keys(hashes).length > id, hashes[Object.keys(hashes).length].length === 0, hashes[Object.keys(hashes).length], Math.abs(msgIndex) === -1, msgIndex) msgs = ooMessages[id]; - if (Object.keys(hashes).length > id && ooMessages[Object.keys(hashes).length].length === 0 && Math.sign(msgIndex) === -1) { - console.log("kurwa", currentMessages, msgIndex) - cp = hashes[id+1] - config.onPatchBack(cp, currentMessages.slice(0, msgIndex)) - } else { - cp = hashes[id-1] ? hashes[id-1] : {}; - var queue = msgs.slice(0, msgIndex); - config.onPatchBack(cp, queue); - } + console.log("prev", hashes, ooMessages, id, msgIndex, currentMessages) + // if (Object.keys(hashes).length > id && ooMessages[Object.keys(hashes).length].length === 0 && Math.sign(msgIndex) === -1) { + // cp = hashes[id+1] + // config.onPatchBack(cp, currentMessages.slice(0, msgIndex)) + // } else { + + //two hashes, no current msgs + if (Object.keys(hashes).length) { + cp = hashes[id-1] ? hashes[id-1] : {}; + var queue = msgs.slice(0, msgIndex); + config.onPatchBack(cp, queue); + //no hashes, current messages + } else { + var queue = currentMessages.slice(0, msgIndex) + config.onPatchBack({}, queue) + } + + // } showVersion(); msgIndex--; From 44d2fc86a05af47fe22dfcadc41459ad46785ad1 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Mon, 15 Sep 2025 18:21:08 +0200 Subject: [PATCH 14/51] wip --- www/common/onlyoffice/history.js | 120 +++++++++++++++++-------------- www/common/onlyoffice/inner.js | 7 +- 2 files changed, 72 insertions(+), 55 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 6408aa27b..2fa02ab93 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -23,6 +23,7 @@ define([ var cpIndex = -1; var msgIndex = -1; + var APP = window.APP var ooMessages = {}; @@ -34,13 +35,11 @@ define([ // Get an array of the checkpoint IDs sorted their patch index var hashes = config.onlyoffice.hashes; - var sortedCp = Object.keys(hashes).map(Number).sort(function (a, b) { - return hashes[a].index - hashes[b].index; - }); + var sortedCp = Object.keys(hashes).map(Number); var getId = function () { var cps = sortedCp.length; - return sortedCp[cps-1] || -1; + return sortedCp[cps-1] || 1; }; var id = getId(); @@ -60,11 +59,14 @@ define([ }); var cpMessages = Object.values(ooMessages).flat().length; var messageDiff = messages.length - cpMessages - if (messageDiff !== 0) { - currentMessages = messages.slice(-messageDiff) - + if (messageDiff !== 0 && cpMessages) { + var keys = Object.keys(ooMessages) + var currentM = parseInt(keys[keys.length - 1]); + ooMessages[currentM+1] = messages.slice(-messageDiff) + } else if (messageDiff !== 0 && !cpMessages) { + ooMessages[1] = messages } - console.log("next fill", messageDiff, cpMessages, currentMessages, ooMessages, messages, hashes) + console.log("next fill", messageDiff, cpMessages, ooMessages, messages, hashes) update(); }; @@ -81,7 +83,7 @@ define([ var getVersion = function () { if (Object.keys(ooMessages).length) { var major = sortedCp.length - cpIndex; - console.log("version", major, sortedCp.length, cpIndex, msgIndex, ooMessages, id ) + // console.log("version", major, sortedCp.length, cpIndex, msgIndex, ooMessages, id ) // console.log("version2", ooMessages ) return major-1 + '.' + (ooMessages[id]?.length-Math.abs(msgIndex+1)); } @@ -146,32 +148,9 @@ define([ var cp = {}; - // Get the checkpoint ID - // var id = -1; - // if (cpIndex < sortedCp.length) { - // id = sortedCp[sortedCp.length - 1 - cpIndex]; - // cp = hashes[id]; - // } - // var nextId = sortedCp[sortedCp.length - cpIndex]; - - // ooCheckpoints[id] = cp; - - // Get the history between "toHash" and "fromHash". This function is using - // "getOlderHistory", that's why we start from the more recent hash - // and we go back in time to an older hash - - // We need to get all the patches between the current cp hash and the next cp hash - - // Current cp or initial hash (invalid hash ==> initial hash) - // var toHash = cp?.hash || 'NONE'; - // // Next cp or last hash - // var fromHash = nextId ? hashes[nextId].hash : config.onlyoffice.lastHash; - - console.log("hashes,", cb) if (cb) { cb() } - showVersion(); if (ooMessages[id] || id === 0) { @@ -179,7 +158,6 @@ define([ loading = false; return void config.onCheckpoint(cp); } - }; @@ -192,6 +170,7 @@ define([ var onClose = function () { config.setHistory(false); }; var onRevert = function () { + APP.revert = true config.onRevert(); }; @@ -234,29 +213,52 @@ define([ //hashes if (Object.keys(hashes).length) { if (!ooMessages[id] && (id !== 0 && id !== 0)) { loading = false; return; } - // console.log("next", hashes, cpIndex, id, ooMessages, msgIndex) - console.log("next", currentMessages, msgIndex) + console.log("next", hashes, cpIndex, id, ooMessages, msgIndex, currentMessages) + // console.log("next", currentMessages, msgIndexm) if (id === 0 && msgIndex === 0) { id++ msgIndex = -1 } - var msgs = ooMessages[id]; - msgIndex++; + if (Object.keys(hashes).length === id && currentMessages.length) { + console.log("next!") + var msgs = currentMessages + msgIndex++; + } else { + console.log("next!?", id, ooMessages, msgIndex) + + var msgs = ooMessages[id+1]; + msgIndex++; + } + + // if (msgIndex-1 === msgs.length) { + // msgsid++ + // msgIndex = -1 + // } + if (msgIndex < msgs.length && Math.sign(msgIndex) === -1) { + console.log("next1") var patch = msgs[msgs.length + msgIndex]; } else if (msgIndex < msgs.length && (Math.sign(msgIndex) === 1 || msgIndex === 0)) { + console.log("next2", msgs) + // var cp = hashes[id] var patch = msgs[msgIndex]; + // config.onPatchBack(cp, [patch]); + // return } else if (msgIndex === msgs.length) { + console.log("next3") + id++; var msgs = ooMessages[id]; msgIndex = 0; var patch = msgs[msgIndex]; + // cp = hashes[id] cp = hashes[id-1]; config.onPatchBack(cp, [patch]); return; } + //no hashes, current msgs } else { msgIndex++ var patch = currentMessages[currentMessages.length + msgIndex] @@ -274,33 +276,43 @@ define([ }; var msgs; + var prev = function () { loadMoreOOHistory(function() { - if (Math.abs(msgIndex) > msgs?.length) { + console.log("PREV", id, msgIndex) + if (Math.abs(msgIndex) > msgs?.length || msgIndex === 0) { id--; - msgIndex = ooMessages[id].length; + console.log("prevhere", id, ooMessages) + msgIndex = ooMessages[id+1].length; } - // console.log("prev", ooMessages, hashes, id, Object.keys(hashes).length > id, hashes[Object.keys(hashes).length].length === 0, hashes[Object.keys(hashes).length], Math.abs(msgIndex) === -1, msgIndex) - msgs = ooMessages[id]; - console.log("prev", hashes, ooMessages, id, msgIndex, currentMessages) - // if (Object.keys(hashes).length > id && ooMessages[Object.keys(hashes).length].length === 0 && Math.sign(msgIndex) === -1) { - // cp = hashes[id+1] - // config.onPatchBack(cp, currentMessages.slice(0, msgIndex)) - // } else { - //two hashes, no current msgs - if (Object.keys(hashes).length) { + console.log("prev", hashes, ooMessages, id, msgIndex, currentMessages) + + //2CPs + CM + if (Object.keys(hashes).length && Object.keys(ooMessages).length > Object.keys(hashes).length) { + cp = hashes[id] ? hashes[id] : {}; + msgs = ooMessages[id+1]; + var queue = msgs.slice(0, msgIndex); + console.log("prev1", queue, msgs) + config.onPatchBack(cp, queue); + } + //2CPS + no CM + else if (Object.keys(hashes).length) { + console.log("prev2") cp = hashes[id-1] ? hashes[id-1] : {}; + msgs = ooMessages[id]; var queue = msgs.slice(0, msgIndex); config.onPatchBack(cp, queue); - //no hashes, current messages - } else { - var queue = currentMessages.slice(0, msgIndex) + } + + //no hashes, current messages + else if (!Object.keys(hashes).length) { + msgs = ooMessages[id] + console.log("here!", id, ooMessages) + var queue = msgs.slice(0, msgIndex) config.onPatchBack({}, queue) } - - // } - + showVersion(); msgIndex--; diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 1a83b2a0b..1a10f1eaf 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -585,10 +585,14 @@ define([ blob = blob || new Blob([text], {type: 'plain/text'}); var file = getFileType(); blob.name = title || (metadataMgr.getMetadataLazy().title || file.doc) + '.' + file.type; + console.log("FILL index", ooChannel) var data = { hash: (APP.history || APP.template) ? ooChannel.historyLastHash : ooChannel.lastHash, - index: ooChannel.cpIndex + index: APP.revert ? ooChannel.currentIndex : ooChannel.cpIndex }; + if (APP.revert) { + APP.revert = false; + } fixSheets(); if (!isLockedModal.modal) { @@ -607,6 +611,7 @@ define([ var noLogin = false; var makeCheckpoint = function (force, msgs) { + console.log("revert", APP.revert) if (APP.cantCheckpoint) { return; } // TOO_LARGE var locked = content.saveLock; From 6409496c6a5f6802d44e8c086ce985300dee80b4 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Wed, 17 Sep 2025 16:05:45 +0200 Subject: [PATCH 15/51] WIP --- www/common/onlyoffice/history.js | 149 +++++++++++++++---------------- www/common/onlyoffice/inner.js | 36 ++++---- 2 files changed, 91 insertions(+), 94 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 2fa02ab93..53e1979fb 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -209,62 +209,46 @@ define([ var next = function () { - - //hashes + msgIndex++; + msgs = ooMessages[id] if (Object.keys(hashes).length) { - if (!ooMessages[id] && (id !== 0 && id !== 0)) { loading = false; return; } - console.log("next", hashes, cpIndex, id, ooMessages, msgIndex, currentMessages) - // console.log("next", currentMessages, msgIndexm) - - if (id === 0 && msgIndex === 0) { - id++ - msgIndex = -1 - } - if (Object.keys(hashes).length === id && currentMessages.length) { - console.log("next!") - var msgs = currentMessages - msgIndex++; - } else { - console.log("next!?", id, ooMessages, msgIndex) - - var msgs = ooMessages[id+1]; - msgIndex++; - } - - // if (msgIndex-1 === msgs.length) { - // msgsid++ - // msgIndex = -1 - // } - - - if (msgIndex < msgs.length && Math.sign(msgIndex) === -1) { - console.log("next1") - var patch = msgs[msgs.length + msgIndex]; - } else if (msgIndex < msgs.length && (Math.sign(msgIndex) === 1 || msgIndex === 0)) { - console.log("next2", msgs) - // var cp = hashes[id] - var patch = msgs[msgIndex]; - // config.onPatchBack(cp, [patch]); - // return - } else if (msgIndex === msgs.length) { - console.log("next3") - + if (!ooMessages[id] && id !== 0) { loading = false; return; } + + if (id === 0 && msgIndex === 0|| msgIndex === msgs.length) { id++; - var msgs = ooMessages[id]; msgIndex = 0; - var patch = msgs[msgIndex]; - // cp = hashes[id] + console.log("next0") + + } + if (Object.keys(hashes).length && msgIndex === 0) { + + var patch = msgs[msgIndex]; cp = hashes[id-1]; + console.log("next1", hashes, ooMessages, id, msgIndex, cp) + config.onPatchBack(cp, [patch]); - return; - } - //no hashes, current msgs + } + else if (Object.keys(hashes).length && msgIndex > 0) { + console.log("next2", hashes, ooMessages, id, msgIndex) + + var patch = msgs[msgIndex]; + } + else if (Object.keys(hashes).length && Math.sign(msgIndex) === -1) { + if (Object.keys(ooMessages) > Object.keys(hashes) && !hashes[id+1]) { + msgs = ooMessages[id+1] + + } else { + msgs = ooMessages[id] + + } + console.log("next3", hashes, ooMessages, id, cpIndex, msgIndex) + // msgs = ooMessages[id+1] + + var patch = msgs[msgs.length + msgIndex]; + } } else { - msgIndex++ - var patch = currentMessages[currentMessages.length + msgIndex] - + var patch = msgs[msgs.length + msgIndex]; } - config.onPatch(patch) showVersion(); @@ -279,39 +263,50 @@ define([ var prev = function () { loadMoreOOHistory(function() { - console.log("PREV", id, msgIndex) - if (Math.abs(msgIndex) > msgs?.length || msgIndex === 0) { + if (Math.abs(msgIndex) > msgs?.length && id > 1 || msgIndex === 0 && id > 0) { id--; - console.log("prevhere", id, ooMessages) - msgIndex = ooMessages[id+1].length; + + if (id === 1 || id === 0) { + console.log("prev?") + + msgIndex = ooMessages[id+1].length-1; + + } else { + console.log("prev!") + msgIndex = ooMessages[id+1].length-2; + + } + console.log("prev0", id, ) } + if (Object.keys(hashes).length && Object.keys(ooMessages).length > Object.keys(hashes).length) { + console.log("prev1", hashes, ooMessages, id, msgIndex) + cp = hashes[id] ? hashes[id] : {}; + msgs = ooMessages[id+1]; + var queue = msgs.slice(0, msgIndex); + config.onPatchBack(cp, queue); + } + else if (Object.keys(hashes).length) { + console.log("prev2", hashes, ooMessages, id, msgIndex) - console.log("prev", hashes, ooMessages, id, msgIndex, currentMessages) - - //2CPs + CM - if (Object.keys(hashes).length && Object.keys(ooMessages).length > Object.keys(hashes).length) { - cp = hashes[id] ? hashes[id] : {}; - msgs = ooMessages[id+1]; - var queue = msgs.slice(0, msgIndex); - console.log("prev1", queue, msgs) - config.onPatchBack(cp, queue); + cp = hashes[id-1] ? hashes[id-1] : {}; + msgs = ooMessages[id]; + console.log("prev2.25", msgs.length) + if (msgIndex === msgs.length) { + msgIndex-- } - //2CPS + no CM - else if (Object.keys(hashes).length) { - console.log("prev2") - cp = hashes[id-1] ? hashes[id-1] : {}; - msgs = ooMessages[id]; - var queue = msgs.slice(0, msgIndex); - config.onPatchBack(cp, queue); - } + msgIndex = msgIndex === msgs.length ? msgIndex-- : msgIndex + console.log("prev2.5", hashes, ooMessages, id, msgIndex) - //no hashes, current messages - else if (!Object.keys(hashes).length) { - msgs = ooMessages[id] - console.log("here!", id, ooMessages) - var queue = msgs.slice(0, msgIndex) - config.onPatchBack({}, queue) - } + var queue = msgs.slice(0, msgIndex); + config.onPatchBack(cp, queue); + } + else if (!Object.keys(hashes).length) { + console.log("prev3", hashes, ooMessages, id, msgIndex) + + msgs = ooMessages[id] + var queue = msgs.slice(0, msgIndex) + config.onPatchBack({}, queue) + } showVersion(); msgIndex--; diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 1a10f1eaf..17f1c6297 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -1089,6 +1089,7 @@ define([ var last = ooChannel.queue.pop(); if (last) { ooChannel.lastHash = last.hash; } } + console.log(ooChannel.queue) return changes }; @@ -2209,7 +2210,7 @@ define([ c.forcesave = true; } - console.error('updated config', ooconfig); + // console.error('updated config', ooconfig); return ooconfig; }; @@ -3147,23 +3148,24 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null var onPatchBack = function (cp, msgs) { if (msgs) { msgsFormatted = [] - 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) + 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; - setTimeout(() => { - loadCp(cp, true); - }, 100); + }) + ooChannel.queue = msgsFormatted; + console.log("patch", ooChannel.queue) + setTimeout(() => { + loadCp(cp, true); + }, 100); } else { loadCp(cp) } From 5ba8baf39acbaea8b87f12240317047542533e96 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 19 Sep 2025 15:55:08 +0200 Subject: [PATCH 16/51] WIP --- www/common/onlyoffice/history.js | 41 +++++++++++++++++++++++++------- www/common/onlyoffice/inner.js | 22 ++++++++--------- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 53e1979fb..87a690a3b 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -198,10 +198,16 @@ define([ } if (cpIndex === 0) { $fastNext.prop('disabled', 'disabled'); - } - if (msgIndex === -1 && cps === id) { + } + var msgLength = Object.keys(ooMessages) + if (ooMessages[id].length === msgIndex-1) { $next.prop('disabled', 'disabled'); } + if ((id+1) === parseInt(msgLength[msgLength.length - 1]) && msgIndex === -1) { + console.log("hello") + // $next.prop('disabled', 'disabled'); + } + console.log("NEXT DISABLE", id, msgIndex, ooMessages[id].length === msgIndex-1, (id+1), msgLength[msgLength.length - 1], (id+1) === parseInt(msgLength[msgLength.length - 1]), msgIndex === -1) if (id === 0 && msgIndex === 0) { $prev.prop('disabled', 'disabled'); } @@ -213,32 +219,49 @@ define([ msgs = ooMessages[id] if (Object.keys(hashes).length) { if (!ooMessages[id] && id !== 0) { loading = false; return; } - - if (id === 0 && msgIndex === 0|| msgIndex === msgs.length) { + if (id === 0 && msgIndex === 0|| msgIndex === msgs?.length || id === 0 && ooMessages[id+1].length === msgIndex) { id++; msgIndex = 0; console.log("next0") } if (Object.keys(hashes).length && msgIndex === 0) { - - var patch = msgs[msgIndex]; - cp = hashes[id-1]; console.log("next1", hashes, ooMessages, id, msgIndex, cp) + msgs = ooMessages[id] + var patch = msgs[msgIndex]; + // cp = hashes[id-1]; + if (id === 1) { + cp = hashes[id]; + } else { + cp = hashes[id-1]; + } + config.onPatchBack(cp, [patch]); } else if (Object.keys(hashes).length && msgIndex > 0) { console.log("next2", hashes, ooMessages, id, msgIndex) - + if (id === 0) { + msgs = ooMessages[id+1] + } var patch = msgs[msgIndex]; } else if (Object.keys(hashes).length && Math.sign(msgIndex) === -1) { if (Object.keys(ooMessages) > Object.keys(hashes) && !hashes[id+1]) { msgs = ooMessages[id+1] + console.log("next3.25") - } else { + } + else if (Object.keys(ooMessages) > Object.keys(hashes) && !ooMessages[id+1].length) { + cp = hashes[id+1] + config.onPatchBack(cp) + id++ + return + } + else { msgs = ooMessages[id] + console.log("next3.5") + } console.log("next3", hashes, ooMessages, id, cpIndex, msgIndex) diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 17f1c6297..38704324a 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -1693,17 +1693,17 @@ define([ } break; case "cursor": - if (cursor && cursor.updateCursor) { - cursor.updateCursor({ - type: "cursor", - messages: [{ - cursor: obj.cursor, - time: +new Date(), - user: myUniqueOOId, - useridoriginal: myOOId - }] - }); - } + // if (cursor && cursor.updateCursor) { + // cursor.updateCursor({ + // type: "cursor", + // messages: [{ + // cursor: obj.cursor, + // time: +new Date(), + // user: myUniqueOOId, + // useridoriginal: myOOId + // }] + // }); + // } break; case "forceSaveStart": if (APP.integrationSave) { From 1be2eb109e7d977d8a991c58f0e24ee9c0bce624 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Sat, 20 Sep 2025 17:05:05 +0200 Subject: [PATCH 17/51] WIP --- www/common/onlyoffice/history.js | 164 +++++++++++------------------- www/common/sframe-common-outer.js | 20 ++-- 2 files changed, 70 insertions(+), 114 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 87a690a3b..1c6a3c346 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -36,19 +36,21 @@ define([ // Get an array of the checkpoint IDs sorted their patch index var hashes = config.onlyoffice.hashes; var sortedCp = Object.keys(hashes).map(Number); + var id var getId = function () { + id = Object.keys(ooMessages).length var cps = sortedCp.length; - return sortedCp[cps-1] || 1; + console.log("ooMSGID", ooMessages) + return id }; - var id = getId(); var endWithCp = sortedCp.length && config.onlyoffice.lastHash === hashes[sortedCp[sortedCp.length - 1]].hash; var fillOO = function (id, messages, ooCheckpoints) { - if (!id) { return; } + // if (!id) { return; } var checkpoints = [] Object.keys(ooCheckpoints).forEach(function(key) { checkpoints.push(ooCheckpoints[key].index) @@ -66,11 +68,17 @@ define([ } else if (messageDiff !== 0 && !cpMessages) { ooMessages[1] = messages } - console.log("next fill", messageDiff, cpMessages, ooMessages, messages, hashes) + id = id ? id : getId() update(); + console.log("next fill", id, ooMessages, messages, hashes) + }; + + + // var id = getId(); + if (endWithCp) { cpIndex = 0; } var $version, $time, $share; @@ -98,7 +106,7 @@ define([ var $pos = $hist.find('.cp-history-timeline-pos'); var cps = sortedCp.length; - var id = sortedCp[cps - cpIndex -1] || -1; + // var id = getId() if (!ooMessages[id]) { return; } var msgs = ooMessages[id]; var p = 100*((msgIndex+1) / (msgs.length)); @@ -199,15 +207,17 @@ define([ if (cpIndex === 0) { $fastNext.prop('disabled', 'disabled'); } - var msgLength = Object.keys(ooMessages) - if (ooMessages[id].length === msgIndex-1) { - $next.prop('disabled', 'disabled'); - } - if ((id+1) === parseInt(msgLength[msgLength.length - 1]) && msgIndex === -1) { - console.log("hello") - // $next.prop('disabled', 'disabled'); - } - console.log("NEXT DISABLE", id, msgIndex, ooMessages[id].length === msgIndex-1, (id+1), msgLength[msgLength.length - 1], (id+1) === parseInt(msgLength[msgLength.length - 1]), msgIndex === -1) + // var msgLength = Object.keys(ooMessages) + // if (ooMessages[id].length === msgIndex-1) { + // $next.prop('disabled', 'disabled'); + // } + // if (ooMessages[id].length && msgIndex === (msgIndex+1)) { + // console.log("hello") + // $next.prop('disabled', 'disabled'); + // } + // console.log("NEXT DISABLE", ooMessages[id], msgIndex) + + // console.log("NEXT DISABLE1", id, msgIndex, ooMessages[id].length === msgIndex-1, (id+1), msgLength[msgLength.length - 1], (id+1) === parseInt(msgLength[msgLength.length - 1]), msgIndex === -1) if (id === 0 && msgIndex === 0) { $prev.prop('disabled', 'disabled'); } @@ -218,57 +228,30 @@ define([ msgIndex++; msgs = ooMessages[id] if (Object.keys(hashes).length) { - if (!ooMessages[id] && id !== 0) { loading = false; return; } - if (id === 0 && msgIndex === 0|| msgIndex === msgs?.length || id === 0 && ooMessages[id+1].length === msgIndex) { - id++; - msgIndex = 0; - console.log("next0") - - } - if (Object.keys(hashes).length && msgIndex === 0) { - console.log("next1", hashes, ooMessages, id, msgIndex, cp) + if (msgIndex === 0) { + id++ msgs = ooMessages[id] - var patch = msgs[msgIndex]; - // cp = hashes[id-1]; - if (id === 1) { - cp = hashes[id]; - } else { - cp = hashes[id-1]; - } - - - config.onPatchBack(cp, [patch]); - } - else if (Object.keys(hashes).length && msgIndex > 0) { - console.log("next2", hashes, ooMessages, id, msgIndex) - if (id === 0) { - msgs = ooMessages[id+1] - } - var patch = msgs[msgIndex]; - } - else if (Object.keys(hashes).length && Math.sign(msgIndex) === -1) { - if (Object.keys(ooMessages) > Object.keys(hashes) && !hashes[id+1]) { - msgs = ooMessages[id+1] - console.log("next3.25") - - } - else if (Object.keys(ooMessages) > Object.keys(hashes) && !ooMessages[id+1].length) { - cp = hashes[id+1] - config.onPatchBack(cp) - id++ + if (msgs.length) { + msgIndex = -msgs.length + msgs = ooMessages[id] + var patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined + var cp = hashes[id-1] + config.onPatchBack(cp, [patch]) return + } else { + id++ + msgs = ooMessages[id] + + msgIndex = -msgs.length + var patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined + var cp = hashes[id-1] + + config.onPatchBack(cp, [patch]) } - else { - msgs = ooMessages[id] - console.log("next3.5") - - } - console.log("next3", hashes, ooMessages, id, cpIndex, msgIndex) - // msgs = ooMessages[id+1] - - var patch = msgs[msgs.length + msgIndex]; } + msgs = ooMessages[id] + var patch = msgs[msgs.length + msgIndex]; } else { var patch = msgs[msgs.length + msgIndex]; } @@ -286,57 +269,30 @@ define([ var prev = function () { loadMoreOOHistory(function() { - if (Math.abs(msgIndex) > msgs?.length && id > 1 || msgIndex === 0 && id > 0) { - id--; - - if (id === 1 || id === 0) { - console.log("prev?") - - msgIndex = ooMessages[id+1].length-1; - - } else { - console.log("prev!") - msgIndex = ooMessages[id+1].length-2; - - } - console.log("prev0", id, ) - } - if (Object.keys(hashes).length && Object.keys(ooMessages).length > Object.keys(hashes).length) { - console.log("prev1", hashes, ooMessages, id, msgIndex) - cp = hashes[id] ? hashes[id] : {}; - msgs = ooMessages[id+1]; - var queue = msgs.slice(0, msgIndex); - config.onPatchBack(cp, queue); - } - else if (Object.keys(hashes).length) { - console.log("prev2", hashes, ooMessages, id, msgIndex) - - cp = hashes[id-1] ? hashes[id-1] : {}; - msgs = ooMessages[id]; - console.log("prev2.25", msgs.length) - if (msgIndex === msgs.length) { - msgIndex-- - } - msgIndex = msgIndex === msgs.length ? msgIndex-- : msgIndex - console.log("prev2.5", hashes, ooMessages, id, msgIndex) - - var queue = msgs.slice(0, msgIndex); - config.onPatchBack(cp, queue); - } - else if (!Object.keys(hashes).length) { - console.log("prev3", hashes, ooMessages, id, msgIndex) - + if (!Object.keys(hashes).length) { msgs = ooMessages[id] var queue = msgs.slice(0, msgIndex) config.onPatchBack({}, queue) - } - + } else { + msgs = ooMessages[id] + if (msgs.length+1 === Math.abs(msgIndex) && id !== 0) { + id-- + msgIndex = -1 + msgs = ooMessages[id] + } + if (!msgs.length && msgIndex < -1) { + id-- + msgIndex = -1 + msgs = ooMessages[id] + } + var queue = msgs.slice(0, msgIndex) + var cp = hashes[id-1] + config.onPatchBack(cp, queue) + } showVersion(); msgIndex--; }); - - }; diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 5b5362dbb..090d1d7de 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -2026,16 +2026,16 @@ define([ }, cb); }); sframeChan.on('Q_CURSOR_OPENCHANNEL', function (data, cb) { - Cryptpad.universal.execCommand({ - type: 'cursor', - data: { - cmd: 'INIT_CURSOR', - data: { - channel: data, - secret: secret - } - } - }, cb); + // Cryptpad.universal.execCommand({ + // type: 'cursor', + // data: { + // cmd: 'INIT_CURSOR', + // data: { + // channel: data, + // secret: secret + // } + // } + // }, cb); }); Cryptpad.onTimeoutEvent.reg(function () { From d0e4f24e910b7a575df3667ee3de3d690dff9806 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Tue, 23 Sep 2025 17:36:14 +0200 Subject: [PATCH 18/51] refactor --- www/common/onlyoffice/history.js | 97 ++++++++++++++------------------ www/common/onlyoffice/inner.js | 28 ++++----- 2 files changed, 53 insertions(+), 72 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 1c6a3c346..5311818c8 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -23,12 +23,9 @@ define([ var cpIndex = -1; var msgIndex = -1; - var APP = window.APP - - + var APP = window.APP; var ooMessages = {}; var ooCheckpoints = {}; - var currentMessages = {} var loading = false; var update = function () {}; var currentTime; @@ -36,49 +33,38 @@ define([ // Get an array of the checkpoint IDs sorted their patch index var hashes = config.onlyoffice.hashes; var sortedCp = Object.keys(hashes).map(Number); - var id + var id; var getId = function () { - id = Object.keys(ooMessages).length - var cps = sortedCp.length; - console.log("ooMSGID", ooMessages) - return id + id = Object.keys(ooMessages).length; + return id; }; - var endWithCp = sortedCp.length && config.onlyoffice.lastHash === hashes[sortedCp[sortedCp.length - 1]].hash; var fillOO = function (id, messages, ooCheckpoints) { - // if (!id) { return; } - var checkpoints = [] + var checkpoints = []; Object.keys(ooCheckpoints).forEach(function(key) { - checkpoints.push(ooCheckpoints[key].index) + checkpoints.push(ooCheckpoints[key].index); }) checkpoints.forEach((current, index) => { var preceding = index > 0 ? checkpoints[index - 1] : 1; - ooMessages[index+1] = messages.slice(preceding-1, current-1) + ooMessages[index+1] = messages.slice(preceding-1, current-1); }); var cpMessages = Object.values(ooMessages).flat().length; - var messageDiff = messages.length - cpMessages + var messageDiff = messages.length - cpMessages; if (messageDiff !== 0 && cpMessages) { - var keys = Object.keys(ooMessages) + var keys = Object.keys(ooMessages); var currentM = parseInt(keys[keys.length - 1]); - ooMessages[currentM+1] = messages.slice(-messageDiff) + ooMessages[currentM+1] = messages.slice(-messageDiff); } else if (messageDiff !== 0 && !cpMessages) { - ooMessages[1] = messages + ooMessages[1] = messages; } - - id = id ? id : getId() + id = id ? id : getId(); update(); - console.log("next fill", id, ooMessages, messages, hashes) - }; - - - // var id = getId(); - if (endWithCp) { cpIndex = 0; } var $version, $time, $share; @@ -157,7 +143,7 @@ define([ var cp = {}; if (cb) { - cb() + cb(); } showVersion(); @@ -223,6 +209,13 @@ define([ } }; + var loadingFalse = function () { + setTimeout(function () { + $('iframe').blur(); + loading = false; + }, 200); + } + var next = function () { msgIndex++; @@ -237,6 +230,7 @@ define([ var patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined var cp = hashes[id-1] config.onPatchBack(cp, [patch]) + loadingFalse() return } else { id++ @@ -245,23 +239,20 @@ define([ msgIndex = -msgs.length var patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined var cp = hashes[id-1] - config.onPatchBack(cp, [patch]) } } msgs = ooMessages[id] + // var patch = msgs[msgs.length + msgIndex]; + } + // else { var patch = msgs[msgs.length + msgIndex]; - } else { - var patch = msgs[msgs.length + msgIndex]; - } + // } config.onPatch(patch) showVersion(); - setTimeout(function () { - $('iframe').blur(); - loading = false; - }, 200); + loadingFalse() }; @@ -269,30 +260,28 @@ define([ var prev = function () { loadMoreOOHistory(function() { + msgs = ooMessages[id]; if (!Object.keys(hashes).length) { - msgs = ooMessages[id] - var queue = msgs.slice(0, msgIndex) - config.onPatchBack({}, queue) + + var cp = {}; } else { - msgs = ooMessages[id] - if (msgs.length+1 === Math.abs(msgIndex) && id !== 0) { - id-- - msgIndex = -1 - msgs = ooMessages[id] + if ((msgs.length+1 === Math.abs(msgIndex) && id !== 0) || (!msgs.length && msgIndex < -1)) { + id--; + msgIndex = -1; + msgs = ooMessages[id]; } - if (!msgs.length && msgIndex < -1) { - id-- - msgIndex = -1 - msgs = ooMessages[id] - } - var queue = msgs.slice(0, msgIndex) - var cp = hashes[id-1] - config.onPatchBack(cp, queue) - } + var cp = hashes[id-1]; + console.log("prev", ooMessages, id, msgs, cp) + + } + var queue = msgs.slice(0, msgIndex); + console.log("prev0", ooMessages, id, msgs, cp, queue) + + config.onPatchBack(cp, queue); showVersion(); msgIndex--; - }); + loadingFalse(); }; @@ -397,7 +386,7 @@ define([ update(); }); $prev.click(function () { - // if (loading) { return; } + if (loading) { return; } loading = true; prev(); update(); diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 38704324a..377520882 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -556,7 +556,7 @@ define([ APP.oldCursor = d.GetSelectionState(); } } - if (APP.docEditor) { APP.docEditor.destroyEditor(); } // Kill the old editor + if (APP.docEditor && APP.docEditor.destroyEditor() ) { APP.docEditor.destroyEditor(); } // Kill the old editor $('iframe[name="frameEditor"]').after(h('div#cp-app-oo-placeholder-a')).remove(); ooLoaded = false; oldLocks = {}; @@ -568,7 +568,7 @@ define([ startOO(blob, type, true); }; - var saveToServer = function (blob, title, msgs) { + var saveToServer = function (blob, title) { if (APP.cantCheckpoint) { return; } // TOO_LARGE var text = !blob && getContent(); if (!text && !blob) { @@ -610,8 +610,7 @@ define([ var noLogin = false; - var makeCheckpoint = function (force, msgs) { - console.log("revert", APP.revert) + var makeCheckpoint = function (force) { if (APP.cantCheckpoint) { return; } // TOO_LARGE var locked = content.saveLock; @@ -647,7 +646,7 @@ define([ content.saveLock = myOOId; APP.onLocal(); APP.realtime.onSettle(function () { - saveToServer(null, null, msgs); + saveToServer(); }); } }; @@ -3130,12 +3129,12 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null if (!privateData.ooVersionHash) { (function () { /* add a history button */ - var commit = function (msgs) { + var commit = function () { // 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, msgs); + makeCheckpoint(true); }; var onPatch = function (patch) { // Patch on the current cp @@ -3147,7 +3146,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null }; var onPatchBack = function (cp, msgs) { if (msgs) { - msgsFormatted = [] + msgsFormatted = []; msgs.forEach(function(msg) { var parsedMsg = JSON.parse(msg.msg); @@ -3157,20 +3156,13 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null author: msg.author, time: msg.time }; - - msgsFormatted.push(formattedMsg) - + msgsFormatted.push(formattedMsg); }) ooChannel.queue = msgsFormatted; - console.log("patch", ooChannel.queue) - setTimeout(() => { - loadCp(cp, true); - }, 100); + loadCp(cp, true); } else { - loadCp(cp) + loadCp(cp); } - - }; var setHistoryMode = function (bool) { if (bool) { From 59092ebdedcc983feed84eead46935c252f13abe Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Tue, 23 Sep 2025 18:12:25 +0200 Subject: [PATCH 19/51] cleaning & refactoring --- www/common/onlyoffice/history.js | 51 ++++++++++--------------------- www/common/onlyoffice/inner.js | 26 ++++++++-------- www/common/sframe-common-outer.js | 20 ++++++------ 3 files changed, 40 insertions(+), 57 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 5311818c8..fa0189d92 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -219,41 +219,27 @@ define([ var next = function () { msgIndex++; - msgs = ooMessages[id] + msgs = ooMessages[id]; if (Object.keys(hashes).length) { if (msgIndex === 0) { - id++ - msgs = ooMessages[id] - if (msgs.length) { - msgIndex = -msgs.length - msgs = ooMessages[id] - var patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined - var cp = hashes[id-1] - config.onPatchBack(cp, [patch]) - loadingFalse() - return - } else { - id++ - msgs = ooMessages[id] - - msgIndex = -msgs.length - var patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined - var cp = hashes[id-1] - config.onPatchBack(cp, [patch]) - } - + id++; + msgs = ooMessages[id]; + if (!msgs.length) { + id++; + msgs = ooMessages[id]; + } + msgIndex = -msgs.length; + var patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined; + var cp = hashes[id-1]; + config.onPatchBack(cp, [patch]); + loadingFalse(); + return; } - msgs = ooMessages[id] - // var patch = msgs[msgs.length + msgIndex]; } - // else { - var patch = msgs[msgs.length + msgIndex]; - // } - - config.onPatch(patch) + var patch = msgs[msgs.length + msgIndex]; + config.onPatch(patch); showVersion(); - loadingFalse() - + loadingFalse(); }; var msgs; @@ -262,7 +248,6 @@ define([ loadMoreOOHistory(function() { msgs = ooMessages[id]; if (!Object.keys(hashes).length) { - var cp = {}; } else { if ((msgs.length+1 === Math.abs(msgIndex) && id !== 0) || (!msgs.length && msgIndex < -1)) { @@ -271,12 +256,8 @@ define([ msgs = ooMessages[id]; } var cp = hashes[id-1]; - console.log("prev", ooMessages, id, msgs, cp) - } var queue = msgs.slice(0, msgIndex); - console.log("prev0", ooMessages, id, msgs, cp, queue) - config.onPatchBack(cp, queue); showVersion(); msgIndex--; diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 377520882..30bfa9563 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -1692,17 +1692,17 @@ define([ } break; case "cursor": - // if (cursor && cursor.updateCursor) { - // cursor.updateCursor({ - // type: "cursor", - // messages: [{ - // cursor: obj.cursor, - // time: +new Date(), - // user: myUniqueOOId, - // useridoriginal: myOOId - // }] - // }); - // } + if (cursor && cursor.updateCursor) { + cursor.updateCursor({ + type: "cursor", + messages: [{ + cursor: obj.cursor, + time: +new Date(), + user: myUniqueOOId, + useridoriginal: myOOId + }] + }); + } break; case "forceSaveStart": if (APP.integrationSave) { @@ -3159,7 +3159,9 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null msgsFormatted.push(formattedMsg); }) ooChannel.queue = msgsFormatted; - loadCp(cp, true); + setTimeout(function () { + loadCp(cp, true); + }, 200); } else { loadCp(cp); } diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 090d1d7de..5b5362dbb 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -2026,16 +2026,16 @@ define([ }, cb); }); sframeChan.on('Q_CURSOR_OPENCHANNEL', function (data, cb) { - // Cryptpad.universal.execCommand({ - // type: 'cursor', - // data: { - // cmd: 'INIT_CURSOR', - // data: { - // channel: data, - // secret: secret - // } - // } - // }, cb); + Cryptpad.universal.execCommand({ + type: 'cursor', + data: { + cmd: 'INIT_CURSOR', + data: { + channel: data, + secret: secret + } + } + }, cb); }); Cryptpad.onTimeoutEvent.reg(function () { From 91091461791d606ed834f77c8204e00475f88e20 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Tue, 23 Sep 2025 21:34:30 +0200 Subject: [PATCH 20/51] version update --- www/common/onlyoffice/history.js | 56 ++++++++++++++------------------ www/common/onlyoffice/inner.js | 1 + 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index fa0189d92..4e6744273 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -17,6 +17,7 @@ define([ var $toolbar = config.$toolbar; var sframeChan = common.getSframeChannel(); History.readOnly = common.getMetadataMgr().getPrivateData().readOnly || !common.isLoggedIn(); + if (!config.onlyoffice || !config.setHistory || !config.onCheckpoint || !config.onPatch || !config.makeSnapshot) { throw new Error("Missing config element"); } @@ -74,25 +75,21 @@ define([ var $bottom = $toolbar.find('.cp-toolbar-bottom'); var Messages = common.Messages; - var getVersion = function () { + var getVersion = function (position) { if (Object.keys(ooMessages).length) { - var major = sortedCp.length - cpIndex; - // console.log("version", major, sortedCp.length, cpIndex, msgIndex, ooMessages, id ) - // console.log("version2", ooMessages ) - return major-1 + '.' + (ooMessages[id]?.length-Math.abs(msgIndex+1)); + var major = id === 0 ? 0 : id-1; + return major + '.' + position; } }; - var showVersion = function (initial) { - var v = getVersion(); + var showVersion = function (initial, position) { + var v = getVersion(position); if (initial) { v = Messages.oo_version_latest; } $version.text(Messages.oo_version + v); var $pos = $hist.find('.cp-history-timeline-pos'); - var cps = sortedCp.length; - // var id = getId() if (!ooMessages[id]) { return; } var msgs = ooMessages[id]; var p = 100*((msgIndex+1) / (msgs.length)); @@ -146,7 +143,6 @@ define([ cb(); } - showVersion(); if (ooMessages[id] || id === 0) { // Cp already loaded: reload OO loading = false; @@ -190,20 +186,13 @@ define([ if (cpIndex >= cps && msgIndex === 0) { $fastPrev.prop('disabled', 'disabled'); } - if (cpIndex === 0) { + var msgLength = Object.keys(ooMessages).length + if (id === msgLength) { $fastNext.prop('disabled', 'disabled'); + } + if (msgLength === id && msgIndex === -1) { + $next.prop('disabled', 'disabled'); } - // var msgLength = Object.keys(ooMessages) - // if (ooMessages[id].length === msgIndex-1) { - // $next.prop('disabled', 'disabled'); - // } - // if (ooMessages[id].length && msgIndex === (msgIndex+1)) { - // console.log("hello") - // $next.prop('disabled', 'disabled'); - // } - // console.log("NEXT DISABLE", ooMessages[id], msgIndex) - - // console.log("NEXT DISABLE1", id, msgIndex, ooMessages[id].length === msgIndex-1, (id+1), msgLength[msgLength.length - 1], (id+1) === parseInt(msgLength[msgLength.length - 1]), msgIndex === -1) if (id === 0 && msgIndex === 0) { $prev.prop('disabled', 'disabled'); } @@ -232,13 +221,14 @@ define([ var patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined; var cp = hashes[id-1]; config.onPatchBack(cp, [patch]); + showVersion(false, msgs.indexOf(patch)+1); loadingFalse(); return; } } var patch = msgs[msgs.length + msgIndex]; config.onPatch(patch); - showVersion(); + showVersion(false, msgs.indexOf(patch)+1); loadingFalse(); }; @@ -259,7 +249,7 @@ define([ } var queue = msgs.slice(0, msgIndex); config.onPatchBack(cp, queue); - showVersion(); + showVersion(false, queue.length); msgIndex--; }); loadingFalse(); @@ -376,20 +366,24 @@ define([ $fastNext.click(function () { if (loading) { return; } loading = true; - cpIndex--; - loadMoreOOHistory(); - update(); + id++; + var cp = hashes[id]; + config.loadCp(cp); + setTimeout(function () { + update(); + loading = false; + }, 100); }); // Go to next checkpoint $fastPrev.click(function () { if (loading) { return; } loading = true; - id = 0 - msgIndex = 0 - console.log("prev0", id, msgIndex) - loadMoreOOHistory(); + id--; + var cp = hashes[id]; + config.loadCp(cp); setTimeout(function () { update(); + loading = false; }, 100); }); diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 30bfa9563..d325cfaad 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -3233,6 +3233,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null var histConfig = { onPatch: onPatch, onPatchBack: onPatchBack, + loadCp: loadCp, onCheckpoint: onCheckpoint, onRevert: commit, setHistory: setHistoryMode, From fc9f8a5bbe95f598f3c5b722217dae51ccdcac7f Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Wed, 24 Sep 2025 14:36:43 +0200 Subject: [PATCH 21/51] wip --- www/common/onlyoffice/inner.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index d325cfaad..90ea2e1e2 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -548,7 +548,12 @@ define([ var app = common.getMetadataMgr().getPrivateData().ooType; var d; if (app === 'doc') { - d = editor.GetDocument().Document; + if (editor.GetDocument()) { + d = editor.GetDocument().Document + } else { + d = undefined + } + // d = editor.GetDocument() ? editor.GetDocument().Document : undefined; } else if (app === 'presentation') { d = editor.GetPresentation().Presentation; } @@ -585,7 +590,6 @@ define([ blob = blob || new Blob([text], {type: 'plain/text'}); var file = getFileType(); blob.name = title || (metadataMgr.getMetadataLazy().title || file.doc) + '.' + file.type; - console.log("FILL index", ooChannel) var data = { hash: (APP.history || APP.template) ? ooChannel.historyLastHash : ooChannel.lastHash, index: APP.revert ? ooChannel.currentIndex : ooChannel.cpIndex @@ -1088,9 +1092,7 @@ define([ var last = ooChannel.queue.pop(); if (last) { ooChannel.lastHash = last.hash; } } - console.log(ooChannel.queue) - return changes - + return changes; }; const onAuth = function () { From c7499efdc21692599d89c92eea567acfb6512f53 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Wed, 24 Sep 2025 17:44:33 +0200 Subject: [PATCH 22/51] wip --- www/common/onlyoffice/history.js | 98 +++++++++++++++++++------------- 1 file changed, 59 insertions(+), 39 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 4e6744273..5824138f3 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -36,34 +36,44 @@ define([ var sortedCp = Object.keys(hashes).map(Number); var id; + var sortedCp = Object.keys(hashes).map(Number).sort(function (a, b) { + return hashes[a].index - hashes[b].index; + }); + + console.log("hashescp", sortedCp) var getId = function () { - id = Object.keys(ooMessages).length; - return id; + var cps = sortedCp.length; + id = sortedCp[cps -1] || -1; + return sortedCp[cps -1] || -1; }; var endWithCp = sortedCp.length && config.onlyoffice.lastHash === hashes[sortedCp[sortedCp.length - 1]].hash; var fillOO = function (id, messages, ooCheckpoints) { - var checkpoints = []; - Object.keys(ooCheckpoints).forEach(function(key) { - checkpoints.push(ooCheckpoints[key].index); - }) - checkpoints.forEach((current, index) => { - var preceding = index > 0 ? checkpoints[index - 1] : 1; - ooMessages[index+1] = messages.slice(preceding-1, current-1); - }); - var cpMessages = Object.values(ooMessages).flat().length; - var messageDiff = messages.length - cpMessages; - if (messageDiff !== 0 && cpMessages) { - var keys = Object.keys(ooMessages); - var currentM = parseInt(keys[keys.length - 1]); - ooMessages[currentM+1] = messages.slice(-messageDiff); - } else if (messageDiff !== 0 && !cpMessages) { - ooMessages[1] = messages; - } - id = id ? id : getId(); + if (!id) { return; } + if (ooMessages[id]) { return; } + ooMessages[id] = messages; update(); + // var checkpoints = []; + // Object.keys(ooCheckpoints).forEach(function(key) { + // checkpoints.push(ooCheckpoints[key].index); + // }) + // checkpoints.forEach((current, index) => { + // var preceding = index > 0 ? checkpoints[index - 1] : 1; + // ooMessages[index+1] = messages.slice(preceding-1, current-1); + // }); + // var cpMessages = Object.values(ooMessages).flat().length; + // var messageDiff = messages.length - cpMessages; + // if (messageDiff !== 0 && cpMessages) { + // var keys = Object.keys(ooMessages); + // var currentM = parseInt(keys[keys.length - 1]); + // ooMessages[currentM+1] = messages.slice(-messageDiff); + // } else if (messageDiff !== 0 && !cpMessages) { + // ooMessages[1] = messages; + // } + // id = id ? id : getId(); + // update(); }; if (endWithCp) { cpIndex = 0; } @@ -120,7 +130,7 @@ define([ let initialCp = cpIndex === sortedCp.length || cp ? !cp?.hash : undefined; const messages = (data.messages || []).slice(initialCp ? 0 : 1); - + console.log("hashmes", messages) if (config.debug) { console.log(data.messages); } @@ -136,27 +146,34 @@ define([ // We want to load a checkpoint (or initial state) var loadMoreOOHistory = function (cb) { if (!Array.isArray(sortedCp)) { return void console.error("Wrong type"); } + var id = id ? id : getId() - var cp = {}; + console.log("hashes2", hashes) + var cp = hashes[id]; if (cb) { cb(); } - if (ooMessages[id] || id === 0) { - // Cp already loaded: reload OO - loading = false; - return void config.onCheckpoint(cp); - } + // if (ooMessages[id] || id === 0) { + // // Cp already loaded: reload OO + // loading = false; + // return void config.onCheckpoint(cp); + // } + + console.log("hashes", config.onlyoffice, hashes, id) + getMessages(config.onlyoffice.lastHash, cp.hash, cpIndex, sortedCp, undefined, -1, config, fillOO, $share, hashes, function (err, messages) { + if (err) { + console.error(err); + return; + } + }); }; - getMessages(config.onlyoffice.lastHash, 'NONE', cpIndex, sortedCp, undefined, -1, config, fillOO, $share, hashes, function (err, messages) { - if (err) { - console.error(err); - return; - } - }); + loadMoreOOHistory() + + var onClose = function () { config.setHistory(false); }; var onRevert = function () { @@ -236,16 +253,19 @@ define([ var prev = function () { loadMoreOOHistory(function() { + console.log("hash messages", ooMessages, id, msgIndex) msgs = ooMessages[id]; + + if (!Object.keys(hashes).length) { var cp = {}; } else { - if ((msgs.length+1 === Math.abs(msgIndex) && id !== 0) || (!msgs.length && msgIndex < -1)) { - id--; - msgIndex = -1; - msgs = ooMessages[id]; - } - var cp = hashes[id-1]; + // if ((msgs.length+1 === Math.abs(msgIndex) && id !== 0) || (!msgs.length && msgIndex < -1)) { + // id--; + // msgIndex = -1; + // msgs = ooMessages[id]; + // } + var cp = hashes[id]; } var queue = msgs.slice(0, msgIndex); config.onPatchBack(cp, queue); From 65a7141912440554666736849d39bff5c9630930 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Wed, 24 Sep 2025 22:23:34 +0200 Subject: [PATCH 23/51] wip --- www/common/onlyoffice/history.js | 160 ++++++++++++++++++------------- 1 file changed, 96 insertions(+), 64 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 5824138f3..76a8f2fe9 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -50,9 +50,14 @@ define([ var endWithCp = sortedCp.length && config.onlyoffice.lastHash === hashes[sortedCp[sortedCp.length - 1]].hash; - var fillOO = function (id, messages, ooCheckpoints) { - if (!id) { return; } - if (ooMessages[id]) { return; } + var fillOO = function (messages, ooCheckpoints) { + console.log("fill1", id) + // if (!id) { return; } + console.log("fill2") + + // if (ooMessages[id]) { return; } + console.log("fill3") + ooMessages = {} ooMessages[id] = messages; update(); // var checkpoints = []; @@ -111,7 +116,7 @@ define([ else { $time.text(''); } }; - function getMessages(fromHash, toHash, cpIndex, sortedCp, cp, id, config, fillOO, $share, ooCheckpoints, callback) { + function getMessages(fromHash, toHash, cpIndex, sortedCp, cp, config, fillOO, $share, ooCheckpoints, callback) { sframeChan.query('Q_GET_HISTORY_RANGE', { channel: config.onlyoffice.channel, lastKnownHash: fromHash, @@ -128,14 +133,15 @@ define([ } let initialCp = cpIndex === sortedCp.length || cp ? !cp?.hash : undefined; - + // console.log("hash messss", data) const messages = (data.messages || []).slice(initialCp ? 0 : 1); - console.log("hashmes", messages) + // console.log("hashmes", messages) if (config.debug) { console.log(data.messages); } - id = getId() - fillOO(id, messages, ooCheckpoints); + console.log("ID HERE", id) + id = id !== undefined ? id : getId(); + fillOO(messages, ooCheckpoints); loading = false; // $share.show(); @@ -145,29 +151,34 @@ define([ // We want to load a checkpoint (or initial state) var loadMoreOOHistory = function (cb) { - if (!Array.isArray(sortedCp)) { return void console.error("Wrong type"); } - var id = id ? id : getId() - - console.log("hashes2", hashes) - var cp = hashes[id]; - - if (cb) { - cb(); - } - - // if (ooMessages[id] || id === 0) { - // // Cp already loaded: reload OO - // loading = false; - // return void config.onCheckpoint(cp); - // } - - console.log("hashes", config.onlyoffice, hashes, id) - getMessages(config.onlyoffice.lastHash, cp.hash, cpIndex, sortedCp, undefined, -1, config, fillOO, $share, hashes, function (err, messages) { - if (err) { - console.error(err); - return; + return new Promise((resolve, reject) => { // Return a promise + if (!Array.isArray(sortedCp)) { + console.error("Wrong type"); + return resolve(); } - }); + + console.log("id", id); + id = id !== undefined ? id : getId(); + console.log("id2", id); + + var cp = hashes[id]; + var nextId = hashes[id+1] ? hashes[id+1] : undefined; + + var toHash = nextId ? nextId.hash : config.onlyoffice.lastHash; + var fromHash = cp?.hash || 'NONE'; + + console.log("hashes", config.onlyoffice.lastHash, nextId?.hash, hashes, id); + console.log("hashes2", toHash, fromHash); + + getMessages(toHash, fromHash, cpIndex, sortedCp, undefined, config, fillOO, $share, hashes, function (err, messages) { + if (err) { + console.error(err); + reject(err); + return; + } + resolve(); // Resolve when done + }); + }); }; @@ -207,9 +218,9 @@ define([ if (id === msgLength) { $fastNext.prop('disabled', 'disabled'); } - if (msgLength === id && msgIndex === -1) { - $next.prop('disabled', 'disabled'); - } + // if (msgLength === id && msgIndex === -1) { + // $next.prop('disabled', 'disabled'); + // } if (id === 0 && msgIndex === 0) { $prev.prop('disabled', 'disabled'); } @@ -227,19 +238,35 @@ define([ msgIndex++; msgs = ooMessages[id]; if (Object.keys(hashes).length) { + console.log("next", ooMessages, id, msgs, msgIndex) if (msgIndex === 0) { id++; - msgs = ooMessages[id]; - if (!msgs.length) { - id++; + loadMoreOOHistory().then(() => { msgs = ooMessages[id]; - } - msgIndex = -msgs.length; - var patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined; - var cp = hashes[id-1]; - config.onPatchBack(cp, [patch]); - showVersion(false, msgs.indexOf(patch)+1); - loadingFalse(); + console.log("next2", ooMessages, id, msgs, msgIndex) + + if (!msgs.length) { + id++; + msgIndex = -1 + config.loadCp(hashes[id]); + return loadMoreOOHistory().then(() => { + loadingFalse(); + return; + }); + } + + msgIndex = -msgs.length; + console.log("next3", ooMessages, id, msgs, msgIndex) + + var patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined; + var cp = hashes[id-1]; + config.onPatchBack(cp, [patch]); + showVersion(false, msgs.indexOf(patch)+1); + loadingFalse(); + }).catch(err => { + console.error(err); + loadingFalse(); + }); return; } } @@ -252,26 +279,30 @@ define([ var msgs; var prev = function () { - loadMoreOOHistory(function() { - console.log("hash messages", ooMessages, id, msgIndex) - msgs = ooMessages[id]; - - - if (!Object.keys(hashes).length) { - var cp = {}; - } else { - // if ((msgs.length+1 === Math.abs(msgIndex) && id !== 0) || (!msgs.length && msgIndex < -1)) { - // id--; - // msgIndex = -1; - // msgs = ooMessages[id]; - // } - var cp = hashes[id]; - } - var queue = msgs.slice(0, msgIndex); - config.onPatchBack(cp, queue); - showVersion(false, queue.length); - msgIndex--; - }); + msgs = ooMessages[id]; + if (!Object.keys(hashes).length) { + var cp = {}; + } else { + if (msgs.length+1 === Math.abs(msgIndex) && id !== 0 || !msgs.length) { + id--; + msgIndex = -1; + loadMoreOOHistory().then(() => { + msgs = ooMessages[id]; + var queue = msgs.slice(0, msgIndex); + var cp = hashes[id]; + config.onPatchBack(cp, queue); + showVersion(false, queue.length); + msgIndex--; + loadingFalse(); + }); + return; + } + var cp = hashes[id]; + } + var queue = msgs.slice(0, msgIndex); + config.onPatchBack(cp, queue); + showVersion(false, queue.length); + msgIndex--; loadingFalse(); }; @@ -295,7 +326,8 @@ define([ $fastPrev = $(fastPrev); $prev = $(_prev); $fastNext = $(fastNext).prop('disabled', 'disabled'); - $next = $(_next).prop('disabled', 'disabled'); + $next = $(_next) + // .prop('disabled', 'disabled'); var pos = h('span.cp-history-timeline-pos.fa.fa-caret-down'); From 553322142e25afcd62bd5f622aa0667c04eda0f7 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 26 Sep 2025 11:23:44 +0200 Subject: [PATCH 24/51] wip --- www/common/onlyoffice/history.js | 135 +++++++++++++++++++------------ www/common/onlyoffice/inner.js | 2 + 2 files changed, 84 insertions(+), 53 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 76a8f2fe9..4d3b2b740 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -40,26 +40,23 @@ define([ return hashes[a].index - hashes[b].index; }); - console.log("hashescp", sortedCp) var getId = function () { var cps = sortedCp.length; id = sortedCp[cps -1] || -1; - return sortedCp[cps -1] || -1; + return id; }; var endWithCp = sortedCp.length && config.onlyoffice.lastHash === hashes[sortedCp[sortedCp.length - 1]].hash; var fillOO = function (messages, ooCheckpoints) { - console.log("fill1", id) // if (!id) { return; } - console.log("fill2") // if (ooMessages[id]) { return; } - console.log("fill3") + ooMessages = {} ooMessages[id] = messages; - update(); + // update(); // var checkpoints = []; // Object.keys(ooCheckpoints).forEach(function(key) { // checkpoints.push(ooCheckpoints[key].index); @@ -133,14 +130,12 @@ define([ } let initialCp = cpIndex === sortedCp.length || cp ? !cp?.hash : undefined; - // console.log("hash messss", data) const messages = (data.messages || []).slice(initialCp ? 0 : 1); - // console.log("hashmes", messages) if (config.debug) { console.log(data.messages); } - console.log("ID HERE", id) id = id !== undefined ? id : getId(); + console.log("nextmsgs", id) fillOO(messages, ooCheckpoints); loading = false; // $share.show(); @@ -151,40 +146,38 @@ define([ // We want to load a checkpoint (or initial state) var loadMoreOOHistory = function (cb) { - return new Promise((resolve, reject) => { // Return a promise + return new Promise((resolve, reject) => { if (!Array.isArray(sortedCp)) { console.error("Wrong type"); return resolve(); } - console.log("id", id); id = id !== undefined ? id : getId(); - console.log("id2", id); - var cp = hashes[id]; + if (ooMessages[id-1] && !ooMessages[id-1].length) { + var cp = hashes[id-1]; + } else { + var cp = hashes[id]; + } + var nextId = hashes[id+1] ? hashes[id+1] : undefined; var toHash = nextId ? nextId.hash : config.onlyoffice.lastHash; var fromHash = cp?.hash || 'NONE'; - console.log("hashes", config.onlyoffice.lastHash, nextId?.hash, hashes, id); - console.log("hashes2", toHash, fromHash); - getMessages(toHash, fromHash, cpIndex, sortedCp, undefined, config, fillOO, $share, hashes, function (err, messages) { if (err) { console.error(err); reject(err); return; } - resolve(); // Resolve when done + resolve(); }); }); }; - loadMoreOOHistory() - - + loadMoreOOHistory(); var onClose = function () { config.setHistory(false); }; var onRevert = function () { @@ -201,8 +194,9 @@ define([ var $fastPrev, $fastNext, $next, $prev; + var position; - update = function () { + update = function (prev) { var cps = sortedCp.length; $fastPrev.show(); $next.show(); @@ -211,19 +205,25 @@ define([ $hist.find('.cp-toolbar-history-next, .cp-toolbar-history-previous') .prop('disabled', ''); + var msgLength = Object.keys(hashes).length + if (cpIndex >= cps && msgIndex === 0) { $fastPrev.prop('disabled', 'disabled'); } - var msgLength = Object.keys(ooMessages).length - if (id === msgLength) { - $fastNext.prop('disabled', 'disabled'); - } - // if (msgLength === id && msgIndex === -1) { - // $next.prop('disabled', 'disabled'); - // } if (id === 0 && msgIndex === 0) { $prev.prop('disabled', 'disabled'); } + var msgs = ooMessages[id]?.length; + console.log("disable", ooMessages, id, msgLength, msgIndex, (id === msgLength || id === msgLength-1), !prev) + console.log("disable2", (id === msgLength) && msgIndex === -1, (id === msgLength || id === msgLength-1), msgIndex === -1, !prev, id === msgLength || (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev) + + if ((id === msgLength) && msgIndex === -1 || (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev) { + $fastNext.prop('disabled', 'disabled'); + } + if ((id === msgLength) && msgIndex === -1 || id === -1 && msgIndex === -1 || (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev) { + $next.prop('disabled', 'disabled'); + } + }; var loadingFalse = function () { @@ -233,47 +233,49 @@ define([ }, 200); } - - var next = function () { + var next = async function () { msgIndex++; msgs = ooMessages[id]; if (Object.keys(hashes).length) { - console.log("next", ooMessages, id, msgs, msgIndex) if (msgIndex === 0) { id++; loadMoreOOHistory().then(() => { msgs = ooMessages[id]; - console.log("next2", ooMessages, id, msgs, msgIndex) - if (!msgs.length) { id++; - msgIndex = -1 config.loadCp(hashes[id]); return loadMoreOOHistory().then(() => { loadingFalse(); + msgIndex = -ooMessages[id].length-1; + showVersion(false, msgs.indexOf(patch)+1); + // position = msgs.indexOf(patch)+1 + console.log("disable patch", msgIndex) + return; }); } - - msgIndex = -msgs.length; - console.log("next3", ooMessages, id, msgs, msgIndex) + console.log("next5", hashes, ooMessages, id, msgIndex) + msgIndex = -msgs.length; var patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined; - var cp = hashes[id-1]; + var cp = hashes[id]; config.onPatchBack(cp, [patch]); showVersion(false, msgs.indexOf(patch)+1); loadingFalse(); - }).catch(err => { - console.error(err); - loadingFalse(); - }); + console.log("disable patch", msgIndex) + + // position = msgs.indexOf(patch)+1 + }) return; } } var patch = msgs[msgs.length + msgIndex]; config.onPatch(patch); + console.log("disable patch", msgIndex) + showVersion(false, msgs.indexOf(patch)+1); loadingFalse(); + // position = msgs.indexOf(patch)+1 }; var msgs; @@ -299,6 +301,7 @@ define([ } var cp = hashes[id]; } + console.log("prev disable", hashes, ooMessages, id, ) var queue = msgs.slice(0, msgIndex); config.onPatchBack(cp, queue); showVersion(false, queue.length); @@ -326,7 +329,7 @@ define([ $fastPrev = $(fastPrev); $prev = $(_prev); $fastNext = $(fastNext).prop('disabled', 'disabled'); - $next = $(_next) + $next = $(_next).prop('disabled', 'disabled'); // .prop('disabled', 'disabled'); @@ -405,38 +408,64 @@ define([ $next.click(function () { // if (loading) { return; } loading = true; - next(); - update(); + next().then( + update() + ); + // update(); }); $prev.click(function () { if (loading) { return; } loading = true; prev(); - update(); + update(true) }); // Go to previous checkpoint $fastNext.click(function () { if (loading) { return; } loading = true; - id++; - var cp = hashes[id]; - config.loadCp(cp); + if (id < Object.keys(hashes).length) { + id++; + var cp = hashes[id]; + config.loadCp(cp); + } else { + var cp = hashes[id]; + var msgs = ooMessages[id] + msgIndex = -1 + config.onPatchBack(cp, msgs); + console.log("disablemsgs", hashes, ooMessages, id, msgs) + + } + + setTimeout(function () { + console.log("disable fastnext", id, ooMessages, msgIndex) + update(); loading = false; }, 100); }); // Go to next checkpoint $fastPrev.click(function () { + console.log("disable fastprev3", id, ooMessages, msgIndex) + if (loading) { return; } loading = true; - id--; + if (!ooMessages[id].length) { + id--; + } var cp = hashes[id]; + console.log("disable fastprev2", id, ooMessages, msgIndex) + config.loadCp(cp); - setTimeout(function () { - update(); + // setTimeout(function () { + console.log("disable fastprev", id, ooMessages, msgIndex) + update(true); + loadMoreOOHistory().then(() => { + var msgs = ooMessages[id]; + msgIndex = -msgs.length-1; + }); loading = false; - }, 100); + // }, 100); }); onKeyDown = function (e) { diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 90ea2e1e2..4461b0d93 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -1081,6 +1081,7 @@ define([ const getInitialChanges = function() { const changes = []; + console.log("prev ooq", ooChannel.queue) if (content.version > 2) { ooChannel.queue.forEach(function (data) { @@ -1092,6 +1093,7 @@ define([ var last = ooChannel.queue.pop(); if (last) { ooChannel.lastHash = last.hash; } } + console.log("prev changes", changes) return changes; }; From 8a11c871e8ad47155651d4e486efae0a84cf12d5 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 26 Sep 2025 11:25:32 +0200 Subject: [PATCH 25/51] wip --- www/common/onlyoffice/history.js | 40 +++++--------------------------- www/common/onlyoffice/inner.js | 3 --- 2 files changed, 6 insertions(+), 37 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 4d3b2b740..2a8955b07 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -135,7 +135,6 @@ define([ console.log(data.messages); } id = id !== undefined ? id : getId(); - console.log("nextmsgs", id) fillOO(messages, ooCheckpoints); loading = false; // $share.show(); @@ -194,8 +193,6 @@ define([ var $fastPrev, $fastNext, $next, $prev; - var position; - update = function (prev) { var cps = sortedCp.length; $fastPrev.show(); @@ -214,8 +211,6 @@ define([ $prev.prop('disabled', 'disabled'); } var msgs = ooMessages[id]?.length; - console.log("disable", ooMessages, id, msgLength, msgIndex, (id === msgLength || id === msgLength-1), !prev) - console.log("disable2", (id === msgLength) && msgIndex === -1, (id === msgLength || id === msgLength-1), msgIndex === -1, !prev, id === msgLength || (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev) if ((id === msgLength) && msgIndex === -1 || (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev) { $fastNext.prop('disabled', 'disabled'); @@ -248,34 +243,23 @@ define([ loadingFalse(); msgIndex = -ooMessages[id].length-1; showVersion(false, msgs.indexOf(patch)+1); - // position = msgs.indexOf(patch)+1 - console.log("disable patch", msgIndex) - return; }); } - console.log("next5", hashes, ooMessages, id, msgIndex) - msgIndex = -msgs.length; var patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined; var cp = hashes[id]; config.onPatchBack(cp, [patch]); showVersion(false, msgs.indexOf(patch)+1); loadingFalse(); - console.log("disable patch", msgIndex) - - // position = msgs.indexOf(patch)+1 }) return; } } var patch = msgs[msgs.length + msgIndex]; config.onPatch(patch); - console.log("disable patch", msgIndex) - showVersion(false, msgs.indexOf(patch)+1); loadingFalse(); - // position = msgs.indexOf(patch)+1 }; var msgs; @@ -301,7 +285,6 @@ define([ } var cp = hashes[id]; } - console.log("prev disable", hashes, ooMessages, id, ) var queue = msgs.slice(0, msgIndex); config.onPatchBack(cp, queue); showVersion(false, queue.length); @@ -432,40 +415,29 @@ define([ var msgs = ooMessages[id] msgIndex = -1 config.onPatchBack(cp, msgs); - console.log("disablemsgs", hashes, ooMessages, id, msgs) - } setTimeout(function () { - console.log("disable fastnext", id, ooMessages, msgIndex) - update(); loading = false; }, 100); }); // Go to next checkpoint $fastPrev.click(function () { - console.log("disable fastprev3", id, ooMessages, msgIndex) - if (loading) { return; } loading = true; if (!ooMessages[id].length) { id--; } var cp = hashes[id]; - console.log("disable fastprev2", id, ooMessages, msgIndex) - config.loadCp(cp); - // setTimeout(function () { - console.log("disable fastprev", id, ooMessages, msgIndex) - update(true); - loadMoreOOHistory().then(() => { - var msgs = ooMessages[id]; - msgIndex = -msgs.length-1; - }); - loading = false; - // }, 100); + update(true); + loadMoreOOHistory().then(() => { + var msgs = ooMessages[id]; + msgIndex = -msgs.length-1; + }); + loading = false; }); onKeyDown = function (e) { diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 4461b0d93..d97333546 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -1081,8 +1081,6 @@ define([ const getInitialChanges = function() { const changes = []; - console.log("prev ooq", ooChannel.queue) - if (content.version > 2) { ooChannel.queue.forEach(function (data) { Array.prototype.push.apply(changes, data.msg.changes); @@ -1093,7 +1091,6 @@ define([ var last = ooChannel.queue.pop(); if (last) { ooChannel.lastHash = last.hash; } } - console.log("prev changes", changes) return changes; }; From 0074ca9b3d4029c7cb793df295d5fbf4b4c2ebc8 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 10 Oct 2025 18:18:22 +0200 Subject: [PATCH 26/51] wip --- www/common/onlyoffice/history.js | 67 +++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 2a8955b07..92efd66b9 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -204,18 +204,28 @@ define([ var msgLength = Object.keys(hashes).length - if (cpIndex >= cps && msgIndex === 0) { + if ((id === -1 || id === 0) && ooMessages[id].length+1 === Math.abs(msgIndex)) { $fastPrev.prop('disabled', 'disabled'); } - if (id === 0 && msgIndex === 0) { + if ((id === -1 || id === 0) && ooMessages[id].length+1 === Math.abs(msgIndex)) { $prev.prop('disabled', 'disabled'); } var msgs = ooMessages[id]?.length; - if ((id === msgLength) && msgIndex === -1 || (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev) { + if ((id === msgLength) && msgIndex === -1 || (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev || + parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) { $fastNext.prop('disabled', 'disabled'); - } - if ((id === msgLength) && msgIndex === -1 || id === -1 && msgIndex === -1 || (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev) { + } + console.log(hashes, ooMessages, id, msgIndex) + // console.log(Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1] === id && !ooMessages[id].length, + // Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1], id, typeof id, + // typeof parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]), + // parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id, + // ooMessages[id]) + + console.log(("next update", id === msgLength) && msgIndex === -1, id === -1 && msgIndex === -1, (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev || Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1] === id && !ooMessages[id].length) + if ((id === msgLength) && msgIndex === -1 || id === -1 && msgIndex === -1 || (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev || + parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) { $next.prop('disabled', 'disabled'); } @@ -229,6 +239,8 @@ define([ } var next = async function () { + console.log("next1", hashes, id, ooMessages, msgIndex) + msgIndex++; msgs = ooMessages[id]; if (Object.keys(hashes).length) { @@ -254,17 +266,21 @@ define([ loadingFalse(); }) return; - } + } } var patch = msgs[msgs.length + msgIndex]; + console.log("next0.5", msgIndex, msgs, msgs.length + msgIndex) config.onPatch(patch); showVersion(false, msgs.indexOf(patch)+1); loadingFalse(); + console.log("next2", hashes, id, ooMessages) + }; var msgs; var prev = function () { + console.log("prev1", hashes, id, ooMessages) msgs = ooMessages[id]; if (!Object.keys(hashes).length) { var cp = {}; @@ -290,6 +306,8 @@ define([ showVersion(false, queue.length); msgIndex--; loadingFalse(); + console.log("prev2", hashes, id, ooMessages) + }; @@ -405,17 +423,36 @@ define([ // Go to previous checkpoint $fastNext.click(function () { if (loading) { return; } + console.log("fastnext1", hashes, id, ooMessages) loading = true; - if (id < Object.keys(hashes).length) { - id++; - var cp = hashes[id]; - config.loadCp(cp); + if (id < Object.keys(hashes).length && id !== -1) { + if (id === -1) { + id = 1; + } else { + id++; + } + loadMoreOOHistory().then(() => { + var cp = hashes[id]; + loadMoreOOHistory() + config.loadCp(cp); + console.log("fastnext0.5", hashes, id, ooMessages, msgIndex) + setTimeout(function () { + update(); + loading = false; + }, 100); + return; + + + }); + } else { var cp = hashes[id]; var msgs = ooMessages[id] msgIndex = -1 config.onPatchBack(cp, msgs); } + console.log("fastnext2", hashes, id, ooMessages, msgIndex) + setTimeout(function () { @@ -425,20 +462,24 @@ define([ }); // Go to next checkpoint $fastPrev.click(function () { + console.log("fastprev1", hashes, id, ooMessages, msgIndex) + if (loading) { return; } loading = true; - if (!ooMessages[id].length) { + if (!ooMessages[id].length || ooMessages[id].length+1 === Math.abs(msgIndex)) { id--; } var cp = hashes[id]; config.loadCp(cp); - update(true); loadMoreOOHistory().then(() => { var msgs = ooMessages[id]; msgIndex = -msgs.length-1; + update(true); + }); loading = false; - + console.log("fastprev2", hashes, id, ooMessages) + }); onKeyDown = function (e) { var p = function () { e.preventDefault(); }; From 50a03b2c68ac007e3e5b4f8d121c04953ef9eb41 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Wed, 22 Oct 2025 10:06:20 +0200 Subject: [PATCH 27/51] wip --- www/common/onlyoffice/history.js | 78 +++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 92efd66b9..24425d860 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -28,7 +28,6 @@ define([ var ooMessages = {}; var ooCheckpoints = {}; var loading = false; - var update = function () {}; var currentTime; // Get an array of the checkpoint IDs sorted their patch index @@ -193,7 +192,7 @@ define([ var $fastPrev, $fastNext, $next, $prev; - update = function (prev) { + var update = function (prev) { var cps = sortedCp.length; $fastPrev.show(); $next.show(); @@ -204,10 +203,10 @@ define([ var msgLength = Object.keys(hashes).length - if ((id === -1 || id === 0) && ooMessages[id].length+1 === Math.abs(msgIndex)) { + if ((id === -1 || id === 0) && ooMessages[id]?.length+1 === Math.abs(msgIndex)) { $fastPrev.prop('disabled', 'disabled'); } - if ((id === -1 || id === 0) && ooMessages[id].length+1 === Math.abs(msgIndex)) { + if ((id === -1 || id === 0) && ooMessages[id]?.length+1 === Math.abs(msgIndex)) { $prev.prop('disabled', 'disabled'); } var msgs = ooMessages[id]?.length; @@ -216,17 +215,34 @@ define([ parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) { $fastNext.prop('disabled', 'disabled'); } - console.log(hashes, ooMessages, id, msgIndex) + console.log(hashes, ooMessages, id, msgIndex, msgLength) + // console.log(Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1] === id && !ooMessages[id].length, // Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1], id, typeof id, // typeof parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]), // parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id, // ooMessages[id]) - console.log(("next update", id === msgLength) && msgIndex === -1, id === -1 && msgIndex === -1, (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev || Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1] === id && !ooMessages[id].length) - if ((id === msgLength) && msgIndex === -1 || id === -1 && msgIndex === -1 || (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev || - parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) { - $next.prop('disabled', 'disabled'); + // console.log((id === msgLength) && msgIndex === -1, + // id === -1 && msgIndex === -1, + // (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev || Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1] === id && !ooMessages[id].length) + + // console.log((id === msgLength) && msgIndex === -1, + // id === -1 && msgIndex === -1, + // (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev, + // Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1] === id && !ooMessages[id].length) + var lastHash = hashes[hashes.length-1] + console.log((id === msgLength) && msgIndex === -1, + id === -1 && msgIndex === -1, + // (id === msgLength || id+1 === msgLength) && !ooMessages[id].length && msgIndex === -1 && !prev, + parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && + parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) + + if ((id === msgLength) && msgIndex === -1 || id === -1 && msgIndex === -1 || + // id === msgLength && msgIndex === -1 && !prev || + parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && + parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) { + // $next.prop('disabled', 'disabled'); } }; @@ -239,10 +255,10 @@ define([ } var next = async function () { - console.log("next1", hashes, id, ooMessages, msgIndex) - msgIndex++; msgs = ooMessages[id]; + // console.log("next1", hashes, id, ooMessages, msgIndex, msgs) + if (Object.keys(hashes).length) { if (msgIndex === 0) { id++; @@ -267,20 +283,25 @@ define([ }) return; } + else if (Math.abs(msgIndex) > msgs.length) { + msgIndex = -msgs.length + } + } + else if (msgs.length + msgIndex === -1) { + msgIndex++ + } var patch = msgs[msgs.length + msgIndex]; - console.log("next0.5", msgIndex, msgs, msgs.length + msgIndex) + // console.log("next0.5", hashes, id, ooMessages, msgIndex, msgs, msgs.length + msgIndex) config.onPatch(patch); showVersion(false, msgs.indexOf(patch)+1); loadingFalse(); - console.log("next2", hashes, id, ooMessages) - }; var msgs; var prev = function () { - console.log("prev1", hashes, id, ooMessages) + // console.log("prev1", hashes, id, ooMessages) msgs = ooMessages[id]; if (!Object.keys(hashes).length) { var cp = {}; @@ -306,7 +327,7 @@ define([ showVersion(false, queue.length); msgIndex--; loadingFalse(); - console.log("prev2", hashes, id, ooMessages) + // console.log("prev2", hashes, id, ooMessages) }; @@ -423,7 +444,7 @@ define([ // Go to previous checkpoint $fastNext.click(function () { if (loading) { return; } - console.log("fastnext1", hashes, id, ooMessages) + // console.log("fastnext1", hashes, id, ooMessages, msgIndex) loading = true; if (id < Object.keys(hashes).length && id !== -1) { if (id === -1) { @@ -435,7 +456,9 @@ define([ var cp = hashes[id]; loadMoreOOHistory() config.loadCp(cp); - console.log("fastnext0.5", hashes, id, ooMessages, msgIndex) + msgs = ooMessages[id] + msgIndex = -msgs.length-1 + // console.log("fastnext0.5", hashes, id, ooMessages, msgIndex) setTimeout(function () { update(); loading = false; @@ -450,35 +473,38 @@ define([ var msgs = ooMessages[id] msgIndex = -1 config.onPatchBack(cp, msgs); + } - console.log("fastnext2", hashes, id, ooMessages, msgIndex) + // console.log("fastnext2", hashes, id, ooMessages, msgIndex) - - setTimeout(function () { - update(); + update('end'); loading = false; }, 100); }); // Go to next checkpoint $fastPrev.click(function () { - console.log("fastprev1", hashes, id, ooMessages, msgIndex) + // console.log("fastprev1", hashes, id, ooMessages, msgIndex) if (loading) { return; } loading = true; - if (!ooMessages[id].length || ooMessages[id].length+1 === Math.abs(msgIndex)) { + if (!ooMessages[id].length || ooMessages[id].length+2 === Math.abs(msgIndex)) { + // console.log("fastprev0.25", ooMessages[id].length+1, Math.abs(msgIndex)) id--; } + // console.log("fastprev0.5", ooMessages[id]?.length+1, Math.abs(msgIndex)) + var cp = hashes[id]; config.loadCp(cp); loadMoreOOHistory().then(() => { var msgs = ooMessages[id]; - msgIndex = -msgs.length-1; + msgIndex = -msgs.length-2; update(true); + // console.log("fastprev2", hashes, id, ooMessages, msgIndex) + }); loading = false; - console.log("fastprev2", hashes, id, ooMessages) }); onKeyDown = function (e) { From 5ea99379547d4ba7ba169e1b2b4efe0f5d5901a1 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Wed, 22 Oct 2025 15:45:57 +0200 Subject: [PATCH 28/51] wip --- www/common/onlyoffice/history.js | 38 +++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 24425d860..6a591ee29 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -215,7 +215,7 @@ define([ parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) { $fastNext.prop('disabled', 'disabled'); } - console.log(hashes, ooMessages, id, msgIndex, msgLength) + // console.log(hashes, ooMessages, id, msgIndex, msgLength) // console.log(Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1] === id && !ooMessages[id].length, // Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1], id, typeof id, @@ -232,11 +232,11 @@ define([ // (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev, // Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1] === id && !ooMessages[id].length) var lastHash = hashes[hashes.length-1] - console.log((id === msgLength) && msgIndex === -1, - id === -1 && msgIndex === -1, - // (id === msgLength || id+1 === msgLength) && !ooMessages[id].length && msgIndex === -1 && !prev, - parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && - parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) + // console.log((id === msgLength) && msgIndex === -1, + // id === -1 && msgIndex === -1, + // // (id === msgLength || id+1 === msgLength) && !ooMessages[id].length && msgIndex === -1 && !prev, + // parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && + // parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) if ((id === msgLength) && msgIndex === -1 || id === -1 && msgIndex === -1 || // id === msgLength && msgIndex === -1 && !prev || @@ -257,8 +257,7 @@ define([ var next = async function () { msgIndex++; msgs = ooMessages[id]; - // console.log("next1", hashes, id, ooMessages, msgIndex, msgs) - + console.log("next1", hashes, id, ooMessages, msgIndex, msgs) if (Object.keys(hashes).length) { if (msgIndex === 0) { id++; @@ -283,16 +282,19 @@ define([ }) return; } - else if (Math.abs(msgIndex) > msgs.length) { + else if (Math.abs(msgIndex) > msgs.length && msgs.length) { msgIndex = -msgs.length } - + else if (!msgs.length) { + config.onPatchBack(hashes[id+1]); + return + } } else if (msgs.length + msgIndex === -1) { - msgIndex++ - } + msgIndex++ + } var patch = msgs[msgs.length + msgIndex]; - // console.log("next0.5", hashes, id, ooMessages, msgIndex, msgs, msgs.length + msgIndex) + console.log("next0.5", hashes, id, ooMessages, msgIndex, msgs, msgs.length + msgIndex) config.onPatch(patch); showVersion(false, msgs.indexOf(patch)+1); loadingFalse(); @@ -301,12 +303,12 @@ define([ var msgs; var prev = function () { - // console.log("prev1", hashes, id, ooMessages) + console.log("prev1", hashes, id, ooMessages, msgIndex) msgs = ooMessages[id]; if (!Object.keys(hashes).length) { var cp = {}; } else { - if (msgs.length+1 === Math.abs(msgIndex) && id !== 0 || !msgs.length) { + if (msgs.length+1 === Math.abs(msgIndex) && id !== 0 || !msgs.length || msgs.length-Math.abs(msgIndex) === -2) { id--; msgIndex = -1; loadMoreOOHistory().then(() => { @@ -327,7 +329,7 @@ define([ showVersion(false, queue.length); msgIndex--; loadingFalse(); - // console.log("prev2", hashes, id, ooMessages) + console.log("prev2", hashes, id, ooMessages, msgIndex) }; @@ -484,7 +486,7 @@ define([ }); // Go to next checkpoint $fastPrev.click(function () { - // console.log("fastprev1", hashes, id, ooMessages, msgIndex) + console.log("fastprev1", hashes, id, ooMessages, msgIndex) if (loading) { return; } loading = true; @@ -500,7 +502,7 @@ define([ var msgs = ooMessages[id]; msgIndex = -msgs.length-2; update(true); - // console.log("fastprev2", hashes, id, ooMessages, msgIndex) + console.log("fastprev2", hashes, id, ooMessages, msgIndex) }); From ccb9a0d8045016423634a37a0ef0fa3ef0ca895d Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Thu, 23 Oct 2025 10:06:49 +0200 Subject: [PATCH 29/51] wip --- www/common/onlyoffice/history.js | 47 ++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 6a591ee29..e69753175 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -129,7 +129,8 @@ define([ } let initialCp = cpIndex === sortedCp.length || cp ? !cp?.hash : undefined; - const messages = (data.messages || []).slice(initialCp ? 0 : 1); + const messages = (data.messages || []).slice(initialCp || APP.ooconfig.documentType === 'spreadsheet' ? 0 : 1); + if (config.debug) { console.log(data.messages); } @@ -203,19 +204,28 @@ define([ var msgLength = Object.keys(hashes).length - if ((id === -1 || id === 0) && ooMessages[id]?.length+1 === Math.abs(msgIndex)) { + if ( + (id === -1 || id === 0) && Math.abs(msgIndex) === ooMessages[id]?.length+2) { $fastPrev.prop('disabled', 'disabled'); } - if ((id === -1 || id === 0) && ooMessages[id]?.length+1 === Math.abs(msgIndex)) { + if ((id === -1 || id === 0) && ooMessages[id]?.length+2=== Math.abs(msgIndex) + ) { $prev.prop('disabled', 'disabled'); } var msgs = ooMessages[id]?.length; - if ((id === msgLength) && msgIndex === -1 || (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev || + if ((id === msgLength) && msgIndex === -1 || + id === -1 && msgIndex === -1 || + Object.keys(hashes)[0] === id && msgIndex === -1 && !prev || parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) { $fastNext.prop('disabled', 'disabled'); } - // console.log(hashes, ooMessages, id, msgIndex, msgLength) + + // console.log((id === msgLength) && msgIndex === -1, + // id === -1 && msgIndex === -1, + // (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev, + // parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) + console.log(hashes, ooMessages, id, msgIndex, msgLength, ooMessages[id].length) // console.log(Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1] === id && !ooMessages[id].length, // Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1], id, typeof id, @@ -231,18 +241,25 @@ define([ // id === -1 && msgIndex === -1, // (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev, // Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1] === id && !ooMessages[id].length) + var lastHash = hashes[hashes.length-1] - // console.log((id === msgLength) && msgIndex === -1, - // id === -1 && msgIndex === -1, - // // (id === msgLength || id+1 === msgLength) && !ooMessages[id].length && msgIndex === -1 && !prev, - // parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && - // parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) - if ((id === msgLength) && msgIndex === -1 || id === -1 && msgIndex === -1 || + console.log( + Object.keys(hashes)[0] === id && msgIndex === -1, + (id === msgLength) && msgIndex === -1, + id === -1 && msgIndex === -1, + // (id === msgLength || id+1 === msgLength) && !ooMessages[id].length && msgIndex === -1 && !prev, + parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && + parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) + + if ( + Object.keys(hashes)[0]=== id && msgIndex === -1 || + (id === msgLength) && msgIndex === -1 || + id === -1 && msgIndex === -1 || // id === msgLength && msgIndex === -1 && !prev || parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) { - // $next.prop('disabled', 'disabled'); + $next.prop('disabled', 'disabled'); } }; @@ -446,7 +463,7 @@ define([ // Go to previous checkpoint $fastNext.click(function () { if (loading) { return; } - // console.log("fastnext1", hashes, id, ooMessages, msgIndex) + console.log("fastnext1", hashes, id, ooMessages, msgIndex) loading = true; if (id < Object.keys(hashes).length && id !== -1) { if (id === -1) { @@ -460,7 +477,7 @@ define([ config.loadCp(cp); msgs = ooMessages[id] msgIndex = -msgs.length-1 - // console.log("fastnext0.5", hashes, id, ooMessages, msgIndex) + console.log("fastnext0.5", hashes, id, ooMessages, msgIndex) setTimeout(function () { update(); loading = false; @@ -477,7 +494,7 @@ define([ config.onPatchBack(cp, msgs); } - // console.log("fastnext2", hashes, id, ooMessages, msgIndex) + console.log("fastnext2", hashes, id, ooMessages, msgIndex) setTimeout(function () { update('end'); From 31b72f2c87d1314759c7001852a46a4012692055 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 24 Oct 2025 11:10:04 +0200 Subject: [PATCH 30/51] wip --- .../src/less2/include/toolbar-history.less | 5 +- www/common/onlyoffice/history.js | 96 ++++++++----------- 2 files changed, 45 insertions(+), 56 deletions(-) diff --git a/customize.dist/src/less2/include/toolbar-history.less b/customize.dist/src/less2/include/toolbar-history.less index 27b2552aa..2eda57cd5 100644 --- a/customize.dist/src/less2/include/toolbar-history.less +++ b/customize.dist/src/less2/include/toolbar-history.less @@ -124,7 +124,7 @@ width: 2px !important; background: @pos-color; &:before { - left: -6px; + right: -6px; } } } @@ -133,6 +133,7 @@ height: 20px !important; .cp-history-timeline-pos { height: 20px !important; + margin-left: 100%; } } .cp-history-timeline-actions { @@ -261,7 +262,7 @@ top: -17px; font-size: 24px; position: absolute; - left: ~"calc(50% - 6px)"; + right: ~"calc(50% - 6px)"; } } @media screen and (max-width: 870px) { diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index e69753175..3c49f1108 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -49,32 +49,8 @@ define([ config.onlyoffice.lastHash === hashes[sortedCp[sortedCp.length - 1]].hash; var fillOO = function (messages, ooCheckpoints) { - // if (!id) { return; } - - // if (ooMessages[id]) { return; } - - ooMessages = {} + ooMessages = {}; ooMessages[id] = messages; - // update(); - // var checkpoints = []; - // Object.keys(ooCheckpoints).forEach(function(key) { - // checkpoints.push(ooCheckpoints[key].index); - // }) - // checkpoints.forEach((current, index) => { - // var preceding = index > 0 ? checkpoints[index - 1] : 1; - // ooMessages[index+1] = messages.slice(preceding-1, current-1); - // }); - // var cpMessages = Object.values(ooMessages).flat().length; - // var messageDiff = messages.length - cpMessages; - // if (messageDiff !== 0 && cpMessages) { - // var keys = Object.keys(ooMessages); - // var currentM = parseInt(keys[keys.length - 1]); - // ooMessages[currentM+1] = messages.slice(-messageDiff); - // } else if (messageDiff !== 0 && !cpMessages) { - // ooMessages[1] = messages; - // } - // id = id ? id : getId(); - // update(); }; if (endWithCp) { cpIndex = 0; } @@ -88,22 +64,46 @@ define([ var getVersion = function (position) { if (Object.keys(ooMessages).length) { - var major = id === 0 ? 0 : id-1; + var major = (id === -1 || id === 0) ? 0 : id; + console.log("MAJOR", id, ooMessages[id], ) return major + '.' + position; } }; var showVersion = function (initial, position) { + if (!position) { + position = 0 + } var v = getVersion(position); if (initial) { v = Messages.oo_version_latest; } + $version.text(Messages.oo_version + v); var $pos = $hist.find('.cp-history-timeline-pos'); if (!ooMessages[id]) { return; } var msgs = ooMessages[id]; - var p = 100*((msgIndex+1) / (msgs.length)); + var p; + + if (!Object.keys(hashes).length) { + p = 100-100*((msgIndex+1) / (-msgs.length)); + p = Math.sign(p) === -1 ? 0 : p + + } else { + var pId = id + if (id) { + p = 100-100*(pId / Object.keys(hashes).length) + + + } else { + p = 0 + } + + + } + // console.log("VERSION", 10-((msgIndex+1) / (-msgs.length)), p) + $pos.css('margin-left', p+'%'); var time = msgs[msgIndex] && msgs[msgIndex].time; @@ -212,12 +212,13 @@ define([ ) { $prev.prop('disabled', 'disabled'); } - var msgs = ooMessages[id]?.length; - + if ((id === msgLength) && msgIndex === -1 || id === -1 && msgIndex === -1 || Object.keys(hashes)[0] === id && msgIndex === -1 && !prev || - parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) { + parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id + && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length || + parseInt(Object.keys(hashes)[Object.keys(hashes).length - 2]) === id && msgIndex === -1) { $fastNext.prop('disabled', 'disabled'); } @@ -225,40 +226,26 @@ define([ // id === -1 && msgIndex === -1, // (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev, // parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) - console.log(hashes, ooMessages, id, msgIndex, msgLength, ooMessages[id].length) - - // console.log(Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1] === id && !ooMessages[id].length, - // Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1], id, typeof id, - // typeof parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]), - // parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id, - // ooMessages[id]) - - // console.log((id === msgLength) && msgIndex === -1, - // id === -1 && msgIndex === -1, - // (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev || Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1] === id && !ooMessages[id].length) - // console.log((id === msgLength) && msgIndex === -1, - // id === -1 && msgIndex === -1, - // (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev, - // Object.keys(hashes)[Object.keys(hashes).length - 1] === Object.keys(ooMessages)[Object.keys(ooMessages).length - 1] === id && !ooMessages[id].length) - - var lastHash = hashes[hashes.length-1] + console.log(hashes, ooMessages, id, msgIndex, msgLength, ooMessages[id]?.length) + // console.log(typeof id, typeof Object.keys(hashes)[Object.keys(hashes).length - 2]) + console.log( Object.keys(hashes)[0] === id && msgIndex === -1, (id === msgLength) && msgIndex === -1, id === -1 && msgIndex === -1, - // (id === msgLength || id+1 === msgLength) && !ooMessages[id].length && msgIndex === -1 && !prev, parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && - parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) + parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length, + parseInt(Object.keys(hashes)[Object.keys(hashes).length - 2]) === id && msgIndex === -1 ) if ( Object.keys(hashes)[0]=== id && msgIndex === -1 || (id === msgLength) && msgIndex === -1 || id === -1 && msgIndex === -1 || - // id === msgLength && msgIndex === -1 && !prev || parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && - parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) { + parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length || + parseInt(Object.keys(hashes)[Object.keys(hashes).length - 2]) === id && msgIndex === -1) { $next.prop('disabled', 'disabled'); } @@ -479,6 +466,7 @@ define([ msgIndex = -msgs.length-1 console.log("fastnext0.5", hashes, id, ooMessages, msgIndex) setTimeout(function () { + showVersion() update(); loading = false; }, 100); @@ -494,6 +482,7 @@ define([ config.onPatchBack(cp, msgs); } + showVersion() console.log("fastnext2", hashes, id, ooMessages, msgIndex) setTimeout(function () { @@ -518,10 +507,9 @@ define([ loadMoreOOHistory().then(() => { var msgs = ooMessages[id]; msgIndex = -msgs.length-2; + showVersion() update(true); - console.log("fastprev2", hashes, id, ooMessages, msgIndex) - - + // console.log("fastprev2", hashes, id, ooMessages, msgIndex) }); loading = false; From bbb0112e63994273d1bff46bf10ee4545771c825 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 7 Nov 2025 16:10:42 +0100 Subject: [PATCH 31/51] shows position on timeline --- www/common/onlyoffice/history.js | 118 ++++++++++++------------------- www/common/onlyoffice/inner.js | 9 +-- 2 files changed, 47 insertions(+), 80 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 3c49f1108..494432e16 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -64,15 +64,14 @@ define([ var getVersion = function (position) { if (Object.keys(ooMessages).length) { - var major = (id === -1 || id === 0) ? 0 : id; - console.log("MAJOR", id, ooMessages[id], ) - return major + '.' + position; + var version = (id === -1 || id === 0) ? 0 : id; + return version + '.' + position; } }; var showVersion = function (initial, position) { if (!position) { - position = 0 + position = 0; } var v = getVersion(position); if (initial) { @@ -85,25 +84,30 @@ define([ if (!ooMessages[id]) { return; } var msgs = ooMessages[id]; var p; - + var messageIndex = APP.next ? msgIndex+1 : msgIndex; if (!Object.keys(hashes).length) { - p = 100-100*((msgIndex+1) / (-msgs.length)); - p = Math.sign(p) === -1 ? 0 : p - + p = 100-100*((messageIndex ) / (-msgs.length)); } else { - var pId = id + var pId = id; if (id) { - p = 100-100*(pId / Object.keys(hashes).length) + pHash = 100-100*(pId / Object.keys(hashes).length); + if (messageIndex === -(msgs.length+2)) { + p = pHash; + } else { + p = pHash+(pHash-Math.abs(messageIndex )*(pHash/msgs.length)); + } - - } else { - p = 0 + } else { + p = pHash-Math.abs(messageIndex)*(pHash/msgs.length); } - + if (Math.sign(p) === -1 ) { + p = 0; + } else if (!p) { + p = 100; + } } - // console.log("VERSION", 10-((msgIndex+1) / (-msgs.length)), p) - + $pos.css('margin-left', p+'%'); var time = msgs[msgIndex] && msgs[msgIndex].time; @@ -214,38 +218,23 @@ define([ } if ((id === msgLength) && msgIndex === -1 || - id === -1 && msgIndex === -1 || - Object.keys(hashes)[0] === id && msgIndex === -1 && !prev || - parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id - && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length || - parseInt(Object.keys(hashes)[Object.keys(hashes).length - 2]) === id && msgIndex === -1) { + id === -1 && msgIndex === -1 || + Object.keys(hashes)[0] === id && msgIndex === -1 && !prev || + parseInt(Object.keys(hashes)[msgLength - 1]) === id + && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length || + parseInt(Object.keys(hashes)[msgLength - 2]) === id && msgIndex === -1 && APP.next) + { $fastNext.prop('disabled', 'disabled'); } - // console.log((id === msgLength) && msgIndex === -1, - // id === -1 && msgIndex === -1, - // (id === msgLength || id === msgLength-1) && msgIndex === -1 && !prev, - // parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length) - - console.log(hashes, ooMessages, id, msgIndex, msgLength, ooMessages[id]?.length) - // console.log(typeof id, typeof Object.keys(hashes)[Object.keys(hashes).length - 2]) - - - console.log( - Object.keys(hashes)[0] === id && msgIndex === -1, - (id === msgLength) && msgIndex === -1, - id === -1 && msgIndex === -1, - parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && - parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length, - parseInt(Object.keys(hashes)[Object.keys(hashes).length - 2]) === id && msgIndex === -1 ) - if ( - Object.keys(hashes)[0]=== id && msgIndex === -1 || - (id === msgLength) && msgIndex === -1 || - id === -1 && msgIndex === -1 || - parseInt(Object.keys(hashes)[Object.keys(hashes).length - 1]) === id && - parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length || - parseInt(Object.keys(hashes)[Object.keys(hashes).length - 2]) === id && msgIndex === -1) { + Object.keys(hashes)[0]=== id && msgIndex === -1 || + (id === msgLength) && msgIndex === -1 || + id === -1 && msgIndex === -1 || + parseInt(Object.keys(hashes)[msgLength - 1]) === id && + parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length + || parseInt(Object.keys(hashes)[msgLength - 2]) === id && msgIndex === -1 && APP.next) + { $next.prop('disabled', 'disabled'); } @@ -259,9 +248,9 @@ define([ } var next = async function () { + APP.next = true; msgIndex++; msgs = ooMessages[id]; - console.log("next1", hashes, id, ooMessages, msgIndex, msgs) if (Object.keys(hashes).length) { if (msgIndex === 0) { id++; @@ -287,18 +276,17 @@ define([ return; } else if (Math.abs(msgIndex) > msgs.length && msgs.length) { - msgIndex = -msgs.length + msgIndex = -msgs.length; } else if (!msgs.length) { config.onPatchBack(hashes[id+1]); - return + return; } } else if (msgs.length + msgIndex === -1) { - msgIndex++ + msgIndex++; } var patch = msgs[msgs.length + msgIndex]; - console.log("next0.5", hashes, id, ooMessages, msgIndex, msgs, msgs.length + msgIndex) config.onPatch(patch); showVersion(false, msgs.indexOf(patch)+1); loadingFalse(); @@ -307,7 +295,7 @@ define([ var msgs; var prev = function () { - console.log("prev1", hashes, id, ooMessages, msgIndex) + APP.next = false msgs = ooMessages[id]; if (!Object.keys(hashes).length) { var cp = {}; @@ -333,8 +321,6 @@ define([ showVersion(false, queue.length); msgIndex--; loadingFalse(); - console.log("prev2", hashes, id, ooMessages, msgIndex) - }; @@ -439,18 +425,16 @@ define([ next().then( update() ); - // update(); }); $prev.click(function () { if (loading) { return; } loading = true; prev(); - update(true) + update(true); }); // Go to previous checkpoint $fastNext.click(function () { if (loading) { return; } - console.log("fastnext1", hashes, id, ooMessages, msgIndex) loading = true; if (id < Object.keys(hashes).length && id !== -1) { if (id === -1) { @@ -460,30 +444,24 @@ define([ } loadMoreOOHistory().then(() => { var cp = hashes[id]; - loadMoreOOHistory() + loadMoreOOHistory(); config.loadCp(cp); - msgs = ooMessages[id] + msgs = ooMessages[id]; msgIndex = -msgs.length-1 - console.log("fastnext0.5", hashes, id, ooMessages, msgIndex) setTimeout(function () { showVersion() update(); loading = false; }, 100); return; - - }); - } else { var cp = hashes[id]; - var msgs = ooMessages[id] - msgIndex = -1 + var msgs = ooMessages[id]; + msgIndex = -1; config.onPatchBack(cp, msgs); - } - showVersion() - console.log("fastnext2", hashes, id, ooMessages, msgIndex) + showVersion(); setTimeout(function () { update('end'); @@ -492,16 +470,11 @@ define([ }); // Go to next checkpoint $fastPrev.click(function () { - console.log("fastprev1", hashes, id, ooMessages, msgIndex) - if (loading) { return; } loading = true; if (!ooMessages[id].length || ooMessages[id].length+2 === Math.abs(msgIndex)) { - // console.log("fastprev0.25", ooMessages[id].length+1, Math.abs(msgIndex)) id--; } - // console.log("fastprev0.5", ooMessages[id]?.length+1, Math.abs(msgIndex)) - var cp = hashes[id]; config.loadCp(cp); loadMoreOOHistory().then(() => { @@ -509,11 +482,10 @@ define([ msgIndex = -msgs.length-2; showVersion() update(true); - // console.log("fastprev2", hashes, id, ooMessages, msgIndex) }); loading = false; - }); + onKeyDown = function (e) { var p = function () { e.preventDefault(); }; if ([38, 39].indexOf(e.which) >= 0) { p(); return $next.click(); } // Right diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index d97333546..708604967 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -548,12 +548,7 @@ define([ var app = common.getMetadataMgr().getPrivateData().ooType; var d; if (app === 'doc') { - if (editor.GetDocument()) { - d = editor.GetDocument().Document - } else { - d = undefined - } - // d = editor.GetDocument() ? editor.GetDocument().Document : undefined; + d = editor.GetDocument() ? editor.GetDocument().Document : undefined; } else if (app === 'presentation') { d = editor.GetPresentation().Presentation; } @@ -3147,7 +3142,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null }; var onPatchBack = function (cp, msgs) { if (msgs) { - msgsFormatted = []; + var msgsFormatted = []; msgs.forEach(function(msg) { var parsedMsg = JSON.parse(msg.msg); From 1a42a561ff6c61634f6bb384c252d63183592d24 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 7 Nov 2025 18:08:28 +0100 Subject: [PATCH 32/51] wip --- src/common/common-hash.js | 1 + www/common/onlyoffice/history.js | 13 +++++++++---- www/common/onlyoffice/inner.js | 5 +++++ www/common/onlyoffice/main.js | 4 ++++ www/common/sframe-common-history.js | 1 + 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/common/common-hash.js b/src/common/common-hash.js index 0eb4faa37..06d32dbe2 100644 --- a/src/common/common-hash.js +++ b/src/common/common-hash.js @@ -470,6 +470,7 @@ Version 4: Data URL when not a realtime link yet (new pad or "static" app) return hash; }; ret.getUrl = function (options) { + console.log("url", options) options = options || {}; var url = '/'; if (!ret.type) { return url; } diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 494432e16..ba0e7a189 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -63,6 +63,9 @@ define([ var Messages = common.Messages; var getVersion = function (position) { + if (!position) { + position = 0; + } if (Object.keys(ooMessages).length) { var version = (id === -1 || id === 0) ? 0 : id; return version + '.' + position; @@ -70,9 +73,7 @@ define([ }; var showVersion = function (initial, position) { - if (!position) { - position = 0; - } + var v = getVersion(position); if (initial) { v = Messages.oo_version_latest; @@ -525,13 +526,17 @@ define([ onClick: function () { var val = $input.val(); if (!val) { return true; } + msgs = ooMessages[id] + var patch = msgs.slice(0, msgIndex) + console.log("patch", msgs.slice(0, msgIndex)) + console.log("bloop", msgs[msgIndex], msgs, msgIndex, ooMessages) config.makeSnapshot(val, function (err) { if (err) { return; } $input.val(''); UI.log(Messages.saved); }, { hash: getVersion(), - time: currentTime || 0 + time: currentTime || patch && patch.time || 0 }); }, keys: [13], diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 708604967..a6e3042ae 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -3188,10 +3188,13 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null }; var makeSnapshot = function (title, cb, obj) { var hash, time; + console.log("obj", obj) if (obj && obj.hash && obj.time) { + console.log("i") hash = obj.hash; time = obj.time; } else { + console.log("11") var major = Object.keys(content.hashes).length; var cpIndex = getLastCp().index || 0; var minor = ooChannel.cpIndex - cpIndex; @@ -3205,11 +3208,13 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null title: title, time: time }; + console.log("spap", snapshots) metadataMgr.updateMetadata(md); APP.onLocal(); APP.realtime.onSettle(cb); }; var loadSnapshot = function (hash) { + console.log("hash", hash) sframeChan.event('EV_OO_OPENVERSION', { hash: hash }); diff --git a/www/common/onlyoffice/main.js b/www/common/onlyoffice/main.js index c3751aa0d..1c7fe4006 100644 --- a/www/common/onlyoffice/main.js +++ b/www/common/onlyoffice/main.js @@ -145,10 +145,14 @@ define([ Cryptpad.onlyoffice.execCommand(obj, cb); }); sframeChan.on('EV_OO_OPENVERSION', function (obj) { + console.log("obj2", obj) if (!obj || !obj.hash) { return; } var parsed = Hash.parsePadUrl(window.location.href); var opts = parsed.getOptions(); + opts.versionHash = obj.hash; + console.log("opts", opts) + window.open(parsed.getUrl(opts)); }); Cryptpad.onlyoffice.onEvent.reg(function (obj) { diff --git a/www/common/sframe-common-history.js b/www/common/sframe-common-history.js index e711d5265..4c47b1a5b 100644 --- a/www/common/sframe-common-history.js +++ b/www/common/sframe-common-history.js @@ -413,6 +413,7 @@ define([ try { var block = states[idx]; var hash = block.serverHash; + console.log("HASH", states, block, hash) var md = config.getLastMetadata(); md.snapshots = md.snapshots || {}; if (md.snapshots[hash]) { return; } From 2780d0303b19d8a4f84e3446a75b4c8fdd1fc661 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Tue, 11 Nov 2025 16:23:28 +0100 Subject: [PATCH 33/51] wip --- src/common/common-hash.js | 4 +- www/common/onlyoffice/history.js | 90 ++++++++++++++++++++++++++------ www/common/onlyoffice/inner.js | 30 ++++++++--- www/common/onlyoffice/main.js | 5 +- 4 files changed, 101 insertions(+), 28 deletions(-) diff --git a/src/common/common-hash.js b/src/common/common-hash.js index 06d32dbe2..2d94372a6 100644 --- a/src/common/common-hash.js +++ b/src/common/common-hash.js @@ -317,7 +317,8 @@ Version 4: Data URL when not a realtime link yet (new pad or "static" app) if (parsed.password || opts.password) { hash += 'p/'; } if (opts.embed) { hash += 'embed/'; } if (opts.present) { hash += 'present/'; } - var versionHash = typeof(opts.versionHash) !== "undefined" ? opts.versionHash : parsed.versionHash; + var versionHash = (typeof(opts.versionHash) !== "undefined") ? opts.versionHash : parsed.versionHash; + if (versionHash) { hash += 'hash=' + Crypto.b64RemoveSlashes(versionHash) + '/'; } @@ -470,7 +471,6 @@ Version 4: Data URL when not a realtime link yet (new pad or "static" app) return hash; }; ret.getUrl = function (options) { - console.log("url", options) options = options || {}; var url = '/'; if (!ret.type) { return url; } diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index ba0e7a189..f606e5d48 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -29,6 +29,7 @@ define([ var ooCheckpoints = {}; var loading = false; var currentTime; + var position; // Get an array of the checkpoint IDs sorted their patch index var hashes = config.onlyoffice.hashes; @@ -62,19 +63,52 @@ define([ var $bottom = $toolbar.find('.cp-toolbar-bottom'); var Messages = common.Messages; - var getVersion = function (position) { - if (!position) { - position = 0; - } + var getVersion = function (position, initial) { if (Object.keys(ooMessages).length) { + console.log('here', id) var version = (id === -1 || id === 0) ? 0 : id; + if (!position) { + position = ooMessages[id].length || 0 + } return version + '.' + position; } + // console.log("hello!", ooMessages) + // if (!position) { + // position = 0 + // } + // if (Object.keys(ooMessages).length) { + // var msgs = ooMessages[id] + // return id + '.' + msgs.length; + + // } + + // // console.log("hello", ooMessages, id) + // // if (initial) { + // // return id + '.' + msgs.length + // // } + + // if (Object.keys(ooMessages).length) { + // var msgs = ooMessages[id] + + + // var version = (id === -1 || id === 0) ? 0 : id; + // if (msgs.length === position) { + // version += 1; + // position = 0; + // } + + // // if (position) + // console.log("hello") + // return version + '.' + position; + // } else if (!position){ + // position =0 + // } }; var showVersion = function (initial, position) { - var v = getVersion(position); + var v = getVersion(position, initial); + console.log("vers",) if (initial) { v = Messages.oo_version_latest; } @@ -91,11 +125,18 @@ define([ } else { var pId = id; if (id) { - pHash = 100-100*(pId / Object.keys(hashes).length); + pHash = 100-100*(pId / Object.keys(hashes).length+1); + console.log("pos1", pId, ) + if (messageIndex === -(msgs.length+2)) { + console.log("pos2", p) + p = pHash; } else { + p = pHash+(pHash-Math.abs(messageIndex )*(pHash/msgs.length)); + console.log("pos3", pHash, Math.abs(messageIndex )*(pHash/msgs.length)) + } } else { @@ -107,6 +148,7 @@ define([ } else if (!p) { p = 100; } + console.log("pos", p) } $pos.css('margin-left', p+'%'); @@ -135,6 +177,7 @@ define([ let initialCp = cpIndex === sortedCp.length || cp ? !cp?.hash : undefined; const messages = (data.messages || []).slice(initialCp || APP.ooconfig.documentType === 'spreadsheet' ? 0 : 1); + console.log("messages", messages, fromHash, toHash) if (config.debug) { console.log(data.messages); @@ -263,7 +306,9 @@ define([ return loadMoreOOHistory().then(() => { loadingFalse(); msgIndex = -ooMessages[id].length-1; - showVersion(false, msgs.indexOf(patch)+1); + position = msgs.indexOf(patch)+1 + console.log("posiiton1", msgs.indexOf(patch)+1, msgs.length) + showVersion(false, position); return; }); } @@ -271,7 +316,10 @@ define([ var patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined; var cp = hashes[id]; config.onPatchBack(cp, [patch]); - showVersion(false, msgs.indexOf(patch)+1); + position = msgs.indexOf(patch)+1 + console.log("posiiton2", msgs.indexOf(patch)+1, msgs.length) + + showVersion(false, position); loadingFalse(); }) return; @@ -289,7 +337,10 @@ define([ } var patch = msgs[msgs.length + msgIndex]; config.onPatch(patch); - showVersion(false, msgs.indexOf(patch)+1); + console.log("posiiton2", msgs.indexOf(patch)+1, msgs.length) + + position = msgs.indexOf(patch)+1 + showVersion(false, position); loadingFalse(); }; @@ -308,8 +359,9 @@ define([ msgs = ooMessages[id]; var queue = msgs.slice(0, msgIndex); var cp = hashes[id]; - config.onPatchBack(cp, queue); - showVersion(false, queue.length); + config.onPatchBack(cp, queue); + position = queue.length + showVersion(false, position); msgIndex--; loadingFalse(); }); @@ -318,8 +370,9 @@ define([ var cp = hashes[id]; } var queue = msgs.slice(0, msgIndex); - config.onPatchBack(cp, queue); - showVersion(false, queue.length); + config.onPatchBack(cp, queue); + position = queue.length + showVersion(false, position); msgIndex--; loadingFalse(); }; @@ -468,6 +521,8 @@ define([ update('end'); loading = false; }, 100); + position = msgs.length + showVersion(position) }); // Go to next checkpoint $fastPrev.click(function () { @@ -484,6 +539,7 @@ define([ showVersion() update(true); }); + position = 0; loading = false; }); @@ -499,8 +555,9 @@ define([ // Versioned link $share.click(function () { + console.log("hello %", position, getVersion(position)) common.getSframeChannel().event('EV_SHARE_OPEN', { - versionHash: getVersion() + versionHash: getVersion(position) }); }); $(snapshot).click(function () { @@ -528,14 +585,13 @@ define([ if (!val) { return true; } msgs = ooMessages[id] var patch = msgs.slice(0, msgIndex) - console.log("patch", msgs.slice(0, msgIndex)) - console.log("bloop", msgs[msgIndex], msgs, msgIndex, ooMessages) config.makeSnapshot(val, function (err) { if (err) { return; } $input.val(''); UI.log(Messages.saved); }, { - hash: getVersion(), + hash: getVersion(position), + //FIXHERE: get the time of the patch and pass here time: currentTime || patch && patch.time || 0 }); }, diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index a6e3042ae..f79d93d7e 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -791,9 +791,11 @@ define([ var minor = Number(s[1]) + 1; if (APP.isDownload) { minor = undefined; } - var toHash = cp.hash || 'NONE'; + // var fromHash = content.hashes[1].hash var fromHash = nextCpId ? hashes[nextCpId].hash : 'NONE'; + console.log('hello version', version, major, minor ) + sframeChan.query('Q_GET_HISTORY_RANGE', { channel: content.channel, @@ -810,7 +812,10 @@ define([ // The first "cp" in history is the empty doc. It doesn't include the first patch // of the history var initialCp = major === 0 || !cp.hash; - var messages = (data.messages || []).slice(initialCp ? 0 : 1, minor); + const messages = data.messages + // var messages = (data.messages || []).slice(initialCp); + + console.log("messages", initialCp, minor, messages, fromHash, toHash, ooChannel, content.hashes) messages.forEach(function (obj) { try { obj.msg = JSON.parse(obj.msg); } catch (e) { console.error(e); } @@ -819,6 +824,7 @@ define([ // The version exists if we have results in the "messages" array // or if we requested a x.0 version var exists = !Number(s[1]) || messages.length; + // console.log("exists", exists, !Number(s[1]), messages.length) var vHashEl; if (!privateData.embed) { @@ -843,7 +849,8 @@ define([ loadLastDocument(cp) .then(({blob, fileType}) => { - ooChannel.queue = messages; + ooChannel.queue = messages.slice(0, minor); + console.log("messages q2", ooChannel.queue) resetData(blob, fileType); UI.removeLoadingScreen(); }) @@ -855,11 +862,21 @@ define([ $(vHashEl).removeClass('alert-warning').addClass('alert-danger'); return; } + //FIXHERE: have to use version number in url to load cp and messages + // var hashes = content.hashes + // var s = version.split('.'); + // var major = parseInt(s[0]) + // var minor = s[1] + // console.log("messages", messages) + // if (hashes && major > 0) { + // loadCp(hashes[major]) + // return; + // } var file = getFileType(); var type = common.getMetadataMgr().getPrivateData().ooType; if (APP.downloadType) { type = APP.downloadType; } var blob = loadInitDocument(type, true); - ooChannel.queue = messages; + ooChannel.queue = messages.slice resetData(blob, file); UI.removeLoadingScreen(); }); @@ -3189,10 +3206,11 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null var makeSnapshot = function (title, cb, obj) { var hash, time; console.log("obj", obj) - if (obj && obj.hash && obj.time) { + if (obj && obj.hash) { console.log("i") hash = obj.hash; - time = obj.time; + time = time = +new Date(); + } else { console.log("11") var major = Object.keys(content.hashes).length; diff --git a/www/common/onlyoffice/main.js b/www/common/onlyoffice/main.js index 1c7fe4006..d9164d164 100644 --- a/www/common/onlyoffice/main.js +++ b/www/common/onlyoffice/main.js @@ -27,6 +27,7 @@ define([ var opts = parsed.getOptions(); version = opts.versionHash; } + console.log(opts, parsed, version) if (isIntegration) { href = integration.href; hash = integration.hash; @@ -36,6 +37,7 @@ define([ let path = (integration && integration.pathname) || window.location.pathname; obj.ooType = path.replace(/^\//, '').replace(/\/$/, ''); obj.ooVersionHash = version; + console.log("obj2 !!!", version) obj.ooForceVersion = localStorage.CryptPad_ooVersion || ""; }; var channels = {}; @@ -145,14 +147,11 @@ define([ Cryptpad.onlyoffice.execCommand(obj, cb); }); sframeChan.on('EV_OO_OPENVERSION', function (obj) { - console.log("obj2", obj) if (!obj || !obj.hash) { return; } var parsed = Hash.parsePadUrl(window.location.href); var opts = parsed.getOptions(); opts.versionHash = obj.hash; - console.log("opts", opts) - window.open(parsed.getUrl(opts)); }); Cryptpad.onlyoffice.onEvent.reg(function (obj) { From 25af0c57ace35ba431feb00d495ad72c431bc16d Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Tue, 11 Nov 2025 16:24:48 +0100 Subject: [PATCH 34/51] wip --- www/common/onlyoffice/history.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index f606e5d48..5eb08602c 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -66,7 +66,9 @@ define([ var getVersion = function (position, initial) { if (Object.keys(ooMessages).length) { console.log('here', id) + var version = (id === -1 || id === 0) ? 0 : id; + if (!position) { position = ooMessages[id].length || 0 } From adf0aece366b0fdeefccd9232f4cbb61a1a64172 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Wed, 12 Nov 2025 16:05:44 +0100 Subject: [PATCH 35/51] wip --- www/common/onlyoffice/history.js | 82 ++++++++++---------------------- www/common/onlyoffice/inner.js | 16 ++----- 2 files changed, 27 insertions(+), 71 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 5eb08602c..d5bff43d4 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -30,6 +30,7 @@ define([ var loading = false; var currentTime; var position; + var patch; // Get an array of the checkpoint IDs sorted their patch index var hashes = config.onlyoffice.hashes; @@ -64,53 +65,23 @@ define([ var Messages = common.Messages; var getVersion = function (position, initial) { - if (Object.keys(ooMessages).length) { - console.log('here', id) - + if (Object.keys(ooMessages).length) { var version = (id === -1 || id === 0) ? 0 : id; - - if (!position) { + if (position === undefined) { position = ooMessages[id].length || 0 + } else if (position === ooMessages[id]?.length && hashes[version+1]) { + position = 0; + if (ooMessages[id].length) { + version = version + 1; + } } return version + '.' + position; } - // console.log("hello!", ooMessages) - // if (!position) { - // position = 0 - // } - // if (Object.keys(ooMessages).length) { - // var msgs = ooMessages[id] - // return id + '.' + msgs.length; - - // } - - // // console.log("hello", ooMessages, id) - // // if (initial) { - // // return id + '.' + msgs.length - // // } - - // if (Object.keys(ooMessages).length) { - // var msgs = ooMessages[id] - - - // var version = (id === -1 || id === 0) ? 0 : id; - // if (msgs.length === position) { - // version += 1; - // position = 0; - // } - - // // if (position) - // console.log("hello") - // return version + '.' + position; - // } else if (!position){ - // position =0 - // } }; var showVersion = function (initial, position) { var v = getVersion(position, initial); - console.log("vers",) if (initial) { v = Messages.oo_version_latest; } @@ -150,7 +121,7 @@ define([ } else if (!p) { p = 100; } - console.log("pos", p) + // console.log("pos", p) } $pos.css('margin-left', p+'%'); @@ -179,7 +150,6 @@ define([ let initialCp = cpIndex === sortedCp.length || cp ? !cp?.hash : undefined; const messages = (data.messages || []).slice(initialCp || APP.ooconfig.documentType === 'spreadsheet' ? 0 : 1); - console.log("messages", messages, fromHash, toHash) if (config.debug) { console.log(data.messages); @@ -270,7 +240,7 @@ define([ && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length || parseInt(Object.keys(hashes)[msgLength - 2]) === id && msgIndex === -1 && APP.next) { - $fastNext.prop('disabled', 'disabled'); + // $fastNext.prop('disabled', 'disabled'); } if ( @@ -281,7 +251,7 @@ define([ parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length || parseInt(Object.keys(hashes)[msgLength - 2]) === id && msgIndex === -1 && APP.next) { - $next.prop('disabled', 'disabled'); + // $next.prop('disabled', 'disabled'); } }; @@ -293,6 +263,8 @@ define([ }, 200); } + // var patch; + var next = async function () { APP.next = true; msgIndex++; @@ -309,18 +281,15 @@ define([ loadingFalse(); msgIndex = -ooMessages[id].length-1; position = msgs.indexOf(patch)+1 - console.log("posiiton1", msgs.indexOf(patch)+1, msgs.length) showVersion(false, position); return; }); } msgIndex = -msgs.length; - var patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined; + patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined; var cp = hashes[id]; config.onPatchBack(cp, [patch]); position = msgs.indexOf(patch)+1 - console.log("posiiton2", msgs.indexOf(patch)+1, msgs.length) - showVersion(false, position); loadingFalse(); }) @@ -337,10 +306,8 @@ define([ else if (msgs.length + msgIndex === -1) { msgIndex++; } - var patch = msgs[msgs.length + msgIndex]; + patch = msgs[msgs.length + msgIndex]; config.onPatch(patch); - console.log("posiiton2", msgs.indexOf(patch)+1, msgs.length) - position = msgs.indexOf(patch)+1 showVersion(false, position); loadingFalse(); @@ -362,7 +329,8 @@ define([ var queue = msgs.slice(0, msgIndex); var cp = hashes[id]; config.onPatchBack(cp, queue); - position = queue.length + position = queue.length + patch = queue[queue.length-1] showVersion(false, position); msgIndex--; loadingFalse(); @@ -373,7 +341,8 @@ define([ } var queue = msgs.slice(0, msgIndex); config.onPatchBack(cp, queue); - position = queue.length + position = queue.length + patch = queue[queue.length-1] showVersion(false, position); msgIndex--; loadingFalse(); @@ -505,7 +474,7 @@ define([ msgs = ooMessages[id]; msgIndex = -msgs.length-1 setTimeout(function () { - showVersion() + showVersion(false, 0) update(); loading = false; }, 100); @@ -517,14 +486,14 @@ define([ msgIndex = -1; config.onPatchBack(cp, msgs); } - showVersion(); + showVersion(false, 0); setTimeout(function () { update('end'); loading = false; }, 100); position = msgs.length - showVersion(position) + showVersion(false, position) }); // Go to next checkpoint $fastPrev.click(function () { @@ -538,7 +507,7 @@ define([ loadMoreOOHistory().then(() => { var msgs = ooMessages[id]; msgIndex = -msgs.length-2; - showVersion() + showVersion(false, 0) update(true); }); position = 0; @@ -557,7 +526,6 @@ define([ // Versioned link $share.click(function () { - console.log("hello %", position, getVersion(position)) common.getSframeChannel().event('EV_SHARE_OPEN', { versionHash: getVersion(position) }); @@ -586,14 +554,12 @@ define([ var val = $input.val(); if (!val) { return true; } msgs = ooMessages[id] - var patch = msgs.slice(0, msgIndex) config.makeSnapshot(val, function (err) { if (err) { return; } $input.val(''); UI.log(Messages.saved); }, { - hash: getVersion(position), - //FIXHERE: get the time of the patch and pass here + hash: getVersion(position), time: currentTime || patch && patch.time || 0 }); }, diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index f79d93d7e..cb0d22b38 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -782,6 +782,7 @@ define([ return hashes[a].index - hashes[b].index; }); var s = version.split('.'); + var version = parseInt(s[1]) if (s.length !== 2) { return UI.errorLoadingScreen(Messages.error); } var major = Number(s[0]); @@ -849,8 +850,7 @@ define([ loadLastDocument(cp) .then(({blob, fileType}) => { - ooChannel.queue = messages.slice(0, minor); - console.log("messages q2", ooChannel.queue) + ooChannel.queue = messages.slice(1, minor) resetData(blob, fileType); UI.removeLoadingScreen(); }) @@ -862,21 +862,11 @@ define([ $(vHashEl).removeClass('alert-warning').addClass('alert-danger'); return; } - //FIXHERE: have to use version number in url to load cp and messages - // var hashes = content.hashes - // var s = version.split('.'); - // var major = parseInt(s[0]) - // var minor = s[1] - // console.log("messages", messages) - // if (hashes && major > 0) { - // loadCp(hashes[major]) - // return; - // } var file = getFileType(); var type = common.getMetadataMgr().getPrivateData().ooType; if (APP.downloadType) { type = APP.downloadType; } var blob = loadInitDocument(type, true); - ooChannel.queue = messages.slice + ooChannel.queue = messages.slice(0, version+1) resetData(blob, file); UI.removeLoadingScreen(); }); From da9f5490ab08e58fe969f70a9af2380ea321ea09 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Thu, 13 Nov 2025 18:13:19 +0100 Subject: [PATCH 36/51] updated version numbers and timeline --- www/common/onlyoffice/history.js | 108 +++++++++++++------------------ 1 file changed, 45 insertions(+), 63 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index d5bff43d4..4afebb495 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -26,11 +26,13 @@ define([ var msgIndex = -1; var APP = window.APP; var ooMessages = {}; - var ooCheckpoints = {}; var loading = false; var currentTime; var position; var patch; + var v; + var fromHash; + var toHash // Get an array of the checkpoint IDs sorted their patch index var hashes = config.onlyoffice.hashes; @@ -50,7 +52,7 @@ define([ var endWithCp = sortedCp.length && config.onlyoffice.lastHash === hashes[sortedCp[sortedCp.length - 1]].hash; - var fillOO = function (messages, ooCheckpoints) { + var fillOO = function (messages) { ooMessages = {}; ooMessages[id] = messages; }; @@ -64,7 +66,7 @@ define([ var $bottom = $toolbar.find('.cp-toolbar-bottom'); var Messages = common.Messages; - var getVersion = function (position, initial) { + var getVersion = function (position) { if (Object.keys(ooMessages).length) { var version = (id === -1 || id === 0) ? 0 : id; if (position === undefined) { @@ -75,17 +77,17 @@ define([ version = version + 1; } } - return version + '.' + position; + v = version + '.' + position; + return v } - }; + var showVersion = function (initial, position) { var v = getVersion(position, initial); if (initial) { v = Messages.oo_version_latest; } - $version.text(Messages.oo_version + v); var $pos = $hist.find('.cp-history-timeline-pos'); @@ -96,40 +98,35 @@ define([ if (!Object.keys(hashes).length) { p = 100-100*((messageIndex ) / (-msgs.length)); } else { - var pId = id; - if (id) { - pHash = 100-100*(pId / Object.keys(hashes).length+1); - console.log("pos1", pId, ) + var lastHash = Object.keys(hashes).pop() + var lastestHash = hashes[lastHash].hash + if (lastestHash === config.onlyoffice.lastHash) { + var hashLength = Object.keys(hashes).length + } else { + var hashLength = Object.keys(hashes).length+1 - if (messageIndex === -(msgs.length+2)) { - console.log("pos2", p) - - p = pHash; - } else { - - p = pHash+(pHash-Math.abs(messageIndex )*(pHash/msgs.length)); - console.log("pos3", pHash, Math.abs(messageIndex )*(pHash/msgs.length)) - - } - - } else { - p = pHash-Math.abs(messageIndex)*(pHash/msgs.length); } + var checkpoints = id/hashLength + p = 100*(checkpoints) + var poz = 100-p - if (Math.sign(p) === -1 ) { - p = 0; - } else if (!p) { - p = 100; + if (id === 0) { + p= 0 + poz = 100/hashLength } - // console.log("pos", p) + + var poz1 = ((position/msgs.length)*100) + var poz2 = (poz1/100)*(100/hashLength) + p = p+poz2 } - + $pos.css('margin-left', p+'%'); var time = msgs[msgIndex] && msgs[msgIndex].time; currentTime = time; if (time) { $time.text(new Date(time).toLocaleString()); } else { $time.text(''); } + update() }; function getMessages(fromHash, toHash, cpIndex, sortedCp, cp, config, fillOO, $share, ooCheckpoints, callback) { @@ -147,6 +144,8 @@ define([ if (!Array.isArray(data.messages)) { return; } + console.log("from", fromHash) + console.log("to", toHash) let initialCp = cpIndex === sortedCp.length || cp ? !cp?.hash : undefined; const messages = (data.messages || []).slice(initialCp || APP.ooconfig.documentType === 'spreadsheet' ? 0 : 1); @@ -181,8 +180,8 @@ define([ var nextId = hashes[id+1] ? hashes[id+1] : undefined; - var toHash = nextId ? nextId.hash : config.onlyoffice.lastHash; - var fromHash = cp?.hash || 'NONE'; + toHash = nextId ? nextId.hash : config.onlyoffice.lastHash; + fromHash = cp?.hash || 'NONE'; getMessages(toHash, fromHash, cpIndex, sortedCp, undefined, config, fillOO, $share, hashes, function (err, messages) { if (err) { @@ -213,8 +212,7 @@ define([ var $fastPrev, $fastNext, $next, $prev; - var update = function (prev) { - var cps = sortedCp.length; + var update = function () { $fastPrev.show(); $next.show(); $prev.show(); @@ -222,36 +220,21 @@ define([ $hist.find('.cp-toolbar-history-next, .cp-toolbar-history-previous') .prop('disabled', ''); - var msgLength = Object.keys(hashes).length - - if ( - (id === -1 || id === 0) && Math.abs(msgIndex) === ooMessages[id]?.length+2) { + if ((id === -1 || id === 0) && Math.abs(msgIndex) === ooMessages[id]?.length+2) { $fastPrev.prop('disabled', 'disabled'); } - if ((id === -1 || id === 0) && ooMessages[id]?.length+2=== Math.abs(msgIndex) - ) { + if ((id === -1 || id === 0) && ooMessages[id]?.length+2=== Math.abs(msgIndex)) { $prev.prop('disabled', 'disabled'); } - if ((id === msgLength) && msgIndex === -1 || - id === -1 && msgIndex === -1 || - Object.keys(hashes)[0] === id && msgIndex === -1 && !prev || - parseInt(Object.keys(hashes)[msgLength - 1]) === id - && parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length || - parseInt(Object.keys(hashes)[msgLength - 2]) === id && msgIndex === -1 && APP.next) - { - // $fastNext.prop('disabled', 'disabled'); - } - - if ( - Object.keys(hashes)[0]=== id && msgIndex === -1 || - (id === msgLength) && msgIndex === -1 || - id === -1 && msgIndex === -1 || - parseInt(Object.keys(hashes)[msgLength - 1]) === id && - parseInt(Object.keys(ooMessages)[Object.keys(ooMessages).length - 1]) === id && !ooMessages[id].length - || parseInt(Object.keys(hashes)[msgLength - 2]) === id && msgIndex === -1 && APP.next) - { + var version = v.split('.') + var hashesLength = Object.keys(hashes).length + + if ((hashesLength === parseInt(version[0]) && (ooMessages[id].length === parseInt(version[1]) || parseInt(version[1]) === 0)) + // && lastestHash === config.onlyoffice.lastHash + ) { // $next.prop('disabled', 'disabled'); + // $fastNext.prop('disabled', 'disabled'); } }; @@ -263,8 +246,6 @@ define([ }, 200); } - // var patch; - var next = async function () { APP.next = true; msgIndex++; @@ -447,15 +428,16 @@ define([ $next.click(function () { // if (loading) { return; } loading = true; - next().then( - update() - ); + next() + // .then( + // update() + // ); }); $prev.click(function () { if (loading) { return; } loading = true; prev(); - update(true); + // update(true); }); // Go to previous checkpoint $fastNext.click(function () { From c61dcea831b2e9d60b9880b89c9cf009a433dee1 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Thu, 13 Nov 2025 18:31:20 +0100 Subject: [PATCH 37/51] disabling arrows --- www/common/onlyoffice/history.js | 21 +++++++++------------ www/common/onlyoffice/inner.js | 7 +------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 4afebb495..7242f0d5e 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -98,20 +98,18 @@ define([ if (!Object.keys(hashes).length) { p = 100-100*((messageIndex ) / (-msgs.length)); } else { - var lastHash = Object.keys(hashes).pop() - var lastestHash = hashes[lastHash].hash + var lastestHash = hashes[Object.keys(hashes).pop()].hash if (lastestHash === config.onlyoffice.lastHash) { var hashLength = Object.keys(hashes).length } else { var hashLength = Object.keys(hashes).length+1 - } var checkpoints = id/hashLength p = 100*(checkpoints) var poz = 100-p if (id === 0) { - p= 0 + p = 0 poz = 100/hashLength } @@ -144,8 +142,6 @@ define([ if (!Array.isArray(data.messages)) { return; } - console.log("from", fromHash) - console.log("to", toHash) let initialCp = cpIndex === sortedCp.length || cp ? !cp?.hash : undefined; const messages = (data.messages || []).slice(initialCp || APP.ooconfig.documentType === 'spreadsheet' ? 0 : 1); @@ -229,12 +225,13 @@ define([ var version = v.split('.') var hashesLength = Object.keys(hashes).length - - if ((hashesLength === parseInt(version[0]) && (ooMessages[id].length === parseInt(version[1]) || parseInt(version[1]) === 0)) - // && lastestHash === config.onlyoffice.lastHash - ) { - // $next.prop('disabled', 'disabled'); - // $fastNext.prop('disabled', 'disabled'); + var lastestHash = hashes[Object.keys(hashes).pop()].hash + + if (hashesLength === parseInt(version[0]) && ooMessages[id].length === parseInt(version[1]) || + hashesLength === parseInt(version[0]) && parseInt(version[1]) === 0 && lastestHash === config.onlyoffice.lastHash) + { + $next.prop('disabled', 'disabled'); + $fastNext.prop('disabled', 'disabled'); } }; diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index cb0d22b38..63cf2526d 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -3195,14 +3195,11 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null }; var makeSnapshot = function (title, cb, obj) { var hash, time; - console.log("obj", obj) if (obj && obj.hash) { - console.log("i") hash = obj.hash; - time = time = +new Date(); + time = time = +new Date(); } else { - console.log("11") var major = Object.keys(content.hashes).length; var cpIndex = getLastCp().index || 0; var minor = ooChannel.cpIndex - cpIndex; @@ -3216,13 +3213,11 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null title: title, time: time }; - console.log("spap", snapshots) metadataMgr.updateMetadata(md); APP.onLocal(); APP.realtime.onSettle(cb); }; var loadSnapshot = function (hash) { - console.log("hash", hash) sframeChan.event('EV_OO_OPENVERSION', { hash: hash }); From dacc38de503d0d43c4a1ec82a55a44bbf2622634 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 14 Nov 2025 11:34:37 +0100 Subject: [PATCH 38/51] timeline position code cleanup --- www/common/onlyoffice/history.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 7242f0d5e..801f4bbc1 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -98,24 +98,22 @@ define([ if (!Object.keys(hashes).length) { p = 100-100*((messageIndex ) / (-msgs.length)); } else { - var lastestHash = hashes[Object.keys(hashes).pop()].hash - if (lastestHash === config.onlyoffice.lastHash) { - var hashLength = Object.keys(hashes).length + var lastHash = hashes[Object.keys(hashes).pop()].hash; + if (lastHash === config.onlyoffice.lastHash) { + var hashLength = Object.keys(hashes).length; } else { - var hashLength = Object.keys(hashes).length+1 + var hashLength = Object.keys(hashes).length+1; } - var checkpoints = id/hashLength - p = 100*(checkpoints) - var poz = 100-p + var segments = id/hashLength; + p = 100*(segments); if (id === 0) { - p = 0 - poz = 100/hashLength + p = 0; } - var poz1 = ((position/msgs.length)*100) - var poz2 = (poz1/100)*(100/hashLength) - p = p+poz2 + var percentage = ((position/msgs.length)*100); + var timelinePosition = (percentage/100)*(100/hashLength); + p += timelinePosition; } $pos.css('margin-left', p+'%'); From 24f6f7e4a7921a0a01353de2b53e563bb6d9b804 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 14 Nov 2025 13:31:06 +0100 Subject: [PATCH 39/51] cleaning and refactoring --- .../src/less2/include/toolbar-history.less | 4 +- www/common/onlyoffice/history.js | 199 ++++++++---------- www/common/onlyoffice/inner.js | 24 +-- www/common/onlyoffice/main.js | 3 - www/common/sframe-common-history.js | 1 - 5 files changed, 92 insertions(+), 139 deletions(-) diff --git a/customize.dist/src/less2/include/toolbar-history.less b/customize.dist/src/less2/include/toolbar-history.less index 2eda57cd5..53f2b6880 100644 --- a/customize.dist/src/less2/include/toolbar-history.less +++ b/customize.dist/src/less2/include/toolbar-history.less @@ -124,7 +124,7 @@ width: 2px !important; background: @pos-color; &:before { - right: -6px; + left: -6px; } } } @@ -262,7 +262,7 @@ top: -17px; font-size: 24px; position: absolute; - right: ~"calc(50% - 6px)"; + left: ~"calc(50% - 6px)"; } } @media screen and (max-width: 870px) { diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 801f4bbc1..f5e44a207 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -17,7 +17,7 @@ define([ var $toolbar = config.$toolbar; var sframeChan = common.getSframeChannel(); History.readOnly = common.getMetadataMgr().getPrivateData().readOnly || !common.isLoggedIn(); - + if (!config.onlyoffice || !config.setHistory || !config.onCheckpoint || !config.onPatch || !config.makeSnapshot) { throw new Error("Missing config element"); } @@ -31,8 +31,6 @@ define([ var position; var patch; var v; - var fromHash; - var toHash // Get an array of the checkpoint IDs sorted their patch index var hashes = config.onlyoffice.hashes; @@ -67,24 +65,24 @@ define([ var Messages = common.Messages; var getVersion = function (position) { - if (Object.keys(ooMessages).length) { - var version = (id === -1 || id === 0) ? 0 : id; + if (Object.keys(ooMessages).length) { + let version = (id === -1 || id === 0) ? 0 : id; + if (position === undefined) { - position = ooMessages[id].length || 0 - } else if (position === ooMessages[id]?.length && hashes[version+1]) { + position = ooMessages[id]?.length || 0; + } else if (position === ooMessages[id]?.length && hashes[version + 1]) { position = 0; - if (ooMessages[id].length) { - version = version + 1; - } + if (ooMessages[id]?.length) { + version++; + } } - v = version + '.' + position; - return v + return version + '.' + position; } }; var showVersion = function (initial, position) { - var v = getVersion(position, initial); + v = getVersion(position, initial); if (initial) { v = Messages.oo_version_latest; } @@ -122,7 +120,7 @@ define([ currentTime = time; if (time) { $time.text(new Date(time).toLocaleString()); } else { $time.text(''); } - update() + update(); }; function getMessages(fromHash, toHash, cpIndex, sortedCp, cp, config, fillOO, $share, ooCheckpoints, callback) { @@ -131,22 +129,13 @@ define([ lastKnownHash: fromHash, toHash: toHash, }, function (err, data) { - if (err) { - console.error(err); - callback(err); - return; - } - - if (!Array.isArray(data.messages)) { - return; - } + if (err) { return void console.error(err); } + if (!Array.isArray(data.messages)) { return void console.error('Not an array!'); } + var messages = (data.messages || []).slice(initialCp || APP.ooconfig.documentType === 'spreadsheet' ? 0 : 1); let initialCp = cpIndex === sortedCp.length || cp ? !cp?.hash : undefined; - const messages = (data.messages || []).slice(initialCp || APP.ooconfig.documentType === 'spreadsheet' ? 0 : 1); - if (config.debug) { - console.log(data.messages); - } + if (config.debug) { console.log(data.messages); } id = id !== undefined ? id : getId(); fillOO(messages, ooCheckpoints); loading = false; @@ -174,8 +163,8 @@ define([ var nextId = hashes[id+1] ? hashes[id+1] : undefined; - toHash = nextId ? nextId.hash : config.onlyoffice.lastHash; - fromHash = cp?.hash || 'NONE'; + var toHash = nextId ? nextId.hash : config.onlyoffice.lastHash; + var fromHash = cp?.hash || 'NONE'; getMessages(toHash, fromHash, cpIndex, sortedCp, undefined, config, fillOO, $share, hashes, function (err, messages) { if (err) { @@ -220,14 +209,12 @@ define([ if ((id === -1 || id === 0) && ooMessages[id]?.length+2=== Math.abs(msgIndex)) { $prev.prop('disabled', 'disabled'); } - - var version = v.split('.') - var hashesLength = Object.keys(hashes).length - var lastestHash = hashes[Object.keys(hashes).pop()].hash - + var version = v.split('.'); + var hashesLength = Object.keys(hashes).length; + var lastestHash = hashes[Object.keys(hashes).pop()]?.hash; + if (hashesLength === parseInt(version[0]) && ooMessages[id].length === parseInt(version[1]) || - hashesLength === parseInt(version[0]) && parseInt(version[1]) === 0 && lastestHash === config.onlyoffice.lastHash) - { + hashesLength === parseInt(version[0]) && parseInt(version[1]) === 0 && lastestHash === config.onlyoffice.lastHash) { $next.prop('disabled', 'disabled'); $fastNext.prop('disabled', 'disabled'); } @@ -245,85 +232,72 @@ define([ APP.next = true; msgIndex++; msgs = ooMessages[id]; + if (Object.keys(hashes).length) { if (msgIndex === 0) { id++; - loadMoreOOHistory().then(() => { - msgs = ooMessages[id]; - if (!msgs.length) { - id++; - config.loadCp(hashes[id]); - return loadMoreOOHistory().then(() => { - loadingFalse(); - msgIndex = -ooMessages[id].length-1; - position = msgs.indexOf(patch)+1 - showVersion(false, position); - return; - }); - } + await loadMoreOOHistory(); + msgs = ooMessages[id]; + + if (!msgs.length) { + id++; + config.loadCp(hashes[id]); + await loadMoreOOHistory(); + msgIndex = -ooMessages[id].length - 1; + } else { msgIndex = -msgs.length; - patch = msgs[msgs.length + msgIndex] ? msgs[msgs.length + msgIndex] : undefined; - var cp = hashes[id]; - config.onPatchBack(cp, [patch]); - position = msgs.indexOf(patch)+1 - showVersion(false, position); - loadingFalse(); - }) - return; - } - else if (Math.abs(msgIndex) > msgs.length && msgs.length) { - msgIndex = -msgs.length; + patch = msgs[msgs.length + msgIndex]; + config.onPatchBack(hashes[id], [patch]); + } + } else { + if (!msgs.length) return config.onPatchBack(hashes[id + 1]); + if (Math.abs(msgIndex) > msgs.length) msgIndex = -msgs.length; } - else if (!msgs.length) { - config.onPatchBack(hashes[id+1]); - return; - } - } - else if (msgs.length + msgIndex === -1) { + } else if (msgs.length + msgIndex === -1) { msgIndex++; } + patch = msgs[msgs.length + msgIndex]; - config.onPatch(patch); - position = msgs.indexOf(patch)+1 + position = msgs.indexOf(patch) + 1; + config.onPatch?.(patch); showVersion(false, position); loadingFalse(); }; + var msgs; var prev = function () { - APP.next = false + APP.next = false; msgs = ooMessages[id]; - if (!Object.keys(hashes).length) { - var cp = {}; - } else { - if (msgs.length+1 === Math.abs(msgIndex) && id !== 0 || !msgs.length || msgs.length-Math.abs(msgIndex) === -2) { - id--; - msgIndex = -1; - loadMoreOOHistory().then(() => { - msgs = ooMessages[id]; - var queue = msgs.slice(0, msgIndex); - var cp = hashes[id]; - config.onPatchBack(cp, queue); - position = queue.length - patch = queue[queue.length-1] - showVersion(false, position); - msgIndex--; - loadingFalse(); - }); - return; - } - var cp = hashes[id]; - } - var queue = msgs.slice(0, msgIndex); - config.onPatchBack(cp, queue); - position = queue.length - patch = queue[queue.length-1] - showVersion(false, position); - msgIndex--; - loadingFalse(); - }; + let hasHashes = Object.keys(hashes).length; + let cp = hasHashes ? hashes[id] : {}; + let loadPrevCp = (!msgs.length) || + (msgs.length + 1 === Math.abs(msgIndex) && id !== 0) || + (msgs.length - Math.abs(msgIndex) === -2); + + var goBack = function () { + var q = msgs.slice(0, msgIndex); + config.onPatchBack(cp, q); + position = q.length; + patch = q[position - 1]; + showVersion(false, position); + msgIndex--; + loadingFalse(); + } + if (hasHashes && loadPrevCp) { + id--; + msgIndex = -1; + return loadMoreOOHistory().then(() => { + msgs = ooMessages[id]; + cp = hashes[id]; + goBack(); + }); + } + + goBack(); + }; // Create the history toolbar var display = function () { @@ -421,20 +395,17 @@ define([ // Push one patch $next.click(function () { - // if (loading) { return; } + if (loading) { return; } loading = true; - next() - // .then( - // update() - // ); + next(); }); $prev.click(function () { if (loading) { return; } loading = true; prev(); - // update(true); }); - // Go to previous checkpoint + + // Go to next checkpoint $fastNext.click(function () { if (loading) { return; } loading = true; @@ -450,11 +421,8 @@ define([ config.loadCp(cp); msgs = ooMessages[id]; msgIndex = -msgs.length-1 - setTimeout(function () { - showVersion(false, 0) - update(); - loading = false; - }, 100); + showVersion(false, 0) + loading = false; return; }); } else { @@ -463,15 +431,12 @@ define([ msgIndex = -1; config.onPatchBack(cp, msgs); } - showVersion(false, 0); - setTimeout(function () { - update('end'); - loading = false; - }, 100); - position = msgs.length + loading = false; + position = msgs?.length showVersion(false, position) }); + // Go to next checkpoint $fastPrev.click(function () { if (loading) { return; } @@ -508,7 +473,7 @@ define([ }); }); $(snapshot).click(function () { - if (cpIndex === -1 && msgIndex === -1) { return void UI.warn(Messages.snapshots_ooPickVersion); } + // if (cpIndex === -1 && msgIndex === -1) { return void UI.warn(Messages.snapshots_ooPickVersion); } var input = h('input', { placeholder: Messages.snapshots_placeholder }); diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 63cf2526d..694465592 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -598,7 +598,6 @@ define([ isLockedModal.modal = UI.openCustomModal(isLockedModal.content); } ooChannel.ready = false; - // ooChannel.queue = []; data.callback = function () { if (APP.template) { APP.template = false; } resetData(blob, file); @@ -792,11 +791,9 @@ define([ var minor = Number(s[1]) + 1; if (APP.isDownload) { minor = undefined; } - var toHash = cp.hash || 'NONE'; - // var fromHash = content.hashes[1].hash - var fromHash = nextCpId ? hashes[nextCpId].hash : 'NONE'; - console.log('hello version', version, major, minor ) + var toHash = cp.hash || 'NONE'; + var fromHash = nextCpId ? hashes[nextCpId].hash : 'NONE'; sframeChan.query('Q_GET_HISTORY_RANGE', { channel: content.channel, @@ -812,11 +809,7 @@ define([ // The first "cp" in history is the empty doc. It doesn't include the first patch // of the history - var initialCp = major === 0 || !cp.hash; - const messages = data.messages - // var messages = (data.messages || []).slice(initialCp); - - console.log("messages", initialCp, minor, messages, fromHash, toHash, ooChannel, content.hashes) + var messages = data.messages messages.forEach(function (obj) { try { obj.msg = JSON.parse(obj.msg); } catch (e) { console.error(e); } @@ -825,7 +818,6 @@ define([ // The version exists if we have results in the "messages" array // or if we requested a x.0 version var exists = !Number(s[1]) || messages.length; - // console.log("exists", exists, !Number(s[1]), messages.length) var vHashEl; if (!privateData.embed) { @@ -1448,7 +1440,7 @@ define([ return; } - // debug(obj, 'toOOClient'); + debug(obj, 'toOOClient'); APP.docEditor.sendMessageToOO(obj); if (obj && obj.type === "saveChanges") { evIntegrationSave.fire(); @@ -1456,7 +1448,7 @@ define([ }; const fromOOHandler = function (obj) { - // debug(obj, 'fromOOClient'); + debug(obj, 'fromOOClient'); switch (obj.type) { case "auth": // Handled by onlyoffice-editor now @@ -2212,7 +2204,7 @@ define([ c.forcesave = true; } - // console.error('updated config', ooconfig); + console.error('updated config', ooconfig); return ooconfig; }; @@ -3195,9 +3187,9 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null }; var makeSnapshot = function (title, cb, obj) { var hash, time; - if (obj && obj.hash) { + if (obj && obj.hash && obj.time) { hash = obj.hash; - time = time = +new Date(); + time = obj.time; } else { var major = Object.keys(content.hashes).length; diff --git a/www/common/onlyoffice/main.js b/www/common/onlyoffice/main.js index d9164d164..c3751aa0d 100644 --- a/www/common/onlyoffice/main.js +++ b/www/common/onlyoffice/main.js @@ -27,7 +27,6 @@ define([ var opts = parsed.getOptions(); version = opts.versionHash; } - console.log(opts, parsed, version) if (isIntegration) { href = integration.href; hash = integration.hash; @@ -37,7 +36,6 @@ define([ let path = (integration && integration.pathname) || window.location.pathname; obj.ooType = path.replace(/^\//, '').replace(/\/$/, ''); obj.ooVersionHash = version; - console.log("obj2 !!!", version) obj.ooForceVersion = localStorage.CryptPad_ooVersion || ""; }; var channels = {}; @@ -150,7 +148,6 @@ define([ if (!obj || !obj.hash) { return; } var parsed = Hash.parsePadUrl(window.location.href); var opts = parsed.getOptions(); - opts.versionHash = obj.hash; window.open(parsed.getUrl(opts)); }); diff --git a/www/common/sframe-common-history.js b/www/common/sframe-common-history.js index 4c47b1a5b..e711d5265 100644 --- a/www/common/sframe-common-history.js +++ b/www/common/sframe-common-history.js @@ -413,7 +413,6 @@ define([ try { var block = states[idx]; var hash = block.serverHash; - console.log("HASH", states, block, hash) var md = config.getLastMetadata(); md.snapshots = md.snapshots || {}; if (md.snapshots[hash]) { return; } From 5026aa3a414fb7a63753c064203c649b732f1528 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 14 Nov 2025 13:38:39 +0100 Subject: [PATCH 40/51] further cleaning --- src/common/common-hash.js | 3 +-- www/common/onlyoffice/history.js | 10 +--------- www/common/onlyoffice/inner.js | 1 - 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/common/common-hash.js b/src/common/common-hash.js index 2d94372a6..0eb4faa37 100644 --- a/src/common/common-hash.js +++ b/src/common/common-hash.js @@ -317,8 +317,7 @@ Version 4: Data URL when not a realtime link yet (new pad or "static" app) if (parsed.password || opts.password) { hash += 'p/'; } if (opts.embed) { hash += 'embed/'; } if (opts.present) { hash += 'present/'; } - var versionHash = (typeof(opts.versionHash) !== "undefined") ? opts.versionHash : parsed.versionHash; - + var versionHash = typeof(opts.versionHash) !== "undefined" ? opts.versionHash : parsed.versionHash; if (versionHash) { hash += 'hash=' + Crypto.b64RemoveSlashes(versionHash) + '/'; } diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index f5e44a207..35c25396f 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -81,7 +81,6 @@ define([ }; var showVersion = function (initial, position) { - v = getVersion(position, initial); if (initial) { v = Messages.oo_version_latest; @@ -162,7 +161,6 @@ define([ } var nextId = hashes[id+1] ? hashes[id+1] : undefined; - var toHash = nextId ? nextId.hash : config.onlyoffice.lastHash; var fromHash = cp?.hash || 'NONE'; @@ -175,7 +173,6 @@ define([ resolve(); }); }); - }; loadMoreOOHistory(); @@ -218,7 +215,6 @@ define([ $next.prop('disabled', 'disabled'); $fastNext.prop('disabled', 'disabled'); } - }; var loadingFalse = function () { @@ -295,7 +291,6 @@ define([ goBack(); }); } - goBack(); }; @@ -319,8 +314,6 @@ define([ $prev = $(_prev); $fastNext = $(fastNext).prop('disabled', 'disabled'); $next = $(_next).prop('disabled', 'disabled'); - // .prop('disabled', 'disabled'); - var pos = h('span.cp-history-timeline-pos.fa.fa-caret-down'); var time = h('div.cp-history-timeline-time'); @@ -437,7 +430,7 @@ define([ showVersion(false, position) }); - // Go to next checkpoint + // Go to previous checkpoint $fastPrev.click(function () { if (loading) { return; } loading = true; @@ -455,7 +448,6 @@ define([ position = 0; loading = false; }); - onKeyDown = function (e) { var p = function () { e.preventDefault(); }; if ([38, 39].indexOf(e.which) >= 0) { p(); return $next.click(); } // Right diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 694465592..2d60c6eb2 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -3190,7 +3190,6 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null if (obj && obj.hash && obj.time) { hash = obj.hash; time = obj.time; - } else { var major = Object.keys(content.hashes).length; var cpIndex = getLastCp().index || 0; From a13a465d4a709b7f219c39ff4171e2623d1f7ae4 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Tue, 18 Nov 2025 15:08:48 +0100 Subject: [PATCH 41/51] quick fix - variable declaration --- www/common/onlyoffice/history.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 35c25396f..e0ffbbdd9 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -131,8 +131,8 @@ 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(initialCp || APP.ooconfig.documentType === 'spreadsheet' ? 0 : 1); let initialCp = cpIndex === sortedCp.length || cp ? !cp?.hash : undefined; + var messages = (data.messages || []).slice(initialCp || APP.ooconfig.documentType === 'spreadsheet' ? 0 : 1); if (config.debug) { console.log(data.messages); } id = id !== undefined ? id : getId(); From b06b38023e7e0196a023e55b1f61c0876aa93e07 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Tue, 18 Nov 2025 18:06:53 +0100 Subject: [PATCH 42/51] merge --- www/common/onlyoffice/history.js | 1 - 1 file changed, 1 deletion(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index e0ffbbdd9..2230fe083 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -133,7 +133,6 @@ define([ let initialCp = cpIndex === sortedCp.length || cp ? !cp?.hash : undefined; var messages = (data.messages || []).slice(initialCp || APP.ooconfig.documentType === 'spreadsheet' ? 0 : 1); - if (config.debug) { console.log(data.messages); } id = id !== undefined ? id : getId(); fillOO(messages, ooCheckpoints); From d3c2d34b68944e03d99a22a1eea1179272320c2d Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Tue, 18 Nov 2025 18:35:09 +0100 Subject: [PATCH 43/51] variable name --- www/common/onlyoffice/history.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 2230fe083..d8e2d5488 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -30,7 +30,7 @@ define([ var currentTime; var position; var patch; - var v; + var currentVersion; // Get an array of the checkpoint IDs sorted their patch index var hashes = config.onlyoffice.hashes; @@ -81,11 +81,11 @@ define([ }; var showVersion = function (initial, position) { - v = getVersion(position, initial); + currentVersion = getVersion(position, initial); if (initial) { - v = Messages.oo_version_latest; + currentVersion = Messages.oo_version_latest; } - $version.text(Messages.oo_version + v); + $version.text(Messages.oo_version + currentVersion); var $pos = $hist.find('.cp-history-timeline-pos'); if (!ooMessages[id]) { return; } @@ -205,7 +205,7 @@ define([ if ((id === -1 || id === 0) && ooMessages[id]?.length+2=== Math.abs(msgIndex)) { $prev.prop('disabled', 'disabled'); } - var version = v.split('.'); + var version = currentVersion.split('.'); var hashesLength = Object.keys(hashes).length; var lastestHash = hashes[Object.keys(hashes).pop()]?.hash; From d128d3b55c04fb05ff65a02e4c3f5b526203ff3f Mon Sep 17 00:00:00 2001 From: Wolfgang Ginolas Date: Fri, 14 Nov 2025 15:41:47 +0100 Subject: [PATCH 44/51] removing cursor --- www/common/onlyoffice/inner.js | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 2d60c6eb2..bcbe93fd0 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -543,20 +543,7 @@ define([ } myUniqueOOId = undefined; setMyId(); - var editor = getEditor(); - if (editor) { - var app = common.getMetadataMgr().getPrivateData().ooType; - var d; - if (app === 'doc') { - d = editor.GetDocument() ? editor.GetDocument().Document : undefined; - } else if (app === 'presentation') { - d = editor.GetPresentation().Presentation; - } - if (d) { - APP.oldCursor = d.GetSelectionState(); - } - } - if (APP.docEditor && APP.docEditor.destroyEditor() ) { APP.docEditor.destroyEditor(); } // Kill the old editor + if (APP.docEditor) { APP.docEditor.destroyEditor(); } // Kill the old editor $('iframe[name="frameEditor"]').after(h('div#cp-app-oo-placeholder-a')).remove(); ooLoaded = false; oldLocks = {}; @@ -2039,20 +2026,6 @@ define([ getEditor().asc_setDefaultLanguage(l); } - if (APP.oldCursor) { - var app = common.getMetadataMgr().getPrivateData().ooType; - var d; - if (app === 'doc') { - d = getEditor().GetDocument().Document; - } else if (app === 'presentation') { - d = getEditor().GetPresentation().Presentation; - } - if (d) { - d.SetSelectionState(APP.oldCursor); - d.UpdateSelection(); - } - delete APP.oldCursor; - } if (integrationChannel) { APP.onDocumentUnlock = () => { integrationChannel.event('EV_INTEGRATION_READY'); From 4b6f5db7501c92b2aea9a67423738539d8d81d7d Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 21 Nov 2025 15:36:12 +0100 Subject: [PATCH 45/51] corrections - wip --- www/common/onlyoffice/history.js | 65 ++++++++++++++------------------ www/common/onlyoffice/inner.js | 14 ++++++- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index d8e2d5488..5d453a59d 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -24,17 +24,17 @@ define([ var cpIndex = -1; var msgIndex = -1; - var APP = window.APP; var ooMessages = {}; var loading = false; var currentTime; var position; var patch; var currentVersion; + var forward; + var APP = window.APP; // Get an array of the checkpoint IDs sorted their patch index var hashes = config.onlyoffice.hashes; - var sortedCp = Object.keys(hashes).map(Number); var id; var sortedCp = Object.keys(hashes).map(Number).sort(function (a, b) { @@ -65,33 +65,28 @@ define([ var Messages = common.Messages; var getVersion = function (position) { - if (Object.keys(ooMessages).length) { - let version = (id === -1 || id === 0) ? 0 : id; - - if (position === undefined) { - position = ooMessages[id]?.length || 0; - } else if (position === ooMessages[id]?.length && hashes[version + 1]) { - position = 0; - if (ooMessages[id]?.length) { - version++; - } - } - return version + '.' + position; + if (!Object.keys(ooMessages).length) { return; } + let version = (id === -1 || id === 0) ? 0 : id; + + if (typeof(position) === "undefined") { + position = ooMessages[id]?.length || 0; + } else if (position === ooMessages[id]?.length && hashes[version + 1]) { + position = 0; + if (ooMessages[id]?.length) { version++; } } + return version + '.' + position; }; var showVersion = function (initial, position) { currentVersion = getVersion(position, initial); - if (initial) { - currentVersion = Messages.oo_version_latest; - } + if (initial) { currentVersion = Messages.oo_version_latest; } $version.text(Messages.oo_version + currentVersion); var $pos = $hist.find('.cp-history-timeline-pos'); if (!ooMessages[id]) { return; } var msgs = ooMessages[id]; var p; - var messageIndex = APP.next ? msgIndex+1 : msgIndex; + var messageIndex = forward ? msgIndex+1 : msgIndex; if (!Object.keys(hashes).length) { p = 100-100*((messageIndex ) / (-msgs.length)); } else { @@ -104,9 +99,7 @@ define([ var segments = id/hashLength; p = 100*(segments); - if (id === 0) { - p = 0; - } + if (id === 0) { p = 0; } var percentage = ((position/msgs.length)*100); var timelinePosition = (percentage/100)*(100/hashLength); @@ -122,7 +115,7 @@ define([ update(); }; - function getMessages(fromHash, toHash, cpIndex, sortedCp, cp, config, fillOO, $share, ooCheckpoints, callback) { + var getMessages = function(fromHash, toHash, cpIndex, sortedCp, cp, config, fillOO, $share, ooCheckpoints, callback) { sframeChan.query('Q_GET_HISTORY_RANGE', { channel: config.onlyoffice.channel, lastKnownHash: fromHash, @@ -132,9 +125,9 @@ define([ if (!Array.isArray(data.messages)) { return void console.error('Not an array!'); } let initialCp = cpIndex === sortedCp.length || cp ? !cp?.hash : undefined; - var messages = (data.messages || []).slice(initialCp || APP.ooconfig.documentType === 'spreadsheet' ? 0 : 1); + var messages = (data.messages || []).slice(initialCp || config.docType() === 'spreadsheet' ? 0 : 1); if (config.debug) { console.log(data.messages); } - id = id !== undefined ? id : getId(); + id = typeof(id) !== "undefined" ? id : getId(); fillOO(messages, ooCheckpoints); loading = false; // $share.show(); @@ -148,10 +141,10 @@ define([ return new Promise((resolve, reject) => { if (!Array.isArray(sortedCp)) { console.error("Wrong type"); - return resolve(); + return reject(); } - - id = id !== undefined ? id : getId(); + + id = typeof(id) !== "undefined" ? id : getId(); if (ooMessages[id-1] && !ooMessages[id-1].length) { var cp = hashes[id-1]; @@ -169,7 +162,7 @@ define([ reject(err); return; } - resolve(); + resolve(); }); }); }; @@ -178,8 +171,8 @@ define([ var onClose = function () { config.setHistory(false); }; var onRevert = function () { - APP.revert = true - config.onRevert(); + APP.revert = true; + config.onRevert(true); }; config.setHistory(true); @@ -224,7 +217,7 @@ define([ } var next = async function () { - APP.next = true; + forward = true; msgIndex++; msgs = ooMessages[id]; @@ -245,12 +238,10 @@ define([ config.onPatchBack(hashes[id], [patch]); } } else { - if (!msgs.length) return config.onPatchBack(hashes[id + 1]); - if (Math.abs(msgIndex) > msgs.length) msgIndex = -msgs.length; + if (!msgs.length) { return config.onPatchBack(hashes[id + 1]); } + if (Math.abs(msgIndex) > msgs.length) { msgIndex = -msgs.length; } } - } else if (msgs.length + msgIndex === -1) { - msgIndex++; - } + } else if (msgs.length + msgIndex === -1) { msgIndex++; } patch = msgs[msgs.length + msgIndex]; position = msgs.indexOf(patch) + 1; @@ -263,7 +254,7 @@ define([ var msgs; var prev = function () { - APP.next = false; + forward = false; msgs = ooMessages[id]; let hasHashes = Object.keys(hashes).length; let cp = hasHashes ? hashes[id] : {}; diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index bcbe93fd0..ae4df0457 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -2887,13 +2887,17 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null resetData(blob, fileType); } catch (e) { var file = getFileType(); - var type = common.getMetadataMgr().getPrivateData().ooType; + var type = common.getMetadataMgr().gistoryetPrivateData().ooType; var blob = loadInitDocument(type, true); if (!keepQueue) { ooChannel.queue = []; } resetData(blob, file); } }; + var loadHistoryCp = function (cp, keepQueue) { + loadCp(cp, keepQueue) + } + var loadTemplate = function (href, pw, parsed) { APP.history = true; APP.template = true; @@ -3097,10 +3101,11 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null if (!privateData.ooVersionHash) { (function () { /* add a history button */ - var commit = function () { + var commit = function (revert) { // 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.revert = revert ? true : false; APP.stopHistory = true; makeCheckpoint(true); }; @@ -3134,6 +3139,9 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null loadCp(cp); } }; + var docType = function() { + return APP.ooconfig.documentType; + } var setHistoryMode = function (bool) { if (bool) { APP.history = true; @@ -3201,7 +3209,9 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null var histConfig = { onPatch: onPatch, onPatchBack: onPatchBack, + docType: docType, loadCp: loadCp, + loadHistoryCp: loadHistoryCp, onCheckpoint: onCheckpoint, onRevert: commit, setHistory: setHistoryMode, From 41a8941e37d0245488b7c20b7bf366143d92038a Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Mon, 24 Nov 2025 13:05:53 +0100 Subject: [PATCH 46/51] refactor and multiple reverts fix --- www/common/onlyoffice/history.js | 21 ++++++++++----------- www/common/onlyoffice/inner.js | 9 +++++++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 5d453a59d..d83b59a17 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -31,7 +31,6 @@ define([ var patch; var currentVersion; var forward; - var APP = window.APP; // Get an array of the checkpoint IDs sorted their patch index var hashes = config.onlyoffice.hashes; @@ -65,8 +64,10 @@ define([ var Messages = common.Messages; var getVersion = function (position) { - if (!Object.keys(ooMessages).length) { return; } let version = (id === -1 || id === 0) ? 0 : id; + if (!Object.keys(ooMessages).length) { + return version + '.0'; + } if (typeof(position) === "undefined") { position = ooMessages[id]?.length || 0; @@ -115,7 +116,7 @@ define([ update(); }; - var getMessages = function(fromHash, toHash, cpIndex, sortedCp, cp, config, fillOO, $share, ooCheckpoints, callback) { + var getMessages = function(fromHash, toHash, callback) { sframeChan.query('Q_GET_HISTORY_RANGE', { channel: config.onlyoffice.channel, lastKnownHash: fromHash, @@ -124,13 +125,12 @@ define([ if (err) { return void console.error(err); } if (!Array.isArray(data.messages)) { return void console.error('Not an array!'); } - let initialCp = cpIndex === sortedCp.length || cp ? !cp?.hash : undefined; + let initialCp = cpIndex === sortedCp.length; var messages = (data.messages || []).slice(initialCp || config.docType() === 'spreadsheet' ? 0 : 1); if (config.debug) { console.log(data.messages); } id = typeof(id) !== "undefined" ? id : getId(); - fillOO(messages, ooCheckpoints); + fillOO(messages); loading = false; - // $share.show(); callback(null, messages); }); @@ -156,7 +156,7 @@ define([ var toHash = nextId ? nextId.hash : config.onlyoffice.lastHash; var fromHash = cp?.hash || 'NONE'; - getMessages(toHash, fromHash, cpIndex, sortedCp, undefined, config, fillOO, $share, hashes, function (err, messages) { + getMessages(toHash, fromHash, function (err, messages) { if (err) { console.error(err); reject(err); @@ -171,7 +171,6 @@ define([ var onClose = function () { config.setHistory(false); }; var onRevert = function () { - APP.revert = true; config.onRevert(true); }; @@ -229,7 +228,7 @@ define([ if (!msgs.length) { id++; - config.loadCp(hashes[id]); + config.loadHistoryCp(hashes[id]); await loadMoreOOHistory(); msgIndex = -ooMessages[id].length - 1; } else { @@ -401,7 +400,7 @@ define([ loadMoreOOHistory().then(() => { var cp = hashes[id]; loadMoreOOHistory(); - config.loadCp(cp); + config.loadHistoryCp(cp); msgs = ooMessages[id]; msgIndex = -msgs.length-1 showVersion(false, 0) @@ -428,7 +427,7 @@ define([ id--; } var cp = hashes[id]; - config.loadCp(cp); + config.loadHistoryCp(cp); loadMoreOOHistory().then(() => { var msgs = ooMessages[id]; msgIndex = -msgs.length-2; diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index ae4df0457..c1b53d418 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -584,6 +584,7 @@ define([ if (!isLockedModal.modal) { isLockedModal.modal = UI.openCustomModal(isLockedModal.content); } + ooChannel.queue = []; ooChannel.ready = false; data.callback = function () { if (APP.template) { APP.template = false; } @@ -2887,7 +2888,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null resetData(blob, fileType); } catch (e) { var file = getFileType(); - var type = common.getMetadataMgr().gistoryetPrivateData().ooType; + var type = common.getMetadataMgr().getPrivateData().ooType; var blob = loadInitDocument(type, true); if (!keepQueue) { ooChannel.queue = []; } resetData(blob, file); @@ -2895,6 +2896,8 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null }; var loadHistoryCp = function (cp, keepQueue) { + APP.history = true; + APP.stopHistory = false; loadCp(cp, keepQueue) } @@ -3105,7 +3108,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null // 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.revert = revert ? true : false; + APP.revert = revert ? true : false; APP.stopHistory = true; makeCheckpoint(true); }; @@ -3118,6 +3121,8 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null loadCp(cp, true); }; var onPatchBack = function (cp, msgs) { + APP.history = true; + APP.stopHistory = false; if (msgs) { var msgsFormatted = []; msgs.forEach(function(msg) { From cc3be919ac10a267ecd2bf783d6f416b6bfadee3 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 28 Nov 2025 16:11:26 +0100 Subject: [PATCH 47/51] further cleanup --- www/common/onlyoffice/history.js | 6 ++---- www/common/onlyoffice/inner.js | 9 +++------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index d83b59a17..7d47a8d39 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -36,9 +36,7 @@ define([ var hashes = config.onlyoffice.hashes; var id; - var sortedCp = Object.keys(hashes).map(Number).sort(function (a, b) { - return hashes[a].index - hashes[b].index; - }); + var sortedCp = Object.keys(hashes).map(Number); var getId = function () { var cps = sortedCp.length; @@ -69,7 +67,7 @@ define([ return version + '.0'; } - if (typeof(position) === "undefined") { + if (typeof(position) === "undefined" || position === -1) { position = ooMessages[id]?.length || 0; } else if (position === ooMessages[id]?.length && hashes[version + 1]) { position = 0; diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index c1b53d418..05b8edbc6 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -574,11 +574,9 @@ define([ blob.name = title || (metadataMgr.getMetadataLazy().title || file.doc) + '.' + file.type; var data = { hash: (APP.history || APP.template) ? ooChannel.historyLastHash : ooChannel.lastHash, - index: APP.revert ? ooChannel.currentIndex : ooChannel.cpIndex + index: (APP.history || APP.template) ? ooChannel.currentIndex : ooChannel.cpIndex }; - if (APP.revert) { - APP.revert = false; - } + fixSheets(); if (!isLockedModal.modal) { @@ -3104,11 +3102,10 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null if (!privateData.ooVersionHash) { (function () { /* add a history button */ - var commit = function (revert) { + var commit = function () { // 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.revert = revert ? true : false; APP.stopHistory = true; makeCheckpoint(true); }; From c37def5b723506941cf1980152111a3664feb699 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Tue, 2 Dec 2025 10:33:40 +0100 Subject: [PATCH 48/51] cleaning, comments, improvements for 'revert' checkpoints --- www/common/onlyoffice/history.js | 337 +++++++++++++++++++------------ www/common/onlyoffice/inner.js | 16 +- 2 files changed, 214 insertions(+), 139 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 7d47a8d39..b39910821 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -27,7 +27,9 @@ define([ var ooMessages = {}; var loading = false; var currentTime; + //Defining position here means it can be passed to the showVersion and share functions var position; + //Defining patch here means it can be passed to the snapshot function var patch; var currentVersion; var forward; @@ -64,18 +66,143 @@ define([ var getVersion = function (position) { let version = (id === -1 || id === 0) ? 0 : id; if (!Object.keys(ooMessages).length) { - return version + '.0'; + return '0.0'; } - if (typeof(position) === "undefined" || position === -1) { position = ooMessages[id]?.length || 0; - } else if (position === ooMessages[id]?.length && hashes[version + 1]) { - position = 0; - if (ooMessages[id]?.length) { version++; } - } + } return version + '.' + position; }; + // var showVersion = function (initial, position) { + // currentVersion = getVersion(position, initial); + // if (initial) { currentVersion = Messages.oo_version_latest; } + // $version.text(Messages.oo_version + currentVersion); + + // var $pos = $hist.find('.cp-history-timeline-pos'); + // if (!ooMessages[id]) { return; } + // var msgs = ooMessages[id]; + // var p; + // var messageIndex = forward ? msgIndex+1 : msgIndex; + // if (!Object.keys(hashes).length) { + // p = 100-100*((messageIndex ) / (-msgs.length)); + // } else { + // var lastHash = hashes[Object.keys(hashes).pop()].hash; + // if (lastHash === config.onlyoffice.lastHash) { + // var hashLength = Object.keys(hashes).length; + // } else { + // var hashLength = Object.keys(hashes).length+1; + // } + // var segments = id/hashLength; + // p = 100*(segments); + + // if (id === 0) { p = 0; } + + // var percentage = ((position/msgs.length)*100); + // var timelinePosition = (percentage/100)*(100/hashLength); + // p += timelinePosition; + // } + + // $pos.css('margin-left', p+'%'); + + // var time = msgs[msgIndex] && msgs[msgIndex].time; + // currentTime = time; + // if (time) { $time.text(new Date(time).toLocaleString()); } + // else { $time.text(''); } + // update(); + // loadingFalse(); + // }; + + var getMessages = function(fromHash, toHash, callback) { + sframeChan.query('Q_GET_HISTORY_RANGE', { + channel: config.onlyoffice.channel, + lastKnownHash: fromHash, + toHash: toHash, + }, function (err, data) { + if (err) { return void console.error(err); } + if (!Array.isArray(data.messages)) { return void console.error('Not an array!'); } + + let initialCp = cpIndex === sortedCp.length; + var messages = (data.messages || []).slice(initialCp || config.docType() === 'spreadsheet' ? 0 : 1); + if (config.debug) { console.log(data.messages); } + id = typeof(id) !== "undefined" ? id : getId(); + fillOO(messages); + loading = false; + + callback(null, messages); + }); + }; + + // We want to load a checkpoint (or initial state) + var loadMoreOOHistory = function () { + return new Promise((resolve, reject) => { + if (!Array.isArray(sortedCp)) { + console.error("Wrong type"); + return reject(); + } + + id = typeof(id) !== "undefined" ? id : getId(); + var cp; + if (ooMessages[id-1] && !ooMessages[id-1].length) { + cp = hashes[id-1]; + } else { + cp = hashes[id]; + } + + var nextId = hashes[id+1] ? hashes[id+1] : undefined; + var toHash = nextId ? nextId.hash : config.onlyoffice.lastHash; + var fromHash = cp?.hash || 'NONE'; + + getMessages(toHash, fromHash, function (err) { + if (err) { + console.error(err); + reject(err); + return; + } + resolve(); + }); + }); + }; + + loadMoreOOHistory(); + + var onClose = function () { config.setHistory(false); }; + var onRevert = function () { + config.onRevert(true); + }; + + config.setHistory(true); + + $hist.html('').css('display', 'flex'); + $bottom.hide(); + + UI.spinner($hist).get().show(); + + var $fastPrev, $fastNext, $next, $prev; + + var update = function () { + $fastPrev.show(); + $next.show(); + $prev.show(); + $fastNext.show(); + $hist.find('.cp-toolbar-history-next, .cp-toolbar-history-previous') + .prop('disabled', ''); + + if ((id === -1 || id === 0) && (ooMessages[id]?.length+1 === Math.abs(msgIndex) || ooMessages[id]?.length+2 === Math.abs(msgIndex))) { + $prev.prop('disabled', 'disabled'); + $fastPrev.prop('disabled', 'disabled'); + } + var version = currentVersion.split('.'); + var hashesLength = Object.keys(hashes).length; + + if (hashesLength === parseInt(version[0]) && ooMessages[id].length === parseInt(version[1]) || + hashesLength+1 === id && (msgIndex === -1) && forward || + hashes[hashesLength-1] === id && !ooMessages[id].length && msgIndex === 0) { + $next.prop('disabled', 'disabled'); + $fastNext.prop('disabled', 'disabled'); + } + }; + var showVersion = function (initial, position) { currentVersion = getVersion(position, initial); if (initial) { currentVersion = Messages.oo_version_latest; } @@ -112,98 +239,7 @@ define([ if (time) { $time.text(new Date(time).toLocaleString()); } else { $time.text(''); } update(); - }; - - var getMessages = function(fromHash, toHash, callback) { - sframeChan.query('Q_GET_HISTORY_RANGE', { - channel: config.onlyoffice.channel, - lastKnownHash: fromHash, - toHash: toHash, - }, function (err, data) { - if (err) { return void console.error(err); } - if (!Array.isArray(data.messages)) { return void console.error('Not an array!'); } - - let initialCp = cpIndex === sortedCp.length; - var messages = (data.messages || []).slice(initialCp || config.docType() === 'spreadsheet' ? 0 : 1); - if (config.debug) { console.log(data.messages); } - id = typeof(id) !== "undefined" ? id : getId(); - fillOO(messages); - loading = false; - - callback(null, messages); - }); - } - - // We want to load a checkpoint (or initial state) - var loadMoreOOHistory = function (cb) { - return new Promise((resolve, reject) => { - if (!Array.isArray(sortedCp)) { - console.error("Wrong type"); - return reject(); - } - - id = typeof(id) !== "undefined" ? id : getId(); - - if (ooMessages[id-1] && !ooMessages[id-1].length) { - var cp = hashes[id-1]; - } else { - var cp = hashes[id]; - } - - var nextId = hashes[id+1] ? hashes[id+1] : undefined; - var toHash = nextId ? nextId.hash : config.onlyoffice.lastHash; - var fromHash = cp?.hash || 'NONE'; - - getMessages(toHash, fromHash, function (err, messages) { - if (err) { - console.error(err); - reject(err); - return; - } - resolve(); - }); - }); - }; - - loadMoreOOHistory(); - - var onClose = function () { config.setHistory(false); }; - var onRevert = function () { - config.onRevert(true); - }; - - config.setHistory(true); - - $hist.html('').css('display', 'flex'); - $bottom.hide(); - - UI.spinner($hist).get().show(); - - var $fastPrev, $fastNext, $next, $prev; - - var update = function () { - $fastPrev.show(); - $next.show(); - $prev.show(); - $fastNext.show(); - $hist.find('.cp-toolbar-history-next, .cp-toolbar-history-previous') - .prop('disabled', ''); - - if ((id === -1 || id === 0) && Math.abs(msgIndex) === ooMessages[id]?.length+2) { - $fastPrev.prop('disabled', 'disabled'); - } - if ((id === -1 || id === 0) && ooMessages[id]?.length+2=== Math.abs(msgIndex)) { - $prev.prop('disabled', 'disabled'); - } - var version = currentVersion.split('.'); - var hashesLength = Object.keys(hashes).length; - var lastestHash = hashes[Object.keys(hashes).pop()]?.hash; - - if (hashesLength === parseInt(version[0]) && ooMessages[id].length === parseInt(version[1]) || - hashesLength === parseInt(version[0]) && parseInt(version[1]) === 0 && lastestHash === config.onlyoffice.lastHash) { - $next.prop('disabled', 'disabled'); - $fastNext.prop('disabled', 'disabled'); - } + loadingFalse(); }; var loadingFalse = function () { @@ -211,74 +247,110 @@ define([ $('iframe').blur(); loading = false; }, 200); - } + }; + + var lastPatchIndex; + var nextPatchIndex; + var msgs; var next = async function () { forward = true; msgIndex++; msgs = ooMessages[id]; - + lastPatchIndex = 0; if (Object.keys(hashes).length) { + //Check if the end of the checkpoint has been reached and the next one should be loaded if (msgIndex === 0) { id++; await loadMoreOOHistory(); msgs = ooMessages[id]; - + //Empty checkpoint (checkpoint created/history restored with no further changes) if (!msgs.length) { - id++; config.loadHistoryCp(hashes[id]); await loadMoreOOHistory(); - msgIndex = -ooMessages[id].length - 1; + msgIndex = -ooMessages[id].length; + showVersion(false); + return; } else { - msgIndex = -msgs.length; - patch = msgs[msgs.length + msgIndex]; - config.onPatchBack(hashes[id], [patch]); + //Is the checkpoint the result of restoring history? If yes, we need to load an extra patch + if (nextPatchIndex !== 0 && Math.abs(nextPatchIndex - JSON.parse(msgs[0].msg).changesIndex) <= 1) { + msgIndex = -ooMessages[id].length; + config.onPatchBack(hashes[id], [msgs[0]]); + position = 1; + } else { + msgIndex = -ooMessages[id].length-1; + config.loadHistoryCp(hashes[id]); + position = 0; + } + showVersion(false, position); + return; } } else { - if (!msgs.length) { return config.onPatchBack(hashes[id + 1]); } + if (!msgs.length) { + position = 0; + showVersion(false, 0); + return config.loadHistoryCp(hashes[id + 1]); } + //Adjust msgIndex after fastPrev if (Math.abs(msgIndex) > msgs.length) { msgIndex = -msgs.length; } } - } else if (msgs.length + msgIndex === -1) { msgIndex++; } + } + else if (msgs.length + msgIndex === -1) { msgIndex++; } patch = msgs[msgs.length + msgIndex]; position = msgs.indexOf(patch) + 1; config.onPatch?.(patch); + nextPatchIndex = JSON.parse(patch.msg).changesIndex; showVersion(false, position); - loadingFalse(); }; - - var msgs; - var prev = function () { forward = false; msgs = ooMessages[id]; + nextPatchIndex = 0; let hasHashes = Object.keys(hashes).length; let cp = hasHashes ? hashes[id] : {}; let loadPrevCp = (!msgs.length) || (msgs.length + 1 === Math.abs(msgIndex) && id !== 0) || (msgs.length - Math.abs(msgIndex) === -2); - - var goBack = function () { - var q = msgs.slice(0, msgIndex); - config.onPatchBack(cp, q); - position = q.length; - patch = q[position - 1]; - showVersion(false, position); - msgIndex--; - loadingFalse(); - } + //Check if the end of the checkpoint has been reached and the previous one should be loaded if (hasHashes && loadPrevCp) { id--; msgIndex = -1; return loadMoreOOHistory().then(() => { + //Empty checkpoint - checkpoint saved with no further changes + if (!msgs.length) { + msgs = ooMessages[id]; + config.onPatchBack(hashes[id], msgs.slice(0, msgIndex)); + msgIndex--; + showVersion(false); + return; + } msgs = ooMessages[id]; cp = hashes[id]; - goBack(); + var q = msgs.slice(0, msgIndex); + patch = msgs[msgs.length-1]; + var currentPatchIndex = JSON.parse(patch.msg).changesIndex; + position = msgs.indexOf(patch); + //Is the checkpoint the result of restoring history? If yes, we need to load an extra patch + if (lastPatchIndex !==0 && Math.abs(lastPatchIndex - currentPatchIndex) <= 1) { + config.onPatchBack(cp, q); + msgIndex--; + } else { + config.onPatchBack(cp, msgs); + } + showVersion(false, position); }); } - goBack(); + + patch = msgs[msgs.length + msgIndex]; + var q = msgs.slice(0, msgIndex); + config.onPatchBack(cp, q); + patch = msgs[msgs.length + msgIndex]; + msgIndex--; + position = msgs.indexOf(patch); + lastPatchIndex = JSON.parse(patch.msg).changesIndex; + showVersion(false, position); }; // Create the history toolbar @@ -387,6 +459,7 @@ define([ // Go to next checkpoint $fastNext.click(function () { + lastPatchIndex = 0; if (loading) { return; } loading = true; if (id < Object.keys(hashes).length && id !== -1) { @@ -399,9 +472,10 @@ define([ var cp = hashes[id]; loadMoreOOHistory(); config.loadHistoryCp(cp); - msgs = ooMessages[id]; - msgIndex = -msgs.length-1 - showVersion(false, 0) + var msgs = ooMessages[id]; + msgIndex = -msgs.length-1; + position = 0; + showVersion(false, position); loading = false; return; }); @@ -413,8 +487,8 @@ define([ } loading = false; - position = msgs?.length - showVersion(false, position) + position = msgs?.length; + showVersion(false, position); }); // Go to previous checkpoint @@ -428,8 +502,9 @@ define([ config.loadHistoryCp(cp); loadMoreOOHistory().then(() => { var msgs = ooMessages[id]; + lastPatchIndex = JSON.parse(msgs[0].msg).changesIndex; msgIndex = -msgs.length-2; - showVersion(false, 0) + showVersion(false, 0); update(true); }); position = 0; @@ -474,7 +549,7 @@ define([ onClick: function () { var val = $input.val(); if (!val) { return true; } - msgs = ooMessages[id] + msgs = ooMessages[id]; config.makeSnapshot(val, function (err) { if (err) { return; } $input.val(''); diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 05b8edbc6..e1daba3f4 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -767,7 +767,7 @@ define([ return hashes[a].index - hashes[b].index; }); var s = version.split('.'); - var version = parseInt(s[1]) + var v = parseInt(s[1]); if (s.length !== 2) { return UI.errorLoadingScreen(Messages.error); } var major = Number(s[0]); @@ -795,7 +795,7 @@ define([ // The first "cp" in history is the empty doc. It doesn't include the first patch // of the history - var messages = data.messages + var messages = data.messages; messages.forEach(function (obj) { try { obj.msg = JSON.parse(obj.msg); } catch (e) { console.error(e); } @@ -828,7 +828,7 @@ define([ loadLastDocument(cp) .then(({blob, fileType}) => { - ooChannel.queue = messages.slice(1, minor) + ooChannel.queue = messages.slice(1, minor); resetData(blob, fileType); UI.removeLoadingScreen(); }) @@ -844,7 +844,7 @@ define([ var type = common.getMetadataMgr().getPrivateData().ooType; if (APP.downloadType) { type = APP.downloadType; } var blob = loadInitDocument(type, true); - ooChannel.queue = messages.slice(0, version+1) + ooChannel.queue = messages.slice(0, v+1); resetData(blob, file); UI.removeLoadingScreen(); }); @@ -2896,8 +2896,8 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null var loadHistoryCp = function (cp, keepQueue) { APP.history = true; APP.stopHistory = false; - loadCp(cp, keepQueue) - } + loadCp(cp, keepQueue); + }; var loadTemplate = function (href, pw, parsed) { APP.history = true; @@ -3132,7 +3132,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null time: msg.time }; msgsFormatted.push(formattedMsg); - }) + }); ooChannel.queue = msgsFormatted; setTimeout(function () { loadCp(cp, true); @@ -3143,7 +3143,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null }; var docType = function() { return APP.ooconfig.documentType; - } + }; var setHistoryMode = function (bool) { if (bool) { APP.history = true; From 04ec63ca5ed9c948ce4deca2efeb3e30a50bda35 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Tue, 2 Dec 2025 11:37:03 +0100 Subject: [PATCH 49/51] more cleaning/comments --- www/common/onlyoffice/history.js | 58 ++++++++------------------------ www/common/onlyoffice/inner.js | 2 +- 2 files changed, 15 insertions(+), 45 deletions(-) diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index b39910821..961a4e80b 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -74,45 +74,6 @@ define([ return version + '.' + position; }; - // var showVersion = function (initial, position) { - // currentVersion = getVersion(position, initial); - // if (initial) { currentVersion = Messages.oo_version_latest; } - // $version.text(Messages.oo_version + currentVersion); - - // var $pos = $hist.find('.cp-history-timeline-pos'); - // if (!ooMessages[id]) { return; } - // var msgs = ooMessages[id]; - // var p; - // var messageIndex = forward ? msgIndex+1 : msgIndex; - // if (!Object.keys(hashes).length) { - // p = 100-100*((messageIndex ) / (-msgs.length)); - // } else { - // var lastHash = hashes[Object.keys(hashes).pop()].hash; - // if (lastHash === config.onlyoffice.lastHash) { - // var hashLength = Object.keys(hashes).length; - // } else { - // var hashLength = Object.keys(hashes).length+1; - // } - // var segments = id/hashLength; - // p = 100*(segments); - - // if (id === 0) { p = 0; } - - // var percentage = ((position/msgs.length)*100); - // var timelinePosition = (percentage/100)*(100/hashLength); - // p += timelinePosition; - // } - - // $pos.css('margin-left', p+'%'); - - // var time = msgs[msgIndex] && msgs[msgIndex].time; - // currentTime = time; - // if (time) { $time.text(new Date(time).toLocaleString()); } - // else { $time.text(''); } - // update(); - // loadingFalse(); - // }; - var getMessages = function(fromHash, toHash, callback) { sframeChan.query('Q_GET_HISTORY_RANGE', { channel: config.onlyoffice.channel, @@ -141,6 +102,7 @@ define([ return reject(); } + // Get the checkpoint ID id = typeof(id) !== "undefined" ? id : getId(); var cp; if (ooMessages[id-1] && !ooMessages[id-1].length) { @@ -148,10 +110,18 @@ define([ } else { cp = hashes[id]; } + + // Get the history between "toHash" and "fromHash". This function is using + // "getOlderHistory", that's why we start from the more recent hash + // and we go back in time to an older hash + + // We need to get all the patches between the current cp hash and the next cp hash var nextId = hashes[id+1] ? hashes[id+1] : undefined; - var toHash = nextId ? nextId.hash : config.onlyoffice.lastHash; + // Current cp or initial hash (invalid hash ==> initial hash) var fromHash = cp?.hash || 'NONE'; + // Next cp or last hash + var toHash = nextId ? nextId.hash : config.onlyoffice.lastHash; getMessages(toHash, fromHash, function (err) { if (err) { @@ -168,7 +138,7 @@ define([ var onClose = function () { config.setHistory(false); }; var onRevert = function () { - config.onRevert(true); + config.onRevert(); }; config.setHistory(true); @@ -486,7 +456,7 @@ define([ config.onPatchBack(cp, msgs); } - loading = false; + loadingFalse(); position = msgs?.length; showVersion(false, position); }); @@ -508,7 +478,7 @@ define([ update(true); }); position = 0; - loading = false; + loadingFalse(); }); onKeyDown = function (e) { var p = function () { e.preventDefault(); }; @@ -527,7 +497,7 @@ define([ }); }); $(snapshot).click(function () { - // if (cpIndex === -1 && msgIndex === -1) { return void UI.warn(Messages.snapshots_ooPickVersion); } + if (cpIndex === -1 && msgIndex === -1) { return void UI.warn(Messages.snapshots_ooPickVersion); } var input = h('input', { placeholder: Messages.snapshots_placeholder }); diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index e1daba3f4..574f18bf7 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -574,7 +574,7 @@ define([ blob.name = title || (metadataMgr.getMetadataLazy().title || file.doc) + '.' + file.type; var data = { hash: (APP.history || APP.template) ? ooChannel.historyLastHash : ooChannel.lastHash, - index: (APP.history || APP.template) ? ooChannel.currentIndex : ooChannel.cpIndex + index: (APP.history || APP.template) ? ooChannel.currentIndex : ooChannel.cpIndex }; fixSheets(); From 17c5db220e28fbc502e9dffdfeb8004a9f911d46 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Fri, 5 Dec 2025 18:03:05 +0100 Subject: [PATCH 50/51] timeline UI - wip --- .../src/less2/include/toolbar-history.less | 10 ++ www/common/onlyoffice/history.js | 110 +++++++++++++++--- 2 files changed, 106 insertions(+), 14 deletions(-) diff --git a/customize.dist/src/less2/include/toolbar-history.less b/customize.dist/src/less2/include/toolbar-history.less index 53f2b6880..f6b3b8c88 100644 --- a/customize.dist/src/less2/include/toolbar-history.less +++ b/customize.dist/src/less2/include/toolbar-history.less @@ -170,6 +170,16 @@ position: relative; background-color: @history_lineBg; height: 39px; + .cp-oohistory-bar-el { + background-color: @history_userBg2; + display: block; + // width: 100%; + height: 100% + // background-color: @history_userBg2; + // &:nth-child(2n) { + // background-color: @history_userBg1; + // } + } } .cp-history-timeline-bar { display: flex; diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 961a4e80b..6954ccc0f 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -173,35 +173,89 @@ define([ } }; - var showVersion = function (initial, position) { + + + var showVersion = function (initial, position, currentCp, nextCp) { currentVersion = getVersion(position, initial); if (initial) { currentVersion = Messages.oo_version_latest; } $version.text(Messages.oo_version + currentVersion); var $pos = $hist.find('.cp-history-timeline-pos'); + var bar = $('.cp-history-timeline-container') + var snapshotsEl = [] + var snapshots = h('div.cp-history-snapshots', [ + snapshotsEl + ]) + $(snapshots).css('height', '100%') + bar.html('').append([ + snapshots + ]); + if (!ooMessages[id]) { return; } var msgs = ooMessages[id]; var p; var messageIndex = forward ? msgIndex+1 : msgIndex; + if (!Object.keys(hashes).length) { p = 100-100*((messageIndex ) / (-msgs.length)); - } else { - var lastHash = hashes[Object.keys(hashes).pop()].hash; - if (lastHash === config.onlyoffice.lastHash) { - var hashLength = Object.keys(hashes).length; - } else { - var hashLength = Object.keys(hashes).length+1; + for (var i = 1; i < msgs.length; i++) { + var msg = msgs[i] + var patchWidth = (1/msgs.length)*100 + var patchDiv = h('div.cp-history-patch', { + style: 'width:'+patchWidth+'%; height: 100%', + title: new Date(msg.time).toLocaleString(), + data: [id, msgs.indexOf(msg)] + }) + snapshotsEl.push(patchDiv); } - var segments = id/hashLength; - p = 100*(segments); - if (id === 0) { p = 0; } + } else { + console.log("hashes,", hashes, id, ooMessages[id], hashes, Object.keys(hashes)[Object.keys(hashes).length-2]) + + if (id === parseInt(Object.keys(hashes)[Object.keys(hashes).length-2])) { + p = 100-100*((messageIndex ) / (-msgs.length)); + + - var percentage = ((position/msgs.length)*100); - var timelinePosition = (percentage/100)*(100/hashLength); - p += timelinePosition; + + + } else { + spanWidth = (nextCp/(nextCp+currentCp))*100 + + + var cPSpan = h('span.cp-oohistory-bar-el'); + $(cPSpan).css('width', `${spanWidth}%`) + bar.append(cPSpan) + + } + + + // var lastHash = hashes[Object.keys(hashes).pop()].hash; + // if (lastHash === config.onlyoffice.lastHash) { + // var hashLength = Object.keys(hashes).length; + // } else { + // var hashLength = Object.keys(hashes).length+1; + // } + // var segments = id/hashLength; + // p = 100*(segments); + + // if (id === 0) { p = 0; } + + // var percentage = ((position/msgs.length)*100); + // var timelinePosition = (percentage/100)*(100/hashLength); + // p += timelinePosition; } + var snapshots = h('div.cp-history-snapshots', [ + snapshotsEl + ]) + $(snapshots).css('height', '100%') + $(snapshots).css('display', 'flex') + + bar.html('').append([ + snapshots + ]); + $pos.css('margin-left', p+'%'); var time = msgs[msgIndex] && msgs[msgIndex].time; @@ -209,9 +263,24 @@ define([ if (time) { $time.text(new Date(time).toLocaleString()); } else { $time.text(''); } update(); + + $('.cp-history-patch').on('click', function(e) { + var patchData = $(e.target).attr('data').split(',') + msgs = ooMessages[id] + if (parseInt(patchData[0]) === -1) { + var q = msgs.slice(0, patchData[1]) + config.onPatchBack({}, q) + } else { + config.onPatchBack(hashes[patchData[0]], msgs[patchData[1]]) + } + + }) + loadingFalse(); }; + + var loadingFalse = function () { setTimeout(function () { $('iframe').blur(); @@ -285,9 +354,14 @@ define([ //Check if the end of the checkpoint has been reached and the previous one should be loaded if (hasHashes && loadPrevCp) { + + var currentCp = msgs.length + + id--; msgIndex = -1; return loadMoreOOHistory().then(() => { + //Empty checkpoint - checkpoint saved with no further changes if (!msgs.length) { msgs = ooMessages[id]; @@ -297,6 +371,12 @@ define([ return; } msgs = ooMessages[id]; + + var nextCp = msgs.length + + + + cp = hashes[id]; var q = msgs.slice(0, msgIndex); patch = msgs[msgs.length-1]; @@ -309,7 +389,7 @@ define([ } else { config.onPatchBack(cp, msgs); } - showVersion(false, position); + showVersion(false, position, currentCp, nextCp); }); } @@ -559,6 +639,8 @@ define([ showVersion(true); + + //return void loadMoreOOHistory(); }; From 6e15d4fdcb27da1fdf028ca41887f97ce7053dd0 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Wed, 10 Dec 2025 16:22:11 +0100 Subject: [PATCH 51/51] timeline UI - wip --- .../src/less2/include/toolbar-history.less | 18 ++++- www/common/onlyoffice/history.js | 73 +++++++++++++------ 2 files changed, 65 insertions(+), 26 deletions(-) diff --git a/customize.dist/src/less2/include/toolbar-history.less b/customize.dist/src/less2/include/toolbar-history.less index f6b3b8c88..aecfb4b69 100644 --- a/customize.dist/src/less2/include/toolbar-history.less +++ b/customize.dist/src/less2/include/toolbar-history.less @@ -168,7 +168,7 @@ .cp-history-timeline-container { flex: 1; position: relative; - background-color: @history_lineBg; + background-color: @history_userBg2; height: 39px; .cp-oohistory-bar-el { background-color: @history_userBg2; @@ -262,8 +262,22 @@ } } + .cp-history-oo-timeline-pos { + width: 2px; + border: 2px solid @cryptpad_text_col; + height: 37px; + //background: @pos-color; + // position: absolute; + &:before { + top: -17px; + font-size: 24px; + position: absolute; + // left: ~"calc(50% - 6px)"; + } + } + .cp-history-timeline-pos { - //width: 2px; + width: 2px; border: 2px solid @cryptpad_text_col; height: 37px; //background: @pos-color; diff --git a/www/common/onlyoffice/history.js b/www/common/onlyoffice/history.js index 6954ccc0f..e2c330e66 100644 --- a/www/common/onlyoffice/history.js +++ b/www/common/onlyoffice/history.js @@ -80,6 +80,7 @@ define([ lastKnownHash: fromHash, toHash: toHash, }, function (err, data) { + if (err) { return void console.error(err); } if (!Array.isArray(data.messages)) { return void console.error('Not an array!'); } @@ -87,6 +88,7 @@ define([ var messages = (data.messages || []).slice(initialCp || config.docType() === 'spreadsheet' ? 0 : 1); if (config.debug) { console.log(data.messages); } id = typeof(id) !== "undefined" ? id : getId(); + fillOO(messages); loading = false; @@ -191,33 +193,47 @@ define([ snapshots ]); - if (!ooMessages[id]) { return; } + if (!ooMessages[id] && !initial) { return; } var msgs = ooMessages[id]; var p; var messageIndex = forward ? msgIndex+1 : msgIndex; if (!Object.keys(hashes).length) { p = 100-100*((messageIndex ) / (-msgs.length)); - for (var i = 1; i < msgs.length; i++) { + var patchWidth; + var patchDiv; + for (var i = 0; i < msgs.length; i++) { var msg = msgs[i] - var patchWidth = (1/msgs.length)*100 - var patchDiv = h('div.cp-history-patch', { + patchWidth = (1/msgs.length)*100 + patchDiv = h('div.cp-history-patch', { style: 'width:'+patchWidth+'%; height: 100%', title: new Date(msg.time).toLocaleString(), data: [id, msgs.indexOf(msg)] }) + console.log("PATCH",msgs.indexOf(patch), i, msgs.length-1) + if (msgs[msgs.indexOf(patch)-1] === msg && !initial && patch && msgs[msgs.indexOf(patch)-1]) { + $(patchDiv).addClass('cp-history-oo-timeline-pos') + } else if (msgs.indexOf(patch) === -1 && i === msgs.length-1) { + $(patchDiv).addClass('cp-history-oo-timeline-pos') + } snapshotsEl.push(patchDiv); } - + var emptyPatchDiv = h('div.cp-history-patch', { + style: 'width:'+patchWidth+'%; height: 100%', + title: new Date().toLocaleString(), + data: [0, 0] + }) + if (msgs[0] === patch) { + $(emptyPatchDiv).addClass('cp-history-oo-timeline-pos') + } + snapshotsEl.unshift(emptyPatchDiv); } else { - console.log("hashes,", hashes, id, ooMessages[id], hashes, Object.keys(hashes)[Object.keys(hashes).length-2]) + console.log("hashes,", hashes, id, ooMessages[id], hashes, Object.keys(hashes)[Object.keys(hashes).length-2]) if (id === parseInt(Object.keys(hashes)[Object.keys(hashes).length-2])) { p = 100-100*((messageIndex ) / (-msgs.length)); - - } else { spanWidth = (nextCp/(nextCp+currentCp))*100 @@ -240,7 +256,7 @@ define([ // p = 100*(segments); // if (id === 0) { p = 0; } - + // var percentage = ((position/msgs.length)*100); // var timelinePosition = (percentage/100)*(100/hashLength); // p += timelinePosition; @@ -264,23 +280,29 @@ define([ else { $time.text(''); } update(); - $('.cp-history-patch').on('click', function(e) { - var patchData = $(e.target).attr('data').split(',') - msgs = ooMessages[id] - if (parseInt(patchData[0]) === -1) { - var q = msgs.slice(0, patchData[1]) - config.onPatchBack({}, q) - } else { - config.onPatchBack(hashes[patchData[0]], msgs[patchData[1]]) - } - - }) + $('.cp-history-patch').on('click', function(e) { + var patchData = $(e.target).attr('data').split(',') + var cpNo = parseInt(patchData[0]) + var patchNo = parseInt(patchData[1]) + msgs = ooMessages[id] + if (cpNo === -1) { + var q = msgs.slice(0, patchNo+1) + config.onPatchBack({}, q) + patch = msgs[patchNo+1] + } else if (cpNo === 0 && patchNo === 0) { + config.onPatchBack({}) + patch = msgs[0] + } else { + config.onPatchBack(hashes[patchData[0]], msgs[patchData[1]]) + patch = msgs[patchData[1]] + } + position = msgs.indexOf(patch)+2 + showVersion(false, position) + }) loadingFalse(); }; - - var loadingFalse = function () { setTimeout(function () { $('iframe').blur(); @@ -637,10 +659,13 @@ define([ display(); - showVersion(true); - + setTimeout(() => { + showVersion(true);; + }, "1000"); + + //return void loadMoreOOHistory(); };