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

Commit 31bd10e

Browse files
authored
Remove usage of deprecated CryptoEvents (#126)
* Remove usage of `CryptoEvent.DeviceVerificationChanged` * Remove usage of `CryptoEvent.KeySignatureUploadFailure` * Remove usage of `CryptoEvent.Warning` * Merge `CryptoEvent.DevicesUpdated` and `CryptoEvent.WillUpdateDevices` behaviour
1 parent a0cb947 commit 31bd10e

File tree

8 files changed

+1
-196
lines changed

8 files changed

+1
-196
lines changed

src/DeviceListener.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ export default class DeviceListener {
8585
public start(matrixClient: MatrixClient): void {
8686
this.running = true;
8787
this.client = matrixClient;
88-
this.client.on(CryptoEvent.WillUpdateDevices, this.onWillUpdateDevices);
8988
this.client.on(CryptoEvent.DevicesUpdated, this.onDevicesUpdated);
90-
this.client.on(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
9189
this.client.on(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
9290
this.client.on(CryptoEvent.KeysChanged, this.onCrossSingingKeysChanged);
9391
this.client.on(ClientEvent.AccountData, this.onAccountData);
@@ -109,9 +107,7 @@ export default class DeviceListener {
109107
public stop(): void {
110108
this.running = false;
111109
if (this.client) {
112-
this.client.removeListener(CryptoEvent.WillUpdateDevices, this.onWillUpdateDevices);
113110
this.client.removeListener(CryptoEvent.DevicesUpdated, this.onDevicesUpdated);
114-
this.client.removeListener(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
115111
this.client.removeListener(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
116112
this.client.removeListener(CryptoEvent.KeysChanged, this.onCrossSingingKeysChanged);
117113
this.client.removeListener(ClientEvent.AccountData, this.onAccountData);
@@ -170,7 +166,7 @@ export default class DeviceListener {
170166
return await getUserDeviceIds(cli, cli.getSafeUserId());
171167
}
172168

173-
private onWillUpdateDevices = async (users: string[], initialFetch?: boolean): Promise<void> => {
169+
private onDevicesUpdated = async (users: string[], initialFetch?: boolean): Promise<void> => {
174170
if (!this.client) return;
175171
// If we didn't know about *any* devices before (ie. it's fresh login),
176172
// then they are all pre-existing devices, so ignore this and set the
@@ -180,19 +176,6 @@ export default class DeviceListener {
180176
const myUserId = this.client.getSafeUserId();
181177
if (users.includes(myUserId)) await this.ensureDeviceIdsAtStartPopulated();
182178

183-
// No need to do a recheck here: we just need to get a snapshot of our devices
184-
// before we download any new ones.
185-
};
186-
187-
private onDevicesUpdated = (users: string[]): void => {
188-
if (!this.client) return;
189-
if (!users.includes(this.client.getSafeUserId())) return;
190-
this.recheck();
191-
};
192-
193-
private onDeviceVerificationChanged = (userId: string): void => {
194-
if (!this.client) return;
195-
if (userId !== this.client.getUserId()) return;
196179
this.recheck();
197180
};
198181

src/components/structures/MatrixChat.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ import Spinner from "../views/elements/Spinner";
8282
import QuestionDialog from "../views/dialogs/QuestionDialog";
8383
import UserSettingsDialog from "../views/dialogs/UserSettingsDialog";
8484
import CreateRoomDialog from "../views/dialogs/CreateRoomDialog";
85-
import KeySignatureUploadFailedDialog from "../views/dialogs/KeySignatureUploadFailedDialog";
8685
import IncomingSasDialog from "../views/dialogs/IncomingSasDialog";
8786
import CompleteSecurity from "./auth/CompleteSecurity";
8887
import Welcome from "../views/auth/Welcome";
@@ -1629,18 +1628,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
16291628
room.setBlacklistUnverifiedDevices(blacklistEnabled);
16301629
}
16311630
});
1632-
cli.on(CryptoEvent.Warning, (type) => {
1633-
switch (type) {
1634-
case "CRYPTO_WARNING_OLD_VERSION_DETECTED":
1635-
Modal.createDialog(ErrorDialog, {
1636-
title: _t("encryption|old_version_detected_title"),
1637-
description: _t("encryption|old_version_detected_description", {
1638-
brand: SdkConfig.get().brand,
1639-
}),
1640-
});
1641-
break;
1642-
}
1643-
});
16441631
cli.on(CryptoEvent.KeyBackupFailed, async (errcode): Promise<void> => {
16451632
let haveNewVersion: boolean | undefined;
16461633
let newVersionInfo: KeyBackupInfo | null = null;
@@ -1674,10 +1661,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
16741661
}
16751662
});
16761663

1677-
cli.on(CryptoEvent.KeySignatureUploadFailure, (failures, source, continuation) => {
1678-
Modal.createDialog(KeySignatureUploadFailedDialog, { failures, source, continuation });
1679-
});
1680-
16811664
cli.on(CryptoEvent.VerificationRequestReceived, (request) => {
16821665
if (request.verifier) {
16831666
Modal.createDialog(

src/components/structures/RoomView.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
428428
context.client.on(RoomStateEvent.Update, this.onRoomStateUpdate);
429429
context.client.on(RoomEvent.MyMembership, this.onMyMembership);
430430
context.client.on(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatus);
431-
context.client.on(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
432431
context.client.on(CryptoEvent.UserTrustStatusChanged, this.onUserVerificationChanged);
433432
context.client.on(CryptoEvent.KeysChanged, this.onCrossSigningKeysChanged);
434433
context.client.on(MatrixEventEvent.Decrypted, this.onEventDecrypted);
@@ -974,7 +973,6 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
974973
this.context.client.removeListener(RoomEvent.MyMembership, this.onMyMembership);
975974
this.context.client.removeListener(RoomStateEvent.Update, this.onRoomStateUpdate);
976975
this.context.client.removeListener(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatus);
977-
this.context.client.removeListener(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
978976
this.context.client.removeListener(CryptoEvent.UserTrustStatusChanged, this.onUserVerificationChanged);
979977
this.context.client.removeListener(CryptoEvent.KeysChanged, this.onCrossSigningKeysChanged);
980978
this.context.client.removeListener(MatrixEventEvent.Decrypted, this.onEventDecrypted);
@@ -1438,14 +1436,6 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
14381436
);
14391437
};
14401438

1441-
private onDeviceVerificationChanged = (userId: string): void => {
1442-
const room = this.state.room;
1443-
if (!room?.currentState.getMember(userId)) {
1444-
return;
1445-
}
1446-
this.updateE2EStatus(room);
1447-
};
1448-
14491439
private onUserVerificationChanged = (userId: string): void => {
14501440
const room = this.state.room;
14511441
if (!room || !room.currentState.getMember(userId)) {

src/components/views/dialogs/KeySignatureUploadFailedDialog.tsx

Lines changed: 0 additions & 117 deletions
This file was deleted.

src/components/views/right_panel/UserInfo.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,22 +1381,16 @@ export const useDevices = (userId: string): IDevice[] | undefined | null => {
13811381
if (!users.includes(userId)) return;
13821382
updateDevices();
13831383
};
1384-
const onDeviceVerificationChanged = (_userId: string, deviceId: string): void => {
1385-
if (_userId !== userId) return;
1386-
updateDevices();
1387-
};
13881384
const onUserTrustStatusChanged = (_userId: string, trustLevel: UserVerificationStatus): void => {
13891385
if (_userId !== userId) return;
13901386
updateDevices();
13911387
};
13921388
cli.on(CryptoEvent.DevicesUpdated, onDevicesUpdated);
1393-
cli.on(CryptoEvent.DeviceVerificationChanged, onDeviceVerificationChanged);
13941389
cli.on(CryptoEvent.UserTrustStatusChanged, onUserTrustStatusChanged);
13951390
// Handle being unmounted
13961391
return () => {
13971392
cancel = true;
13981393
cli.removeListener(CryptoEvent.DevicesUpdated, onDevicesUpdated);
1399-
cli.removeListener(CryptoEvent.DeviceVerificationChanged, onDeviceVerificationChanged);
14001394
cli.removeListener(CryptoEvent.UserTrustStatusChanged, onUserTrustStatusChanged);
14011395
};
14021396
}, [cli, userId]);

src/components/views/rooms/EventTile.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
385385
this.suppressReadReceiptAnimation = false;
386386
const client = MatrixClientPeg.safeGet();
387387
if (!this.props.forExport) {
388-
client.on(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
389388
client.on(CryptoEvent.UserTrustStatusChanged, this.onUserVerificationChanged);
390389
this.props.mxEvent.on(MatrixEventEvent.Decrypted, this.onDecrypted);
391390
this.props.mxEvent.on(MatrixEventEvent.Replaced, this.onReplaced);
@@ -425,7 +424,6 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
425424
public componentWillUnmount(): void {
426425
const client = MatrixClientPeg.get();
427426
if (client) {
428-
client.removeListener(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
429427
client.removeListener(CryptoEvent.UserTrustStatusChanged, this.onUserVerificationChanged);
430428
client.removeListener(RoomEvent.Receipt, this.onRoomReceipt);
431429
const room = client.getRoom(this.props.mxEvent.getRoomId());
@@ -564,12 +562,6 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
564562
this.forceUpdate(this.props.onHeightChanged);
565563
};
566564

567-
private onDeviceVerificationChanged = (userId: string, device: string): void => {
568-
if (userId === this.props.mxEvent.getSender()) {
569-
this.verifyEvent();
570-
}
571-
};
572-
573565
private onUserVerificationChanged = (userId: string, _trustStatus: UserVerificationStatus): void => {
574566
if (userId === this.props.mxEvent.getSender()) {
575567
this.verifyEvent();

src/components/views/rooms/MemberTile.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Please see LICENSE files in the repository root for full details.
99

1010
import React from "react";
1111
import { RoomMember, RoomStateEvent, MatrixEvent, EventType } from "matrix-js-sdk/src/matrix";
12-
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
1312
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
1413
import { UserVerificationStatus } from "matrix-js-sdk/src/crypto-api";
1514

@@ -62,7 +61,6 @@ export default class MemberTile extends React.Component<IProps, IState> {
6261
});
6362
if (isRoomEncrypted) {
6463
cli.on(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
65-
cli.on(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
6664
this.updateE2EStatus();
6765
} else {
6866
// Listen for room to become encrypted
@@ -77,7 +75,6 @@ export default class MemberTile extends React.Component<IProps, IState> {
7775
if (cli) {
7876
cli.removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
7977
cli.removeListener(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
80-
cli.removeListener(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
8178
}
8279
}
8380

@@ -100,11 +97,6 @@ export default class MemberTile extends React.Component<IProps, IState> {
10097
this.updateE2EStatus();
10198
};
10299

103-
private onDeviceVerificationChanged = (userId: string, deviceId: string, deviceInfo: DeviceInfo): void => {
104-
if (userId !== this.props.member.userId) return;
105-
this.updateE2EStatus();
106-
};
107-
108100
private async updateE2EStatus(): Promise<void> {
109101
const cli = MatrixClientPeg.safeGet();
110102
const { userId } = this.props.member;

src/i18n/strings/en_EN.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -904,16 +904,6 @@
904904
"incompatible_database_disable": "Continue With Encryption Disabled",
905905
"incompatible_database_sign_out_description": "To avoid losing your chat history, you must export your room keys before logging out. You will need to go back to the newer version of %(brand)s to do this",
906906
"incompatible_database_title": "Incompatible Database",
907-
"key_signature_upload_cancelled": "Cancelled signature upload",
908-
"key_signature_upload_completed": "Upload completed",
909-
"key_signature_upload_failed": "Unable to upload",
910-
"key_signature_upload_failed_body": "%(brand)s encountered an error during upload of:",
911-
"key_signature_upload_failed_cross_signing_key_signature": "a new cross-signing key signature",
912-
"key_signature_upload_failed_device_cross_signing_key_signature": "a device cross-signing signature",
913-
"key_signature_upload_failed_key_signature": "a key signature",
914-
"key_signature_upload_failed_master_key_signature": "a new master key signature",
915-
"key_signature_upload_failed_title": "Signature upload failed",
916-
"key_signature_upload_success_title": "Signature upload success",
917907
"messages_not_secure": {
918908
"cause_1": "Your homeserver",
919909
"cause_2": "The homeserver the user you're verifying is connected to",
@@ -929,8 +919,6 @@
929919
"warning": "If you didn't set the new recovery method, an attacker may be trying to access your account. Change your account password and set a new recovery method immediately in Settings."
930920
},
931921
"not_supported": "<not supported>",
932-
"old_version_detected_description": "Data from an older version of %(brand)s has been detected. This will have caused end-to-end cryptography to malfunction in the older version. End-to-end encrypted messages exchanged recently whilst using the older version may not be decryptable in this version. This may also cause messages exchanged with this version to fail. If you experience problems, log out and back in again. To retain message history, export and re-import your keys.",
933-
"old_version_detected_title": "Old cryptography data detected",
934922
"recovery_method_removed": {
935923
"description_1": "This session has detected that your Security Phrase and key for Secure Messages have been removed.",
936924
"description_2": "If you did this accidentally, you can setup Secure Messages on this session which will re-encrypt this session's message history with a new recovery method.",

0 commit comments

Comments
 (0)