From 03728ccb4254fe1c326a5988b4d2681bff435143 Mon Sep 17 00:00:00 2001 From: Krille Date: Wed, 31 Jan 2024 07:46:13 +0100 Subject: [PATCH] fix: onDragDone crashes when no files found --- lib/pages/chat/chat.dart | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 6e400630..1f7eb424 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -135,25 +135,31 @@ class ChatController extends State void onDragDone(DropDoneDetails details) async { setState(() => dragging = false); - final bytesList = await showFutureLoadingDialog( + if (details.files.isEmpty) return; + final result = await showFutureLoadingDialog( context: context, - future: () => Future.wait( - details.files.map( - (xfile) => xfile.readAsBytes(), - ), - ), + future: () async { + final clientConfig = await room.client.getConfig(); + final maxUploadSize = clientConfig.mUploadSize ?? 100 * 1024 * 1024; + final matrixFiles = await Future.wait( + details.files.map( + (xfile) async { + final length = await xfile.length(); + if (length > maxUploadSize) { + throw FileTooBigMatrixException(length, maxUploadSize); + } + return MatrixFile( + bytes: await xfile.readAsBytes(), + name: xfile.name, + ); + }, + ), + ); + return matrixFiles; + }, ); - if (bytesList.error != null) return; - - final matrixFiles = []; - for (var i = 0; i < bytesList.result!.length; i++) { - matrixFiles.add( - MatrixFile( - bytes: bytesList.result![i], - name: details.files[i].name, - ).detectFileType, - ); - } + final matrixFiles = result.result; + if (matrixFiles == null || matrixFiles.isEmpty) return; await showAdaptiveDialog( context: context,