diff --git a/src/components/views/settings/tabs/user/EncryptionUserSettingsTab.tsx b/src/components/views/settings/tabs/user/EncryptionUserSettingsTab.tsx index fa7db599a53..613bbf0d25f 100644 --- a/src/components/views/settings/tabs/user/EncryptionUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/EncryptionUserSettingsTab.tsx @@ -5,19 +5,42 @@ * Please see LICENSE files in the repository root for full details. */ -import React, { JSX, useState } from "react"; +import React, { JSX, useCallback, useEffect, useState } from "react"; +import { Button, InlineSpinner } from "@vector-im/compound-web"; +import ComputerIcon from "@vector-im/compound-design-tokens/assets/web/icons/computer"; import SettingsTab from "../SettingsTab"; import { RecoveryPanel } from "../../encryption/RecoveryPanel"; import { ChangeRecoveryKey } from "../../encryption/ChangeRecoveryKey"; +import { useMatrixClientContext } from "../../../../../contexts/MatrixClientContext.tsx"; +import { _t } from "../../../../../languageHandler.tsx"; +import Modal from "../../../../../Modal.tsx"; +import SetupEncryptionDialog from "../../../dialogs/security/SetupEncryptionDialog.tsx"; +import { SettingsSection } from "../../shared/SettingsSection.tsx"; +import { SettingsSubheader } from "../../SettingsSubheader.tsx"; -type Panel = "main" | "change_recovery_key" | "set_recovery_key"; +/** + * The panel to show in the encryption settings tab. + * - "loading": We are checking if the device is verified. + * - "main": The main panel with all the sections (Key storage, recovery, advanced). + * - "verification_required": The panel to show when the user needs to verify their session. + * - "change_recovery_key": The panel to show when the user is changing their recovery key. + * - "set_recovery_key": The panel to show when the user is setting up their recovery key. + */ +type Panel = "loading" | "main" | "verification_required" | "change_recovery_key" | "set_recovery_key"; export function EncryptionUserSettingsTab(): JSX.Element { - const [panel, setPanel] = useState("main"); + const [panel, setPanel] = useState("loading"); + const checkVerificationRequired = useVerificationRequired(setPanel); let content: JSX.Element; switch (panel) { + case "loading": + content = ; + break; + case "verification_required": + content = ; + break; case "main": content = ( {content}; } + +/** + * Hook to check if the user needs to verify their session. + * If the user needs to verify their session, the panel will be set to "verification_required". + * If the user doesn't need to verify their session, the panel will be set to "main". + * @param setPanel + */ +function useVerificationRequired(setPanel: (panel: Panel) => void): () => Promise { + const matrixClient = useMatrixClientContext(); + + const checkVerificationRequired = useCallback(async () => { + const crypto = matrixClient.getCrypto(); + if (!crypto) return; + + const isCrossSigningReady = await crypto.isCrossSigningReady(); + if (isCrossSigningReady) setPanel("main"); + else setPanel("verification_required"); + }, [matrixClient, setPanel]); + + useEffect(() => { + checkVerificationRequired(); + }, [checkVerificationRequired]); + + return checkVerificationRequired; +} + +interface VerifySessionPanelProps { + /** + * Callback to call when the user has finished verifying their session. + */ + onFinish: () => void; +} + +/** + * Panel to show when the user needs to verify their session. + */ +function VerifySessionPanel({ onFinish }: VerifySessionPanelProps): JSX.Element { + return ( + + } + > + + + ); +} diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 2f41337307f..98a8cf4c979 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2463,6 +2463,9 @@ "enable_markdown": "Enable Markdown", "enable_markdown_description": "Start messages with /plain to send without markdown.", "encryption": { + "device_not_verified_button": "Verify this device", + "device_not_verified_description": "You need to verify this device in order to view your encryption settings.", + "device_not_verified_title": "Device not verified", "dialog_title": "Settings: Encryption", "recovery": { "change_recovery_key": "Change recovery key",