Move the shared folder loader to the new module

pull/1/head
yflory 5 years ago
parent 05caf86033
commit 670d845262

@ -1504,15 +1504,18 @@ define([
}; };
// SHARED FOLDERS // SHARED FOLDERS
var handleSharedFolder = function (id, rt) {
store.sharedFolders[id] = rt;
if (store.driveEvents) {
registerProxyEvents(rt.proxy, id);
}
};
var loadSharedFolder = Store.loadSharedFolder = function (id, data, cb) { var loadSharedFolder = Store.loadSharedFolder = function (id, data, cb) {
var rt = SF.load({ var rt = SF.load({
network: store.network, network: store.network,
manager: store.manager manager: store.manager
}, id, data, cb); }, id, data, cb);
store.sharedFolders[id] = rt; handleSharedFolder(id, rt);
if (store.driveEvents) {
registerProxyEvents(rt.proxy, id);
}
return rt; return rt;
}; };
Store.loadSharedFolderAnon = function (clientId, data, cb) { Store.loadSharedFolderAnon = function (clientId, data, cb) {
@ -1768,51 +1771,6 @@ define([
/////////////////////// Init ///////////////////////////////////// /////////////////////// Init /////////////////////////////////////
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
var loadSharedFolders = function (waitFor) {
store.sharedFolders = {};
var shared = Util.find(store.proxy, ['drive', UserObject.SHARED_FOLDERS]) || {};
// 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;
});*/
// XXX test: we probably shouldn't filter shared folder anymore here because
// the owner or the expiration time can change, so they can all be deleted
var checkExpired = Object.keys(shared).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 (waitFor) {
Object.keys(shared).forEach(function (id) {
var sf = shared[id];
loadSharedFolder(id, sf, waitFor());
});
}).nThen(waitFor());
};
var onReady = function (clientId, returned, cb) { var onReady = function (clientId, returned, cb) {
var proxy = store.proxy; var proxy = store.proxy;
var unpin = function (data, cb) { var unpin = function (data, cb) {
@ -1863,7 +1821,7 @@ define([
state: 3 state: 3
}); });
userObject.fixFiles(); userObject.fixFiles();
loadSharedFolders(waitFor); SF.loadSharedFolders(store.proxy, userObject, handleSharedFolder, waitFor);
loadMessenger(); loadMessenger();
loadCursor(); loadCursor();
loadOnlyOffice(); loadOnlyOffice();

@ -1,12 +1,21 @@
define([ define([
'/common/common-hash.js', '/common/common-hash.js',
'/common/common-util.js',
'/common/userObject.js',
'/bower_components/nthen/index.js',
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/bower_components/chainpad-listmap/chainpad-listmap.js', '/bower_components/chainpad-listmap/chainpad-listmap.js',
'/bower_components/chainpad/chainpad.dist.js', '/bower_components/chainpad/chainpad.dist.js',
], function (Hash, Crypto, Listmap, ChainPad) { ], function (Hash, Util, UserObject,
nThen, Crypto, Listmap, ChainPad) {
var SF = {}; var SF = {};
/* load
create and load a proxy using listmap for a given shared folder
- config: network and "manager" (either the user one or a team manager)
- id: shared folder id
*/
SF.load = function (config, id, data, cb) { SF.load = function (config, id, data, cb) {
var network = config.network; var network = config.network;
var manager = config.manager; var manager = config.manager;
@ -30,18 +39,53 @@ define([
} }
}; };
var rt = Listmap.create(listmapConfig); var rt = Listmap.create(listmapConfig);
//store.sharedFolders[id] = rt; // XXX
rt.proxy.on('ready', function (info) { rt.proxy.on('ready', function (info) {
manager.addProxy(id, rt.proxy, info.leave); manager.addProxy(id, rt.proxy, info.leave);
cb(rt, info.metadata); cb(rt, info.metadata);
}); });
// XXX
/*if (store.driveEvents) {
registerProxyEvents(rt.proxy, id);
}*/
return rt; return rt;
}; };
/* loadSharedFolders
load all shared folder stored in a given drive
- proxy: user or team main proxy
- userObject: userObject associated to the main drive
- handler: a function (sfid, rt) called for each shared folder loaded
*/
SF.loadSharedFolders = function (proxy, userObject, handler, waitFor) {
store.sharedFolders = {};
var shared = Util.find(proxy, ['drive', UserObject.SHARED_FOLDERS]) || {};
// 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 checkExpired = Object.keys(shared).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 = userObject.findFile(Number(fId));
userObject.delete(paths, waitFor(), true);
delete shared[fId];
});
}));
}).nThen(function (waitFor) {
Object.keys(shared).forEach(function (id) {
var sf = shared[id];
var rt = loadSharedFolder(id, sf, waitFor());
handler(id, rt);
});
}).nThen(waitFor());
};
return SF; return SF;
}); });

Loading…
Cancel
Save