distinguish between "waiting to go online" vs "backup not configured"

This commit is contained in:
Bruno Windels 2022-02-01 11:08:13 +01:00
parent 997666164c
commit fd4eb6b50d
2 changed files with 18 additions and 7 deletions

View file

@ -53,12 +53,11 @@ export class KeyBackupViewModel extends ViewModel {
const keyBackup = this._session.keyBackup.get();
if (keyBackup) {
status = keyBackup.needsNewKey ? Status.NewVersionAvailable : Status.Enabled;
} else {
} else if (keyBackup === null) {
status = this.showPhraseSetup() ? Status.SetupPhrase : Status.SetupKey;
} /* TODO: bring back "waiting to get online"
else {
} else {
status = Status.Pending;
} */
}
const changed = status !== this._status;
this._status = status;
return changed;

View file

@ -289,9 +289,15 @@ export class Session {
} catch (err) {
log.catch(err);
}
return false;
});
}
/**
* @type {ObservableValue<KeyBackup | undefined | null}
* - `undefined` means, we're not done with catchup sync yet and haven't checked yet if key backup is configured
* - `null` means we've checked and key backup hasn't been configured correctly or at all.
*/
get keyBackup() {
return this._keyBackup;
}
@ -468,7 +474,7 @@ export class Session {
log.set("success", true);
await this._writeSSSSKey(ssssKey);
}
})
});
}
const txn = await this._storage.readTxn([
this._storage.storeNames.session,
@ -478,10 +484,16 @@ export class Session {
const ssssKey = await ssssReadKey(txn);
if (ssssKey) {
// txn will end here as this does a network request
await this._createKeyBackup(ssssKey, txn, log);
if (await this._createKeyBackup(ssssKey, txn, log)) {
this._keyBackup.get()?.flush(log);
}
}
if (!this._keyBackup.get()) {
// null means key backup isn't configured yet
// as opposed to undefined, which means we're still checking
this._keyBackup.set(null);
}
}
// restore unfinished operations, like sending out room keys
const opsTxn = await this._storage.readWriteTxn([
this._storage.storeNames.operations