Skip to content

Commit 833feff

Browse files
committed
Remove unused code
1 parent 7ddaa7c commit 833feff

File tree

5 files changed

+2
-375
lines changed

5 files changed

+2
-375
lines changed

res/css/views/right_panel/_UserInfo.pcss

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -244,45 +244,6 @@ Please see LICENSE files in the repository root for full details.
244244
flex: 1 1 0;
245245
}
246246

247-
.mx_UserInfo_devices {
248-
.mx_UserInfo_device {
249-
display: flex;
250-
margin: $spacing-8 0;
251-
252-
&.mx_UserInfo_device_verified {
253-
.mx_UserInfo_device_trusted {
254-
color: $accent;
255-
}
256-
}
257-
&.mx_UserInfo_device_unverified {
258-
.mx_UserInfo_device_trusted {
259-
color: $alert;
260-
}
261-
}
262-
263-
.mx_UserInfo_device_name {
264-
flex: 1;
265-
margin: 0 5px;
266-
word-break: break-word;
267-
}
268-
}
269-
270-
/* both for icon in expand button and device item */
271-
.mx_E2EIcon {
272-
/* don't squeeze */
273-
flex: 0 0 auto;
274-
margin: 0;
275-
width: 12px;
276-
height: 12px;
277-
}
278-
279-
.mx_UserInfo_expand {
280-
column-gap: 5px; /* cf: mx_UserInfo_device_name */
281-
margin-bottom: 11px;
282-
align-items: initial; /* Cancel the default property */
283-
}
284-
}
285-
286247
&.mx_UserInfo_smallAvatar {
287248
.mx_UserInfo_avatar {
288249
.mx_UserInfo_avatar_transition {

src/components/views/right_panel/UserInfo.tsx

Lines changed: 2 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import dis from "../../../dispatcher/dispatcher";
4343
import Modal from "../../../Modal";
4444
import { _t, UserFriendlyError } from "../../../languageHandler";
4545
import DMRoomMap from "../../../utils/DMRoomMap";
46-
import AccessibleButton, { type ButtonEvent } from "../elements/AccessibleButton";
46+
import { type ButtonEvent } from "../elements/AccessibleButton";
4747
import SdkConfig from "../../../SdkConfig";
4848
import MultiInviter from "../../../utils/MultiInviter";
4949
import { useTypedEventEmitter } from "../../../hooks/useEventEmitter";
@@ -52,7 +52,7 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext";
5252
import { RightPanelPhases } from "../../../stores/right-panel/RightPanelStorePhases";
5353
import EncryptionPanel from "./EncryptionPanel";
5454
import { useAsyncMemo } from "../../../hooks/useAsyncMemo";
55-
import { verifyDevice, verifyUser } from "../../../verification";
55+
import { verifyUser } from "../../../verification";
5656
import { Action } from "../../../dispatcher/actions";
5757
import { useIsEncrypted } from "../../../hooks/useIsEncrypted";
5858
import BaseCard from "./BaseCard";
@@ -118,92 +118,6 @@ async function openDmForUser(matrixClient: MatrixClient, user: Member): Promise<
118118
await startDmOnFirstMessage(matrixClient, [startDmUser]);
119119
}
120120

121-
/**
122-
* Display one device and the related actions
123-
* @param userId current user id
124-
* @param device device to display
125-
* @param isUserVerified false when the user is not verified
126-
* @constructor
127-
*/
128-
export function DeviceItem({
129-
userId,
130-
device,
131-
isUserVerified,
132-
}: {
133-
userId: string;
134-
device: IDevice;
135-
isUserVerified: boolean;
136-
}): JSX.Element {
137-
const cli = useContext(MatrixClientContext);
138-
const isMe = userId === cli.getUserId();
139-
140-
/** is the device verified? */
141-
const isVerified = useAsyncMemo(async () => {
142-
const deviceTrust = await cli.getCrypto()?.getDeviceVerificationStatus(userId, device.deviceId);
143-
if (!deviceTrust) return false;
144-
145-
// For your own devices, we use the stricter check of cross-signing
146-
// verification to encourage everyone to trust their own devices via
147-
// cross-signing so that other users can then safely trust you.
148-
// For other people's devices, the more general verified check that
149-
// includes locally verified devices can be used.
150-
return isMe ? deviceTrust.crossSigningVerified : deviceTrust.isVerified();
151-
}, [cli, userId, device]);
152-
153-
const classes = classNames("mx_UserInfo_device", {
154-
mx_UserInfo_device_verified: isVerified,
155-
mx_UserInfo_device_unverified: !isVerified,
156-
});
157-
const iconClasses = classNames("mx_E2EIcon", {
158-
mx_E2EIcon_normal: !isUserVerified,
159-
mx_E2EIcon_verified: isVerified,
160-
mx_E2EIcon_warning: isUserVerified && !isVerified,
161-
});
162-
163-
const onDeviceClick = (): void => {
164-
const user = cli.getUser(userId);
165-
if (user) {
166-
verifyDevice(cli, user, device);
167-
}
168-
};
169-
170-
let deviceName;
171-
if (!device.displayName?.trim()) {
172-
deviceName = device.deviceId;
173-
} else {
174-
deviceName = device.ambiguous ? device.displayName + " (" + device.deviceId + ")" : device.displayName;
175-
}
176-
177-
let trustedLabel: string | undefined;
178-
if (isUserVerified) trustedLabel = isVerified ? _t("common|trusted") : _t("common|not_trusted");
179-
180-
if (isVerified === undefined) {
181-
// we're still deciding if the device is verified
182-
return <div className={classes} title={device.deviceId} />;
183-
} else if (isVerified) {
184-
return (
185-
<div className={classes} title={device.deviceId}>
186-
<div className={iconClasses} />
187-
<div className="mx_UserInfo_device_name">{deviceName}</div>
188-
<div className="mx_UserInfo_device_trusted">{trustedLabel}</div>
189-
</div>
190-
);
191-
} else {
192-
return (
193-
<AccessibleButton
194-
className={classes}
195-
title={device.deviceId}
196-
aria-label={deviceName}
197-
onClick={onDeviceClick}
198-
>
199-
<div className={iconClasses} />
200-
<div className="mx_UserInfo_device_name">{deviceName}</div>
201-
<div className="mx_UserInfo_device_trusted">{trustedLabel}</div>
202-
</AccessibleButton>
203-
);
204-
}
205-
}
206-
207121
const MessageButton = ({ member }: { member: Member }): JSX.Element => {
208122
const cli = useContext(MatrixClientContext);
209123
const [busy, setBusy] = useState(false);

src/verification.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ import { type User, type MatrixClient, type RoomMember } from "matrix-js-sdk/src
1010
import { CrossSigningKey, type VerificationRequest } from "matrix-js-sdk/src/crypto-api";
1111

1212
import dis from "./dispatcher/dispatcher";
13-
import Modal from "./Modal";
1413
import { RightPanelPhases } from "./stores/right-panel/RightPanelStorePhases";
1514
import { accessSecretStorage } from "./SecurityManager";
16-
import UntrustedDeviceDialog from "./components/views/dialogs/UntrustedDeviceDialog";
17-
import { type IDevice } from "./components/views/right_panel/UserInfo";
1815
import RightPanelStore from "./stores/right-panel/RightPanelStore";
1916
import { type IRightPanelCardState } from "./stores/right-panel/RightPanelStoreIPanelState";
2017
import { findDMForUser } from "./utils/dm/findDMForUser";
@@ -31,32 +28,6 @@ async function enable4SIfNeeded(matrixClient: MatrixClient): Promise<boolean> {
3128
return true;
3229
}
3330

34-
export async function verifyDevice(matrixClient: MatrixClient, user: User, device: IDevice): Promise<void> {
35-
if (matrixClient.isGuest()) {
36-
dis.dispatch({ action: "require_registration" });
37-
return;
38-
}
39-
// if cross-signing is not explicitly disabled, check if it should be enabled first.
40-
if (matrixClient.getCrypto()?.getTrustCrossSignedDevices()) {
41-
if (!(await enable4SIfNeeded(matrixClient))) {
42-
return;
43-
}
44-
}
45-
46-
Modal.createDialog(UntrustedDeviceDialog, {
47-
user,
48-
device,
49-
onFinished: async (action): Promise<void> => {
50-
if (action === "sas") {
51-
const verificationRequestPromise = matrixClient
52-
.getCrypto()
53-
?.requestDeviceVerification(user.userId, device.deviceId);
54-
setRightPanel({ member: user, verificationRequestPromise });
55-
}
56-
},
57-
});
58-
}
59-
6031
export async function verifyUser(matrixClient: MatrixClient, user: User): Promise<void> {
6132
if (matrixClient.isGuest()) {
6233
dis.dispatch({ action: "require_registration" });

test/unit-tests/components/views/right_panel/UserInfo-test.tsx

Lines changed: 0 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ import {
2828
VerificationPhase as Phase,
2929
VerificationRequestEvent,
3030
type CryptoApi,
31-
type DeviceVerificationStatus,
3231
} from "matrix-js-sdk/src/crypto-api";
3332

3433
import UserInfo, {
3534
BanToggleButton,
36-
DeviceItem,
3735
disambiguateDevices,
3836
getPowerLevels,
3937
isMuted,
@@ -48,7 +46,6 @@ import { RightPanelPhases } from "../../../../../src/stores/right-panel/RightPan
4846
import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg";
4947
import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext";
5048
import MultiInviter from "../../../../../src/utils/MultiInviter";
51-
import * as mockVerification from "../../../../../src/verification";
5249
import Modal from "../../../../../src/Modal";
5350
import { DirectoryMember, startDmOnFirstMessage } from "../../../../../src/utils/direct-messages";
5451
import { clearAllModals, flushPromises } from "../../../../test-utils";
@@ -532,153 +529,6 @@ describe("<UserInfoHeader />", () => {
532529
});
533530
});
534531

535-
describe("<DeviceItem />", () => {
536-
const device = { deviceId: "deviceId", displayName: "deviceName" } as Device;
537-
const defaultProps = {
538-
userId: defaultUserId,
539-
device,
540-
isUserVerified: false,
541-
};
542-
543-
const renderComponent = (props = {}) => {
544-
const Wrapper = (wrapperProps = {}) => {
545-
return <MatrixClientContext.Provider value={mockClient} {...wrapperProps} />;
546-
};
547-
548-
return render(<DeviceItem {...defaultProps} {...props} />, {
549-
wrapper: Wrapper,
550-
});
551-
};
552-
553-
const setMockDeviceTrust = (isVerified = false, isCrossSigningVerified = false) => {
554-
mockCrypto.getDeviceVerificationStatus.mockResolvedValue({
555-
isVerified: () => isVerified,
556-
crossSigningVerified: isCrossSigningVerified,
557-
} as DeviceVerificationStatus);
558-
};
559-
560-
const mockVerifyDevice = jest.spyOn(mockVerification, "verifyDevice");
561-
562-
beforeEach(() => {
563-
setMockDeviceTrust();
564-
});
565-
566-
afterEach(() => {
567-
mockCrypto.getDeviceVerificationStatus.mockReset();
568-
mockVerifyDevice.mockClear();
569-
});
570-
571-
afterAll(() => {
572-
mockVerifyDevice.mockRestore();
573-
});
574-
575-
it("with unverified user and device, displays button without a label", async () => {
576-
renderComponent();
577-
await flushPromises();
578-
579-
expect(screen.getByRole("button", { name: device.displayName! })).toBeInTheDocument();
580-
expect(screen.queryByText(/trusted/i)).not.toBeInTheDocument();
581-
});
582-
583-
it("with verified user only, displays button with a 'Not trusted' label", async () => {
584-
renderComponent({ isUserVerified: true });
585-
await flushPromises();
586-
587-
const button = screen.getByRole("button", { name: device.displayName });
588-
expect(button).toHaveTextContent(`${device.displayName}Not trusted`);
589-
});
590-
591-
it("with verified device only, displays no button without a label", async () => {
592-
setMockDeviceTrust(true);
593-
renderComponent();
594-
await flushPromises();
595-
596-
expect(screen.getByText(device.displayName!)).toBeInTheDocument();
597-
expect(screen.queryByText(/trusted/)).not.toBeInTheDocument();
598-
});
599-
600-
it("when userId is the same as userId from client, uses isCrossSigningVerified to determine if button is shown", async () => {
601-
const deferred = defer<DeviceVerificationStatus>();
602-
mockCrypto.getDeviceVerificationStatus.mockReturnValue(deferred.promise);
603-
604-
mockClient.getSafeUserId.mockReturnValueOnce(defaultUserId);
605-
mockClient.getUserId.mockReturnValueOnce(defaultUserId);
606-
renderComponent();
607-
await flushPromises();
608-
609-
// set trust to be false for isVerified, true for isCrossSigningVerified
610-
deferred.resolve({
611-
isVerified: () => false,
612-
crossSigningVerified: true,
613-
} as DeviceVerificationStatus);
614-
615-
await expect(screen.findByText(device.displayName!)).resolves.toBeInTheDocument();
616-
// expect to see no button in this case
617-
expect(screen.queryByRole("button")).not.toBeInTheDocument();
618-
});
619-
620-
it("with verified user and device, displays no button and a 'Trusted' label", async () => {
621-
setMockDeviceTrust(true);
622-
renderComponent({ isUserVerified: true });
623-
await flushPromises();
624-
625-
expect(screen.queryByRole("button")).not.toBeInTheDocument();
626-
expect(screen.getByText(device.displayName!)).toBeInTheDocument();
627-
expect(screen.getByText("Trusted")).toBeInTheDocument();
628-
});
629-
630-
it("does not call verifyDevice if client.getUser returns null", async () => {
631-
mockClient.getUser.mockReturnValueOnce(null);
632-
renderComponent();
633-
await flushPromises();
634-
635-
const button = screen.getByRole("button", { name: device.displayName! });
636-
expect(button).toBeInTheDocument();
637-
await userEvent.click(button);
638-
639-
expect(mockVerifyDevice).not.toHaveBeenCalled();
640-
});
641-
642-
it("calls verifyDevice if client.getUser returns an object", async () => {
643-
mockClient.getUser.mockReturnValueOnce(defaultUser);
644-
// set mock return of isGuest to short circuit verifyDevice call to avoid
645-
// even more mocking
646-
mockClient.isGuest.mockReturnValueOnce(true);
647-
renderComponent();
648-
await flushPromises();
649-
650-
const button = screen.getByRole("button", { name: device.displayName! });
651-
expect(button).toBeInTheDocument();
652-
await userEvent.click(button);
653-
654-
expect(mockVerifyDevice).toHaveBeenCalledTimes(1);
655-
expect(mockVerifyDevice).toHaveBeenCalledWith(mockClient, defaultUser, device);
656-
});
657-
658-
it("with display name", async () => {
659-
const { container } = renderComponent();
660-
await flushPromises();
661-
662-
expect(container).toMatchSnapshot();
663-
});
664-
665-
it("without display name", async () => {
666-
const device = { deviceId: "deviceId" } as Device;
667-
const { container } = renderComponent({ device, userId: defaultUserId });
668-
await flushPromises();
669-
670-
expect(container).toMatchSnapshot();
671-
});
672-
673-
it("ambiguous display name", async () => {
674-
const device = { deviceId: "deviceId", ambiguous: true, displayName: "my display name" };
675-
const { container } = renderComponent({ device, userId: defaultUserId });
676-
await flushPromises();
677-
678-
expect(container).toMatchSnapshot();
679-
});
680-
});
681-
682532
describe("<UserOptionsSection />", () => {
683533
const member = new RoomMember(defaultRoomId, defaultUserId);
684534
const defaultProps = { member, canInvite: false, isSpace: false };

0 commit comments

Comments
 (0)