@@ -318,6 +318,7 @@ export interface ServerSideSecretStorage {
318
318
319
319
/**
320
320
* Set the default key ID for encrypting secrets.
321
+ *
321
322
* If keyId is `null`, the default key id value in the account data will be set to an empty object.
322
323
* This is considered as "disabling" the default key.
323
324
*
@@ -367,19 +368,26 @@ export class ServerSideSecretStorageImpl implements ServerSideSecretStorage {
367
368
public setDefaultKeyId ( keyId : string | null ) : Promise < void > {
368
369
return new Promise < void > ( ( resolve , reject ) => {
369
370
const listener = ( ev : MatrixEvent ) : void => {
371
+ if ( ev . getType ( ) !== "m.secret_storage.default_key" ) {
372
+ // Different account data item
373
+ return ;
374
+ }
375
+
370
376
const content = ev . getContent ( ) ;
377
+ // If keyId === null, the content should be an empty object.
378
+ // Otherwise, keyId should be returned in the content object.
371
379
const isSameKey = keyId === null ? ! Object . keys ( content ) . length : content . key === keyId ;
372
- if ( ev . getType ( ) === "m.secret_storage.default_key" && isSameKey ) {
380
+ if ( isSameKey ) {
373
381
this . accountDataAdapter . removeListener ( ClientEvent . AccountData , listener ) ;
374
382
resolve ( ) ;
375
383
}
376
384
} ;
377
385
this . accountDataAdapter . on ( ClientEvent . AccountData , listener ) ;
378
386
379
- // The spec says that the key should be an object with a `key` property
380
- // https://spec.matrix.org/v1.13/client-server-api/# key-storage
381
- // To delete the default key, we send an empty object like the rust sdk does
382
- // (see https://docs.rs/ matrix-sdk/latest/matrix_sdk/encryption/recovery/struct.Recovery.html#method.reset_identity)
387
+ // The spec [1] says that the value of the account data entry should be an object with a `key` property.
388
+ // It doesn't specify how to delete the default key; we do it by setting the account data to an empty object.
389
+ //
390
+ // [1]: https://spec. matrix.org/v1.13/client-server-api/#key-storage
383
391
const newValue : Record < string , never > | { key : string } = keyId === null ? { } : { key : keyId } ;
384
392
this . accountDataAdapter . setAccountData ( "m.secret_storage.default_key" , newValue ) . catch ( ( e ) => {
385
393
this . accountDataAdapter . removeListener ( ClientEvent . AccountData , listener ) ;
0 commit comments