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.
This commit is contained in:
Richard van der Hoff
2025-02-14 10:59:02 +00:00
committed by GitHub
parent c47ce59478
commit 09db599fe0
4 changed files with 12 additions and 11 deletions

View File

@@ -10,7 +10,6 @@ import { logger } from "matrix-js-sdk/src/logger";
import { type CryptoApi, type StartDehydrationOpts } from "matrix-js-sdk/src/crypto-api";
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import { MatrixClientPeg } from "../../MatrixClientPeg";
/**
* Check if device dehydration is enabled.
@@ -38,11 +37,13 @@ async function deviceDehydrationEnabled(client: MatrixClient, crypto: CryptoApi
* the configuration), rehydrate a device (if available) and create
* a new dehydrated device.
*
* @param createNewKey: force a new dehydration key to be created, even if one
* already exists. This is used when we reset secret storage.
* @param client - MatrixClient to use for the operation
* @param opts - options for the startDehydration operation, if one is performed.
*/
export async function initialiseDehydration(opts: StartDehydrationOpts = {}, client?: MatrixClient): Promise<void> {
client = client || MatrixClientPeg.safeGet();
export async function initialiseDehydrationIfEnabled(
client: MatrixClient,
opts: StartDehydrationOpts = {},
): Promise<void> {
const crypto = client.getCrypto();
if (await deviceDehydrationEnabled(client, crypto)) {
logger.log("Device dehydration enabled");