Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit bbfb413

Browse files
committed
Replace MatrixClient.isCryptoEnabled by MatrixClient.getCrypto
1 parent 4e5cf1b commit bbfb413

File tree

14 files changed

+12
-35
lines changed

14 files changed

+12
-35
lines changed

src/components/structures/MatrixChat.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
412412

413413
private async postLoginSetup(): Promise<void> {
414414
const cli = MatrixClientPeg.safeGet();
415-
const cryptoEnabled = cli.isCryptoEnabled();
415+
const cryptoEnabled = cli.getCrypto();
416416
if (!cryptoEnabled) {
417417
this.onLoggedIn();
418418
}
@@ -1618,7 +1618,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
16181618
.catch((e) => logger.error("Unable to start DecryptionFailureTracker", e));
16191619

16201620
cli.on(ClientEvent.Room, (room) => {
1621-
if (cli.isCryptoEnabled()) {
1621+
if (cli.getCrypto()) {
16221622
const blacklistEnabled = SettingsStore.getValueAt(
16231623
SettingLevel.ROOM_DEVICE,
16241624
"blacklistUnverifiedDevices",
@@ -1706,7 +1706,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
17061706
}
17071707
}
17081708

1709-
if (cli.isCryptoEnabled()) {
1709+
if (cli.getCrypto()) {
17101710
const blacklistEnabled = SettingsStore.getValueAt(SettingLevel.DEVICE, "blacklistUnverifiedDevices");
17111711
cli.setGlobalBlacklistUnverifiedDevices(blacklistEnabled);
17121712

src/components/structures/RoomView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
14611461
// set the state immediately then update, so we don't scare the user into thinking the room is unencrypted
14621462
this.setState({ e2eStatus });
14631463

1464-
if (this.context.client.isCryptoEnabled()) {
1464+
if (this.context.client.getCrypto()) {
14651465
/* At this point, the user has encryption on and cross-signing on */
14661466
e2eStatus = await shieldStatusForRoom(this.context.client, room);
14671467
RoomView.e2eStatusCache.set(room.roomId, e2eStatus);

src/components/views/rooms/SendMessageComposer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
265265
public constructor(props: ISendMessageComposerProps, context: React.ContextType<typeof RoomContext>) {
266266
super(props, context);
267267

268-
if (this.props.mxClient.isCryptoEnabled() && this.props.mxClient.isRoomEncrypted(this.props.room.roomId)) {
268+
if (this.props.mxClient.getCrypto() && this.props.mxClient.isRoomEncrypted(this.props.room.roomId)) {
269269
this.prepareToEncrypt = throttle(
270270
() => {
271271
this.props.mxClient.prepareToEncrypt(this.props.room);

src/hooks/useEncryptionStatus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function useEncryptionStatus(client: MatrixClient, room: Room): E2EStatus
1515
const [e2eStatus, setE2eStatus] = useState<E2EStatus | null>(null);
1616

1717
useEffect(() => {
18-
if (client.isCryptoEnabled()) {
18+
if (client.getCrypto()) {
1919
shieldStatusForRoom(client, room).then((e2eStatus) => {
2020
setE2eStatus(e2eStatus);
2121
});

test/components/structures/MatrixChat-test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ describe("<MatrixChat />", () => {
9898
getThirdpartyProtocols: jest.fn().mockResolvedValue({}),
9999
getClientWellKnown: jest.fn().mockReturnValue({}),
100100
isVersionSupported: jest.fn().mockResolvedValue(false),
101-
isCryptoEnabled: jest.fn().mockReturnValue(false),
102101
initRustCrypto: jest.fn(),
103102
getRoom: jest.fn(),
104103
getMediaHandler: jest.fn().mockReturnValue({
@@ -1011,13 +1010,12 @@ describe("<MatrixChat />", () => {
10111010
.mockResolvedValue(new UserVerificationStatus(false, false, false)),
10121011
setDeviceIsolationMode: jest.fn(),
10131012
};
1014-
loginClient.isCryptoEnabled.mockReturnValue(true);
10151013
loginClient.getCrypto.mockReturnValue(mockCrypto as any);
10161014
loginClient.userHasCrossSigningKeys.mockClear().mockResolvedValue(false);
10171015
});
10181016

10191017
it("should go straight to logged in view when crypto is not enabled", async () => {
1020-
loginClient.isCryptoEnabled.mockReturnValue(false);
1018+
loginClient.getCrypto.mockReturnValue(undefined);
10211019

10221020
await getComponentAndLogin(true);
10231021

test/components/structures/RoomView-test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ describe("RoomView", () => {
9797
stores.rightPanelStore.useUnitTestClient(cli);
9898

9999
jest.spyOn(VoipUserMapper.sharedInstance(), "getVirtualRoomForRoom").mockResolvedValue(undefined);
100+
jest.spyOn(cli, "getCrypto").mockReturnValue(undefined);
100101
});
101102

102103
afterEach(() => {
@@ -230,7 +231,6 @@ describe("RoomView", () => {
230231
it("updates url preview visibility on encryption state change", async () => {
231232
room.getMyMembership = jest.fn().mockReturnValue(KnownMembership.Join);
232233
// we should be starting unencrypted
233-
expect(cli.isCryptoEnabled()).toEqual(false);
234234
expect(cli.isRoomEncrypted(room.roomId)).toEqual(false);
235235

236236
const roomViewInstance = await getRoomViewInstance();
@@ -246,7 +246,7 @@ describe("RoomView", () => {
246246
expect(roomViewInstance.state.showUrlPreview).toBe(true);
247247

248248
// now enable encryption
249-
cli.isCryptoEnabled.mockReturnValue(true);
249+
// cli.getCrypto.mockReturnValue({});
250250
cli.isRoomEncrypted.mockReturnValue(true);
251251

252252
// and fake an encryption event into the room to prompt it to re-check

test/components/views/dialogs/security/CreateSecretStorageDialog-test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ describe("CreateSecretStorageDialog", () => {
134134
});
135135

136136
it("calls bootstrapSecretStorage once keys are restored if the backup is now trusted", async () => {
137-
mockClient.isCryptoEnabled.mockReturnValue(true);
138-
139137
const result = renderComponent();
140138
await result.findByText(/Enter your account password to confirm the upgrade/);
141139
expect(result.container).toMatchSnapshot();

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ beforeEach(() => {
142142
isUserIgnored: jest.fn(),
143143
getIgnoredUsers: jest.fn(),
144144
setIgnoredUsers: jest.fn(),
145-
isCryptoEnabled: jest.fn(),
146145
getUserId: jest.fn(),
147146
getSafeUserId: jest.fn(),
148147
getDomain: jest.fn(),
@@ -424,7 +423,6 @@ describe("<UserInfo />", () => {
424423

425424
describe("with crypto enabled", () => {
426425
beforeEach(() => {
427-
mockClient.isCryptoEnabled.mockReturnValue(true);
428426
mockClient.doesServerSupportUnstableFeature.mockResolvedValue(true);
429427
mockCrypto.getUserVerificationStatus.mockResolvedValue(new UserVerificationStatus(false, false, false));
430428

@@ -663,7 +661,6 @@ describe("<UserInfo />", () => {
663661

664662
describe("with an encrypted room", () => {
665663
beforeEach(() => {
666-
mockClient.isCryptoEnabled.mockReturnValue(true);
667664
mockClient.isRoomEncrypted.mockReturnValue(true);
668665
});
669666

test/components/views/rooms/RoomHeader-test.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@ Please see LICENSE files in the repository root for full details.
88

99
import React from "react";
1010
import { CallType, MatrixCall } from "matrix-js-sdk/src/webrtc/call";
11-
import {
12-
EventType,
13-
JoinRule,
14-
MatrixClient,
15-
MatrixEvent,
16-
PendingEventOrdering,
17-
Room,
18-
RoomMember,
19-
} from "matrix-js-sdk/src/matrix";
11+
import { EventType, JoinRule, MatrixEvent, PendingEventOrdering, Room, RoomMember } from "matrix-js-sdk/src/matrix";
2012
import { KnownMembership } from "matrix-js-sdk/src/types";
2113
import {
2214
createEvent,
@@ -86,6 +78,7 @@ describe("RoomHeader", () => {
8678
} as unknown as DMRoomMap);
8779

8880
setCardSpy = jest.spyOn(RightPanelStore.instance, "setCard");
81+
jest.spyOn(ShieldUtils, "shieldStatusForRoom").mockResolvedValue(ShieldUtils.E2EStatus.Normal);
8982
});
9083

9184
afterEach(() => {
@@ -579,10 +572,7 @@ describe("RoomHeader", () => {
579572
});
580573

581574
describe("dm", () => {
582-
let client: MatrixClient;
583575
beforeEach(() => {
584-
client = MatrixClientPeg.get()!;
585-
586576
// Make the mocked room a DM
587577
mocked(DMRoomMap.shared().getUserIdForRoomId).mockImplementation((roomId) => {
588578
if (roomId === room.roomId) return "@user:example.com";
@@ -608,8 +598,6 @@ describe("RoomHeader", () => {
608598
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
609599
},
610600
]);
611-
jest.spyOn(client, "isCryptoEnabled").mockReturnValue(true);
612-
jest.spyOn(ShieldUtils, "shieldStatusForRoom").mockResolvedValue(ShieldUtils.E2EStatus.Normal);
613601
});
614602

615603
it.each([

test/components/views/rooms/SendMessageComposer-test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ describe("<SendMessageComposer/>", () => {
571571

572572
it("should call prepareToEncrypt when the user is typing", async () => {
573573
const cli = stubClient();
574-
cli.isCryptoEnabled = jest.fn().mockReturnValue(true);
574+
cli.getCrypto = jest.fn().mockReturnValue({});
575575
cli.isRoomEncrypted = jest.fn().mockReturnValue(true);
576576
cli.prepareToEncrypt = jest.fn();
577577
const room = mkStubRoom("!roomId:server", "Room", cli);

0 commit comments

Comments
 (0)