Only use offline cache in the drive app for now

pull/1/head
yflory 4 years ago
parent bb13165e86
commit 65628a5169

@ -2108,6 +2108,7 @@ define([
anonHash: LocalStore.getFSHash(), anonHash: LocalStore.getFSHash(),
localToken: tryParsing(localStorage.getItem(Constants.tokenKey)), // TODO move this to LocalStore ? localToken: tryParsing(localStorage.getItem(Constants.tokenKey)), // TODO move this to LocalStore ?
language: common.getLanguage(), language: common.getLanguage(),
cache: rdyCfg.cache,
driveEvents: true //rdyCfg.driveEvents // Boolean driveEvents: true //rdyCfg.driveEvents // Boolean
}; };

@ -34,6 +34,8 @@ define([
NetConfig, AppConfig, NetConfig, AppConfig,
Crypto, ChainPad, CpNetflux, Listmap, nThen, Saferphore) { Crypto, ChainPad, CpNetflux, Listmap, nThen, Saferphore) {
var onReadyEvt = Util.mkEvent(true);
// Default settings for new users // Default settings for new users
var NEW_USER_SETTINGS = { var NEW_USER_SETTINGS = {
drive: { drive: {
@ -595,6 +597,7 @@ define([
pendingFriends: store.proxy.friends_pending || {}, pendingFriends: store.proxy.friends_pending || {},
supportPrivateKey: Util.find(store.proxy, ['mailboxes', 'supportadmin', 'keys', 'curvePrivate']), supportPrivateKey: Util.find(store.proxy, ['mailboxes', 'supportadmin', 'keys', 'curvePrivate']),
accountName: store.proxy.login_name || '', accountName: store.proxy.login_name || '',
offline: store.offline,
teams: teams, teams: teams,
plan: account.plan plan: account.plan
} }
@ -2178,6 +2181,7 @@ define([
}); });
}; };
Store.addSharedFolder = function (clientId, data, cb) { Store.addSharedFolder = function (clientId, data, cb) {
onReadyEvt.reg(function () {
var s = getStore(data.teamId); var s = getStore(data.teamId);
s.manager.addSharedFolder(data, function (id) { s.manager.addSharedFolder(data, function (id) {
if (id && typeof(id) === "object" && id.error) { if (id && typeof(id) === "object" && id.error) {
@ -2189,6 +2193,7 @@ define([
}, clientId); }, clientId);
cb(id); cb(id);
}); });
});
}; };
Store.updateSharedFolderPassword = function (clientId, data, cb) { Store.updateSharedFolderPassword = function (clientId, data, cb) {
SF.updatePassword(Store, data, store.network, cb); SF.updatePassword(Store, data, store.network, cb);
@ -2500,49 +2505,20 @@ define([
addSharedFolderHandler(); addSharedFolderHandler();
userObject.migrate(cb); userObject.migrate(cb);
}; };
var onReady = function (clientId, returned/*, cb*/) {
// onReady: called when the drive is synced (not using the cache anymore)
// "cb" is wrapped in Util.once() and may have already been called
// if we have a local cache
var onReady = function (clientId, returned, cb) {
console.error('READY'); console.error('READY');
var proxy = store.proxy;
/*
var unpin = function (data, cb) {
if (!store.loggedIn) { return void cb(); }
Store.unpinPads(null, data, cb);
};
var pin = function (data, cb) {
if (!store.loggedIn) { return void cb(); }
Store.pinPads(null, data, cb);
};
if (!proxy.settings) { proxy.settings = NEW_USER_SETTINGS; }
if (!proxy.friends_pending) { proxy.friends_pending = {}; }
var manager = store.manager = ProxyManager.create(proxy.drive, {
onSync: function (cb) { onSync(null, cb); },
edPublic: proxy.edPublic,
pin: pin,
unpin: unpin,
loadSharedFolder: loadSharedFolder,
settings: proxy.settings,
removeOwnedChannel: function (channel, cb) { Store.removeOwnedChannel('', channel, cb); },
Store: Store
}, {
outer: true,
edPublic: store.proxy.edPublic,
loggedIn: store.loggedIn,
log: function (msg) {
// broadcast to all drive apps
sendDriveEvent("DRIVE_LOG", msg);
},
rt: store.realtime
});
var userObject = store.userObject = manager.user.userObject;
addSharedFolderHandler();
*/
store.ready = true; store.ready = true;
var proxy = store.proxy;
var manager = store.manager; var manager = store.manager;
var userObject = store.userObject; var userObject = store.userObject;
nThen(function (waitFor) { nThen(function (waitFor) {
if (manager) { return; } if (manager) { return; }
onCacheReady(clientId, waitFor); onCacheReady(clientId, waitFor());
manager = store.manager; manager = store.manager;
userObject = store.userObject; userObject = store.userObject;
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
@ -2616,9 +2592,12 @@ define([
Feedback.init(returned.feedback); Feedback.init(returned.feedback);
// XXX send feedback and logintoken to outer... // XXX send feedback and logintoken to outer...
//if (typeof(cb) === 'function') { cb(returned); } // "cb" may have already been called by onCacheReady
store.offline = false; if (typeof(cb) === 'function') { cb(returned); }
sendDriveEvent('NETWORK_RECONNECT'); sendDriveEvent('NETWORK_RECONNECT');
store.offline = false;
// XXX broadcast READY event with the missing data
// XXX we can improve feedback to queue the queries and send them when coming back online
if (typeof(proxy.uid) !== 'string' || proxy.uid.length !== 32) { if (typeof(proxy.uid) !== 'string' || proxy.uid.length !== 32) {
// even anonymous users should have a persistent, unique-ish id // even anonymous users should have a persistent, unique-ish id
@ -2673,6 +2652,8 @@ define([
broadcast([], "UPDATE_TOKEN", { token: proxy[Constants.tokenKey] }); broadcast([], "UPDATE_TOKEN", { token: proxy[Constants.tokenKey] });
}); });
onReadyEvt.fire();
loadMailbox(); loadMailbox();
}); });
}; };
@ -2717,8 +2698,8 @@ define([
if (!data.userHash) { if (!data.userHash) {
returned.anonHash = Hash.getEditHashFromKeys(secret); returned.anonHash = Hash.getEditHashFromKeys(secret);
} }
if (typeof(cb) === "function") { cb(returned); }
}).on('cacheready', function (info) { }).on('cacheready', function (info) {
if (!data.cache) { return; }
store.offline = true; store.offline = true;
store.realtime = info.realtime; store.realtime = info.realtime;
store.networkPromise = info.networkPromise; store.networkPromise = info.networkPromise;
@ -2753,10 +2734,12 @@ define([
rt.proxy.on('disconnect', function () { rt.proxy.on('disconnect', function () {
store.offline = true; store.offline = true;
sendDriveEvent('NETWORK_DISCONNECT'); sendDriveEvent('NETWORK_DISCONNECT');
broadcast([], "UPDATE_METADATA");
}); });
rt.proxy.on('reconnect', function () { rt.proxy.on('reconnect', function () {
store.offline = false; store.offline = false;
sendDriveEvent('NETWORK_RECONNECT'); sendDriveEvent('NETWORK_RECONNECT');
broadcast([], "UPDATE_METADATA");
}); });
// Ping clients regularly to make sure one tab was not closed without sending a removeClient() // Ping clients regularly to make sure one tab was not closed without sending a removeClient()

@ -151,6 +151,7 @@ define([
Cryptpad.ready(waitFor(), { Cryptpad.ready(waitFor(), {
driveEvents: cfg.driveEvents, driveEvents: cfg.driveEvents,
cache: Boolean(cfg.cache),
currentPad: currentPad currentPad: currentPad
}); });

@ -278,6 +278,7 @@ define([
if (!proxy.drive || typeof(proxy.drive) !== 'object') { if (!proxy.drive || typeof(proxy.drive) !== 'object') {
throw new Error("Corrupted drive"); throw new Error("Corrupted drive");
} }
APP.online = !privateData.offline;
var drive = DriveUI.create(common, { var drive = DriveUI.create(common, {
$limit: usageBar && usageBar.$container, $limit: usageBar && usageBar.$container,
proxy: proxy, proxy: proxy,
@ -309,6 +310,7 @@ define([
onDisconnect(); onDisconnect();
}); });
sframeChan.on('EV_NETWORK_RECONNECT', function () { sframeChan.on('EV_NETWORK_RECONNECT', function () {
console.log('here');
onReconnect(); onReconnect();
}); });
common.onLogout(function () { setEditable(false); }); common.onLogout(function () { setEditable(false); });

@ -129,6 +129,7 @@ define([
hash: hash, hash: hash,
href: href, href: href,
afterSecrets: afterSecrets, afterSecrets: afterSecrets,
cache: true,
noHash: true, noHash: true,
noRealtime: true, noRealtime: true,
driveEvents: true, driveEvents: true,

Loading…
Cancel
Save