2019-01-18 13:09:17 -07:00
|
|
|
/*
|
|
|
|
|
Copyright 2019 New Vector Ltd
|
2019-10-31 13:19:54 -06:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2019-01-18 13:09:17 -07:00
|
|
|
|
|
|
|
|
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 React from "react";
|
2021-10-22 17:23:32 -05:00
|
|
|
|
2021-06-29 13:11:58 +01:00
|
|
|
import TabbedView, { Tab } from "../../structures/TabbedView";
|
|
|
|
|
import { _t, _td } from "../../../languageHandler";
|
2019-02-22 10:47:18 -07:00
|
|
|
import GeneralUserSettingsTab from "../settings/tabs/user/GeneralUserSettingsTab";
|
2021-06-18 12:44:15 +01:00
|
|
|
import SettingsStore, { CallbackFn } from "../../../settings/SettingsStore";
|
2023-10-13 14:24:00 +01:00
|
|
|
import LabsUserSettingsTab, { showLabsFlags } from "../settings/tabs/user/LabsUserSettingsTab";
|
2020-04-16 20:26:04 +01:00
|
|
|
import AppearanceUserSettingsTab from "../settings/tabs/user/AppearanceUserSettingsTab";
|
2019-02-22 10:47:18 -07:00
|
|
|
import SecurityUserSettingsTab from "../settings/tabs/user/SecurityUserSettingsTab";
|
|
|
|
|
import NotificationUserSettingsTab from "../settings/tabs/user/NotificationUserSettingsTab";
|
|
|
|
|
import PreferencesUserSettingsTab from "../settings/tabs/user/PreferencesUserSettingsTab";
|
|
|
|
|
import VoiceUserSettingsTab from "../settings/tabs/user/VoiceUserSettingsTab";
|
|
|
|
|
import HelpUserSettingsTab from "../settings/tabs/user/HelpUserSettingsTab";
|
2019-10-31 13:19:54 -06:00
|
|
|
import MjolnirUserSettingsTab from "../settings/tabs/user/MjolnirUserSettingsTab";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { UIFeature } from "../../../settings/UIFeature";
|
2021-07-03 10:44:03 +02:00
|
|
|
import BaseDialog from "./BaseDialog";
|
2021-11-11 13:07:41 +00:00
|
|
|
import SidebarUserSettingsTab from "../settings/tabs/user/SidebarUserSettingsTab";
|
2022-01-17 12:53:10 +01:00
|
|
|
import KeyboardUserSettingsTab from "../settings/tabs/user/KeyboardUserSettingsTab";
|
2022-08-08 15:51:00 +02:00
|
|
|
import SessionManagerTab from "../settings/tabs/user/SessionManagerTab";
|
2022-03-24 16:42:53 -06:00
|
|
|
import { UserTab } from "./UserTab";
|
2023-03-10 14:55:06 +00:00
|
|
|
import { NonEmptyArray } from "../../../@types/common";
|
2023-10-16 12:03:25 +13:00
|
|
|
import { SDKContext, SdkContextClass } from "../../../contexts/SDKContext";
|
2021-06-14 23:42:36 +01:00
|
|
|
|
2023-02-28 10:31:48 +00:00
|
|
|
interface IProps {
|
2021-12-17 09:26:32 +00:00
|
|
|
initialTabId?: UserTab;
|
2023-10-16 12:03:25 +13:00
|
|
|
sdkContext: SdkContextClass;
|
2023-02-28 10:31:48 +00:00
|
|
|
onFinished(): void;
|
2021-06-14 23:42:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
|
mjolnirEnabled: boolean;
|
|
|
|
|
}
|
2020-06-08 08:20:15 -06:00
|
|
|
|
2021-06-14 23:42:36 +01:00
|
|
|
export default class UserSettingsDialog extends React.Component<IProps, IState> {
|
2022-08-08 15:51:00 +02:00
|
|
|
private settingsWatchers: string[] = [];
|
2019-01-18 13:09:17 -07:00
|
|
|
|
2023-02-13 11:39:16 +00:00
|
|
|
public constructor(props: IProps) {
|
2021-06-14 23:42:36 +01:00
|
|
|
super(props);
|
2019-10-31 13:19:54 -06:00
|
|
|
|
|
|
|
|
this.state = {
|
2020-08-17 13:12:18 -06:00
|
|
|
mjolnirEnabled: SettingsStore.getValue("feature_mjolnir"),
|
2019-10-31 16:27:45 -06:00
|
|
|
};
|
2019-10-31 13:19:54 -06:00
|
|
|
}
|
|
|
|
|
|
2021-06-14 23:42:36 +01:00
|
|
|
public componentDidMount(): void {
|
2023-05-26 13:58:28 +12:00
|
|
|
this.settingsWatchers = [SettingsStore.watchSetting("feature_mjolnir", null, this.mjolnirChanged)];
|
2019-10-31 13:19:54 -06:00
|
|
|
}
|
|
|
|
|
|
2021-06-14 23:42:36 +01:00
|
|
|
public componentWillUnmount(): void {
|
2022-08-08 15:51:00 +02:00
|
|
|
this.settingsWatchers.forEach((watcherRef) => SettingsStore.unwatchSetting(watcherRef));
|
2019-10-31 13:19:54 -06:00
|
|
|
}
|
|
|
|
|
|
2021-06-18 12:44:15 +01:00
|
|
|
private mjolnirChanged: CallbackFn = (settingName, roomId, atLevel, newValue) => {
|
2019-10-31 13:19:54 -06:00
|
|
|
// We can cheat because we know what levels a feature is tracked at, and how it is tracked
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ mjolnirEnabled: newValue });
|
|
|
|
|
};
|
2019-10-31 13:19:54 -06:00
|
|
|
|
2023-04-27 12:55:29 +01:00
|
|
|
private getTabs(): NonEmptyArray<Tab<UserTab>> {
|
|
|
|
|
const tabs: Tab<UserTab>[] = [];
|
2019-01-23 17:32:27 -07:00
|
|
|
|
|
|
|
|
tabs.push(
|
|
|
|
|
new Tab(
|
2021-06-18 12:44:15 +01:00
|
|
|
UserTab.General,
|
2023-09-26 13:04:17 +01:00
|
|
|
_td("common|general"),
|
2019-01-23 17:32:27 -07:00
|
|
|
"mx_UserSettingsDialog_settingsIcon",
|
2019-07-11 14:54:49 -06:00
|
|
|
<GeneralUserSettingsTab closeSettingsFn={this.props.onFinished} />,
|
2022-02-10 14:38:31 +00:00
|
|
|
"UserSettingsGeneral",
|
2022-12-12 12:24:14 +01:00
|
|
|
),
|
2019-01-23 17:32:27 -07:00
|
|
|
);
|
2020-04-14 16:20:41 +01:00
|
|
|
tabs.push(
|
|
|
|
|
new Tab(
|
2021-06-18 12:44:15 +01:00
|
|
|
UserTab.Appearance,
|
2023-08-23 10:25:33 +01:00
|
|
|
_td("common|appearance"),
|
2020-04-23 12:20:10 +01:00
|
|
|
"mx_UserSettingsDialog_appearanceIcon",
|
2020-04-16 20:26:04 +01:00
|
|
|
<AppearanceUserSettingsTab />,
|
2022-02-10 14:38:31 +00:00
|
|
|
"UserSettingsAppearance",
|
2022-12-12 12:24:14 +01:00
|
|
|
),
|
2020-04-14 16:20:41 +01:00
|
|
|
);
|
2019-01-23 17:32:27 -07:00
|
|
|
tabs.push(
|
|
|
|
|
new Tab(
|
2021-06-18 12:44:15 +01:00
|
|
|
UserTab.Notifications,
|
2023-09-25 18:12:41 +01:00
|
|
|
_td("notifications|enable_prompt_toast_title"),
|
2019-01-23 17:32:27 -07:00
|
|
|
"mx_UserSettingsDialog_bellIcon",
|
2019-02-22 10:47:18 -07:00
|
|
|
<NotificationUserSettingsTab />,
|
2022-02-10 14:38:31 +00:00
|
|
|
"UserSettingsNotifications",
|
2022-12-12 12:24:14 +01:00
|
|
|
),
|
2019-01-23 17:32:27 -07:00
|
|
|
);
|
|
|
|
|
tabs.push(
|
|
|
|
|
new Tab(
|
2021-06-18 12:44:15 +01:00
|
|
|
UserTab.Preferences,
|
2023-08-31 11:22:10 +01:00
|
|
|
_td("common|preferences"),
|
2019-01-23 17:32:27 -07:00
|
|
|
"mx_UserSettingsDialog_preferencesIcon",
|
2021-08-04 10:37:35 +01:00
|
|
|
<PreferencesUserSettingsTab closeSettingsFn={this.props.onFinished} />,
|
2022-02-10 14:38:31 +00:00
|
|
|
"UserSettingsPreferences",
|
2022-12-12 12:24:14 +01:00
|
|
|
),
|
2019-01-23 17:32:27 -07:00
|
|
|
);
|
2022-01-17 12:53:10 +01:00
|
|
|
tabs.push(
|
|
|
|
|
new Tab(
|
|
|
|
|
UserTab.Keyboard,
|
2023-09-19 17:16:38 +01:00
|
|
|
_td("settings|keyboard|title"),
|
2022-01-17 12:53:10 +01:00
|
|
|
"mx_UserSettingsDialog_keyboardIcon",
|
|
|
|
|
<KeyboardUserSettingsTab />,
|
2022-02-10 14:38:31 +00:00
|
|
|
"UserSettingsKeyboard",
|
2022-12-12 12:24:14 +01:00
|
|
|
),
|
2022-01-17 12:53:10 +01:00
|
|
|
);
|
2022-01-25 12:33:17 +00:00
|
|
|
tabs.push(
|
|
|
|
|
new Tab(
|
|
|
|
|
UserTab.Sidebar,
|
2023-09-25 18:12:41 +01:00
|
|
|
_td("settings|sidebar|title"),
|
2022-01-25 12:33:17 +00:00
|
|
|
"mx_UserSettingsDialog_sidebarIcon",
|
|
|
|
|
<SidebarUserSettingsTab />,
|
2022-02-10 14:38:31 +00:00
|
|
|
"UserSettingsSidebar",
|
2022-12-12 12:24:14 +01:00
|
|
|
),
|
2022-01-25 12:33:17 +00:00
|
|
|
);
|
2021-11-11 13:07:41 +00:00
|
|
|
|
2020-09-16 13:40:27 +01:00
|
|
|
if (SettingsStore.getValue(UIFeature.Voip)) {
|
|
|
|
|
tabs.push(
|
|
|
|
|
new Tab(
|
2021-06-18 12:44:15 +01:00
|
|
|
UserTab.Voice,
|
2023-09-26 18:35:55 +01:00
|
|
|
_td("settings|voip|title"),
|
2020-09-16 13:40:27 +01:00
|
|
|
"mx_UserSettingsDialog_voiceIcon",
|
|
|
|
|
<VoiceUserSettingsTab />,
|
2022-02-10 14:38:31 +00:00
|
|
|
"UserSettingsVoiceVideo",
|
2022-12-12 12:24:14 +01:00
|
|
|
),
|
2020-09-16 13:40:27 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 17:32:27 -07:00
|
|
|
tabs.push(
|
|
|
|
|
new Tab(
|
2021-06-18 12:44:15 +01:00
|
|
|
UserTab.Security,
|
2023-09-21 09:11:26 +01:00
|
|
|
_td("room_settings|security|title"),
|
2022-08-08 15:51:00 +02:00
|
|
|
"mx_UserSettingsDialog_securityIcon",
|
2020-04-27 14:25:47 +01:00
|
|
|
<SecurityUserSettingsTab closeSettingsFn={this.props.onFinished} />,
|
2022-02-10 14:38:31 +00:00
|
|
|
"UserSettingsSecurityPrivacy",
|
2022-12-12 12:24:14 +01:00
|
|
|
),
|
|
|
|
|
);
|
2023-05-26 13:58:28 +12:00
|
|
|
tabs.push(
|
|
|
|
|
new Tab(
|
|
|
|
|
UserTab.SessionManager,
|
2023-09-25 18:12:41 +01:00
|
|
|
_td("settings|sessions|title"),
|
2023-05-26 13:58:28 +12:00
|
|
|
"mx_UserSettingsDialog_sessionsIcon",
|
|
|
|
|
<SessionManagerTab />,
|
|
|
|
|
// don't track with posthog while under construction
|
|
|
|
|
undefined,
|
|
|
|
|
),
|
|
|
|
|
);
|
2021-04-27 16:29:42 +01:00
|
|
|
// Show the Labs tab if enabled or if there are any active betas
|
2023-10-13 14:24:00 +01:00
|
|
|
if (showLabsFlags() || SettingsStore.getFeatureSettingNames().some((k) => SettingsStore.getBetaInfo(k))) {
|
2019-01-23 17:32:27 -07:00
|
|
|
tabs.push(
|
|
|
|
|
new Tab(
|
2021-06-18 12:44:15 +01:00
|
|
|
UserTab.Labs,
|
2023-08-23 10:25:33 +01:00
|
|
|
_td("common|labs"),
|
2019-01-23 17:32:27 -07:00
|
|
|
"mx_UserSettingsDialog_labsIcon",
|
2019-02-22 10:47:18 -07:00
|
|
|
<LabsUserSettingsTab />,
|
2022-02-10 14:38:31 +00:00
|
|
|
"UserSettingsLabs",
|
2022-12-12 12:24:14 +01:00
|
|
|
),
|
2019-01-23 17:32:27 -07:00
|
|
|
);
|
|
|
|
|
}
|
2019-10-31 13:19:54 -06:00
|
|
|
if (this.state.mjolnirEnabled) {
|
|
|
|
|
tabs.push(
|
|
|
|
|
new Tab(
|
2021-06-18 12:44:15 +01:00
|
|
|
UserTab.Mjolnir,
|
2023-09-21 18:16:04 +01:00
|
|
|
_td("labs_mjolnir|title"),
|
2019-10-31 13:19:54 -06:00
|
|
|
"mx_UserSettingsDialog_mjolnirIcon",
|
|
|
|
|
<MjolnirUserSettingsTab />,
|
2022-02-10 14:38:31 +00:00
|
|
|
"UserSettingMjolnir",
|
2022-12-12 12:24:14 +01:00
|
|
|
),
|
2019-10-31 13:19:54 -06:00
|
|
|
);
|
|
|
|
|
}
|
2019-01-23 17:32:27 -07:00
|
|
|
tabs.push(
|
|
|
|
|
new Tab(
|
2021-06-18 12:44:15 +01:00
|
|
|
UserTab.Help,
|
2023-09-13 09:30:56 +01:00
|
|
|
_td("setting|help_about|title"),
|
2019-01-23 17:32:27 -07:00
|
|
|
"mx_UserSettingsDialog_helpIcon",
|
2024-02-12 15:04:13 +00:00
|
|
|
<HelpUserSettingsTab />,
|
2022-02-10 14:38:31 +00:00
|
|
|
"UserSettingsHelpAbout",
|
2022-12-12 12:24:14 +01:00
|
|
|
),
|
2019-01-23 17:32:27 -07:00
|
|
|
);
|
|
|
|
|
|
2023-04-27 12:55:29 +01:00
|
|
|
return tabs as NonEmptyArray<Tab<UserTab>>;
|
2019-01-18 13:43:17 -07:00
|
|
|
}
|
2019-01-18 13:09:17 -07:00
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2019-01-18 13:09:17 -07:00
|
|
|
return (
|
2023-10-16 12:03:25 +13:00
|
|
|
// XXX: SDKContext is provided within the LoggedInView subtree.
|
|
|
|
|
// Modals function outside the MatrixChat React tree, so sdkContext is reprovided here to simulate that.
|
|
|
|
|
// The longer term solution is to move our ModalManager into the React tree to inherit contexts properly.
|
|
|
|
|
<SDKContext.Provider value={this.props.sdkContext}>
|
|
|
|
|
<BaseDialog
|
|
|
|
|
className="mx_UserSettingsDialog"
|
|
|
|
|
hasCancel={true}
|
|
|
|
|
onFinished={this.props.onFinished}
|
|
|
|
|
title={_t("common|settings")}
|
|
|
|
|
>
|
|
|
|
|
<div className="mx_SettingsDialog_content">
|
|
|
|
|
<TabbedView
|
|
|
|
|
tabs={this.getTabs()}
|
|
|
|
|
initialTabId={this.props.initialTabId}
|
|
|
|
|
screenName="UserSettings"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</BaseDialog>
|
|
|
|
|
</SDKContext.Provider>
|
2019-01-18 13:09:17 -07:00
|
|
|
);
|
2019-01-18 13:43:17 -07:00
|
|
|
}
|
|
|
|
|
}
|