From 09db599fe0d0ffd56b78b96856ba58b131e188b0 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Fri, 14 Feb 2025 10:59:02 +0000 Subject: [PATCH] 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. --- src/MatrixClientPeg.ts | 4 ++-- .../dialogs/security/CreateSecretStorageDialog.tsx | 4 ++-- src/stores/SetupEncryptionStore.ts | 4 ++-- src/utils/device/dehydration.ts | 11 ++++++----- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/MatrixClientPeg.ts b/src/MatrixClientPeg.ts index 81a73ffccc..9682b41800 100644 --- a/src/MatrixClientPeg.ts +++ b/src/MatrixClientPeg.ts @@ -41,7 +41,7 @@ import PlatformPeg from "./PlatformPeg"; import { formatList } from "./utils/FormattingUtils"; import SdkConfig from "./SdkConfig"; import { setDeviceIsolationMode } from "./settings/controllers/DeviceIsolationModeController.ts"; -import { initialiseDehydration } from "./utils/device/dehydration"; +import { initialiseDehydrationIfEnabled } from "./utils/device/dehydration"; export interface IMatrixClientCreds { homeserverUrl: string; @@ -347,7 +347,7 @@ class MatrixClientPegClass implements IMatrixClientPeg { // is a new login, we will start dehydration after Secret Storage is // unlocked. try { - await initialiseDehydration({ onlyIfKeyCached: true, rehydrate: false }, this.matrixClient); + await initialiseDehydrationIfEnabled(this.matrixClient, { onlyIfKeyCached: true, rehydrate: false }); } catch (e) { // We may get an error dehydrating, such as if cross-signing and // SSSS are not set up yet. Just log the error and continue. diff --git a/src/async-components/views/dialogs/security/CreateSecretStorageDialog.tsx b/src/async-components/views/dialogs/security/CreateSecretStorageDialog.tsx index 14ad5d3039..daefa267bc 100644 --- a/src/async-components/views/dialogs/security/CreateSecretStorageDialog.tsx +++ b/src/async-components/views/dialogs/security/CreateSecretStorageDialog.tsx @@ -37,7 +37,7 @@ import Spinner from "../../../../components/views/elements/Spinner"; import InteractiveAuthDialog from "../../../../components/views/dialogs/InteractiveAuthDialog"; import { type IValidationResult } from "../../../../components/views/elements/Validation"; import PassphraseConfirmField from "../../../../components/views/auth/PassphraseConfirmField"; -import { initialiseDehydration } from "../../../../utils/device/dehydration"; +import { initialiseDehydrationIfEnabled } from "../../../../utils/device/dehydration"; // I made a mistake while converting this and it has to be fixed! enum Phase { @@ -273,7 +273,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent { - client = client || MatrixClientPeg.safeGet(); +export async function initialiseDehydrationIfEnabled( + client: MatrixClient, + opts: StartDehydrationOpts = {}, +): Promise { const crypto = client.getCrypto(); if (await deviceDehydrationEnabled(client, crypto)) { logger.log("Device dehydration enabled");