From 17c932b0004cf17830facf22a0f881c2cde74b96 Mon Sep 17 00:00:00 2001 From: sherlockvn Date: Thu, 6 Jun 2024 15:24:04 +0700 Subject: [PATCH] TW-1806: add optional conditions for message type --- lib/src/utils/matrix_file.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/src/utils/matrix_file.dart b/lib/src/utils/matrix_file.dart index 83e636350..758729d53 100644 --- a/lib/src/utils/matrix_file.dart +++ b/lib/src/utils/matrix_file.dart @@ -68,17 +68,20 @@ class MatrixFile with EquatableMixin { String? filePath, Stream>? readStream, int? sizeInBytes, + bool optionalConditionForImageType = true, + bool optionalConditionForVideoType = true, + bool optionalConditionForAudioType = true, }) { final msgType = msgTypeFromMime(mimeType ?? lookupMimeType(name, headerBytes: bytes) ?? 'application/octet-stream'); - if (msgType == MessageTypes.Image) { + if (msgType == MessageTypes.Image && optionalConditionForImageType) { return MatrixImageFile(name: name, mimeType: mimeType, filePath: filePath, bytes: bytes, readStream: readStream,sizeInBytes: sizeInBytes); } - if (msgType == MessageTypes.Video) { + if (msgType == MessageTypes.Video && optionalConditionForVideoType) { return MatrixVideoFile(bytes: bytes, name: name, mimeType: mimeType, filePath: filePath, readStream: readStream, sizeInBytes: sizeInBytes); } - if (msgType == MessageTypes.Audio && bytes != null) { + if (msgType == MessageTypes.Audio && bytes != null && optionalConditionForAudioType) { return MatrixAudioFile(bytes: bytes, name: name, mimeType: mimeType, filePath: filePath, readStream: readStream, sizeInBytes: sizeInBytes); } return MatrixFile(bytes: bytes, name: name, mimeType: mimeType, filePath: filePath, readStream: readStream, sizeInBytes: sizeInBytes);