@@ -9,7 +9,7 @@ import { useCallback, useEffect, useState } from "react";
9
9
import { logger } from "matrix-js-sdk/src/logger" ;
10
10
11
11
import { useMatrixClientContext } from "../../../../contexts/MatrixClientContext" ;
12
- import { BACKUP_DISABLED_ACCOUNT_DATA_KEY } from "../../../../DeviceListener" ;
12
+ import DeviceListener , { BACKUP_DISABLED_ACCOUNT_DATA_KEY } from "../../../../DeviceListener" ;
13
13
14
14
interface KeyStoragePanelState {
15
15
/**
@@ -67,6 +67,12 @@ export function useKeyStoragePanelViewModel(): KeyStoragePanelState {
67
67
async ( enable : boolean ) => {
68
68
setPendingValue ( enable ) ;
69
69
try {
70
+ // stop the device listener since enabling or (especially) disabling key storage must be
71
+ // done with a sequence of API calls that will put the account in a slightly different
72
+ // state each time, so suppress any warning toasts until the process is finished (when
73
+ // we'll turn it back on again.)
74
+ DeviceListener . sharedInstance ( ) . stop ( ) ;
75
+
70
76
const crypto = matrixClient . getCrypto ( ) ;
71
77
if ( ! crypto ) {
72
78
logger . error ( "Can't change key backup status: no crypto module available" ) ;
@@ -85,34 +91,11 @@ export function useKeyStoragePanelViewModel(): KeyStoragePanelState {
85
91
// Set the flag so that EX no longer thinks the user wants backup disabled
86
92
await matrixClient . setAccountData ( BACKUP_DISABLED_ACCOUNT_DATA_KEY , { disabled : false } ) ;
87
93
} else {
88
- // Get the key backup version we're using
89
- const info = await crypto . getKeyBackupInfo ( ) ;
90
- if ( ! info ?. version ) {
91
- logger . error ( "Can't delete key backup version: no version available" ) ;
92
- return ;
93
- }
94
-
95
- // Bye bye backup
96
- await crypto . deleteKeyBackupVersion ( info . version ) ;
97
-
98
- // also turn off 4S, since this is also storing keys on the server.
99
- // Delete the cross signing keys from secret storage
100
- await matrixClient . deleteAccountData ( "m.cross_signing.master" ) ;
101
- await matrixClient . deleteAccountData ( "m.cross_signing.self_signing" ) ;
102
- await matrixClient . deleteAccountData ( "m.cross_signing.user_signing" ) ;
103
- // and the key backup key (we just turned it off anyway)
104
- await matrixClient . deleteAccountData ( "m.megolm_backup.v1" ) ;
105
-
106
- // Delete the key information
107
- const defaultKey = await matrixClient . secretStorage . getDefaultKeyId ( ) ;
108
- if ( defaultKey ) {
109
- await matrixClient . deleteAccountData ( `m.secret_storage.key.${ defaultKey } ` ) ;
110
-
111
- // ...and the default key pointer
112
- await matrixClient . deleteAccountData ( "m.secret_storage.default_key" ) ;
113
- }
94
+ // This method will delete the key backup as well as server side recovery keys and other
95
+ // server-side crypto data.
96
+ await crypto . disableKeyStorage ( ) ;
114
97
115
- // finally, set a flag to say that the user doesn't want key backup.
98
+ // Set a flag to say that the user doesn't want key backup.
116
99
// Element X uses this to determine whether to set up automatically,
117
100
// so this will stop EX turning it back on spontaneously.
118
101
await matrixClient . setAccountData ( BACKUP_DISABLED_ACCOUNT_DATA_KEY , { disabled : true } ) ;
@@ -121,6 +104,7 @@ export function useKeyStoragePanelViewModel(): KeyStoragePanelState {
121
104
await checkStatus ( ) ;
122
105
} finally {
123
106
setPendingValue ( undefined ) ;
107
+ DeviceListener . sharedInstance ( ) . start ( matrixClient ) ;
124
108
}
125
109
} ,
126
110
[ setPendingValue , checkStatus , matrixClient ] ,
0 commit comments