This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 829
Fix some features not being configurable via features
#10276
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
369fb8d
Fix some features not being configurable via `features`
t3chguy 4665fe0
Update LabsUserSettingsTab.tsx
t3chguy e4743a2
Add mock
t3chguy 3f06358
Merge remote-tracking branch 'origin/t3chguy/fix-unstable-feature-fla…
t3chguy 30ce89c
Iterate based on PR feedback
t3chguy 9e170b2
Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into…
t3chguy 9455b35
Update test
t3chguy 8b85ce3
delint
t3chguy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2023 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { MatrixClient } from "matrix-js-sdk/src/client"; | ||
|
||
import SettingController from "./SettingController"; | ||
|
||
// Dev note: This whole class exists in the event someone logs out and back in - we want | ||
// to make sure the right MatrixClient is listening for changes. | ||
|
||
/** | ||
* Represents the base class for settings controllers which need access to a MatrixClient. | ||
* This class performs no logic and should be overridden. | ||
*/ | ||
export default abstract class MatrixClientBackedController extends SettingController { | ||
private static _matrixClient: MatrixClient; | ||
private static instances: MatrixClientBackedController[] = []; | ||
|
||
public static set matrixClient(client: MatrixClient) { | ||
const oldClient = MatrixClientBackedController._matrixClient; | ||
MatrixClientBackedController._matrixClient = client; | ||
|
||
for (const instance of MatrixClientBackedController.instances) { | ||
instance.initMatrixClient(oldClient, client); | ||
} | ||
} | ||
|
||
protected constructor() { | ||
super(); | ||
|
||
MatrixClientBackedController.instances.push(this); | ||
} | ||
|
||
public get client(): MatrixClient { | ||
return MatrixClientBackedController._matrixClient; | ||
} | ||
|
||
protected abstract initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient): void; | ||
} |
77 changes: 77 additions & 0 deletions
77
src/settings/controllers/ServerSupportUnstableFeatureController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
Copyright 2023 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { MatrixClient } from "matrix-js-sdk/src/matrix"; | ||
|
||
import { SettingLevel } from "../SettingLevel"; | ||
import MatrixClientBackedController from "./MatrixClientBackedController"; | ||
import { WatchManager } from "../WatchManager"; | ||
import SettingsStore from "../SettingsStore"; | ||
|
||
/** | ||
* Disables a given setting if the server unstable feature it requires is not supported | ||
* When a setting gets disabled or enabled from this controller it notifies the given WatchManager | ||
*/ | ||
export default class ServerSupportUnstableFeatureController extends MatrixClientBackedController { | ||
private enabled: boolean | undefined; | ||
|
||
public constructor( | ||
private readonly settingName: string, | ||
private readonly watchers: WatchManager, | ||
private readonly unstableFeatures: string[], | ||
private readonly forcedValue: any = false, | ||
) { | ||
super(); | ||
} | ||
|
||
public get disabled(): boolean { | ||
return !this.enabled; | ||
} | ||
|
||
public set disabled(v: boolean) { | ||
if (!v === this.enabled) return; | ||
this.enabled = !v; | ||
const level = SettingsStore.firstSupportedLevel(this.settingName); | ||
const settingValue = SettingsStore.getValue(this.settingName, null); | ||
this.watchers.notifyUpdate(this.settingName, null, level, settingValue); | ||
} | ||
|
||
protected async initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient): Promise<void> { | ||
this.disabled = true; | ||
let supported = true; | ||
for (const feature of this.unstableFeatures) { | ||
supported = await this.client.doesServerSupportUnstableFeature(feature); | ||
if (!supported) break; | ||
} | ||
this.disabled = !supported; | ||
} | ||
|
||
public getValueOverride( | ||
level: SettingLevel, | ||
roomId: string, | ||
calculatedValue: any, | ||
calculatedAtLevel: SettingLevel | null, | ||
): any { | ||
if (this.settingDisabled) { | ||
return this.forcedValue; | ||
} | ||
return null; // no override | ||
} | ||
|
||
public get settingDisabled(): boolean { | ||
return this.disabled; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we somehow watch for settings getting enabled?