expose whether we already have a 4s key,to show the 4s setup in settings

it's a tri-state of null/false/true with null meaning we need to
go online first to know as only then we try to setup session backup
This commit is contained in:
Bruno Windels 2020-10-23 12:57:47 +02:00
parent df72e829bf
commit df8eed14aa
3 changed files with 20 additions and 1 deletions

View file

@ -23,6 +23,9 @@ export class SessionBackupViewModel extends ViewModel {
this._showKeySetup = true; this._showKeySetup = true;
this._error = null; this._error = null;
this._isBusy = false; this._isBusy = false;
this.track(this._session.hasSecretStorageKey.subscribe(() => {
this.emitChange("status");
}));
} }
get isBusy() { get isBusy() {
@ -37,7 +40,11 @@ export class SessionBackupViewModel extends ViewModel {
if (this._session.sessionBackup) { if (this._session.sessionBackup) {
return "enabled"; return "enabled";
} else { } else {
if (this._session.hasSecretStorageKey.get() === false) {
return this._showKeySetup ? "setupKey" : "setupPhrase"; return this._showKeySetup ? "setupKey" : "setupPhrase";
} else {
return "pending";
}
} }
} }

View file

@ -63,6 +63,7 @@ export class Session {
this._olmWorker = olmWorker; this._olmWorker = olmWorker;
this._cryptoDriver = cryptoDriver; this._cryptoDriver = cryptoDriver;
this._sessionBackup = null; this._sessionBackup = null;
this._hasSecretStorageKey = new ObservableValue(null);
if (olm) { if (olm) {
this._olmUtil = new olm.Utility(); this._olmUtil = new olm.Utility();
@ -82,6 +83,10 @@ export class Session {
return this._e2eeAccount?.identityKeys.ed25519; return this._e2eeAccount?.identityKeys.ed25519;
} }
get hasSecretStorageKey() {
return this._hasSecretStorageKey;
}
get deviceId() { get deviceId() {
return this._sessionInfo.deviceId; return this._sessionInfo.deviceId;
} }
@ -175,6 +180,9 @@ export class Session {
if (!this._olm) { if (!this._olm) {
throw new Error("olm required"); throw new Error("olm required");
} }
if (this._sessionBackup) {
return false;
}
const key = await ssssKeyFromCredential(type, credential, this._storage, this._cryptoDriver, this._olm); const key = await ssssKeyFromCredential(type, credential, this._storage, this._cryptoDriver, this._olm);
// and create session backup, which needs to read from accountData // and create session backup, which needs to read from accountData
const readTxn = this._storage.readTxn([ const readTxn = this._storage.readTxn([
@ -193,6 +201,7 @@ export class Session {
throw err; throw err;
} }
await writeTxn.complete(); await writeTxn.complete();
this._hasSecretStorageKey.set(true);
} }
async _createSessionBackup(ssssKey, txn) { async _createSessionBackup(ssssKey, txn) {
@ -297,6 +306,7 @@ export class Session {
// txn will end here as this does a network request // txn will end here as this does a network request
await this._createSessionBackup(ssssKey, txn); await this._createSessionBackup(ssssKey, txn);
} }
this._hasSecretStorageKey.set(!!ssssKey);
} }
// restore unfinished operations, like sending out room keys // restore unfinished operations, like sending out room keys
const opsTxn = this._storage.readWriteTxn([ const opsTxn = this._storage.readWriteTxn([

View file

@ -15,6 +15,7 @@ limitations under the License.
*/ */
import {TemplateView} from "../../general/TemplateView.js"; import {TemplateView} from "../../general/TemplateView.js";
import {StaticView} from "../../general/StaticView.js";
export class SessionBackupSettingsView extends TemplateView { export class SessionBackupSettingsView extends TemplateView {
render(t, vm) { render(t, vm) {
@ -23,6 +24,7 @@ export class SessionBackupSettingsView extends TemplateView {
case "enabled": return new TemplateView(vm, renderEnabled) case "enabled": return new TemplateView(vm, renderEnabled)
case "setupKey": return new TemplateView(vm, renderEnableFromKey) case "setupKey": return new TemplateView(vm, renderEnableFromKey)
case "setupPhrase": return new TemplateView(vm, renderEnableFromPhrase) case "setupPhrase": return new TemplateView(vm, renderEnableFromPhrase)
case "pending": return new StaticView(vm, t => t.p(vm.i18n`Waiting to go online…`))
} }
}); });
} }