Skip to content

Commit

Permalink
TW-1561: get filePath from mem, then display to the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn authored and hoangdat committed Apr 1, 2024
1 parent 729b6c7 commit 059b7fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/pages/chat/events/message_download_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class _MessageDownloadContentState extends State<MessageDownloadContent>
}

void checkDownloadFileState() async {
checkFileExistInMemory();
final filePath = await widget.event.getFileNameInAppDownload();
final file = File(filePath);
if (await file.exists() &&
Expand All @@ -65,6 +66,16 @@ class _MessageDownloadContentState extends State<MessageDownloadContent>
}
}

void checkFileExistInMemory() {
final filePathInMem = widget.event.getFilePathFromMem();
if (filePathInMem.isNotEmpty) {
downloadFileStateNotifier.value = DownloadedPresentationState(
filePath: filePathInMem,
);
return;
}
}

void _trySetupDownloadingStreamSubcription() {
streamSubscription = downloadManager
.getDownloadStateStream(widget.event.eventId)
Expand Down
11 changes: 10 additions & 1 deletion lib/utils/matrix_sdk_extensions/event_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ extension LocalizedBody on Event {
return await matrixFile.result?.downloadFile(context);
}

String get filenameEllipsized {
return filename.ellipsizeFileName;
}

String get filename {
return (content.tryGet<String>('filename') ?? body).ellipsizeFileName;
return (content.tryGet<String>('filename') ?? body);
}

String? get blurHash {
Expand Down Expand Up @@ -113,6 +117,11 @@ extension LocalizedBody on Event {
return room.sendingFilePlaceholders[txId];
}

String getFilePathFromMem() {
final matrixFile = getMatrixFile();
return matrixFile?.filePath ?? '';
}

Size? getOriginalResolution() {
if (infoMap['w'] != null && infoMap['h'] != null) {
return Size(
Expand Down

0 comments on commit 059b7fc

Please sign in to comment.