Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge E2EState and E2EStatus enums #28889

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ import { Action } from "../../../../dispatcher/actions";
import { asyncSome } from "../../../../utils/arrays";
import { getUserDeviceIds } from "../../../../utils/crypto/deviceInfo";
import { RoomMember } from "../../../../models/rooms/RoomMember";
import { E2EState } from "../../../views/rooms/E2EIcon";
import { _t, _td, TranslationKey } from "../../../../languageHandler";
import UserIdentifierCustomisations from "../../../../customisations/UserIdentifier";
import { E2EStatus } from "../../../../utils/ShieldUtils";

interface MemberTileViewModelProps {
member: RoomMember;
showPresence?: boolean;
}

export interface MemberTileViewState extends MemberTileViewModelProps {
e2eStatus?: E2EState;
e2eStatus?: E2EStatus;
name: string;
onClick: () => void;
title?: string;
Expand All @@ -43,7 +43,7 @@ const PowerLabel: Record<PowerStatus, TranslationKey> = {
};

export function useMemberTileViewModel(props: MemberTileViewModelProps): MemberTileViewState {
const [e2eStatus, setE2eStatus] = useState<E2EState | undefined>();
const [e2eStatus, setE2eStatus] = useState<E2EStatus | undefined>();

useEffect(() => {
const cli = MatrixClientPeg.safeGet();
Expand All @@ -53,7 +53,7 @@ export function useMemberTileViewModel(props: MemberTileViewModelProps): MemberT
const isMe = userId === cli.getUserId();
const userTrust = await cli.getCrypto()?.getUserVerificationStatus(userId);
if (!userTrust?.isCrossSigningVerified()) {
setE2eStatus(userTrust?.wasCrossSigningVerified() ? E2EState.Warning : E2EState.Normal);
setE2eStatus(userTrust?.wasCrossSigningVerified() ? E2EStatus.Warning : E2EStatus.Normal);
return;
}

Expand All @@ -67,7 +67,7 @@ export function useMemberTileViewModel(props: MemberTileViewModelProps): MemberT
const deviceTrust = await cli.getCrypto()?.getDeviceVerificationStatus(userId, deviceId);
return !deviceTrust || (isMe ? !deviceTrust.crossSigningVerified : !deviceTrust.isVerified());
});
setE2eStatus(anyDeviceUnverified ? E2EState.Warning : E2EState.Verified);
setE2eStatus(anyDeviceUnverified ? E2EStatus.Warning : E2EStatus.Verified);
};

const onRoomStateEvents = (ev: MatrixEvent): void => {
Expand Down
5 changes: 3 additions & 2 deletions src/components/views/dialogs/UntrustedDeviceDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { User } from "matrix-js-sdk/src/matrix";

import { _t } from "../../../languageHandler";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import E2EIcon, { E2EState } from "../rooms/E2EIcon";
import E2EIcon from "../rooms/E2EIcon";
import AccessibleButton from "../elements/AccessibleButton";
import BaseDialog from "./BaseDialog";
import { IDevice } from "../right_panel/UserInfo";
import { E2EStatus } from "../../../utils/ShieldUtils";

interface IProps {
/**
Expand Down Expand Up @@ -54,7 +55,7 @@ const UntrustedDeviceDialog: React.FC<IProps> = ({ device, user, onFinished }) =
className="mx_UntrustedDeviceDialog"
title={
<>
<E2EIcon status={E2EState.Warning} isUser size={24} hideTooltip={true} />
<E2EIcon status={E2EStatus.Warning} isUser size={24} hideTooltip={true} />
{_t("encryption|udd|title")}
</>
}
Expand Down
7 changes: 4 additions & 3 deletions src/components/views/right_panel/VerificationPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import { MatrixClientPeg } from "../../../MatrixClientPeg";
import VerificationQRCode from "../elements/crypto/VerificationQRCode";
import { _t } from "../../../languageHandler";
import SdkConfig from "../../../SdkConfig";
import E2EIcon, { E2EState } from "../rooms/E2EIcon";
import E2EIcon from "../rooms/E2EIcon";
import Spinner from "../elements/Spinner";
import AccessibleButton from "../elements/AccessibleButton";
import VerificationShowSas from "../verification/VerificationShowSas";
import { getDeviceCryptoInfo } from "../../../utils/crypto/deviceInfo";
import { E2EStatus } from "../../../utils/ShieldUtils";

interface IProps {
layout: string;
Expand Down Expand Up @@ -233,7 +234,7 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
body = (
<React.Fragment>
<p>{description}</p>
<E2EIcon isUser={true} status={E2EState.Verified} size={128} hideTooltip={true} />
<E2EIcon isUser={true} status={E2EStatus.Verified} size={128} hideTooltip={true} />
<div className="mx_VerificationPanel_reciprocateButtons">
<AccessibleButton
kind="danger"
Expand Down Expand Up @@ -302,7 +303,7 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
return (
<div className="mx_UserInfo_container mx_VerificationPanel_verified_section">
<p>{description}</p>
<E2EIcon isUser={true} status={E2EState.Verified} size={128} hideTooltip={true} />
<E2EIcon isUser={true} status={E2EStatus.Verified} size={128} hideTooltip={true} />
{text ? <p>{text}</p> : null}
<AccessibleButton kind="primary" className="mx_UserInfo_wideButton" onClick={this.props.onClose}>
{_t("action|got_it")}
Expand Down
41 changes: 13 additions & 28 deletions src/components/views/rooms/E2EIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,16 @@ import { Tooltip } from "@vector-im/compound-web";
import { _t, _td, TranslationKey } from "../../../languageHandler";
import AccessibleButton from "../elements/AccessibleButton";
import { E2EStatus } from "../../../utils/ShieldUtils";
import { XOR } from "../../../@types/common";

export enum E2EState {
Verified = "verified",
Warning = "warning",
Normal = "normal",
}

export const crossSigningUserTitles: { [key in E2EState]?: TranslationKey } = {
[E2EState.Warning]: _td("encryption|cross_signing_user_warning"),
[E2EState.Normal]: _td("encryption|cross_signing_user_normal"),
[E2EState.Verified]: _td("encryption|cross_signing_user_verified"),
export const crossSigningUserTitles: { [key in E2EStatus]?: TranslationKey } = {
[E2EStatus.Warning]: _td("encryption|cross_signing_user_warning"),
[E2EStatus.Normal]: _td("encryption|cross_signing_user_normal"),
[E2EStatus.Verified]: _td("encryption|cross_signing_user_verified"),
};
const crossSigningRoomTitles: { [key in E2EState]?: TranslationKey } = {
[E2EState.Warning]: _td("encryption|cross_signing_room_warning"),
[E2EState.Normal]: _td("encryption|cross_signing_room_normal"),
[E2EState.Verified]: _td("encryption|cross_signing_room_verified"),
const crossSigningRoomTitles: { [key in E2EStatus]?: TranslationKey } = {
[E2EStatus.Warning]: _td("encryption|cross_signing_room_warning"),
[E2EStatus.Normal]: _td("encryption|cross_signing_room_normal"),
[E2EStatus.Verified]: _td("encryption|cross_signing_room_verified"),
};

interface Props {
Expand All @@ -40,19 +33,11 @@ interface Props {
hideTooltip?: boolean;
tooltipPlacement?: ComponentProps<typeof Tooltip>["placement"];
bordered?: boolean;
}

interface UserProps extends Props {
isUser: true;
status: E2EState | E2EStatus;
}

interface RoomProps extends Props {
isUser?: false;
status: E2EStatus;
isUser?: boolean;
}

const E2EIcon: React.FC<XOR<UserProps, RoomProps>> = ({
const E2EIcon: React.FC<Props> = ({
isUser,
status,
className,
Expand All @@ -66,9 +51,9 @@ const E2EIcon: React.FC<XOR<UserProps, RoomProps>> = ({
{
mx_E2EIcon: true,
mx_E2EIcon_bordered: bordered,
mx_E2EIcon_warning: status === E2EState.Warning,
mx_E2EIcon_normal: status === E2EState.Normal,
mx_E2EIcon_verified: status === E2EState.Verified,
mx_E2EIcon_warning: status === E2EStatus.Warning,
mx_E2EIcon_normal: status === E2EStatus.Normal,
mx_E2EIcon_verified: status === E2EStatus.Verified,
},
className,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,21 @@ import ErrorIcon from "@vector-im/compound-design-tokens/assets/web/icons/error"

import { _t } from "../../../../../../languageHandler";
import { E2EStatus } from "../../../../../../utils/ShieldUtils";
import { E2EState, crossSigningUserTitles } from "../../../E2EIcon";
import { crossSigningUserTitles } from "../../../E2EIcon";

function getIconFromStatus(status: E2EState | E2EStatus): React.JSX.Element | undefined {
function getIconFromStatus(status: E2EStatus): React.JSX.Element | undefined {
switch (status) {
case E2EState.Normal:
case E2EStatus.Normal:
return undefined;
case E2EState.Verified:
case E2EStatus.Verified:
return <VerifiedIcon height="16px" width="16px" className="mx_E2EIconView_verified" />;
case E2EState.Warning:
case E2EStatus.Warning:
return <ErrorIcon height="16px" width="16px" className="mx_E2EIconView_warning" />;
}
}

interface Props {
status: E2EState | E2EStatus;
status: E2EStatus;
}

export const E2EIconView: React.FC<Props> = ({ status }) => {
Expand Down
Loading