Add support for version hash

pull/1/head
yflory 5 years ago
parent 6100fdfd7a
commit f5831cccb0

@ -162,6 +162,17 @@ Version 1
/code/#/1/edit/3Ujt4F2Sjnjbis6CoYWpoQ/usn4+9CqVja8Q7RZOGTfRgqI /code/#/1/edit/3Ujt4F2Sjnjbis6CoYWpoQ/usn4+9CqVja8Q7RZOGTfRgqI
*/ */
var getVersionHash = function (hashArr) {
var k;
// Check if we have a ownerKey for this pad
hashArr.some(function (data) {
if (/^hash=/.test(data)) {
k = data.slice(5);
return true;
}
});
return k;
};
var getOwnerKey = function (hashArr) { var getOwnerKey = function (hashArr) {
var k; var k;
// Check if we have a ownerKey for this pad // Check if we have a ownerKey for this pad
@ -183,6 +194,7 @@ Version 1
parsed.password = options.indexOf('p') !== -1; parsed.password = options.indexOf('p') !== -1;
parsed.present = options.indexOf('present') !== -1; parsed.present = options.indexOf('present') !== -1;
parsed.embed = options.indexOf('embed') !== -1; parsed.embed = options.indexOf('embed') !== -1;
parsed.versionHash = getVersionHash(options);
parsed.ownerKey = getOwnerKey(options); parsed.ownerKey = getOwnerKey(options);
}; };
@ -194,6 +206,7 @@ Version 1
embed: parsed.embed, embed: parsed.embed,
present: parsed.present, present: parsed.present,
ownerKey: parsed.ownerKey, ownerKey: parsed.ownerKey,
versionHash: parsed.versionHash,
password: parsed.password password: parsed.password
}; };
}; };
@ -213,6 +226,7 @@ Version 1
if (parsed.password || opts.password) { hash += 'p/'; } if (parsed.password || opts.password) { hash += 'p/'; }
if (opts.embed) { hash += 'embed/'; } if (opts.embed) { hash += 'embed/'; }
if (opts.present) { hash += 'present/'; } if (opts.present) { hash += 'present/'; }
var versionHash = typeof(opts.versionHash) !== "undefined" ? opts.versionHash : parsed.versionHash;
return hash; return hash;
}; };

@ -2035,6 +2035,7 @@ define([
} }
msg = msg.replace(/cp\|(([A-Za-z0-9+\/=]+)\|)?/, ''); msg = msg.replace(/cp\|(([A-Za-z0-9+\/=]+)\|)?/, '');
msgs.push({ msgs.push({
serverHash: msg.slice(0,64),
msg: msg, msg: msg,
author: parsed[2][1], author: parsed[2][1],
time: parsed[2][5] time: parsed[2][5]

@ -71,9 +71,6 @@ define([
lastKnownHash = data.lastKnownHash; lastKnownHash = data.lastKnownHash;
isComplete = data.isFull; isComplete = data.isFull;
var messages = (data.messages || []).map(function (obj) { var messages = (data.messages || []).map(function (obj) {
if (!config.debug) {
return obj.msg;
}
return obj; return obj;
}); });
if (config.debug) { console.log(data.messages); } if (config.debug) { console.log(data.messages); }
@ -160,7 +157,7 @@ define([
if (cb) { cb(); } if (cb) { cb(); }
}); });
}; };
get = function (i) { get = function (i, blockOnly) {
i = parseInt(i); i = parseInt(i);
if (isNaN(i)) { return; } if (isNaN(i)) { return; }
if (i > 0) { i = 0; } if (i > 0) { i = 0; }
@ -169,6 +166,8 @@ define([
loadMore(); loadMore();
} }
var idx = states.length - 1 + i; var idx = states.length - 1 + i;
if (blockOnly) { return states[idx]; }
var val = states[idx].getContent().doc; var val = states[idx].getContent().doc;
c = i; c = i;
if (typeof onUpdate === "function") { onUpdate(); } if (typeof onUpdate === "function") { onUpdate(); }
@ -237,6 +236,10 @@ define([
'class': 'cp-toolbar-history-fast-next fa fa-fast-forward buttonPrimary', 'class': 'cp-toolbar-history-fast-next fa fa-fast-forward buttonPrimary',
title: Messages.history_next title: Messages.history_next
}).appendTo($hist); }).appendTo($hist);
var $share = $('<button>', {
'class': 'fa fa-shhare-alt buttonPrimary',
title: Messages.shareButton
}).appendTo($hist);
$('<span>', {'class': 'cp-history-filler'}).appendTo($hist); $('<span>', {'class': 'cp-history-filler'}).appendTo($hist);
var $close = $('<button>', { var $close = $('<button>', {
'class':'cp-toolbar-history-close fa fa-window-close', 'class':'cp-toolbar-history-close fa fa-window-close',
@ -298,6 +301,15 @@ define([
onKeyUp = function (e) { e.stopPropagation(); }; onKeyUp = function (e) { e.stopPropagation(); };
$(window).on('keydown', onKeyDown).on('keyup', onKeyUp).focus(); $(window).on('keydown', onKeyDown).on('keyup', onKeyUp).focus();
// Share
$share.click(function () {
var block = get(c, true);
common.getSframeChannel().event('EV_SHARE_OPEN', {
versionHash: block.serverHash,
//title: title
});
});
// Close & restore buttons // Close & restore buttons
$close.click(function () { $close.click(function () {
states = []; states = [];

@ -1084,6 +1084,7 @@ define([
// We don't need it since the message is already validated serverside by hk // We don't need it since the message is already validated serverside by hk
return { return {
msg: crypto.decrypt(obj.msg, true, true), msg: crypto.decrypt(obj.msg, true, true),
serverHash: obj.serverHash,
author: obj.author, author: obj.author,
time: obj.time time: obj.time
}; };

Loading…
Cancel
Save