You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-05 17:02:07 +03:00
userId must be included in exported data
This commit is contained in:
@@ -101,7 +101,8 @@ function keyFromRecoverySession(session, decryptionKey) {
|
|||||||
* @param {Object} opts.deviceToImport Device data exported with
|
* @param {Object} opts.deviceToImport Device data exported with
|
||||||
* (TODO link to export method) that must be imported to recreate this device.
|
* (TODO link to export method) that must be imported to recreate this device.
|
||||||
* Should only be useful for deviced with end-to-end crypto enabled.
|
* Should only be useful for deviced with end-to-end crypto enabled.
|
||||||
* If provided, opts.userId should **not** be provided.
|
* If provided, opts.deviceId and opts.userId should **NOT** be provided
|
||||||
|
* (they are present in the exported data).
|
||||||
*
|
*
|
||||||
* @param {IdentityServerProvider} [opts.identityServer]
|
* @param {IdentityServerProvider} [opts.identityServer]
|
||||||
* Optional. A provider object with one function `getAccessToken`, which is a
|
* Optional. A provider object with one function `getAccessToken`, which is a
|
||||||
@@ -248,23 +249,26 @@ export function MatrixClient(opts) {
|
|||||||
|
|
||||||
this.deviceId = opts.deviceId || null;
|
this.deviceId = opts.deviceId || null;
|
||||||
|
|
||||||
if (opts.deviceToImport) {
|
|
||||||
if (this.deviceId) {
|
|
||||||
logger.warn('not importing device because device ID is provided to constructor independently of exported data');
|
|
||||||
} else if (!(opts.deviceToImport.deviceId)){
|
|
||||||
logger.warn('not importing device because no device ID in exported data');
|
|
||||||
} else {
|
|
||||||
this.deviceId = opts.deviceToImport.deviceId;
|
|
||||||
// will be used during async initialization of the crypto
|
|
||||||
this._exportedOlmDeviceToImport = opts.deviceToImport.olmDevice;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const userId = (opts.userId || null);
|
const userId = (opts.userId || null);
|
||||||
this.credentials = {
|
this.credentials = {
|
||||||
userId: userId,
|
userId: userId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (opts.deviceToImport) {
|
||||||
|
if (this.deviceId) {
|
||||||
|
logger.warn('not importing device because device ID is provided to constructor independently of exported data');
|
||||||
|
} else if (this.credentials.userId) {
|
||||||
|
logger.warn('not importing device because user ID is provided to constructor independently of exported data');
|
||||||
|
} else if (!(opts.deviceToImport.deviceId)){
|
||||||
|
logger.warn('not importing device because no device ID in exported data');
|
||||||
|
} else {
|
||||||
|
this.deviceId = opts.deviceToImport.deviceId;
|
||||||
|
this.credentials.userId = opts.deviceToImport.userId;
|
||||||
|
// will be used during async initialization of the crypto
|
||||||
|
this._exportedOlmDeviceToImport = opts.deviceToImport.olmDevice;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.scheduler = opts.scheduler;
|
this.scheduler = opts.scheduler;
|
||||||
if (this.scheduler) {
|
if (this.scheduler) {
|
||||||
const self = this;
|
const self = this;
|
||||||
@@ -414,6 +418,7 @@ MatrixClient.prototype.exportDevice = async function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
userId: this.credentials.userId,
|
||||||
deviceId: this.deviceId,
|
deviceId: this.deviceId,
|
||||||
olmDevice: await this._crypto._olmDevice.export(),
|
olmDevice: await this._crypto._olmDevice.export(),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user