Skip to content

Commit 09db599

Browse files
authored
Minor cleanups to initialiseDehydration (#29261)
* dehydration: fix documentation * initialiseDehydration: improve name ... to make it clearer that it does nothing if dehydration is disabled * initialiseDehydration: remove dependency on MatrixClientPeg We're trying to move away from relying on `MatrixClientPeg` everywhere, and this is a particularly easy win.
1 parent c47ce59 commit 09db599

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/MatrixClientPeg.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import PlatformPeg from "./PlatformPeg";
4141
import { formatList } from "./utils/FormattingUtils";
4242
import SdkConfig from "./SdkConfig";
4343
import { setDeviceIsolationMode } from "./settings/controllers/DeviceIsolationModeController.ts";
44-
import { initialiseDehydration } from "./utils/device/dehydration";
44+
import { initialiseDehydrationIfEnabled } from "./utils/device/dehydration";
4545

4646
export interface IMatrixClientCreds {
4747
homeserverUrl: string;
@@ -347,7 +347,7 @@ class MatrixClientPegClass implements IMatrixClientPeg {
347347
// is a new login, we will start dehydration after Secret Storage is
348348
// unlocked.
349349
try {
350-
await initialiseDehydration({ onlyIfKeyCached: true, rehydrate: false }, this.matrixClient);
350+
await initialiseDehydrationIfEnabled(this.matrixClient, { onlyIfKeyCached: true, rehydrate: false });
351351
} catch (e) {
352352
// We may get an error dehydrating, such as if cross-signing and
353353
// SSSS are not set up yet. Just log the error and continue.

src/async-components/views/dialogs/security/CreateSecretStorageDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import Spinner from "../../../../components/views/elements/Spinner";
3737
import InteractiveAuthDialog from "../../../../components/views/dialogs/InteractiveAuthDialog";
3838
import { type IValidationResult } from "../../../../components/views/elements/Validation";
3939
import PassphraseConfirmField from "../../../../components/views/auth/PassphraseConfirmField";
40-
import { initialiseDehydration } from "../../../../utils/device/dehydration";
40+
import { initialiseDehydrationIfEnabled } from "../../../../utils/device/dehydration";
4141

4242
// I made a mistake while converting this and it has to be fixed!
4343
enum Phase {
@@ -273,7 +273,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
273273
setupNewKeyBackup: !backupInfo,
274274
});
275275
}
276-
await initialiseDehydration({ createNewKey: true });
276+
await initialiseDehydrationIfEnabled(cli, { createNewKey: true });
277277

278278
this.setState({
279279
phase: Phase.Stored,

src/stores/SetupEncryptionStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { type Device, type SecretStorage } from "matrix-js-sdk/src/matrix";
2020
import { MatrixClientPeg } from "../MatrixClientPeg";
2121
import { AccessCancelledError, accessSecretStorage } from "../SecurityManager";
2222
import { asyncSome } from "../utils/arrays";
23-
import { initialiseDehydration } from "../utils/device/dehydration";
23+
import { initialiseDehydrationIfEnabled } from "../utils/device/dehydration";
2424

2525
export enum Phase {
2626
Loading = 0,
@@ -149,7 +149,7 @@ export class SetupEncryptionStore extends EventEmitter {
149149
);
150150
resolve();
151151

152-
await initialiseDehydration();
152+
await initialiseDehydrationIfEnabled(cli);
153153

154154
if (backupInfo) {
155155
await cli.getCrypto()?.loadSessionBackupPrivateKeyFromSecretStorage();

src/utils/device/dehydration.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { logger } from "matrix-js-sdk/src/logger";
1010
import { type CryptoApi, type StartDehydrationOpts } from "matrix-js-sdk/src/crypto-api";
1111

1212
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
13-
import { MatrixClientPeg } from "../../MatrixClientPeg";
1413

1514
/**
1615
* Check if device dehydration is enabled.
@@ -38,11 +37,13 @@ async function deviceDehydrationEnabled(client: MatrixClient, crypto: CryptoApi
3837
* the configuration), rehydrate a device (if available) and create
3938
* a new dehydrated device.
4039
*
41-
* @param createNewKey: force a new dehydration key to be created, even if one
42-
* already exists. This is used when we reset secret storage.
40+
* @param client - MatrixClient to use for the operation
41+
* @param opts - options for the startDehydration operation, if one is performed.
4342
*/
44-
export async function initialiseDehydration(opts: StartDehydrationOpts = {}, client?: MatrixClient): Promise<void> {
45-
client = client || MatrixClientPeg.safeGet();
43+
export async function initialiseDehydrationIfEnabled(
44+
client: MatrixClient,
45+
opts: StartDehydrationOpts = {},
46+
): Promise<void> {
4647
const crypto = client.getCrypto();
4748
if (await deviceDehydrationEnabled(client, crypto)) {
4849
logger.log("Device dehydration enabled");

0 commit comments

Comments
 (0)