1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

split up setKey and setKeyAndQueue

as dehydrating in the background prevents use-cases where you
want to await the creation of the dehydrated device
This commit is contained in:
Bruno Windels
2020-11-04 16:01:25 +01:00
parent 4ab675863a
commit 13c7f55a79
2 changed files with 16 additions and 4 deletions

View File

@@ -577,7 +577,7 @@ MatrixClient.prototype.setDehydrationKey = async function(
logger.warn('not dehydrating device if crypto is not enabled'); logger.warn('not dehydrating device if crypto is not enabled');
return; return;
} }
return await this._crypto._dehydrationManager.setDehydrationKey( return await this._crypto._dehydrationManager.setKeyAndQueue(
key, keyInfo, deviceDisplayName, key, keyInfo, deviceDisplayName,
); );
}; };

View File

@@ -77,10 +77,23 @@ export class DehydrationManager {
}, },
); );
} }
async setDehydrationKey(
/** set the key, and queue periodic dehydration to the server in the background */
async setKeyAndQueueDehydration(
key: Uint8Array, keyInfo: {[props: string]: any} = {}, key: Uint8Array, keyInfo: {[props: string]: any} = {},
deviceDisplayName: string = undefined, deviceDisplayName: string = undefined,
): Promise<void> { ): Promise<void> {
const matches = await this.setKey(key, keyInfo, deviceDisplayName);
if (!matches) {
// start dehydration in the background
this.dehydrateDevice();
}
}
async setKey(
key: Uint8Array, keyInfo: {[props: string]: any} = {},
deviceDisplayName: string = undefined,
): Promise<boolean> {
if (!key) { if (!key) {
// unsetting the key -- cancel any pending dehydration task // unsetting the key -- cancel any pending dehydration task
if (this.timeoutId) { if (this.timeoutId) {
@@ -116,9 +129,8 @@ export class DehydrationManager {
this.key = key; this.key = key;
this.keyInfo = keyInfo; this.keyInfo = keyInfo;
this.deviceDisplayName = deviceDisplayName; this.deviceDisplayName = deviceDisplayName;
// start dehydration in the background
this.dehydrateDevice();
} }
return matches;
} }
private async dehydrateDevice(): Promise<void> { private async dehydrateDevice(): Promise<void> {
if (this.inProgress) { if (this.inProgress) {