Roughly convert Settings to TS

This commit is contained in:
Travis Ralston 2020-07-28 12:02:02 -06:00
parent 1f7f40736b
commit 27b81d1e26

View file

@ -16,9 +16,9 @@ See the License for the specific language governing permissions and
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 {
AudioNotificationsEnabledController,
NotificationBodyEnabledController,
@ -28,75 +28,88 @@ import CustomStatusController from "./controllers/CustomStatusController";
import ThemeController from './controllers/ThemeController';
import PushToMatrixClientController from './controllers/PushToMatrixClientController';
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 SystemFontController from './controllers/SystemFontController';
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
const LEVELS_ROOM_SETTINGS = ['device', 'room-device', 'room-account', 'account', 'config'];
const LEVELS_ROOM_OR_ACCOUNT = ['room-account', 'account'];
const LEVELS_ROOM_SETTINGS_WITH_ROOM = ['device', 'room-device', 'room-account', 'account', 'config', 'room'];
const LEVELS_ACCOUNT_SETTINGS = ['device', 'account', 'config'];
const LEVELS_FEATURE = ['device', 'config'];
const LEVELS_DEVICE_ONLY_SETTINGS = ['device'];
const LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG = ['device', 'config'];
const LEVELS_ROOM_SETTINGS = [
SettingLevel.DEVICE,
SettingLevel.ROOM_DEVICE,
SettingLevel.ROOM_ACCOUNT,
SettingLevel.ACCOUNT,
SettingLevel.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 = {
// EXAMPLE SETTING:
// "my-setting": {
// // Must be set to true for features. Default is 'false'.
// isFeature: false,
//
// // Display names are strongly recommended for clarity.
// displayName: _td("Cool Name"),
//
// // Display name can also be an object for different levels.
// //displayName: {
// // "device": _td("Name for when the setting is used at 'device'"),
// // "room": _td("Name for when the setting is used at 'room'"),
// // "default": _td("The name for all other levels"),
// //}
//
// // The supported levels are required. Preferably, use the preset arrays
// // at the top of this file to define this rather than a custom array.
// supportedLevels: [
// // The order does not matter.
//
// "device", // Affects the current device only
// "room-device", // Affects the current room on the current device
// "room-account", // Affects the current room for the current account
// "account", // Affects the current account
// "room", // Affects the current room (controlled by room admins)
// "config", // Affects the current application
//
// // "default" is always supported and does not get listed here.
// ],
//
// // Required. Can be any data type. The value specified here should match
// // the data being stored (ie: if a boolean is used, the setting should
// // represent a boolean).
// default: {
// your: "value",
// },
//
// // Optional settings controller. See SettingsController for more information.
// 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",
// },
interface ISetting {
// Must be set to true for features. Default is 'false'.
isFeature?: boolean;
// Display names are strongly recommended for clarity.
// Display name can also be an object for different levels.
displayName?: string | {
// @ts-ignore - TS wants the key to be a string, but we know better
[level: SettingLevel]: string;
};
// The supported levels are required. Preferably, use the preset arrays
// at the top of this file to define this rather than a custom array.
supportedLevels?: SettingLevel[];
// Required. Can be any data type. The value specified here should match
// the data being stored (ie: if a boolean is used, the setting should
// represent a boolean).
default: any;
// Optional settings controller. See SettingsController for more information.
controller?: any; // TODO: [TS] Type
// 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?: boolean;
// 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?: string;
}
export const SETTINGS: {[setting: string]: ISetting} = {
"feature_new_spinner": {
isFeature: true,
displayName: _td("New spinner design"),
@ -153,11 +166,11 @@ export const SETTINGS = {
default: false,
},
"mjolnirRooms": {
supportedLevels: ['account'],
supportedLevels: [SettingLevel.ACCOUNT],
default: [],
},
"mjolnirPersonalRoom": {
supportedLevels: ['account'],
supportedLevels: [SettingLevel.ACCOUNT],
default: null,
},
"feature_bridge_state": {
@ -354,24 +367,24 @@ export const SETTINGS = {
},
"breadcrumb_rooms": {
// not really a setting
supportedLevels: ['account'],
supportedLevels: [SettingLevel.ACCOUNT],
default: [],
},
"recent_emoji": {
// not really a setting
supportedLevels: ['account'],
supportedLevels: [SettingLevel.ACCOUNT],
default: [],
},
"room_directory_servers": {
supportedLevels: ['account'],
supportedLevels: [SettingLevel.ACCOUNT],
default: [],
},
"integrationProvisioning": {
supportedLevels: ['account'],
supportedLevels: [SettingLevel.ACCOUNT],
default: true,
},
"allowedWidgets": {
supportedLevels: ['room-account'],
supportedLevels: [SettingLevel.ROOM_ACCOUNT],
default: {}, // none allowed
},
"analyticsOptIn": {
@ -398,7 +411,7 @@ export const SETTINGS = {
"blacklistUnverifiedDevices": {
// We specifically want to have room-device > device so that users may set a device default
// with a per-room override.
supportedLevels: ['room-device', 'device'],
supportedLevels: [SettingLevel.ROOM_DEVICE, SettingLevel.ROOM_ACCOUNT],
supportedLevelsAreOrdered: true,
displayName: {
"default": _td('Never send encrypted messages to unverified sessions from this session'),
@ -416,7 +429,7 @@ export const SETTINGS = {
default: true,
},
"urlPreviewsEnabled_e2ee": {
supportedLevels: ['room-device', 'room-account'],
supportedLevels: [SettingLevel.ROOM_DEVICE, SettingLevel.ROOM_ACCOUNT],
displayName: {
"room-account": _td("Enable URL previews for this room (only affects you)"),
},
@ -455,7 +468,7 @@ export const SETTINGS = {
default: false,
},
"PinnedEvents.isOpen": {
supportedLevels: ['room-device'],
supportedLevels: [SettingLevel.ROOM_DEVICE],
default: false,
},
"promptBeforeInviteUnknownUsers": {
@ -565,7 +578,8 @@ export const SETTINGS = {
"ircDisplayNameWidth": {
// We specifically want to have room-device > device so that users may set a device default
// with a per-room override.
supportedLevels: ['room-device', 'device'],
supportedLevels: [SettingLevel.ROOM_DEVICE, SettingLevel.DEVICE],
supportedLevelsAreOrdered: true,
displayName: _td("IRC display name width"),
default: 80,
},