From d81e1f3ecd58146ba75ed855a1fd2cd0bf8bcaf9 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 8 Mar 2021 10:59:54 +0100 Subject: [PATCH] Prototype --- www/common/cryptpad-common.js | 4 +- www/common/outer/async-store.js | 60 ++++++++++++++------- www/common/sframe-app-outer.js | 1 + www/common/sframe-chainpad-netflux-inner.js | 1 + www/common/sframe-common-outer.js | 2 + 5 files changed, 49 insertions(+), 19 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 68e341562..f6b6fbc96 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -499,6 +499,7 @@ define([ var isNew = function () { error = undefined; postMessage('IS_NEW_CHANNEL', {channel: channel}, function (obj) { + console.error(obj); if (obj && obj.error) { error = obj.error; } if (!obj) { error = "INVALID_RESPONSE"; } @@ -2271,8 +2272,9 @@ define([ localToken: tryParsing(localStorage.getItem(Constants.tokenKey)), // TODO move this to LocalStore ? language: common.getLanguage(), cache: rdyCfg.cache, + noDrive: rdyCfg.noDrive, disableCache: localStorage['CRYPTPAD_STORE|disableCache'], - driveEvents: true //rdyCfg.driveEvents // Boolean + driveEvents: !rdyCfg.noDrive //rdyCfg.driveEvents // Boolean }; common.userHash = userHash; diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index bc857be7f..44723a415 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -547,6 +547,7 @@ define([ ////////////////////////////////////////////////////////////////// var getAllStores = Store.getAllStores = function () { + if (!store.proxy) { return []; } var stores = [store]; var teamModule = store.modules['team']; if (teamModule) { @@ -568,7 +569,7 @@ define([ getColor().toString(16); }; var getUserColor = function () { - var color = Util.find(store.proxy, ['settings', 'general', 'cursor', 'color']); + var color = Util.find(store, ['proxy', 'settings', 'general', 'cursor', 'color']); if (!color) { color = getRandomColor(); Store.setAttribute(null, { @@ -581,33 +582,34 @@ define([ // Get the metadata for sframe-common-outer Store.getMetadata = function (clientId, app, cb) { - var disableThumbnails = Util.find(store.proxy, ['settings', 'general', 'disableThumbnails']); + var proxy = store.proxy || {}; + var disableThumbnails = Util.find(proxy, ['settings', 'general', 'disableThumbnails']); var teams = (store.modules['team'] && store.modules['team'].getTeamsData(app)) || {}; var metadata = { // "user" is shared with everybody via the userlist user: { - name: store.proxy[Constants.displayNameKey] || "", - uid: store.proxy.uid, - avatar: Util.find(store.proxy, ['profile', 'avatar']), - profile: Util.find(store.proxy, ['profile', 'view']), + name: proxy[Constants.displayNameKey] || "", + uid: proxy.uid, + avatar: Util.find(proxy, ['profile', 'avatar']), + profile: Util.find(proxy, ['profile', 'view']), color: getUserColor(), - notifications: Util.find(store.proxy, ['mailboxes', 'notifications', 'channel']), - curvePublic: store.proxy.curvePublic, + notifications: Util.find(proxy, ['mailboxes', 'notifications', 'channel']), + curvePublic: proxy.curvePublic, }, // "priv" is not shared with other users but is needed by the apps priv: { clientId: clientId, - edPublic: store.proxy.edPublic, - friends: store.proxy.friends || {}, - settings: store.proxy.settings, + edPublic: proxy.edPublic, + friends: proxy.friends || {}, + settings: proxy.settings || NEW_USER_SETTINGS, thumbnails: disableThumbnails === false, isDriveOwned: Boolean(Util.find(store, ['driveMetadata', 'owners'])), - support: Util.find(store.proxy, ['mailboxes', 'support', 'channel']), + support: Util.find(proxy, ['mailboxes', 'support', 'channel']), driveChannel: store.driveChannel, - pendingFriends: store.proxy.friends_pending || {}, - supportPrivateKey: Util.find(store.proxy, ['mailboxes', 'supportadmin', 'keys', 'curvePrivate']), - accountName: store.proxy.login_name || '', - offline: store.offline, + pendingFriends: proxy.friends_pending || {}, + supportPrivateKey: Util.find(proxy, ['mailboxes', 'supportadmin', 'keys', 'curvePrivate']), + accountName: proxy.login_name || '', + offline: store.proxy && store.offline, teams: teams, plan: account.plan } @@ -1632,6 +1634,7 @@ define([ }; Store.joinPad = function (clientId, data) { + console.error('JOINPAD'); if (data.versionHash) { return void getVersionHash(clientId, data); } @@ -1708,6 +1711,7 @@ define([ postMessage(clientId, "PAD_CACHE_READY"); }, onReady: function (pad) { +console.warn(pad); var padData = pad.metadata || {}; channel.data = padData; if (padData && padData.validateKey && store.messenger) { @@ -1768,8 +1772,10 @@ define([ channel: data.channel, metadata: data.metadata, network: store.network || store.networkPromise, + websocketURL: NetConfig.getWebsocketURL(), //readOnly: data.readOnly, onConnect: function (wc, sendMessage) { +console.warn('CONNECT'); channel.sendMessage = function (msg, cId, cb) { // Send to server sendMessage(msg, function (err) { @@ -2636,7 +2642,7 @@ define([ loadUniversal(Messenger, 'messenger', waitFor); store.messenger = store.modules['messenger']; loadUniversal(Profile, 'profile', waitFor); - store.modules['team'].onReady(waitFor); + if (store.modules['team']) { store.modules['team'].onReady(waitFor); } loadUniversal(History, 'history', waitFor); }).nThen(function () { var requestLogin = function () { @@ -2748,6 +2754,11 @@ define([ return void cb({error: '[Store.init] Unable to find or create a drive hash. Aborting...'}); } + var lock = false; + if (!data.userHash && !data.anonHash) { + lock = true; + } + var updateProgress = function (data) { data.type = 'drive'; postMessage(clientId, 'LOADING_DRIVE', data); @@ -2767,6 +2778,7 @@ define([ userName: 'fs', logLevel: 1, ChainPad: ChainPad, + lock: lock, updateProgress: updateProgress, classic: true, }; @@ -2914,6 +2926,7 @@ define([ */ var initialized = false; + var noDrive = []; Store.init = function (clientId, data, _callback) { var callback = Util.once(_callback); @@ -2948,7 +2961,6 @@ define([ Cache.disable(); } - initialized = true; postMessage = function (clientId, cmd, d, cb) { data.query(clientId, cmd, d, cb); }; @@ -2956,6 +2968,18 @@ define([ data.broadcast(excludes, cmd, d, cb); }; + // First tab, no user hash, no anon hash and this app doesn't need a drive + // ==> don't create a drive + if (data.noDrive && !data.userHash && !data.anonHash) { + noDrive.push(clientId); + // XXX We need a network before initAnonRpc... + return void initAnonRpc(null, null, function () { + callback({}); + }); + } + + initialized = true; + store.data = data; connect(clientId, data, function (ret) { if (Object.keys(store.proxy).length === 1) { diff --git a/www/common/sframe-app-outer.js b/www/common/sframe-app-outer.js index 2ff61145f..3d3cfaf28 100644 --- a/www/common/sframe-app-outer.js +++ b/www/common/sframe-app-outer.js @@ -16,6 +16,7 @@ define([ }).nThen(function (/*waitFor*/) { SFCommonO.start({ cache: true, + noDrive: true, hash: hash, href: href, useCreationScreen: true, diff --git a/www/common/sframe-chainpad-netflux-inner.js b/www/common/sframe-chainpad-netflux-inner.js index 1bdcc260f..8303d7445 100644 --- a/www/common/sframe-chainpad-netflux-inner.js +++ b/www/common/sframe-chainpad-netflux-inner.js @@ -152,6 +152,7 @@ define([ cb('OK'); }); sframeChan.on('EV_RT_READY', function () { + console.error('INNER READY'); if (isReady) { return; } if (updateLoadingProgress) { updateLoadingProgress({ diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 39a53d9c5..412bfc687 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -222,6 +222,7 @@ define([ } catch (e) { console.error(e); } Cryptpad.ready(waitFor(), { + noDrive: cfg.noDrive, driveEvents: cfg.driveEvents, cache: Boolean(cfg.cache), currentPad: currentPad @@ -486,6 +487,7 @@ define([ } // Not a file, so we can use `isNewChannel` Cryptpad.isNewChannel(currentPad.href, password, w(function(e, isNew) { + alert('ko'); if (isNew && expire && expire < (+new Date())) { sframeChan.event("EV_EXPIRED_ERROR"); waitFor.abort();