From 52fae066530cf4d21ea93f266a0e03461afca594 Mon Sep 17 00:00:00 2001 From: Estelle Comment Date: Mon, 27 Jun 2022 17:14:21 +0200 Subject: [PATCH 1/2] Use componentVisibility to disable createSpaces --- customisations.json | 3 +- .../TchapComponentVisibility.ts | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/customisations/TchapComponentVisibility.ts diff --git a/customisations.json b/customisations.json index 6d8c5f0081..430a224244 100644 --- a/customisations.json +++ b/customisations.json @@ -2,5 +2,6 @@ "src/@types/tchap.ts": "src/@types/tchap.ts", "src/components/views/dialogs/CreateRoomDialog.tsx": "src/components/views/dialogs/TchapCreateRoomDialog.tsx", "src/components/views/elements/TchapRoomTypeSelector.tsx": "src/components/views/elements/TchapRoomTypeSelector.tsx", - "src/components/views/dialogs/ServerPickerDialog.tsx": "src/components/views/dialogs/TchapServerPickerDialog.tsx" + "src/components/views/dialogs/ServerPickerDialog.tsx": "src/components/views/dialogs/TchapServerPickerDialog.tsx", + "src/customisations/ComponentVisibility.ts": "src/customisations/TchapComponentVisibility.ts" } diff --git a/src/customisations/TchapComponentVisibility.ts b/src/customisations/TchapComponentVisibility.ts new file mode 100644 index 0000000000..0497801f30 --- /dev/null +++ b/src/customisations/TchapComponentVisibility.ts @@ -0,0 +1,46 @@ +/* +Copyright 2022 - DINUM - MIT license + +File copied from ComponentVisibility.ts in matrix-react-sdk v3.46.0 +*/ + + +// Dev note: this customisation point is heavily inspired by UIFeature flags, though +// with an intention of being used for more complex switching on whether or not a feature +// should be shown. + +// Populate this class with the details of your customisations when copying it. + +import { UIComponent } from "matrix-react-sdk/src/settings/UIFeature"; + +/** + * Determines whether or not the active MatrixClient user should be able to use + * the given UI component. If shown, the user might still not be able to use the + * component depending on their contextual permissions. For example, invite options + * might be shown to the user but they won't have permission to invite users to + * the current room: the button will appear disabled. + * @param {UIComponent} component The component to check visibility for. + * @returns {boolean} True (default) if the user is able to see the component, false + * otherwise. + */ +function shouldShowComponent(component: UIComponent): boolean { + if (component === UIComponent.CreateSpaces) { + return false; + } + return true; // default to visible +} + +// This interface summarises all available customisation points and also marks +// them all as optional. This allows customisers to only define and export the +// customisations they need while still maintaining type safety. +export interface IComponentVisibilityCustomisations { + shouldShowComponent?: typeof shouldShowComponent; +} + +// A real customisation module will define and export one or more of the +// customisation points that make up the interface above. +export const ComponentVisibilityCustomisations: IComponentVisibilityCustomisations = { + // while we don't specify the functions here, their defaults are described + // in their pseudo-implementations above. + shouldShowComponent +}; From d24c732ae8a4efc566d597dc13b9ae47c1a66279 Mon Sep 17 00:00:00 2001 From: Estelle Comment Date: Thu, 30 Jun 2022 14:26:48 +0200 Subject: [PATCH 2/2] Fix lint errore --- src/customisations/TchapComponentVisibility.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/customisations/TchapComponentVisibility.ts b/src/customisations/TchapComponentVisibility.ts index 0497801f30..2f1a3c93cd 100644 --- a/src/customisations/TchapComponentVisibility.ts +++ b/src/customisations/TchapComponentVisibility.ts @@ -4,7 +4,6 @@ Copyright 2022 - DINUM - MIT license File copied from ComponentVisibility.ts in matrix-react-sdk v3.46.0 */ - // Dev note: this customisation point is heavily inspired by UIFeature flags, though // with an intention of being used for more complex switching on whether or not a feature // should be shown. @@ -42,5 +41,5 @@ export interface IComponentVisibilityCustomisations { export const ComponentVisibilityCustomisations: IComponentVisibilityCustomisations = { // while we don't specify the functions here, their defaults are described // in their pseudo-implementations above. - shouldShowComponent + shouldShowComponent, };