diff --git a/lib/components/dialogs/bootstrap_dialog.dart b/lib/components/dialogs/bootstrap_dialog.dart index 9ff7c9ea..80119066 100644 --- a/lib/components/dialogs/bootstrap_dialog.dart +++ b/lib/components/dialogs/bootstrap_dialog.dart @@ -10,11 +10,15 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'key_verification_dialog.dart'; + class BootstrapDialog extends StatefulWidget { + final bool wipe; const BootstrapDialog({ Key key, @required this.l10n, @required this.client, + this.wipe = false, }) : super(key: key); Future show(BuildContext context) => PlatformInfos.isCupertinoStyle @@ -42,7 +46,7 @@ class _BootstrapDialogState extends State { bool _recoveryKeyStored = false; - bool _wipe = false; + bool _wipe; void _createBootstrap(bool wipe) { setState(() { @@ -56,6 +60,7 @@ class _BootstrapDialogState extends State { @override Widget build(BuildContext context) { + _wipe ??= widget.wipe; final buttons = []; Widget body = LinearProgressIndicator(); titleText = widget.l10n.loadingPleaseWait; @@ -155,6 +160,19 @@ class _BootstrapDialogState extends State { } }, )); + buttons.add(AdaptiveFlatButton( + child: Text('Transfer from another device'), + onPressed: () async { + final req = await widget + .client.userDeviceKeys[widget.client.userID] + .startVerification(); + await KeyVerificationDialog( + request: req, + l10n: widget.l10n, + ).show(context); + Navigator.of(context).pop(); + }, + )); buttons.add(AdaptiveFlatButton( child: Text(widget.l10n.next), onPressed: () async { diff --git a/lib/views/settings.dart b/lib/views/settings.dart index 50ed5d24..1734cfaf 100644 --- a/lib/views/settings.dart +++ b/lib/views/settings.dart @@ -504,10 +504,28 @@ class _SettingsState extends State { trailing: Icon(Icons.wb_cloudy_outlined), subtitle: Text( '${client.encryption.keyManager.enabled ? L10n.of(context).onlineKeyBackupEnabled : L10n.of(context).onlineKeyBackupDisabled}\n${client.encryption.crossSigning.enabled ? L10n.of(context).crossSigningEnabled : L10n.of(context).crossSigningDisabled}'), - onTap: () => BootstrapDialog( - l10n: L10n.of(context), - client: Matrix.of(context).client, - ).show(context), + onTap: () async { + if (await client.encryption.keyManager.isCached()) { + if (OkCancelResult.ok == + await showOkCancelAlertDialog( + context: context, + title: L10n.of(context).keysCached, + message: + 'Wipe your chat backup to create a new security key?', + isDestructiveAction: true, + )) { + return BootstrapDialog( + l10n: L10n.of(context), + client: Matrix.of(context).client, + wipe: true, + ).show(context); + } + } + return BootstrapDialog( + l10n: L10n.of(context), + client: Matrix.of(context).client, + ).show(context); + }, ), }, Divider(thickness: 1),