From e629f0aa470364280bc35f360bf27e6fd2695ed2 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 9 Nov 2020 13:29:16 +0100 Subject: [PATCH] Offline fixes --- www/common/common-ui-elements.js | 1 + www/common/inner/access.js | 7 +++++++ www/common/inner/properties.js | 3 +++ www/common/inner/share.js | 24 +++++++++++++++++++++--- www/common/outer/async-store.js | 2 ++ www/common/sframe-common-outer.js | 9 +++++---- 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index e977f1f49..706a8e305 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -229,6 +229,7 @@ define([ }; }; + UIElements.noContactsMessage = function (common) { var metadataMgr = common.getMetadataMgr(); var data = metadataMgr.getUserData(); diff --git a/www/common/inner/access.js b/www/common/inner/access.js index c0967c139..fcb07a4b4 100644 --- a/www/common/inner/access.js +++ b/www/common/inner/access.js @@ -769,6 +769,7 @@ define([ }, function () {}); }; + Messages.access_offline = "You're currently offline. Access management is not available"; // XXX var getAccessTab = function (Env, data, opts, _cb) { var cb = Util.once(Util.mkAsync(_cb)); var common = Env.common; @@ -776,8 +777,14 @@ define([ var sframeChan = common.getSframeChannel(); var metadataMgr = common.getMetadataMgr(); + var priv = metadataMgr.getPrivateData(); var $div = $(h('div.cp-share-columns')); + + if (priv.offline) { + $div.append(h('p', Messages.access_offline)); + return void cb(void 0, $div); + } if (!data) { return void cb(void 0, $div); } var div1 = h('div.cp-usergrid-user.cp-share-column.cp-access'); diff --git a/www/common/inner/properties.js b/www/common/inner/properties.js index 58f10e738..46d570d3e 100644 --- a/www/common/inner/properties.js +++ b/www/common/inner/properties.js @@ -47,6 +47,9 @@ define([ if (!common.isLoggedIn()) { return void cb(void 0, $d); } + var privateData = common.getMetadataMgr().getPrivateData(); + if (privateData.offline) { return void cb(void 0, $d); } + // File and history size... var owned = Modal.isOwned(Env, data); diff --git a/www/common/inner/share.js b/www/common/inner/share.js index f3ca53f75..b70a71fa2 100644 --- a/www/common/inner/share.js +++ b/www/common/inner/share.js @@ -273,6 +273,21 @@ define([ var hasFriends = opts.hasFriends; var onFriendShare = Util.mkEvent(); + Messages.share_noContactsOffline = "OFFLINE"; // XXX + var metadataMgr = common.getMetadataMgr(); + var priv = metadataMgr.getPrivateData(); + if (priv.offline) { + return void cb(void 0, { + content: h('p', Messages.share_noContactsOffline), + buttons: [{ + className: 'cancel', + name: Messages.filePicker_close, + onClick: function () {}, + keys: [27] + }] + }); + } + var friendsObject = hasFriends ? createShareWithFriends(opts, onFriendShare, opts.getLinkValue) : UIElements.noContactsMessage(common); var friendsList = friendsObject.content; @@ -642,6 +657,8 @@ define([ opts.teams = teams; var hasFriends = opts.hasFriends = Object.keys(opts.friends || {}).length || Object.keys(teams).length; + var metadataMgr = common.getMetadataMgr(); + var priv = metadataMgr.getPrivateData(); // check if the pad is password protected var pathname = opts.pathname; @@ -662,23 +679,24 @@ define([ $rights.find('input[type="radio"]').trigger('change'); }; var onShowContacts = function () { - if (!hasFriends) { + if (!hasFriends || priv.offline) { $rights.hide(); } }; + var contactsActive = hasFriends && !priv.offline; var tabs = [{ getTab: getContactsTab, title: Messages.share_contactCategory, icon: "fa fa-address-book", - active: hasFriends, + active: contactsActive, onShow: onShowContacts, onHide: resetTab }, { getTab: getLinkTab, title: Messages.share_linkCategory, icon: "fa fa-link", - active: !hasFriends, + active: !contactsActive, }, { getTab: getEmbedTab, title: Messages.share_embedCategory, diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 5715038cc..57f31905a 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -1924,6 +1924,7 @@ define([ Store.getPadMetadata = function (clientId, data, _cb) { var cb = Util.once(Util.mkAsync(_cb)); + if (store.offline || !store.anon_rpc) { return void cb({ error: 'OFFLINE' }); } if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); } if (data.channel.length !== 32) { return void cb({ error: 'EINVAL'}); } store.anon_rpc.send('GET_METADATA', data.channel, function (err, obj) { @@ -2605,6 +2606,7 @@ define([ // "cb" may have already been called by onCacheReady if (typeof(cb) === 'function') { cb(returned); } sendDriveEvent('NETWORK_RECONNECT'); + broadcast([], "UPDATE_METADATA"); 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 diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 4d06b8a1e..3238db7f0 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -431,12 +431,13 @@ define([ } if (!stored && !parsed.hashData.password) { // We've received a link without /p/ and it doesn't work without a password: abort - if (e === "ANON_RPC_NOT_READY") { - // We're currently offline and the pad is not in our cache - sframeChan.event('EV_OFFLINE'); - } return void todo(); } + if (e === "ANON_RPC_NOT_READY") { + // We're currently offline and the pad is not in our cache + w.abort(); + return void sframeChan.event('EV_OFFLINE'); + } // Wrong password or deleted file? askPassword(true, passwordCfg); }));