From 5aea0c31fabe4361c2e001d9f5e326b907c8adbf Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Thu, 8 Sep 2022 09:12:08 +0200 Subject: [PATCH] feat: Automatic key requests and better key error dialog --- assets/l10n/intl_en.arb | 4 +- ios/Flutter/AppFrameworkInfo.plist | 2 +- ios/Runner.xcodeproj/project.pbxproj | 6 +- lib/pages/chat/chat.dart | 2 +- lib/pages/chat/events/message_content.dart | 60 ++++++++++++++----- .../matrix_locals.dart | 2 +- 6 files changed, 53 insertions(+), 23 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 3307ee90d..ede10af32 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -2890,5 +2890,7 @@ } }, "user": "User", - "custom": "Custom" + "custom": "Custom", + "whyIsThisMessageEncrypted": "Why is this message unreadable?", + "noKeyForThisMessage": "This can happen if the message was sent before you have signed in to your account at this device.\n\nIt is also possible that the sender has blocked your device or something went wrong with the internet connection.\n\nAre you able to read the message on another session? Then you can transfer the message from it! Go to Settings > Devices and make sure that your devices have verified each other. When you open the room the next time and both sessions are in the foreground, the keys will be transmitted automatically.\n\nDo you not want to loose the keys when logging out or switching devices? Make sure that you have enabled the chat backup in the settings." } diff --git a/ios/Flutter/AppFrameworkInfo.plist b/ios/Flutter/AppFrameworkInfo.plist index f2872cf47..4f8d4d245 100644 --- a/ios/Flutter/AppFrameworkInfo.plist +++ b/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 9.0 + 11.0 diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index dfc4598c2..a3dd9d163 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -450,7 +450,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -539,7 +539,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -588,7 +588,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 2a8120845..800317516 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -235,7 +235,7 @@ class ChatController extends State { }); } filteredEvents = timeline!.getFilteredEvents(unfolded: unfolded); - timeline!.requestKeys(); + timeline!.requestKeys(onlineKeyBackupOnly: false); return true; } diff --git a/lib/pages/chat/events/message_content.dart b/lib/pages/chat/events/message_content.dart index 3e0c8b88a..7c5710b86 100644 --- a/lib/pages/chat/events/message_content.dart +++ b/lib/pages/chat/events/message_content.dart @@ -1,12 +1,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; -import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:matrix/matrix.dart'; import 'package:matrix_link_text/link_text.dart'; import 'package:fluffychat/pages/chat/events/video_player.dart'; +import 'package:fluffychat/utils/date_time_extension.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions.dart/matrix_locals.dart'; +import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/matrix.dart'; import '../../../config/app_config.dart'; import '../../../utils/platform_infos.dart'; @@ -29,35 +30,62 @@ class MessageContent extends StatelessWidget { : super(key: key); void _verifyOrRequestKey(BuildContext context) async { + final l10n = L10n.of(context)!; if (event.content['can_request_session'] != true) { ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text( event.type == EventTypes.Encrypted - ? L10n.of(context)!.needPantalaimonWarning + ? l10n.needPantalaimonWarning : event.calcLocalizedBodyFallback( - MatrixLocals(L10n.of(context)!), + MatrixLocals(l10n), ), ))); return; } final client = Matrix.of(context).client; if (client.isUnknownSession && client.encryption!.crossSigning.enabled) { - await BootstrapDialog( + final success = await BootstrapDialog( client: Matrix.of(context).client, ).show(context); - final timeline = await event.room.getTimeline(); - timeline.requestKeys(); - timeline.cancelSubscriptions(); - } else { - final success = await showFutureLoadingDialog( - context: context, - future: () => event.requestKey(), - ); - if (success.error == null) { - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text(L10n.of(context)!.requestToReadOlderMessages))); - } + if (success != true) return; } + event.requestKey(); + final sender = event.senderFromMemoryOrFallback; + await showModalBottomSheet( + context: context, + builder: (context) => Scaffold( + appBar: AppBar( + leading: CloseButton(onPressed: Navigator.of(context).pop), + title: Text( + l10n.whyIsThisMessageEncrypted, + style: const TextStyle(fontSize: 16), + ), + ), + body: SafeArea( + child: ListView( + padding: const EdgeInsets.all(16), + children: [ + ListTile( + contentPadding: EdgeInsets.zero, + leading: Avatar( + mxContent: sender.avatarUrl, + name: sender.calcDisplayname(), + ), + title: Text(sender.calcDisplayname()), + subtitle: Text(event.originServerTs.localizedTime(context)), + trailing: const Icon(Icons.lock_outlined), + ), + const Divider(), + Text( + event.calcLocalizedBodyFallback( + MatrixLocals(l10n), + ), + ) + ], + ), + ), + ), + ); } @override diff --git a/lib/utils/matrix_sdk_extensions.dart/matrix_locals.dart b/lib/utils/matrix_sdk_extensions.dart/matrix_locals.dart index f54bd68d4..cae432843 100644 --- a/lib/utils/matrix_sdk_extensions.dart/matrix_locals.dart +++ b/lib/utils/matrix_sdk_extensions.dart/matrix_locals.dart @@ -175,7 +175,7 @@ class MatrixLocals extends MatrixLocalizations { String get needPantalaimonWarning => l10n.needPantalaimonWarning; @override - String get noPermission => l10n.noPermission; + String get noPermission => l10n.noKeyForThisMessage; @override String redactedAnEvent(String senderName) {