From 35a2f95eae5931eb6b4c0a5ed288bf145108fa4f Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Wed, 30 Mar 2022 11:46:24 +0200 Subject: [PATCH] feat: Better image sending experience --- lib/pages/chat/chat.dart | 10 +++++----- lib/pages/chat/events/message.dart | 2 ++ lib/pages/chat/send_file_dialog.dart | 16 ++++++---------- .../event_extension.dart | 3 ++- pubspec.lock | 2 +- pubspec.yaml | 2 +- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index bd7230b6..0d2908e1 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -414,10 +414,10 @@ class ChatController extends State { bytes: audioFile.readAsBytesSync(), name: audioFile.path, ); - await showFutureLoadingDialog( - context: context, - future: () => - room!.sendFileEvent(file, inReplyTo: replyEvent, extraContent: { + await room!.sendFileEvent( + file, + inReplyTo: replyEvent, + extraContent: { 'info': { ...file.info, 'duration': result.duration, @@ -427,7 +427,7 @@ class ChatController extends State { 'duration': result.duration, 'waveform': result.waveform, }, - }), + }, ); setState(() { replyEvent = null; diff --git a/lib/pages/chat/events/message.dart b/lib/pages/chat/events/message.dart index c5c0f3c5..69ab5995 100644 --- a/lib/pages/chat/events/message.dart +++ b/lib/pages/chat/events/message.dart @@ -290,6 +290,8 @@ class Message extends StatelessWidget { )), ), row, + if (event.fileSendingStatus != null) + Text(event.fileSendingStatus!.name), if (event.hasAggregatedEvents(timeline, RelationshipTypes.reaction)) Padding( padding: EdgeInsets.only( diff --git a/lib/pages/chat/send_file_dialog.dart b/lib/pages/chat/send_file_dialog.dart index aadcb117..bb6d93a8 100644 --- a/lib/pages/chat/send_file_dialog.dart +++ b/lib/pages/chat/send_file_dialog.dart @@ -31,20 +31,16 @@ class _SendFileDialogState extends State { Future _send() async { var file = widget.file; MatrixImageFile? thumbnail; - if (file is MatrixImageFile && - !origImage && - file.bytes.length > minSizeToCompress) { - file = await MatrixImageFile.shrink( - bytes: file.bytes, - name: file.name, - compute: widget.room.client.runInBackground, - ); - } if (file is MatrixVideoFile && file.bytes.length > minSizeToCompress) { file = await file.resizeVideo(); thumbnail = await file.getVideoThumbnail(); } - await widget.room.sendFileEvent(file, thumbnail: thumbnail); + widget.room.sendFileEvent( + file, + thumbnail: thumbnail, + shrinkImageMaxDimension: origImage ? null : 1600, + ); + return; } @override diff --git a/lib/utils/matrix_sdk_extensions.dart/event_extension.dart b/lib/utils/matrix_sdk_extensions.dart/event_extension.dart index cd55e905..3871d4cb 100644 --- a/lib/utils/matrix_sdk_extensions.dart/event_extension.dart +++ b/lib/utils/matrix_sdk_extensions.dart/event_extension.dart @@ -76,7 +76,8 @@ extension LocalizedBody on Event { Future downloadAndDecryptAttachmentCached( {bool getThumbnail = false}) async { final mxcUrl = - attachmentOrThumbnailMxcUrl(getThumbnail: getThumbnail).toString(); + attachmentOrThumbnailMxcUrl(getThumbnail: getThumbnail)?.toString() ?? + eventId; _downloadAndDecryptFutures[mxcUrl] ??= downloadAndDecryptAttachment( getThumbnail: getThumbnail, downloadCallback: (Uri url) async { diff --git a/pubspec.lock b/pubspec.lock index ca39b2a8..826e7572 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -976,7 +976,7 @@ packages: name: matrix url: "https://pub.dartlang.org" source: hosted - version: "0.8.14" + version: "0.8.15" matrix_api_lite: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index d925cab8..8ae6c8dc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,7 +57,7 @@ dependencies: keyboard_shortcuts: ^0.1.4 localstorage: ^4.0.0+1 lottie: ^1.2.2 - matrix: ^0.8.14 + matrix: ^0.8.15 matrix_link_text: ^1.0.2 open_noti_settings: ^0.4.0 package_info_plus: ^1.3.0