From 0135780f65095da5c65f3990566f2ee0b7deee45 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sun, 1 Aug 2021 15:45:41 +0200 Subject: [PATCH] fix: Missing null check and bootstrap ask --- assets/l10n/intl_en.arb | 5 +++++ lib/config/setting_keys.dart | 2 ++ lib/pages/bootstrap_dialog.dart | 13 +++++++++++++ lib/pages/chat_list.dart | 13 +++++++++++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 7b36b909..2518f0a7 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -903,6 +903,11 @@ "type": "text", "placeholders": {} }, + "dontAskAgain": "Cancel and don't ask again", + "@dontAskAgain": { + "type": "text", + "placeholders": {} + }, "encrypted": "Encrypted", "@encrypted": { "type": "text", diff --git a/lib/config/setting_keys.dart b/lib/config/setting_keys.dart index f56da382..62f774eb 100644 --- a/lib/config/setting_keys.dart +++ b/lib/config/setting_keys.dart @@ -18,4 +18,6 @@ abstract class SettingKeys { static const String unifiedPushEndpoint = 'chat.fluffy.unifiedpush.endpoint'; static const String notificationCurrentIds = 'chat.fluffy.notification_ids'; static const String ownStatusMessage = 'chat.fluffy.status_msg'; + static const String dontAskForBootstrapKey = + 'chat.fluffychat.dont_ask_bootstrap'; } diff --git a/lib/pages/bootstrap_dialog.dart b/lib/pages/bootstrap_dialog.dart index 97c2194d..f63abdd0 100644 --- a/lib/pages/bootstrap_dialog.dart +++ b/lib/pages/bootstrap_dialog.dart @@ -1,4 +1,6 @@ import 'package:adaptive_dialog/adaptive_dialog.dart'; +import 'package:fluffychat/config/setting_keys.dart'; +import 'package:fluffychat/utils/matrix_sdk_extensions.dart/flutter_matrix_hive_database.dart'; import 'package:matrix/encryption.dart'; import 'package:matrix/encryption/utils/bootstrap.dart'; import 'package:matrix/matrix.dart'; @@ -65,6 +67,12 @@ class _BootstrapDialogState extends State { }); } + void cancelAndDontAskAgain() async { + await (widget.client.database as FlutterMatrixHiveStore) + .put(SettingKeys.dontAskForBootstrapKey, true); + Navigator.of(context, rootNavigator: false).pop(false); + } + @override Widget build(BuildContext context) { _wipe ??= widget.wipe; @@ -81,6 +89,11 @@ class _BootstrapDialogState extends State { label: L10n.of(context).next, onPressed: () => _createBootstrap(false), )); + buttons.add(AdaptiveFlatButton( + label: L10n.of(context).dontAskAgain, + onPressed: cancelAndDontAskAgain, + textColor: Colors.red, + )); } else if (bootstrap.newSsssKey?.recoveryKey != null && _recoveryKeyStored == false) { final key = bootstrap.newSsssKey.recoveryKey; diff --git a/lib/pages/chat_list.dart b/lib/pages/chat_list.dart index 438f8d56..4656ad57 100644 --- a/lib/pages/chat_list.dart +++ b/lib/pages/chat_list.dart @@ -2,6 +2,8 @@ import 'dart:async'; import 'dart:io'; import 'package:adaptive_dialog/adaptive_dialog.dart'; +import 'package:fluffychat/config/setting_keys.dart'; +import 'package:fluffychat/utils/matrix_sdk_extensions.dart/flutter_matrix_hive_database.dart'; import 'package:matrix/matrix.dart'; import 'package:fluffychat/utils/fluffy_share.dart'; @@ -156,6 +158,11 @@ class ChatListController extends State { _initReceiveSharingIntent(); WidgetsBinding.instance.addPostFrameCallback((_) async { if (!Matrix.of(context).client.encryptionEnabled) return; + if ((Matrix.of(context).client.database as FlutterMatrixHiveStore) + .get(SettingKeys.dontAskForBootstrapKey) == + true) { + return; + } final crossSigning = await crossSigningCachedFuture; final needsBootstrap = Matrix.of(context).client.encryption?.crossSigning?.enabled == @@ -181,10 +188,12 @@ class ChatListController extends State { if (room.isSpace) return false; if (activeSpaceId != null) { final space = Matrix.of(context).client.getRoomById(activeSpaceId); - if (space.spaceChildren.any((child) => child.roomId == room.id)) { + if (space.spaceChildren?.any((child) => child.roomId == room.id) ?? + false) { return true; } - if (room.spaceParents.any((parent) => parent.roomId == activeSpaceId)) { + if (room.spaceParents?.any((parent) => parent.roomId == activeSpaceId) ?? + false) { return true; } if (room.isDirectChat &&