diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index f746399fa..2ada4ecc6 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -366,7 +366,7 @@ define([ Store.getDeletedPads = function (clientId, data, cb) { if (!store.anon_rpc) { return void cb({error: 'ANON_RPC_NOT_READY'}); } - var list = getCanonicalChannelList(true); + var list = (data && data.list) || getCanonicalChannelList(true); if (!Array.isArray(list)) { return void cb({error: 'INVALID_FILE_LIST'}); } @@ -1313,11 +1313,45 @@ define([ ////////////////////////////////////////////////////////////////// var loadSharedFolders = function (waitFor) { + var w = waitFor(); store.sharedFolders = {}; var shared = Util.find(store.proxy, ['drive', UserObject.SHARED_FOLDERS]) || {}; - Object.keys(shared).forEach(function (id) { - var sf = shared[id]; - loadSharedFolder(id, sf, waitFor()); + // Check if any of our shared folder is expired or deleted by its owner. + // If we don't check now, Listmap will create an empty proxy if it no longer exists on + // the server. + nThen(function (waitFor) { + var edPublic = store.proxy.edPublic; + var checkExpired = Object.keys(shared).filter(function (fId) { + var d = shared[fId]; + return (Array.isArray(d.owners) && d.owners.length && + (!edPublic || d.owners.indexOf(edPublic) === -1)) + || (d.expire && d.expire < (+new Date())); + }).map(function (fId) { + return shared[fId].channel; + }); + Store.getDeletedPads(null, {list: checkExpired}, waitFor(function (chans) { + if (chans && chans.error) { return void console.error(chans.error); } + if (!Array.isArray(chans) || !chans.length) { return; } + var toDelete = []; + Object.keys(shared).forEach(function (fId) { + if (chans.indexOf(shared[fId].channel) !== -1 + && toDelete.indexOf(fId) === -1) { + toDelete.push(fId); + } + }); + toDelete.forEach(function (fId) { + var paths = store.userObject.findFile(Number(fId)); + store.userObject.delete(paths, waitFor(), true); + delete shared[fId]; + }); + })); + }).nThen(function () { + Object.keys(shared).forEach(function (id) { + var sf = shared[id]; + loadSharedFolder(id, sf, function () { + w(); + }); + }); }); }; @@ -1355,6 +1389,7 @@ define([ progress: progress }); }); + Store.initAnonRpc(null, null, waitFor()); }).nThen(function (waitFor) { postMessage(clientId, 'LOADING_DRIVE', { state: 3 diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index ca927cfe3..a89dfd206 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -2,8 +2,9 @@ define([ '/common/userObject.js', '/common/common-util.js', '/common/common-hash.js', + '/customize/messages.js', '/bower_components/nthen/index.js', -], function (UserObject, Util, Hash, nThen) { +], function (UserObject, Util, Hash, Messages, nThen) { var getConfig = function (Env) { @@ -361,8 +362,8 @@ define([ // 2b. load the proxy Env.loadSharedFolder(id, folderData, waitFor(function (rt, metadata) { - if (data.name && !rt.proxy.metadata) { // Creating a new shared folder - rt.proxy.metadata = {title: data.name}; + if (!rt.proxy.metadata) { // Creating a new shared folder + rt.proxy.metadata = {title: data.name || Messages.fm_newFolder}; // XXX } // If we're importing a folder, check its serverside metadata if (data.folderData && metadata) { diff --git a/www/common/userObject.js b/www/common/userObject.js index 7a1576f96..d373e89d6 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -40,9 +40,12 @@ define([ var log = config.log || logging; var logError = config.logError || logging; var debug = exp.debug = config.debug || logging; + + exp.fixFiles = function () {}; // Overriden by OuterFO + var error = exp.error = function() { - exp.fixFiles(); console.error.apply(console, arguments); + exp.fixFiles(); }; if (config.outer) { @@ -139,6 +142,9 @@ define([ // Data from filesData var getTitle = exp.getTitle = function (file, type) { + if (isSharedFolder(file)) { + return '??'; // XXX + } var data = getFileData(file); if (!file || !data || !(data.href || data.roHref)) { error("getTitle called with a non-existing file id: ", file, data); diff --git a/www/drive/inner.js b/www/drive/inner.js index d74d61d06..1fa7e5eb0 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -3192,6 +3192,7 @@ define([ var title = manager.getTitle(id); titles.push(title); var paths = manager.findFile(id); + console.log(title, id, paths); manager.delete(paths, refresh); }); if (!titles.length) { return; }