Skip to content

Commit f56f814

Browse files
authored
Remove references to MatrixClient.crypto (#28204)
* Remove `VerificationExplorer` * Remove `remakeolm` slash command * Remove call to `crypto.cancelAndResendAllOutgoingKeyRequests` * Remove crypto mock in `LoginWithQR-test.tsx` * Remove `StopGadWidgetDriver.sendToDevice` * Remove remaining mock
1 parent f26b51c commit f56f814

File tree

12 files changed

+0
-380
lines changed

12 files changed

+0
-380
lines changed

src/SlashCommands.tsx

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -736,34 +736,6 @@ export const Commands = [
736736
category: CommandCategories.advanced,
737737
renderingTypes: [TimelineRenderingType.Room],
738738
}),
739-
new Command({
740-
command: "remakeolm",
741-
description: _td("slash_command|remakeolm"),
742-
isEnabled: (cli) => {
743-
return SettingsStore.getValue("developerMode") && !isCurrentLocalRoom(cli);
744-
},
745-
runFn: (cli, roomId) => {
746-
try {
747-
const room = cli.getRoom(roomId);
748-
749-
cli.forceDiscardSession(roomId);
750-
751-
return success(
752-
room?.getEncryptionTargetMembers().then((members) => {
753-
// noinspection JSIgnoredPromiseFromCall
754-
cli.crypto?.ensureOlmSessionsForUsers(
755-
members.map((m) => m.userId),
756-
true,
757-
);
758-
}),
759-
);
760-
} catch (e) {
761-
return reject(e instanceof Error ? e.message : e);
762-
}
763-
},
764-
category: CommandCategories.advanced,
765-
renderingTypes: [TimelineRenderingType.Room],
766-
}),
767739
new Command({
768740
command: "rainbow",
769741
description: _td("slash_command|rainbow"),

src/components/views/dialogs/DevtoolsDialog.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext";
1414
import BaseDialog from "./BaseDialog";
1515
import { TimelineEventEditor } from "./devtools/Event";
1616
import ServersInRoom from "./devtools/ServersInRoom";
17-
import VerificationExplorer from "./devtools/VerificationExplorer";
1817
import SettingExplorer from "./devtools/SettingExplorer";
1918
import { RoomStateExplorer } from "./devtools/RoomState";
2019
import BaseTool, { DevtoolsContext, IDevtoolsProps } from "./devtools/BaseTool";
@@ -45,7 +44,6 @@ const Tools: Record<Category, [label: TranslationKey, tool: Tool][]> = {
4544
[_td("devtools|explore_room_account_data"), RoomAccountDataExplorer],
4645
[_td("devtools|view_servers_in_room"), ServersInRoom],
4746
[_td("devtools|notifications_debug"), RoomNotifications],
48-
[_td("devtools|verification_explorer"), VerificationExplorer],
4947
[_td("devtools|active_widgets"), WidgetExplorer],
5048
],
5149
[Category.Other]: [
Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +0,0 @@
1-
/*
2-
Copyright 2024 New Vector Ltd.
3-
Copyright 2023 The Matrix.org Foundation C.I.C.
4-
Copyright 2022 Michael Telatynski <[email protected]>
5-
6-
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
7-
Please see LICENSE files in the repository root for full details.
8-
*/
9-
10-
import React, { useContext, useEffect, useState } from "react";
11-
import {
12-
VerificationPhase as Phase,
13-
VerificationRequest,
14-
VerificationRequestEvent,
15-
CryptoEvent,
16-
} from "matrix-js-sdk/src/crypto-api";
17-
18-
import { useTypedEventEmitter, useTypedEventEmitterState } from "../../../../hooks/useEventEmitter";
19-
import { _t, _td, TranslationKey } from "../../../../languageHandler";
20-
import MatrixClientContext from "../../../../contexts/MatrixClientContext";
21-
import BaseTool, { DevtoolsContext, IDevtoolsProps } from "./BaseTool";
22-
import { Tool } from "../DevtoolsDialog";
23-
24-
const PHASE_MAP: Record<Phase, TranslationKey> = {
25-
[Phase.Unsent]: _td("common|unsent"),
26-
[Phase.Requested]: _td("devtools|phase_requested"),
27-
[Phase.Ready]: _td("devtools|phase_ready"),
28-
[Phase.Done]: _td("action|done"),
29-
[Phase.Started]: _td("devtools|phase_started"),
30-
[Phase.Cancelled]: _td("devtools|phase_cancelled"),
31-
};
32-
33-
const VerificationRequestExplorer: React.FC<{
34-
txnId: string;
35-
request: VerificationRequest;
36-
}> = ({ txnId, request }) => {
37-
const [, updateState] = useState();
38-
const [timeout, setRequestTimeout] = useState(request.timeout);
39-
40-
/* Re-render if something changes state */
41-
useTypedEventEmitter(request, VerificationRequestEvent.Change, updateState);
42-
43-
/* Keep re-rendering if there's a timeout */
44-
useEffect(() => {
45-
if (request.timeout == 0) return;
46-
47-
/* Note that request.timeout is a getter, so its value changes */
48-
const id = window.setInterval(() => {
49-
setRequestTimeout(request.timeout);
50-
}, 500);
51-
52-
return () => {
53-
clearInterval(id);
54-
};
55-
}, [request]);
56-
57-
return (
58-
<div className="mx_DevTools_VerificationRequest">
59-
<dl>
60-
<dt>{_t("devtools|phase_transaction")}</dt>
61-
<dd>{txnId}</dd>
62-
<dt>{_t("devtools|phase")}</dt>
63-
<dd>{PHASE_MAP[request.phase] ? _t(PHASE_MAP[request.phase]) : request.phase}</dd>
64-
<dt>{_t("devtools|timeout")}</dt>
65-
<dd>{timeout === null ? _t("devtools|timeout_none") : Math.floor(timeout / 1000)}</dd>
66-
<dt>{_t("devtools|methods")}</dt>
67-
<dd>{request.methods && request.methods.join(", ")}</dd>
68-
<dt>{_t("devtools|other_user")}</dt>
69-
<dd>{request.otherUserId}</dd>
70-
</dl>
71-
</div>
72-
);
73-
};
74-
75-
const VerificationExplorer: Tool = ({ onBack }: IDevtoolsProps) => {
76-
const cli = useContext(MatrixClientContext);
77-
const context = useContext(DevtoolsContext);
78-
79-
const requests = useTypedEventEmitterState(cli, CryptoEvent.VerificationRequestReceived, () => {
80-
return (
81-
cli.crypto?.inRoomVerificationRequests["requestsByRoomId"]?.get(context.room.roomId) ??
82-
new Map<string, VerificationRequest>()
83-
);
84-
});
85-
86-
return (
87-
<BaseTool onBack={onBack}>
88-
{Array.from(requests.entries())
89-
.reverse()
90-
.map(([txnId, request]) => (
91-
<VerificationRequestExplorer txnId={txnId} request={request} key={txnId} />
92-
))}
93-
{requests.size < 1 && _t("devtools|no_verification_requests_found")}
94-
</BaseTool>
95-
);
96-
};
97-
98-
export default VerificationExplorer;

src/i18n/strings/en_EN.json

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,6 @@
579579
"unmute": "Unmute",
580580
"unnamed_room": "Unnamed Room",
581581
"unnamed_space": "Unnamed Space",
582-
"unsent": "Unsent",
583582
"unverified": "Unverified",
584583
"updating": "Updating...",
585584
"user": "User",
@@ -764,20 +763,11 @@
764763
"low_bandwidth_mode": "Low bandwidth mode",
765764
"low_bandwidth_mode_description": "Requires compatible homeserver.",
766765
"main_timeline": "Main timeline",
767-
"methods": "Methods",
768766
"no_receipt_found": "No receipt found",
769-
"no_verification_requests_found": "No verification requests found",
770767
"notification_state": "Notification state is <strong>%(notificationState)s</strong>",
771768
"notifications_debug": "Notifications debug",
772769
"number_of_users": "Number of users",
773770
"original_event_source": "Original event source",
774-
"other_user": "Other user",
775-
"phase": "Phase",
776-
"phase_cancelled": "Cancelled",
777-
"phase_ready": "Ready",
778-
"phase_requested": "Requested",
779-
"phase_started": "Started",
780-
"phase_transaction": "Transaction",
781771
"room_encrypted": "Room is <strong>encrypted ✅</strong>",
782772
"room_id": "Room ID: %(roomId)s",
783773
"room_not_encrypted": "Room is <strong>not encrypted 🚨</strong>",
@@ -815,8 +805,6 @@
815805
"state_key": "State Key",
816806
"thread_root_id": "Thread Root ID: %(threadRootId)s",
817807
"threads_timeline": "Threads timeline",
818-
"timeout": "Timeout",
819-
"timeout_none": "None",
820808
"title": "Developer tools",
821809
"toggle_event": "toggle event",
822810
"toolbox": "Toolbox",
@@ -833,7 +821,6 @@
833821
"values_explicit_colon": "Values at explicit levels:",
834822
"values_explicit_room": "Values at explicit levels in this room",
835823
"values_explicit_this_room_colon": "Values at explicit levels in this room:",
836-
"verification_explorer": "Verification explorer",
837824
"view_servers_in_room": "View servers in room",
838825
"view_source_decrypted_event_source": "Decrypted event source",
839826
"view_source_decrypted_event_source_unavailable": "Decrypted source unavailable",
@@ -3038,7 +3025,6 @@
30383025
"rageshake": "Send a bug report with logs",
30393026
"rainbow": "Sends the given message coloured as a rainbow",
30403027
"rainbowme": "Sends the given emote coloured as a rainbow",
3041-
"remakeolm": "Developer command: Discards the current outbound group session and sets up new Olm sessions",
30423028
"remove": "Removes user with given id from this room",
30433029
"roomavatar": "Changes the avatar of the current room",
30443030
"roomname": "Sets the room name",

src/stores/SetupEncryptionStore.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ export class SetupEncryptionStore extends EventEmitter {
284284
public done(): void {
285285
this.phase = Phase.Finished;
286286
this.emit("update");
287-
// async - ask other clients for keys, if necessary
288-
MatrixClientPeg.safeGet().crypto?.cancelAndResendAllOutgoingKeyRequests();
289287
}
290288

291289
private async setActiveVerificationRequest(request: VerificationRequest): Promise<void> {

src/stores/widgets/StopGapWidgetDriver.ts

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -414,55 +414,6 @@ export class StopGapWidgetDriver extends WidgetDriver {
414414
await client._unstable_updateDelayedEvent(delayId, action);
415415
}
416416

417-
public async sendToDevice(
418-
eventType: string,
419-
encrypted: boolean,
420-
contentMap: { [userId: string]: { [deviceId: string]: object } },
421-
): Promise<void> {
422-
const client = MatrixClientPeg.safeGet();
423-
424-
if (encrypted) {
425-
const deviceInfoMap = await client.crypto!.deviceList.downloadKeys(Object.keys(contentMap), false);
426-
427-
await Promise.all(
428-
Object.entries(contentMap).flatMap(([userId, userContentMap]) =>
429-
Object.entries(userContentMap).map(async ([deviceId, content]): Promise<void> => {
430-
const devices = deviceInfoMap.get(userId);
431-
if (!devices) return;
432-
433-
if (deviceId === "*") {
434-
// Send the message to all devices we have keys for
435-
await client.encryptAndSendToDevices(
436-
Array.from(devices.values()).map((deviceInfo) => ({
437-
userId,
438-
deviceInfo,
439-
})),
440-
content,
441-
);
442-
} else if (devices.has(deviceId)) {
443-
// Send the message to a specific device
444-
await client.encryptAndSendToDevices(
445-
[{ userId, deviceInfo: devices.get(deviceId)! }],
446-
content,
447-
);
448-
}
449-
}),
450-
),
451-
);
452-
} else {
453-
await client.queueToDevice({
454-
eventType,
455-
batch: Object.entries(contentMap).flatMap(([userId, userContentMap]) =>
456-
Object.entries(userContentMap).map(([deviceId, content]) => ({
457-
userId,
458-
deviceId,
459-
payload: content,
460-
})),
461-
),
462-
});
463-
}
464-
}
465-
466417
private pickRooms(roomIds?: (string | Symbols.AnyRoom)[]): Room[] {
467418
const client = MatrixClientPeg.get();
468419
if (!client) throw new Error("Not attached to a client");

test/test-utils/test-utils.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,6 @@ export function createTestClient(): MatrixClient {
119119
removeRoom: jest.fn(),
120120
},
121121

122-
crypto: {
123-
deviceList: {
124-
downloadKeys: jest.fn(),
125-
},
126-
},
127122
getCrypto: jest.fn().mockReturnValue({
128123
getOwnDeviceKeys: jest.fn(),
129124
getUserDeviceInfo: jest.fn(),

test/unit-tests/SlashCommands-test.tsx

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -236,50 +236,6 @@ describe("SlashCommands", () => {
236236
});
237237
});
238238

239-
describe("/remakeolm", () => {
240-
beforeEach(() => {
241-
command = findCommand("remakeolm")!;
242-
});
243-
244-
describe("isEnabled", () => {
245-
describe("when developer mode is enabled", () => {
246-
beforeEach(() => {
247-
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName: string) => {
248-
if (settingName === "developerMode") return true;
249-
});
250-
});
251-
252-
it("should return true for Room", () => {
253-
setCurrentRoom();
254-
expect(command.isEnabled(client)).toBe(true);
255-
});
256-
257-
it("should return false for LocalRoom", () => {
258-
setCurrentLocalRoom();
259-
expect(command.isEnabled(client)).toBe(false);
260-
});
261-
});
262-
263-
describe("when developer mode is not enabled", () => {
264-
beforeEach(() => {
265-
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName: string) => {
266-
if (settingName === "developerMode") return false;
267-
});
268-
});
269-
270-
it("should return false for Room", () => {
271-
setCurrentRoom();
272-
expect(command.isEnabled(client)).toBe(false);
273-
});
274-
275-
it("should return false for LocalRoom", () => {
276-
setCurrentLocalRoom();
277-
expect(command.isEnabled(client)).toBe(false);
278-
});
279-
});
280-
});
281-
});
282-
283239
describe("/part", () => {
284240
it("should part room matching alias if found", async () => {
285241
const room1 = new Room("room-id", client, client.getSafeUserId());

test/unit-tests/components/views/dialogs/__snapshots__/DevtoolsDialog-test.tsx.snap

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ exports[`DevtoolsDialog renders the devtools dialog 1`] = `
7575
>
7676
Notifications debug
7777
</button>
78-
<button
79-
class="mx_DevTools_button"
80-
>
81-
Verification explorer
82-
</button>
8378
<button
8479
class="mx_DevTools_button"
8580
>

test/unit-tests/components/views/settings/devices/LoginWithQR-test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ function makeClient() {
5151
},
5252
getClientWellKnown: jest.fn().mockReturnValue({}),
5353
getCrypto: jest.fn().mockReturnValue({}),
54-
crypto: {},
5554
} as unknown as MatrixClient);
5655
}
5756

@@ -194,7 +193,6 @@ describe("<LoginWithQR />", () => {
194193
});
195194

196195
test("approve - no crypto", async () => {
197-
(client as any).crypto = undefined;
198196
(client as any).getCrypto = () => undefined;
199197
const onFinished = jest.fn();
200198
render(getComponent({ client, onFinished }));

0 commit comments

Comments
 (0)