Cleanup tasks in the Settings code (#12125)
* inline call to `SettingsStore.isEnabled` * Remove confusing `SettingsStore.isEnabled` This was basically the same as `SettingsStore.canSetValue` only more confusing, so let's get rid of it. * Add `configDisablesSetting` value for Settings The current magic where this only works for features (but not beta features!) is, well, magical. And I need more flexibility here. * Remove redundant levels constant `LEVELS_FEATURE` I don't know if this was ever intended to have different semantics to `LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG`, but if it was, those semantics shuold have been written down. They now seem to be used entirely interchangably.
This commit is contained in:
parent
c2b5c1fe96
commit
65d6bfe6e9
7 changed files with 84 additions and 60 deletions
|
@ -40,8 +40,6 @@ interface IProps {
|
|||
|
||||
interface IState {
|
||||
value: boolean;
|
||||
/** true if `SettingsStore.isEnabled` returned false. */
|
||||
disabled: boolean;
|
||||
}
|
||||
|
||||
export default class SettingsFlag extends React.Component<IProps, IState> {
|
||||
|
@ -52,7 +50,6 @@ export default class SettingsFlag extends React.Component<IProps, IState> {
|
|||
|
||||
this.state = {
|
||||
value: this.getSettingValue(),
|
||||
disabled: this.isSettingDisabled(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -72,15 +69,9 @@ export default class SettingsFlag extends React.Component<IProps, IState> {
|
|||
this.props.isExplicit,
|
||||
);
|
||||
}
|
||||
|
||||
private isSettingDisabled(): boolean {
|
||||
return !SettingsStore.isEnabled(this.props.name);
|
||||
}
|
||||
|
||||
private onSettingChange = (): void => {
|
||||
this.setState({
|
||||
value: this.getSettingValue(),
|
||||
disabled: this.isSettingDisabled(),
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -104,14 +95,13 @@ export default class SettingsFlag extends React.Component<IProps, IState> {
|
|||
};
|
||||
|
||||
public render(): React.ReactNode {
|
||||
const canChange = SettingsStore.canSetValue(this.props.name, this.props.roomId ?? null, this.props.level);
|
||||
const disabled = !SettingsStore.canSetValue(this.props.name, this.props.roomId ?? null, this.props.level);
|
||||
|
||||
if (!canChange && this.props.hideIfCannotSet) return null;
|
||||
if (disabled && this.props.hideIfCannotSet) return null;
|
||||
|
||||
const label = this.props.label ?? SettingsStore.getDisplayName(this.props.name, this.props.level);
|
||||
const description = SettingsStore.getDescription(this.props.name);
|
||||
const shouldWarn = SettingsStore.shouldHaveWarning(this.props.name);
|
||||
const disabled = this.state.disabled || !canChange;
|
||||
|
||||
if (this.props.useCheckbox) {
|
||||
return (
|
||||
|
|
|
@ -62,7 +62,7 @@ export default class CryptographyPanel extends React.Component<IProps, IState> {
|
|||
}
|
||||
|
||||
let noSendUnverifiedSetting: JSX.Element | undefined;
|
||||
if (SettingsStore.isEnabled("blacklistUnverifiedDevices")) {
|
||||
if (SettingsStore.canSetValue("blacklistUnverifiedDevices", null, SettingLevel.DEVICE)) {
|
||||
noSendUnverifiedSetting = (
|
||||
<SettingsFlag
|
||||
name="blacklistUnverifiedDevices"
|
||||
|
|
|
@ -38,5 +38,5 @@ const E2eAdvancedPanel: React.FC = () => {
|
|||
export default E2eAdvancedPanel;
|
||||
|
||||
export function isE2eAdvancedPanelPossible(): boolean {
|
||||
return SettingsStore.isEnabled(SETTING_MANUALLY_VERIFY_ALL_SESSIONS);
|
||||
return SettingsStore.canSetValue(SETTING_MANUALLY_VERIFY_ALL_SESSIONS, null, SettingLevel.DEVICE);
|
||||
}
|
||||
|
|
|
@ -427,7 +427,10 @@ export default class SecurityRoomSettingsTab extends React.Component<IProps, ISt
|
|||
const canEnableEncryption = !isEncrypted && !isEncryptionForceDisabled && hasEncryptionPermission;
|
||||
|
||||
let encryptionSettings: JSX.Element | undefined;
|
||||
if (isEncrypted && SettingsStore.isEnabled("blacklistUnverifiedDevices")) {
|
||||
if (
|
||||
isEncrypted &&
|
||||
SettingsStore.canSetValue("blacklistUnverifiedDevices", this.props.room.roomId, SettingLevel.ROOM_DEVICE)
|
||||
) {
|
||||
encryptionSettings = (
|
||||
<SettingsFlag
|
||||
name="blacklistUnverifiedDevices"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue