Merge remote-tracking branch 'origin/bar' into bar

This commit is contained in:
David Benqué 2020-01-13 16:29:29 +00:00
commit 332f9e37aa
8 changed files with 105 additions and 6 deletions

View File

@ -4001,6 +4001,8 @@ define([
msg += Messages.errorCopy; msg += Messages.errorCopy;
} }
} }
var sframeChan = common.getSframeChannel();
sframeChan.event('EV_SHARE_OPEN', {hidden: true});
if (toolbar && typeof toolbar.deleted === "function") { toolbar.deleted(); } if (toolbar && typeof toolbar.deleted === "function") { toolbar.deleted(); }
UI.errorLoadingScreen(msg, true, true); UI.errorLoadingScreen(msg, true, true);
(cb || function () {})(); (cb || function () {})();

View File

@ -1653,6 +1653,45 @@ define([
}; };
// Delete a pad received with a burn after reading URL // Delete a pad received with a burn after reading URL
var notifyOwnerPadRemoved = function (data, obj) {
var channel = data.channel;
var href = data.href;
var parsed = Hash.parsePadUrl(href);
var secret = Hash.getSecrets(parsed.type, parsed.hash, data.password);
if (obj && obj.error) { return; }
if (!obj.mailbox) { return; }
// Decrypt the mailbox
var crypto = Crypto.createEncryptor(secret.keys);
var m = [];
try {
if (typeof (obj.mailbox) === "string") {
m.push(crypto.decrypt(obj.mailbox, true, true));
} else {
Object.keys(obj.mailbox).forEach(function (k) {
m.push(crypto.decrypt(obj.mailbox[k], true, true));
});
}
} catch (e) {
console.error(e);
}
// Tell all the owners that the pad was deleted from the server
var curvePublic = store.proxy.curvePublic;
var myData = Messaging.createData(store.proxy, false);
m.forEach(function (obj) {
var mb = JSON.parse(obj);
if (mb.curvePublic === curvePublic) { return; }
store.mailbox.sendTo('OWNED_PAD_REMOVED', {
channel: channel,
user: myData
}, {
channel: mb.notifications,
curvePublic: mb.curvePublic
}, function () {});
});
};
Store.burnPad = function (clientId, data) { Store.burnPad = function (clientId, data) {
var channel = data.channel; var channel = data.channel;
var ownerKey = Crypto.b64AddSlashes(data.ownerKey || ''); var ownerKey = Crypto.b64AddSlashes(data.ownerKey || '');
@ -1665,8 +1704,14 @@ define([
edPrivate: Hash.encodeBase64(pair.secretKey) edPrivate: Hash.encodeBase64(pair.secretKey)
}, function (e, rpc) { }, function (e, rpc) {
if (e) { return void console.error(e); } if (e) { return void console.error(e); }
rpc.removeOwnedChannel(channel, function (err) { Store.getPadMetadata(null, {
if (err) { console.error(err); } channel: channel
}, function (md) {
rpc.removeOwnedChannel(channel, function (err) {
if (err) { return void console.error(err); }
// Notify owners that the pad was removed
notifyOwnerPadRemoved(data, md);
});
}); });
}); });
} catch (e) { } catch (e) {
@ -2130,6 +2175,11 @@ define([
updateMetadata: function () { updateMetadata: function () {
broadcast([], "UPDATE_METADATA"); broadcast([], "UPDATE_METADATA");
}, },
updateDrive: function () {
sendDriveEvent('DRIVE_CHANGE', {
path: ['drive', 'filesData']
});
},
pinPads: function (data, cb) { Store.pinPads(null, data, cb); }, pinPads: function (data, cb) { Store.pinPads(null, data, cb); },
}, waitFor, function (ev, data, clients, _cb) { }, waitFor, function (ev, data, clients, _cb) {
var cb = Util.once(_cb || function () {}); var cb = Util.once(_cb || function () {});

View File

@ -482,6 +482,31 @@ define([
cb(true); cb(true);
}; };
handlers['OWNED_PAD_REMOVED'] = function (ctx, box, data, cb) {
var msg = data.msg;
var content = msg.content;
if (msg.author !== content.user.curvePublic) { return void cb(true); }
if (!content.channel) {
console.log('Remove invalid notification');
return void cb(true);
}
var channel = content.channel;
var res = ctx.store.manager.findChannel(channel);
res.forEach(function (obj) {
var paths = ctx.store.manager.findFile(obj.id);
ctx.store.manager.delete({
paths: paths
}, function () {
ctx.updateDrive();
});
});
cb(true);
};
return { return {

View File

@ -422,6 +422,7 @@ proxy.mailboxes = {
store: store, store: store,
pinPads: cfg.pinPads, pinPads: cfg.pinPads,
updateMetadata: cfg.updateMetadata, updateMetadata: cfg.updateMetadata,
updateDrive: cfg.updateDrive,
emit: emit, emit: emit,
clients: [], clients: [],
boxes: {}, boxes: {},

View File

@ -119,6 +119,7 @@ define([
// If it's not a shared folder, check the pads // If it's not a shared folder, check the pads
if (!data) { data = Env.user.userObject.getFileData(id, editable); } if (!data) { data = Env.user.userObject.getFileData(id, editable); }
ret.push({ ret.push({
id: id,
data: data, data: data,
userObject: Env.user.userObject userObject: Env.user.userObject
}); });
@ -126,6 +127,7 @@ define([
Object.keys(Env.folders).forEach(function (fId) { Object.keys(Env.folders).forEach(function (fId) {
Env.folders[fId].userObject.findChannels([channel]).forEach(function (id) { Env.folders[fId].userObject.findChannels([channel]).forEach(function (id) {
ret.push({ ret.push({
id: id,
fId: fId, fId: fId,
data: Env.folders[fId].userObject.getFileData(id, editable), data: Env.folders[fId].userObject.getFileData(id, editable),
userObject: Env.folders[fId].userObject userObject: Env.folders[fId].userObject
@ -1095,9 +1097,11 @@ define([
// Store // Store
getChannelsList: callWithEnv(getChannelsList), getChannelsList: callWithEnv(getChannelsList),
addPad: callWithEnv(addPad), addPad: callWithEnv(addPad),
delete: callWithEnv(_delete),
// Tools // Tools
findChannel: callWithEnv(findChannel), findChannel: callWithEnv(findChannel),
findHref: callWithEnv(findHref), findHref: callWithEnv(findHref),
findFile: callWithEnv(findFile),
getEditHash: callWithEnv(getEditHash), getEditHash: callWithEnv(getEditHash),
user: Env.user, user: Env.user,
folders: Env.folders folders: Env.folders

View File

@ -81,8 +81,8 @@ define([
}); });
localStorage.CRYPTPAD_URLARGS = ApiConfig.requireConf.urlArgs; localStorage.CRYPTPAD_URLARGS = ApiConfig.requireConf.urlArgs;
} }
var cache = {}; var cache = window.cpCache = {};
var localStore = {}; var localStore = window.localStore = {};
Object.keys(localStorage).forEach(function (k) { Object.keys(localStorage).forEach(function (k) {
if (k.indexOf('CRYPTPAD_CACHE|') === 0) { if (k.indexOf('CRYPTPAD_CACHE|') === 0) {
cache[k.slice(('CRYPTPAD_CACHE|').length)] = localStorage[k]; cache[k.slice(('CRYPTPAD_CACHE|').length)] = localStorage[k];
@ -1240,6 +1240,8 @@ define([
if (burnAfterReading) { if (burnAfterReading) {
Cryptpad.padRpc.onReadyEvent.reg(function () { Cryptpad.padRpc.onReadyEvent.reg(function () {
Cryptpad.burnPad({ Cryptpad.burnPad({
password: password,
href: window.location.href,
channel: secret.channel, channel: secret.channel,
ownerKey: burnAfterReading ownerKey: burnAfterReading
}); });

View File

@ -58,7 +58,7 @@ define([
// Remove the listener once we've received the READY message // Remove the listener once we've received the READY message
window.removeEventListener('message', whenReady); window.removeEventListener('message', whenReady);
// Answer with the requested data // Answer with the requested data
postMsg(JSON.stringify({ txid: data.txid, language: Cryptpad.getLanguage() })); postMsg(JSON.stringify({ txid: data.txid, language: Cryptpad.getLanguage(), localStore: window.localStore, cache: window.cpCache }));
// Then start the channel // Then start the channel
window.addEventListener('message', function (msg) { window.addEventListener('message', function (msg) {

View File

@ -60,7 +60,7 @@ define([
// Remove the listener once we've received the READY message // Remove the listener once we've received the READY message
window.removeEventListener('message', whenReady); window.removeEventListener('message', whenReady);
// Answer with the requested data // Answer with the requested data
postMsg(JSON.stringify({ txid: data.txid, language: Cryptpad.getLanguage() })); postMsg(JSON.stringify({ txid: data.txid, language: Cryptpad.getLanguage(), localStore: window.localStore, cache: window.cpCache }));
// Then start the channel // Then start the channel
window.addEventListener('message', function (msg) { window.addEventListener('message', function (msg) {
@ -105,6 +105,21 @@ define([
config.addCommonRpc(sframeChan); config.addCommonRpc(sframeChan);
sframeChan.on('EV_CACHE_PUT', function (x) {
Object.keys(x).forEach(function (k) {
localStorage['CRYPTPAD_CACHE|' + k] = x[k];
});
});
sframeChan.on('EV_LOCALSTORE_PUT', function (x) {
Object.keys(x).forEach(function (k) {
if (typeof(x[k]) === "undefined") {
delete localStorage['CRYPTPAD_STORE|' + k];
return;
}
localStorage['CRYPTPAD_STORE|' + k] = x[k];
});
});
sframeChan.on('Q_GET_FILES_LIST', function (types, cb) { sframeChan.on('Q_GET_FILES_LIST', function (types, cb) {
Cryptpad.getSecureFilesList(types, function (err, data) { Cryptpad.getSecureFilesList(types, function (err, data) {
cb({ cb({