diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index da1e4a103..66ad6a442 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -130,6 +130,12 @@ define([ postMessage("DRIVE_USEROBJECT", data, cb); }; common.restoreDrive = function (data, cb) { + if (data.sfId) { // Shared folder ID + postMessage('RESTORE_SHARED_FOLDER', data, cb, { + timeout: 5 * 60 * 1000 + }); + return; + } postMessage("SET", { key:['drive'], value: data diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index cfa071ec1..e951e41df 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -85,6 +85,20 @@ define([ cb({}); }; + Store.restoreSharedFolder = function (clientId, data, cb) { + if (!data.sfId || !data.drive) { return void cb({error:'EINVAL'}); } + if (store.sharedFolders[data.sfId]) { + Object.keys(data.drive).forEach(function (k) { + store.sharedFolders[data.sfId].proxy[k] = data.drive[k]; + }); + Object.keys(store.sharedFolders[data.sfId].proxy).forEach(function (k) { + if (data.drive[k]) { return; } + delete store.sharedFolders[data.sfId].proxy[k]; + }); + } + onSync(cb); + }; + Store.hasSigningKeys = function () { if (!store.proxy) { return; } return typeof(store.proxy.edPrivate) === 'string' && diff --git a/www/common/outer/store-rpc.js b/www/common/outer/store-rpc.js index ca9208f71..4bc2dfbc8 100644 --- a/www/common/outer/store-rpc.js +++ b/www/common/outer/store-rpc.js @@ -57,6 +57,7 @@ define([ GET_SHARED_FOLDER: Store.getSharedFolder, ADD_SHARED_FOLDER: Store.addSharedFolder, LOAD_SHARED_FOLDER: Store.loadSharedFolderAnon, + RESTORE_SHARED_FOLDER: Store.restoreSharedFolder, // Messaging ANSWER_FRIEND_REQUEST: Store.answerFriendRequest, SEND_FRIEND_REQUEST: Store.sendFriendRequest, diff --git a/www/common/sframe-common-history.js b/www/common/sframe-common-history.js index 6711efb2b..aae04ca95 100644 --- a/www/common/sframe-common-history.js +++ b/www/common/sframe-common-history.js @@ -63,7 +63,8 @@ define([ var sframeChan = common.getSframeChannel(); sframeChan.query('Q_GET_HISTORY_RANGE', { - lastKnownHash: lastKnownHash + lastKnownHash: lastKnownHash, + sharedFolder: config.sharedFolder }, function (err, data) { if (err) { return void console.error(err); } if (!Array.isArray(data.messages)) { return void console.error('Not an array!'); } @@ -313,6 +314,10 @@ define([ $(window).trigger('resize'); }; + if (config.onOpen) { + config.onOpen(); + } + // Load all the history messages into a new chainpad object loadMoreHistory(config, common, function (err, newRt, isFull) { History.readOnly = common.getMetadataMgr().getPrivateData().readOnly; diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 29f84ea66..95337d463 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -537,9 +537,12 @@ define([ sframeChan.on('Q_GET_HISTORY_RANGE', function (data, cb) { var nSecret = secret; if (cfg.isDrive) { + // Shared folder or user hash or fs hash var hash = Utils.LocalStore.getUserHash() || Utils.LocalStore.getFSHash(); + if (data.sharedFolder) { hash = data.sharedFolder.hash; } if (hash) { - nSecret = Utils.Hash.getSecrets('drive', hash); + var password = (data.sharedFolder && data.sharedFolder.password) || undefined; + nSecret = Utils.Hash.getSecrets('drive', hash, password); } } var channel = nSecret.channel; diff --git a/www/drive/inner.js b/www/drive/inner.js index 3f6609676..8f7981093 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -1705,6 +1705,11 @@ define([ default: msg = undefined; } + if (history.isHistoryMode && history.sfId) { + // Shared folder history: always display the warning + msg = Messages.fm_info_sharedFolderHistory; + return $(common.fixLinks($box.html(msg))); + } if (!APP.loggedIn) { msg = APP.newSharedFolder ? Messages.fm_info_sharedFolder : Messages.fm_info_anonymous; return $(common.fixLinks($box.html(msg))); @@ -3527,7 +3532,32 @@ define([ return false; }); + APP.histConfig.onOpen = function () { + // If we're in a shared folder history, store its id in memory + // so that we remember that this isn't the drive history if + // we browse through the drive + var sfId = manager.isInSharedFolder(currentPath); + if (!sfId) { + delete history.sfId; + delete APP.histConfig.sharedFolder; + return; + } + history.sfId = sfId; + var data = manager.getSharedFolderData(sfId); + var parsed = Hash.parsePadUrl(data.href || data.roHref); + APP.histConfig.sharedFolder = { + hash: parsed.hash, + password: data.password + }; + }; history.onEnterHistory = function (obj) { + if (history.sfId) { + if (!obj || typeof(obj) !== "object" || Object.keys(obj).length === 0) { return; } + copyObjectValue(folders[history.sfId], obj); + refresh(); + return; + } + history.sfId = false; copyObjectValue(files, obj.drive); appStatus.isReady = true; refresh(); @@ -3667,13 +3697,22 @@ define([ APP.histConfig = { onLocal: function () { UI.addLoadingScreen({ loadingText: Messages.fm_restoreDrive }); - proxy.drive = history.currentObj.drive; - sframeChan.query("Q_DRIVE_RESTORE", history.currentObj.drive, function () { + var data = {}; + if (history.sfId) { + copyObjectValue(folders[history.sfId], history.currentObj); + data.sfId = history.sfId; + data.drive = history.currentObj; + } else { + proxy.drive = history.currentObj.drive; + data.drive = history.currentObj.drive; + } + sframeChan.query("Q_DRIVE_RESTORE", data, function () { UI.removeLoadingScreen(); }, { timeout: 5 * 60 * 1000 }); }, + onOpen: function () {}, onRemote: function () {}, setHistory: setHistory, applyVal: function (val) {