2019-01-18 13:09:17 -07:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
|
Copyright 2019-2024 The Matrix.org Foundation C.I.C.
|
2019-01-18 13:09:17 -07:00
|
|
|
Copyright 2019 New Vector Ltd
|
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2019-01-18 13:09:17 -07:00
|
|
|
*/
|
|
|
|
|
|
2024-06-06 14:56:38 +01:00
|
|
|
import { Toast } from "@vector-im/compound-web";
|
2024-06-06 09:57:28 +01:00
|
|
|
import React, { useState } from "react";
|
2024-08-06 17:08:45 +01:00
|
|
|
import UserProfileIcon from "@vector-im/compound-design-tokens/assets/web/icons/user-profile";
|
|
|
|
|
import DevicesIcon from "@vector-im/compound-design-tokens/assets/web/icons/devices";
|
|
|
|
|
import VisibilityOnIcon from "@vector-im/compound-design-tokens/assets/web/icons/visibility-on";
|
|
|
|
|
import NotificationsIcon from "@vector-im/compound-design-tokens/assets/web/icons/notifications";
|
|
|
|
|
import PreferencesIcon from "@vector-im/compound-design-tokens/assets/web/icons/preferences";
|
|
|
|
|
import KeyboardIcon from "@vector-im/compound-design-tokens/assets/web/icons/keyboard";
|
2025-01-15 13:44:20 +01:00
|
|
|
import KeyIcon from "@vector-im/compound-design-tokens/assets/web/icons/key";
|
2024-08-06 17:08:45 +01:00
|
|
|
import SidebarIcon from "@vector-im/compound-design-tokens/assets/web/icons/sidebar";
|
|
|
|
|
import MicOnIcon from "@vector-im/compound-design-tokens/assets/web/icons/mic-on";
|
|
|
|
|
import LockIcon from "@vector-im/compound-design-tokens/assets/web/icons/lock";
|
|
|
|
|
import LabsIcon from "@vector-im/compound-design-tokens/assets/web/icons/labs";
|
|
|
|
|
import BlockIcon from "@vector-im/compound-design-tokens/assets/web/icons/block";
|
|
|
|
|
import HelpIcon from "@vector-im/compound-design-tokens/assets/web/icons/help";
|
2021-10-22 17:23:32 -05:00
|
|
|
|
2024-05-03 16:01:01 +01:00
|
|
|
import TabbedView, { Tab, useActiveTabWithDefault } from "../../structures/TabbedView";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { _t, _td } from "../../../languageHandler";
|
2024-08-06 18:05:08 +01:00
|
|
|
import AccountUserSettingsTab from "../settings/tabs/user/AccountUserSettingsTab";
|
2024-04-30 19:52:32 +01:00
|
|
|
import SettingsStore 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";
|
2025-02-05 13:25:06 +00:00
|
|
|
import { type NonEmptyArray } from "../../../@types/common";
|
|
|
|
|
import { SDKContext, type SdkContextClass } from "../../../contexts/SDKContext";
|
2024-04-30 19:52:32 +01:00
|
|
|
import { useSettingValue } from "../../../hooks/useSettings";
|
2024-06-06 14:56:38 +01:00
|
|
|
import { ToastContext, useActiveToast } from "../../../contexts/ToastContext";
|
2025-01-15 13:44:20 +01:00
|
|
|
import { EncryptionUserSettingsTab } from "../settings/tabs/user/EncryptionUserSettingsTab";
|
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;
|
2024-06-06 09:57:28 +01:00
|
|
|
showMsc4108QrCode?: boolean;
|
2025-03-18 14:35:39 +00:00
|
|
|
/**
|
|
|
|
|
* If `true`, the flow for a user to reset their encryption will be shown. In this case, `initialTabId` must be `UserTab.Encryption`.
|
|
|
|
|
*
|
|
|
|
|
* If false or undefined, show the tab as normal.
|
|
|
|
|
*/
|
2025-02-04 17:40:31 +00:00
|
|
|
showResetIdentity?: boolean;
|
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
|
|
|
}
|
|
|
|
|
|
2024-05-07 10:32:24 +01:00
|
|
|
function titleForTabID(tabId: UserTab): React.ReactNode {
|
|
|
|
|
const subs = {
|
2024-06-20 11:29:38 +02:00
|
|
|
strong: (sub: string) => <span className="mx_UserSettingsDialog_title_strong">{sub}</span>,
|
2024-05-07 10:32:24 +01:00
|
|
|
};
|
|
|
|
|
switch (tabId) {
|
2024-08-06 18:05:08 +01:00
|
|
|
case UserTab.Account:
|
|
|
|
|
return _t("settings|account|dialog_title", undefined, subs);
|
2024-05-07 10:32:24 +01:00
|
|
|
case UserTab.SessionManager:
|
|
|
|
|
return _t("settings|sessions|dialog_title", undefined, subs);
|
|
|
|
|
case UserTab.Appearance:
|
|
|
|
|
return _t("settings|appearance|dialog_title", undefined, subs);
|
|
|
|
|
case UserTab.Notifications:
|
|
|
|
|
return _t("settings|notifications|dialog_title", undefined, subs);
|
|
|
|
|
case UserTab.Preferences:
|
|
|
|
|
return _t("settings|preferences|dialog_title", undefined, subs);
|
|
|
|
|
case UserTab.Keyboard:
|
|
|
|
|
return _t("settings|keyboard|dialog_title", undefined, subs);
|
|
|
|
|
case UserTab.Sidebar:
|
|
|
|
|
return _t("settings|sidebar|dialog_title", undefined, subs);
|
|
|
|
|
case UserTab.Voice:
|
|
|
|
|
return _t("settings|voip|dialog_title", undefined, subs);
|
|
|
|
|
case UserTab.Security:
|
|
|
|
|
return _t("settings|security|dialog_title", undefined, subs);
|
2025-01-15 13:44:20 +01:00
|
|
|
case UserTab.Encryption:
|
|
|
|
|
return _t("settings|encryption|dialog_title", undefined, subs);
|
2024-05-07 10:32:24 +01:00
|
|
|
case UserTab.Labs:
|
|
|
|
|
return _t("settings|labs|dialog_title", undefined, subs);
|
|
|
|
|
case UserTab.Mjolnir:
|
|
|
|
|
return _t("settings|labs_mjolnir|dialog_title", undefined, subs);
|
|
|
|
|
case UserTab.Help:
|
|
|
|
|
return _t("setting|help_about|dialog_title", undefined, subs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-30 19:52:32 +01:00
|
|
|
export default function UserSettingsDialog(props: IProps): JSX.Element {
|
2024-12-23 20:25:15 +00:00
|
|
|
const voipEnabled = useSettingValue(UIFeature.Voip);
|
|
|
|
|
const mjolnirEnabled = useSettingValue("feature_mjolnir");
|
2025-03-18 14:35:39 +00:00
|
|
|
// store these props in state as changing tabs back and forth should clear them
|
2024-06-06 09:57:28 +01:00
|
|
|
const [showMsc4108QrCode, setShowMsc4108QrCode] = useState(props.showMsc4108QrCode);
|
2025-02-04 17:40:31 +00:00
|
|
|
const [showResetIdentity, setShowResetIdentity] = useState(props.showResetIdentity);
|
2020-06-08 08:20:15 -06:00
|
|
|
|
2024-04-30 19:52:32 +01:00
|
|
|
const getTabs = (): NonEmptyArray<Tab<UserTab>> => {
|
2023-04-27 12:55:29 +01:00
|
|
|
const tabs: Tab<UserTab>[] = [];
|
2019-01-23 17:32:27 -07:00
|
|
|
|
|
|
|
|
tabs.push(
|
|
|
|
|
new Tab(
|
2024-08-06 18:05:08 +01:00
|
|
|
UserTab.Account,
|
|
|
|
|
_td("settings|account|title"),
|
2024-08-06 17:08:45 +01:00
|
|
|
<UserProfileIcon />,
|
2024-08-06 18:05:08 +01:00
|
|
|
<AccountUserSettingsTab closeSettingsFn={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
|
|
|
);
|
2024-03-22 15:50:06 +00:00
|
|
|
tabs.push(
|
|
|
|
|
new Tab(
|
|
|
|
|
UserTab.SessionManager,
|
|
|
|
|
_td("settings|sessions|title"),
|
2024-08-06 17:08:45 +01:00
|
|
|
<DevicesIcon />,
|
2024-06-06 09:57:28 +01:00
|
|
|
<SessionManagerTab showMsc4108QrCode={showMsc4108QrCode} />,
|
2024-03-22 15:50:06 +00:00
|
|
|
undefined,
|
|
|
|
|
),
|
|
|
|
|
);
|
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"),
|
2024-08-06 17:08:45 +01:00
|
|
|
<VisibilityOnIcon />,
|
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"),
|
2024-08-06 17:08:45 +01:00
|
|
|
<NotificationsIcon />,
|
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"),
|
2024-08-06 17:08:45 +01:00
|
|
|
<PreferencesIcon />,
|
2024-04-30 19:52:32 +01:00
|
|
|
<PreferencesUserSettingsTab closeSettingsFn={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"),
|
2024-08-06 17:08:45 +01:00
|
|
|
<KeyboardIcon />,
|
2022-01-17 12:53:10 +01:00
|
|
|
<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"),
|
2024-08-06 17:08:45 +01:00
|
|
|
<SidebarIcon />,
|
2022-01-25 12:33:17 +00:00
|
|
|
<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
|
|
|
|
2024-04-30 19:52:32 +01:00
|
|
|
if (voipEnabled) {
|
2020-09-16 13:40:27 +01:00
|
|
|
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"),
|
2024-08-06 17:08:45 +01:00
|
|
|
<MicOnIcon />,
|
2020-09-16 13:40:27 +01:00
|
|
|
<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"),
|
2024-08-06 17:08:45 +01:00
|
|
|
<LockIcon />,
|
2024-04-30 19:52:32 +01:00
|
|
|
<SecurityUserSettingsTab closeSettingsFn={props.onFinished} />,
|
2022-02-10 14:38:31 +00:00
|
|
|
"UserSettingsSecurityPrivacy",
|
2022-12-12 12:24:14 +01:00
|
|
|
),
|
|
|
|
|
);
|
2024-04-30 19:52:32 +01:00
|
|
|
|
2025-01-15 13:44:20 +01:00
|
|
|
tabs.push(
|
2025-02-04 17:40:31 +00:00
|
|
|
new Tab(
|
|
|
|
|
UserTab.Encryption,
|
|
|
|
|
_td("settings|encryption|title"),
|
|
|
|
|
<KeyIcon />,
|
|
|
|
|
<EncryptionUserSettingsTab initialState={showResetIdentity ? "reset_identity_forgot" : undefined} />,
|
2025-03-14 10:06:44 +00:00
|
|
|
"UserSettingsEncryption",
|
2025-02-04 17:40:31 +00:00
|
|
|
),
|
2025-01-15 13:44:20 +01:00
|
|
|
);
|
|
|
|
|
|
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(
|
2024-08-06 17:08:45 +01:00
|
|
|
new Tab(UserTab.Labs, _td("common|labs"), <LabsIcon />, <LabsUserSettingsTab />, "UserSettingsLabs"),
|
2019-01-23 17:32:27 -07:00
|
|
|
);
|
|
|
|
|
}
|
2024-04-30 19:52:32 +01:00
|
|
|
if (mjolnirEnabled) {
|
2019-10-31 13:19:54 -06:00
|
|
|
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"),
|
2024-08-06 17:08:45 +01:00
|
|
|
<BlockIcon />,
|
2019-10-31 13:19:54 -06:00
|
|
|
<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"),
|
2024-08-06 17:08:45 +01:00
|
|
|
<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>>;
|
2024-04-30 19:52:32 +01:00
|
|
|
};
|
2019-01-18 13:09:17 -07:00
|
|
|
|
2024-08-06 18:05:08 +01:00
|
|
|
const [activeTabId, _setActiveTabId] = useActiveTabWithDefault(getTabs(), UserTab.Account, props.initialTabId);
|
2024-06-06 09:57:28 +01:00
|
|
|
const setActiveTabId = (tabId: UserTab): void => {
|
|
|
|
|
_setActiveTabId(tabId);
|
2025-02-04 17:40:31 +00:00
|
|
|
// Clear these so switching away from the tab and back to it will not show the QR code again
|
2024-06-06 09:57:28 +01:00
|
|
|
setShowMsc4108QrCode(false);
|
2025-02-04 17:40:31 +00:00
|
|
|
setShowResetIdentity(false);
|
2024-06-06 09:57:28 +01:00
|
|
|
};
|
2024-05-03 16:01:01 +01:00
|
|
|
|
2024-06-06 14:56:38 +01:00
|
|
|
const [activeToast, toastRack] = useActiveToast();
|
|
|
|
|
|
2024-04-30 19:52:32 +01:00
|
|
|
return (
|
|
|
|
|
// 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={props.sdkContext}>
|
2024-06-06 14:56:38 +01:00
|
|
|
<ToastContext.Provider value={toastRack}>
|
|
|
|
|
<BaseDialog
|
|
|
|
|
className="mx_UserSettingsDialog"
|
|
|
|
|
hasCancel={true}
|
|
|
|
|
onFinished={props.onFinished}
|
|
|
|
|
title={titleForTabID(activeTabId)}
|
2024-06-20 11:29:38 +02:00
|
|
|
titleClass="mx_UserSettingsDialog_title"
|
2024-06-06 14:56:38 +01:00
|
|
|
>
|
|
|
|
|
<div className="mx_SettingsDialog_content">
|
|
|
|
|
<TabbedView
|
|
|
|
|
tabs={getTabs()}
|
|
|
|
|
activeTabId={activeTabId}
|
|
|
|
|
screenName="UserSettings"
|
|
|
|
|
onChange={setActiveTabId}
|
|
|
|
|
responsive={true}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mx_SettingsDialog_toastContainer">
|
|
|
|
|
{activeToast && <Toast>{activeToast}</Toast>}
|
|
|
|
|
</div>
|
|
|
|
|
</BaseDialog>
|
|
|
|
|
</ToastContext.Provider>
|
2024-04-30 19:52:32 +01:00
|
|
|
</SDKContext.Provider>
|
|
|
|
|
);
|
2019-01-18 13:43:17 -07:00
|
|
|
}
|