mirror of
https://github.com/vector-im/element-web.git
synced 2025-09-04 13:21:28 +02:00
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:
parent
c47ce59478
commit
09db599fe0
@ -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.
|
||||
|
@ -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<IProp
|
||||
setupNewKeyBackup: !backupInfo,
|
||||
});
|
||||
}
|
||||
await initialiseDehydration({ createNewKey: true });
|
||||
await initialiseDehydrationIfEnabled(cli, { createNewKey: true });
|
||||
|
||||
this.setState({
|
||||
phase: Phase.Stored,
|
||||
|
@ -20,7 +20,7 @@ import { type Device, type SecretStorage } from "matrix-js-sdk/src/matrix";
|
||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||
import { AccessCancelledError, accessSecretStorage } from "../SecurityManager";
|
||||
import { asyncSome } from "../utils/arrays";
|
||||
import { initialiseDehydration } from "../utils/device/dehydration";
|
||||
import { initialiseDehydrationIfEnabled } from "../utils/device/dehydration";
|
||||
|
||||
export enum Phase {
|
||||
Loading = 0,
|
||||
@ -149,7 +149,7 @@ export class SetupEncryptionStore extends EventEmitter {
|
||||
);
|
||||
resolve();
|
||||
|
||||
await initialiseDehydration();
|
||||
await initialiseDehydrationIfEnabled(cli);
|
||||
|
||||
if (backupInfo) {
|
||||
await cli.getCrypto()?.loadSessionBackupPrivateKeyFromSecretStorage();
|
||||
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user