diff --git a/src/components/views/settings/SecureBackupPanel.tsx b/src/components/views/settings/SecureBackupPanel.tsx
index 18c2ee6e90a..a0416d01a55 100644
--- a/src/components/views/settings/SecureBackupPanel.tsx
+++ b/src/components/views/settings/SecureBackupPanel.tsx
@@ -16,10 +16,9 @@ limitations under the License.
*/
import React, { ReactNode } from "react";
-import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup";
-import { TrustInfo } from "matrix-js-sdk/src/crypto/backup";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import { logger } from "matrix-js-sdk/src/logger";
+import { BackupTrustInfo, KeyBackupInfo } from "matrix-js-sdk/src/crypto-api";
import type CreateKeyBackupDialog from "../../../async-components/views/dialogs/security/CreateKeyBackupDialog";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
@@ -41,9 +40,34 @@ interface IState {
backupKeyWellFormed: boolean | null;
secretStorageKeyInAccount: boolean | null;
secretStorageReady: boolean | null;
- backupInfo: IKeyBackupInfo | null;
- backupSigStatus: TrustInfo | null;
- sessionsRemaining: number;
+
+ /** Information on the current key backup version, as returned by the server.
+ *
+ * `null` could mean any of:
+ * * we haven't yet requested the data from the server.
+ * * we were unable to reach the server.
+ * * the server returned key backup version data we didn't understand or was malformed.
+ * * there is actually no backup on the server.
+ */
+ backupInfo: KeyBackupInfo | null;
+
+ /**
+ * Information on whether the backup in `backupInfo` is correctly signed, and whether we have the right key to
+ * decrypt it.
+ *
+ * `undefined` if `backupInfo` is null, or if crypto is not enabled in the client.
+ */
+ backupTrustInfo: BackupTrustInfo | undefined;
+
+ /**
+ * If key backup is currently enabled, the backup version we are backing up to.
+ */
+ activeBackupVersion: string | null;
+
+ /**
+ * Number of sessions remaining to be backed up. `null` if we have no information on this.
+ */
+ sessionsRemaining: number | null;
}
export default class SecureBackupPanel extends React.PureComponent<{}, IState> {
@@ -61,8 +85,9 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> {
secretStorageKeyInAccount: null,
secretStorageReady: null,
backupInfo: null,
- backupSigStatus: null,
- sessionsRemaining: 0,
+ backupTrustInfo: undefined,
+ activeBackupVersion: null,
+ sessionsRemaining: null,
};
}
@@ -101,14 +126,19 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> {
this.setState({ loading: true });
this.getUpdatedDiagnostics();
try {
- const backupInfo = await MatrixClientPeg.safeGet().getKeyBackupVersion();
- const backupSigStatus = backupInfo ? await MatrixClientPeg.safeGet().isKeyBackupTrusted(backupInfo) : null;
+ const cli = MatrixClientPeg.safeGet();
+ const backupInfo = await cli.getKeyBackupVersion();
+ const backupTrustInfo = backupInfo ? await cli.getCrypto()?.isKeyBackupTrusted(backupInfo) : undefined;
+
+ const activeBackupVersion = (await cli.getCrypto()?.getActiveSessionBackupVersion()) ?? null;
+
if (this.unmounted) return;
this.setState({
loading: false,
error: false,
backupInfo,
- backupSigStatus,
+ backupTrustInfo,
+ activeBackupVersion,
});
} catch (e) {
logger.log("Unable to fetch key backup status", e);
@@ -117,7 +147,8 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> {
loading: false,
error: true,
backupInfo: null,
- backupSigStatus: null,
+ backupTrustInfo: undefined,
+ activeBackupVersion: null,
});
}
}
@@ -173,8 +204,10 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> {
onFinished: (proceed) => {
if (!proceed) return;
this.setState({ loading: true });
+ const versionToDelete = this.state.backupInfo!.version!;
MatrixClientPeg.safeGet()
- .deleteKeyBackupVersion(this.state.backupInfo!.version!)
+ .getCrypto()
+ ?.deleteKeyBackupVersion(versionToDelete)
.then(() => {
this.loadBackupStatus();
});
@@ -209,7 +242,7 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> {
secretStorageKeyInAccount,
secretStorageReady,
backupInfo,
- backupSigStatus,
+ backupTrustInfo,
sessionsRemaining,
} = this.state;
@@ -228,7 +261,7 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> {
} else if (backupInfo) {
let restoreButtonCaption = _t("Restore from Backup");
- if (MatrixClientPeg.safeGet().getKeyBackupEnabled()) {
+ if (this.state.activeBackupVersion !== null) {
statusDescription = (
{backupInfo.algorithm}
)
+
+ test
+
+ )