From d47328a8fd45cfc513b27ce86224408773afb06b Mon Sep 17 00:00:00 2001 From: Mikhail Aheichyk Date: Wed, 15 Mar 2023 11:31:07 +0300 Subject: [PATCH 1/2] Add support to customize UI components rendering using module API Signed-off-by: Mikhail Aheichyk --- src/customisations/helpers/UIComponents.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/customisations/helpers/UIComponents.ts b/src/customisations/helpers/UIComponents.ts index 11b8a409695..dab88fa1f86 100644 --- a/src/customisations/helpers/UIComponents.ts +++ b/src/customisations/helpers/UIComponents.ts @@ -14,9 +14,29 @@ See the License for the specific language governing permissions and limitations under the License. */ +import { + ShouldShowUiComponentOps, + UiComponentLifecycle, +} from "@matrix-org/react-sdk-module-api/lib/lifecycles/UiComponentLifecycle"; + import { UIComponent } from "../../settings/UIFeature"; import { ComponentVisibilityCustomisations } from "../ComponentVisibility"; +import { ModuleRunner } from "../../modules/ModuleRunner"; +import { MatrixClientPeg } from "../../MatrixClientPeg"; export function shouldShowComponent(component: UIComponent): boolean { - return ComponentVisibilityCustomisations.shouldShowComponent?.(component) ?? true; + let approved: boolean | undefined; + if (ComponentVisibilityCustomisations.shouldShowComponent) { + approved = ComponentVisibilityCustomisations.shouldShowComponent(component); + } else { + const opts: ShouldShowUiComponentOps = { shouldShowComponent: undefined }; + ModuleRunner.instance.invoke( + UiComponentLifecycle.ShouldShowComponent, + opts, + component, + MatrixClientPeg.get().getUserId(), + ); + approved = opts.shouldShowComponent; + } + return approved ?? true; } From e3fd6240f6ae28768435abcd28a0266ab9ce4295 Mon Sep 17 00:00:00 2001 From: Mikhail Aheichyk Date: Fri, 21 Jul 2023 10:05:05 +0300 Subject: [PATCH 2/2] Update to fit into changes from module branch Signed-off-by: Mikhail Aheichyk --- src/customisations/helpers/UIComponents.ts | 16 +++++----------- src/modules/ProxiedModuleApi.ts | 4 ++++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/customisations/helpers/UIComponents.ts b/src/customisations/helpers/UIComponents.ts index dab88fa1f86..e6cb65caac4 100644 --- a/src/customisations/helpers/UIComponents.ts +++ b/src/customisations/helpers/UIComponents.ts @@ -15,27 +15,21 @@ limitations under the License. */ import { - ShouldShowUiComponentOps, - UiComponentLifecycle, -} from "@matrix-org/react-sdk-module-api/lib/lifecycles/UiComponentLifecycle"; + ShouldShowUIComponentOps, + UIComponentLifecycle, +} from "@matrix-org/react-sdk-module-api/lib/lifecycles/UIComponentLifecycle"; import { UIComponent } from "../../settings/UIFeature"; import { ComponentVisibilityCustomisations } from "../ComponentVisibility"; import { ModuleRunner } from "../../modules/ModuleRunner"; -import { MatrixClientPeg } from "../../MatrixClientPeg"; export function shouldShowComponent(component: UIComponent): boolean { let approved: boolean | undefined; if (ComponentVisibilityCustomisations.shouldShowComponent) { approved = ComponentVisibilityCustomisations.shouldShowComponent(component); } else { - const opts: ShouldShowUiComponentOps = { shouldShowComponent: undefined }; - ModuleRunner.instance.invoke( - UiComponentLifecycle.ShouldShowComponent, - opts, - component, - MatrixClientPeg.get().getUserId(), - ); + const opts: ShouldShowUIComponentOps = { shouldShowComponent: undefined }; + ModuleRunner.instance.invoke(UIComponentLifecycle.ShouldShowComponent, opts, component); approved = opts.shouldShowComponent; } return approved ?? true; diff --git a/src/modules/ProxiedModuleApi.ts b/src/modules/ProxiedModuleApi.ts index 0c2b75e71f7..d9bd88b1793 100644 --- a/src/modules/ProxiedModuleApi.ts +++ b/src/modules/ProxiedModuleApi.ts @@ -216,4 +216,8 @@ export class ProxiedModuleApi implements ModuleApi { if (!maybeObj || !(typeof maybeObj === "object")) return undefined; return maybeObj[key]; } + + public getUserId(): string | undefined { + return MatrixClientPeg.get()?.getUserId() ?? undefined; + } }