From fc7eb6954c592f5cfd9c8e1e6d23bdd8a373c360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Mon, 9 Mar 2026 17:01:11 +0100 Subject: [PATCH] refactor: Make file events more fail safe for failed to send --- lib/pages/chat/events/audio_player.dart | 8 ++++---- lib/pages/chat/send_file_dialog.dart | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/pages/chat/events/audio_player.dart b/lib/pages/chat/events/audio_player.dart index f2edc232f..f78345d37 100644 --- a/lib/pages/chat/events/audio_player.dart +++ b/lib/pages/chat/events/audio_player.dart @@ -165,11 +165,11 @@ class AudioPlayerState extends State { : null, ); - if (!kIsWeb) { + final attachmentUrl = widget.event.attachmentOrThumbnailMxcUrl(); + + if (!kIsWeb && attachmentUrl != null) { final tempDir = await getTemporaryDirectory(); - final fileName = Uri.encodeComponent( - widget.event.attachmentOrThumbnailMxcUrl()!.pathSegments.last, - ); + final fileName = Uri.encodeComponent(attachmentUrl.pathSegments.last); file = File('${tempDir.path}/${fileName}_${matrixFile.name}'); await file.writeAsBytes(matrixFile.bytes); diff --git a/lib/pages/chat/send_file_dialog.dart b/lib/pages/chat/send_file_dialog.dart index 57f124b2c..8ae0627bb 100644 --- a/lib/pages/chat/send_file_dialog.dart +++ b/lib/pages/chat/send_file_dialog.dart @@ -1,8 +1,9 @@ +import 'package:async/async.dart' show Result; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:cross_file/cross_file.dart'; -import 'package:matrix/matrix.dart'; +import 'package:matrix/matrix.dart' hide Result; import 'package:mime/mime.dart'; import 'package:fluffychat/config/app_config.dart'; @@ -53,8 +54,9 @@ class SendFileDialogState extends State { } scaffoldMessenger.showLoadingSnackBar(l10n.prepareSendingAttachment); Navigator.of(context, rootNavigator: false).pop(); - final clientConfig = await widget.room.client.getConfig(); - final maxUploadSize = clientConfig.mUploadSize ?? 100 * 1000 * 1000; + final clientConfig = await Result.capture(widget.room.client.getConfig()); + final maxUploadSize = + clientConfig.asValue?.value.mUploadSize ?? 100 * 1000 * 1000; for (final xfile in widget.files) { final MatrixFile file;