mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
setup session backup as part of start method, so we know we're online
also don't upload OTKs in case of existing account until catchup sync has happened
This commit is contained in:
parent
08645c8bc0
commit
df72e829bf
@ -62,6 +62,7 @@ export class Session {
|
|||||||
this._getSyncToken = () => this.syncToken;
|
this._getSyncToken = () => this.syncToken;
|
||||||
this._olmWorker = olmWorker;
|
this._olmWorker = olmWorker;
|
||||||
this._cryptoDriver = cryptoDriver;
|
this._cryptoDriver = cryptoDriver;
|
||||||
|
this._sessionBackup = null;
|
||||||
|
|
||||||
if (olm) {
|
if (olm) {
|
||||||
this._olmUtil = new olm.Utility();
|
this._olmUtil = new olm.Utility();
|
||||||
@ -211,12 +212,9 @@ export class Session {
|
|||||||
return this._sessionBackup;
|
return this._sessionBackup;
|
||||||
}
|
}
|
||||||
|
|
||||||
// called after load
|
/** @internal */
|
||||||
async beforeFirstSync(isNewLogin) {
|
async createIdentity() {
|
||||||
if (this._olm) {
|
if (this._olm) {
|
||||||
if (isNewLogin && this._e2eeAccount) {
|
|
||||||
throw new Error("there should not be an e2ee account already on a fresh login");
|
|
||||||
}
|
|
||||||
if (!this._e2eeAccount) {
|
if (!this._e2eeAccount) {
|
||||||
this._e2eeAccount = await E2EEAccount.create({
|
this._e2eeAccount = await E2EEAccount.create({
|
||||||
hsApi: this._hsApi,
|
hsApi: this._hsApi,
|
||||||
@ -231,18 +229,6 @@ export class Session {
|
|||||||
}
|
}
|
||||||
await this._e2eeAccount.generateOTKsIfNeeded(this._storage);
|
await this._e2eeAccount.generateOTKsIfNeeded(this._storage);
|
||||||
await this._e2eeAccount.uploadKeys(this._storage);
|
await this._e2eeAccount.uploadKeys(this._storage);
|
||||||
await this._deviceMessageHandler.decryptPending(this.rooms);
|
|
||||||
|
|
||||||
const txn = this._storage.readTxn([
|
|
||||||
this._storage.storeNames.session,
|
|
||||||
this._storage.storeNames.accountData,
|
|
||||||
]);
|
|
||||||
// try set up session backup if we stored the ssss key
|
|
||||||
const ssssKey = await ssssReadKey(txn);
|
|
||||||
if (ssssKey) {
|
|
||||||
// txn will end here as this does a network request
|
|
||||||
await this._createSessionBackup(ssssKey, txn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,7 +285,20 @@ export class Session {
|
|||||||
// TODO: what can we do if this throws?
|
// TODO: what can we do if this throws?
|
||||||
await txn.complete();
|
await txn.complete();
|
||||||
}
|
}
|
||||||
|
// enable session backup, this requests the latest backup version
|
||||||
|
if (!this._sessionBackup) {
|
||||||
|
const txn = this._storage.readTxn([
|
||||||
|
this._storage.storeNames.session,
|
||||||
|
this._storage.storeNames.accountData,
|
||||||
|
]);
|
||||||
|
// try set up session backup if we stored the ssss key
|
||||||
|
const ssssKey = await ssssReadKey(txn);
|
||||||
|
if (ssssKey) {
|
||||||
|
// txn will end here as this does a network request
|
||||||
|
await this._createSessionBackup(ssssKey, txn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// restore unfinished operations, like sending out room keys
|
||||||
const opsTxn = this._storage.readWriteTxn([
|
const opsTxn = this._storage.readWriteTxn([
|
||||||
this._storage.storeNames.operations
|
this._storage.storeNames.operations
|
||||||
]);
|
]);
|
||||||
|
@ -179,8 +179,10 @@ export class SessionContainer {
|
|||||||
mediaRepository: new MediaRepository(sessionInfo.homeServer)
|
mediaRepository: new MediaRepository(sessionInfo.homeServer)
|
||||||
});
|
});
|
||||||
await this._session.load();
|
await this._session.load();
|
||||||
|
if (isNewLogin) {
|
||||||
this._status.set(LoadStatus.SessionSetup);
|
this._status.set(LoadStatus.SessionSetup);
|
||||||
await this._session.beforeFirstSync(isNewLogin);
|
await this._session.createIdentity();
|
||||||
|
}
|
||||||
|
|
||||||
this._sync = new Sync({hsApi: this._requestScheduler.hsApi, storage: this._storage, session: this._session});
|
this._sync = new Sync({hsApi: this._requestScheduler.hsApi, storage: this._storage, session: this._session});
|
||||||
// notify sync and session when back online
|
// notify sync and session when back online
|
||||||
|
Loading…
Reference in New Issue
Block a user