From aff10ab0ed344d8c68108d51a35fb31e7c99620b Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 13 Feb 2023 15:38:08 +0100 Subject: [PATCH] fix: Display error when user tries to send too large file --- assets/l10n/intl_en.arb | 3 ++- lib/pages/chat/chat.dart | 12 +++++++++++- lib/pages/chat/send_file_dialog.dart | 3 ++- lib/utils/localized_exception_extension.dart | 3 +++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 10875bf71..27451abc4 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -2518,5 +2518,6 @@ "enterInviteLinkOrMatrixId": "Enter invite link or Matrix ID...", "reopenChat": "Reopen chat", "noBackupWarning": "Warning! Without enabling chat backup, you will lose access to your encrypted messages. It is highly recommended to enable the chat backup first before logging out.", - "noOtherDevicesFound": "No other devices found" + "noOtherDevicesFound": "No other devices found", + "fileIsTooBigForServer": "The server reports that the file is too large to be sent." } \ No newline at end of file diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index d25c5d1e7..6c74475bb 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -446,6 +446,7 @@ class ChatController extends State { } void voiceMessageAction() async { + final scaffoldMessenger = ScaffoldMessenger.of(context); if (PlatformInfos.isAndroid) { final info = await DeviceInfoPlugin().androidInfo; if (info.version.sdkInt < 19) { @@ -486,7 +487,16 @@ class ChatController extends State { 'waveform': result.waveform, }, }, - ); + ).catchError((e) { + scaffoldMessenger.showSnackBar( + SnackBar( + content: Text( + (e as Object).toLocalizedString(context), + ), + ), + ); + return null; + }); setState(() { replyEvent = null; }); diff --git a/lib/pages/chat/send_file_dialog.dart b/lib/pages/chat/send_file_dialog.dart index 922f05c59..e7f2ace8b 100644 --- a/lib/pages/chat/send_file_dialog.dart +++ b/lib/pages/chat/send_file_dialog.dart @@ -4,6 +4,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:matrix/matrix.dart'; +import 'package:fluffychat/utils/localized_exception_extension.dart'; import 'package:fluffychat/utils/size_string.dart'; import '../../utils/resize_image.dart'; @@ -47,7 +48,7 @@ class SendFileDialogState extends State { ) .catchError((e) { scaffoldMessenger.showSnackBar( - SnackBar(content: Text(e.toLocalizedString())), + SnackBar(content: Text((e as Object).toLocalizedString(context))), ); return null; }); diff --git a/lib/utils/localized_exception_extension.dart b/lib/utils/localized_exception_extension.dart index 20530ed7e..b3d6093c3 100644 --- a/lib/utils/localized_exception_extension.dart +++ b/lib/utils/localized_exception_extension.dart @@ -19,6 +19,9 @@ extension LocalizedExceptionExtension on Object { return (this as MatrixException).errorMessage; } } + if (this is FileTooBigMatrixException) { + return L10n.of(context)!.fileIsTooBigForServer; + } if (this is BadServerVersionsException) { final serverVersions = (this as BadServerVersionsException) .serverVersions