Skip to content

Commit

Permalink
TW-1806: add optional conditions for message type
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn committed Jun 6, 2024
1 parent 32d3a73 commit 17c932b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/src/utils/matrix_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,20 @@ class MatrixFile with EquatableMixin {
String? filePath,
Stream<List<int>>? 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);
Expand Down

0 comments on commit 17c932b

Please sign in to comment.