Skip to content

Commit

Permalink
TW-1605: Fix image thumbnail from file
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn authored and hoangdat committed Mar 28, 2024
1 parent d459287 commit a3700f0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
21 changes: 15 additions & 6 deletions lib/presentation/extensions/send_file_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ extension SendFileExtension on Room {
fileSendingStatusKey,
FileSendingStatus.generatingThumbnail.name,
);
thumbnail ??= await _getThumbnailVideo(tempThumbnailFile, fileInfo);
thumbnail ??= await _getThumbnailVideo(tempThumbnailFile, fileInfo, txid);
if (fileInfo.width == null || fileInfo.height == null) {
fileInfo = VideoFileInfo(
fileInfo.fileName,
Expand All @@ -136,10 +136,18 @@ extension SendFileExtension on Room {
width: thumbnail.width,
height: thumbnail.height,
);
storePlaceholderFileInMem(
fileInfo: fileInfo,
txid: txid,
);
if (fileInfo.imagePlaceholderBytes.isNotEmpty) {
storePlaceholderFileInMem(
fileInfo: fileInfo,
txid: txid,
);
} else {
storePlaceholderFileInMem(
fileInfo: thumbnail,
txid: txid,
);
}

fakeImageEvent = await sendFakeImagePickerFileEvent(
fileInfo,
txid: txid,
Expand Down Expand Up @@ -453,6 +461,7 @@ extension SendFileExtension on Room {
Future<ImageFileInfo> _getThumbnailVideo(
File tempThumbnailFile,
VideoFileInfo fileInfo,
String txid,
) async {
final int fileSize;
if (fileInfo.imagePlaceholderBytes.isNotEmpty) {
Expand All @@ -472,7 +481,7 @@ extension SendFileExtension on Room {
if (width == null || height == null) {
try {
final imageDimension = await _calculateImageBytesDimension(
tempThumbnailFile.readAsBytesSync(),
await tempThumbnailFile.readAsBytes(),
);
width = imageDimension.width.toInt();
height = imageDimension.height.toInt();
Expand Down
6 changes: 4 additions & 2 deletions lib/presentation/mixins/send_files_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ mixin SendFilesMixin {
final temporaryDirectory = await getTemporaryDirectory();
fileInfos ??= result?.files
.map(
(xFile) => xFile.toFileInfo(
temporaryDirectoryPath: temporaryDirectory.path,
(xFile) => FileInfo.fromMatrixFile(
xFile.toMatrixFile(
temporaryDirectoryPath: temporaryDirectory.path,
),
),
)
.toList();
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1598,8 +1598,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: update-duratation-for-file-info
resolved-ref: "93cbacde518ed75d73a0f6b76b213b041233689f"
ref: "twake-supported-0.22.6"
resolved-ref: "8f821c1cab2506d13c2266cc8759ffd2b2818770"
url: "[email protected]:linagora/matrix-dart-sdk.git"
source: git
version: "0.22.6"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
matrix:
git:
url: [email protected]:linagora/matrix-dart-sdk.git
ref: update-duratation-for-file-info
ref: twake-supported-0.22.6

receive_sharing_intent:
git:
Expand Down

0 comments on commit a3700f0

Please sign in to comment.