diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 150d2a469..2d77fbe6b 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -89,6 +89,12 @@ define([ cb(obj); }); }; + common.loadSharedFolder = function (id, data, cb) { + postMessage("LOAD_SHARED_FOLDER", { + id: id, + data: data + }, cb); + }; // Settings and ready common.mergeAnonDrive = function (cb) { var data = { diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index da5edd951..536d6b71a 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -1239,6 +1239,9 @@ define([ } return rt; }; + Store.loadSharedFolderAnon = function (clientId, data, cb) { + loadSharedFolder(data.id, data.data, cb); + }; Store.addSharedFolder = function (clientId, data, cb) { Store.userObjectCommand(clientId, { cmd: 'addSharedFolder', diff --git a/www/common/outer/store-rpc.js b/www/common/outer/store-rpc.js index a724fbd06..1c37be12c 100644 --- a/www/common/outer/store-rpc.js +++ b/www/common/outer/store-rpc.js @@ -56,6 +56,7 @@ define([ INCREMENT_TEMPLATE_USE: Store.incrementTemplateUse, GET_SHARED_FOLDER: Store.getSharedFolder, ADD_SHARED_FOLDER: Store.addSharedFolder, + LOAD_SHARED_FOLDER: Store.loadSharedFolderAnon, // Messaging INVITE_FROM_USERLIST: Store.inviteFromUserlist, ADD_DIRECT_MESSAGE_HANDLERS: Store.addDirectMessageHandlers, diff --git a/www/drive/main.js b/www/drive/main.js index 2ace94441..668f77f38 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -39,7 +39,7 @@ define([ var getSecrets = function (Cryptpad, Utils, cb) { var hash = window.location.hash.slice(1); var secret = Utils.Hash.getSecrets('drive', hash); - if (hash) { + if (hash && Utils.LocalStore.isLoggedIn()) { // Add a shared folder! // TODO password? Cryptpad.addSharedFolder(secret, function (id) { @@ -53,6 +53,16 @@ define([ cb(null, secret); }); return; + } else if (hash) { + var id = Utils.Util.createRandomInteger(); + window.CryptPad_newSharedFolder = id; + var data = { + href: Utils.Hash.getRelativeHref(window.location.href), + }; + Cryptpad.loadSharedFolder(id, data, function () { + cb(null, secret); + }); + return; } // No password for drive cb(null, secret);