You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
add client method for one-time dehydration that can be awaited
This commit is contained in:
@@ -582,6 +582,28 @@ MatrixClient.prototype.setDehydrationKey = async function(
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new dehydrated device (without queuing periodic dehydration)
|
||||
* @param {Uint8Array} key the dehydration key
|
||||
* @param {object} [keyInfo] Information about the key. Primarily for
|
||||
* information about how to generate the key from a passphrase.
|
||||
* @param {string} [deviceDisplayName] The device display name for the
|
||||
* dehydrated device.
|
||||
* @return {Promise<String>} the device id of the newly created dehydrated device
|
||||
*/
|
||||
MatrixClient.prototype.createDehydratedDevice = async function(
|
||||
key, keyInfo = {}, deviceDisplayName = undefined,
|
||||
) {
|
||||
if (!(this._crypto)) {
|
||||
logger.warn('not dehydrating device if crypto is not enabled');
|
||||
return;
|
||||
}
|
||||
await this._crypto._dehydrationManager.setKey(
|
||||
key, keyInfo, deviceDisplayName,
|
||||
);
|
||||
return await this._crypto._dehydrationManager.dehydrateDevice();
|
||||
};
|
||||
|
||||
MatrixClient.prototype.exportDevice = async function() {
|
||||
if (!(this._crypto)) {
|
||||
logger.warn('not exporting device if crypto is not enabled');
|
||||
|
||||
@@ -132,7 +132,9 @@ export class DehydrationManager {
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
private async dehydrateDevice(): Promise<void> {
|
||||
|
||||
/** returns the device id of the newly created dehydrated device */
|
||||
async dehydrateDevice(): Promise<string> {
|
||||
if (this.inProgress) {
|
||||
logger.log("Dehydration already in progress -- not starting new dehydration");
|
||||
return;
|
||||
@@ -270,6 +272,8 @@ export class DehydrationManager {
|
||||
this.timeoutId = global.setTimeout(
|
||||
this.dehydrateDevice.bind(this), oneweek,
|
||||
);
|
||||
|
||||
return deviceId;
|
||||
} finally {
|
||||
this.inProgress = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user