diff --git a/customize.dist/main.js b/customize.dist/main.js index 44ef51d0d..5969c6c71 100644 --- a/customize.dist/main.js +++ b/customize.dist/main.js @@ -12,7 +12,7 @@ define([ // Make sure we don't display non-translated content (empty button) $main.find('#data').removeClass('hidden'); - if (LocalStore.isLoggedIn()) { + if (LocalStore.isLoggedIn() && LocalStore.getDriveRedirectPreference()) { if (window.location.pathname === '/') { window.location = '/drive/'; return; diff --git a/www/common/common-constants.js b/www/common/common-constants.js index 0a1c1d7f6..fd4d1474b 100644 --- a/www/common/common-constants.js +++ b/www/common/common-constants.js @@ -10,6 +10,7 @@ define(['/customize/application_config.js'], function (AppConfig) { oldStorageKey: 'CryptPad_RECENTPADS', storageKey: 'filesData', tokenKey: 'loginToken', + prefersDriveRedirectKey: 'prefersDriveRedirect', displayPadCreationScreen: 'displayPadCreationScreen', deprecatedKey: 'deprecated', MAX_TEAMS_SLOTS: AppConfig.maxTeamsSlots || 5, diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index e9635d5b5..fd2d29cd2 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -1103,6 +1103,11 @@ define([ postMessage('BURN_PAD', data); }; + common.setDriveRedirectPreference = function (data, cb) { + LocalStore.setDriveRedirectPreference(data && data.value); + cb(); + }; + common.changePadPassword = function (Crypt, Crypto, data, cb) { var href = data.href; var oldPassword = data.oldPassword; @@ -2506,6 +2511,11 @@ define([ } if (data.anonHash && !cfg.userHash) { LocalStore.setFSHash(data.anonHash); } + var prefersDriveRedirect = data[Constants.prefersDriveRedirectKey]; + if (typeof(prefersDriveRedirect) === 'boolean') { + LocalStore.setDriveRedirectPreference(prefersDriveRedirect); + } + initialized = true; channelIsReady(); }); diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 21bc77798..cec0d7d73 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -3167,6 +3167,10 @@ define([ initialized = false; } + var redirect = Constants.prefersDriveRedirectKey; + var redirectPreference = Util.find(store, [ 'proxy', 'settings', 'general', redirect, ]); + ret[redirect] = redirectPreference; + callback(ret); }); diff --git a/www/common/outer/local-store.js b/www/common/outer/local-store.js index 9b62fbbde..fb49d084d 100644 --- a/www/common/outer/local-store.js +++ b/www/common/outer/local-store.js @@ -76,6 +76,16 @@ define([ return window.CP_logged_in || typeof getUserHash() === "string"; }; + LocalStore.getDriveRedirectPreference = function () { + try { + return JSON.parse(localStorage[Constants.redirectToDriveKey]); + } catch (err) { return; } + }; + + LocalStore.setDriveRedirectPreference = function (bool) { + localStorage.setItem(Constants.redirectToDriveKey, Boolean(bool)); + }; + LocalStore.login = function (hash, name, cb) { if (!hash) { throw new Error('expected a user hash'); } if (!name) { throw new Error('expected a user name'); } diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 198d17099..cc1ddf2f5 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -615,6 +615,7 @@ define([ newTemplate: Array.isArray(Cryptpad.initialPath) && Cryptpad.initialPath[0] === "template", feedbackAllowed: Utils.Feedback.state, + prefersDriveRedirect: Utils.LocalStore.getDriveRedirectPreference(), isPresent: parsed.hashData && parsed.hashData.present, isEmbed: parsed.hashData && parsed.hashData.embed, oldVersionHash: parsed.hashData && parsed.hashData.version < 2, // password diff --git a/www/settings/inner.js b/www/settings/inner.js index 24e03a4cf..f979379d7 100644 --- a/www/settings/inner.js +++ b/www/settings/inner.js @@ -14,6 +14,7 @@ define([ '/api/config', '/common/make-backup.js', '/common/common-feedback.js', + '/common/common-constants.js', '/common/jscolor.js', '/bower_components/file-saver/FileSaver.min.js', @@ -35,7 +36,8 @@ define([ AppConfig, ApiConfig, Backup, - Feedback + Feedback, + Constants ) { var saveAs = window.saveAs; var APP = window.APP = {}; @@ -72,7 +74,8 @@ define([ 'cp-settings-thumbnails', 'cp-settings-drive-backup', 'cp-settings-drive-import-local', - 'cp-settings-trim-history' + 'cp-settings-trim-history', + 'cp-settings-redirect', //'cp-settings-drive-reset' ], 'cursor': [ // Msg.settings_cat_cursor @@ -841,6 +844,49 @@ define([ return $div; }; + Messages.settings_driveRedirectTitle = "DRIVE REDIRECT TITLE"; // XXX redirect + Messages.settings_driveRedirectHint = "DRIVE REDIRECT HINT"; // XXX redirect + Messages.settings_driveRedirect = "DRIVE REDIRECT"; // XXX redirect + + create['redirect'] = function () { + if (!common.isLoggedIn()) { return; } + var $div = $('