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
*/
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 k;
// Check if we have a ownerKey for this pad
@ -183,6 +194,7 @@ Version 1
parsed.password = options.indexOf('p') !== -1;
parsed.present = options.indexOf('present') !== -1;
parsed.embed = options.indexOf('embed') !== -1;
parsed.versionHash = getVersionHash(options);
parsed.ownerKey = getOwnerKey(options);
};
@ -194,6 +206,7 @@ Version 1
embed: parsed.embed,
present: parsed.present,
ownerKey: parsed.ownerKey,
versionHash: parsed.versionHash,
password: parsed.password
};
};
@ -213,6 +226,7 @@ Version 1
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;
return hash;
};

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

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

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

Loading…
Cancel
Save