diff --git a/src/IConfigOptions.ts b/src/IConfigOptions.ts index 2df5e7fca1f..487da16e172 100644 --- a/src/IConfigOptions.ts +++ b/src/IConfigOptions.ts @@ -207,6 +207,12 @@ export interface IConfigOptions { client_id: string; } >; + + custom_power_level_roles?: { + [level: string]: { + [lang: string]: string; + }; + }; } export interface ISsoRedirectOptions { diff --git a/src/Roles.ts b/src/Roles.ts index aa6a369081b..bd84886f2c6 100644 --- a/src/Roles.ts +++ b/src/Roles.ts @@ -14,9 +14,30 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { _t } from "./languageHandler"; +import { safeSet } from "matrix-js-sdk/src/utils"; + +import SdkConfig from "./SdkConfig"; +import { _t, pickBestLanguage } from "./languageHandler"; export function levelRoleMap(usersDefault: number): Record { + const customPowerLevelRoles = SdkConfig.get().custom_power_level_roles; + if (customPowerLevelRoles) { + const mappings: Record = { + undefined: _t("Default"), + }; + + Object.entries(customPowerLevelRoles).forEach(([levelString, langs]) => { + const lang = pickBestLanguage(Object.keys(langs)); + if (lang && langs[lang]) { + safeSet(mappings, parseInt(levelString), langs[lang]); + } + }); + + if (Object.keys(mappings).length > 1) { + return mappings; + } + } + return { undefined: _t("Default"), 0: _t("Restricted"), diff --git a/src/components/views/elements/PowerSelector.tsx b/src/components/views/elements/PowerSelector.tsx index 6bfaf52f673..337f4448c43 100644 --- a/src/components/views/elements/PowerSelector.tsx +++ b/src/components/views/elements/PowerSelector.tsx @@ -22,6 +22,8 @@ import Field from "./Field"; import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts"; import { getKeyBindingsManager } from "../../../KeyBindingsManager"; import { objectHasDiff } from "../../../utils/objects"; +import SettingsStore from "../../../settings/SettingsStore"; +import { UIFeature } from "../../../settings/UIFeature"; const CUSTOM_VALUE = "SELECT_VALUE_CUSTOM"; @@ -173,7 +175,9 @@ export default class PowerSelector extends React.C text: Roles.textualPowerLevel(level, this.props.usersDefault), }; }); - options.push({ value: CUSTOM_VALUE, text: _t("Custom level") }); + if (SettingsStore.getValue(UIFeature.CustomPowerLevel)) { + options.push({ value: CUSTOM_VALUE, text: _t("Custom level") }); + } const optionsElements = options.map((op) => { return (