This commit is contained in:
Zuzanna 2025-11-11 16:23:28 +01:00
parent c5d17673dc
commit 20e3a77991
4 changed files with 101 additions and 28 deletions

View File

@ -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; }

View File

@ -31,6 +31,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;
@ -64,19 +65,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;
}
@ -93,11 +127,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 {
@ -109,6 +150,7 @@ define([
} else if (!p) {
p = 100;
}
console.log("pos", p)
}
$pos.css('margin-left', p+'%');
@ -137,6 +179,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);
@ -266,7 +309,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;
});
}
@ -274,7 +319,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;
@ -292,7 +340,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();
};
@ -311,8 +362,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();
});
@ -321,8 +373,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();
};
@ -471,6 +524,8 @@ define([
update('end');
loading = false;
}, 100);
position = msgs.length
showVersion(position)
});
// Go to next checkpoint
$fastPrev.click(function () {
@ -487,6 +542,7 @@ define([
showVersion()
update(true);
});
position = 0;
loading = false;
});
@ -502,8 +558,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 () {
@ -531,14 +588,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
});
},

View File

@ -810,9 +810,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,
@ -829,7 +831,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); }
@ -838,6 +843,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) {
@ -862,7 +868,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();
})
@ -874,11 +881,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();
});
@ -3213,10 +3230,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;

View File

@ -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) {