import CheckIcon from "@mui/icons-material/Check"; import CloseIcon from "@mui/icons-material/Close"; import KeyIcon from "@mui/icons-material/Key"; import LinkIcon from "@mui/icons-material/Link"; import LinkOffIcon from "@mui/icons-material/LinkOff"; import { Button, Card, CardActions, CardContent, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, TextField, Typography, } from "@mui/material"; import React from "react"; import { MatrixLinkApi } from "../api/MatrixLinkApi"; import { useAlert } from "../hooks/contexts_provider/AlertDialogProvider"; import { useConfirm } from "../hooks/contexts_provider/ConfirmDialogProvider"; import { useLoadingMessage } from "../hooks/contexts_provider/LoadingMessageProvider"; import { useSnackbar } from "../hooks/contexts_provider/SnackbarProvider"; import { useUserInfo } from "../widgets/dashboard/BaseAuthenticatedPage"; import { MatrixGWRouteContainer } from "../widgets/MatrixGWRouteContainer"; export function MatrixLinkRoute(): React.ReactElement { const user = useUserInfo(); return ( {user.info.matrix_user_id === null ? ( ) : ( <> )} ); } function ConnectCard(): React.ReactElement { const alert = useAlert(); const loadingMessage = useLoadingMessage(); const startMatrixConnection = async () => { try { loadingMessage.show("Initiating Matrix link..."); const res = await MatrixLinkApi.StartAuth(); window.location.href = res.url; } catch (e) { console.error(`Failed to connect to Matrix account! ${e}`); alert(`Failed to connect to Matrix account! ${e}`); } finally { loadingMessage.hide(); } }; return ( Disconnected from your Matrix account You need to connect MatrixGW to your Matrix account to let it access your messages. ); } function ConnectedCard(): React.ReactElement { const snackbar = useSnackbar(); const confirm = useConfirm(); const alert = useAlert(); const loadingMessage = useLoadingMessage(); const user = useUserInfo(); const handleDisconnect = async () => { if (!(await confirm("Do you really want to unlink your Matrix account?"))) return; try { loadingMessage.show("Unlinking Matrix account..."); await MatrixLinkApi.Disconnect(); snackbar("Successfully unlinked Matrix account!"); } catch (e) { console.error(`Failed to unlink user account! ${e}`); alert(`Failed to unlink your account! ${e}`); } finally { user.reloadUserInfo(); loadingMessage.hide(); } }; return ( Connected to your Matrix account

MatrixGW is currently connected to your account with the following information:

  • User id: {user.info.matrix_user_id}
  • Device id: {user.info.matrix_device_id}

If you encounter issues with your Matrix account you can try to disconnect and connect back again.

); } function EncryptionKeyStatus(): React.ReactElement { const alert = useAlert(); const snackbar = useSnackbar(); const loadingMessage = useLoadingMessage(); const user = useUserInfo(); const [typeNewKey, setTypeNewKey] = React.useState(false); const [newKey, setNewKey] = React.useState(""); const handleSetKey = () => setTypeNewKey(true); const cancelSetKey = () => setTypeNewKey(false); const handleSubmitKey = async () => { try { loadingMessage.show("Updating recovery key..."); await MatrixLinkApi.SetRecoveryKey(newKey); setNewKey(""); setTypeNewKey(false); snackbar("Recovery key successfully updated!"); user.reloadUserInfo(); } catch (e) { console.error(`Failed to set new recovery key! ${e}`); alert(`Failed to set new recovery key! ${e}`); } finally { loadingMessage.hide(); } }; return ( <> Recovery keys

Recovery key is used to verify MatrixGW connection and access message history in encrypted rooms.

Current encryption status:{" "} {user.info.matrix_recovery_state === "Enabled" ? ( ) : ( )}{" "} {user.info.matrix_recovery_state}

{/* Set new key dialog */} Set new recovery key Enter below you recovery key to verify this session and gain access to old messages. setNewKey(e.target.value)} fullWidth /> ); }