diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 4c38a9ffef..726b9db4a0 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -2754,5 +2754,8 @@ "workIdentitiesInfo": "WORK IDENTITIES INFO", "editWorkIdentitiesDescriptions": "Edit your work identity settings such as Matrix ID, email or company name.", "copiedMatrixIdToClipboard": "Copied Matrix ID to clipboard.", - "changeProfilePhoto": "Change profile photo" + "changeProfilePhoto": "Change profile photo", + "roomCreationFailed": "Room creation failed", + "errorGettingPdf": "Error getting PDF", + "errorPreviewingFile": "Error previewing file" } \ No newline at end of file diff --git a/lib/domain/model/extensions/mime_type_extension.dart b/lib/domain/model/extensions/mime_type_extension.dart index edbd1706c7..5b0573b8d2 100644 --- a/lib/domain/model/extensions/mime_type_extension.dart +++ b/lib/domain/model/extensions/mime_type_extension.dart @@ -43,20 +43,26 @@ extension MediaTypeExtension on Event { 'AttachmentExtension::getIcon(): mediaType: $mimeType || fileType: $fileType', ); if (mimeType?.isEmpty == true || fileType == null) { - return ImagePaths.icFileUnKnow; + return ImagePaths.icFileUnknown; } - if (isDocFile()) { - return ImagePaths.icFileDocx; - } else if (isExcelFile()) { - return ImagePaths.icFileXlsx; - } else if (isPowerPointFile()) { - return ImagePaths.icFilePptx; - } else if (isPdfFile()) { - return ImagePaths.icFilePdf; - } else if (isZipFile()) { - return ImagePaths.icFileZip; + + switch (getSupportedPreviewFileType()) { + case SupportedPreviewFileTypesEnum.image: + return ImagePaths.icFileUnknown; + case SupportedPreviewFileTypesEnum.doc: + return ImagePaths.icFileDocx; + case SupportedPreviewFileTypesEnum.excel: + return ImagePaths.icFileXlsx; + case SupportedPreviewFileTypesEnum.powerPoint: + return ImagePaths.icFilePptx; + case SupportedPreviewFileTypesEnum.pdf: + return ImagePaths.icFilePdf; + case SupportedPreviewFileTypesEnum.zip: + return ImagePaths.icFileZip; + case SupportedPreviewFileTypesEnum.unknown: + default: + return ImagePaths.icFileUnknown; } - return ImagePaths.icFileUnKnow; } String getFileType(BuildContext context) { @@ -70,4 +76,22 @@ extension MediaTypeExtension on Event { return L10n.of(context)!.file.toUpperCase(); } } + + SupportedPreviewFileTypesEnum getSupportedPreviewFileType() { + if (isImageFile()) { + return SupportedPreviewFileTypesEnum.image; + } else if (isDocFile()) { + return SupportedPreviewFileTypesEnum.doc; + } else if (isExcelFile()) { + return SupportedPreviewFileTypesEnum.excel; + } else if (isPowerPointFile()) { + return SupportedPreviewFileTypesEnum.powerPoint; + } else if (isPdfFile()) { + return SupportedPreviewFileTypesEnum.pdf; + } else if (isZipFile()) { + return SupportedPreviewFileTypesEnum.zip; + } else { + return SupportedPreviewFileTypesEnum.unknown; + } + } } diff --git a/lib/domain/model/preview_file/supported_preview_file_types.dart b/lib/domain/model/preview_file/supported_preview_file_types.dart index 68c9de0efd..eb900a0538 100644 --- a/lib/domain/model/preview_file/supported_preview_file_types.dart +++ b/lib/domain/model/preview_file/supported_preview_file_types.dart @@ -1,3 +1,13 @@ +enum SupportedPreviewFileTypesEnum { + image, + doc, + excel, + powerPoint, + pdf, + zip, + unknown, +} + class SupportedPreviewFileTypes { static const imageMimeTypes = [ 'image/bmp', diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 9c6fe920f0..347b9df491 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -575,10 +575,16 @@ class ChatController extends State } void _handlePreviewWeb({required Event event}) async { - if (event.isPdfFile()) { - downloadAndPreviewPdfOnWeb(context, event); - } else { - downloadFileAction(context, event); + if (!event.hasAttachment) { + Fluttertoast.showToast(msg: L10n.of(context)!.errorPreviewingFile); + return; + } + + switch (event.getSupportedPreviewFileType()) { + case SupportedPreviewFileTypesEnum.pdf: + return previewPdfWeb(context, event); + default: + downloadFileAction(context, event); } } @@ -1494,10 +1500,12 @@ class ChatController extends State Future downloadFileAction(BuildContext context, Event event) async => await event.saveFile(context); - void downloadAndPreviewPdfOnWeb(BuildContext context, Event event) async { + void previewPdfWeb(BuildContext context, Event event) async { final pdf = await event.getFile(context); - - if (pdf.result == null) return; + if (pdf.result == null || event.sizeString != pdf.result?.sizeString) { + Fluttertoast.showToast(msg: L10n.of(context)!.errorGettingPdf); + return; + } final blob = html.Blob([pdf.result!.bytes], 'application/pdf'); final url = html.Url.createObjectUrlFromBlob(blob); diff --git a/lib/pages/chat_draft/draft_chat.dart b/lib/pages/chat_draft/draft_chat.dart index 61a148596c..f56d441f6b 100644 --- a/lib/pages/chat_draft/draft_chat.dart +++ b/lib/pages/chat_draft/draft_chat.dart @@ -26,6 +26,7 @@ import 'package:linagora_design_flutter/images_picker/images_picker.dart' hide ImagePicker; import 'package:matrix/matrix.dart'; import 'package:scroll_to_index/scroll_to_index.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; typedef OnRoomCreatedSuccess = FutureOr Function(Room room)?; typedef OnRoomCreatedFailed = FutureOr Function()?; @@ -238,7 +239,7 @@ class DraftChatController extends State void onInputBarSubmitted(_) { sendText( onCreateRoomFailed: () { - Fluttertoast.showToast(msg: 'Create room failed'); + Fluttertoast.showToast(msg: L10n.of(context)!.roomCreationFailed); FocusScope.of(context).requestFocus(inputFocus); }, ); diff --git a/lib/resource/image_paths.dart b/lib/resource/image_paths.dart index bf1080c38a..67b1f07d9b 100644 --- a/lib/resource/image_paths.dart +++ b/lib/resource/image_paths.dart @@ -24,7 +24,7 @@ class ImagePaths { static String get icFilePdf => _getImagePath('ic_file_pdf.svg'); static String get icFilePptx => _getImagePath('ic_file_ppt.svg'); static String get icFileFolder => _getImagePath('ic_file_folder.svg'); - static String get icFileUnKnow => _getImagePath('ic_file_unknow.svg'); + static String get icFileUnknown => _getImagePath('ic_file_unknow.svg'); static String get icTwakeImageLogoDark => _getImagePath('ic_twake_image_logo_dark.svg'); static String get icApplicationGrid =>