|
|
@ -28,6 +28,7 @@ define([
|
|
|
|
var postMessage = function () {};
|
|
|
|
var postMessage = function () {};
|
|
|
|
var broadcast = function () {};
|
|
|
|
var broadcast = function () {};
|
|
|
|
var sendDriveEvent = function () {};
|
|
|
|
var sendDriveEvent = function () {};
|
|
|
|
|
|
|
|
var registerProxyEvents = function () {};
|
|
|
|
|
|
|
|
|
|
|
|
var storeHash;
|
|
|
|
var storeHash;
|
|
|
|
|
|
|
|
|
|
|
@ -1168,6 +1169,9 @@ define([
|
|
|
|
store.manager.addProxy(id, rt.proxy, info.leave);
|
|
|
|
store.manager.addProxy(id, rt.proxy, info.leave);
|
|
|
|
cb(rt, info.metadata);
|
|
|
|
cb(rt, info.metadata);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
if (store.driveEvents) {
|
|
|
|
|
|
|
|
registerProxyEvents(rt.proxy, id);
|
|
|
|
|
|
|
|
}
|
|
|
|
return rt;
|
|
|
|
return rt;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
Store.addSharedFolder = function (clientId, data, cb) {
|
|
|
|
Store.addSharedFolder = function (clientId, data, cb) {
|
|
|
@ -1231,32 +1235,41 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
// Special events
|
|
|
|
// Special events
|
|
|
|
|
|
|
|
|
|
|
|
var driveEventInit = false;
|
|
|
|
|
|
|
|
sendDriveEvent = function (q, data, sender) {
|
|
|
|
sendDriveEvent = function (q, data, sender) {
|
|
|
|
driveEventClients.forEach(function (cId) {
|
|
|
|
driveEventClients.forEach(function (cId) {
|
|
|
|
if (cId === sender) { return; }
|
|
|
|
if (cId === sender) { return; }
|
|
|
|
postMessage(cId, q, data);
|
|
|
|
postMessage(cId, q, data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
Store._subscribeToDrive = function (clientId) {
|
|
|
|
registerProxyEvents = function (proxy, fId) {
|
|
|
|
if (driveEventClients.indexOf(clientId) === -1) {
|
|
|
|
proxy.on('change', [], function (o, n, p) {
|
|
|
|
driveEventClients.push(clientId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!driveEventInit) {
|
|
|
|
|
|
|
|
store.proxy.on('change', [], function (o, n, p) {
|
|
|
|
|
|
|
|
sendDriveEvent('DRIVE_CHANGE', {
|
|
|
|
sendDriveEvent('DRIVE_CHANGE', {
|
|
|
|
|
|
|
|
id: fId,
|
|
|
|
old: o,
|
|
|
|
old: o,
|
|
|
|
new: n,
|
|
|
|
new: n,
|
|
|
|
path: p
|
|
|
|
path: p
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
store.proxy.on('remove', [], function (o, p) {
|
|
|
|
proxy.on('remove', [], function (o, p) {
|
|
|
|
sendDriveEvent(clientId, 'DRIVE_REMOVE', {
|
|
|
|
sendDriveEvent('DRIVE_REMOVE', {
|
|
|
|
|
|
|
|
id: fId,
|
|
|
|
old: o,
|
|
|
|
old: o,
|
|
|
|
path: p
|
|
|
|
path: p
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
driveEventInit = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Store._subscribeToDrive = function (clientId) {
|
|
|
|
|
|
|
|
if (driveEventClients.indexOf(clientId) === -1) {
|
|
|
|
|
|
|
|
driveEventClients.push(clientId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!store.driveEvents) {
|
|
|
|
|
|
|
|
store.driveEvents = true;
|
|
|
|
|
|
|
|
registerProxyEvents(store.proxy);
|
|
|
|
|
|
|
|
Object.keys(store.manager.folders).forEach(function (fId) {
|
|
|
|
|
|
|
|
var proxy = store.manager.folders[fId].proxy;
|
|
|
|
|
|
|
|
registerProxyEvents(proxy, fId);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -1313,7 +1326,6 @@ define([
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
var loadSharedFolders = function (waitFor) {
|
|
|
|
var loadSharedFolders = function (waitFor) {
|
|
|
|
var w = waitFor();
|
|
|
|
|
|
|
|
store.sharedFolders = {};
|
|
|
|
store.sharedFolders = {};
|
|
|
|
var shared = Util.find(store.proxy, ['drive', UserObject.SHARED_FOLDERS]) || {};
|
|
|
|
var shared = Util.find(store.proxy, ['drive', UserObject.SHARED_FOLDERS]) || {};
|
|
|
|
// Check if any of our shared folder is expired or deleted by its owner.
|
|
|
|
// Check if any of our shared folder is expired or deleted by its owner.
|
|
|
@ -1345,14 +1357,12 @@ define([
|
|
|
|
delete shared[fId];
|
|
|
|
delete shared[fId];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}).nThen(function () {
|
|
|
|
}).nThen(function (waitFor) {
|
|
|
|
Object.keys(shared).forEach(function (id) {
|
|
|
|
Object.keys(shared).forEach(function (id) {
|
|
|
|
var sf = shared[id];
|
|
|
|
var sf = shared[id];
|
|
|
|
loadSharedFolder(id, sf, function () {
|
|
|
|
loadSharedFolder(id, sf, waitFor());
|
|
|
|
w();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}).nThen(waitFor());
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var onReady = function (clientId, returned, cb) {
|
|
|
|
var onReady = function (clientId, returned, cb) {
|
|
|
|