Roughly convert Settings to TS

pull/21833/head
Travis Ralston 2020-07-28 12:02:02 -06:00
parent 1f7f40736b
commit 27b81d1e26
1 changed files with 90 additions and 76 deletions

View File

@ -16,9 +16,9 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import {MatrixClient} from 'matrix-js-sdk'; import { MatrixClient } from 'matrix-js-sdk/src/client';
import {_td} from '../languageHandler'; import { _td } from '../languageHandler';
import { import {
AudioNotificationsEnabledController, AudioNotificationsEnabledController,
NotificationBodyEnabledController, NotificationBodyEnabledController,
@ -28,75 +28,88 @@ import CustomStatusController from "./controllers/CustomStatusController";
import ThemeController from './controllers/ThemeController'; import ThemeController from './controllers/ThemeController';
import PushToMatrixClientController from './controllers/PushToMatrixClientController'; import PushToMatrixClientController from './controllers/PushToMatrixClientController';
import ReloadOnChangeController from "./controllers/ReloadOnChangeController"; import ReloadOnChangeController from "./controllers/ReloadOnChangeController";
import {RIGHT_PANEL_PHASES} from "../stores/RightPanelStorePhases"; import { RIGHT_PANEL_PHASES } from "../stores/RightPanelStorePhases";
import FontSizeController from './controllers/FontSizeController'; import FontSizeController from './controllers/FontSizeController';
import SystemFontController from './controllers/SystemFontController'; import SystemFontController from './controllers/SystemFontController';
import UseSystemFontController from './controllers/UseSystemFontController'; import UseSystemFontController from './controllers/UseSystemFontController';
import { SettingLevel } from "./SettingLevel";
// These are just a bunch of helper arrays to avoid copy/pasting a bunch of times // These are just a bunch of helper arrays to avoid copy/pasting a bunch of times
const LEVELS_ROOM_SETTINGS = ['device', 'room-device', 'room-account', 'account', 'config']; const LEVELS_ROOM_SETTINGS = [
const LEVELS_ROOM_OR_ACCOUNT = ['room-account', 'account']; SettingLevel.DEVICE,
const LEVELS_ROOM_SETTINGS_WITH_ROOM = ['device', 'room-device', 'room-account', 'account', 'config', 'room']; SettingLevel.ROOM_DEVICE,
const LEVELS_ACCOUNT_SETTINGS = ['device', 'account', 'config']; SettingLevel.ROOM_ACCOUNT,
const LEVELS_FEATURE = ['device', 'config']; SettingLevel.ACCOUNT,
const LEVELS_DEVICE_ONLY_SETTINGS = ['device']; SettingLevel.CONFIG,
const LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG = ['device', 'config']; ];
const LEVELS_ROOM_OR_ACCOUNT = [
SettingLevel.ROOM_ACCOUNT,
SettingLevel.ACCOUNT,
];
const LEVELS_ROOM_SETTINGS_WITH_ROOM = [
SettingLevel.DEVICE,
SettingLevel.ROOM_DEVICE,
SettingLevel.ROOM_ACCOUNT,
SettingLevel.ACCOUNT,
SettingLevel.CONFIG,
SettingLevel.ROOM,
];
const LEVELS_ACCOUNT_SETTINGS = [
SettingLevel.DEVICE,
SettingLevel.ACCOUNT,
SettingLevel.CONFIG,
];
const LEVELS_FEATURE = [
SettingLevel.DEVICE,
SettingLevel.CONFIG,
];
const LEVELS_DEVICE_ONLY_SETTINGS = [
SettingLevel.DEVICE,
];
const LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG = [
SettingLevel.DEVICE,
SettingLevel.CONFIG,
];
export const SETTINGS = { interface ISetting {
// EXAMPLE SETTING: // Must be set to true for features. Default is 'false'.
// "my-setting": { isFeature?: boolean;
// // Must be set to true for features. Default is 'false'.
// isFeature: false, // Display names are strongly recommended for clarity.
// // Display name can also be an object for different levels.
// // Display names are strongly recommended for clarity. displayName?: string | {
// displayName: _td("Cool Name"), // @ts-ignore - TS wants the key to be a string, but we know better
// [level: SettingLevel]: string;
// // Display name can also be an object for different levels. };
// //displayName: {
// // "device": _td("Name for when the setting is used at 'device'"), // The supported levels are required. Preferably, use the preset arrays
// // "room": _td("Name for when the setting is used at 'room'"), // at the top of this file to define this rather than a custom array.
// // "default": _td("The name for all other levels"), supportedLevels?: SettingLevel[];
// //}
// // Required. Can be any data type. The value specified here should match
// // The supported levels are required. Preferably, use the preset arrays // the data being stored (ie: if a boolean is used, the setting should
// // at the top of this file to define this rather than a custom array. // represent a boolean).
// supportedLevels: [ default: any;
// // The order does not matter.
// // Optional settings controller. See SettingsController for more information.
// "device", // Affects the current device only controller?: any; // TODO: [TS] Type
// "room-device", // Affects the current room on the current device
// "room-account", // Affects the current room for the current account // Optional flag to make supportedLevels be respected as the order to handle
// "account", // Affects the current account // settings. The first element is treated as "most preferred". The "default"
// "room", // Affects the current room (controlled by room admins) // level is always appended to the end.
// "config", // Affects the current application supportedLevelsAreOrdered?: boolean;
//
// // "default" is always supported and does not get listed here. // Optional value to invert a boolean setting's value. The string given will
// ], // be read as the setting's ID instead of the one provided as the key for the
// // setting definition. By setting this, the returned value will automatically
// // Required. Can be any data type. The value specified here should match // be inverted, except for when the default value is returned. Inversion will
// // the data being stored (ie: if a boolean is used, the setting should // occur after the controller is asked for an override. This should be used by
// // represent a boolean). // historical settings which we don't want existing user's values be wiped. Do
// default: { // not use this for new settings.
// your: "value", invertedSettingName?: string;
// }, }
//
// // Optional settings controller. See SettingsController for more information. export const SETTINGS: {[setting: string]: ISetting} = {
// controller: new MySettingController(),
//
// // Optional flag to make supportedLevels be respected as the order to handle
// // settings. The first element is treated as "most preferred". The "default"
// // level is always appended to the end.
// supportedLevelsAreOrdered: false,
//
// // Optional value to invert a boolean setting's value. The string given will
// // be read as the setting's ID instead of the one provided as the key for the
// // setting definition. By setting this, the returned value will automatically
// // be inverted, except for when the default value is returned. Inversion will
// // occur after the controller is asked for an override. This should be used by
// // historical settings which we don't want existing user's values be wiped. Do
// // not use this for new settings.
// invertedSettingName: "my-negative-setting",
// },
"feature_new_spinner": { "feature_new_spinner": {
isFeature: true, isFeature: true,
displayName: _td("New spinner design"), displayName: _td("New spinner design"),
@ -153,11 +166,11 @@ export const SETTINGS = {
default: false, default: false,
}, },
"mjolnirRooms": { "mjolnirRooms": {
supportedLevels: ['account'], supportedLevels: [SettingLevel.ACCOUNT],
default: [], default: [],
}, },
"mjolnirPersonalRoom": { "mjolnirPersonalRoom": {
supportedLevels: ['account'], supportedLevels: [SettingLevel.ACCOUNT],
default: null, default: null,
}, },
"feature_bridge_state": { "feature_bridge_state": {
@ -354,24 +367,24 @@ export const SETTINGS = {
}, },
"breadcrumb_rooms": { "breadcrumb_rooms": {
// not really a setting // not really a setting
supportedLevels: ['account'], supportedLevels: [SettingLevel.ACCOUNT],
default: [], default: [],
}, },
"recent_emoji": { "recent_emoji": {
// not really a setting // not really a setting
supportedLevels: ['account'], supportedLevels: [SettingLevel.ACCOUNT],
default: [], default: [],
}, },
"room_directory_servers": { "room_directory_servers": {
supportedLevels: ['account'], supportedLevels: [SettingLevel.ACCOUNT],
default: [], default: [],
}, },
"integrationProvisioning": { "integrationProvisioning": {
supportedLevels: ['account'], supportedLevels: [SettingLevel.ACCOUNT],
default: true, default: true,
}, },
"allowedWidgets": { "allowedWidgets": {
supportedLevels: ['room-account'], supportedLevels: [SettingLevel.ROOM_ACCOUNT],
default: {}, // none allowed default: {}, // none allowed
}, },
"analyticsOptIn": { "analyticsOptIn": {
@ -398,7 +411,7 @@ export const SETTINGS = {
"blacklistUnverifiedDevices": { "blacklistUnverifiedDevices": {
// We specifically want to have room-device > device so that users may set a device default // We specifically want to have room-device > device so that users may set a device default
// with a per-room override. // with a per-room override.
supportedLevels: ['room-device', 'device'], supportedLevels: [SettingLevel.ROOM_DEVICE, SettingLevel.ROOM_ACCOUNT],
supportedLevelsAreOrdered: true, supportedLevelsAreOrdered: true,
displayName: { displayName: {
"default": _td('Never send encrypted messages to unverified sessions from this session'), "default": _td('Never send encrypted messages to unverified sessions from this session'),
@ -416,7 +429,7 @@ export const SETTINGS = {
default: true, default: true,
}, },
"urlPreviewsEnabled_e2ee": { "urlPreviewsEnabled_e2ee": {
supportedLevels: ['room-device', 'room-account'], supportedLevels: [SettingLevel.ROOM_DEVICE, SettingLevel.ROOM_ACCOUNT],
displayName: { displayName: {
"room-account": _td("Enable URL previews for this room (only affects you)"), "room-account": _td("Enable URL previews for this room (only affects you)"),
}, },
@ -455,7 +468,7 @@ export const SETTINGS = {
default: false, default: false,
}, },
"PinnedEvents.isOpen": { "PinnedEvents.isOpen": {
supportedLevels: ['room-device'], supportedLevels: [SettingLevel.ROOM_DEVICE],
default: false, default: false,
}, },
"promptBeforeInviteUnknownUsers": { "promptBeforeInviteUnknownUsers": {
@ -565,7 +578,8 @@ export const SETTINGS = {
"ircDisplayNameWidth": { "ircDisplayNameWidth": {
// We specifically want to have room-device > device so that users may set a device default // We specifically want to have room-device > device so that users may set a device default
// with a per-room override. // with a per-room override.
supportedLevels: ['room-device', 'device'], supportedLevels: [SettingLevel.ROOM_DEVICE, SettingLevel.DEVICE],
supportedLevelsAreOrdered: true,
displayName: _td("IRC display name width"), displayName: _td("IRC display name width"),
default: 80, default: 80,
}, },