From d7e4da0e550226f32d1a3ddca408011bc1cd6dbf Mon Sep 17 00:00:00 2001 From: otsmr Date: Sun, 17 May 2026 22:31:22 +0200 Subject: [PATCH] Fix: Images not shown after opening due to cleanup --- CHANGELOG.md | 4 ++++ lib/src/services/mediafiles/mediafile.service.dart | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cb6b10d..d4c4d816 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.2.16 + +- Fix: Images not shown after opening due to cleanup + ## 0.2.15 - Fix: Issue with opening directly in chats diff --git a/lib/src/services/mediafiles/mediafile.service.dart b/lib/src/services/mediafiles/mediafile.service.dart index aee30809..f6c1c4b6 100644 --- a/lib/src/services/mediafiles/mediafile.service.dart +++ b/lib/src/services/mediafiles/mediafile.service.dart @@ -84,6 +84,15 @@ class MediaFileService { if (message.openedAt == null) { // Message was not yet opened from all persons, so wait... delete = false; + } else if (message.openedAt!.isAfter( + clock.now().subtract(const Duration(minutes: 3)), + )) { + // When the message was opened in the last two minutes, do not purge. + // Bug: When the user opens an image immediately after starting the app, there is a race condition: + // The message is marked as opened, but then purgeTempFolder is run + // (it is unawaited) and deletes the file. Thi gives a grace period: + // The image must have been opened within the last two minutes, otherwise do not delete it. + delete = false; } else if (mediaFile.requiresAuthentication || mediaFile.displayLimitInMilliseconds != null) { // Message was opened by all persons, and they can not reopen the image.