Merge branch 'pad2' of github.com:xwiki-labs/cryptpad into pad2

This commit is contained in:
Caleb James DeLisle 2017-08-21 18:08:46 +02:00
commit bffa4d01a8
5 changed files with 84 additions and 12 deletions

View File

@ -38,13 +38,13 @@ define([
var parsed = config.href ? common.parsePadUrl(config.href) : {};
var secret = common.getSecrets(parsed.type, parsed.hash);
History.readOnly = 1;
History.readOnly = 0;
if (!secret.keys) {
secret.keys = secret.key;
History.readOnly = 2;
History.readOnly = 0;
}
else if (!secret.keys.validateKey) {
History.readOnly = 0;
History.readOnly = 1;
}
var crypto = Crypto.createEncryptor(secret.keys);
@ -203,7 +203,7 @@ define([
'class':'revertHistory buttonSuccess',
title: Messages.history_restoreTitle
}).text(Messages.history_restore).appendTo($nav);
if (!History.readOnly) { $rev.hide(); }
if (History.readOnly) { $rev.hide(); }
onUpdate = function () {
$cur.attr('max', states.length);

View File

@ -5,15 +5,18 @@ define([
'/common/sframe-channel.js',
'/common/sframe-common-title.js',
'/common/sframe-common-interface.js',
'/common/sframe-common-history.js',
'/common/metadata-manager.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
var funcs = {};
var ctx = {};
funcs.Messages = Messages;
funcs.startRealtime = function (options) {
if (ctx.cpNfInner) { return ctx.cpNfInner; }
options.sframeChan = ctx.sframeChan;
@ -23,6 +26,13 @@ define([
return ctx.cpNfInner;
};
funcs.getMetadataMgr = function () {
return ctx.metadataMgr;
};
funcs.getCryptpadCommon = function () {
return Cryptpad;
};
var isLoggedIn = funcs.isLoggedIn = function () {
if (!ctx.cpNfInner) { throw new Error("cpNfInner is not ready!"); }
return ctx.cpNfInner.metadataMgr.getPrivateData().accountName;
@ -38,6 +48,9 @@ define([
funcs.createUserAdminMenu = UI.createUserAdminMenu;
funcs.displayAvatar = UI.displayAvatar;
// History
funcs.getHistory = function (config) { return History.create(funcs, config); };
// Title module
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
funcs.feedback = function () {};
@ -199,10 +219,10 @@ define([
}
break;
case 'history':
if (!AppConfig.enableHistory) {
/*if (!AppConfig.enableHistory) {
button = $('<span>');
break;
}
}*/
button = $('<button>', {
title: Messages.historyButton,
'class': "fa fa-history history",
@ -211,7 +231,7 @@ define([
button
.click(prepareFeedback(type))
.on('click', function () {
common.getHistory(data.histConfig);
funcs.getHistory(data.histConfig);
});
}
break;

View File

@ -52,16 +52,22 @@ define({
// end of the login process. This query set the current href to the sessionStorage.
'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,
// 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,
// 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
'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,
// 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
});

View File

@ -528,6 +528,17 @@ define([
$('.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 */
var $export = Cryptpad.createButton('export', true, {}, exportFile);
$drawer.append($export);

View File

@ -136,6 +136,41 @@ define([
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({
sframeChan: sframeChan,
channel: secret.channel,