Be more positive with setting labels

Fixes https://github.com/vector-im/riot-web/issues/6435

This is done through an on-the-fly inverter for the settings. All the settings changed are boolean values, so this should be more than safe to just let happen throughout the SettingsStore. Typically a change like this would be done in the individual handlers (similar to how setting names are remapped to different properties or even different storage locations on the fly), however doing that for this many settings would be a huge nightmare and involve changing *all* the layers. By putting a global "invert this" flag on the setting, we can get away with doing the inversion as the last possible step during a read (or write).

To speed up calculations of the default values, we cache all the inverted values into a lookup table similar to how we represent the defaults already. Without this, the DefaultHandler would need to iterate the setting list and invert the values, slowing things down over time. We invert the value up front so we can keep the generic inversion logic without checking the level ahead of time. It is fully intended that a default value represents the new setting name, not the legacy name.

This commit also includes a debugger for settings because it was hard to visualize what the SettingsStore was doing during development. Some added information is included as it may be helpful for when someone has a problem with their settings and we need to debug it. Typically the debugger would be run in conjunction with `mxSendRageshake`: `mxSettingsStore.debugSetting('showJoinLeaves') && mxSendRageshake('Debugging showJoinLeaves setting')`.
This commit is contained in:
Travis Ralston 2019-01-24 20:57:40 -07:00
parent c5deeeaceb
commit cb6f415a05
15 changed files with 255 additions and 96 deletions

View file

@ -77,6 +77,15 @@ export const SETTINGS = {
// // 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_pinning": {
isFeature: true,
@ -116,40 +125,46 @@ export const SETTINGS = {
supportedLevels: LEVELS_FEATURE,
default: false,
},
"MessageComposerInput.dontSuggestEmoji": {
"MessageComposerInput.suggestEmoji": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
displayName: _td('Disable Emoji suggestions while typing'),
default: false,
displayName: _td('Enable Emoji suggestions while typing'),
default: true,
invertedSettingName: 'MessageComposerInput.dontSuggestEmoji',
},
"useCompactLayout": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
displayName: _td('Use compact timeline layout'),
default: false,
},
"hideRedactions": {
"showRedactions": {
supportedLevels: LEVELS_ROOM_SETTINGS_WITH_ROOM,
displayName: _td('Hide removed messages'),
default: false,
displayName: _td('Show a placeholder for removed messages'),
default: true,
invertedSettingName: 'hideRedactions',
},
"hideJoinLeaves": {
"showJoinLeaves": {
supportedLevels: LEVELS_ROOM_SETTINGS_WITH_ROOM,
displayName: _td('Hide join/leave messages (invites/kicks/bans unaffected)'),
default: false,
displayName: _td('Show join/leave messages (invites/kicks/bans unaffected)'),
default: true,
invertedSettingName: 'hideJoinLeaves',
},
"hideAvatarChanges": {
"showAvatarChanges": {
supportedLevels: LEVELS_ROOM_SETTINGS_WITH_ROOM,
displayName: _td('Hide avatar changes'),
default: false,
displayName: _td('Show avatar changes'),
default: true,
invertedSettingName: 'hideAvatarChanges',
},
"hideDisplaynameChanges": {
"showDisplaynameChanges": {
supportedLevels: LEVELS_ROOM_SETTINGS_WITH_ROOM,
displayName: _td('Hide display name changes'),
default: false,
displayName: _td('Show display name changes'),
default: true,
invertedSettingName: 'hideDisplaynameChanges',
},
"hideReadReceipts": {
"showReadReceipts": {
supportedLevels: LEVELS_ROOM_SETTINGS,
displayName: _td('Hide read receipts'),
default: false,
displayName: _td('Show read receipts'),
default: true,
invertedSettingName: 'hideReadReceipts',
},
"showTwelveHourTimestamps": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
@ -181,15 +196,17 @@ export const SETTINGS = {
displayName: _td('Enable automatic language detection for syntax highlighting'),
default: false,
},
"Pill.shouldHidePillAvatar": {
"Pill.shouldShowPillAvatar": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
displayName: _td('Hide avatars in user and room mentions'),
default: false,
displayName: _td('Show avatars in user and room mentions'),
default: true,
invertedSettingName: 'Pill.shouldHidePillAvatar',
},
"TextualBody.disableBigEmoji": {
"TextualBody.enableBigEmoji": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
displayName: _td('Disable big emoji in chat'),
default: false,
displayName: _td('Enable big emoji in chat'),
default: true,
invertedSettingName: 'TextualBody.disableBigEmoji',
},
"MessageComposerInput.isRichTextEnabled": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
@ -199,10 +216,11 @@ export const SETTINGS = {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
default: false,
},
"dontSendTypingNotifications": {
"sendTypingNotifications": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
displayName: _td("Don't send typing notifications"),
default: false,
displayName: _td("Send typing notifications"),
default: true,
invertedSettingName: 'dontSendTypingNotifications',
},
"MessageComposerInput.autoReplaceEmoji": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
@ -214,19 +232,21 @@ export const SETTINGS = {
displayName: _td('Mirror local video feed'),
default: false,
},
"TagPanel.disableTagPanel": {
"TagPanel.enableTagPanel": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
displayName: _td('Disable Community Filter Panel'),
default: false,
displayName: _td('Enable Community Filter Panel'),
default: true,
invertedSettingName: 'TagPanel.disableTagPanel',
},
"theme": {
supportedLevels: ['config'],
default: "dharma",
},
"webRtcForceTURN": {
"webRtcForcePeerToPeer": {
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
displayName: _td('Disable Peer-to-Peer for 1:1 calls'),
default: false,
default: true,
invertedSettingName: 'webRtcForceTURN',
},
"webrtc_audiooutput": {
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,