refactor: Use getCryptoIdentityState to check backup state
This commit is contained in:
parent
5bcdd6d1b0
commit
66566e6901
4 changed files with 22 additions and 40 deletions
|
|
@ -3,6 +3,7 @@ import 'dart:math';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:matrix/encryption.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/setting_keys.dart';
|
import 'package:fluffychat/config/setting_keys.dart';
|
||||||
|
|
@ -57,7 +58,8 @@ class MessageContent extends StatelessWidget {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final client = Matrix.of(context).client;
|
final client = Matrix.of(context).client;
|
||||||
if (client.isUnknownSession && client.encryption!.crossSigning.enabled) {
|
final state = await client.getCryptoIdentityState();
|
||||||
|
if (!state.connected) {
|
||||||
final success = await context.push('/backup');
|
final success = await context.push('/backup');
|
||||||
if (success != true) return;
|
if (success != true) return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:collection/collection.dart' show IterableExtension;
|
import 'package:collection/collection.dart' show IterableExtension;
|
||||||
import 'package:matrix/encryption/utils/key_verification.dart';
|
import 'package:matrix/encryption.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
|
|
@ -40,16 +40,10 @@ class DevicesSettingsController extends State<DevicesSettings> {
|
||||||
|
|
||||||
void _checkChatBackup() async {
|
void _checkChatBackup() async {
|
||||||
final client = Matrix.of(context).client;
|
final client = Matrix.of(context).client;
|
||||||
if (client.encryption?.keyManager.enabled == true) {
|
final state = await client.getCryptoIdentityState();
|
||||||
if (await client.encryption?.keyManager.isCached() == false ||
|
|
||||||
await client.encryption?.crossSigning.isCached() == false ||
|
|
||||||
client.isUnknownSession && !mounted) {
|
|
||||||
setState(() {
|
setState(() {
|
||||||
chatBackupEnabled = false;
|
chatBackupEnabled = state.initialized && !state.connected;
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeDevicesAction(List<Device> devices) async {
|
void removeDevicesAction(List<Device> devices) async {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import 'package:collection/collection.dart';
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
|
import 'package:matrix/encryption.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/l10n/l10n.dart';
|
import 'package:fluffychat/l10n/l10n.dart';
|
||||||
|
|
@ -61,13 +62,12 @@ class SettingsController extends State<Settings> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void logoutAction() async {
|
void logoutAction() async {
|
||||||
final noBackup = showChatBackupBanner == true;
|
|
||||||
if (await showOkCancelAlertDialog(
|
if (await showOkCancelAlertDialog(
|
||||||
useRootNavigator: false,
|
useRootNavigator: false,
|
||||||
context: context,
|
context: context,
|
||||||
title: L10n.of(context).areYouSureYouWantToLogout,
|
title: L10n.of(context).areYouSureYouWantToLogout,
|
||||||
message: L10n.of(context).noBackupWarning,
|
message: L10n.of(context).noBackupWarning,
|
||||||
isDestructive: noBackup,
|
isDestructive: cryptoIdentityConnected == false,
|
||||||
okLabel: L10n.of(context).logout,
|
okLabel: L10n.of(context).logout,
|
||||||
cancelLabel: L10n.of(context).cancel,
|
cancelLabel: L10n.of(context).cancel,
|
||||||
) ==
|
) ==
|
||||||
|
|
@ -167,23 +167,17 @@ class SettingsController extends State<Settings> {
|
||||||
if (client.prevBatch == null) {
|
if (client.prevBatch == null) {
|
||||||
await client.onSync.stream.first;
|
await client.onSync.stream.first;
|
||||||
}
|
}
|
||||||
final crossSigning =
|
|
||||||
await client.encryption?.crossSigning.isCached() ?? false;
|
final state = await client.getCryptoIdentityState();
|
||||||
final needsBootstrap =
|
|
||||||
await client.encryption?.keyManager.isCached() == false ||
|
|
||||||
client.encryption?.crossSigning.enabled == false ||
|
|
||||||
!crossSigning;
|
|
||||||
final isUnknownSession = client.isUnknownSession;
|
|
||||||
setState(() {
|
setState(() {
|
||||||
showChatBackupBanner = needsBootstrap || isUnknownSession;
|
cryptoIdentityConnected = state.initialized && state.connected;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool? crossSigningCached;
|
bool? cryptoIdentityConnected;
|
||||||
bool? showChatBackupBanner;
|
|
||||||
|
|
||||||
void firstRunBootstrapAction([_]) async {
|
void firstRunBootstrapAction([_]) async {
|
||||||
if (showChatBackupBanner != true) {
|
if (cryptoIdentityConnected == true) {
|
||||||
showOkAlertDialog(
|
showOkAlertDialog(
|
||||||
context: context,
|
context: context,
|
||||||
title: L10n.of(context).chatBackup,
|
title: L10n.of(context).chatBackup,
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ class SettingsView extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final showChatBackupBanner = controller.showChatBackupBanner;
|
|
||||||
final activeRoute = GoRouter.of(
|
final activeRoute = GoRouter.of(
|
||||||
context,
|
context,
|
||||||
).routeInformationProvider.value.uri.path;
|
).routeInformationProvider.value.uri.path;
|
||||||
|
|
@ -142,16 +141,9 @@ class SettingsView extends StatelessWidget {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Divider(color: theme.dividerColor),
|
Divider(color: theme.dividerColor),
|
||||||
if (showChatBackupBanner == null)
|
|
||||||
ListTile(
|
|
||||||
leading: const Icon(Icons.backup_outlined),
|
|
||||||
title: Text(L10n.of(context).chatBackup),
|
|
||||||
trailing: const CircularProgressIndicator.adaptive(),
|
|
||||||
)
|
|
||||||
else
|
|
||||||
SwitchListTile.adaptive(
|
SwitchListTile.adaptive(
|
||||||
controlAffinity: ListTileControlAffinity.trailing,
|
controlAffinity: ListTileControlAffinity.trailing,
|
||||||
value: controller.showChatBackupBanner == false,
|
value: controller.cryptoIdentityConnected == true,
|
||||||
secondary: const Icon(Icons.backup_outlined),
|
secondary: const Icon(Icons.backup_outlined),
|
||||||
title: Text(L10n.of(context).chatBackup),
|
title: Text(L10n.of(context).chatBackup),
|
||||||
onChanged: controller.firstRunBootstrapAction,
|
onChanged: controller.firstRunBootstrapAction,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue