Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Add support to customize UI components rendering using module API #10382

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/customisations/helpers/UIComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,23 @@
limitations under the License.
*/

import {
ShouldShowUIComponentOps,
UIComponentLifecycle,
} from "@matrix-org/react-sdk-module-api/lib/lifecycles/UIComponentLifecycle";

Check failure on line 20 in src/customisations/helpers/UIComponents.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Cannot find module '@matrix-org/react-sdk-module-api/lib/lifecycles/UIComponentLifecycle' or its corresponding type declarations.

import { UIComponent } from "../../settings/UIFeature";
import { ComponentVisibilityCustomisations } from "../ComponentVisibility";
import { ModuleRunner } from "../../modules/ModuleRunner";

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);
approved = opts.shouldShowComponent;
}
return approved ?? true;
}
4 changes: 4 additions & 0 deletions src/modules/ProxiedModuleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Loading