Add history to pad2
This commit is contained in:
parent
b2e6df1f9d
commit
8d837d22ea
@ -38,13 +38,13 @@ define([
|
|||||||
var parsed = config.href ? common.parsePadUrl(config.href) : {};
|
var parsed = config.href ? common.parsePadUrl(config.href) : {};
|
||||||
var secret = common.getSecrets(parsed.type, parsed.hash);
|
var secret = common.getSecrets(parsed.type, parsed.hash);
|
||||||
|
|
||||||
History.readOnly = 1;
|
History.readOnly = 0;
|
||||||
if (!secret.keys) {
|
if (!secret.keys) {
|
||||||
secret.keys = secret.key;
|
secret.keys = secret.key;
|
||||||
History.readOnly = 2;
|
History.readOnly = 0;
|
||||||
}
|
}
|
||||||
else if (!secret.keys.validateKey) {
|
else if (!secret.keys.validateKey) {
|
||||||
History.readOnly = 0;
|
History.readOnly = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var crypto = Crypto.createEncryptor(secret.keys);
|
var crypto = Crypto.createEncryptor(secret.keys);
|
||||||
@ -203,7 +203,7 @@ define([
|
|||||||
'class':'revertHistory buttonSuccess',
|
'class':'revertHistory buttonSuccess',
|
||||||
title: Messages.history_restoreTitle
|
title: Messages.history_restoreTitle
|
||||||
}).text(Messages.history_restore).appendTo($nav);
|
}).text(Messages.history_restore).appendTo($nav);
|
||||||
if (!History.readOnly) { $rev.hide(); }
|
if (History.readOnly) { $rev.hide(); }
|
||||||
|
|
||||||
onUpdate = function () {
|
onUpdate = function () {
|
||||||
$cur.attr('max', states.length);
|
$cur.attr('max', states.length);
|
||||||
|
|||||||
@ -5,15 +5,18 @@ define([
|
|||||||
'/common/sframe-channel.js',
|
'/common/sframe-channel.js',
|
||||||
'/common/sframe-common-title.js',
|
'/common/sframe-common-title.js',
|
||||||
'/common/sframe-common-interface.js',
|
'/common/sframe-common-interface.js',
|
||||||
|
'/common/sframe-common-history.js',
|
||||||
'/common/metadata-manager.js',
|
'/common/metadata-manager.js',
|
||||||
|
|
||||||
'/common/cryptpad-common.js'
|
'/common/cryptpad-common.js'
|
||||||
], function (nThen, Messages, CpNfInner, SFrameChannel, Title, UI, MetadataMgr, Cryptpad) {
|
], function (nThen, Messages, CpNfInner, SFrameChannel, Title, UI, History, MetadataMgr, Cryptpad) {
|
||||||
|
|
||||||
// Chainpad Netflux Inner
|
// Chainpad Netflux Inner
|
||||||
var funcs = {};
|
var funcs = {};
|
||||||
var ctx = {};
|
var ctx = {};
|
||||||
|
|
||||||
|
funcs.Messages = Messages;
|
||||||
|
|
||||||
funcs.startRealtime = function (options) {
|
funcs.startRealtime = function (options) {
|
||||||
if (ctx.cpNfInner) { return ctx.cpNfInner; }
|
if (ctx.cpNfInner) { return ctx.cpNfInner; }
|
||||||
options.sframeChan = ctx.sframeChan;
|
options.sframeChan = ctx.sframeChan;
|
||||||
@ -23,6 +26,13 @@ define([
|
|||||||
return ctx.cpNfInner;
|
return ctx.cpNfInner;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
funcs.getMetadataMgr = function () {
|
||||||
|
return ctx.metadataMgr;
|
||||||
|
};
|
||||||
|
funcs.getCryptpadCommon = function () {
|
||||||
|
return Cryptpad;
|
||||||
|
};
|
||||||
|
|
||||||
var isLoggedIn = funcs.isLoggedIn = function () {
|
var isLoggedIn = funcs.isLoggedIn = function () {
|
||||||
if (!ctx.cpNfInner) { throw new Error("cpNfInner is not ready!"); }
|
if (!ctx.cpNfInner) { throw new Error("cpNfInner is not ready!"); }
|
||||||
return ctx.cpNfInner.metadataMgr.getPrivateData().accountName;
|
return ctx.cpNfInner.metadataMgr.getPrivateData().accountName;
|
||||||
@ -38,6 +48,9 @@ define([
|
|||||||
funcs.createUserAdminMenu = UI.createUserAdminMenu;
|
funcs.createUserAdminMenu = UI.createUserAdminMenu;
|
||||||
funcs.displayAvatar = UI.displayAvatar;
|
funcs.displayAvatar = UI.displayAvatar;
|
||||||
|
|
||||||
|
// History
|
||||||
|
funcs.getHistory = function (config) { return History.create(funcs, config); };
|
||||||
|
|
||||||
// Title module
|
// Title module
|
||||||
funcs.createTitle = Title.create;
|
funcs.createTitle = Title.create;
|
||||||
|
|
||||||
@ -79,6 +92,13 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
funcs.getFullHistory = function (realtime, cb) {
|
||||||
|
ctx.sframeChan.on('EV_RT_HIST_MESSAGE', function (content) {
|
||||||
|
realtime.message(content);
|
||||||
|
});
|
||||||
|
ctx.sframeChan.query('Q_GET_FULL_HISTORY', null, cb);
|
||||||
|
};
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
funcs.feedback = function () {};
|
funcs.feedback = function () {};
|
||||||
@ -199,10 +219,10 @@ define([
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'history':
|
case 'history':
|
||||||
if (!AppConfig.enableHistory) {
|
/*if (!AppConfig.enableHistory) {
|
||||||
button = $('<span>');
|
button = $('<span>');
|
||||||
break;
|
break;
|
||||||
}
|
}*/
|
||||||
button = $('<button>', {
|
button = $('<button>', {
|
||||||
title: Messages.historyButton,
|
title: Messages.historyButton,
|
||||||
'class': "fa fa-history history",
|
'class': "fa fa-history history",
|
||||||
@ -211,7 +231,7 @@ define([
|
|||||||
button
|
button
|
||||||
.click(prepareFeedback(type))
|
.click(prepareFeedback(type))
|
||||||
.on('click', function () {
|
.on('click', function () {
|
||||||
common.getHistory(data.histConfig);
|
funcs.getHistory(data.histConfig);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -52,16 +52,22 @@ define({
|
|||||||
// end of the login process. This query set the current href to the sessionStorage.
|
// end of the login process. This query set the current href to the sessionStorage.
|
||||||
'Q_SET_LOGIN_REDIRECT': true,
|
'Q_SET_LOGIN_REDIRECT': true,
|
||||||
|
|
||||||
// Store the editing or readonly link of the current pad to the clipboard (share button)
|
// Store the editing or readonly link of the current pad to the clipboard (share button).
|
||||||
'Q_STORE_LINK_TO_CLIPBOARD': true,
|
'Q_STORE_LINK_TO_CLIPBOARD': true,
|
||||||
|
|
||||||
// Use anonymous rpc from inside the iframe (for avatars & pin usage)
|
// Use anonymous rpc from inside the iframe (for avatars & pin usage).
|
||||||
'Q_ANON_RPC_MESSAGE': true,
|
'Q_ANON_RPC_MESSAGE': true,
|
||||||
|
|
||||||
// Check the pin limit to determine if we can store the pad in the drive or if we should
|
// Check the pin limit to determine if we can store the pad in the drive or if we should.
|
||||||
// display a warning
|
// display a warning
|
||||||
'Q_GET_PIN_LIMIT_STATUS': true,
|
'Q_GET_PIN_LIMIT_STATUS': true,
|
||||||
|
|
||||||
// Move a pad to the trash using the forget button
|
// Move a pad to the trash when using the forget button.
|
||||||
'Q_MOVE_TO_TRASH': true,
|
'Q_MOVE_TO_TRASH': true,
|
||||||
|
|
||||||
|
// Request the full history from the server when the users clicks on the history button.
|
||||||
|
// Callback is called when the FULL_HISTORY_END message is received in the outside.
|
||||||
|
'Q_GET_FULL_HISTORY': true,
|
||||||
|
// When a (full) history message is received from the server.
|
||||||
|
'EV_RT_HIST_MESSAGE': true
|
||||||
});
|
});
|
||||||
|
|||||||
@ -528,6 +528,17 @@ define([
|
|||||||
$('.cke_toolbox_main').hide();
|
$('.cke_toolbox_main').hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* add a history button */
|
||||||
|
var histConfig = {
|
||||||
|
onLocal: realtimeOptions.onLocal,
|
||||||
|
onRemote: realtimeOptions.onRemote,
|
||||||
|
setHistory: setHistory,
|
||||||
|
applyVal: function (val) { applyHjson(val || '["BODY",{},[]]'); },
|
||||||
|
$toolbar: $bar
|
||||||
|
};
|
||||||
|
var $hist = common.createButton('history', true, {histConfig: histConfig});
|
||||||
|
$drawer.append($hist);
|
||||||
|
|
||||||
/* add an export button */
|
/* add an export button */
|
||||||
var $export = Cryptpad.createButton('export', true, {}, exportFile);
|
var $export = Cryptpad.createButton('export', true, {}, exportFile);
|
||||||
$drawer.append($export);
|
$drawer.append($export);
|
||||||
|
|||||||
@ -136,6 +136,41 @@ define([
|
|||||||
Cryptpad.moveToTrash(cb);
|
Cryptpad.moveToTrash(cb);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
sframeChan.on('Q_GET_FULL_HISTORY', function (data, cb) {
|
||||||
|
var network = Cryptpad.getNetwork();
|
||||||
|
var hkn = network.historyKeeper;
|
||||||
|
var crypto = Crypto.createEncryptor(secret.keys);
|
||||||
|
// Get the history messages and send them to the iframe
|
||||||
|
var parse = function (msg) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(msg);
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var onMsg = function (msg) {
|
||||||
|
var parsed = parse(msg);
|
||||||
|
if (parsed[0] === 'FULL_HISTORY_END') {
|
||||||
|
console.log('END');
|
||||||
|
cb();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (parsed[0] !== 'FULL_HISTORY') { return; }
|
||||||
|
if (parsed[1] && parsed[1].validateKey) { // First message
|
||||||
|
secret.keys.validateKey = parsed[1].validateKey;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
msg = parsed[1][4];
|
||||||
|
if (msg) {
|
||||||
|
msg = msg.replace(/^cp\|/, '');
|
||||||
|
var decryptedMsg = crypto.decrypt(msg, secret.keys.validateKey);
|
||||||
|
sframeChan.event('EV_RT_HIST_MESSAGE', decryptedMsg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
network.on('message', onMsg);
|
||||||
|
network.sendto(hkn, JSON.stringify(['GET_FULL_HISTORY', secret.channel, secret.keys.validateKey]));
|
||||||
|
});
|
||||||
|
|
||||||
CpNfOuter.start({
|
CpNfOuter.start({
|
||||||
sframeChan: sframeChan,
|
sframeChan: sframeChan,
|
||||||
channel: secret.channel,
|
channel: secret.channel,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user